krnl
sm.c
Go to the documentation of this file.
1
2
#include <stdio.h>
3
4
// .
5
typedef
void
*(*(
void
pF
));
// for typecast for calling function
6
7
#define NEXT(x,y,z) return ((void *)x)
8
9
// States -- you need this forward dcl for the compiler and calling
10
11
// NEXT(next,here,cond)
12
// |---- condition to be put on the arc in state machine
13
// |-------- state we are in just now (just for graph)
14
// |-------------- next state we will jump to
15
//
16
// all driven from main (or here setup fct)
17
18
19
pF
statefunc
=
led_on
,
oldfunc
= NULL;
// where to start
20
21
void
*
led_on
();
// as name indicates ...
22
void
*
led_off
();
23
void
*
led_save
();
24
void
*
pause
();
25
void
*
jens
();
26
27
28
void
*
led_on
() {
29
printf(
"on\n"
);
30
31
NEXT
(
led_off
,
led_on
,always);
// BLA BLAB blabla
32
}
33
34
35
void
*
jens
() {
36
printf(
"on\n"
);
37
if
(1)
38
NEXT
(
led_off
,
jens
,always);
// BLA BLAB blabla
39
else
40
NEXT
(
led_on
,
jens
,always);
// BLA BLAB blabla
41
}
42
43
44
void
pause
()
45
{
46
// pausefire
47
NEXT
(
led_on
,
pause
, yep);
48
49
}
50
void
*
led_off
() {
51
static
int
toogle = 0;
52
53
if
(toogle) toogle = 0;
54
else
toogle = 1;
55
56
printf(
"off \n"
);
57
if
(toogle)
58
NEXT
(
led_on
,
led_off
,conOST);
59
else
60
NEXT
(
led_save
,
led_off
,cond2kurt);
61
62
NEXT
(
pause
,
led_off
,oev);
63
}
64
65
void
*
led_save
() {
66
printf(
"off \n"
);
67
if
(1)
68
NEXT
(
led_on
,
led_save
,alarm);
69
else
70
NEXT
(
led_off
,
led_save
,peace);
71
NEXT
(
jens
,
led_save
,peace);
72
73
}
74
75
void
main
() {
76
while
(1) {
77
oldfunc
=
statefunc
;
// if you want to see/track the previous state }
78
statefunc
= (
pF
)(*
statefunc
)();
// next state is called here
79
// print nest state
80
//debug
81
// here statefunc is last and oldfunc is last last
82
}
83
return ;
// should not get here
84
}
85
led_off
void * led_off()
Definition:
sm.c:50
NEXT
#define NEXT(x, y, z)
Definition:
sm.c:7
statefunc
pF statefunc
Definition:
sm.c:19
oldfunc
pF oldfunc
Definition:
sm.c:19
pF
void *(* pF)(void)
Definition:
sm.c:5
led_save
void * led_save()
Definition:
sm.c:65
pause
void * pause()
Definition:
sm.c:44
jens
void * jens()
Definition:
sm.c:35
main
void main()
Definition:
sm.c:75
led_on
void * led_on()
Definition:
sm.c:28
Generated by
1.8.17