krnl 1
Loading...
Searching...
No Matches
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
8struct k_t *pt1, // pointer to hold reference
9*pt2, // to taskdescriptor for t1 and t2
11
12char s1[200]; // stak for task t1
13char s2[200]; // stak for task t2
14
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
29void 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
52void loop(){ /* loop will never be called */
53}
54
55
56
57
58
struct k_t * pt2
struct k_t * pt1
unsigned char s2[110]
Definition k03asleep.ino:25
unsigned char s1[110]
Definition k03asleep.ino:25
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
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
int k_init(int nrTask, int nrSem, int nrMsg)
Definition krnl.c:1108
int k_start()
Definition krnl.c:1149
struct k_t * mutexSem
Definition mutex.ino:3
void setup()
Definition k04mutex.ino:29
void toggleLED13()
Definition k04mutex.ino:15
void loop()
Definition k04mutex.ino:52
struct k_t * t1
Definition krnlgen.ino:3
struct k_t * t2
Definition krnlgen.ino:3
Definition krnl.h:323