2 FreeRTOS V6.0.2 - Copyright (C) 2010 Real Time Engineers Ltd.
\r
4 ***************************************************************************
\r
8 * + New to FreeRTOS, *
\r
9 * + Wanting to learn FreeRTOS or multitasking in general quickly *
\r
10 * + Looking for basic training, *
\r
11 * + Wanting to improve your FreeRTOS skills and productivity *
\r
13 * then take a look at the FreeRTOS eBook *
\r
15 * "Using the FreeRTOS Real Time Kernel - a Practical Guide" *
\r
16 * http://www.FreeRTOS.org/Documentation *
\r
18 * A pdf reference manual is also available. Both are usually delivered *
\r
19 * to your inbox within 20 minutes to two hours when purchased between 8am *
\r
20 * and 8pm GMT (although please allow up to 24 hours in case of *
\r
21 * exceptional circumstances). Thank you for your support! *
\r
23 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 ***NOTE*** The exception to the GPL is included to allow you to distribute
\r
31 a combined work that includes FreeRTOS without being obliged to provide the
\r
32 source code for proprietary components outside of the FreeRTOS kernel.
\r
33 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
\r
34 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
35 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
47 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
50 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
51 licensing and training services.
\r
54 #ifndef INC_FREERTOS_H
\r
55 #error "#include FreeRTOS.h" must appear in source files before "#include croutine.h"
\r
61 #ifndef CO_ROUTINE_H
\r
62 #define CO_ROUTINE_H
\r
70 /* Used to hide the implementation of the co-routine control block. The
\r
71 control block structure however has to be included in the header due to
\r
72 the macro implementation of the co-routine functionality. */
\r
73 typedef void * xCoRoutineHandle;
\r
75 /* Defines the prototype to which co-routine functions must conform. */
\r
76 typedef void (*crCOROUTINE_CODE)( xCoRoutineHandle, unsigned portBASE_TYPE );
\r
78 typedef struct corCoRoutineControlBlock
\r
80 crCOROUTINE_CODE pxCoRoutineFunction;
\r
81 xListItem xGenericListItem; /*< List item used to place the CRCB in ready and blocked queues. */
\r
82 xListItem xEventListItem; /*< List item used to place the CRCB in event lists. */
\r
83 unsigned portBASE_TYPE uxPriority; /*< The priority of the co-routine in relation to other co-routines. */
\r
84 unsigned portBASE_TYPE uxIndex; /*< Used to distinguish between co-routines when multiple co-routines use the same co-routine function. */
\r
85 unsigned short uxState; /*< Used internally by the co-routine implementation. */
\r
86 } corCRCB; /* Co-routine control block. Note must be identical in size down to uxPriority with tskTCB. */
\r
91 portBASE_TYPE xCoRoutineCreate(
\r
92 crCOROUTINE_CODE pxCoRoutineCode,
\r
93 unsigned portBASE_TYPE uxPriority,
\r
94 unsigned portBASE_TYPE uxIndex
\r
97 * Create a new co-routine and add it to the list of co-routines that are
\r
100 * @param pxCoRoutineCode Pointer to the co-routine function. Co-routine
\r
101 * functions require special syntax - see the co-routine section of the WEB
\r
102 * documentation for more information.
\r
104 * @param uxPriority The priority with respect to other co-routines at which
\r
105 * the co-routine will run.
\r
107 * @param uxIndex Used to distinguish between different co-routines that
\r
108 * execute the same function. See the example below and the co-routine section
\r
109 * of the WEB documentation for further information.
\r
111 * @return pdPASS if the co-routine was successfully created and added to a ready
\r
112 * list, otherwise an error code defined with ProjDefs.h.
\r
116 // Co-routine to be created.
\r
117 void vFlashCoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
\r
119 // Variables in co-routines must be declared static if they must maintain value across a blocking call.
\r
120 // This may not be necessary for const variables.
\r
121 static const char cLedToFlash[ 2 ] = { 5, 6 };
\r
122 static const portTickType xTimeToDelay[ 2 ] = { 200, 400 };
\r
124 // Must start every co-routine with a call to crSTART();
\r
125 crSTART( xHandle );
\r
129 // This co-routine just delays for a fixed period, then toggles
\r
130 // an LED. Two co-routines are created using this function, so
\r
131 // the uxIndex parameter is used to tell the co-routine which
\r
132 // LED to flash and how long to delay. This assumes xQueue has
\r
133 // already been created.
\r
134 vParTestToggleLED( cLedToFlash[ uxIndex ] );
\r
135 crDELAY( xHandle, uxFlashRates[ uxIndex ] );
\r
138 // Must end every co-routine with a call to crEND();
\r
142 // Function that creates two co-routines.
\r
143 void vOtherFunction( void )
\r
145 unsigned char ucParameterToPass;
\r
146 xTaskHandle xHandle;
\r
148 // Create two co-routines at priority 0. The first is given index 0
\r
149 // so (from the code above) toggles LED 5 every 200 ticks. The second
\r
150 // is given index 1 so toggles LED 6 every 400 ticks.
\r
151 for( uxIndex = 0; uxIndex < 2; uxIndex++ )
\r
153 xCoRoutineCreate( vFlashCoRoutine, 0, uxIndex );
\r
157 * \defgroup xCoRoutineCreate xCoRoutineCreate
\r
160 signed portBASE_TYPE xCoRoutineCreate( crCOROUTINE_CODE pxCoRoutineCode, unsigned portBASE_TYPE uxPriority, unsigned portBASE_TYPE uxIndex );
\r
166 void vCoRoutineSchedule( void );</pre>
\r
168 * Run a co-routine.
\r
170 * vCoRoutineSchedule() executes the highest priority co-routine that is able
\r
171 * to run. The co-routine will execute until it either blocks, yields or is
\r
172 * preempted by a task. Co-routines execute cooperatively so one
\r
173 * co-routine cannot be preempted by another, but can be preempted by a task.
\r
175 * If an application comprises of both tasks and co-routines then
\r
176 * vCoRoutineSchedule should be called from the idle task (in an idle task
\r
181 // This idle task hook will schedule a co-routine each time it is called.
\r
182 // The rest of the idle task will execute between co-routine calls.
\r
183 void vApplicationIdleHook( void )
\r
185 vCoRoutineSchedule();
\r
188 // Alternatively, if you do not require any other part of the idle task to
\r
189 // execute, the idle task hook can call vCoRoutineScheduler() within an
\r
191 void vApplicationIdleHook( void )
\r
195 vCoRoutineSchedule();
\r
199 * \defgroup vCoRoutineSchedule vCoRoutineSchedule
\r
202 void vCoRoutineSchedule( void );
\r
207 crSTART( xCoRoutineHandle xHandle );</pre>
\r
209 * This macro MUST always be called at the start of a co-routine function.
\r
213 // Co-routine to be created.
\r
214 void vACoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
\r
216 // Variables in co-routines must be declared static if they must maintain value across a blocking call.
\r
217 static long ulAVariable;
\r
219 // Must start every co-routine with a call to crSTART();
\r
220 crSTART( xHandle );
\r
224 // Co-routine functionality goes here.
\r
227 // Must end every co-routine with a call to crEND();
\r
230 * \defgroup crSTART crSTART
\r
233 #define crSTART( pxCRCB ) switch( ( ( corCRCB * )pxCRCB )->uxState ) { case 0:
\r
240 * This macro MUST always be called at the end of a co-routine function.
\r
244 // Co-routine to be created.
\r
245 void vACoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
\r
247 // Variables in co-routines must be declared static if they must maintain value across a blocking call.
\r
248 static long ulAVariable;
\r
250 // Must start every co-routine with a call to crSTART();
\r
251 crSTART( xHandle );
\r
255 // Co-routine functionality goes here.
\r
258 // Must end every co-routine with a call to crEND();
\r
261 * \defgroup crSTART crSTART
\r
267 * These macros are intended for internal use by the co-routine implementation
\r
268 * only. The macros should not be used directly by application writers.
\r
270 #define crSET_STATE0( xHandle ) ( ( corCRCB * )xHandle)->uxState = (__LINE__ * 2); return; case (__LINE__ * 2):
\r
271 #define crSET_STATE1( xHandle ) ( ( corCRCB * )xHandle)->uxState = ((__LINE__ * 2)+1); return; case ((__LINE__ * 2)+1):
\r
276 crDELAY( xCoRoutineHandle xHandle, portTickType xTicksToDelay );</pre>
\r
278 * Delay a co-routine for a fixed period of time.
\r
280 * crDELAY can only be called from the co-routine function itself - not
\r
281 * from within a function called by the co-routine function. This is because
\r
282 * co-routines do not maintain their own stack.
\r
284 * @param xHandle The handle of the co-routine to delay. This is the xHandle
\r
285 * parameter of the co-routine function.
\r
287 * @param xTickToDelay The number of ticks that the co-routine should delay
\r
288 * for. The actual amount of time this equates to is defined by
\r
289 * configTICK_RATE_HZ (set in FreeRTOSConfig.h). The constant portTICK_RATE_MS
\r
290 * can be used to convert ticks to milliseconds.
\r
294 // Co-routine to be created.
\r
295 void vACoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
\r
297 // Variables in co-routines must be declared static if they must maintain value across a blocking call.
\r
298 // This may not be necessary for const variables.
\r
299 // We are to delay for 200ms.
\r
300 static const xTickType xDelayTime = 200 / portTICK_RATE_MS;
\r
302 // Must start every co-routine with a call to crSTART();
\r
303 crSTART( xHandle );
\r
307 // Delay for 200ms.
\r
308 crDELAY( xHandle, xDelayTime );
\r
310 // Do something here.
\r
313 // Must end every co-routine with a call to crEND();
\r
316 * \defgroup crDELAY crDELAY
\r
319 #define crDELAY( xHandle, xTicksToDelay ) \
\r
320 if( xTicksToDelay > 0 ) \
\r
322 vCoRoutineAddToDelayedList( xTicksToDelay, NULL ); \
\r
324 crSET_STATE0( xHandle );
\r
329 xCoRoutineHandle xHandle,
\r
330 xQueueHandle pxQueue,
\r
331 void *pvItemToQueue,
\r
332 portTickType xTicksToWait,
\r
333 portBASE_TYPE *pxResult
\r
336 * The macro's crQUEUE_SEND() and crQUEUE_RECEIVE() are the co-routine
\r
337 * equivalent to the xQueueSend() and xQueueReceive() functions used by tasks.
\r
339 * crQUEUE_SEND and crQUEUE_RECEIVE can only be used from a co-routine whereas
\r
340 * xQueueSend() and xQueueReceive() can only be used from tasks.
\r
342 * crQUEUE_SEND can only be called from the co-routine function itself - not
\r
343 * from within a function called by the co-routine function. This is because
\r
344 * co-routines do not maintain their own stack.
\r
346 * See the co-routine section of the WEB documentation for information on
\r
347 * passing data between tasks and co-routines and between ISR's and
\r
350 * @param xHandle The handle of the calling co-routine. This is the xHandle
\r
351 * parameter of the co-routine function.
\r
353 * @param pxQueue The handle of the queue on which the data will be posted.
\r
354 * The handle is obtained as the return value when the queue is created using
\r
355 * the xQueueCreate() API function.
\r
357 * @param pvItemToQueue A pointer to the data being posted onto the queue.
\r
358 * The number of bytes of each queued item is specified when the queue is
\r
359 * created. This number of bytes is copied from pvItemToQueue into the queue
\r
362 * @param xTickToDelay The number of ticks that the co-routine should block
\r
363 * to wait for space to become available on the queue, should space not be
\r
364 * available immediately. The actual amount of time this equates to is defined
\r
365 * by configTICK_RATE_HZ (set in FreeRTOSConfig.h). The constant
\r
366 * portTICK_RATE_MS can be used to convert ticks to milliseconds (see example
\r
369 * @param pxResult The variable pointed to by pxResult will be set to pdPASS if
\r
370 * data was successfully posted onto the queue, otherwise it will be set to an
\r
371 * error defined within ProjDefs.h.
\r
375 // Co-routine function that blocks for a fixed period then posts a number onto
\r
377 static void prvCoRoutineFlashTask( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
\r
379 // Variables in co-routines must be declared static if they must maintain value across a blocking call.
\r
380 static portBASE_TYPE xNumberToPost = 0;
\r
381 static portBASE_TYPE xResult;
\r
383 // Co-routines must begin with a call to crSTART().
\r
384 crSTART( xHandle );
\r
388 // This assumes the queue has already been created.
\r
389 crQUEUE_SEND( xHandle, xCoRoutineQueue, &xNumberToPost, NO_DELAY, &xResult );
\r
391 if( xResult != pdPASS )
\r
393 // The message was not posted!
\r
396 // Increment the number to be posted onto the queue.
\r
399 // Delay for 100 ticks.
\r
400 crDELAY( xHandle, 100 );
\r
403 // Co-routines must end with a call to crEND().
\r
406 * \defgroup crQUEUE_SEND crQUEUE_SEND
\r
409 #define crQUEUE_SEND( xHandle, pxQueue, pvItemToQueue, xTicksToWait, pxResult ) \
\r
411 *pxResult = xQueueCRSend( pxQueue, pvItemToQueue, xTicksToWait ); \
\r
412 if( *pxResult == errQUEUE_BLOCKED ) \
\r
414 crSET_STATE0( xHandle ); \
\r
415 *pxResult = xQueueCRSend( pxQueue, pvItemToQueue, 0 ); \
\r
417 if( *pxResult == errQUEUE_YIELD ) \
\r
419 crSET_STATE1( xHandle ); \
\r
420 *pxResult = pdPASS; \
\r
428 xCoRoutineHandle xHandle,
\r
429 xQueueHandle pxQueue,
\r
431 portTickType xTicksToWait,
\r
432 portBASE_TYPE *pxResult
\r
435 * The macro's crQUEUE_SEND() and crQUEUE_RECEIVE() are the co-routine
\r
436 * equivalent to the xQueueSend() and xQueueReceive() functions used by tasks.
\r
438 * crQUEUE_SEND and crQUEUE_RECEIVE can only be used from a co-routine whereas
\r
439 * xQueueSend() and xQueueReceive() can only be used from tasks.
\r
441 * crQUEUE_RECEIVE can only be called from the co-routine function itself - not
\r
442 * from within a function called by the co-routine function. This is because
\r
443 * co-routines do not maintain their own stack.
\r
445 * See the co-routine section of the WEB documentation for information on
\r
446 * passing data between tasks and co-routines and between ISR's and
\r
449 * @param xHandle The handle of the calling co-routine. This is the xHandle
\r
450 * parameter of the co-routine function.
\r
452 * @param pxQueue The handle of the queue from which the data will be received.
\r
453 * The handle is obtained as the return value when the queue is created using
\r
454 * the xQueueCreate() API function.
\r
456 * @param pvBuffer The buffer into which the received item is to be copied.
\r
457 * The number of bytes of each queued item is specified when the queue is
\r
458 * created. This number of bytes is copied into pvBuffer.
\r
460 * @param xTickToDelay The number of ticks that the co-routine should block
\r
461 * to wait for data to become available from the queue, should data not be
\r
462 * available immediately. The actual amount of time this equates to is defined
\r
463 * by configTICK_RATE_HZ (set in FreeRTOSConfig.h). The constant
\r
464 * portTICK_RATE_MS can be used to convert ticks to milliseconds (see the
\r
465 * crQUEUE_SEND example).
\r
467 * @param pxResult The variable pointed to by pxResult will be set to pdPASS if
\r
468 * data was successfully retrieved from the queue, otherwise it will be set to
\r
469 * an error code as defined within ProjDefs.h.
\r
473 // A co-routine receives the number of an LED to flash from a queue. It
\r
474 // blocks on the queue until the number is received.
\r
475 static void prvCoRoutineFlashWorkTask( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
\r
477 // Variables in co-routines must be declared static if they must maintain value across a blocking call.
\r
478 static portBASE_TYPE xResult;
\r
479 static unsigned portBASE_TYPE uxLEDToFlash;
\r
481 // All co-routines must start with a call to crSTART().
\r
482 crSTART( xHandle );
\r
486 // Wait for data to become available on the queue.
\r
487 crQUEUE_RECEIVE( xHandle, xCoRoutineQueue, &uxLEDToFlash, portMAX_DELAY, &xResult );
\r
489 if( xResult == pdPASS )
\r
491 // We received the LED to flash - flash it!
\r
492 vParTestToggleLED( uxLEDToFlash );
\r
498 * \defgroup crQUEUE_RECEIVE crQUEUE_RECEIVE
\r
501 #define crQUEUE_RECEIVE( xHandle, pxQueue, pvBuffer, xTicksToWait, pxResult ) \
\r
503 *pxResult = xQueueCRReceive( pxQueue, pvBuffer, xTicksToWait ); \
\r
504 if( *pxResult == errQUEUE_BLOCKED ) \
\r
506 crSET_STATE0( xHandle ); \
\r
507 *pxResult = xQueueCRReceive( pxQueue, pvBuffer, 0 ); \
\r
509 if( *pxResult == errQUEUE_YIELD ) \
\r
511 crSET_STATE1( xHandle ); \
\r
512 *pxResult = pdPASS; \
\r
519 crQUEUE_SEND_FROM_ISR(
\r
520 xQueueHandle pxQueue,
\r
521 void *pvItemToQueue,
\r
522 portBASE_TYPE xCoRoutinePreviouslyWoken
\r
525 * The macro's crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() are the
\r
526 * co-routine equivalent to the xQueueSendFromISR() and xQueueReceiveFromISR()
\r
527 * functions used by tasks.
\r
529 * crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() can only be used to
\r
530 * pass data between a co-routine and and ISR, whereas xQueueSendFromISR() and
\r
531 * xQueueReceiveFromISR() can only be used to pass data between a task and and
\r
534 * crQUEUE_SEND_FROM_ISR can only be called from an ISR to send data to a queue
\r
535 * that is being used from within a co-routine.
\r
537 * See the co-routine section of the WEB documentation for information on
\r
538 * passing data between tasks and co-routines and between ISR's and
\r
541 * @param xQueue The handle to the queue on which the item is to be posted.
\r
543 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
544 * queue. The size of the items the queue will hold was defined when the
\r
545 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
546 * into the queue storage area.
\r
548 * @param xCoRoutinePreviouslyWoken This is included so an ISR can post onto
\r
549 * the same queue multiple times from a single interrupt. The first call
\r
550 * should always pass in pdFALSE. Subsequent calls should pass in
\r
551 * the value returned from the previous call.
\r
553 * @return pdTRUE if a co-routine was woken by posting onto the queue. This is
\r
554 * used by the ISR to determine if a context switch may be required following
\r
559 // A co-routine that blocks on a queue waiting for characters to be received.
\r
560 static void vReceivingCoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
\r
563 portBASE_TYPE xResult;
\r
565 // All co-routines must start with a call to crSTART().
\r
566 crSTART( xHandle );
\r
570 // Wait for data to become available on the queue. This assumes the
\r
571 // queue xCommsRxQueue has already been created!
\r
572 crQUEUE_RECEIVE( xHandle, xCommsRxQueue, &uxLEDToFlash, portMAX_DELAY, &xResult );
\r
574 // Was a character received?
\r
575 if( xResult == pdPASS )
\r
577 // Process the character here.
\r
581 // All co-routines must end with a call to crEND().
\r
585 // An ISR that uses a queue to send characters received on a serial port to
\r
587 void vUART_ISR( void )
\r
590 portBASE_TYPE xCRWokenByPost = pdFALSE;
\r
592 // We loop around reading characters until there are none left in the UART.
\r
593 while( UART_RX_REG_NOT_EMPTY() )
\r
595 // Obtain the character from the UART.
\r
596 cRxedChar = UART_RX_REG;
\r
598 // Post the character onto a queue. xCRWokenByPost will be pdFALSE
\r
599 // the first time around the loop. If the post causes a co-routine
\r
600 // to be woken (unblocked) then xCRWokenByPost will be set to pdTRUE.
\r
601 // In this manner we can ensure that if more than one co-routine is
\r
602 // blocked on the queue only one is woken by this ISR no matter how
\r
603 // many characters are posted to the queue.
\r
604 xCRWokenByPost = crQUEUE_SEND_FROM_ISR( xCommsRxQueue, &cRxedChar, xCRWokenByPost );
\r
607 * \defgroup crQUEUE_SEND_FROM_ISR crQUEUE_SEND_FROM_ISR
\r
610 #define crQUEUE_SEND_FROM_ISR( pxQueue, pvItemToQueue, xCoRoutinePreviouslyWoken ) xQueueCRSendFromISR( pxQueue, pvItemToQueue, xCoRoutinePreviouslyWoken )
\r
616 crQUEUE_SEND_FROM_ISR(
\r
617 xQueueHandle pxQueue,
\r
619 portBASE_TYPE * pxCoRoutineWoken
\r
622 * The macro's crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() are the
\r
623 * co-routine equivalent to the xQueueSendFromISR() and xQueueReceiveFromISR()
\r
624 * functions used by tasks.
\r
626 * crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() can only be used to
\r
627 * pass data between a co-routine and and ISR, whereas xQueueSendFromISR() and
\r
628 * xQueueReceiveFromISR() can only be used to pass data between a task and and
\r
631 * crQUEUE_RECEIVE_FROM_ISR can only be called from an ISR to receive data
\r
632 * from a queue that is being used from within a co-routine (a co-routine
\r
633 * posted to the queue).
\r
635 * See the co-routine section of the WEB documentation for information on
\r
636 * passing data between tasks and co-routines and between ISR's and
\r
639 * @param xQueue The handle to the queue on which the item is to be posted.
\r
641 * @param pvBuffer A pointer to a buffer into which the received item will be
\r
642 * placed. The size of the items the queue will hold was defined when the
\r
643 * queue was created, so this many bytes will be copied from the queue into
\r
646 * @param pxCoRoutineWoken A co-routine may be blocked waiting for space to become
\r
647 * available on the queue. If crQUEUE_RECEIVE_FROM_ISR causes such a
\r
648 * co-routine to unblock *pxCoRoutineWoken will get set to pdTRUE, otherwise
\r
649 * *pxCoRoutineWoken will remain unchanged.
\r
651 * @return pdTRUE an item was successfully received from the queue, otherwise
\r
656 // A co-routine that posts a character to a queue then blocks for a fixed
\r
657 // period. The character is incremented each time.
\r
658 static void vSendingCoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
\r
660 // cChar holds its value while this co-routine is blocked and must therefore
\r
661 // be declared static.
\r
662 static char cCharToTx = 'a';
\r
663 portBASE_TYPE xResult;
\r
665 // All co-routines must start with a call to crSTART().
\r
666 crSTART( xHandle );
\r
670 // Send the next character to the queue.
\r
671 crQUEUE_SEND( xHandle, xCoRoutineQueue, &cCharToTx, NO_DELAY, &xResult );
\r
673 if( xResult == pdPASS )
\r
675 // The character was successfully posted to the queue.
\r
679 // Could not post the character to the queue.
\r
682 // Enable the UART Tx interrupt to cause an interrupt in this
\r
683 // hypothetical UART. The interrupt will obtain the character
\r
684 // from the queue and send it.
\r
685 ENABLE_RX_INTERRUPT();
\r
687 // Increment to the next character then block for a fixed period.
\r
688 // cCharToTx will maintain its value across the delay as it is
\r
689 // declared static.
\r
691 if( cCharToTx > 'x' )
\r
698 // All co-routines must end with a call to crEND().
\r
702 // An ISR that uses a queue to receive characters to send on a UART.
\r
703 void vUART_ISR( void )
\r
706 portBASE_TYPE xCRWokenByPost = pdFALSE;
\r
708 while( UART_TX_REG_EMPTY() )
\r
710 // Are there any characters in the queue waiting to be sent?
\r
711 // xCRWokenByPost will automatically be set to pdTRUE if a co-routine
\r
712 // is woken by the post - ensuring that only a single co-routine is
\r
713 // woken no matter how many times we go around this loop.
\r
714 if( crQUEUE_RECEIVE_FROM_ISR( pxQueue, &cCharToTx, &xCRWokenByPost ) )
\r
716 SEND_CHARACTER( cCharToTx );
\r
720 * \defgroup crQUEUE_RECEIVE_FROM_ISR crQUEUE_RECEIVE_FROM_ISR
\r
723 #define crQUEUE_RECEIVE_FROM_ISR( pxQueue, pvBuffer, pxCoRoutineWoken ) xQueueCRReceiveFromISR( pxQueue, pvBuffer, pxCoRoutineWoken )
\r
726 * This function is intended for internal use by the co-routine macros only.
\r
727 * The macro nature of the co-routine implementation requires that the
\r
728 * prototype appears here. The function should not be used by application
\r
731 * Removes the current co-routine from its ready list and places it in the
\r
732 * appropriate delayed list.
\r
734 void vCoRoutineAddToDelayedList( portTickType xTicksToDelay, xList *pxEventList );
\r
737 * This function is intended for internal use by the queue implementation only.
\r
738 * The function should not be used by application writers.
\r
740 * Removes the highest priority co-routine from the event list and places it in
\r
741 * the pending ready list.
\r
743 signed portBASE_TYPE xCoRoutineRemoveFromEventList( const xList *pxEventList );
\r
749 #endif /* CO_ROUTINE_H */
\r