www.freertos.org

Dependents:   Nucleo freertos_test FreeRTOS_test freertos_bluetooth ... more

Committer:
rgrover1
Date:
Fri Jan 24 14:56:04 2014 +0000
Revision:
0:8e57f3e9cc89
Making FreeRTOS available as a library

Who changed what in which revision?

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