krnl 1
Loading...
Searching...
No Matches
k013semsync.ino
Go to the documentation of this file.
1#include <krnl.h>
2// one task loops and blink
3// k_wait ensures proper timing
4
5struct k_t *p1,*s1;
6
7void t1()
8{
10 while (1) {
11 k_wait(s1,0); //wait until a kick comes
12 digitalWrite(13,! digitalRead(13));
13 }
14}
15
16
17void setup()
18{
19 int res;
20 Serial.begin(9600);
21 while (! Serial) ;
22 pinMode(13,OUTPUT);
23
24 k_init(1,1,0); // init with space for one task
25 // |--- no of mg Queues (0)
26 // |----- no of semaphores (0)
27 // |------- no of tasks (2)
28
29 // priority low number higher priority than higher number
30 p1 = k_crt_task(t1,10,100); // t1 as task, priority 10, 100 B stak
31 s1 = k_crt_sem(0,10);
32 res= k_start(1); // 1 milli sec tick speed
33 // you will never return from k_start
34 Serial.print("ups an error occured: "); Serial.println(res);
35 while (1) ;
36}
37
38void loop() {}
void setup()
void t1()
void loop()
struct k_t * p1
Definition k03asleep.ino:22
unsigned char s1[110]
Definition k03asleep.ino:25
int k_wait(struct k_t *sem, int timeout)
stand wait on semaphore call with timeout facility
Definition krnl.c:683
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
int k_set_sem_timer(struct k_t *sem, int val)
attach a periodic timer to a semaphore, to be used for realtime
Definition krnl.c:586
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 * t1
Definition krnlgen.ino:3
Definition krnl.h:323