-
Notifications
You must be signed in to change notification settings - Fork 908
Expand file tree
/
Copy pathmain.c
More file actions
90 lines (72 loc) · 1.89 KB
/
main.c
File metadata and controls
90 lines (72 loc) · 1.89 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
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
85
86
87
88
89
90
#include <stdint.h>
#include <stdbool.h>
#include "board/config.h"
// ********************* Globals **********************
uint8_t hw_type = 0;
board *current_board;
uint32_t uptime_cnt = 0;
uint32_t heartbeat_counter = 0;
bool heartbeat_lost = false;
bool heartbeat_disabled = false;
bool siren_enabled = false;
#include "board/drivers/led.h"
#include "board/drivers/pwm.h"
#include "board/drivers/usb.h"
#include "board/early_init.h"
#include "board/obj/gitversion.h"
#include "board/body/motor_control.h"
#include "board/body/can.h"
#include "opendbc/safety/safety.h"
#include "board/drivers/can_common.h"
#include "board/drivers/fdcan.h"
#include "board/can_comms.h"
extern int _app_start[0xc000];
#include "board/body/main_comms.h"
void debug_ring_callback(uart_ring *ring) {
char rcv;
while (get_char(ring, &rcv)) {
(void)injectc(ring, rcv);
}
}
void __attribute__ ((noinline)) enable_fpu(void) {
SCB->CPACR |= ((3UL << (10U * 2U)) | (3UL << (11U * 2U)));
}
void __initialize_hardware_early(void) {
enable_fpu();
early_initialization();
}
volatile uint32_t tick_count = 0;
void tick_handler(void) {
if (TICK_TIMER->SR != 0) {
if (can_health[0].transmit_error_cnt >= 128) {
(void)llcan_init(CANIF_FROM_CAN_NUM(0));
}
static bool led_on = false;
led_set(LED_RED, led_on);
led_on = !led_on;
tick_count++;
}
TICK_TIMER->SR = 0;
}
int main(void) {
disable_interrupts();
init_interrupts(true);
clock_init();
peripherals_init();
current_board = &board_body;
hw_type = HW_TYPE_BODY;
current_board->init();
REGISTER_INTERRUPT(TICK_TIMER_IRQ, tick_handler, 10U, FAULT_INTERRUPT_RATE_TICK);
led_init();
microsecond_timer_init();
tick_timer_init();
usb_init();
body_can_init();
enable_interrupts();
while (true) {
uint32_t now = microsecond_timer_get();
motor_speed_controller_update(now);
body_can_periodic(now);
}
return 0;
}