Première version du code du minuteur et schéma d'implantation.
This commit is contained in:
80
minuteur/pt.h
Normal file
80
minuteur/pt.h
Normal file
@@ -0,0 +1,80 @@
|
||||
/*--------------------------------------------------------
|
||||
Projet: InsoL@b
|
||||
File : pt.h 08/28/20
|
||||
Authors: initial work of Adam Dunkels, user@W500;
|
||||
little dressing & minor changes to limit compile warnings
|
||||
----------------------------------------------------------*/
|
||||
#ifndef __PT_H__
|
||||
#define __PT_H__
|
||||
typedef struct pt { unsigned short lc; } pt_t ;
|
||||
|
||||
#define PT_WAITING 0
|
||||
#define PT_YIELDED 1
|
||||
#define PT_EXITED 2
|
||||
#define PT_ENDED 3
|
||||
#define PT_INIT(pt) (pt)->lc = 0; // INIT
|
||||
#define PT_THREAD(name_args) char name_args // THREAD
|
||||
#define PT_BEGIN(pt) { \
|
||||
/*char PT_YIELD_FLAG = 1 ; not used here */ \
|
||||
switch((pt)->lc) \
|
||||
{ case 0: // BEGIN
|
||||
#define PT_END(pt) ((pt)->lc = 0 ); }; \
|
||||
/*PT_YIELD_FLAG = 0; not used here */ \
|
||||
PT_INIT(pt); return PT_ENDED; } // END
|
||||
#define PT_WAIT_UNTIL(pt, condition) \
|
||||
do { \
|
||||
(pt)->lc = __LINE__; \
|
||||
case __LINE__: \
|
||||
if(!(condition)) { \
|
||||
return PT_WAITING; \
|
||||
} \
|
||||
} while(0) // WAIT_UNTIL
|
||||
#define PT_WAIT_WHILE(pt, cond) \
|
||||
PT_WAIT_UNTIL((pt), !(cond)) // WAIT_WHILE
|
||||
#define PT_WAIT_THREAD(pt, thread) \
|
||||
PT_WAIT_WHILE((pt), PT_SCHEDULE(thread)) // WAIT_THREAD
|
||||
#define PT_SPAWN(pt, child, thread) \
|
||||
do { \
|
||||
PT_INIT((child)); \
|
||||
PT_WAIT_THREAD((pt), (thread)); \
|
||||
} while(0) // SPAWN
|
||||
#define PT_RESTART(pt) \
|
||||
do { \
|
||||
PT_INIT(pt); \
|
||||
return PT_WAITING; \
|
||||
} while(0) // RESTART
|
||||
#define PT_EXIT(pt) \
|
||||
do { \
|
||||
PT_INIT(pt); \
|
||||
return PT_EXITED; \
|
||||
} while(0) // EXIT
|
||||
#define PT_SCHEDULE(f) ((f) < PT_EXITED) // SCHEDULE
|
||||
#define PT_YIELD(pt) \
|
||||
do { \
|
||||
PT_YIELD_FLAG = 0; \
|
||||
(pt)->lc = __LINE__; \
|
||||
case __LINE__: \
|
||||
if(PT_YIELD_FLAG == 0) { \
|
||||
return PT_YIELDED; \
|
||||
} \
|
||||
} while(0) // YIELD
|
||||
#define PT_YIELD_UNTIL(pt, cond) \
|
||||
do { \
|
||||
PT_YIELD_FLAG = 0; \
|
||||
(pt)->lc = __LINE__; \
|
||||
case __LINE__: \
|
||||
if((PT_YIELD_FLAG == 0) || !(cond)) { \
|
||||
return PT_YIELDED; \
|
||||
} \
|
||||
} while(0) // YIELD_UNTIL
|
||||
#define PT_DELAY(pt, ms) \
|
||||
do { \
|
||||
static unsigned long _PTTTL_ ; \
|
||||
_PTTTL_ = millis() + (unsigned int)(ms); \
|
||||
PT_WAIT_UNTIL((pt), (millis() > _PTTTL_)); \
|
||||
} while(0) // DELAY
|
||||
#define PT_SYNC(pt, mark, ms) \
|
||||
do { \
|
||||
PT_WAIT_UNTIL((pt), (millis() - (mark) > (ms) )); \
|
||||
} while(0) // SYNC
|
||||
#endif /* __PT_H__ */
|
||||
Reference in New Issue
Block a user