Francisco Paez / freertos

Dependents:   frdm_k64f_freertos_lib

Committer:
fep
Date:
Wed May 31 02:27:10 2017 +0000
Revision:
0:62cd296ba2a7
FreeRTOS v9.0.0 for Cortex-M4F (FRDM-K64F and others...)

Who changed what in which revision?

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