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