krnl 1
Loading...
Searching...
No Matches
msg2.ino
Go to the documentation of this file.
1
2#include <krnl.h>
3
4// External triggered ISR
5// An Interrupt Service Routine is attached to pin 2
6// So when pin2 is drived to ground (by a wire) an interrupt is generated.
7// The ISR increment a counter and send it to a message Q
8// naming ki_send .... "i" indicates it can be used in an ISR and demand interrupt to be disabled prio to call
9// and that no task shift takes place in the call
10// demonstrates ISR with message Q and preemption(task shift) in the ISR
11// NB Take a look on the ISR. For 1280 and 2560 it is INT4 but for 168,328,.. it's INTO
12// It is taken care by a compile flag
13// (c) beerware license JDN 2013
14
15struct k_t * p_t1, *p_t2;
16struct k_msg_t *pMsg2;
17
18char mar2[10 * 2]; // 10 ints each 2 bytes could instead write 10 *sizeof(int)
19
20#define STK_SIZE 200
21
22char s1[STK_SIZE]; // stak for t1 ... and t2
24
25volatile int icnt = 0;
26
27
28void doBlink(void) {
29 static char flag = 0;
30 flag != flag;
31 digitalWrite(13, flag);
32}
33
34void t1(void) {
35 int i;
36 while (1) {
37 delay(100);
38 if (0 <= k_receive(pMsg2, &i, -1, NULL) ) {
39 doBlink();
40 }
41 }
42}
43
44void t2(void) {
45 int i;
46 i = 0;
47 while (1) {
48 k_sleep(20); // just ZZZZZZZZZZZZZZZZ
49 k_send(pMsg2, &i); //just send 0,1,2,3,4....
50 i++;
51 }
52}
53
54void setup() {
55
56 Serial.begin(9600);
57
58 k_init(2, 0, 1); // from now you can crt task,sem etc
59
60 p_t1 = k_crt_task(t1, 10, s1, STK_SIZE);
62
63
64 pMsg2 = k_crt_send_Q(10, 2, mar2);
65 pinMode(13, OUTPUT);
66 Serial.print("start ");
67 Serial.println(KRNL_VRS);
68 delay(2000);
69
70 Serial.println("bef gogo");
71
72 k_start(10); // now we are runnning with timer 10 msev
73 Serial.println("shit - should not come here");
74
75 // main will not come back and will sleep rest of life
76}
77
78void loop(void) {/* just for compilation - will never be called*/
79}
80
81/* QED :-) */
82
83
84
volatile int i
unsigned char s2[110]
Definition k03asleep.ino:25
unsigned char s1[110]
Definition k03asleep.ino:25
char k_receive(struct k_msg_t *pB, void *el, int timeout, int *lost_msg)
Definition krnl.c:991
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
char k_send(struct k_msg_t *pB, void *el)
Definition krnl.c:944
int k_init(int nrTask, int nrSem, int nrMsg)
Definition krnl.c:1108
struct k_msg_t * k_crt_send_Q(int nr_el, int el_size, void *pBuf)
Definition krnl.c:841
int k_start()
Definition krnl.c:1149
#define KRNL_VRS
Definition krnl.h:2
#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_msg_t * pMsg2
Definition msg1.ino:18
char mar2[10 *2]
Definition msg1.ino:20
struct k_t * p_t2
Definition msg1.ino:16
void loop(void)
Definition msg2.ino:78
void doBlink(void)
Definition msg2.ino:28
void setup()
Definition msg2.ino:54
void t2(void)
Definition msg2.ino:44
void t1(void)
Definition msg2.ino:34
struct k_t * t1
Definition krnlgen.ino:3
struct k_t * t2
Definition krnlgen.ino:3
Definition krnl.h:323