Skip to content

Commit

Permalink
ignition_can: set it to False after 2s of not seeing CAN msgs
Browse files Browse the repository at this point in the history
  • Loading branch information
rbiasini committed Dec 4, 2019
1 parent 96137f1 commit 1bcc351
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion board/drivers/can.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ bool can_pop(can_ring *q, CAN_FIFOMailBox_TypeDef *elem);

// Ignition detected from CAN meessages
bool ignition_can = false;
uint32_t ignition_can_cnt = 0U;

// end API

Expand Down Expand Up @@ -323,11 +324,12 @@ void process_can(uint8_t can_number) {
}

void ignition_can_hook(CAN_FIFOMailBox_TypeDef *to_push) {

int bus = GET_BUS(to_push);
int addr = GET_ADDR(to_push);
int len = GET_LEN(to_push);

ignition_can_cnt = 0U; // reset counter

if (bus == 0) {
// GM exception
if ((addr == 0x1F1) && (len == 8)) {
Expand Down
6 changes: 6 additions & 0 deletions board/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -699,9 +699,15 @@ void TIM1_BRK_TIM9_IRQ_Handler(void) {
}
#endif

// set ignition_can to false after 2s of no CAN seen
if (ignition_can_cnt > 2U) {
ignition_can = false;
};

// on to the next one
uptime_cnt += 1U;
safety_mode_cnt += 1U;
ignition_can_cnt += 1U;
}
TIM9->SR = 0;
}
Expand Down

0 comments on commit 1bcc351

Please sign in to comment.