FreeRTOS Tetris
croutine.h
1 /*
2  FreeRTOS V9.0.0 - Copyright (C) 2016 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  This file is part of the FreeRTOS distribution.
8 
9  FreeRTOS is free software; you can redistribute it and/or modify it under
10  the terms of the GNU General Public License (version 2) as published by the
11  Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
12 
13  ***************************************************************************
14  >>! NOTE: The modification to the GPL is included to allow you to !<<
15  >>! distribute a combined work that includes FreeRTOS without being !<<
16  >>! obliged to provide the source code for proprietary components !<<
17  >>! outside of the FreeRTOS kernel. !<<
18  ***************************************************************************
19 
20  FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
21  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22  FOR A PARTICULAR PURPOSE. Full license text is available on the following
23  link: http://www.freertos.org/a00114.html
24 
25  ***************************************************************************
26  * *
27  * FreeRTOS provides completely free yet professionally developed, *
28  * robust, strictly quality controlled, supported, and cross *
29  * platform software that is more than just the market leader, it *
30  * is the industry's de facto standard. *
31  * *
32  * Help yourself get started quickly while simultaneously helping *
33  * to support the FreeRTOS project by purchasing a FreeRTOS *
34  * tutorial book, reference manual, or both: *
35  * http://www.FreeRTOS.org/Documentation *
36  * *
37  ***************************************************************************
38 
39  http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
40  the FAQ page "My application does not run, what could be wrong?". Have you
41  defined configASSERT()?
42 
43  http://www.FreeRTOS.org/support - In return for receiving this top quality
44  embedded software for free we request you assist our global community by
45  participating in the support forum.
46 
47  http://www.FreeRTOS.org/training - Investing in training allows your team to
48  be as productive as possible as early as possible. Now you can receive
49  FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
50  Ltd, and the world's leading authority on the world's leading RTOS.
51 
52  http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
53  including FreeRTOS+Trace - an indispensable productivity tool, a DOS
54  compatible FAT file system, and our tiny thread aware UDP/IP stack.
55 
56  http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
57  Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
58 
59  http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
60  Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
61  licenses offer ticketed support, indemnification and commercial middleware.
62 
63  http://www.SafeRTOS.com - High Integrity Systems also provide a safety
64  engineered and independently SIL3 certified version for use in safety and
65  mission critical applications that require provable dependability.
66 
67  1 tab == 4 spaces!
68 */
69 
74 #ifndef CO_ROUTINE_H
75 #define CO_ROUTINE_H
76 
77 #ifndef INC_FREERTOS_H
78 #error "include FreeRTOS.h must appear in source files before include croutine.h"
79 #endif
80 
81 #include "list.h"
82 
83 #ifdef __cplusplus
84 extern "C" {
85 #endif
86 
87 /* Used to hide the implementation of the co-routine control block. The
88 control block structure however has to be included in the header due to
89 the macro implementation of the co-routine functionality. */
90 typedef void *CoRoutineHandle_t;
91 
92 /* Defines the prototype to which co-routine functions must conform. */
93 typedef void (*crCOROUTINE_CODE)(CoRoutineHandle_t, UBaseType_t);
94 
95 typedef struct corCoRoutineControlBlock {
96  crCOROUTINE_CODE pxCoRoutineFunction;
97  ListItem_t xGenericListItem; /*< List item used to place the CRCB in ready and blocked queues. */
98  ListItem_t xEventListItem; /*< List item used to place the CRCB in event lists. */
99  UBaseType_t uxPriority; /*< The priority of the co-routine in relation to other co-routines. */
100  UBaseType_t uxIndex; /*< Used to distinguish between co-routines when multiple co-routines use the same co-routine function. */
101  uint16_t uxState; /*< Used internally by the co-routine implementation. */
102 } CRCB_t; /* Co-routine control block. Note must be identical in size down to uxPriority with TCB_t. */
103 
176 BaseType_t xCoRoutineCreate(crCOROUTINE_CODE pxCoRoutineCode, UBaseType_t uxPriority, UBaseType_t uxIndex);
177 
178 
218 void vCoRoutineSchedule(void);
219 
249 #define crSTART( pxCRCB ) switch( ( ( CRCB_t * )( pxCRCB ) )->uxState ) { case 0:
250 
280 #define crEND() }
281 
282 /*
283  * These macros are intended for internal use by the co-routine implementation
284  * only. The macros should not be used directly by application writers.
285  */
286 #define crSET_STATE0( xHandle ) ( ( CRCB_t * )( xHandle ) )->uxState = (__LINE__ * 2); return; case (__LINE__ * 2):
287 #define crSET_STATE1( xHandle ) ( ( CRCB_t * )( xHandle ) )->uxState = ((__LINE__ * 2)+1); return; case ((__LINE__ * 2)+1):
288 
335 #define crDELAY( xHandle, xTicksToDelay ) \
336  if( ( xTicksToDelay ) > 0 ) \
337  { \
338  vCoRoutineAddToDelayedList( ( xTicksToDelay ), NULL ); \
339  } \
340  crSET_STATE0( ( xHandle ) );
341 
425 #define crQUEUE_SEND( xHandle, pxQueue, pvItemToQueue, xTicksToWait, pxResult ) \
426  { \
427  *( pxResult ) = xQueueCRSend( ( pxQueue) , ( pvItemToQueue) , ( xTicksToWait ) ); \
428  if( *( pxResult ) == errQUEUE_BLOCKED ) \
429  { \
430  crSET_STATE0( ( xHandle ) ); \
431  *pxResult = xQueueCRSend( ( pxQueue ), ( pvItemToQueue ), 0 ); \
432  } \
433  if( *pxResult == errQUEUE_YIELD ) \
434  { \
435  crSET_STATE1( ( xHandle ) ); \
436  *pxResult = pdPASS; \
437  } \
438  }
439 
517 #define crQUEUE_RECEIVE( xHandle, pxQueue, pvBuffer, xTicksToWait, pxResult ) \
518  { \
519  *( pxResult ) = xQueueCRReceive( ( pxQueue) , ( pvBuffer ), ( xTicksToWait ) ); \
520  if( *( pxResult ) == errQUEUE_BLOCKED ) \
521  { \
522  crSET_STATE0( ( xHandle ) ); \
523  *( pxResult ) = xQueueCRReceive( ( pxQueue) , ( pvBuffer ), 0 ); \
524  } \
525  if( *( pxResult ) == errQUEUE_YIELD ) \
526  { \
527  crSET_STATE1( ( xHandle ) ); \
528  *( pxResult ) = pdPASS; \
529  } \
530  }
531 
626 #define crQUEUE_SEND_FROM_ISR( pxQueue, pvItemToQueue, xCoRoutinePreviouslyWoken ) xQueueCRSendFromISR( ( pxQueue ), ( pvItemToQueue ), ( xCoRoutinePreviouslyWoken ) )
627 
628 
739 #define crQUEUE_RECEIVE_FROM_ISR( pxQueue, pvBuffer, pxCoRoutineWoken ) xQueueCRReceiveFromISR( ( pxQueue ), ( pvBuffer ), ( pxCoRoutineWoken ) )
740 
741 /*
742  * This function is intended for internal use by the co-routine macros only.
743  * The macro nature of the co-routine implementation requires that the
744  * prototype appears here. The function should not be used by application
745  * writers.
746  *
747  * Removes the current co-routine from its ready list and places it in the
748  * appropriate delayed list.
749  */
750 void vCoRoutineAddToDelayedList(TickType_t xTicksToDelay, List_t *pxEventList);
751 
752 /*
753  * This function is intended for internal use by the queue implementation only.
754  * The function should not be used by application writers.
755  *
756  * Removes the highest priority co-routine from the event list and places it in
757  * the pending ready list.
758  */
759 BaseType_t xCoRoutineRemoveFromEventList(const List_t *pxEventList);
760 
761 #ifdef __cplusplus
762 }
763 #endif
764 
766 #endif /* CO_ROUTINE_H */
xLIST_ITEM
Definition: list.h:181
TickType_t
uint32_t TickType_t
FreeRTOS definition for a single tick.
Definition: portmacro.h:98
UBaseType_t
unsigned long UBaseType_t
FreeRTOS definition for unsigned long ints.
Definition: portmacro.h:92
BaseType_t
long BaseType_t
FreeRTOS definition for long ints.
Definition: portmacro.h:91
corCoRoutineControlBlock
Definition: croutine.h:95
xLIST
Definition: list.h:203