krnl 1
Loading...
Searching...
No Matches
rt-arduino-isrsendmsg.ino
Go to the documentation of this file.
1/* critical region - by semaphores - aka mutex
2 JDN
3 * */
4
5#include <krnl.h>
6
7#define STK 150
8
9#define TASKPRIO 10
10
11
12struct k_t * pTask1 ;
13struct k_msg_t * msgQ;
14const int BUFSZ = 10;
15
17
18
19
20
21volatile int ISRoverflow = 0;
22
23volatile int nrISR = 0;
24
25volatile unsigned long last = 0;
26
27ISR(INT4_vect, ISR_NAKED) { // digital pin 2 på uno
28 PUSHREGS();
29 if (!k_running)
30 goto exitt ;
31
32 nrISR++;
34
35 K_CHG_STAK();
36
37exitt:
38 POPREGS();
39 RETI();
40}
41
42
43void task1()
44{
45 int res = 0;
46 int t = 0;
47 int lost;
48
49 while (1) {
50
51 if (-1 == k_receive(msgQ, &res, 1000, &lost)) { // next time nr lost is received inside msg Q system
52 t++;
53 Serial.print("timeout "); Serial.println(t);
54 }
55 else {
56 Serial.print("get msg "); Serial.print(res); Serial.print(" lost since last "); Serial.println(lost);
57 }
58 }
59}
60
61
62
63
64void setup() {
65 // for debugging - only on uno eq- If Mega etc use PORTA(which is pn 22,23,...)
66 // see http://kom.aau.dk/~jdn/edu/doc/arduino/mega.png
67
68 Serial.begin(115200);
69 delay(2000);
70
71 Serial.println("just bef init part");
72
73 k_init(1, 0, 1); // 2 task, 1 semaphores, 0 messaegQueues */
74
75 pTask1 = k_crt_task(task1, 15, STK);
76
77
78
79 Serial.println("just bef k_start");
80
81
82 pinMode(2, INPUT_PULLUP);
83
84 noInterrupts();
85
86 msgQ = k_crt_send_Q(BUFSZ, sizeof(int), bufForQ);
87
88 // eller fra krnl DI();
89
90 EICRA |= (1 << ISC01); // trigger INT0 on falling edge
91 EIMSK |= (1 << INT0); // enable external intr
92
93 //https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7810-Automotive-Microcontrollers-ATmega328P_Datasheet.pdf p 54
94 // EICRB |= 1>> ISC41; // for mega on pin 2
95 // EIMSK |= B00010000; // enable INT 4 for mega
96 // https://ww1.microchip.com/downloads/en/devicedoc/atmel-2549-8-bit-avr-microcontroller-atmega640-1280-1281-2560-2561_datasheet.pdf
97
98 interrupts();
99
100 k_start(1); /* start krnl timer speed 1 milliseconds*/
101
102 Serial.println("If you see this then krnl didnt start :-( ");
103}
104
105void loop() {}
#define STK
void task1()
volatile int ISRoverflow
Definition k08isrsem.ino:26
struct k_t * pTask1
Definition k08isrsem.ino:17
struct k_msg_t * msgQ
Definition k09msgq.ino:13
char k_receive(struct k_msg_t *pB, void *el, int timeout, int *lost_msg)
Definition krnl.c:991
volatile char k_running
Definition krnl.c:156
char ki_send(struct k_msg_t *pB, void *el)
Definition krnl.c:908
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
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 RETI()
Definition krnl.h:480
#define K_CHG_STAK()
Definition krnl.h:488
int bufForQ[BUFSZ]
const int BUFSZ
void setup()
ISR(INT4_vect, ISR_NAKED)
volatile int nrISR
volatile unsigned long last
void task1()
void loop()
PUSHREGS()
Definition krnl.h:323