Francisco Paez / freertos-cm3

Dependents:   mbed_lpc1768_freertos_lib

Committer:
fep
Date:
Wed May 31 02:36:43 2017 +0000
Revision:
0:5ff20db10a96
FreeRTOS v9.0.0 for ARM Cortex-M3 based boards.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fep 0:5ff20db10a96 1 /*
fep 0:5ff20db10a96 2 FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
fep 0:5ff20db10a96 3 All rights reserved
fep 0:5ff20db10a96 4
fep 0:5ff20db10a96 5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
fep 0:5ff20db10a96 6
fep 0:5ff20db10a96 7 This file is part of the FreeRTOS distribution.
fep 0:5ff20db10a96 8
fep 0:5ff20db10a96 9 FreeRTOS is free software; you can redistribute it and/or modify it under
fep 0:5ff20db10a96 10 the terms of the GNU General Public License (version 2) as published by the
fep 0:5ff20db10a96 11 Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
fep 0:5ff20db10a96 12
fep 0:5ff20db10a96 13 ***************************************************************************
fep 0:5ff20db10a96 14 >>! NOTE: The modification to the GPL is included to allow you to !<<
fep 0:5ff20db10a96 15 >>! distribute a combined work that includes FreeRTOS without being !<<
fep 0:5ff20db10a96 16 >>! obliged to provide the source code for proprietary components !<<
fep 0:5ff20db10a96 17 >>! outside of the FreeRTOS kernel. !<<
fep 0:5ff20db10a96 18 ***************************************************************************
fep 0:5ff20db10a96 19
fep 0:5ff20db10a96 20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
fep 0:5ff20db10a96 21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
fep 0:5ff20db10a96 22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
fep 0:5ff20db10a96 23 link: http://www.freertos.org/a00114.html
fep 0:5ff20db10a96 24
fep 0:5ff20db10a96 25 ***************************************************************************
fep 0:5ff20db10a96 26 * *
fep 0:5ff20db10a96 27 * FreeRTOS provides completely free yet professionally developed, *
fep 0:5ff20db10a96 28 * robust, strictly quality controlled, supported, and cross *
fep 0:5ff20db10a96 29 * platform software that is more than just the market leader, it *
fep 0:5ff20db10a96 30 * is the industry's de facto standard. *
fep 0:5ff20db10a96 31 * *
fep 0:5ff20db10a96 32 * Help yourself get started quickly while simultaneously helping *
fep 0:5ff20db10a96 33 * to support the FreeRTOS project by purchasing a FreeRTOS *
fep 0:5ff20db10a96 34 * tutorial book, reference manual, or both: *
fep 0:5ff20db10a96 35 * http://www.FreeRTOS.org/Documentation *
fep 0:5ff20db10a96 36 * *
fep 0:5ff20db10a96 37 ***************************************************************************
fep 0:5ff20db10a96 38
fep 0:5ff20db10a96 39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
fep 0:5ff20db10a96 40 the FAQ page "My application does not run, what could be wrong?". Have you
fep 0:5ff20db10a96 41 defined configASSERT()?
fep 0:5ff20db10a96 42
fep 0:5ff20db10a96 43 http://www.FreeRTOS.org/support - In return for receiving this top quality
fep 0:5ff20db10a96 44 embedded software for free we request you assist our global community by
fep 0:5ff20db10a96 45 participating in the support forum.
fep 0:5ff20db10a96 46
fep 0:5ff20db10a96 47 http://www.FreeRTOS.org/training - Investing in training allows your team to
fep 0:5ff20db10a96 48 be as productive as possible as early as possible. Now you can receive
fep 0:5ff20db10a96 49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
fep 0:5ff20db10a96 50 Ltd, and the world's leading authority on the world's leading RTOS.
fep 0:5ff20db10a96 51
fep 0:5ff20db10a96 52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
fep 0:5ff20db10a96 53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
fep 0:5ff20db10a96 54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
fep 0:5ff20db10a96 55
fep 0:5ff20db10a96 56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
fep 0:5ff20db10a96 57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
fep 0:5ff20db10a96 58
fep 0:5ff20db10a96 59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
fep 0:5ff20db10a96 60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
fep 0:5ff20db10a96 61 licenses offer ticketed support, indemnification and commercial middleware.
fep 0:5ff20db10a96 62
fep 0:5ff20db10a96 63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
fep 0:5ff20db10a96 64 engineered and independently SIL3 certified version for use in safety and
fep 0:5ff20db10a96 65 mission critical applications that require provable dependability.
fep 0:5ff20db10a96 66
fep 0:5ff20db10a96 67 1 tab == 4 spaces!
fep 0:5ff20db10a96 68 */
fep 0:5ff20db10a96 69
fep 0:5ff20db10a96 70
fep 0:5ff20db10a96 71 #include <stdlib.h>
fep 0:5ff20db10a96 72 #include "FreeRTOS.h"
fep 0:5ff20db10a96 73 #include "list.h"
fep 0:5ff20db10a96 74
fep 0:5ff20db10a96 75 /*-----------------------------------------------------------
fep 0:5ff20db10a96 76 * PUBLIC LIST API documented in list.h
fep 0:5ff20db10a96 77 *----------------------------------------------------------*/
fep 0:5ff20db10a96 78
fep 0:5ff20db10a96 79 void vListInitialise( List_t * const pxList )
fep 0:5ff20db10a96 80 {
fep 0:5ff20db10a96 81 /* The list structure contains a list item which is used to mark the
fep 0:5ff20db10a96 82 end of the list. To initialise the list the list end is inserted
fep 0:5ff20db10a96 83 as the only list entry. */
fep 0:5ff20db10a96 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. */
fep 0:5ff20db10a96 85
fep 0:5ff20db10a96 86 /* The list end value is the highest possible value in the list to
fep 0:5ff20db10a96 87 ensure it remains at the end of the list. */
fep 0:5ff20db10a96 88 pxList->xListEnd.xItemValue = portMAX_DELAY;
fep 0:5ff20db10a96 89
fep 0:5ff20db10a96 90 /* The list end next and previous pointers point to itself so we know
fep 0:5ff20db10a96 91 when the list is empty. */
fep 0:5ff20db10a96 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. */
fep 0:5ff20db10a96 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. */
fep 0:5ff20db10a96 94
fep 0:5ff20db10a96 95 pxList->uxNumberOfItems = ( UBaseType_t ) 0U;
fep 0:5ff20db10a96 96
fep 0:5ff20db10a96 97 /* Write known values into the list if
fep 0:5ff20db10a96 98 configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
fep 0:5ff20db10a96 99 listSET_LIST_INTEGRITY_CHECK_1_VALUE( pxList );
fep 0:5ff20db10a96 100 listSET_LIST_INTEGRITY_CHECK_2_VALUE( pxList );
fep 0:5ff20db10a96 101 }
fep 0:5ff20db10a96 102 /*-----------------------------------------------------------*/
fep 0:5ff20db10a96 103
fep 0:5ff20db10a96 104 void vListInitialiseItem( ListItem_t * const pxItem )
fep 0:5ff20db10a96 105 {
fep 0:5ff20db10a96 106 /* Make sure the list item is not recorded as being on a list. */
fep 0:5ff20db10a96 107 pxItem->pvContainer = NULL;
fep 0:5ff20db10a96 108
fep 0:5ff20db10a96 109 /* Write known values into the list item if
fep 0:5ff20db10a96 110 configUSE_LIST_DATA_INTEGRITY_CHECK_BYTES is set to 1. */
fep 0:5ff20db10a96 111 listSET_FIRST_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem );
fep 0:5ff20db10a96 112 listSET_SECOND_LIST_ITEM_INTEGRITY_CHECK_VALUE( pxItem );
fep 0:5ff20db10a96 113 }
fep 0:5ff20db10a96 114 /*-----------------------------------------------------------*/
fep 0:5ff20db10a96 115
fep 0:5ff20db10a96 116 void vListInsertEnd( List_t * const pxList, ListItem_t * const pxNewListItem )
fep 0:5ff20db10a96 117 {
fep 0:5ff20db10a96 118 ListItem_t * const pxIndex = pxList->pxIndex;
fep 0:5ff20db10a96 119
fep 0:5ff20db10a96 120 /* Only effective when configASSERT() is also defined, these tests may catch
fep 0:5ff20db10a96 121 the list data structures being overwritten in memory. They will not catch
fep 0:5ff20db10a96 122 data errors caused by incorrect configuration or use of FreeRTOS. */
fep 0:5ff20db10a96 123 listTEST_LIST_INTEGRITY( pxList );
fep 0:5ff20db10a96 124 listTEST_LIST_ITEM_INTEGRITY( pxNewListItem );
fep 0:5ff20db10a96 125
fep 0:5ff20db10a96 126 /* Insert a new list item into pxList, but rather than sort the list,
fep 0:5ff20db10a96 127 makes the new list item the last item to be removed by a call to
fep 0:5ff20db10a96 128 listGET_OWNER_OF_NEXT_ENTRY(). */
fep 0:5ff20db10a96 129 pxNewListItem->pxNext = pxIndex;
fep 0:5ff20db10a96 130 pxNewListItem->pxPrevious = pxIndex->pxPrevious;
fep 0:5ff20db10a96 131
fep 0:5ff20db10a96 132 /* Only used during decision coverage testing. */
fep 0:5ff20db10a96 133 mtCOVERAGE_TEST_DELAY();
fep 0:5ff20db10a96 134
fep 0:5ff20db10a96 135 pxIndex->pxPrevious->pxNext = pxNewListItem;
fep 0:5ff20db10a96 136 pxIndex->pxPrevious = pxNewListItem;
fep 0:5ff20db10a96 137
fep 0:5ff20db10a96 138 /* Remember which list the item is in. */
fep 0:5ff20db10a96 139 pxNewListItem->pvContainer = ( void * ) pxList;
fep 0:5ff20db10a96 140
fep 0:5ff20db10a96 141 ( pxList->uxNumberOfItems )++;
fep 0:5ff20db10a96 142 }
fep 0:5ff20db10a96 143 /*-----------------------------------------------------------*/
fep 0:5ff20db10a96 144
fep 0:5ff20db10a96 145 void vListInsert( List_t * const pxList, ListItem_t * const pxNewListItem )
fep 0:5ff20db10a96 146 {
fep 0:5ff20db10a96 147 ListItem_t *pxIterator;
fep 0:5ff20db10a96 148 const TickType_t xValueOfInsertion = pxNewListItem->xItemValue;
fep 0:5ff20db10a96 149
fep 0:5ff20db10a96 150 /* Only effective when configASSERT() is also defined, these tests may catch
fep 0:5ff20db10a96 151 the list data structures being overwritten in memory. They will not catch
fep 0:5ff20db10a96 152 data errors caused by incorrect configuration or use of FreeRTOS. */
fep 0:5ff20db10a96 153 listTEST_LIST_INTEGRITY( pxList );
fep 0:5ff20db10a96 154 listTEST_LIST_ITEM_INTEGRITY( pxNewListItem );
fep 0:5ff20db10a96 155
fep 0:5ff20db10a96 156 /* Insert the new list item into the list, sorted in xItemValue order.
fep 0:5ff20db10a96 157
fep 0:5ff20db10a96 158 If the list already contains a list item with the same item value then the
fep 0:5ff20db10a96 159 new list item should be placed after it. This ensures that TCB's which are
fep 0:5ff20db10a96 160 stored in ready lists (all of which have the same xItemValue value) get a
fep 0:5ff20db10a96 161 share of the CPU. However, if the xItemValue is the same as the back marker
fep 0:5ff20db10a96 162 the iteration loop below will not end. Therefore the value is checked
fep 0:5ff20db10a96 163 first, and the algorithm slightly modified if necessary. */
fep 0:5ff20db10a96 164 if( xValueOfInsertion == portMAX_DELAY )
fep 0:5ff20db10a96 165 {
fep 0:5ff20db10a96 166 pxIterator = pxList->xListEnd.pxPrevious;
fep 0:5ff20db10a96 167 }
fep 0:5ff20db10a96 168 else
fep 0:5ff20db10a96 169 {
fep 0:5ff20db10a96 170 /* *** NOTE ***********************************************************
fep 0:5ff20db10a96 171 If you find your application is crashing here then likely causes are
fep 0:5ff20db10a96 172 listed below. In addition see http://www.freertos.org/FAQHelp.html for
fep 0:5ff20db10a96 173 more tips, and ensure configASSERT() is defined!
fep 0:5ff20db10a96 174 http://www.freertos.org/a00110.html#configASSERT
fep 0:5ff20db10a96 175
fep 0:5ff20db10a96 176 1) Stack overflow -
fep 0:5ff20db10a96 177 see http://www.freertos.org/Stacks-and-stack-overflow-checking.html
fep 0:5ff20db10a96 178 2) Incorrect interrupt priority assignment, especially on Cortex-M
fep 0:5ff20db10a96 179 parts where numerically high priority values denote low actual
fep 0:5ff20db10a96 180 interrupt priorities, which can seem counter intuitive. See
fep 0:5ff20db10a96 181 http://www.freertos.org/RTOS-Cortex-M3-M4.html and the definition
fep 0:5ff20db10a96 182 of configMAX_SYSCALL_INTERRUPT_PRIORITY on
fep 0:5ff20db10a96 183 http://www.freertos.org/a00110.html
fep 0:5ff20db10a96 184 3) Calling an API function from within a critical section or when
fep 0:5ff20db10a96 185 the scheduler is suspended, or calling an API function that does
fep 0:5ff20db10a96 186 not end in "FromISR" from an interrupt.
fep 0:5ff20db10a96 187 4) Using a queue or semaphore before it has been initialised or
fep 0:5ff20db10a96 188 before the scheduler has been started (are interrupts firing
fep 0:5ff20db10a96 189 before vTaskStartScheduler() has been called?).
fep 0:5ff20db10a96 190 **********************************************************************/
fep 0:5ff20db10a96 191
fep 0:5ff20db10a96 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. */
fep 0:5ff20db10a96 193 {
fep 0:5ff20db10a96 194 /* There is nothing to do here, just iterating to the wanted
fep 0:5ff20db10a96 195 insertion position. */
fep 0:5ff20db10a96 196 }
fep 0:5ff20db10a96 197 }
fep 0:5ff20db10a96 198
fep 0:5ff20db10a96 199 pxNewListItem->pxNext = pxIterator->pxNext;
fep 0:5ff20db10a96 200 pxNewListItem->pxNext->pxPrevious = pxNewListItem;
fep 0:5ff20db10a96 201 pxNewListItem->pxPrevious = pxIterator;
fep 0:5ff20db10a96 202 pxIterator->pxNext = pxNewListItem;
fep 0:5ff20db10a96 203
fep 0:5ff20db10a96 204 /* Remember which list the item is in. This allows fast removal of the
fep 0:5ff20db10a96 205 item later. */
fep 0:5ff20db10a96 206 pxNewListItem->pvContainer = ( void * ) pxList;
fep 0:5ff20db10a96 207
fep 0:5ff20db10a96 208 ( pxList->uxNumberOfItems )++;
fep 0:5ff20db10a96 209 }
fep 0:5ff20db10a96 210 /*-----------------------------------------------------------*/
fep 0:5ff20db10a96 211
fep 0:5ff20db10a96 212 UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove )
fep 0:5ff20db10a96 213 {
fep 0:5ff20db10a96 214 /* The list item knows which list it is in. Obtain the list from the list
fep 0:5ff20db10a96 215 item. */
fep 0:5ff20db10a96 216 List_t * const pxList = ( List_t * ) pxItemToRemove->pvContainer;
fep 0:5ff20db10a96 217
fep 0:5ff20db10a96 218 pxItemToRemove->pxNext->pxPrevious = pxItemToRemove->pxPrevious;
fep 0:5ff20db10a96 219 pxItemToRemove->pxPrevious->pxNext = pxItemToRemove->pxNext;
fep 0:5ff20db10a96 220
fep 0:5ff20db10a96 221 /* Only used during decision coverage testing. */
fep 0:5ff20db10a96 222 mtCOVERAGE_TEST_DELAY();
fep 0:5ff20db10a96 223
fep 0:5ff20db10a96 224 /* Make sure the index is left pointing to a valid item. */
fep 0:5ff20db10a96 225 if( pxList->pxIndex == pxItemToRemove )
fep 0:5ff20db10a96 226 {
fep 0:5ff20db10a96 227 pxList->pxIndex = pxItemToRemove->pxPrevious;
fep 0:5ff20db10a96 228 }
fep 0:5ff20db10a96 229 else
fep 0:5ff20db10a96 230 {
fep 0:5ff20db10a96 231 mtCOVERAGE_TEST_MARKER();
fep 0:5ff20db10a96 232 }
fep 0:5ff20db10a96 233
fep 0:5ff20db10a96 234 pxItemToRemove->pvContainer = NULL;
fep 0:5ff20db10a96 235 ( pxList->uxNumberOfItems )--;
fep 0:5ff20db10a96 236
fep 0:5ff20db10a96 237 return pxList->uxNumberOfItems;
fep 0:5ff20db10a96 238 }
fep 0:5ff20db10a96 239 /*-----------------------------------------------------------*/
fep 0:5ff20db10a96 240
fep 0:5ff20db10a96 241