Freertos for LPC CM3 tested on LPC1768

Committer:
dflet
Date:
Sat Jun 06 13:27:43 2015 +0000
Revision:
0:91ad48ad5687
Setup for LPC CM3 but may work with LPC CM4

Who changed what in which revision?

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