uc-sdk
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
croutine.h
Go to the documentation of this file.
1 /*
2  FreeRTOS V7.5.3 - Copyright (C) 2013 Real Time Engineers Ltd.
3  All rights reserved
4 
5  VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
6 
7  ***************************************************************************
8  * *
9  * FreeRTOS provides completely free yet professionally developed, *
10  * robust, strictly quality controlled, supported, and cross *
11  * platform software that has become a de facto standard. *
12  * *
13  * Help yourself get started quickly and support the FreeRTOS *
14  * project by purchasing a FreeRTOS tutorial book, reference *
15  * manual, or both from: http://www.FreeRTOS.org/Documentation *
16  * *
17  * Thank you! *
18  * *
19  ***************************************************************************
20 
21  This file is part of the FreeRTOS distribution.
22 
23  FreeRTOS is free software; you can redistribute it and/or modify it under
24  the terms of the GNU General Public License (version 2) as published by the
25  Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
26 
27  >>! NOTE: The modification to the GPL is included to allow you to distribute
28  >>! a combined work that includes FreeRTOS without being obliged to provide
29  >>! the source code for proprietary components outside of the FreeRTOS
30  >>! kernel.
31 
32  FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
33  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
34  FOR A PARTICULAR PURPOSE. Full license text is available from the following
35  link: http://www.freertos.org/a00114.html
36 
37  1 tab == 4 spaces!
38 
39  ***************************************************************************
40  * *
41  * Having a problem? Start by reading the FAQ "My application does *
42  * not run, what could be wrong?" *
43  * *
44  * http://www.FreeRTOS.org/FAQHelp.html *
45  * *
46  ***************************************************************************
47 
48  http://www.FreeRTOS.org - Documentation, books, training, latest versions,
49  license and Real Time Engineers Ltd. contact details.
50 
51  http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
52  including FreeRTOS+Trace - an indispensable productivity tool, a DOS
53  compatible FAT file system, and our tiny thread aware UDP/IP stack.
54 
55  http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
56  Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
57  licenses offer ticketed support, indemnification and middleware.
58 
59  http://www.SafeRTOS.com - High Integrity Systems also provide a safety
60  engineered and independently SIL3 certified version for use in safety and
61  mission critical applications that require provable dependability.
62 
63  1 tab == 4 spaces!
64 */
65 
66 #ifndef CO_ROUTINE_H
67 #define CO_ROUTINE_H
68 
69 #ifndef INC_FREERTOS_H
70  #error "include FreeRTOS.h must appear in source files before include croutine.h"
71 #endif
72 
73 #include "list.h"
74 
75 #ifdef __cplusplus
76 extern "C" {
77 #endif
78 
79 /* Used to hide the implementation of the co-routine control block. The
80 control block structure however has to be included in the header due to
81 the macro implementation of the co-routine functionality. */
82 typedef void * xCoRoutineHandle;
83 
84 /* Defines the prototype to which co-routine functions must conform. */
85 typedef void (*crCOROUTINE_CODE)( xCoRoutineHandle, unsigned portBASE_TYPE );
86 
88 {
90  xListItem xGenericListItem; /*< List item used to place the CRCB in ready and blocked queues. */
91  xListItem xEventListItem; /*< List item used to place the CRCB in event lists. */
92  unsigned portBASE_TYPE uxPriority; /*< The priority of the co-routine in relation to other co-routines. */
93  unsigned portBASE_TYPE uxIndex; /*< Used to distinguish between co-routines when multiple co-routines use the same co-routine function. */
94  unsigned short uxState; /*< Used internally by the co-routine implementation. */
95 } corCRCB; /* Co-routine control block. Note must be identical in size down to uxPriority with tskTCB. */
96 
169 signed portBASE_TYPE xCoRoutineCreate( crCOROUTINE_CODE pxCoRoutineCode, unsigned portBASE_TYPE uxPriority, unsigned portBASE_TYPE uxIndex );
170 
171 
211 void vCoRoutineSchedule( void );
212 
242 #define crSTART( pxCRCB ) switch( ( ( corCRCB * )( pxCRCB ) )->uxState ) { case 0:
243 
273 #define crEND() }
274 
275 /*
276  * These macros are intended for internal use by the co-routine implementation
277  * only. The macros should not be used directly by application writers.
278  */
279 #define crSET_STATE0( xHandle ) ( ( corCRCB * )( xHandle ) )->uxState = (__LINE__ * 2); return; case (__LINE__ * 2):
280 #define crSET_STATE1( xHandle ) ( ( corCRCB * )( xHandle ) )->uxState = ((__LINE__ * 2)+1); return; case ((__LINE__ * 2)+1):
281 
328 #define crDELAY( xHandle, xTicksToDelay ) \
329  if( ( xTicksToDelay ) > 0 ) \
330  { \
331  vCoRoutineAddToDelayedList( ( xTicksToDelay ), NULL ); \
332  } \
333  crSET_STATE0( ( xHandle ) );
334 
418 #define crQUEUE_SEND( xHandle, pxQueue, pvItemToQueue, xTicksToWait, pxResult ) \
419 { \
420  *( pxResult ) = xQueueCRSend( ( pxQueue) , ( pvItemToQueue) , ( xTicksToWait ) ); \
421  if( *( pxResult ) == errQUEUE_BLOCKED ) \
422  { \
423  crSET_STATE0( ( xHandle ) ); \
424  *pxResult = xQueueCRSend( ( pxQueue ), ( pvItemToQueue ), 0 ); \
425  } \
426  if( *pxResult == errQUEUE_YIELD ) \
427  { \
428  crSET_STATE1( ( xHandle ) ); \
429  *pxResult = pdPASS; \
430  } \
431 }
432 
510 #define crQUEUE_RECEIVE( xHandle, pxQueue, pvBuffer, xTicksToWait, pxResult ) \
511 { \
512  *( pxResult ) = xQueueCRReceive( ( pxQueue) , ( pvBuffer ), ( xTicksToWait ) ); \
513  if( *( pxResult ) == errQUEUE_BLOCKED ) \
514  { \
515  crSET_STATE0( ( xHandle ) ); \
516  *( pxResult ) = xQueueCRReceive( ( pxQueue) , ( pvBuffer ), 0 ); \
517  } \
518  if( *( pxResult ) == errQUEUE_YIELD ) \
519  { \
520  crSET_STATE1( ( xHandle ) ); \
521  *( pxResult ) = pdPASS; \
522  } \
523 }
524 
619 #define crQUEUE_SEND_FROM_ISR( pxQueue, pvItemToQueue, xCoRoutinePreviouslyWoken ) xQueueCRSendFromISR( ( pxQueue ), ( pvItemToQueue ), ( xCoRoutinePreviouslyWoken ) )
620 
621 
732 #define crQUEUE_RECEIVE_FROM_ISR( pxQueue, pvBuffer, pxCoRoutineWoken ) xQueueCRReceiveFromISR( ( pxQueue ), ( pvBuffer ), ( pxCoRoutineWoken ) )
733 
734 /*
735  * This function is intended for internal use by the co-routine macros only.
736  * The macro nature of the co-routine implementation requires that the
737  * prototype appears here. The function should not be used by application
738  * writers.
739  *
740  * Removes the current co-routine from its ready list and places it in the
741  * appropriate delayed list.
742  */
743 void vCoRoutineAddToDelayedList( portTickType xTicksToDelay, xList *pxEventList );
744 
745 /*
746  * This function is intended for internal use by the queue implementation only.
747  * The function should not be used by application writers.
748  *
749  * Removes the highest priority co-routine from the event list and places it in
750  * the pending ready list.
751  */
752 signed portBASE_TYPE xCoRoutineRemoveFromEventList( const xList *pxEventList );
753 
754 #ifdef __cplusplus
755 }
756 #endif
757 
758 #endif /* CO_ROUTINE_H */