krnl
1
Loading...
Searching...
No Matches
examples
oldexamples
old
k01debug
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
11
char
stak
[
STKSIZE
];
12
struct
k_t
*
pStak
;
13
14
void
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
32
void
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 */
40
pStak
=
k_crt_task
(
task
,
TASKPRIO
,
stak
,
STKSIZE
);
41
k_start
(1);
/* start krnl timer speed 1 milliseconds*/
42
43
Serial.println(
"If you see this then krnl didnt start :-( "
);
44
}
45
46
void
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
52
extern
"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
STKSIZE
#define STKSIZE
Definition
k02.ino:8
stak
char stak[100]
Definition
k02.ino:12
led13
unsigned char led13
Definition
k02.ino:59
i
volatile int i
Definition
k02twotasks.ino:29
TASKPRIO
#define TASKPRIO
Definition
k08isrsem.ino:14
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
pStak
struct k_t * pStak
Definition
k01.ino:12
setup
void setup()
Definition
k01debug.ino:32
k_breakout
void k_breakout()
Definition
k01debug.ino:74
k_sem_noclip
void k_sem_noclip(unsigned char nr)
Definition
k01debug.ino:63
k_sem_clip
void k_sem_clip(unsigned char nr, int i)
Definition
k01debug.ino:56
task
void task()
Definition
k01debug.ino:14
loop
void loop()
Definition
k01debug.ino:46
task
struct k_t * task
Definition
kernelmoviesimple.ino:10
k_t
Definition
krnl.h:323
k_t::nr
unsigned char nr
Definition
krnl.h:327
Generated by
1.15.0