diff options
author | Julian T <julian@jtle.dk> | 2020-06-07 23:40:14 +0200 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2020-06-07 23:40:14 +0200 |
commit | 6075c41624efa8260344dfd4b0c7fa563f4cfe5e (patch) | |
tree | 0ee0942543935c70ddd108f71562612cdd72daee /sem4/embedded/m6 | |
parent | 6cb9bec1e0241fe64afdad9a520f026a9c25ea91 (diff) |
Added solutions for many of the first exercises
Diffstat (limited to 'sem4/embedded/m6')
-rw-r--r-- | sem4/embedded/m6/m6.ino | 67 |
1 files changed, 67 insertions, 0 deletions
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 <krnl.h> +#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() +{ + +} |