-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTaskMacro.h
78 lines (52 loc) · 2.21 KB
/
TaskMacro.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#pragma once // include guard
#include <util/atomic.h>
typedef void Task; // Task Type
// grundlegene Worte um einen Task Bereich einzugrenzen
#define taskBegin() \
static int Task_mark = 0; \
static unsigned long __attribute__((unused)) Task_timeStamp = 0; \
switch(Task_mark) \
{ \
case 0:
#define taskEnd() \
for(;;) \
{ \
taskSwitch(); \
} \
}
// Task Kontrol Worte, diese werden Taskwechsel einleiten
#define taskSwitch() do { Task_mark = __LINE__; return ; case __LINE__: ; } while (0)
#define taskPause(Task_interval) Task_timeStamp = millis(); while((millis() - Task_timeStamp) < (Task_interval)) taskSwitch()
#define taskWaitFor(Task_condition) while(!(Task_condition)) taskSwitch();
// Benennen und anspringen von Schrittketten Verzweigungen
#define taskStepName(Task_stepname) Task_step_##Task_stepname :
#define taskJumpTo(Task_stepname) goto Task_step_##Task_stepname
// Task Prioritaet festlegen
// 0 == hoch(wird bei jedem Durchlauf ausgeführt) bis 65535 (AnzahlAusfuehrungen == Durchlaeufe/pri )
#define taskPriority(pri) \
do \
{ \
static uint16_t taskPri; \
taskPri++; \
if(taskPri < (pri) ) return;taskPri=0; \
} while(0)
// kleine helferlein
#define CriticalSection ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
// Mutex , Semaphor, Monitor, Lock
/* TODO
// Mutex Abhandlung
struct Mutex {int8_t flag = 0;};
static inline bool mutexFree(Mutex * mutex)
{
return (!(mutex)->flag);
}
static inline void mutexClaim(Mutex * mutex)
{
++(mutex)->flag;
}
#define taskWaitForMutex(mutex) \
do{ \
taskWaitFor(mutexFree(mutex)); \
mutexClaim(mutex); \
}while(0)
*/