krnl 1
Loading...
Searching...
No Matches
krnldebug01.ino
Go to the documentation of this file.
1#include <krnl.h>
2// one task loops and blink
3// k_sleep is used for delay - and ensure no busy waiting
4// if delay(...) is used then you use cpu time
5
6struct k_t *p;
7char stak[100];
8volatile int cntt1 = 0, cntt2 = 0;
9void t1()
10{
11 while (1) {
12
13
14 digitalWrite(13, HIGH);
15 //delay(1000);
16 k_eat_msec_time(1000);
17 digitalWrite(13, LOW);
18 Serial.print(cntt1); Serial.print(" "); Serial.println(cntt2);
19 k_sleep(1000);
20
21 }
22}
23
24void setup()
25{
26 Serial.begin(9600);
27 pinMode(12, OUTPUT); // krnl breakout
28 pinMode(13, OUTPUT);
29 k_init(1, 0, 0); // init with space for one task
30
31 // priority low number higher priority than higher number
32 p = k_crt_task(t1, 10, stak, 100); // t1 as task, priority 10, 100 B stak
33
34 k_start(1); // 1 milli sec tick speed
35}
36
37void loop() {
38}
39
40
41
42extern "C" {
43
44
45 void k_breakout() // called every task shift from dispatcher
46 {
47
48 if (pRun->nr == 0) {
49 PORTB |= 0x10;
50 cntt1++;
51
52 }
53 else {
54 cntt2++;
55 PORTB &= 0x20;
56 }
57
58 // for a MEGA you have to find another port :-)
59 // port K (adc8-15) seems feasible
60 }
61}
char stak[100]
Definition k02.ino:12
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
volatile int cntt2
void setup()
void k_breakout()
void t1()
volatile int cntt1
void loop()
struct k_t * t1
Definition krnlgen.ino:3
struct k_t * p
Definition krnl.h:323