Prusa MINI Firmware overview
list.c File Reference
#include <stdlib.h>
#include "FreeRTOS.h"
#include "list.h"

Functions

void vListInitialise (List_t *const pxList)
 
void vListInitialiseItem (ListItem_t *const pxItem)
 
void vListInsertEnd (List_t *const pxList, ListItem_t *const pxNewListItem)
 
void vListInsert (List_t *const pxList, ListItem_t *const pxNewListItem)
 
UBaseType_t uxListRemove (ListItem_t *const pxItemToRemove)
 

Function Documentation

◆ vListInitialise()

void vListInitialise ( List_t *const  pxList)
80 {
81  /* The list structure contains a list item which is used to mark the
82  end of the list. To initialise the list the list end is inserted
83  as the only list entry. */
84  pxList->pxIndex = ( ListItem_t * ) &( pxList->xListEnd ); /*lint !e826 !e740 The mini list structure is used as the list end to save RAM. This is checked and valid. */
85 
86  /* The list end value is the highest possible value in the list to
87  ensure it remains at the end of the list. */
89 
90  /* The list end next and previous pointers point to itself so we know
91  when the list is empty. */
92  pxList->xListEnd.pxNext = ( ListItem_t * ) &( pxList->xListEnd ); /*lint !e826 !e740 The mini list structure is used as the list end to save RAM. This is checked and valid. */
93  pxList->xListEnd.pxPrevious = ( ListItem_t * ) &( pxList->xListEnd );/*lint !e826 !e740 The mini list structure is used as the list end to save RAM. This is checked and valid. */
94 
95  pxList->uxNumberOfItems = ( UBaseType_t ) 0U;
96 
97  /* Write known values into the list if
98  configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
101 }
Here is the caller graph for this function:

◆ vListInitialiseItem()

void vListInitialiseItem ( ListItem_t *const  pxItem)
105 {
106  /* Make sure the list item is not recorded as being on a list. */
107  pxItem->pvContainer = NULL;
108 
109  /* Write known values into the list item if
110  configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
113 }
Here is the caller graph for this function:

◆ vListInsertEnd()

void vListInsertEnd ( List_t *const  pxList,
ListItem_t *const  pxNewListItem 
)
117 {
118 ListItem_t * const pxIndex = pxList->pxIndex;
119 
120  /* Only effective when configASSERT() is also defined, these tests may catch
121  the list data structures being overwritten in memory. They will not catch
122  data errors caused by incorrect configuration or use of FreeRTOS. */
123  listTEST_LIST_INTEGRITY( pxList );
124  listTEST_LIST_ITEM_INTEGRITY( pxNewListItem );
125 
126  /* Insert a new list item into pxList, but rather than sort the list,
127  makes the new list item the last item to be removed by a call to
128  listGET_OWNER_OF_NEXT_ENTRY(). */
129  pxNewListItem->pxNext = pxIndex;
130  pxNewListItem->pxPrevious = pxIndex->pxPrevious;
131 
132  /* Only used during decision coverage testing. */
134 
135  pxIndex->pxPrevious->pxNext = pxNewListItem;
136  pxIndex->pxPrevious = pxNewListItem;
137 
138  /* Remember which list the item is in. */
139  pxNewListItem->pvContainer = ( void * ) pxList;
140 
141  ( pxList->uxNumberOfItems )++;
142 }
Here is the caller graph for this function:

◆ vListInsert()

void vListInsert ( List_t *const  pxList,
ListItem_t *const  pxNewListItem 
)
146 {
147 ListItem_t *pxIterator;
148 const TickType_t xValueOfInsertion = pxNewListItem->xItemValue;
149 
150  /* Only effective when configASSERT() is also defined, these tests may catch
151  the list data structures being overwritten in memory. They will not catch
152  data errors caused by incorrect configuration or use of FreeRTOS. */
153  listTEST_LIST_INTEGRITY( pxList );
154  listTEST_LIST_ITEM_INTEGRITY( pxNewListItem );
155 
156  /* Insert the new list item into the list, sorted in xItemValue order.
157 
158  If the list already contains a list item with the same item value then the
159  new list item should be placed after it. This ensures that TCB's which are
160  stored in ready lists (all of which have the same xItemValue value) get a
161  share of the CPU. However, if the xItemValue is the same as the back marker
162  the iteration loop below will not end. Therefore the value is checked
163  first, and the algorithm slightly modified if necessary. */
164  if( xValueOfInsertion == portMAX_DELAY )
165  {
166  pxIterator = pxList->xListEnd.pxPrevious;
167  }
168  else
169  {
170  /* *** NOTE ***********************************************************
171  If you find your application is crashing here then likely causes are
172  listed below. In addition see http://www.freertos.org/FAQHelp.html for
173  more tips, and ensure configASSERT() is defined!
174  http://www.freertos.org/a00110.html#configASSERT
175 
176  1) Stack overflow -
177  see http://www.freertos.org/Stacks-and-stack-overflow-checking.html
178  2) Incorrect interrupt priority assignment, especially on Cortex-M
179  parts where numerically high priority values denote low actual
180  interrupt priorities, which can seem counter intuitive. See
181  http://www.freertos.org/RTOS-Cortex-M3-M4.html and the definition
182  of configMAX_SYSCALL_INTERRUPT_PRIORITY on
183  http://www.freertos.org/a00110.html
184  3) Calling an API function from within a critical section or when
185  the scheduler is suspended, or calling an API function that does
186  not end in "FromISR" from an interrupt.
187  4) Using a queue or semaphore before it has been initialised or
188  before the scheduler has been started (are interrupts firing
189  before vTaskStartScheduler() has been called?).
190  **********************************************************************/
191 
192  for( pxIterator = ( ListItem_t * ) &( pxList->xListEnd ); pxIterator->pxNext->xItemValue <= xValueOfInsertion; pxIterator = pxIterator->pxNext ) /*lint !e826 !e740 The mini list structure is used as the list end to save RAM. This is checked and valid. */
193  {
194  /* There is nothing to do here, just iterating to the wanted
195  insertion position. */
196  }
197  }
198 
199  pxNewListItem->pxNext = pxIterator->pxNext;
200  pxNewListItem->pxNext->pxPrevious = pxNewListItem;
201  pxNewListItem->pxPrevious = pxIterator;
202  pxIterator->pxNext = pxNewListItem;
203 
204  /* Remember which list the item is in. This allows fast removal of the
205  item later. */
206  pxNewListItem->pvContainer = ( void * ) pxList;
207 
208  ( pxList->uxNumberOfItems )++;
209 }
Here is the caller graph for this function:

