krnl
1
Loading...
Searching...
No Matches
examples
oldexamples
old
krnldebugled8to13full
krnldebugled8to13full.ino
Go to the documentation of this file.
1
#include <
krnl.h
>
2
3
// LED on pin 8 to 12 (and 13) used for indicating who is running
4
// pin 8 high = dmy
5
// pin 9 high = first task created
6
// pin 10 high = second
7
//
8
// if more than 6 task created they will no be shown individually but led 8 and 9 will be on
9
10
11
// NBNB
12
13
// it can be wise to create tasks in order lwo priority first
14
// Then pin 8 will be dummy, pin9 will be lowest prio, pin 10 next lowest etc
15
16
struct
k_t
*
p1
, *
p2
, *
p3
;
17
char
st1
[100],
st2
[100],
st3
[100];
18
19
// LED 13 not used from user space bq we use led for indicating dummy i srunning
20
// when dummy is running it indicates enough cpu power
21
// if dummy is not running for a longer time you may have problems ....
22
void
t1
()
23
{
24
while
(1) {
25
26
Serial.println(
"I am running"
);
27
k_eat_msec_time(500);
// you are running
28
Serial.println(
"dummy is now running"
);
29
k_sleep
(2000);
// you are NOT running so dummmy is running
30
}
31
}
32
33
void
setup
()
34
{
35
36
Serial.begin(9600);
37
for
(
int
i
= 8;
i
< 14;
i
++) {
38
pinMode(
i
, OUTPUT);
39
}
40
41
// set 8 to 13 to low (PB0 to PB5
42
//PORTB &= B11000000; // 11 on PB6 and PB7 bq they might be high or low we do not know
43
44
k_init
(3, 0, 0);
// init with space for one task
45
46
// priority low number higher priority than higher number
47
p1
=
k_crt_task
(
t1
, 10,
st1
, 100);
// t1 as task, priority 10, 100 B stak
48
p2
=
k_crt_task
(
t1
, 11,
st2
, 100);
// t1 as task, priority 10, 100 B stak
49
p3
=
k_crt_task
(
t1
, 12,
st3
, 100);
// t1 as task, priority 10, 100 B stak
50
51
k_start
(1);
// 1 milli sec tick speed
52
}
53
54
void
loop
() {
55
}
56
57
58
59
extern
"C"
{
60
61
void
k_breakout
()
// called every task shift from dispatcher
62
{
63
64
uint8_t c;
65
// FOR UNO
66
c = PORTB & B11000000;
// preserve PORTB bit 6 and 7
67
68
if
(
pRun
->nr < 6) {
// do we have more tasks than LEDs ?
69
c |= (0x01 <<
pRun
->nr);
70
PORTB = c;
71
}
72
else
{
73
PORTB = c | B00000011;
// on pin8 and 9 to indicate more than 6 tasks
74
}
75
}
76
}
77
78
79
/* or just LED13 if dummy ...
80
*
81
* both: pinMode(13,OUTPUT);
82
* uno mega
83
*
84
* if (pRun->nr == 0)
85
* PORTB = PORTB | B00100000; // led on uno
86
* | B10000000; // mega
87
*
88
* else
89
*
90
* PORTB = PORTB & B11011111; // led off uno
91
* & B01111111; / mega
92
*
93
* mega
94
*
95
*/
96
97
/*
98
99
Suggested PORTS TO USE
100
101
UNO
102
pin port
103
8 PB0
104
9 PB1
105
10 PB2
106
11 PB3
107
12 PB4
108
13 PB5 LED13
109
PB6 and 7 etc not to be used !
110
111
112
MEGA
113
pin port
114
78 PA0
115
77 PA1
116
76 PA2
117
75 PA3
118
74 PA4
119
73 PA5
120
72 PA6
121
71 PA7
122
13 PB7 LED13
123
124
MICRO
125
8 PB4
126
9 PB5
127
10 PB6
128
11 PB7
129
13 PC7 LED13
130
131
NANO
132
D8 PD0
133
D9 PD1
134
D2 PD2
135
D3 PD3
136
D4 PD4
137
D5 PD5
138
D6 PD6
139
D7 PD7
140
13 PB5 LED13
141
142
PRO MINI
143
2 PD2
144
3 PD3
145
4 PD4
146
5 PD5
147
6 PD6
148
13 PB5 LED13
149
150
* */
i
volatile int i
Definition
k02twotasks.ino:29
p1
struct k_t * p1
Definition
k03asleep.ino:22
p2
struct k_t * p2
Definition
k03asleep.ino:22
st2
char st2[110]
Definition
k04periodic-clip.ino:7
st1
char st1[110]
Definition
k04periodic-clip.ino:7
pRun
struct k_t * pRun
Definition
krnl.c:148
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
st3
char st3[110]
Definition
krnldebugled13.ino:8
p3
struct k_t * p3
Definition
krnldebugled13.ino:5
setup
void setup()
Definition
krnldebugled8to13full.ino:33
k_breakout
void k_breakout()
Definition
krnldebugled8to13full.ino:61
t1
void t1()
Definition
krnldebugled8to13full.ino:22
loop
void loop()
Definition
krnldebugled8to13full.ino:54
t1
struct k_t * t1
Definition
krnlgen.ino:3
k_t
Definition
krnl.h:323
Generated by
1.15.0