krnl 1
Loading...
Searching...
No Matches
k01debug.ino
Go to the documentation of this file.
1/* k01
2 One task printing own usage of stak
3*/
4
5#include <krnl.h>
6
7#define STKSIZE 100
8
9#define TASKPRIO 10
10
12struct k_t * pStak;
13
14void task()
15{
16 char flipflop = 0;
17 while (1) {
18 k_eat_msec_time(10); // consume 10 millisec of CPU time
19 k_sleep(30); // sleep 100 ticks - replacement for delay bq k_seelp releases CPU
20
21 if (flipflop) {
22 flipflop = 0;
23 digitalWrite(13, HIGH);
24 }
25 else {
26 flipflop = 1;
27 digitalWrite(13, LOW);
28 }
29 }
30}
31
32void setup() {
33 // for debugging - ON UNO led ON PIN 8,9,...,13
34 for (int i = 8; i < 14; i++)
35 pinMode(i, OUTPUT);
36
37 Serial.begin(9600);
38
39 k_init(1, 0, 0); // 1 task, 0 semaphores, 0 messaegQueues */
41 k_start(1); /* start krnl timer speed 1 milliseconds*/
42
43 Serial.println("If you see this then krnl didnt start :-( ");
44}
45
46void loop() {}
47
48/***** DEBUGGING PART - LED ON 8-12**********/
49/************************ DEBUG CALLBACK BREAKOUT PART ****************/
50// must be extern C ! its not mandatory to supply with these functions - only if you need
51
52extern "C" {
53
54 // called when a semphore is clipping - nr is id of semaphore and i os nr of times clip has occured
55 unsigned char led13;
56 void k_sem_clip(unsigned char nr, int i)
57 {
58 return;
59 if (nr == 2)
60 led13 |= 0x20;
61 }
62
63 void k_sem_noclip(unsigned char nr)
64 {
65 return;
66 if (nr == 2)
67 led13 = 0x00;
68 }
69
70
71 /* void k_send_Q_clip(unsigned char nr, int i) {} */
72
73 // task numbering is in creation order: dummy: 0, first of yours 1, next 2,...
74 void k_breakout() // called every task shift from dispatcher
75 {
76 unsigned char c;
77 PORTB = (1 << pRun->nr); // arduino uno !! specific usage of PORTB
78 }
79 // for a MEGA you have to find another port :-)
80 // port K (adc8-15) seems feasible
81 // get inspired at http://kom.aau.dk/~jdn/edu/doc/arduino/ards.html
82}
83
84
85
86
#define STKSIZE
Definition k02.ino:8
char stak[100]
Definition k02.ino:12
unsigned char led13
Definition k02.ino:59
volatile int i
#define TASKPRIO
Definition k08isrsem.ino:14
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
struct k_t * pStak
Definition k01.ino:12
void setup()
Definition k01debug.ino:32
void k_breakout()
Definition k01debug.ino:74
void k_sem_noclip(unsigned char nr)
Definition k01debug.ino:63
void k_sem_clip(unsigned char nr, int i)
Definition k01debug.ino:56
void task()
Definition k01debug.ino:14
void loop()
Definition k01debug.ino:46
struct k_t * task
Definition krnl.h:323
unsigned char nr
Definition krnl.h:327