krnl
1
Loading...
Searching...
No Matches
examples
oldexamples
old
k0skeleton
k0skeleton.ino
Go to the documentation of this file.
1
#include <
krnl.h
>
2
3
// A small krnl program with two independent tasks
4
// They run at same priority so krnl will do timeslicing between them
5
// Watch LED and Serial TX
6
7
struct
k_t
*
pt1
,
// pointer to hold reference
8
*
pt2
;
// to taskdescriptor for t1 and t2
9
10
char
s1
[200];
// stak for task t1
11
char
s2
[200];
// stak for task t2
12
13
void
t1
(
void
)
14
{
15
// a task must have an endless loop
16
// if you end and leave the task function - a crash will occur!!
17
// so this loop is the code body for task 1
18
while
(1) {
19
Serial.println(
"Hello World"
);
20
k_sleep
(1000);
// let task sleep for 1000 kernel ticks
21
}
// lenght of ticks in millisec is specified in
22
}
// k_start call called from setup
23
24
void
t2
(
void
)
25
{
26
// and task body for task 2
27
// runs independent of task t1
28
while
(1) {
29
digitalWrite(13,HIGH);
// led 13 ON
30
k_sleep
(500);
// sleep 500 ticks
31
digitalWrite(13,LOW);
// led 13 OFF
32
k_sleep
(500);
// and sleep
33
}
34
}
35
36
void
setup
()
37
{
38
Serial.begin(9600);
// for output from task 1
39
pinMode(13,OUTPUT);
// for blink on LED from task 2
40
41
// init krnl so you can create 2 tasks, 0 semaphores and no message queues
42
k_init
(2,0,0);
43
44
// two task are created
45
// |------------ function used for body code for task
46
// | |--------- priority (lower number= higher prio
47
// | | |------- array used for stak for task
48
// | | | |--- staksize for array s1
49
50
pt1
=
k_crt_task
(
t1
,11,
s1
,200);
51
pt2
=
k_crt_task
(
t2
,11,
s2
,200);
52
53
54
// NB-1 remember an Arduino has only 2-8 kByte RAM
55
// NB-2 remember that stak is used in function calls for
56
// - return address
57
// - registers stakked
58
// - local variabels in a function
59
// So having 200 Bytes of stak excludes a local variable like ...
60
// int arr[400];
61
// krnl call k_unused_stak returns size of unused stak
62
// Both task has same priority so krnl will shift between the
63
// tasks every 10 milli second (speed set in k_start)
64
65
k_start
(1);
// start kernel with tick speed 10 milli seconds
66
}
67
68
void
loop
(){
/* loop will never be called */
}
69
70
71
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_sleep
int k_sleep(int time)
let task sleep for a number of milliseconds
Definition
krnl.c:445
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_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
setup
void setup()
Definition
k0skeleton.ino:36
t2
void t2(void)
Definition
k0skeleton.ino:24
t1
void t1(void)
Definition
k0skeleton.ino:13
loop
void loop()
Definition
k0skeleton.ino:68
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