Please see my note book http://mbed.org/users/kenjiArai/notebook/freertos-on-mbed-board-with-mbed-cloud-ide--never-/
This is too old.
Below is another FreeRTOS on mbed.
http://developer.mbed.org/users/rgrover1/code/FreeRTOS/
I don't know it works well or not.
I have not evaluated it.
FreeRTOS/Source/list.c@0:d4960fcea8ff, 2011-01-01 (annotated)
- Committer:
- kenjiArai
- Date:
- Sat Jan 01 11:17:45 2011 +0000
- Revision:
- 0:d4960fcea8ff
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kenjiArai | 0:d4960fcea8ff | 1 | /* |
kenjiArai | 0:d4960fcea8ff | 2 | FreeRTOS V6.0.3 - Copyright (C) 2010 Real Time Engineers Ltd. |
kenjiArai | 0:d4960fcea8ff | 3 | |
kenjiArai | 0:d4960fcea8ff | 4 | *************************************************************************** |
kenjiArai | 0:d4960fcea8ff | 5 | * * |
kenjiArai | 0:d4960fcea8ff | 6 | * If you are: * |
kenjiArai | 0:d4960fcea8ff | 7 | * * |
kenjiArai | 0:d4960fcea8ff | 8 | * + New to FreeRTOS, * |
kenjiArai | 0:d4960fcea8ff | 9 | * + Wanting to learn FreeRTOS or multitasking in general quickly * |
kenjiArai | 0:d4960fcea8ff | 10 | * + Looking for basic training, * |
kenjiArai | 0:d4960fcea8ff | 11 | * + Wanting to improve your FreeRTOS skills and productivity * |
kenjiArai | 0:d4960fcea8ff | 12 | * * |
kenjiArai | 0:d4960fcea8ff | 13 | * then take a look at the FreeRTOS eBook * |
kenjiArai | 0:d4960fcea8ff | 14 | * * |
kenjiArai | 0:d4960fcea8ff | 15 | * "Using the FreeRTOS Real Time Kernel - a Practical Guide" * |
kenjiArai | 0:d4960fcea8ff | 16 | * http://www.FreeRTOS.org/Documentation * |
kenjiArai | 0:d4960fcea8ff | 17 | * * |
kenjiArai | 0:d4960fcea8ff | 18 | * A pdf reference manual is also available. Both are usually delivered * |
kenjiArai | 0:d4960fcea8ff | 19 | * to your inbox within 20 minutes to two hours when purchased between 8am * |
kenjiArai | 0:d4960fcea8ff | 20 | * and 8pm GMT (although please allow up to 24 hours in case of * |
kenjiArai | 0:d4960fcea8ff | 21 | * exceptional circumstances). Thank you for your support! * |
kenjiArai | 0:d4960fcea8ff | 22 | * * |
kenjiArai | 0:d4960fcea8ff | 23 | *************************************************************************** |
kenjiArai | 0:d4960fcea8ff | 24 | |
kenjiArai | 0:d4960fcea8ff | 25 | This file is part of the FreeRTOS distribution. |
kenjiArai | 0:d4960fcea8ff | 26 | |
kenjiArai | 0:d4960fcea8ff | 27 | FreeRTOS is free software; you can redistribute it and/or modify it under |
kenjiArai | 0:d4960fcea8ff | 28 | the terms of the GNU General Public License (version 2) as published by the |
kenjiArai | 0:d4960fcea8ff | 29 | Free Software Foundation AND MODIFIED BY the FreeRTOS exception. |
kenjiArai | 0:d4960fcea8ff | 30 | ***NOTE*** The exception to the GPL is included to allow you to distribute |
kenjiArai | 0:d4960fcea8ff | 31 | a combined work that includes FreeRTOS without being obliged to provide the |
kenjiArai | 0:d4960fcea8ff | 32 | source code for proprietary components outside of the FreeRTOS kernel. |
kenjiArai | 0:d4960fcea8ff | 33 | FreeRTOS is distributed in the hope that it will be useful, but WITHOUT |
kenjiArai | 0:d4960fcea8ff | 34 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
kenjiArai | 0:d4960fcea8ff | 35 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
kenjiArai | 0:d4960fcea8ff | 36 | more details. You should have received a copy of the GNU General Public |
kenjiArai | 0:d4960fcea8ff | 37 | License and the FreeRTOS license exception along with FreeRTOS; if not it |
kenjiArai | 0:d4960fcea8ff | 38 | can be viewed here: http://www.freertos.org/a00114.html and also obtained |
kenjiArai | 0:d4960fcea8ff | 39 | by writing to Richard Barry, contact details for whom are available on the |
kenjiArai | 0:d4960fcea8ff | 40 | FreeRTOS WEB site. |
kenjiArai | 0:d4960fcea8ff | 41 | |
kenjiArai | 0:d4960fcea8ff | 42 | 1 tab == 4 spaces! |
kenjiArai | 0:d4960fcea8ff | 43 | |
kenjiArai | 0:d4960fcea8ff | 44 | http://www.FreeRTOS.org - Documentation, latest information, license and |
kenjiArai | 0:d4960fcea8ff | 45 | contact details. |
kenjiArai | 0:d4960fcea8ff | 46 | |
kenjiArai | 0:d4960fcea8ff | 47 | http://www.SafeRTOS.com - A version that is certified for use in safety |
kenjiArai | 0:d4960fcea8ff | 48 | critical systems. |
kenjiArai | 0:d4960fcea8ff | 49 | |
kenjiArai | 0:d4960fcea8ff | 50 | http://www.OpenRTOS.com - Commercial support, development, porting, |
kenjiArai | 0:d4960fcea8ff | 51 | licensing and training services. |
kenjiArai | 0:d4960fcea8ff | 52 | */ |
kenjiArai | 0:d4960fcea8ff | 53 | |
kenjiArai | 0:d4960fcea8ff | 54 | |
kenjiArai | 0:d4960fcea8ff | 55 | #include "stdlib.h" |
kenjiArai | 0:d4960fcea8ff | 56 | #include "./FreeRTOS/Source/include/FreeRTOS.h" |
kenjiArai | 0:d4960fcea8ff | 57 | #include "./FreeRTOS/Source/include/list.h" |
kenjiArai | 0:d4960fcea8ff | 58 | |
kenjiArai | 0:d4960fcea8ff | 59 | /*----------------------------------------------------------- |
kenjiArai | 0:d4960fcea8ff | 60 | * PUBLIC LIST API documented in list.h |
kenjiArai | 0:d4960fcea8ff | 61 | *----------------------------------------------------------*/ |
kenjiArai | 0:d4960fcea8ff | 62 | |
kenjiArai | 0:d4960fcea8ff | 63 | void vListInitialise( xList *pxList ) |
kenjiArai | 0:d4960fcea8ff | 64 | { |
kenjiArai | 0:d4960fcea8ff | 65 | /* The list structure contains a list item which is used to mark the |
kenjiArai | 0:d4960fcea8ff | 66 | end of the list. To initialise the list the list end is inserted |
kenjiArai | 0:d4960fcea8ff | 67 | as the only list entry. */ |
kenjiArai | 0:d4960fcea8ff | 68 | pxList->pxIndex = ( xListItem * ) &( pxList->xListEnd ); |
kenjiArai | 0:d4960fcea8ff | 69 | |
kenjiArai | 0:d4960fcea8ff | 70 | /* The list end value is the highest possible value in the list to |
kenjiArai | 0:d4960fcea8ff | 71 | ensure it remains at the end of the list. */ |
kenjiArai | 0:d4960fcea8ff | 72 | pxList->xListEnd.xItemValue = portMAX_DELAY; |
kenjiArai | 0:d4960fcea8ff | 73 | |
kenjiArai | 0:d4960fcea8ff | 74 | /* The list end next and previous pointers point to itself so we know |
kenjiArai | 0:d4960fcea8ff | 75 | when the list is empty. */ |
kenjiArai | 0:d4960fcea8ff | 76 | pxList->xListEnd.pxNext = ( xListItem * ) &( pxList->xListEnd ); |
kenjiArai | 0:d4960fcea8ff | 77 | pxList->xListEnd.pxPrevious = ( xListItem * ) &( pxList->xListEnd ); |
kenjiArai | 0:d4960fcea8ff | 78 | |
kenjiArai | 0:d4960fcea8ff | 79 | pxList->uxNumberOfItems = 0; |
kenjiArai | 0:d4960fcea8ff | 80 | } |
kenjiArai | 0:d4960fcea8ff | 81 | /*-----------------------------------------------------------*/ |
kenjiArai | 0:d4960fcea8ff | 82 | |
kenjiArai | 0:d4960fcea8ff | 83 | void vListInitialiseItem( xListItem *pxItem ) |
kenjiArai | 0:d4960fcea8ff | 84 | { |
kenjiArai | 0:d4960fcea8ff | 85 | /* Make sure the list item is not recorded as being on a list. */ |
kenjiArai | 0:d4960fcea8ff | 86 | pxItem->pvContainer = NULL; |
kenjiArai | 0:d4960fcea8ff | 87 | } |
kenjiArai | 0:d4960fcea8ff | 88 | /*-----------------------------------------------------------*/ |
kenjiArai | 0:d4960fcea8ff | 89 | |
kenjiArai | 0:d4960fcea8ff | 90 | void vListInsertEnd( xList *pxList, xListItem *pxNewListItem ) |
kenjiArai | 0:d4960fcea8ff | 91 | { |
kenjiArai | 0:d4960fcea8ff | 92 | volatile xListItem * pxIndex; |
kenjiArai | 0:d4960fcea8ff | 93 | |
kenjiArai | 0:d4960fcea8ff | 94 | /* Insert a new list item into pxList, but rather than sort the list, |
kenjiArai | 0:d4960fcea8ff | 95 | makes the new list item the last item to be removed by a call to |
kenjiArai | 0:d4960fcea8ff | 96 | pvListGetOwnerOfNextEntry. This means it has to be the item pointed to by |
kenjiArai | 0:d4960fcea8ff | 97 | the pxIndex member. */ |
kenjiArai | 0:d4960fcea8ff | 98 | pxIndex = pxList->pxIndex; |
kenjiArai | 0:d4960fcea8ff | 99 | |
kenjiArai | 0:d4960fcea8ff | 100 | pxNewListItem->pxNext = pxIndex->pxNext; |
kenjiArai | 0:d4960fcea8ff | 101 | pxNewListItem->pxPrevious = pxList->pxIndex; |
kenjiArai | 0:d4960fcea8ff | 102 | pxIndex->pxNext->pxPrevious = ( volatile xListItem * ) pxNewListItem; |
kenjiArai | 0:d4960fcea8ff | 103 | pxIndex->pxNext = ( volatile xListItem * ) pxNewListItem; |
kenjiArai | 0:d4960fcea8ff | 104 | pxList->pxIndex = ( volatile xListItem * ) pxNewListItem; |
kenjiArai | 0:d4960fcea8ff | 105 | |
kenjiArai | 0:d4960fcea8ff | 106 | /* Remember which list the item is in. */ |
kenjiArai | 0:d4960fcea8ff | 107 | pxNewListItem->pvContainer = ( void * ) pxList; |
kenjiArai | 0:d4960fcea8ff | 108 | |
kenjiArai | 0:d4960fcea8ff | 109 | ( pxList->uxNumberOfItems )++; |
kenjiArai | 0:d4960fcea8ff | 110 | } |
kenjiArai | 0:d4960fcea8ff | 111 | /*-----------------------------------------------------------*/ |
kenjiArai | 0:d4960fcea8ff | 112 | |
kenjiArai | 0:d4960fcea8ff | 113 | void vListInsert( xList *pxList, xListItem *pxNewListItem ) |
kenjiArai | 0:d4960fcea8ff | 114 | { |
kenjiArai | 0:d4960fcea8ff | 115 | volatile xListItem *pxIterator; |
kenjiArai | 0:d4960fcea8ff | 116 | portTickType xValueOfInsertion; |
kenjiArai | 0:d4960fcea8ff | 117 | |
kenjiArai | 0:d4960fcea8ff | 118 | /* Insert the new list item into the list, sorted in ulListItem order. */ |
kenjiArai | 0:d4960fcea8ff | 119 | xValueOfInsertion = pxNewListItem->xItemValue; |
kenjiArai | 0:d4960fcea8ff | 120 | |
kenjiArai | 0:d4960fcea8ff | 121 | /* If the list already contains a list item with the same item value then |
kenjiArai | 0:d4960fcea8ff | 122 | the new list item should be placed after it. This ensures that TCB's which |
kenjiArai | 0:d4960fcea8ff | 123 | are stored in ready lists (all of which have the same ulListItem value) |
kenjiArai | 0:d4960fcea8ff | 124 | get an equal share of the CPU. However, if the xItemValue is the same as |
kenjiArai | 0:d4960fcea8ff | 125 | the back marker the iteration loop below will not end. This means we need |
kenjiArai | 0:d4960fcea8ff | 126 | to guard against this by checking the value first and modifying the |
kenjiArai | 0:d4960fcea8ff | 127 | algorithm slightly if necessary. */ |
kenjiArai | 0:d4960fcea8ff | 128 | if( xValueOfInsertion == portMAX_DELAY ) |
kenjiArai | 0:d4960fcea8ff | 129 | { |
kenjiArai | 0:d4960fcea8ff | 130 | pxIterator = pxList->xListEnd.pxPrevious; |
kenjiArai | 0:d4960fcea8ff | 131 | } |
kenjiArai | 0:d4960fcea8ff | 132 | else |
kenjiArai | 0:d4960fcea8ff | 133 | { |
kenjiArai | 0:d4960fcea8ff | 134 | /* *** NOTE *********************************************************** |
kenjiArai | 0:d4960fcea8ff | 135 | If you find your application is crashing here then likely causes are: |
kenjiArai | 0:d4960fcea8ff | 136 | 1) Stack overflow - |
kenjiArai | 0:d4960fcea8ff | 137 | see http://www.freertos.org/Stacks-and-stack-overflow-checking.html |
kenjiArai | 0:d4960fcea8ff | 138 | 2) Incorrect interrupt priority assignment, especially on Cortex M3 |
kenjiArai | 0:d4960fcea8ff | 139 | parts where numerically high priority values denote low actual |
kenjiArai | 0:d4960fcea8ff | 140 | interrupt priories, which can seem counter intuitive. See |
kenjiArai | 0:d4960fcea8ff | 141 | configMAX_SYSCALL_INTERRUPT_PRIORITY on http://www.freertos.org/a00110.html |
kenjiArai | 0:d4960fcea8ff | 142 | 3) Calling an API function from within a critical section or when |
kenjiArai | 0:d4960fcea8ff | 143 | the scheduler is suspended. |
kenjiArai | 0:d4960fcea8ff | 144 | 4) Using a queue or semaphore before it has been initialised or |
kenjiArai | 0:d4960fcea8ff | 145 | before the scheduler has been started (are interrupts firing |
kenjiArai | 0:d4960fcea8ff | 146 | before vTaskStartScheduler() has been called?). |
kenjiArai | 0:d4960fcea8ff | 147 | See http://www.freertos.org/FAQHelp.html for more tips. |
kenjiArai | 0:d4960fcea8ff | 148 | **********************************************************************/ |
kenjiArai | 0:d4960fcea8ff | 149 | |
kenjiArai | 0:d4960fcea8ff | 150 | for( pxIterator = ( xListItem * ) &( pxList->xListEnd ); pxIterator->pxNext->xItemValue <= xValueOfInsertion; pxIterator = pxIterator->pxNext ) |
kenjiArai | 0:d4960fcea8ff | 151 | { |
kenjiArai | 0:d4960fcea8ff | 152 | /* There is nothing to do here, we are just iterating to the |
kenjiArai | 0:d4960fcea8ff | 153 | wanted insertion position. */ |
kenjiArai | 0:d4960fcea8ff | 154 | } |
kenjiArai | 0:d4960fcea8ff | 155 | } |
kenjiArai | 0:d4960fcea8ff | 156 | |
kenjiArai | 0:d4960fcea8ff | 157 | pxNewListItem->pxNext = pxIterator->pxNext; |
kenjiArai | 0:d4960fcea8ff | 158 | pxNewListItem->pxNext->pxPrevious = ( volatile xListItem * ) pxNewListItem; |
kenjiArai | 0:d4960fcea8ff | 159 | pxNewListItem->pxPrevious = pxIterator; |
kenjiArai | 0:d4960fcea8ff | 160 | pxIterator->pxNext = ( volatile xListItem * ) pxNewListItem; |
kenjiArai | 0:d4960fcea8ff | 161 | |
kenjiArai | 0:d4960fcea8ff | 162 | /* Remember which list the item is in. This allows fast removal of the |
kenjiArai | 0:d4960fcea8ff | 163 | item later. */ |
kenjiArai | 0:d4960fcea8ff | 164 | pxNewListItem->pvContainer = ( void * ) pxList; |
kenjiArai | 0:d4960fcea8ff | 165 | |
kenjiArai | 0:d4960fcea8ff | 166 | ( pxList->uxNumberOfItems )++; |
kenjiArai | 0:d4960fcea8ff | 167 | } |
kenjiArai | 0:d4960fcea8ff | 168 | /*-----------------------------------------------------------*/ |
kenjiArai | 0:d4960fcea8ff | 169 | |
kenjiArai | 0:d4960fcea8ff | 170 | void vListRemove( xListItem *pxItemToRemove ) |
kenjiArai | 0:d4960fcea8ff | 171 | { |
kenjiArai | 0:d4960fcea8ff | 172 | xList * pxList; |
kenjiArai | 0:d4960fcea8ff | 173 | |
kenjiArai | 0:d4960fcea8ff | 174 | pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious; |
kenjiArai | 0:d4960fcea8ff | 175 | pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext; |
kenjiArai | 0:d4960fcea8ff | 176 | |
kenjiArai | 0:d4960fcea8ff | 177 | /* The list item knows which list it is in. Obtain the list from the list |
kenjiArai | 0:d4960fcea8ff | 178 | item. */ |
kenjiArai | 0:d4960fcea8ff | 179 | pxList = ( xList * ) pxItemToRemove->pvContainer; |
kenjiArai | 0:d4960fcea8ff | 180 | |
kenjiArai | 0:d4960fcea8ff | 181 | /* Make sure the index is left pointing to a valid item. */ |
kenjiArai | 0:d4960fcea8ff | 182 | if( pxList->pxIndex == pxItemToRemove ) |
kenjiArai | 0:d4960fcea8ff | 183 | { |
kenjiArai | 0:d4960fcea8ff | 184 | pxList->pxIndex = pxItemToRemove->pxPrevious; |
kenjiArai | 0:d4960fcea8ff | 185 | } |
kenjiArai | 0:d4960fcea8ff | 186 | |
kenjiArai | 0:d4960fcea8ff | 187 | pxItemToRemove->pvContainer = NULL; |
kenjiArai | 0:d4960fcea8ff | 188 | ( pxList->uxNumberOfItems )--; |
kenjiArai | 0:d4960fcea8ff | 189 | } |
kenjiArai | 0:d4960fcea8ff | 190 | /*-----------------------------------------------------------*/ |
kenjiArai | 0:d4960fcea8ff | 191 |