FreeRTOS Learning

eaoiyrioeaf wrote on Tuesday, February 28, 2017:

I’m learning FreeRTOS currently, I will try to write down what I learned from the source code and share it in this forum. hope it can help the beginner, and if I have made some mistake, it will be highly appreciated if some one can point out.

eaoiyrioeaf wrote on Tuesday, February 28, 2017:

Don’t know how to insert picture, attached picture is how I understood the List of FreeRTOS.

eaoiyrioeaf wrote on Tuesday, February 28, 2017:

Another picture to explain the function:
void vListInsert( List_t * const pxList, ListItem_t * const pxNewListItem )

eaoiyrioeaf wrote on Tuesday, February 28, 2017:

Picture to explain the function:
UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove )

heinbali01 wrote on Tuesday, February 28, 2017:

Hi John, thanks for the clear pictures. That all looks correct to me.

As you can see, the List_t type has been implemented with a minimum RAM footprint. All items (elements) know to which list they belong, if any. Each node in the list is part its object.

For instance, an example taken from FreeRTOS+TCP: a network buffer is either linked into a free list or into a list of occupied buffers. In order to make it linkable, it gets a ListItem_t field:

typedef struct xNETWORK_BUFFER
{
    ListItem_t xBufferListItem;   /* Used to reference the buffer form the free buffer list or a socket. */
    uint32_t ulIPAddress;         /* Source or destination IP address, depending on usage scenario. */
    uint8_t *pucEthernetBuffer;   /* Pointer to the start of the Ethernet frame. */
    ...
} NetworkBufferDescriptor_t;

Now xBufferListItem will always point to one of the two lists. You can add more ListItem_t's to your objects to make them linkable to several lists.

The List_t type has been exposed in a header file, but normally developers will not make use of them. It is a type definition “internal to the kernel”. But you’re free to use it, of course. Note that with a few additions (wrappers), you can create both FIFO’s and stacks, based on List_t.

Other objects are more important for most developers: Queue’s, Semaphores, Event-Groups and the mechanisms to notify (and wake-up) a task.

eaoiyrioeaf wrote on Tuesday, February 28, 2017:

Hello Hein, your explanation help me a lot to move forward, Thank you very much Sir!