SAM4S-EK_FreeRTOS+FAT-SL  1.0
An example project to test the functionality of FreeRTOS+FAT-SL using SD card as data storage medium
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules
list.c
Go to the documentation of this file.
1 /*
2  FreeRTOS V8.0.1 - Copyright (C) 2014 Real Time Engineers Ltd.
3  All rights reserved
4 
5  VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
6 
7  ***************************************************************************
8  * *
9  * FreeRTOS provides completely free yet professionally developed, *
10  * robust, strictly quality controlled, supported, and cross *
11  * platform software that has become a de facto standard. *
12  * *
13  * Help yourself get started quickly and support the FreeRTOS *
14  * project by purchasing a FreeRTOS tutorial book, reference *
15  * manual, or both from: http://www.FreeRTOS.org/Documentation *
16  * *
17  * Thank you! *
18  * *
19  ***************************************************************************
20 
21  This file is part of the FreeRTOS distribution.
22 
23  FreeRTOS is free software; you can redistribute it and/or modify it under
24  the terms of the GNU General Public License (version 2) as published by the
25  Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
26 
27  >>! NOTE: The modification to the GPL is included to allow you to !<<
28  >>! distribute a combined work that includes FreeRTOS without being !<<
29  >>! obliged to provide the source code for proprietary components !<<
30  >>! outside of the FreeRTOS kernel. !<<
31 
32  FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
33  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
34  FOR A PARTICULAR PURPOSE. Full license text is available from the following
35  link: http://www.freertos.org/a00114.html
36 
37  1 tab == 4 spaces!
38 
39  ***************************************************************************
40  * *
41  * Having a problem? Start by reading the FAQ "My application does *
42  * not run, what could be wrong?" *
43  * *
44  * http://www.FreeRTOS.org/FAQHelp.html *
45  * *
46  ***************************************************************************
47 
48  http://www.FreeRTOS.org - Documentation, books, training, latest versions,
49  license and Real Time Engineers Ltd. contact details.
50 
51  http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
52  including FreeRTOS+Trace - an indispensable productivity tool, a DOS
53  compatible FAT file system, and our tiny thread aware UDP/IP stack.
54 
55  http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
56  Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
57  licenses offer ticketed support, indemnification and middleware.
58 
59  http://www.SafeRTOS.com - High Integrity Systems also provide a safety
60  engineered and independently SIL3 certified version for use in safety and
61  mission critical applications that require provable dependability.
62 
63  1 tab == 4 spaces!
64 */
65 
66 
67 #include <stdlib.h>
68 #include "FreeRTOS.h"
69 #include "list.h"
70 
71 /*-----------------------------------------------------------
72  * PUBLIC LIST API documented in list.h
73  *----------------------------------------------------------*/
74 
75 void vListInitialise( List_t * const pxList )
76 {
77  /* The list structure contains a list item which is used to mark the
78  end of the list. To initialise the list the list end is inserted
79  as the only list entry. */
80  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. */
81 
82  /* The list end value is the highest possible value in the list to
83  ensure it remains at the end of the list. */
85 
86  /* The list end next and previous pointers point to itself so we know
87  when the list is empty. */
88  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. */
89  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. */
90 
91  pxList->uxNumberOfItems = ( UBaseType_t ) 0U;
92 }
93 /*-----------------------------------------------------------*/
94 
95 void vListInitialiseItem( ListItem_t * const pxItem )
96 {
97  /* Make sure the list item is not recorded as being on a list. */
98  pxItem->pvContainer = NULL;
99 }
100 /*-----------------------------------------------------------*/
101 
102 void vListInsertEnd( List_t * const pxList, ListItem_t * const pxNewListItem )
103 {
104 ListItem_t * const pxIndex = pxList->pxIndex;
105 
106  /* Insert a new list item into pxList, but rather than sort the list,
107  makes the new list item the last item to be removed by a call to
108  listGET_OWNER_OF_NEXT_ENTRY(). */
109  pxNewListItem->pxNext = pxIndex;
110  pxNewListItem->pxPrevious = pxIndex->pxPrevious;
111  pxIndex->pxPrevious->pxNext = pxNewListItem;
112  pxIndex->pxPrevious = pxNewListItem;
113 
114  /* Remember which list the item is in. */
115  pxNewListItem->pvContainer = ( void * ) pxList;
116 
117  ( pxList->uxNumberOfItems )++;
118 }
119 /*-----------------------------------------------------------*/
120 
121 void vListInsert( List_t * const pxList, ListItem_t * const pxNewListItem )
122 {
123 ListItem_t *pxIterator;
124 const TickType_t xValueOfInsertion = pxNewListItem->xItemValue;
125 
126  /* Insert the new list item into the list, sorted in xItemValue order.
127 
128  If the list already contains a list item with the same item value then
129  the new list item should be placed after it. This ensures that TCB's which
130  are stored in ready lists (all of which have the same xItemValue value)
131  get an equal share of the CPU. However, if the xItemValue is the same as
132  the back marker the iteration loop below will not end. This means we need
133  to guard against this by checking the value first and modifying the
134  algorithm slightly if necessary. */
135  if( xValueOfInsertion == portMAX_DELAY )
136  {
137  pxIterator = pxList->xListEnd.pxPrevious;
138  }
139  else
140  {
141  /* *** NOTE ***********************************************************
142  If you find your application is crashing here then likely causes are:
143  1) Stack overflow -
144  see http://www.freertos.org/Stacks-and-stack-overflow-checking.html
145  2) Incorrect interrupt priority assignment, especially on Cortex-M3
146  parts where numerically high priority values denote low actual
147  interrupt priories, which can seem counter intuitive. See
148  configMAX_SYSCALL_INTERRUPT_PRIORITY on http://www.freertos.org/a00110.html
149  3) Calling an API function from within a critical section or when
150  the scheduler is suspended, or calling an API function that does
151  not end in "FromISR" from an interrupt.
152  4) Using a queue or semaphore before it has been initialised or
153  before the scheduler has been started (are interrupts firing
154  before vTaskStartScheduler() has been called?).
155  See http://www.freertos.org/FAQHelp.html for more tips, and ensure
156  configASSERT() is defined! http://www.freertos.org/a00110.html#configASSERT
157  **********************************************************************/
158 
159  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. */
160  {
161  /* There is nothing to do here, we are just iterating to the
162  wanted insertion position. */
163  }
164  }
165 
166  pxNewListItem->pxNext = pxIterator->pxNext;
167  pxNewListItem->pxNext->pxPrevious = pxNewListItem;
168  pxNewListItem->pxPrevious = pxIterator;
169  pxIterator->pxNext = pxNewListItem;
170 
171  /* Remember which list the item is in. This allows fast removal of the
172  item later. */
173  pxNewListItem->pvContainer = ( void * ) pxList;
174 
175  ( pxList->uxNumberOfItems )++;
176 }
177 /*-----------------------------------------------------------*/
178 
179 UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove )
180 {
181 /* The list item knows which list it is in. Obtain the list from the list
182 item. */
183 List_t * const pxList = ( List_t * ) pxItemToRemove->pvContainer;
184 
185  pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious;
186  pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext;
187 
188  /* Make sure the index is left pointing to a valid item. */
189  if( pxList->pxIndex == pxItemToRemove )
190  {
191  pxList->pxIndex = pxItemToRemove->pxPrevious;
192  }
193  else
194  {
196  }
197 
198  pxItemToRemove->pvContainer = NULL;
199  ( pxList->uxNumberOfItems )--;
200 
201  return pxList->uxNumberOfItems;
202 }
203 /*-----------------------------------------------------------*/
204 
#define portMAX_DELAY
Definition: portmacro.h:102
#define mtCOVERAGE_TEST_MARKER()
Definition: FreeRTOS.h:717
MiniListItem_t xListEnd
Definition: list.h:161
void vListInitialise(List_t *const pxList)
Definition: list.c:75
unsigned long UBaseType_t
Definition: portmacro.h:95
uint32_t TickType_t
Definition: portmacro.h:101
void vListInitialiseItem(ListItem_t *const pxItem)
Definition: list.c:95
struct xLIST_ITEM *configLIST_VOLATILE pxNext
Definition: list.h:149
UBaseType_t uxListRemove(ListItem_t *const pxItemToRemove)
Definition: list.c:179
struct xLIST_ITEM *configLIST_VOLATILE pxPrevious
Definition: list.h:150
configLIST_VOLATILE UBaseType_t uxNumberOfItems
Definition: list.h:159
void *configLIST_VOLATILE pvContainer
Definition: list.h:142
configLIST_VOLATILE TickType_t xItemValue
Definition: list.h:138
ListItem_t *configLIST_VOLATILE pxIndex
Definition: list.h:160
void vListInsert(List_t *const pxList, ListItem_t *const pxNewListItem)
Definition: list.c:121
void vListInsertEnd(List_t *const pxList, ListItem_t *const pxNewListItem)
Definition: list.c:102
Definition: list.h:157
configLIST_VOLATILE TickType_t xItemValue
Definition: list.h:148
struct xLIST_ITEM *configLIST_VOLATILE pxNext
Definition: list.h:139
struct xLIST_ITEM *configLIST_VOLATILE pxPrevious
Definition: list.h:140