Update revision to use TI's mqtt and Freertos.

Dependencies:   mbed client server

Fork of cc3100_Test_mqtt_CM3 by David Fletcher

Committer:
dflet
Date:
Thu Sep 03 14:02:37 2015 +0000
Revision:
3:a8c249046181
SPI Mode change 1 to 0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dflet 3:a8c249046181 1 /*
dflet 3:a8c249046181 2 FreeRTOS V8.2.1 - Copyright (C) 2015 Real Time Engineers Ltd.
dflet 3:a8c249046181 3 All rights reserved
dflet 3:a8c249046181 4
dflet 3:a8c249046181 5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
dflet 3:a8c249046181 6
dflet 3:a8c249046181 7 This file is part of the FreeRTOS distribution.
dflet 3:a8c249046181 8
dflet 3:a8c249046181 9 FreeRTOS is free software; you can redistribute it and/or modify it under
dflet 3:a8c249046181 10 the terms of the GNU General Public License (version 2) as published by the
dflet 3:a8c249046181 11 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
dflet 3:a8c249046181 12
dflet 3:a8c249046181 13 ***************************************************************************
dflet 3:a8c249046181 14 >>! NOTE: The modification to the GPL is included to allow you to !<<
dflet 3:a8c249046181 15 >>! distribute a combined work that includes FreeRTOS without being !<<
dflet 3:a8c249046181 16 >>! obliged to provide the source code for proprietary components !<<
dflet 3:a8c249046181 17 >>! outside of the FreeRTOS kernel. !<<
dflet 3:a8c249046181 18 ***************************************************************************
dflet 3:a8c249046181 19
dflet 3:a8c249046181 20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
dflet 3:a8c249046181 21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
dflet 3:a8c249046181 22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
dflet 3:a8c249046181 23 link: http://www.freertos.org/a00114.html
dflet 3:a8c249046181 24
dflet 3:a8c249046181 25 ***************************************************************************
dflet 3:a8c249046181 26 * *
dflet 3:a8c249046181 27 * FreeRTOS provides completely free yet professionally developed, *
dflet 3:a8c249046181 28 * robust, strictly quality controlled, supported, and cross *
dflet 3:a8c249046181 29 * platform software that is more than just the market leader, it *
dflet 3:a8c249046181 30 * is the industry's de facto standard. *
dflet 3:a8c249046181 31 * *
dflet 3:a8c249046181 32 * Help yourself get started quickly while simultaneously helping *
dflet 3:a8c249046181 33 * to support the FreeRTOS project by purchasing a FreeRTOS *
dflet 3:a8c249046181 34 * tutorial book, reference manual, or both: *
dflet 3:a8c249046181 35 * http://www.FreeRTOS.org/Documentation *
dflet 3:a8c249046181 36 * *
dflet 3:a8c249046181 37 ***************************************************************************
dflet 3:a8c249046181 38
dflet 3:a8c249046181 39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
dflet 3:a8c249046181 40 the FAQ page "My application does not run, what could be wrong?". Have you
dflet 3:a8c249046181 41 defined configASSERT()?
dflet 3:a8c249046181 42
dflet 3:a8c249046181 43 http://www.FreeRTOS.org/support - In return for receiving this top quality
dflet 3:a8c249046181 44 embedded software for free we request you assist our global community by
dflet 3:a8c249046181 45 participating in the support forum.
dflet 3:a8c249046181 46
dflet 3:a8c249046181 47 http://www.FreeRTOS.org/training - Investing in training allows your team to
dflet 3:a8c249046181 48 be as productive as possible as early as possible. Now you can receive
dflet 3:a8c249046181 49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
dflet 3:a8c249046181 50 Ltd, and the world's leading authority on the world's leading RTOS.
dflet 3:a8c249046181 51
dflet 3:a8c249046181 52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
dflet 3:a8c249046181 53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
dflet 3:a8c249046181 54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
dflet 3:a8c249046181 55
dflet 3:a8c249046181 56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
dflet 3:a8c249046181 57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
dflet 3:a8c249046181 58
dflet 3:a8c249046181 59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
dflet 3:a8c249046181 60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
dflet 3:a8c249046181 61 licenses offer ticketed support, indemnification and commercial middleware.
dflet 3:a8c249046181 62
dflet 3:a8c249046181 63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
dflet 3:a8c249046181 64 engineered and independently SIL3 certified version for use in safety and
dflet 3:a8c249046181 65 mission critical applications that require provable dependability.
dflet 3:a8c249046181 66
dflet 3:a8c249046181 67 1 tab == 4 spaces!
dflet 3:a8c249046181 68 */
dflet 3:a8c249046181 69
dflet 3:a8c249046181 70 #include "FreeRTOS.h"
dflet 3:a8c249046181 71 #include "task.h"
dflet 3:a8c249046181 72 #include "croutine.h"
dflet 3:a8c249046181 73
dflet 3:a8c249046181 74 /* Remove the whole file is co-routines are not being used. */
dflet 3:a8c249046181 75 #if( configUSE_CO_ROUTINES != 0 )
dflet 3:a8c249046181 76
dflet 3:a8c249046181 77 /*
dflet 3:a8c249046181 78 * Some kernel aware debuggers require data to be viewed to be global, rather
dflet 3:a8c249046181 79 * than file scope.
dflet 3:a8c249046181 80 */
dflet 3:a8c249046181 81 #ifdef portREMOVE_STATIC_QUALIFIER
dflet 3:a8c249046181 82 #define static
dflet 3:a8c249046181 83 #endif
dflet 3:a8c249046181 84
dflet 3:a8c249046181 85
dflet 3:a8c249046181 86 /* Lists for ready and blocked co-routines. --------------------*/
dflet 3:a8c249046181 87 static List_t pxReadyCoRoutineLists[ configMAX_CO_ROUTINE_PRIORITIES ]; /*< Prioritised ready co-routines. */
dflet 3:a8c249046181 88 static List_t xDelayedCoRoutineList1; /*< Delayed co-routines. */
dflet 3:a8c249046181 89 static List_t xDelayedCoRoutineList2; /*< Delayed co-routines (two lists are used - one for delays that have overflowed the current tick count. */
dflet 3:a8c249046181 90 static List_t * pxDelayedCoRoutineList; /*< Points to the delayed co-routine list currently being used. */
dflet 3:a8c249046181 91 static List_t * pxOverflowDelayedCoRoutineList; /*< Points to the delayed co-routine list currently being used to hold co-routines that have overflowed the current tick count. */
dflet 3:a8c249046181 92 static List_t xPendingReadyCoRoutineList; /*< Holds co-routines that have been readied by an external event. They cannot be added directly to the ready lists as the ready lists cannot be accessed by interrupts. */
dflet 3:a8c249046181 93
dflet 3:a8c249046181 94 /* Other file private variables. --------------------------------*/
dflet 3:a8c249046181 95 CRCB_t * pxCurrentCoRoutine = NULL;
dflet 3:a8c249046181 96 static UBaseType_t uxTopCoRoutineReadyPriority = 0;
dflet 3:a8c249046181 97 static TickType_t xCoRoutineTickCount = 0, xLastTickCount = 0, xPassedTicks = 0;
dflet 3:a8c249046181 98
dflet 3:a8c249046181 99 /* The initial state of the co-routine when it is created. */
dflet 3:a8c249046181 100 #define corINITIAL_STATE ( 0 )
dflet 3:a8c249046181 101
dflet 3:a8c249046181 102 /*
dflet 3:a8c249046181 103 * Place the co-routine represented by pxCRCB into the appropriate ready queue
dflet 3:a8c249046181 104 * for the priority. It is inserted at the end of the list.
dflet 3:a8c249046181 105 *
dflet 3:a8c249046181 106 * This macro accesses the co-routine ready lists and therefore must not be
dflet 3:a8c249046181 107 * used from within an ISR.
dflet 3:a8c249046181 108 */
dflet 3:a8c249046181 109 #define prvAddCoRoutineToReadyQueue( pxCRCB ) \
dflet 3:a8c249046181 110 { \
dflet 3:a8c249046181 111 if( pxCRCB->uxPriority > uxTopCoRoutineReadyPriority ) \
dflet 3:a8c249046181 112 { \
dflet 3:a8c249046181 113 uxTopCoRoutineReadyPriority = pxCRCB->uxPriority; \
dflet 3:a8c249046181 114 } \
dflet 3:a8c249046181 115 vListInsertEnd( ( List_t * ) &( pxReadyCoRoutineLists[ pxCRCB->uxPriority ] ), &( pxCRCB->xGenericListItem ) ); \
dflet 3:a8c249046181 116 }
dflet 3:a8c249046181 117
dflet 3:a8c249046181 118 /*
dflet 3:a8c249046181 119 * Utility to ready all the lists used by the scheduler. This is called
dflet 3:a8c249046181 120 * automatically upon the creation of the first co-routine.
dflet 3:a8c249046181 121 */
dflet 3:a8c249046181 122 static void prvInitialiseCoRoutineLists( void );
dflet 3:a8c249046181 123
dflet 3:a8c249046181 124 /*
dflet 3:a8c249046181 125 * Co-routines that are readied by an interrupt cannot be placed directly into
dflet 3:a8c249046181 126 * the ready lists (there is no mutual exclusion). Instead they are placed in
dflet 3:a8c249046181 127 * in the pending ready list in order that they can later be moved to the ready
dflet 3:a8c249046181 128 * list by the co-routine scheduler.
dflet 3:a8c249046181 129 */
dflet 3:a8c249046181 130 static void prvCheckPendingReadyList( void );
dflet 3:a8c249046181 131
dflet 3:a8c249046181 132 /*
dflet 3:a8c249046181 133 * Macro that looks at the list of co-routines that are currently delayed to
dflet 3:a8c249046181 134 * see if any require waking.
dflet 3:a8c249046181 135 *
dflet 3:a8c249046181 136 * Co-routines are stored in the queue in the order of their wake time -
dflet 3:a8c249046181 137 * meaning once one co-routine has been found whose timer has not expired
dflet 3:a8c249046181 138 * we need not look any further down the list.
dflet 3:a8c249046181 139 */
dflet 3:a8c249046181 140 static void prvCheckDelayedList( void );
dflet 3:a8c249046181 141
dflet 3:a8c249046181 142 /*-----------------------------------------------------------*/
dflet 3:a8c249046181 143
dflet 3:a8c249046181 144 BaseType_t xCoRoutineCreate( crCOROUTINE_CODE pxCoRoutineCode, UBaseType_t uxPriority, UBaseType_t uxIndex )
dflet 3:a8c249046181 145 {
dflet 3:a8c249046181 146 BaseType_t xReturn;
dflet 3:a8c249046181 147 CRCB_t *pxCoRoutine;
dflet 3:a8c249046181 148
dflet 3:a8c249046181 149 /* Allocate the memory that will store the co-routine control block. */
dflet 3:a8c249046181 150 pxCoRoutine = ( CRCB_t * ) pvPortMalloc( sizeof( CRCB_t ) );
dflet 3:a8c249046181 151 if( pxCoRoutine )
dflet 3:a8c249046181 152 {
dflet 3:a8c249046181 153 /* If pxCurrentCoRoutine is NULL then this is the first co-routine to
dflet 3:a8c249046181 154 be created and the co-routine data structures need initialising. */
dflet 3:a8c249046181 155 if( pxCurrentCoRoutine == NULL )
dflet 3:a8c249046181 156 {
dflet 3:a8c249046181 157 pxCurrentCoRoutine = pxCoRoutine;
dflet 3:a8c249046181 158 prvInitialiseCoRoutineLists();
dflet 3:a8c249046181 159 }
dflet 3:a8c249046181 160
dflet 3:a8c249046181 161 /* Check the priority is within limits. */
dflet 3:a8c249046181 162 if( uxPriority >= configMAX_CO_ROUTINE_PRIORITIES )
dflet 3:a8c249046181 163 {
dflet 3:a8c249046181 164 uxPriority = configMAX_CO_ROUTINE_PRIORITIES - 1;
dflet 3:a8c249046181 165 }
dflet 3:a8c249046181 166
dflet 3:a8c249046181 167 /* Fill out the co-routine control block from the function parameters. */
dflet 3:a8c249046181 168 pxCoRoutine->uxState = corINITIAL_STATE;
dflet 3:a8c249046181 169 pxCoRoutine->uxPriority = uxPriority;
dflet 3:a8c249046181 170 pxCoRoutine->uxIndex = uxIndex;
dflet 3:a8c249046181 171 pxCoRoutine->pxCoRoutineFunction = pxCoRoutineCode;
dflet 3:a8c249046181 172
dflet 3:a8c249046181 173 /* Initialise all the other co-routine control block parameters. */
dflet 3:a8c249046181 174 vListInitialiseItem( &( pxCoRoutine->xGenericListItem ) );
dflet 3:a8c249046181 175 vListInitialiseItem( &( pxCoRoutine->xEventListItem ) );
dflet 3:a8c249046181 176
dflet 3:a8c249046181 177 /* Set the co-routine control block as a link back from the ListItem_t.
dflet 3:a8c249046181 178 This is so we can get back to the containing CRCB from a generic item
dflet 3:a8c249046181 179 in a list. */
dflet 3:a8c249046181 180 listSET_LIST_ITEM_OWNER( &( pxCoRoutine->xGenericListItem ), pxCoRoutine );
dflet 3:a8c249046181 181 listSET_LIST_ITEM_OWNER( &( pxCoRoutine->xEventListItem ), pxCoRoutine );
dflet 3:a8c249046181 182
dflet 3:a8c249046181 183 /* Event lists are always in priority order. */
dflet 3:a8c249046181 184 listSET_LIST_ITEM_VALUE( &( pxCoRoutine->xEventListItem ), ( ( TickType_t ) configMAX_CO_ROUTINE_PRIORITIES - ( TickType_t ) uxPriority ) );
dflet 3:a8c249046181 185
dflet 3:a8c249046181 186 /* Now the co-routine has been initialised it can be added to the ready
dflet 3:a8c249046181 187 list at the correct priority. */
dflet 3:a8c249046181 188 prvAddCoRoutineToReadyQueue( pxCoRoutine );
dflet 3:a8c249046181 189
dflet 3:a8c249046181 190 xReturn = pdPASS;
dflet 3:a8c249046181 191 }
dflet 3:a8c249046181 192 else
dflet 3:a8c249046181 193 {
dflet 3:a8c249046181 194 xReturn = errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY;
dflet 3:a8c249046181 195 }
dflet 3:a8c249046181 196
dflet 3:a8c249046181 197 return xReturn;
dflet 3:a8c249046181 198 }
dflet 3:a8c249046181 199 /*-----------------------------------------------------------*/
dflet 3:a8c249046181 200
dflet 3:a8c249046181 201 void vCoRoutineAddToDelayedList( TickType_t xTicksToDelay, List_t *pxEventList )
dflet 3:a8c249046181 202 {
dflet 3:a8c249046181 203 TickType_t xTimeToWake;
dflet 3:a8c249046181 204
dflet 3:a8c249046181 205 /* Calculate the time to wake - this may overflow but this is
dflet 3:a8c249046181 206 not a problem. */
dflet 3:a8c249046181 207 xTimeToWake = xCoRoutineTickCount + xTicksToDelay;
dflet 3:a8c249046181 208
dflet 3:a8c249046181 209 /* We must remove ourselves from the ready list before adding
dflet 3:a8c249046181 210 ourselves to the blocked list as the same list item is used for
dflet 3:a8c249046181 211 both lists. */
dflet 3:a8c249046181 212 ( void ) uxListRemove( ( ListItem_t * ) &( pxCurrentCoRoutine->xGenericListItem ) );
dflet 3:a8c249046181 213
dflet 3:a8c249046181 214 /* The list item will be inserted in wake time order. */
dflet 3:a8c249046181 215 listSET_LIST_ITEM_VALUE( &( pxCurrentCoRoutine->xGenericListItem ), xTimeToWake );
dflet 3:a8c249046181 216
dflet 3:a8c249046181 217 if( xTimeToWake < xCoRoutineTickCount )
dflet 3:a8c249046181 218 {
dflet 3:a8c249046181 219 /* Wake time has overflowed. Place this item in the
dflet 3:a8c249046181 220 overflow list. */
dflet 3:a8c249046181 221 vListInsert( ( List_t * ) pxOverflowDelayedCoRoutineList, ( ListItem_t * ) &( pxCurrentCoRoutine->xGenericListItem ) );
dflet 3:a8c249046181 222 }
dflet 3:a8c249046181 223 else
dflet 3:a8c249046181 224 {
dflet 3:a8c249046181 225 /* The wake time has not overflowed, so we can use the
dflet 3:a8c249046181 226 current block list. */
dflet 3:a8c249046181 227 vListInsert( ( List_t * ) pxDelayedCoRoutineList, ( ListItem_t * ) &( pxCurrentCoRoutine->xGenericListItem ) );
dflet 3:a8c249046181 228 }
dflet 3:a8c249046181 229
dflet 3:a8c249046181 230 if( pxEventList )
dflet 3:a8c249046181 231 {
dflet 3:a8c249046181 232 /* Also add the co-routine to an event list. If this is done then the
dflet 3:a8c249046181 233 function must be called with interrupts disabled. */
dflet 3:a8c249046181 234 vListInsert( pxEventList, &( pxCurrentCoRoutine->xEventListItem ) );
dflet 3:a8c249046181 235 }
dflet 3:a8c249046181 236 }
dflet 3:a8c249046181 237 /*-----------------------------------------------------------*/
dflet 3:a8c249046181 238
dflet 3:a8c249046181 239 static void prvCheckPendingReadyList( void )
dflet 3:a8c249046181 240 {
dflet 3:a8c249046181 241 /* Are there any co-routines waiting to get moved to the ready list? These
dflet 3:a8c249046181 242 are co-routines that have been readied by an ISR. The ISR cannot access
dflet 3:a8c249046181 243 the ready lists itself. */
dflet 3:a8c249046181 244 while( listLIST_IS_EMPTY( &xPendingReadyCoRoutineList ) == pdFALSE )
dflet 3:a8c249046181 245 {
dflet 3:a8c249046181 246 CRCB_t *pxUnblockedCRCB;
dflet 3:a8c249046181 247
dflet 3:a8c249046181 248 /* The pending ready list can be accessed by an ISR. */
dflet 3:a8c249046181 249 portDISABLE_INTERRUPTS();
dflet 3:a8c249046181 250 {
dflet 3:a8c249046181 251 pxUnblockedCRCB = ( CRCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( (&xPendingReadyCoRoutineList) );
dflet 3:a8c249046181 252 ( void ) uxListRemove( &( pxUnblockedCRCB->xEventListItem ) );
dflet 3:a8c249046181 253 }
dflet 3:a8c249046181 254 portENABLE_INTERRUPTS();
dflet 3:a8c249046181 255
dflet 3:a8c249046181 256 ( void ) uxListRemove( &( pxUnblockedCRCB->xGenericListItem ) );
dflet 3:a8c249046181 257 prvAddCoRoutineToReadyQueue( pxUnblockedCRCB );
dflet 3:a8c249046181 258 }
dflet 3:a8c249046181 259 }
dflet 3:a8c249046181 260 /*-----------------------------------------------------------*/
dflet 3:a8c249046181 261
dflet 3:a8c249046181 262 static void prvCheckDelayedList( void )
dflet 3:a8c249046181 263 {
dflet 3:a8c249046181 264 CRCB_t *pxCRCB;
dflet 3:a8c249046181 265
dflet 3:a8c249046181 266 xPassedTicks = xTaskGetTickCount() - xLastTickCount;
dflet 3:a8c249046181 267 while( xPassedTicks )
dflet 3:a8c249046181 268 {
dflet 3:a8c249046181 269 xCoRoutineTickCount++;
dflet 3:a8c249046181 270 xPassedTicks--;
dflet 3:a8c249046181 271
dflet 3:a8c249046181 272 /* If the tick count has overflowed we need to swap the ready lists. */
dflet 3:a8c249046181 273 if( xCoRoutineTickCount == 0 )
dflet 3:a8c249046181 274 {
dflet 3:a8c249046181 275 List_t * pxTemp;
dflet 3:a8c249046181 276
dflet 3:a8c249046181 277 /* Tick count has overflowed so we need to swap the delay lists. If there are
dflet 3:a8c249046181 278 any items in pxDelayedCoRoutineList here then there is an error! */
dflet 3:a8c249046181 279 pxTemp = pxDelayedCoRoutineList;
dflet 3:a8c249046181 280 pxDelayedCoRoutineList = pxOverflowDelayedCoRoutineList;
dflet 3:a8c249046181 281 pxOverflowDelayedCoRoutineList = pxTemp;
dflet 3:a8c249046181 282 }
dflet 3:a8c249046181 283
dflet 3:a8c249046181 284 /* See if this tick has made a timeout expire. */
dflet 3:a8c249046181 285 while( listLIST_IS_EMPTY( pxDelayedCoRoutineList ) == pdFALSE )
dflet 3:a8c249046181 286 {
dflet 3:a8c249046181 287 pxCRCB = ( CRCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxDelayedCoRoutineList );
dflet 3:a8c249046181 288
dflet 3:a8c249046181 289 if( xCoRoutineTickCount < listGET_LIST_ITEM_VALUE( &( pxCRCB->xGenericListItem ) ) )
dflet 3:a8c249046181 290 {
dflet 3:a8c249046181 291 /* Timeout not yet expired. */
dflet 3:a8c249046181 292 break;
dflet 3:a8c249046181 293 }
dflet 3:a8c249046181 294
dflet 3:a8c249046181 295 portDISABLE_INTERRUPTS();
dflet 3:a8c249046181 296 {
dflet 3:a8c249046181 297 /* The event could have occurred just before this critical
dflet 3:a8c249046181 298 section. If this is the case then the generic list item will
dflet 3:a8c249046181 299 have been moved to the pending ready list and the following
dflet 3:a8c249046181 300 line is still valid. Also the pvContainer parameter will have
dflet 3:a8c249046181 301 been set to NULL so the following lines are also valid. */
dflet 3:a8c249046181 302 ( void ) uxListRemove( &( pxCRCB->xGenericListItem ) );
dflet 3:a8c249046181 303
dflet 3:a8c249046181 304 /* Is the co-routine waiting on an event also? */
dflet 3:a8c249046181 305 if( pxCRCB->xEventListItem.pvContainer )
dflet 3:a8c249046181 306 {
dflet 3:a8c249046181 307 ( void ) uxListRemove( &( pxCRCB->xEventListItem ) );
dflet 3:a8c249046181 308 }
dflet 3:a8c249046181 309 }
dflet 3:a8c249046181 310 portENABLE_INTERRUPTS();
dflet 3:a8c249046181 311
dflet 3:a8c249046181 312 prvAddCoRoutineToReadyQueue( pxCRCB );
dflet 3:a8c249046181 313 }
dflet 3:a8c249046181 314 }
dflet 3:a8c249046181 315
dflet 3:a8c249046181 316 xLastTickCount = xCoRoutineTickCount;
dflet 3:a8c249046181 317 }
dflet 3:a8c249046181 318 /*-----------------------------------------------------------*/
dflet 3:a8c249046181 319
dflet 3:a8c249046181 320 void vCoRoutineSchedule( void )
dflet 3:a8c249046181 321 {
dflet 3:a8c249046181 322 /* See if any co-routines readied by events need moving to the ready lists. */
dflet 3:a8c249046181 323 prvCheckPendingReadyList();
dflet 3:a8c249046181 324
dflet 3:a8c249046181 325 /* See if any delayed co-routines have timed out. */
dflet 3:a8c249046181 326 prvCheckDelayedList();
dflet 3:a8c249046181 327
dflet 3:a8c249046181 328 /* Find the highest priority queue that contains ready co-routines. */
dflet 3:a8c249046181 329 while( listLIST_IS_EMPTY( &( pxReadyCoRoutineLists[ uxTopCoRoutineReadyPriority ] ) ) )
dflet 3:a8c249046181 330 {
dflet 3:a8c249046181 331 if( uxTopCoRoutineReadyPriority == 0 )
dflet 3:a8c249046181 332 {
dflet 3:a8c249046181 333 /* No more co-routines to check. */
dflet 3:a8c249046181 334 return;
dflet 3:a8c249046181 335 }
dflet 3:a8c249046181 336 --uxTopCoRoutineReadyPriority;
dflet 3:a8c249046181 337 }
dflet 3:a8c249046181 338
dflet 3:a8c249046181 339 /* listGET_OWNER_OF_NEXT_ENTRY walks through the list, so the co-routines
dflet 3:a8c249046181 340 of the same priority get an equal share of the processor time. */
dflet 3:a8c249046181 341 listGET_OWNER_OF_NEXT_ENTRY( pxCurrentCoRoutine, &( pxReadyCoRoutineLists[ uxTopCoRoutineReadyPriority ] ) );
dflet 3:a8c249046181 342
dflet 3:a8c249046181 343 /* Call the co-routine. */
dflet 3:a8c249046181 344 ( pxCurrentCoRoutine->pxCoRoutineFunction )( pxCurrentCoRoutine, pxCurrentCoRoutine->uxIndex );
dflet 3:a8c249046181 345
dflet 3:a8c249046181 346 return;
dflet 3:a8c249046181 347 }
dflet 3:a8c249046181 348 /*-----------------------------------------------------------*/
dflet 3:a8c249046181 349
dflet 3:a8c249046181 350 static void prvInitialiseCoRoutineLists( void )
dflet 3:a8c249046181 351 {
dflet 3:a8c249046181 352 UBaseType_t uxPriority;
dflet 3:a8c249046181 353
dflet 3:a8c249046181 354 for( uxPriority = 0; uxPriority < configMAX_CO_ROUTINE_PRIORITIES; uxPriority++ )
dflet 3:a8c249046181 355 {
dflet 3:a8c249046181 356 vListInitialise( ( List_t * ) &( pxReadyCoRoutineLists[ uxPriority ] ) );
dflet 3:a8c249046181 357 }
dflet 3:a8c249046181 358
dflet 3:a8c249046181 359 vListInitialise( ( List_t * ) &xDelayedCoRoutineList1 );
dflet 3:a8c249046181 360 vListInitialise( ( List_t * ) &xDelayedCoRoutineList2 );
dflet 3:a8c249046181 361 vListInitialise( ( List_t * ) &xPendingReadyCoRoutineList );
dflet 3:a8c249046181 362
dflet 3:a8c249046181 363 /* Start with pxDelayedCoRoutineList using list1 and the
dflet 3:a8c249046181 364 pxOverflowDelayedCoRoutineList using list2. */
dflet 3:a8c249046181 365 pxDelayedCoRoutineList = &xDelayedCoRoutineList1;
dflet 3:a8c249046181 366 pxOverflowDelayedCoRoutineList = &xDelayedCoRoutineList2;
dflet 3:a8c249046181 367 }
dflet 3:a8c249046181 368 /*-----------------------------------------------------------*/
dflet 3:a8c249046181 369
dflet 3:a8c249046181 370 BaseType_t xCoRoutineRemoveFromEventList( const List_t *pxEventList )
dflet 3:a8c249046181 371 {
dflet 3:a8c249046181 372 CRCB_t *pxUnblockedCRCB;
dflet 3:a8c249046181 373 BaseType_t xReturn;
dflet 3:a8c249046181 374
dflet 3:a8c249046181 375 /* This function is called from within an interrupt. It can only access
dflet 3:a8c249046181 376 event lists and the pending ready list. This function assumes that a
dflet 3:a8c249046181 377 check has already been made to ensure pxEventList is not empty. */
dflet 3:a8c249046181 378 pxUnblockedCRCB = ( CRCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxEventList );
dflet 3:a8c249046181 379 ( void ) uxListRemove( &( pxUnblockedCRCB->xEventListItem ) );
dflet 3:a8c249046181 380 vListInsertEnd( ( List_t * ) &( xPendingReadyCoRoutineList ), &( pxUnblockedCRCB->xEventListItem ) );
dflet 3:a8c249046181 381
dflet 3:a8c249046181 382 if( pxUnblockedCRCB->uxPriority >= pxCurrentCoRoutine->uxPriority )
dflet 3:a8c249046181 383 {
dflet 3:a8c249046181 384 xReturn = pdTRUE;
dflet 3:a8c249046181 385 }
dflet 3:a8c249046181 386 else
dflet 3:a8c249046181 387 {
dflet 3:a8c249046181 388 xReturn = pdFALSE;
dflet 3:a8c249046181 389 }
dflet 3:a8c249046181 390
dflet 3:a8c249046181 391 return xReturn;
dflet 3:a8c249046181 392 }
dflet 3:a8c249046181 393
dflet 3:a8c249046181 394 #endif /* configUSE_CO_ROUTINES == 0 */
dflet 3:a8c249046181 395
dflet 3:a8c249046181 396