2 FreeRTOS V5.4.2 - 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 * Looking for a quick start? Then check out the FreeRTOS eBook! *
\r
29 * See http://www.FreeRTOS.org/Documentation for details *
\r
31 ***************************************************************************
\r
35 Please ensure to read the configuration and relevant port sections of the
\r
36 online documentation.
\r
38 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
41 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
44 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
45 licensing and training services.
\r
48 #ifndef INC_FREERTOS_H
\r
49 #error "#include FreeRTOS.h" must appear in source files before "#include croutine.h"
\r
55 #ifndef CO_ROUTINE_H
\r
56 #define CO_ROUTINE_H
\r
64 /* Used to hide the implementation of the co-routine control block. The
\r
65 control block structure however has to be included in the header due to
\r
66 the macro implementation of the co-routine functionality. */
\r
67 typedef void * xCoRoutineHandle;
\r
69 /* Defines the prototype to which co-routine functions must conform. */
\r
70 typedef void (*crCOROUTINE_CODE)( xCoRoutineHandle, unsigned portBASE_TYPE );
\r
72 typedef struct corCoRoutineControlBlock
\r
74 crCOROUTINE_CODE pxCoRoutineFunction;
\r
75 xListItem xGenericListItem; /*< List item used to place the CRCB in ready and blocked queues. */
\r
76 xListItem xEventListItem; /*< List item used to place the CRCB in event lists. */
\r
77 unsigned portBASE_TYPE uxPriority; /*< The priority of the co-routine in relation to other co-routines. */
\r
78 unsigned portBASE_TYPE uxIndex; /*< Used to distinguish between co-routines when multiple co-routines use the same co-routine function. */
\r
79 unsigned portSHORT uxState; /*< Used internally by the co-routine implementation. */
\r
80 } corCRCB; /* Co-routine control block. Note must be identical in size down to uxPriority with tskTCB. */
\r
85 portBASE_TYPE xCoRoutineCreate(
\r
86 crCOROUTINE_CODE pxCoRoutineCode,
\r
87 unsigned portBASE_TYPE uxPriority,
\r
88 unsigned portBASE_TYPE uxIndex
\r
91 * Create a new co-routine and add it to the list of co-routines that are
\r
94 * @param pxCoRoutineCode Pointer to the co-routine function. Co-routine
\r
95 * functions require special syntax - see the co-routine section of the WEB
\r
96 * documentation for more information.
\r
98 * @param uxPriority The priority with respect to other co-routines at which
\r
99 * the co-routine will run.
\r
101 * @param uxIndex Used to distinguish between different co-routines that
\r
102 * execute the same function. See the example below and the co-routine section
\r
103 * of the WEB documentation for further information.
\r
105 * @return pdPASS if the co-routine was successfully created and added to a ready
\r
106 * list, otherwise an error code defined with ProjDefs.h.
\r
110 // Co-routine to be created.
\r
111 void vFlashCoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
\r
113 // Variables in co-routines must be declared static if they must maintain value across a blocking call.
\r
114 // This may not be necessary for const variables.
\r
115 static const char cLedToFlash[ 2 ] = { 5, 6 };
\r
116 static const portTickType xTimeToDelay[ 2 ] = { 200, 400 };
\r
118 // Must start every co-routine with a call to crSTART();
\r
119 crSTART( xHandle );
\r
123 // This co-routine just delays for a fixed period, then toggles
\r
124 // an LED. Two co-routines are created using this function, so
\r
125 // the uxIndex parameter is used to tell the co-routine which
\r
126 // LED to flash and how long to delay. This assumes xQueue has
\r
127 // already been created.
\r
128 vParTestToggleLED( cLedToFlash[ uxIndex ] );
\r
129 crDELAY( xHandle, uxFlashRates[ uxIndex ] );
\r
132 // Must end every co-routine with a call to crEND();
\r
136 // Function that creates two co-routines.
\r
137 void vOtherFunction( void )
\r
139 unsigned char ucParameterToPass;
\r
140 xTaskHandle xHandle;
\r
142 // Create two co-routines at priority 0. The first is given index 0
\r
143 // so (from the code above) toggles LED 5 every 200 ticks. The second
\r
144 // is given index 1 so toggles LED 6 every 400 ticks.
\r
145 for( uxIndex = 0; uxIndex < 2; uxIndex++ )
\r
147 xCoRoutineCreate( vFlashCoRoutine, 0, uxIndex );
\r
151 * \defgroup xCoRoutineCreate xCoRoutineCreate
\r
154 signed portBASE_TYPE xCoRoutineCreate( crCOROUTINE_CODE pxCoRoutineCode, unsigned portBASE_TYPE uxPriority, unsigned portBASE_TYPE uxIndex );
\r
160 void vCoRoutineSchedule( void );</pre>
\r
162 * Run a co-routine.
\r
164 * vCoRoutineSchedule() executes the highest priority co-routine that is able
\r
165 * to run. The co-routine will execute until it either blocks, yields or is
\r
166 * preempted by a task. Co-routines execute cooperatively so one
\r
167 * co-routine cannot be preempted by another, but can be preempted by a task.
\r
169 * If an application comprises of both tasks and co-routines then
\r
170 * vCoRoutineSchedule should be called from the idle task (in an idle task
\r
175 // This idle task hook will schedule a co-routine each time it is called.
\r
176 // The rest of the idle task will execute between co-routine calls.
\r
177 void vApplicationIdleHook( void )
\r
179 vCoRoutineSchedule();
\r
182 // Alternatively, if you do not require any other part of the idle task to
\r
183 // execute, the idle task hook can call vCoRoutineScheduler() within an
\r
185 void vApplicationIdleHook( void )
\r
189 vCoRoutineSchedule();
\r
193 * \defgroup vCoRoutineSchedule vCoRoutineSchedule
\r
196 void vCoRoutineSchedule( void );
\r
201 crSTART( xCoRoutineHandle xHandle );</pre>
\r
203 * This macro MUST always be called at the start of a co-routine function.
\r
207 // Co-routine to be created.
\r
208 void vACoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
\r
210 // Variables in co-routines must be declared static if they must maintain value across a blocking call.
\r
211 static portLONG ulAVariable;
\r
213 // Must start every co-routine with a call to crSTART();
\r
214 crSTART( xHandle );
\r
218 // Co-routine functionality goes here.
\r
221 // Must end every co-routine with a call to crEND();
\r
224 * \defgroup crSTART crSTART
\r
227 #define crSTART( pxCRCB ) switch( ( ( corCRCB * )pxCRCB )->uxState ) { case 0:
\r
234 * This macro MUST always be called at the end of a co-routine function.
\r
238 // Co-routine to be created.
\r
239 void vACoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
\r
241 // Variables in co-routines must be declared static if they must maintain value across a blocking call.
\r
242 static portLONG ulAVariable;
\r
244 // Must start every co-routine with a call to crSTART();
\r
245 crSTART( xHandle );
\r
249 // Co-routine functionality goes here.
\r
252 // Must end every co-routine with a call to crEND();
\r
255 * \defgroup crSTART crSTART
\r
261 * These macros are intended for internal use by the co-routine implementation
\r
262 * only. The macros should not be used directly by application writers.
\r
264 #define crSET_STATE0( xHandle ) ( ( corCRCB * )xHandle)->uxState = (__LINE__ * 2); return; case (__LINE__ * 2):
\r
265 #define crSET_STATE1( xHandle ) ( ( corCRCB * )xHandle)->uxState = ((__LINE__ * 2)+1); return; case ((__LINE__ * 2)+1):
\r
270 crDELAY( xCoRoutineHandle xHandle, portTickType xTicksToDelay );</pre>
\r
272 * Delay a co-routine for a fixed period of time.
\r
274 * crDELAY can only be called from the co-routine function itself - not
\r
275 * from within a function called by the co-routine function. This is because
\r
276 * co-routines do not maintain their own stack.
\r
278 * @param xHandle The handle of the co-routine to delay. This is the xHandle
\r
279 * parameter of the co-routine function.
\r
281 * @param xTickToDelay The number of ticks that the co-routine should delay
\r
282 * for. The actual amount of time this equates to is defined by
\r
283 * configTICK_RATE_HZ (set in FreeRTOSConfig.h). The constant portTICK_RATE_MS
\r
284 * can be used to convert ticks to milliseconds.
\r
288 // Co-routine to be created.
\r
289 void vACoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
\r
291 // Variables in co-routines must be declared static if they must maintain value across a blocking call.
\r
292 // This may not be necessary for const variables.
\r
293 // We are to delay for 200ms.
\r
294 static const xTickType xDelayTime = 200 / portTICK_RATE_MS;
\r
296 // Must start every co-routine with a call to crSTART();
\r
297 crSTART( xHandle );
\r
301 // Delay for 200ms.
\r
302 crDELAY( xHandle, xDelayTime );
\r
304 // Do something here.
\r
307 // Must end every co-routine with a call to crEND();
\r
310 * \defgroup crDELAY crDELAY
\r
313 #define crDELAY( xHandle, xTicksToDelay ) \
\r
314 if( xTicksToDelay > 0 ) \
\r
316 vCoRoutineAddToDelayedList( xTicksToDelay, NULL ); \
\r
318 crSET_STATE0( xHandle );
\r
323 xCoRoutineHandle xHandle,
\r
324 xQueueHandle pxQueue,
\r
325 void *pvItemToQueue,
\r
326 portTickType xTicksToWait,
\r
327 portBASE_TYPE *pxResult
\r
330 * The macro's crQUEUE_SEND() and crQUEUE_RECEIVE() are the co-routine
\r
331 * equivalent to the xQueueSend() and xQueueReceive() functions used by tasks.
\r
333 * crQUEUE_SEND and crQUEUE_RECEIVE can only be used from a co-routine whereas
\r
334 * xQueueSend() and xQueueReceive() can only be used from tasks.
\r
336 * crQUEUE_SEND can only be called from the co-routine function itself - not
\r
337 * from within a function called by the co-routine function. This is because
\r
338 * co-routines do not maintain their own stack.
\r
340 * See the co-routine section of the WEB documentation for information on
\r
341 * passing data between tasks and co-routines and between ISR's and
\r
344 * @param xHandle The handle of the calling co-routine. This is the xHandle
\r
345 * parameter of the co-routine function.
\r
347 * @param pxQueue The handle of the queue on which the data will be posted.
\r
348 * The handle is obtained as the return value when the queue is created using
\r
349 * the xQueueCreate() API function.
\r
351 * @param pvItemToQueue A pointer to the data being posted onto the queue.
\r
352 * The number of bytes of each queued item is specified when the queue is
\r
353 * created. This number of bytes is copied from pvItemToQueue into the queue
\r
356 * @param xTickToDelay The number of ticks that the co-routine should block
\r
357 * to wait for space to become available on the queue, should space not be
\r
358 * available immediately. The actual amount of time this equates to is defined
\r
359 * by configTICK_RATE_HZ (set in FreeRTOSConfig.h). The constant
\r
360 * portTICK_RATE_MS can be used to convert ticks to milliseconds (see example
\r
363 * @param pxResult The variable pointed to by pxResult will be set to pdPASS if
\r
364 * data was successfully posted onto the queue, otherwise it will be set to an
\r
365 * error defined within ProjDefs.h.
\r
369 // Co-routine function that blocks for a fixed period then posts a number onto
\r
371 static void prvCoRoutineFlashTask( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
\r
373 // Variables in co-routines must be declared static if they must maintain value across a blocking call.
\r
374 static portBASE_TYPE xNumberToPost = 0;
\r
375 static portBASE_TYPE xResult;
\r
377 // Co-routines must begin with a call to crSTART().
\r
378 crSTART( xHandle );
\r
382 // This assumes the queue has already been created.
\r
383 crQUEUE_SEND( xHandle, xCoRoutineQueue, &xNumberToPost, NO_DELAY, &xResult );
\r
385 if( xResult != pdPASS )
\r
387 // The message was not posted!
\r
390 // Increment the number to be posted onto the queue.
\r
393 // Delay for 100 ticks.
\r
394 crDELAY( xHandle, 100 );
\r
397 // Co-routines must end with a call to crEND().
\r
400 * \defgroup crQUEUE_SEND crQUEUE_SEND
\r
403 #define crQUEUE_SEND( xHandle, pxQueue, pvItemToQueue, xTicksToWait, pxResult ) \
\r
405 *pxResult = xQueueCRSend( pxQueue, pvItemToQueue, xTicksToWait ); \
\r
406 if( *pxResult == errQUEUE_BLOCKED ) \
\r
408 crSET_STATE0( xHandle ); \
\r
409 *pxResult = xQueueCRSend( pxQueue, pvItemToQueue, 0 ); \
\r
411 if( *pxResult == errQUEUE_YIELD ) \
\r
413 crSET_STATE1( xHandle ); \
\r
414 *pxResult = pdPASS; \
\r
422 xCoRoutineHandle xHandle,
\r
423 xQueueHandle pxQueue,
\r
425 portTickType xTicksToWait,
\r
426 portBASE_TYPE *pxResult
\r
429 * The macro's crQUEUE_SEND() and crQUEUE_RECEIVE() are the co-routine
\r
430 * equivalent to the xQueueSend() and xQueueReceive() functions used by tasks.
\r
432 * crQUEUE_SEND and crQUEUE_RECEIVE can only be used from a co-routine whereas
\r
433 * xQueueSend() and xQueueReceive() can only be used from tasks.
\r
435 * crQUEUE_RECEIVE can only be called from the co-routine function itself - not
\r
436 * from within a function called by the co-routine function. This is because
\r
437 * co-routines do not maintain their own stack.
\r
439 * See the co-routine section of the WEB documentation for information on
\r
440 * passing data between tasks and co-routines and between ISR's and
\r
443 * @param xHandle The handle of the calling co-routine. This is the xHandle
\r
444 * parameter of the co-routine function.
\r
446 * @param pxQueue The handle of the queue from which the data will be received.
\r
447 * The handle is obtained as the return value when the queue is created using
\r
448 * the xQueueCreate() API function.
\r
450 * @param pvBuffer The buffer into which the received item is to be copied.
\r
451 * The number of bytes of each queued item is specified when the queue is
\r
452 * created. This number of bytes is copied into pvBuffer.
\r
454 * @param xTickToDelay The number of ticks that the co-routine should block
\r
455 * to wait for data to become available from the queue, should data not be
\r
456 * available immediately. The actual amount of time this equates to is defined
\r
457 * by configTICK_RATE_HZ (set in FreeRTOSConfig.h). The constant
\r
458 * portTICK_RATE_MS can be used to convert ticks to milliseconds (see the
\r
459 * crQUEUE_SEND example).
\r
461 * @param pxResult The variable pointed to by pxResult will be set to pdPASS if
\r
462 * data was successfully retrieved from the queue, otherwise it will be set to
\r
463 * an error code as defined within ProjDefs.h.
\r
467 // A co-routine receives the number of an LED to flash from a queue. It
\r
468 // blocks on the queue until the number is received.
\r
469 static void prvCoRoutineFlashWorkTask( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
\r
471 // Variables in co-routines must be declared static if they must maintain value across a blocking call.
\r
472 static portBASE_TYPE xResult;
\r
473 static unsigned portBASE_TYPE uxLEDToFlash;
\r
475 // All co-routines must start with a call to crSTART().
\r
476 crSTART( xHandle );
\r
480 // Wait for data to become available on the queue.
\r
481 crQUEUE_RECEIVE( xHandle, xCoRoutineQueue, &uxLEDToFlash, portMAX_DELAY, &xResult );
\r
483 if( xResult == pdPASS )
\r
485 // We received the LED to flash - flash it!
\r
486 vParTestToggleLED( uxLEDToFlash );
\r
492 * \defgroup crQUEUE_RECEIVE crQUEUE_RECEIVE
\r
495 #define crQUEUE_RECEIVE( xHandle, pxQueue, pvBuffer, xTicksToWait, pxResult ) \
\r
497 *pxResult = xQueueCRReceive( pxQueue, pvBuffer, xTicksToWait ); \
\r
498 if( *pxResult == errQUEUE_BLOCKED ) \
\r
500 crSET_STATE0( xHandle ); \
\r
501 *pxResult = xQueueCRReceive( pxQueue, pvBuffer, 0 ); \
\r
503 if( *pxResult == errQUEUE_YIELD ) \
\r
505 crSET_STATE1( xHandle ); \
\r
506 *pxResult = pdPASS; \
\r
513 crQUEUE_SEND_FROM_ISR(
\r
514 xQueueHandle pxQueue,
\r
515 void *pvItemToQueue,
\r
516 portBASE_TYPE xCoRoutinePreviouslyWoken
\r
519 * The macro's crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() are the
\r
520 * co-routine equivalent to the xQueueSendFromISR() and xQueueReceiveFromISR()
\r
521 * functions used by tasks.
\r
523 * crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() can only be used to
\r
524 * pass data between a co-routine and and ISR, whereas xQueueSendFromISR() and
\r
525 * xQueueReceiveFromISR() can only be used to pass data between a task and and
\r
528 * crQUEUE_SEND_FROM_ISR can only be called from an ISR to send data to a queue
\r
529 * that is being used from within a co-routine.
\r
531 * See the co-routine section of the WEB documentation for information on
\r
532 * passing data between tasks and co-routines and between ISR's and
\r
535 * @param xQueue The handle to the queue on which the item is to be posted.
\r
537 * @param pvItemToQueue A pointer to the item that is to be placed on the
\r
538 * queue. The size of the items the queue will hold was defined when the
\r
539 * queue was created, so this many bytes will be copied from pvItemToQueue
\r
540 * into the queue storage area.
\r
542 * @param xCoRoutinePreviouslyWoken This is included so an ISR can post onto
\r
543 * the same queue multiple times from a single interrupt. The first call
\r
544 * should always pass in pdFALSE. Subsequent calls should pass in
\r
545 * the value returned from the previous call.
\r
547 * @return pdTRUE if a co-routine was woken by posting onto the queue. This is
\r
548 * used by the ISR to determine if a context switch may be required following
\r
553 // A co-routine that blocks on a queue waiting for characters to be received.
\r
554 static void vReceivingCoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
\r
556 portCHAR cRxedChar;
\r
557 portBASE_TYPE xResult;
\r
559 // All co-routines must start with a call to crSTART().
\r
560 crSTART( xHandle );
\r
564 // Wait for data to become available on the queue. This assumes the
\r
565 // queue xCommsRxQueue has already been created!
\r
566 crQUEUE_RECEIVE( xHandle, xCommsRxQueue, &uxLEDToFlash, portMAX_DELAY, &xResult );
\r
568 // Was a character received?
\r
569 if( xResult == pdPASS )
\r
571 // Process the character here.
\r
575 // All co-routines must end with a call to crEND().
\r
579 // An ISR that uses a queue to send characters received on a serial port to
\r
581 void vUART_ISR( void )
\r
583 portCHAR cRxedChar;
\r
584 portBASE_TYPE xCRWokenByPost = pdFALSE;
\r
586 // We loop around reading characters until there are none left in the UART.
\r
587 while( UART_RX_REG_NOT_EMPTY() )
\r
589 // Obtain the character from the UART.
\r
590 cRxedChar = UART_RX_REG;
\r
592 // Post the character onto a queue. xCRWokenByPost will be pdFALSE
\r
593 // the first time around the loop. If the post causes a co-routine
\r
594 // to be woken (unblocked) then xCRWokenByPost will be set to pdTRUE.
\r
595 // In this manner we can ensure that if more than one co-routine is
\r
596 // blocked on the queue only one is woken by this ISR no matter how
\r
597 // many characters are posted to the queue.
\r
598 xCRWokenByPost = crQUEUE_SEND_FROM_ISR( xCommsRxQueue, &cRxedChar, xCRWokenByPost );
\r
601 * \defgroup crQUEUE_SEND_FROM_ISR crQUEUE_SEND_FROM_ISR
\r
604 #define crQUEUE_SEND_FROM_ISR( pxQueue, pvItemToQueue, xCoRoutinePreviouslyWoken ) xQueueCRSendFromISR( pxQueue, pvItemToQueue, xCoRoutinePreviouslyWoken )
\r
610 crQUEUE_SEND_FROM_ISR(
\r
611 xQueueHandle pxQueue,
\r
613 portBASE_TYPE * pxCoRoutineWoken
\r
616 * The macro's crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() are the
\r
617 * co-routine equivalent to the xQueueSendFromISR() and xQueueReceiveFromISR()
\r
618 * functions used by tasks.
\r
620 * crQUEUE_SEND_FROM_ISR() and crQUEUE_RECEIVE_FROM_ISR() can only be used to
\r
621 * pass data between a co-routine and and ISR, whereas xQueueSendFromISR() and
\r
622 * xQueueReceiveFromISR() can only be used to pass data between a task and and
\r
625 * crQUEUE_RECEIVE_FROM_ISR can only be called from an ISR to receive data
\r
626 * from a queue that is being used from within a co-routine (a co-routine
\r
627 * posted to the queue).
\r
629 * See the co-routine section of the WEB documentation for information on
\r
630 * passing data between tasks and co-routines and between ISR's and
\r
633 * @param xQueue The handle to the queue on which the item is to be posted.
\r
635 * @param pvBuffer A pointer to a buffer into which the received item will be
\r
636 * placed. The size of the items the queue will hold was defined when the
\r
637 * queue was created, so this many bytes will be copied from the queue into
\r
640 * @param pxCoRoutineWoken A co-routine may be blocked waiting for space to become
\r
641 * available on the queue. If crQUEUE_RECEIVE_FROM_ISR causes such a
\r
642 * co-routine to unblock *pxCoRoutineWoken will get set to pdTRUE, otherwise
\r
643 * *pxCoRoutineWoken will remain unchanged.
\r
645 * @return pdTRUE an item was successfully received from the queue, otherwise
\r
650 // A co-routine that posts a character to a queue then blocks for a fixed
\r
651 // period. The character is incremented each time.
\r
652 static void vSendingCoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
\r
654 // cChar holds its value while this co-routine is blocked and must therefore
\r
655 // be declared static.
\r
656 static portCHAR cCharToTx = 'a';
\r
657 portBASE_TYPE xResult;
\r
659 // All co-routines must start with a call to crSTART().
\r
660 crSTART( xHandle );
\r
664 // Send the next character to the queue.
\r
665 crQUEUE_SEND( xHandle, xCoRoutineQueue, &cCharToTx, NO_DELAY, &xResult );
\r
667 if( xResult == pdPASS )
\r
669 // The character was successfully posted to the queue.
\r
673 // Could not post the character to the queue.
\r
676 // Enable the UART Tx interrupt to cause an interrupt in this
\r
677 // hypothetical UART. The interrupt will obtain the character
\r
678 // from the queue and send it.
\r
679 ENABLE_RX_INTERRUPT();
\r
681 // Increment to the next character then block for a fixed period.
\r
682 // cCharToTx will maintain its value across the delay as it is
\r
683 // declared static.
\r
685 if( cCharToTx > 'x' )
\r
692 // All co-routines must end with a call to crEND().
\r
696 // An ISR that uses a queue to receive characters to send on a UART.
\r
697 void vUART_ISR( void )
\r
699 portCHAR cCharToTx;
\r
700 portBASE_TYPE xCRWokenByPost = pdFALSE;
\r
702 while( UART_TX_REG_EMPTY() )
\r
704 // Are there any characters in the queue waiting to be sent?
\r
705 // xCRWokenByPost will automatically be set to pdTRUE if a co-routine
\r
706 // is woken by the post - ensuring that only a single co-routine is
\r
707 // woken no matter how many times we go around this loop.
\r
708 if( crQUEUE_RECEIVE_FROM_ISR( pxQueue, &cCharToTx, &xCRWokenByPost ) )
\r
710 SEND_CHARACTER( cCharToTx );
\r
714 * \defgroup crQUEUE_RECEIVE_FROM_ISR crQUEUE_RECEIVE_FROM_ISR
\r
717 #define crQUEUE_RECEIVE_FROM_ISR( pxQueue, pvBuffer, pxCoRoutineWoken ) xQueueCRReceiveFromISR( pxQueue, pvBuffer, pxCoRoutineWoken )
\r
720 * This function is intended for internal use by the co-routine macros only.
\r
721 * The macro nature of the co-routine implementation requires that the
\r
722 * prototype appears here. The function should not be used by application
\r
725 * Removes the current co-routine from its ready list and places it in the
\r
726 * appropriate delayed list.
\r
728 void vCoRoutineAddToDelayedList( portTickType xTicksToDelay, xList *pxEventList );
\r
731 * This function is intended for internal use by the queue implementation only.
\r
732 * The function should not be used by application writers.
\r
734 * Removes the highest priority co-routine from the event list and places it in
\r
735 * the pending ready list.
\r
737 signed portBASE_TYPE xCoRoutineRemoveFromEventList( const xList *pxEventList );
\r
743 #endif /* CO_ROUTINE_H */
\r