2 FreeRTOS V6.0.0 - Copyright (C) 2009 Real Time Engineers Ltd.
\r
4 This file is part of the FreeRTOS distribution.
\r
6 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
7 the terms of the GNU General Public License (version 2) as published by the
\r
8 Free Software Foundation and modified by the FreeRTOS exception.
\r
9 **NOTE** The exception to the GPL is included to allow you to distribute a
\r
10 combined work that includes FreeRTOS without being obliged to provide the
\r
11 source code for proprietary components outside of the FreeRTOS kernel.
\r
12 Alternative commercial license and support terms are also available upon
\r
13 request. See the licensing section of http://www.FreeRTOS.org for full
\r
16 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
\r
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
21 You should have received a copy of the GNU General Public License along
\r
22 with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59
\r
23 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
26 ***************************************************************************
\r
28 * The FreeRTOS eBook and reference manual are available to purchase for a *
\r
29 * small fee. Help yourself get started quickly while also helping the *
\r
30 * FreeRTOS project! See http://www.FreeRTOS.org/Documentation for details *
\r
32 ***************************************************************************
\r
36 Please ensure to read the configuration and relevant port sections of the
\r
37 online documentation.
\r
39 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
42 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
45 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
46 licensing and training services.
\r
49 #ifndef INC_FREERTOS_H
\r
50 #error "#include FreeRTOS.h" must appear in source files before "#include croutine.h"
\r
56 #ifndef CO_ROUTINE_H
\r
57 #define CO_ROUTINE_H
\r
65 /* Used to hide the implementation of the co-routine control block. The
\r
66 control block structure however has to be included in the header due to
\r
67 the macro implementation of the co-routine functionality. */
\r
68 typedef void * xCoRoutineHandle;
\r
70 /* Defines the prototype to which co-routine functions must conform. */
\r
71 typedef void (*crCOROUTINE_CODE)( xCoRoutineHandle, unsigned portBASE_TYPE );
\r
73 typedef struct corCoRoutineControlBlock
\r
75 crCOROUTINE_CODE pxCoRoutineFunction;
\r
76 xListItem xGenericListItem; /*< List item used to place the CRCB in ready and blocked queues. */
\r
77 xListItem xEventListItem; /*< List item used to place the CRCB in event lists. */
\r
78 unsigned portBASE_TYPE uxPriority; /*< The priority of the co-routine in relation to other co-routines. */
\r
79 unsigned portBASE_TYPE uxIndex; /*< Used to distinguish between co-routines when multiple co-routines use the same co-routine function. */
\r
80 unsigned short uxState; /*< Used internally by the co-routine implementation. */
\r
81 } corCRCB; /* Co-routine control block. Note must be identical in size down to uxPriority with tskTCB. */
\r
86 portBASE_TYPE xCoRoutineCreate(
\r
87 crCOROUTINE_CODE pxCoRoutineCode,
\r
88 unsigned portBASE_TYPE uxPriority,
\r
89 unsigned portBASE_TYPE uxIndex
\r
92 * Create a new co-routine and add it to the list of co-routines that are
\r
95 * @param pxCoRoutineCode Pointer to the co-routine function. Co-routine
\r
96 * functions require special syntax - see the co-routine section of the WEB
\r
97 * documentation for more information.
\r
99 * @param uxPriority The priority with respect to other co-routines at which
\r
100 * the co-routine will run.
\r
102 * @param uxIndex Used to distinguish between different co-routines that
\r
103 * execute the same function. See the example below and the co-routine section
\r
104 * of the WEB documentation for further information.
\r
106 * @return pdPASS if the co-routine was successfully created and added to a ready
\r
107 * list, otherwise an error code defined with ProjDefs.h.
\r
111 // Co-routine to be created.
\r
112 void vFlashCoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
\r
114 // Variables in co-routines must be declared static if they must maintain value across a blocking call.
\r
115 // This may not be necessary for const variables.
\r
116 static const char cLedToFlash[ 2 ] = { 5, 6 };
\r
117 static const portTickType xTimeToDelay[ 2 ] = { 200, 400 };
\r
119 // Must start every co-routine with a call to crSTART();
\r
120 crSTART( xHandle );
\r
124 // This co-routine just delays for a fixed period, then toggles
\r
125 // an LED. Two co-routines are created using this function, so
\r
126 // the uxIndex parameter is used to tell the co-routine which
\r
127 // LED to flash and how long to delay. This assumes xQueue has
\r
128 // already been created.
\r
129 vParTestToggleLED( cLedToFlash[ uxIndex ] );
\r
130 crDELAY( xHandle, uxFlashRates[ uxIndex ] );
\r
133 // Must end every co-routine with a call to crEND();
\r
137 // Function that creates two co-routines.
\r
138 void vOtherFunction( void )
\r
140 unsigned char ucParameterToPass;
\r
141 xTaskHandle xHandle;
\r
143 // Create two co-routines at priority 0. The first is given index 0
\r
144 // so (from the code above) toggles LED 5 every 200 ticks. The second
\r
145 // is given index 1 so toggles LED 6 every 400 ticks.
\r
146 for( uxIndex = 0; uxIndex < 2; uxIndex++ )
\r
148 xCoRoutineCreate( vFlashCoRoutine, 0, uxIndex );
\r
152 * \defgroup xCoRoutineCreate xCoRoutineCreate
\r
155 signed portBASE_TYPE xCoRoutineCreate( crCOROUTINE_CODE pxCoRoutineCode, unsigned portBASE_TYPE uxPriority, unsigned portBASE_TYPE uxIndex );
\r
161 void vCoRoutineSchedule( void );</pre>
\r
163 * Run a co-routine.
\r
165 * vCoRoutineSchedule() executes the highest priority co-routine that is able
\r
166 * to run. The co-routine will execute until it either blocks, yields or is
\r
167 * preempted by a task. Co-routines execute cooperatively so one
\r
168 * co-routine cannot be preempted by another, but can be preempted by a task.
\r
170 * If an application comprises of both tasks and co-routines then
\r
171 * vCoRoutineSchedule should be called from the idle task (in an idle task
\r
176 // This idle task hook will schedule a co-routine each time it is called.
\r
177 // The rest of the idle task will execute between co-routine calls.
\r
178 void vApplicationIdleHook( void )
\r
180 vCoRoutineSchedule();
\r
183 // Alternatively, if you do not require any other part of the idle task to
\r
184 // execute, the idle task hook can call vCoRoutineScheduler() within an
\r
186 void vApplicationIdleHook( void )
\r
190 vCoRoutineSchedule();
\r
194 * \defgroup vCoRoutineSchedule vCoRoutineSchedule
\r
197 void vCoRoutineSchedule( void );
\r
202 crSTART( xCoRoutineHandle xHandle );</pre>
\r
204 * This macro MUST always be called at the start of a co-routine function.
\r
208 // Co-routine to be created.
\r
209 void vACoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
\r
211 // Variables in co-routines must be declared static if they must maintain value across a blocking call.
\r
212 static long ulAVariable;
\r
214 // Must start every co-routine with a call to crSTART();
\r
215 crSTART( xHandle );
\r
219 // Co-routine functionality goes here.
\r
222 // Must end every co-routine with a call to crEND();
\r
225 * \defgroup crSTART crSTART
\r
228 #define crSTART( pxCRCB ) switch( ( ( corCRCB * )pxCRCB )->uxState ) { case 0:
\r
235 * This macro MUST always be called at the end of a co-routine function.
\r
239 // Co-routine to be created.
\r
240 void vACoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
\r
242 // Variables in co-routines must be declared static if they must maintain value across a blocking call.
\r
243 static long ulAVariable;
\r
245 // Must start every co-routine with a call to crSTART();
\r
246 crSTART( xHandle );
\r
250 // Co-routine functionality goes here.
\r
253 // Must end every co-routine with a call to crEND();
\r
256 * \defgroup crSTART crSTART
\r
262 * These macros are intended for internal use by the co-routine implementation
\r
263 * only. The macros should not be used directly by application writers.
\r
265 #define crSET_STATE0( xHandle ) ( ( corCRCB * )xHandle)->uxState = (__LINE__ * 2); return; case (__LINE__ * 2):
\r
266 #define crSET_STATE1( xHandle ) ( ( corCRCB * )xHandle)->uxState = ((__LINE__ * 2)+1); return; case ((__LINE__ * 2)+1):
\r
271 crDELAY( xCoRoutineHandle xHandle, portTickType xTicksToDelay );</pre>
\r
273 * Delay a co-routine for a fixed period of time.
\r
275 * crDELAY can only be called from the co-routine function itself - not
\r
276 * from within a function called by the co-routine function. This is because
\r
277 * co-routines do not maintain their own stack.
\r
279 * @param xHandle The handle of the co-routine to delay. This is the xHandle
\r
280 * parameter of the co-routine function.
\r
282 * @param xTickToDelay The number of ticks that the co-routine should delay
\r
283 * for. The actual amount of time this equates to is defined by
\r
284 * configTICK_RATE_HZ (set in FreeRTOSConfig.h). The constant portTICK_RATE_MS
\r
285 * can be used to convert ticks to milliseconds.
\r
289 // Co-routine to be created.
\r
290 void vACoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
\r
292 // Variables in co-routines must be declared static if they must maintain value across a blocking call.
\r
293 // This may not be necessary for const variables.
\r
294 // We are to delay for 200ms.
\r
295 static const xTickType xDelayTime = 200 / portTICK_RATE_MS;
\r
297 // Must start every co-routine with a call to crSTART();
\r
298 crSTART( xHandle );
\r
302 // Delay for 200ms.
\r
303 crDELAY( xHandle, xDelayTime );
\r
305 // Do something here.
\r
308 // Must end every co-routine with a call to crEND();
\r
311 * \defgroup crDELAY crDELAY
\r
314 #define crDELAY( xHandle, xTicksToDelay ) \
\r
315 if( xTicksToDelay > 0 ) \
\r
317 vCoRoutineAddToDelayedList( xTicksToDelay, NULL ); \
\r
319 crSET_STATE0( xHandle );
\r
324 xCoRoutineHandle xHandle,
\r
325 xQueueHandle pxQueue,
\r
326 void *pvItemToQueue,
\r
327 portTickType xTicksToWait,
\r
328 portBASE_TYPE *pxResult
\r
331 * The macro's crQUEUE_SEND() and crQUEUE_RECEIVE() are the co-routine
\r
332 * equivalent to the xQueueSend() and xQueueReceive() functions used by tasks.
\r
334 * crQUEUE_SEND and crQUEUE_RECEIVE can only be used from a co-routine whereas
\r
335 * xQueueSend() and xQueueReceive() can only be used from tasks.
\r
337 * crQUEUE_SEND can only be called from the co-routine function itself - not
\r
338 * from within a function called by the co-routine function. This is because
\r
339 * co-routines do not maintain their own stack.
\r
341 * See the co-routine section of the WEB documentation for information on
\r
342 * passing data between tasks and co-routines and between ISR's and
\r
345 * @param xHandle The handle of the calling co-routine. This is the xHandle
\r
346 * parameter of the co-routine function.
\r
348 * @param pxQueue The handle of the queue on which the data will be posted.
\r
349 * The handle is obtained as the return value when the queue is created using
\r
350 * the xQueueCreate() API function.
\r
352 * @param pvItemToQueue A pointer to the data being posted onto the queue.
\r
353 * The number of bytes of each queued item is specified when the queue is
\r
354 * created. This number of bytes is copied from pvItemToQueue into the queue
\r
357 * @param xTickToDelay The number of ticks that the co-routine should block
\r
358 * to wait for space to become available on the queue, should space not be
\r
359 * available immediately. The actual amount of time this equates to is defined
\r
360 * by configTICK_RATE_HZ (set in FreeRTOSConfig.h). The constant
\r
361 * portTICK_RATE_MS can be used to convert ticks to milliseconds (see example
\r
364 * @param pxResult The variable pointed to by pxResult will be set to pdPASS if
\r
365 * data was successfully posted onto the queue, otherwise it will be set to an
\r
366 * error defined within ProjDefs.h.
\r
370 // Co-routine function that blocks for a fixed period then posts a number onto
\r
372 static void prvCoRoutineFlashTask( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
\r
374 // Variables in co-routines must be declared static if they must maintain value across a blocking call.
\r
375 static portBASE_TYPE xNumberToPost = 0;
\r
376 static portBASE_TYPE xResult;
\r
378 // Co-routines must begin with a call to crSTART().
\r
379 crSTART( xHandle );
\r
383 // This assumes the queue has already been created.
\r
384 crQUEUE_SEND( xHandle, xCoRoutineQueue, &xNumberToPost, NO_DELAY, &xResult );
\r
386 if( xResult != pdPASS )
\r
388 // The message was not posted!
\r
391 // Increment the number to be posted onto the queue.
\r
394 // Delay for 100 ticks.
\r
395 crDELAY( xHandle, 100 );
\r
398 // Co-routines must end with a call to crEND().
\r
401 * \defgroup crQUEUE_SEND crQUEUE_SEND
\r
404 #define crQUEUE_SEND( xHandle, pxQueue, pvItemToQueue, xTicksToWait, pxResult ) \
\r
406 *pxResult = xQueueCRSend( pxQueue, pvItemToQueue, xTicksToWait ); \
\r
407 if( *pxResult == errQUEUE_BLOCKED ) \
\r
409 crSET_STATE0( xHandle ); \
\r
410 *pxResult = xQueueCRSend( pxQueue, pvItemToQueue, 0 ); \
\r
412 if( *pxResult == errQUEUE_YIELD ) \
\r
414 crSET_STATE1( xHandle ); \
\r
415 *pxResult = pdPASS; \
\r
423 xCoRoutineHandle xHandle,
\r
424 xQueueHandle pxQueue,
\r
426 portTickType xTicksToWait,
\r
427 portBASE_TYPE *pxResult
\r
430 * The macro's crQUEUE_SEND() and crQUEUE_RECEIVE() are the co-routine
\r
431 * equivalent to the xQueueSend() and xQueueReceive() functions used by tasks.
\r
433 * crQUEUE_SEND and crQUEUE_RECEIVE can only be used from a co-routine whereas
\r
434 * xQueueSend() and xQueueReceive() can only be used from tasks.
\r
436 * crQUEUE_RECEIVE can only be called from the co-routine function itself - not
\r
437 * from within a function called by the co-routine function. This is because
\r
438 * co-routines do not maintain their own stack.
\r
440 * See the co-routine section of the WEB documentation for information on
\r
441 * passing data between tasks and co-routines and between ISR's and
\r
444 * @param xHandle The handle of the calling co-routine. This is the xHandle
\r
445 * parameter of the co-routine function.
\r
447 * @param pxQueue The handle of the queue from which the data will be received.
\r
448 * The handle is obtained as the return value when the queue is created using
\r
449 * the xQueueCreate() API function.
\r
451 * @param pvBuffer The buffer into which the received item is to be copied.
\r
452 * The number of bytes of each queued item is specified when the queue is
\r
453 * created. This number of bytes is copied into pvBuffer.
\r
455 * @param xTickToDelay The number of ticks that the co-routine should block
\r
456 * to wait for data to become available from the queue, should data not be
\r
457 * available immediately. The actual amount of time this equates to is defined
\r
458 * by configTICK_RATE_HZ (set in FreeRTOSConfig.h). The constant
\r
459 * portTICK_RATE_MS can be used to convert ticks to milliseconds (see the
\r
460 * crQUEUE_SEND example).
\r
462 * @param pxResult The variable pointed to by pxResult will be set to pdPASS if
\r
463 * data was successfully retrieved from the queue, otherwise it will be set to
\r
464 * an error code as defined within ProjDefs.h.
\r
468 // A co-routine receives the number of an LED to flash from a queue. It
\r
469 // blocks on the queue until the number is received.
\r
470 static void prvCoRoutineFlashWorkTask( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
\r
472 // Variables in co-routines must be declared static if they must maintain value across a blocking call.
\r
473 static portBASE_TYPE xResult;
\r
474 static unsigned portBASE_TYPE uxLEDToFlash;
\r
476 // All co-routines must start with a call to crSTART().
\r
477 crSTART( xHandle );
\r
481 // Wait for data to become available on the queue.
\r
482 crQUEUE_RECEIVE( xHandle, xCoRoutineQueue, &uxLEDToFlash, portMAX_DELAY, &xResult );
\r
484 if( xResult == pdPASS )
\r
486 // We received the LED to flash - flash it!
\r
487 vParTestToggleLED( uxLEDToFlash );
\r
493 * \defgroup crQUEUE_RECEIVE crQUEUE_RECEIVE
\r
496 #define crQUEUE_RECEIVE( xHandle, pxQueue, pvBuffer, xTicksToWait, pxResult ) \
\r
498 *pxResult = xQueueCRReceive( pxQueue, pvBuffer, xTicksToWait ); \
\r
499 if( *pxResult == errQUEUE_BLOCKED ) \
\r
501 crSET_STATE0( xHandle ); \
\r
502 *pxResult = xQueueCRReceive( pxQueue, pvBuffer, 0 ); \
\r
504 if( *pxResult == errQUEUE_YIELD ) \
\r
506 crSET_STATE1( xHandle ); \
\r
507 *pxResult = pdPASS; \
\r
514 crQUEUE_SEND_FROM_ISR(
\r
515 xQueueHandle pxQueue,
\r
516 void *pvItemToQueue,
\r
517 portBASE_TYPE xCoRoutinePreviouslyWoken
\r
520 * The macro's crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() are the
\r
521 * co-routine equivalent to the xQueueSendFromISR() and xQueueReceiveFromISR()
\r
522 * functions used by tasks.
\r
524 * crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() can only be used to
\r
525 * pass data between a co-routine and and ISR, whereas xQueueSendFromISR() and
\r
526 * xQueueReceiveFromISR() can only be used to pass data between a task and and
\r
529 * crQUEUE_SEND_FROM_ISR can only be called from an ISR to send data to a queue
\r
530 * that is being used from within a co-routine.
\r
532 * See the co-routine section of the WEB documentation for information on
\r
533 * passing data between tasks and co-routines and between ISR's and
\r
536 * @param xQueue The handle to the queue on which the item is to be posted.
\r
538 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
539 * queue. The size of the items the queue will hold was defined when the
\r
540 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
541 * into the queue storage area.
\r
543 * @param xCoRoutinePreviouslyWoken This is included so an ISR can post onto
\r
544 * the same queue multiple times from a single interrupt. The first call
\r
545 * should always pass in pdFALSE. Subsequent calls should pass in
\r
546 * the value returned from the previous call.
\r
548 * @return pdTRUE if a co-routine was woken by posting onto the queue. This is
\r
549 * used by the ISR to determine if a context switch may be required following
\r
554 // A co-routine that blocks on a queue waiting for characters to be received.
\r
555 static void vReceivingCoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
\r
558 portBASE_TYPE xResult;
\r
560 // All co-routines must start with a call to crSTART().
\r
561 crSTART( xHandle );
\r
565 // Wait for data to become available on the queue. This assumes the
\r
566 // queue xCommsRxQueue has already been created!
\r
567 crQUEUE_RECEIVE( xHandle, xCommsRxQueue, &uxLEDToFlash, portMAX_DELAY, &xResult );
\r
569 // Was a character received?
\r
570 if( xResult == pdPASS )
\r
572 // Process the character here.
\r
576 // All co-routines must end with a call to crEND().
\r
580 // An ISR that uses a queue to send characters received on a serial port to
\r
582 void vUART_ISR( void )
\r
585 portBASE_TYPE xCRWokenByPost = pdFALSE;
\r
587 // We loop around reading characters until there are none left in the UART.
\r
588 while( UART_RX_REG_NOT_EMPTY() )
\r
590 // Obtain the character from the UART.
\r
591 cRxedChar = UART_RX_REG;
\r
593 // Post the character onto a queue. xCRWokenByPost will be pdFALSE
\r
594 // the first time around the loop. If the post causes a co-routine
\r
595 // to be woken (unblocked) then xCRWokenByPost will be set to pdTRUE.
\r
596 // In this manner we can ensure that if more than one co-routine is
\r
597 // blocked on the queue only one is woken by this ISR no matter how
\r
598 // many characters are posted to the queue.
\r
599 xCRWokenByPost = crQUEUE_SEND_FROM_ISR( xCommsRxQueue, &cRxedChar, xCRWokenByPost );
\r
602 * \defgroup crQUEUE_SEND_FROM_ISR crQUEUE_SEND_FROM_ISR
\r
605 #define crQUEUE_SEND_FROM_ISR( pxQueue, pvItemToQueue, xCoRoutinePreviouslyWoken ) xQueueCRSendFromISR( pxQueue, pvItemToQueue, xCoRoutinePreviouslyWoken )
\r
611 crQUEUE_SEND_FROM_ISR(
\r
612 xQueueHandle pxQueue,
\r
614 portBASE_TYPE * pxCoRoutineWoken
\r
617 * The macro's crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() are the
\r
618 * co-routine equivalent to the xQueueSendFromISR() and xQueueReceiveFromISR()
\r
619 * functions used by tasks.
\r
621 * crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() can only be used to
\r
622 * pass data between a co-routine and and ISR, whereas xQueueSendFromISR() and
\r
623 * xQueueReceiveFromISR() can only be used to pass data between a task and and
\r
626 * crQUEUE_RECEIVE_FROM_ISR can only be called from an ISR to receive data
\r
627 * from a queue that is being used from within a co-routine (a co-routine
\r
628 * posted to the queue).
\r
630 * See the co-routine section of the WEB documentation for information on
\r
631 * passing data between tasks and co-routines and between ISR's and
\r
634 * @param xQueue The handle to the queue on which the item is to be posted.
\r
636 * @param pvBuffer A pointer to a buffer into which the received item will be
\r
637 * placed. The size of the items the queue will hold was defined when the
\r
638 * queue was created, so this many bytes will be copied from the queue into
\r
641 * @param pxCoRoutineWoken A co-routine may be blocked waiting for space to become
\r
642 * available on the queue. If crQUEUE_RECEIVE_FROM_ISR causes such a
\r
643 * co-routine to unblock *pxCoRoutineWoken will get set to pdTRUE, otherwise
\r
644 * *pxCoRoutineWoken will remain unchanged.
\r
646 * @return pdTRUE an item was successfully received from the queue, otherwise
\r
651 // A co-routine that posts a character to a queue then blocks for a fixed
\r
652 // period. The character is incremented each time.
\r
653 static void vSendingCoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
\r
655 // cChar holds its value while this co-routine is blocked and must therefore
\r
656 // be declared static.
\r
657 static char cCharToTx = 'a';
\r
658 portBASE_TYPE xResult;
\r
660 // All co-routines must start with a call to crSTART().
\r
661 crSTART( xHandle );
\r
665 // Send the next character to the queue.
\r
666 crQUEUE_SEND( xHandle, xCoRoutineQueue, &cCharToTx, NO_DELAY, &xResult );
\r
668 if( xResult == pdPASS )
\r
670 // The character was successfully posted to the queue.
\r
674 // Could not post the character to the queue.
\r
677 // Enable the UART Tx interrupt to cause an interrupt in this
\r
678 // hypothetical UART. The interrupt will obtain the character
\r
679 // from the queue and send it.
\r
680 ENABLE_RX_INTERRUPT();
\r
682 // Increment to the next character then block for a fixed period.
\r
683 // cCharToTx will maintain its value across the delay as it is
\r
684 // declared static.
\r
686 if( cCharToTx > 'x' )
\r
693 // All co-routines must end with a call to crEND().
\r
697 // An ISR that uses a queue to receive characters to send on a UART.
\r
698 void vUART_ISR( void )
\r
701 portBASE_TYPE xCRWokenByPost = pdFALSE;
\r
703 while( UART_TX_REG_EMPTY() )
\r
705 // Are there any characters in the queue waiting to be sent?
\r
706 // xCRWokenByPost will automatically be set to pdTRUE if a co-routine
\r
707 // is woken by the post - ensuring that only a single co-routine is
\r
708 // woken no matter how many times we go around this loop.
\r
709 if( crQUEUE_RECEIVE_FROM_ISR( pxQueue, &cCharToTx, &xCRWokenByPost ) )
\r
711 SEND_CHARACTER( cCharToTx );
\r
715 * \defgroup crQUEUE_RECEIVE_FROM_ISR crQUEUE_RECEIVE_FROM_ISR
\r
718 #define crQUEUE_RECEIVE_FROM_ISR( pxQueue, pvBuffer, pxCoRoutineWoken ) xQueueCRReceiveFromISR( pxQueue, pvBuffer, pxCoRoutineWoken )
\r
721 * This function is intended for internal use by the co-routine macros only.
\r
722 * The macro nature of the co-routine implementation requires that the
\r
723 * prototype appears here. The function should not be used by application
\r
726 * Removes the current co-routine from its ready list and places it in the
\r
727 * appropriate delayed list.
\r
729 void vCoRoutineAddToDelayedList( portTickType xTicksToDelay, xList *pxEventList );
\r
732 * This function is intended for internal use by the queue implementation only.
\r
733 * The function should not be used by application writers.
\r
735 * Removes the highest priority co-routine from the event list and places it in
\r
736 * the pending ready list.
\r
738 signed portBASE_TYPE xCoRoutineRemoveFromEventList( const xList *pxEventList );
\r
744 #endif /* CO_ROUTINE_H */
\r