From db7d3aa8d72db8fa361da89d3e50535437590365 Mon Sep 17 00:00:00 2001 From: xps-genesis Date: Tue, 24 Nov 2020 19:20:28 -0500 Subject: [PATCH 1/4] smart MDPS support for white panda based smart mdps --- board/main.c | 6 +++--- board/safety/safety_defaults.h | 29 ++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/board/main.c b/board/main.c index c6e4f0fceed..ea08ea3aaf7 100644 --- a/board/main.c +++ b/board/main.c @@ -712,7 +712,7 @@ void TIM1_BRK_TIM9_IRQ_Handler(void) { heartbeat_counter += 1U; } - #ifdef EON + #ifdef EONNO // check heartbeat counter if we are running EON code. // if the heartbeat has been gone for a while, go to SILENT safety mode and enter power save if (heartbeat_counter >= (check_started() ? EON_HEARTBEAT_IGNITION_CNT_ON : EON_HEARTBEAT_IGNITION_CNT_OFF)) { @@ -833,8 +833,8 @@ int main(void) { TIM2->EGR = TIM_EGR_UG; // use TIM2->CNT to read - // init to SILENT and can silent - set_safety_mode(SAFETY_SILENT, 0); + // init to ALLOUTPUT and can silent + set_safety_mode(SAFETY_ALLOUTPUT, 0); // enable CAN TXs current_board->enable_can_transceivers(true); diff --git a/board/safety/safety_defaults.h b/board/safety/safety_defaults.h index 793dc961588..5a3095efc08 100644 --- a/board/safety/safety_defaults.h +++ b/board/safety/safety_defaults.h @@ -1,3 +1,16 @@ +static void send_mdps_enable_speed(CAN_FIFOMailBox_TypeDef *to_fwd){ + bool is_speed_unit_mph = GET_BYTE(to_fwd, 2) & 0x2; + + int mdps_cutoff_speed = is_speed_unit_mph ? 76 : 120; // factor of 2 from dbc + + int veh_clu_speed = GET_BYTE(to_fwd, 1) | (GET_BYTE(to_fwd, 2) & 0x1) << 8; + + if (veh_clu_speed < mdps_cutoff_speed) { + to_fwd->RDLR &= 0xFFFE00FF; + to_fwd->RDLR |= mdps_cutoff_speed << 8; + } +}; + int default_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { UNUSED(to_push); return true; @@ -24,9 +37,19 @@ static int nooutput_tx_lin_hook(int lin_num, uint8_t *data, int len) { } static int default_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) { - UNUSED(bus_num); - UNUSED(to_fwd); - return -1; + int addr = GET_ADDR(to_fwd); + int bus_fwd = -1; + + if (bus_num == 0) { + bus_fwd = 2; + if (addr == 1265) { + send_mdps_enable_speed(to_fwd); + } + } + if (bus_num == 2) { + bus_fwd = 0; + } + return bus_fwd; } const safety_hooks nooutput_hooks = { From fb1c6ed91846d69ca01d1e2c1cc7ff5309d1894a Mon Sep 17 00:00:00 2001 From: xps-genesis <65239463+xps-genesis@users.noreply.github.com> Date: Sat, 5 Dec 2020 14:29:45 -0500 Subject: [PATCH 2/4] Fix C2 power draw (#614) (#1) (#5) Co-authored-by: robbederks Co-authored-by: robbederks --- board/boards/uno.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/board/boards/uno.h b/board/boards/uno.h index 91f65a246b3..cc9c4c0dc4a 100644 --- a/board/boards/uno.h +++ b/board/boards/uno.h @@ -56,7 +56,12 @@ void uno_set_gps_load_switch(bool enabled) { } void uno_set_bootkick(bool enabled){ - set_gpio_output(GPIOB, 14, !enabled); + if(enabled){ + set_gpio_output(GPIOB, 14, false); + } else { + // We want the pin to be floating, not forced high! + set_gpio_mode(GPIOB, 14, MODE_INPUT); + } } void uno_bootkick(void) { From d03c46b7d6e69393cb5ec880ab95f254f0ddbef5 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Thu, 9 Jun 2022 11:33:51 -0400 Subject: [PATCH 3/4] Send ID message to openpilot --- board/main.c | 6 ++++++ board/safety/safety_defaults.h | 3 +++ 2 files changed, 9 insertions(+) diff --git a/board/main.c b/board/main.c index ea08ea3aaf7..b3a5ae63abf 100644 --- a/board/main.c +++ b/board/main.c @@ -104,6 +104,12 @@ void debug_ring_callback(uart_ring *ring) { } } +void smdps_clu11(void) { + CAN1->sTxMailBox[0].TDLR = 0x00; + CAN1->sTxMailBox[0].TDTR = 4; + CAN1->sTxMailBox[0].TIR = (0x2AAU << 21) | 1U; +} + // ****************************** safety mode ****************************** // this is the only way to leave silent mode diff --git a/board/safety/safety_defaults.h b/board/safety/safety_defaults.h index 5a3095efc08..eed18dae62d 100644 --- a/board/safety/safety_defaults.h +++ b/board/safety/safety_defaults.h @@ -1,3 +1,5 @@ +void smdps_clu11(void); + static void send_mdps_enable_speed(CAN_FIFOMailBox_TypeDef *to_fwd){ bool is_speed_unit_mph = GET_BYTE(to_fwd, 2) & 0x2; @@ -45,6 +47,7 @@ static int default_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) { if (addr == 1265) { send_mdps_enable_speed(to_fwd); } + smdps_clu11(); } if (bus_num == 2) { bus_fwd = 0; From a4d275305a8e8f18d16c16c3d2242a99e5d6eed7 Mon Sep 17 00:00:00 2001 From: Jason Lim Date: Fri, 15 Mar 2024 11:50:09 +0800 Subject: [PATCH 4/4] BP SMDPS Testing --- board/main.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/board/main.c b/board/main.c index b3a5ae63abf..60837f3e85f 100644 --- a/board/main.c +++ b/board/main.c @@ -105,9 +105,11 @@ void debug_ring_callback(uart_ring *ring) { } void smdps_clu11(void) { - CAN1->sTxMailBox[0].TDLR = 0x00; - CAN1->sTxMailBox[0].TDTR = 4; - CAN1->sTxMailBox[0].TIR = (0x2AAU << 21) | 1U; + CAN_FIFOMailBox_TypeDef to_send; + to_send.RDLR = 0x00; + to_send.RDTR = 4; + to_send.RIR = (0x2AA << 21) | 1U; + can_send(&to_send, 0, false); } // ****************************** safety mode ******************************