◆ uxListRemove()

UBaseType_t uxListRemove ( ListItem_t *const  pxItemToRemove)
213 {
214 /* The list item knows which list it is in. Obtain the list from the list
215 item. */
216 List_t * const pxList = ( List_t * ) pxItemToRemove->pvContainer;
217 
218  pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious;
219  pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext;
220 
221  /* Only used during decision coverage testing. */
223 
224  /* Make sure the index is left pointing to a valid item. */
225  if( pxList->pxIndex == pxItemToRemove )
226  {
227  pxList->pxIndex = pxItemToRemove->pxPrevious;
228  }
229  else
230  {
232  }
233 
234  pxItemToRemove->pvContainer = NULL;
235  ( pxList->uxNumberOfItems )--;
236 
237  return pxList->uxNumberOfItems;
238 }
Here is the caller graph for this function:
listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE
#define listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE(pxItem)
Definition: list.h:153
xLIST_ITEM::xItemValue
listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE configLIST_VOLATILE TickType_t xItemValue
Definition: list.h:184
listTEST_LIST_ITEM_INTEGRITY
#define listTEST_LIST_ITEM_INTEGRITY(pxItem)
Definition: list.h:156
xMINI_LIST_ITEM::pxNext
struct xLIST_ITEM *configLIST_VOLATILE pxNext
Definition: list.h:197
portMAX_DELAY
#define portMAX_DELAY
Definition: portmacro.h:106
xLIST
Definition: list.h:205
xLIST_ITEM
Definition: list.h:181
xLIST::pxIndex
ListItem_t *configLIST_VOLATILE pxIndex
Definition: list.h:209
xMINI_LIST_ITEM::pxPrevious
struct xLIST_ITEM *configLIST_VOLATILE pxPrevious
Definition: list.h:198
NULL
#define NULL
Definition: usbd_def.h:53
TickType_t
uint32_t TickType_t
Definition: portmacro.h:105
xLIST_ITEM::pvContainer
void *configLIST_VOLATILE pvContainer
Definition: list.h:188
UBaseType_t
unsigned long UBaseType_t
Definition: portmacro.h:99
xLIST_ITEM::pxPrevious
struct xLIST_ITEM *configLIST_VOLATILE pxPrevious
Definition: list.h:186
xLIST::xListEnd
MiniListItem_t xListEnd
Definition: list.h:210
xMINI_LIST_ITEM::xItemValue
listFIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE configLIST_VOLATILE TickType_t xItemValue
Definition: list.h:196
xLIST_ITEM::pxNext
struct xLIST_ITEM *configLIST_VOLATILE pxNext
Definition: list.h:185
listTEST_LIST_INTEGRITY
#define listTEST_LIST_INTEGRITY(pxList)
Definition: list.h:157
xLIST::uxNumberOfItems
listFIRST_LIST_INTEGRITY_CHECK_VALUE configLIST_VOLATILE UBaseType_t uxNumberOfItems
Definition: list.h:208
listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE
#define listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE(pxItem)
Definition: list.h:152
listSET_LIST_INTEGRITY_CHECK_1_VALUE
#define listSET_LIST_INTEGRITY_CHECK_1_VALUE(pxList)
Definition: list.h:154
mtCOVERAGE_TEST_DELAY
#define mtCOVERAGE_TEST_DELAY()
Definition: FreeRTOS.h:752
listSET_LIST_INTEGRITY_CHECK_2_VALUE
#define listSET_LIST_INTEGRITY_CHECK_2_VALUE(pxList)
Definition: list.h:155
mtCOVERAGE_TEST_MARKER
#define mtCOVERAGE_TEST_MARKER()
Definition: FreeRTOS.h:748