From 6075c41624efa8260344dfd4b0c7fa563f4cfe5e Mon Sep 17 00:00:00 2001 From: Julian T Date: Sun, 7 Jun 2020 23:40:14 +0200 Subject: Added solutions for many of the first exercises --- sem4/embedded/m6/m6.ino | 67 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 sem4/embedded/m6/m6.ino (limited to 'sem4/embedded/m6/m6.ino') diff --git a/sem4/embedded/m6/m6.ino b/sem4/embedded/m6/m6.ino new file mode 100644 index 0000000..949c3d4 --- /dev/null +++ b/sem4/embedded/m6/m6.ino @@ -0,0 +1,67 @@ +#include +#define STACK 100 +#define BUTTONPIN 2 +#define LEDPIN 13 + +char stk1[STACK]; +struct k_t *tsk1; +struct k_msg_t *pmsg; +char msgbuff[10]; + +ISR(INT0_vect) { + static unsigned long last = 0; + + unsigned long now = millis(); + if (now - last < 100) { + return; + } + last = now; + + static char state = 0; + state = !state; + + ki_send(pmsg, (void *)&state); + +} + +void f1() { + while(true) { + char state; + int lost; + if (k_receive(pmsg, &state, 0, &lost) < 0) { + continue; + } + + //k_eat_msec_time(1000); + + Serial.print("Lost: "); Serial.println(lost); + + digitalWrite(LEDPIN, state); + } +} + +void setup() +{ + pinMode(LEDPIN, OUTPUT); + + pinMode(BUTTONPIN, INPUT_PULLUP); + // Enable interrupt 0 + EIMSK |= 1 << INT0; + // Eable on rising edge + EICRA |= (1 << ISC01); + + Serial.begin(115200); + Serial.println("Starting"); + + k_init(1, 0, 1); + + pmsg = k_crt_send_Q(10, 1, msgbuff); + tsk1 = k_crt_task(f1, 10, stk1, STACK); + + k_start(1); +} + +void loop() +{ + +} -- cgit v1.2.3