aboutsummaryrefslogtreecommitdiff
path: root/sem4/embedded/m6
diff options
context:
space:
mode:
Diffstat (limited to 'sem4/embedded/m6')
-rw-r--r--sem4/embedded/m6/m6.ino67
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()
+{
+
+}