dit projekt
examples
k03priorityequal
k03priorityequal.ino
Go to the documentation of this file.
1
//220216
2
#include <
krnl.h
>
3
//
4
// busy waiting all the way around - like using ya old delay
5
//
6
7
// Set t1 priority to 9 == highest priority
8
// What will happen ? What do you see on the led and the measurements
9
// REALTIME ?
10
//
11
// gives a guess how cpu time is used in krnl "dummy time eating"
12
13
struct
k_t
*
p1
, *
p2
;
14
15
#define SS 110
16
unsigned
char
s1
[
SS
],
s2
[
SS
];
17
18
19
void
t1
()
20
{
21
int
v;
22
23
while
(1) {
24
k_eat_msec
(2000);
// eat time for 2000 ticks so mimic cpu usage == 2000 msec
25
}
26
}
27
28
unsigned
long
tStart
,
tStop
;
29
void
t2
()
30
{
31
int
i
= 0;
32
while
(1) {
33
Serial.println(
"start"
);
34
tStart
=
k_millis
();
35
for
(
int
i
=0;
i
< 10 ;
i
++) {
// 10 loops of 100 milliseconds == 1 second ! ?
36
digitalWrite(13, HIGH);
37
k_eat_msec
(50);
38
digitalWrite(13, LOW);
39
k_eat_msec
(50);
40
}
41
tStop
=
k_millis
();
42
Serial.print((
tStop
-
tStart
)/1000.0);
43
Serial.print(
" sec "
);
44
Serial.println(
"Did it take 1 second ???- not - why "
);
45
// hint task t1 ies eating 50% of cputime
46
// the have same priority to you share cpu 50/50
47
// so it will approx take 100 msec to execut k_eat_msec(50)
48
}
49
}
50
51
52
void
setup
()
53
{
54
int
res;
55
Serial.begin(115200);
56
while
(! Serial) ;
57
pinMode(13, OUTPUT);
58
59
k_init
(2, 0, 0);
// init with space for one task
60
// |--- no of mg Queues (0)
61
// |----- no of semaphores (0)
62
// |------- no of tasks (2)
63
64
// priority low number higher priority than higher number
65
p1
=
k_crt_task
(
t1
, 10,
s1
,
SS
);
// t1 as task, priority 9, 100 B stak
66
p2
=
k_crt_task
(
t2
, 10,
s2
,
SS
);
// t2 as task, priority 10, 100 B stak
67
68
Serial.println(
"bef start"
);
69
res =
k_start
();
// 1 milli sec tick speed
70
// you will never return from k_start
71
Serial.print(
"ups an error occured: "
); Serial.println(res);
72
while
(1) ;
73
}
74
75
void
loop
() {}
i
volatile int i
Definition:
k02twotasks.ino:29
setup
void setup()
Definition:
k03priorityequal.ino:52
t2
void t2()
Definition:
k03priorityequal.ino:29
t1
void t1()
Definition:
k03priorityequal.ino:19
tStart
unsigned long tStart
Definition:
k03priorityequal.ino:28
SS
#define SS
Definition:
k03priorityequal.ino:15
s1
unsigned char s1[SS]
Definition:
k03priorityequal.ino:16
p1
struct k_t * p1
Definition:
k03priorityequal.ino:13
tStop
unsigned long tStop
Definition:
k03priorityequal.ino:28
p2
struct k_t * p2
Definition:
k03priorityequal.ino:13
s2
unsigned char s2[SS]
Definition:
k03priorityequal.ino:16
loop
void loop()
Definition:
k03priorityequal.ino:75
k_millis
unsigned long k_millis(void)
Definition:
krnl.c:1322
k_eat_msec
void k_eat_msec(unsigned int eatTime)
Definition:
krnl.c:292
k_crt_task
struct k_t * k_crt_task(void(*pTask)(void), char prio, char *pStk, int stkSize)
Definition:
krnl.c:374
k_init
int k_init(int nrTask, int nrSem, int nrMsg)
Definition:
krnl.c:1152
k_start
int k_start()
Definition:
krnl.c:1192
krnl.h
k_t
Definition:
krnl.h:334
Generated by
1.9.1