krnl 1
Loading...
Searching...
No Matches
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
16struct k_t *p1, *p2, *p3;
17char 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 ....
22void 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
33void 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
54void loop() {
55}
56
57
58
59extern "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
101UNO
102pin port
1038 PB0
1049 PB1
10510 PB2
10611 PB3
10712 PB4
10813 PB5 LED13
109PB6 and 7 etc not to be used !
110
111
112MEGA
113pin port
11478 PA0
11577 PA1
11676 PA2
11775 PA3
11874 PA4
11973 PA5
12072 PA6
12171 PA7
12213 PB7 LED13
123
124MICRO
1258 PB4
1269 PB5
12710 PB6
12811 PB7
12913 PC7 LED13
130
131NANO
132D8 PD0
133D9 PD1
134D2 PD2
135D3 PD3
136D4 PD4
137D5 PD5
138D6 PD6
139D7 PD7
14013 PB5 LED13
141
142PRO MINI
1432 PD2
1443 PD3
1454 PD4
1465 PD5
1476 PD6
14813 PB5 LED13
149
150 * */
volatile int i
struct k_t * p1
Definition k03asleep.ino:22
struct k_t * p2
Definition k03asleep.ino:22
char st2[110]
char st1[110]
struct k_t * pRun
Definition krnl.c:148
int k_sleep(int time)
let task sleep for a number of milliseconds
Definition krnl.c:445
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_init(int nrTask, int nrSem, int nrMsg)
Definition krnl.c:1108
int k_start()
Definition krnl.c:1149
char st3[110]
struct k_t * p3
void setup()
void k_breakout()
void t1()
void loop()
struct k_t * t1
Definition krnlgen.ino:3
Definition krnl.h:323