00001 /* 00002 FreeRTOS V6.0.0 - Copyright (C) 2009 Real Time Engineers Ltd. 00003 00004 *************************************************************************** 00005 * * 00006 * If you are: * 00007 * * 00008 * + New to FreeRTOS, * 00009 * + Wanting to learn FreeRTOS or multitasking in general quickly * 00010 * + Looking for basic training, * 00011 * + Wanting to improve your FreeRTOS skills and productivity * 00012 * * 00013 * then take a look at the FreeRTOS eBook * 00014 * * 00015 * "Using the FreeRTOS Real Time Kernel - a Practical Guide" * 00016 * http://www.FreeRTOS.org/Documentation * 00017 * * 00018 * A pdf reference manual is also available. Both are usually delivered * 00019 * to your inbox within 20 minutes to two hours when purchased between 8am * 00020 * and 8pm GMT (although please allow up to 24 hours in case of * 00021 * exceptional circumstances). Thank you for your support! * 00022 * * 00023 *************************************************************************** 00024 00025 This file is part of the FreeRTOS distribution. 00026 00027 FreeRTOS is free software; you can redistribute it and/or modify it under 00028 the terms of the GNU General Public License (version 2) as published by the 00029 Free Software Foundation AND MODIFIED BY the FreeRTOS exception. 00030 ***NOTE*** The exception to the GPL is included to allow you to distribute 00031 a combined work that includes FreeRTOS without being obliged to provide the 00032 source code for proprietary components outside of the FreeRTOS kernel. 00033 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT 00034 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00035 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 00036 more details. You should have received a copy of the GNU General Public 00037 License and the FreeRTOS license exception along with FreeRTOS; if not it 00038 can be viewed here: http://www.freertos.org/a00114.html and also obtained 00039 by writing to Richard Barry, contact details for whom are available on the 00040 FreeRTOS WEB site. 00041 00042 1 tab == 4 spaces! 00043 00044 http://www.FreeRTOS.org - Documentation, latest information, license and 00045 contact details. 00046 00047 http://www.SafeRTOS.com - A version that is certified for use in safety 00048 critical systems. 00049 00050 http://www.OpenRTOS.com - Commercial support, development, porting, 00051 licensing and training services. 00052 */ 00053 00054 #ifndef INC_FREERTOS_H 00055 #error "#include FreeRTOS.h" must appear in source files before "#include croutine.h" 00056 #endif 00057 00058 00059 00060 00061 #ifndef CO_ROUTINE_H 00062 #define CO_ROUTINE_H 00063 00064 #include "list.h" 00065 00066 #ifdef __cplusplus 00067 extern "C" { 00068 #endif 00069 00070 /* Used to hide the implementation of the co-routine control block. The 00071 control block structure however has to be included in the header due to 00072 the macro implementation of the co-routine functionality. */ 00073 typedef void * xCoRoutineHandle; 00074 00075 /* Defines the prototype to which co-routine functions must conform. */ 00076 typedef void (*crCOROUTINE_CODE)( xCoRoutineHandle, unsigned portBASE_TYPE ); 00077 00078 typedef struct corCoRoutineControlBlock 00079 { 00080 crCOROUTINE_CODE pxCoRoutineFunction; 00081 xListItem xGenericListItem; /*< List item used to place the CRCB in ready and blocked queues. */ 00082 xListItem xEventListItem; /*< List item used to place the CRCB in event lists. */ 00083 unsigned portBASE_TYPE uxPriority; /*< The priority of the co-routine in relation to other co-routines. */ 00084 unsigned portBASE_TYPE uxIndex; /*< Used to distinguish between co-routines when multiple co-routines use the same co-routine function. */ 00085 unsigned short uxState; /*< Used internally by the co-routine implementation. */ 00086 } corCRCB; /* Co-routine control block. Note must be identical in size down to uxPriority with tskTCB. */ 00087 00160 signed portBASE_TYPE xCoRoutineCreate( crCOROUTINE_CODE pxCoRoutineCode, unsigned portBASE_TYPE uxPriority, unsigned portBASE_TYPE uxIndex ); 00161 00162 00202 void vCoRoutineSchedule( void ); 00203 00233 #define crSTART( pxCRCB ) switch( ( ( corCRCB * )pxCRCB )->uxState ) { case 0: 00234 00264 #define crEND() } 00265 00266 /* 00267 * These macros are intended for internal use by the co-routine implementation 00268 * only. The macros should not be used directly by application writers. 00269 */ 00270 #define crSET_STATE0( xHandle ) ( ( corCRCB * )xHandle)->uxState = (__LINE__ * 2); return; case (__LINE__ * 2): 00271 #define crSET_STATE1( xHandle ) ( ( corCRCB * )xHandle)->uxState = ((__LINE__ * 2)+1); return; case ((__LINE__ * 2)+1): 00272 00319 #define crDELAY( xHandle, xTicksToDelay ) \ 00320 if( xTicksToDelay > 0 ) \ 00321 { \ 00322 vCoRoutineAddToDelayedList( xTicksToDelay, NULL ); \ 00323 } \ 00324 crSET_STATE0( xHandle ); 00325 00409 #define crQUEUE_SEND( xHandle, pxQueue, pvItemToQueue, xTicksToWait, pxResult ) \ 00410 { \ 00411 *pxResult = xQueueCRSend( pxQueue, pvItemToQueue, xTicksToWait ); \ 00412 if( *pxResult == errQUEUE_BLOCKED ) \ 00413 { \ 00414 crSET_STATE0( xHandle ); \ 00415 *pxResult = xQueueCRSend( pxQueue, pvItemToQueue, 0 ); \ 00416 } \ 00417 if( *pxResult == errQUEUE_YIELD ) \ 00418 { \ 00419 crSET_STATE1( xHandle ); \ 00420 *pxResult = pdPASS; \ 00421 } \ 00422 } 00423 00501 #define crQUEUE_RECEIVE( xHandle, pxQueue, pvBuffer, xTicksToWait, pxResult ) \ 00502 { \ 00503 *pxResult = xQueueCRReceive( pxQueue, pvBuffer, xTicksToWait ); \ 00504 if( *pxResult == errQUEUE_BLOCKED ) \ 00505 { \ 00506 crSET_STATE0( xHandle ); \ 00507 *pxResult = xQueueCRReceive( pxQueue, pvBuffer, 0 ); \ 00508 } \ 00509 if( *pxResult == errQUEUE_YIELD ) \ 00510 { \ 00511 crSET_STATE1( xHandle ); \ 00512 *pxResult = pdPASS; \ 00513 } \ 00514 } 00515 00610 #define crQUEUE_SEND_FROM_ISR( pxQueue, pvItemToQueue, xCoRoutinePreviouslyWoken ) xQueueCRSendFromISR( pxQueue, pvItemToQueue, xCoRoutinePreviouslyWoken ) 00611 00612 00723 #define crQUEUE_RECEIVE_FROM_ISR( pxQueue, pvBuffer, pxCoRoutineWoken ) xQueueCRReceiveFromISR( pxQueue, pvBuffer, pxCoRoutineWoken ) 00724 00725 /* 00726 * This function is intended for internal use by the co-routine macros only. 00727 * The macro nature of the co-routine implementation requires that the 00728 * prototype appears here. The function should not be used by application 00729 * writers. 00730 * 00731 * Removes the current co-routine from its ready list and places it in the 00732 * appropriate delayed list. 00733 */ 00734 void vCoRoutineAddToDelayedList( portTickType xTicksToDelay, xList *pxEventList ); 00735 00736 /* 00737 * This function is intended for internal use by the queue implementation only. 00738 * The function should not be used by application writers. 00739 * 00740 * Removes the highest priority co-routine from the event list and places it in 00741 * the pending ready list. 00742 */ 00743 signed portBASE_TYPE xCoRoutineRemoveFromEventList( const xList *pxEventList ); 00744 00745 #ifdef __cplusplus 00746 } 00747 #endif 00748 00749 #endif /* CO_ROUTINE_H */