krnl 1
Loading...
Searching...
No Matches
krnlisrsemkickArd.ino
Go to the documentation of this file.
1#include <krnl.h>
2
3// External triggered ISR
4// An Interrupt Service Routine is attached to pin 2
5// So when pin2 is drived to ground (by a wire) an interrupt is generated.
6// The ISR increment a counter and send it to a message Q
7// naming ki_send .... "i" indicates it can be used in an ISR and demand interrupt to be disabled prio to call
8// and that no task shift takes place in the call
9// demonstrates ISR with message Q and preemption(task shift) in the ISR
10// NB Take a look on the ISR. For 1280 and 2560 it is INT4 but for 168,328,.. it's INTO
11// It is taken care by a compile flag
12// (c) beerware license JDN 2013
13// AS USUAL Serial.print is not krnl safe !!! cant break your program
14
15struct k_t * p_t1,*p_t2,*sem1;
16
17#define STK_SIZE 400
18
19char s1[STK_SIZE]; // stak for t1 ... and t2
20char s2[STK_SIZE]; // stak for t1 ... and t2
21
22volatile int icnt=0;
23
24void doBlink(void) {
25 static char flag = 0;
26 flag = ! flag;
27 digitalWrite(13,flag);
28}
29
30
31void t2()
32{
33 while (1) {
34 // doBlink();
35 // k_sleep(100);
36 }
37}
38
39void t1(void) {
40
41 while (1) {
42 int i;
43
44 k_wait(sem1,0); // wait forever
45 doBlink();
46 }
47
48}
49
50void xxx()
51{
52
53 // no local vars ?!? ! I think
54 PUSHREGS();
55 if (!k_running)
56 goto exitt ;
57
58 icnt++;
60 K_CHG_STAK();
61exitt:
62
63 POPREGS();
64 RETI();
65}
66
67void initISR()
68{
69
70 attachInterrupt(0,xxx,FALLING);
71 digitalWrite(2,HIGH);
72 }
73
74void setup() {
75
76 Serial.begin(9600);
77 pinMode(13,OUTPUT);
78
79 k_init(2,1,0); // from now you can crt task,sem etc
80
81 sem1 = k_crt_sem(0,10); //
82
83 p_t1 = k_crt_task(t1, 10, s1, STK_SIZE);
84 p_t2 = k_crt_task(t2, 10, s2, STK_SIZE);
85
86 initISR();
87
88 Serial.println("just bef");
89 k_start(10); // now we are runnning with timer 10 msev
90 //Serial.println("oev");
91
92 // main will not come back and will sleep rest of life
93}
94
95void loop(void) {
96 // just for compilation - will never be called
97}
98
99/* QED :-) */
100
101
102
103
volatile int i
unsigned char s2[110]
Definition k03asleep.ino:25
unsigned char s1[110]
Definition k03asleep.ino:25
struct k_t * sem1
int ki_signal(struct k_t *sem)
signal a semaphore from AN ISR - no task shift , do not enable intr,...
Definition krnl.c:605
volatile char k_running
Definition krnl.c:156
int k_wait(struct k_t *sem, int timeout)
stand wait on semaphore call with timeout facility
Definition krnl.c:683
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
struct k_t * k_crt_sem(int init_val, int maxvalue)
change task priority and reinserts it in task Q and do a task shift
Definition krnl.c:544
int k_init(int nrTask, int nrSem, int nrMsg)
Definition krnl.c:1108
int k_start()
Definition krnl.c:1149
#define RETI()
Definition krnl.h:480
#define K_CHG_STAK()
Definition krnl.h:488
#define STK_SIZE
Definition isem.ino:17
struct k_t * p_t1
Definition isem.ino:15
volatile int icnt
Definition isem.ino:22
struct k_t * p_t2
Definition msg1.ino:16
struct k_t * t1
Definition krnlgen.ino:3
struct k_t * t2
Definition krnlgen.ino:3
void loop(void)
void doBlink(void)
void setup()
void xxx()
void t2()
void initISR()
void t1(void)
PUSHREGS()
Definition krnl.h:323