forked from IlliniSolarCar/ElecOnboarding24
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.cpp
More file actions
56 lines (47 loc) · 1.18 KB
/
main.cpp
File metadata and controls
56 lines (47 loc) · 1.18 KB
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
#include <mbed.h>
#include "pins.h"
#include "setup.h"
#include "peripherals.h"
#include "can_struct.h"
#include "CAN/can_id.h"
#include "CAN/can_data.h"
#include "can_buffer.h"
void heartbeat() {
if(common.toggleHeartbeatLED())
common.writeCANMessage(makeMessage(BRIZO_CAN::DEMO_HEART.ID, timer.read_us()));
}
void checkCANController() {
common.checkCANController();
}
void setup() {
common.setupCAN();
common.setupLEDs(&led1, &led2, &led3, &led4);
timing.addCallback(BRIZO_CAN::DEMO_HEART.RATE / 2, heartbeat);
timing.addCallback(CHECK_CAN_RATE_US, checkCANController);
bool wdt_reset;
common.startTimingCommon(&timing, &wdt_reset);
if(wdt_reset){
}
}
void shutdown_method() {
while(1) {
wdt.feed();
}
}
int main() {
setup();
uint32_t last_task_1_time = timing.onTick(NULL);
CANMessage msg;
bool shutdown = false;
while (!shutdown) {
bool overflow;
uint32_t now = common.loopTime(&timing, &overflow);
while(!common.readCANMessage(msg)) {
common.toggleReceiveCANLED();
}
if(timing.tickThreshold(last_task_1_time, HEARTBEAT_RATE_US)){
led_heartbeat.write(!led_heartbeat.read());
}
}
shutdown_method();
}