krnl
1
Loading...
Searching...
No Matches
examples
oldexamples
old-may-not_work
k04mutex
k04mutex.ino
Go to the documentation of this file.
1
#include <
krnl.h
>
2
3
// A small krnl program with two independent tasks
4
// They share data which is guarded by a semaphore implemented mutex
5
// Tasks has same priority in this examples
6
// you can have more mutex regions by using more sempahores :-)
7
8
struct
k_t
*
pt1
,
// pointer to hold reference
9
*
pt2
,
// to taskdescriptor for t1 and t2
10
*
mutexSem
;
11
12
char
s1
[200];
// stak for task t1
13
char
s2
[200];
// stak for task t2
14
15
void
toggleLED13
()
16
{
17
static
char
flag=0;
18
if
(flag) {
19
flag = 0;
20
digitalWrite(13,HIGH);
21
}
22
else
{
23
flag = 1;
24
digitalWrite(13,LOW);
25
}
26
}
27
}
28
29
void
setup
()
30
{
31
Serial.begin(9600);
// for output from task 1
32
pinMode(13,OUTPUT);
// for blink on LED from task 2
33
34
// init krnl so you can create 2 tasks, 1 semaphore and no message queues
35
k_init
(2,1,0);
36
37
// two task are created
38
// |------------ function used for body code for task
39
// | |--------- priority (lower number= higher prio
40
// | | |------- array used for stak for task
41
// | | | |--- staksize for array s1
42
pt1
=
k_crt_task
(
t1
,11,
s1
,200);
//
43
pt2
=
k_crt_task
(
t2
,11,
s2
,200);
//
44
45
// |--- startvalue is 1 bq it is for mutex usage
46
// |-- max value before maxing out
47
mutexSem
=
k_crt_sem
(1,10);
48
49
k_start
(1);
// start kernel with tick speed 10 milli seconds
50
}
51
52
void
loop
(){
/* loop will never be called */
53
}
54
55
56
57
58
pt2
struct k_t * pt2
Definition
k02twotasks.ino:7
pt1
struct k_t * pt1
Definition
k02twotasks.ino:6
s2
unsigned char s2[110]
Definition
k03asleep.ino:25
s1
unsigned char s1[110]
Definition
k03asleep.ino:25
k_crt_task
struct k_t * k_crt_task(void(*pTask)(void), char prio, char *pStk, int stkSize)
create a task - only to be called before k_start creates a task and put it in the active Q
Definition
krnl.c:328
k_crt_sem
struct k_t * k_crt_sem(int init_val, int maxvalue)
change task priority and reinserts it in task Q and do a task shift
Definition
krnl.c:544
k_init
int k_init(int nrTask, int nrSem, int nrMsg)
Definition
krnl.c:1108
k_start
int k_start()
Definition
krnl.c:1149
krnl.h
mutexSem
struct k_t * mutexSem
Definition
mutex.ino:3
setup
void setup()
Definition
k04mutex.ino:29
toggleLED13
void toggleLED13()
Definition
k04mutex.ino:15
loop
void loop()
Definition
k04mutex.ino:52
t1
struct k_t * t1
Definition
krnlgen.ino:3
t2
struct k_t * t2
Definition
krnlgen.ino:3
k_t
Definition
krnl.h:323
Generated by
1.15.0