Port of TI's CC3100 Websock camera demo. Using FreeRTOS, mbedTLS, also parts of Arducam for cams ov5642 and 0v2640. Can also use MT9D111. Work in progress. Be warned some parts maybe a bit flacky. This is for Seeed Arch max only, for an M3, see the demo for CM3 using the 0v5642 aducam mini.

Dependencies:   mbed

Committer:
dflet
Date:
Tue Sep 15 16:45:04 2015 +0000
Revision:
22:f9b5e0b80bf2
Parent:
0:50cedd586816
Removed some debug.

Who changed what in which revision?

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