On nie, 2016-10-09 at 05:02 +0000, Kenny Koller wrote: > Hi Everyone, > > I'm starting with some code generated by the ST Cube software for > FreeRTOS. > > I prefer not to use the FreeRTOS memory manager and the current > version supports static allocation so I pleased to read this: > > Since lwIP 1.4.0, semaphore, mutexes and mailbox functions are > prototyped in a way that allows both using pointers or actual OS > structures to be used. This way, memory required for such types can > be either allocated in place (globally or on the stack) or on the > heap (allocated internally in the "*_new()" functions). > > Of course I understand what is meant by allocating in place or on the > stack but in practice how would be be used? It seems that you still > need to preallocate a number of mailboxes or semaphores. Is creating > a simple static array in sys_arch.c and doing some book keeping on > which have been allocated/freed a reasonable approach?
Hello Kenny! You don't need to preallocate anything, but keep in mind that in case of mailboxes the memory for the mailbox object is usually separate from the memory for the mailbox contents. In theory you could have both of these memories allocated in place or on stack, but this way each mailbox you create would have to have the same size - not very flexible... To use this feature I believe you'd need to set configSUPPORT_STATIC_ALLOCATION in your configuration and declare sys_sem_t to be StaticSemaphore_t. The same for mailbox - just use StaticQueue_t for sys_mbox_t. Then in the *_new() functions you just "construct" the objects in provided buffers with xSemaphoreCreateCountingStatic() and xQueueCreateStatic(). Due to the thing I mentioned in the first paragraph this gets tricky with queues, as you'd need to allocate the storage for contents (pucQueueStorageBuffer argument for xQueueCreateStatic()) from somewhere else - heap of preallocated buffers... Regards, FCh _______________________________________________ lwip-users mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/lwip-users
