OS  v7.3.3
Documentation
Loading...
Searching...
No Matches
qcoroutine.h
1
8#ifndef QCOROUTINE_H
9 #define QCOROUTINE_H
10
11 #include "qtypes.h"
12 #include "qstimers.h"
13
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17
24 typedef qINT32_t _qCR_TaskPC_t; // skipcq: CXX-E2000
25 typedef _qCR_TaskPC_t qCR_ExtPosition_t; // skipcq: CXX-E2000
29 #define qCR_Position_t static _qCR_TaskPC_t
30
31 /* Please don't access any members of this structure directly */
33 typedef struct _qCR_Instance_s { // skipcq: CXX-E2000
34 _qCR_TaskPC_t instr; /*< Used to hold the local continuation. */
35 _qCR_TaskPC_t prev; /*< Temporally holds the local continuation during a coroutine suspension*/
36 qSTimer_t crdelay; /*< Used to hold the required delay for #qCR_Delay. */
37 }
38 _qCR_Instance_t; // skipcq: CXX-E2000
42 typedef _qCR_Instance_t *qCR_Handle_t;
43
45 typedef struct _qCR_Semaphore_s { // skipcq: CXX-E2000
47 size_t count;
49 }
51
53 #define QCR_RESTART ( 0 )
54 #define QCR_POSITION_SET ( 1 )
55 #define QCR_SUSPEND ( 2 )
56 #define QCR_RESUME ( 3 )
63 typedef enum {
64 qCR_RESTART = QCR_RESTART,
65 qCR_POSITION_SET = QCR_POSITION_SET,
66 qCR_SUSPEND = QCR_SUSPEND,
67 qCR_RESUME = QCR_RESUME
68 }
70
72 typedef enum {
73 _qCR_UNDEFINED = 0,
74 _qCR_PC_INIT_VAL = -1,
75 _qCR_PC_SUSPENDED_VAL = -2,
76 _qCR_SEM_SIGNAL = -3,
77 _qCR_SEM_TRYLOCK = -4
78 }
79 _qCR_Oper_t; // skipcq: CXX-E2000
80
81 /*Construction statements*/
82 #define _qCR_LCInit /* skipcq: CXX-E2000 */\
83 { _qCR_PC_INIT_VAL, _qCR_UNDEFINED, QSTIMER_INITIALIZER } \
84
85 #define _qCR_RT( _PT_ ) /* skipcq: CXX-E2000 */ \
86 case (_qCR_TaskPC_t)(_PT_) : \
87
88 #define _qCR_JUMP( _DST_ ) switch (_DST_) // skipcq: CXX-W1164
89
90 #define _qCR_LCON( _DST_ , _STATE_, _REST_, _ACTION_ ) \
91 ( _DST_ ) = (_STATE_); \
92 _ACTION_; \
93 _REST_ Q_UNUSED(0) \
94
95 #define _qCR_EXIT goto _qCR_ExitPoint // skipcq: CXX-E2000
96
97 #define _qCR_DEF /* skipcq: CXX-E2000 */\
98 static _qCR_Instance_t _qCRState = _qCR_LCInit; \
99 _qCR_Instance_t * const _qcr = &_qCRState \
100
104 /*Core Statements*/
105 /*=======================================================================*/
106 #define _qCR_Start /* skipcq: CXX-E2000 */\
107 _qCR_DEF; \
108 _qCR_JUMP( _qcr->instr ) { /* skipcq: CXX-W1197 */\
109 _qCR_RT( _qCR_PC_INIT_VAL ) \
110
111
112 /*=======================================================================*/
113 #define _qCR_hStart( handle ) /* skipcq: CXX-E2000 */\
114 _qCR_DEF; \
115 if ( NULL == (handle) ) { \
116 (handle) = &_qCRState; \
117 } \
118 _qCR_JUMP( _qcr->instr ) { \
119 default: _qCR_EXIT; /*suspend point*/ \
120 _qCR_RT( _qCR_PC_INIT_VAL ) \
121
122 /*=======================================================================*/
123 #define _qCR_Dispose /* skipcq: CXX-E2000 */\
124 _qcr->instr = _qCR_PC_INIT_VAL; \
125 } \
126 _qCR_ExitPoint: Q_UNUSED(0) \
127
128
129 /*=======================================================================*/
130 #define _qCR_Yield /* skipcq: CXX-E2000 */\
131 do { \
132 _qCR_LCON( _qcr->instr, __LINE__, _qCR_RT(__LINE__), _qCR_EXIT ); \
133 } while ( qFalse ) \
134
135
136 /*=======================================================================*/
137 #define _qCR_Restart /* skipcq: CXX-E2000 */\
138 do { \
139 _qCR_LCON( _qcr->instr, _qCR_PC_INIT_VAL, Q_NONE, _qCR_EXIT ); \
140 } while ( qFalse ) \
141
142
143 /*=======================================================================*/
144 #define _qCR_wu_Assert( condition ) /* skipcq: CXX-E2000 */\
145 do { \
146 _qCR_LCON( _qcr->instr, __LINE__, _qCR_RT(__LINE__), Q_UNUSED(0) ); \
147 if ( !(condition) ) { \
148 _qCR_EXIT; \
149 } \
150 } while ( qFalse ) \
151
152
153 /*=======================================================================*/
154 #define _qCR_GetPosition( position ) /* skipcq: CXX-E2000 */\
155 do { \
156 _qCR_LCON( position, __LINE__, _qCR_RT(__LINE__), Q_UNUSED(0) ); \
157 Q_UNUSED( (position) ); \
158 } while ( qFalse ) \
159
160
161 /*=======================================================================*/
162 #define _qCR_RestoreFromPosition( position ) /* skipcq: CXX-E2000 */\
163 do { \
164 _qCR_LCON( _qcr->instr, (position), Q_NONE, _qCR_EXIT ); \
165 } while ( qFalse ) \
166
167
168 /*=======================================================================*/
169 #define _qCR_Delay( dTime ) /* skipcq: CXX-E2000 */\
170 do { \
171 qCR_TimeoutSet( dTime ); \
172 _qCR_LCON( _qcr->instr, __LINE__, _qCR_RT(__LINE__), Q_UNUSED(0) ); \
173 if ( !qCR_TimeoutExpired() ) { \
174 _qCR_EXIT; \
175 } \
176 } while ( qFalse ) \
177
178
179 /*=======================================================================*/
180 #define _qCR_wu_TmrAssert( condition, timeout ) /* skipcq: CXX-E2000 */\
181 do { \
182 qCR_TimeoutSet( timeout ); \
183 _qCR_LCON( _qcr->instr, __LINE__, _qCR_RT(__LINE__), Q_UNUSED(0) ); \
184 if ( !( (condition) || qCR_TimeoutExpired() ) ) { \
185 _qCR_EXIT; \
186 } \
187 } while ( qFalse ) \
188
189
190 /*=======================================================================*/
191 #define _qCR_do /* skipcq: CXX-E2000 */\
192 do { \
193 _qCR_LCON( _qcr->instr, __LINE__, _qCR_RT(__LINE__), Q_UNUSED(0) ); \
194
195
196 /*=======================================================================*/
197 #define _qCR_until( condition ) /* skipcq: CXX-E2000 */\
198 if ( !(condition) ) { \
199 _qCR_EXIT; \
200 } \
201 } while ( qFalse ) \
202
203
204 /*=======================================================================*/
222 #define qCR_Begin _qCR_Start
223
241 #define qCR_BeginWithHandle( handle ) _qCR_hStart( handle )
242
259 #define qCR_End _qCR_Dispose
260
268 #define qCR_Yield _qCR_Yield
269
275 #define qCR_Restart _qCR_Restart
276
288 #define qCR_WaitUntil( bCondition ) _qCR_wu_Assert( bCondition )
289
303 #define qCR_TimedWaitUntil( bCondition, tValue ) \
304 _qCR_wu_TmrAssert( bCondition, tValue ) \
305
317 #define qCR_Do _qCR_do
318
334 #define qCR_Until( bCondition ) _qCR_until( bCondition )
335
346 #define qCR_SemInit( pSem, sValue ) Q_UNUSED( _qCR_Sem( pSem, sValue ) )
347
358 #define qCR_SemWait( pSem ) \
359 _qCR_wu_Assert( _qCR_Sem( pSem, _qCR_SEM_TRYLOCK ) ) \
360
371 #define qCR_SemSignal( pSem ) \
372 Q_UNUSED( _qCR_Sem( pSem, _qCR_SEM_SIGNAL ) ) \
373
383 #define qCR_PositionGet( p ) _qCR_GetPosition( p )
384
393 #define qCR_PositionRestore( p ) _qCR_RestoreFromPosition( p )
394
402 #define qCR_PositionReset( p ) (p) = _qCR_PC_INIT_VAL
403
410 #define qCR_Delay( tValue ) _qCR_Delay( tValue )
411
417 #define qCR_TimeoutSet( tValue ) qSTimer_Set( &_qcr->crdelay , tValue )
418
423 #define qCR_TimeoutExpired( ) qSTimer_Expired( &_qcr->crdelay )
424
437 const qCR_ExternAction_t action,
438 const qCR_ExtPosition_t pos );
439
441 qBool_t _qCR_Sem( qCR_Semaphore_t * const sem, const _qCR_Oper_t oper ); // skipcq: CXX-E2000
446 #ifdef __cplusplus
447 }
448 #endif
449
450#endif
qBool_t qCR_ExternControl(qCR_Handle_t h, const qCR_ExternAction_t action, const qCR_ExtPosition_t pos)
Perform an external action over the requested Co-routine.
Definition qcoroutine.c:10
qCR_ExternAction_t
An enumeration to define the possible actions that can be performed outside the context of a Co-Routi...
Definition qcoroutine.h:63
_qCR_Instance_t * qCR_Handle_t
A typedef to instantiate a Co-Routine handle.
Definition qcoroutine.h:42
@ qCR_RESUME
Definition qcoroutine.h:67
@ qCR_SUSPEND
Definition qcoroutine.h:66
@ qCR_POSITION_SET
Definition qcoroutine.h:65
@ qCR_RESTART
Definition qcoroutine.h:64
qUINT8_t qBool_t
A type to instantiate an OS boolean variable.
Definition qtypes.h:139
int32_t qINT32_t
Signed integer type with width of exactly 32 bits respectively.
Definition qtypes.h:55
A typedef to instantiate a Co-Routine Semaphore.
Definition qcoroutine.h:45
A STimer(Software Timer) object.
Definition qstimers.h:32