-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmainloop.cpp
84 lines (58 loc) · 1.62 KB
/
mainloop.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* A stm32duino eventloop
* Copyright (c) 2018 Andrew Goh
* Provided as-is, No warranties of any kind, Use at your own risk
* License: MIT
*/
#include <Arduino.h>
#include <libmaple/systick.h>
#include "eventloop/ASyncWait.h"
#include "eventloop/Event.h"
#include "eventloop/EventLoop.h"
#include "eventloop/RingBuffer.h"
#include "eventloop/util.h"
#include "tasks/CKeySenderTask.h"
#include "tasks/CLedTask.h"
void systick_handler(void);
uint16_t systick_fired = 0;
//------------------------------------------------------------------------------
void setup() {
pinMode(BOARD_LED_PIN, OUTPUT);
digitalWrite(BOARD_LED_PIN, HIGH);
Serial.begin(115200);
delay(1000);
// Throw away serial input
while (Serial.available()) Serial.read();
//Initialize Eventloop
EventLoop.registerhandler(EHandleID::KeySenderTask, KeySenderTask);
EventLoop.registerhandler(EHandleID::LedTask, LedTask);
digitalWrite(BOARD_LED_PIN, LOW);
Serial.print(F("FreeStack:"));
Serial.println(FreeStack());
systick_attach_callback(systick_handler);
systick_fired = 0;
Event event;
event.handle_id = EHandleID::BroadCast;
event.event = EventID::AppStart;
EventLoop.post(event);
}
void loop() {
//interrupts();
if(systick_fired) {
systick_fired = 0;
//process waits
WaitMgr.processwaits();
//systick event is pre-emptive
TEvent event;
event.handle_id = EHandleID::BroadCast;
event.event = EventID::Systick;
EventLoop.proceventimm(event);
//then we process the event queue
EventLoop.processevent();
}
//noInterrupts();
//wait for interrupts and events
asm("wfe");
}
void systick_handler(void) {
systick_fired++;
}