@@ -26,6 +26,33 @@ static void black_enable_can_transceiver(uint8_t transceiver, bool enabled) {
|
||||
}
|
||||
}
|
||||
|
||||
static void black_enable_can_transceivers(bool enabled) {
|
||||
for(uint8_t i=1U; i<=4U; i++){
|
||||
// Leave main CAN always on for CAN-based ignition detection
|
||||
if((harness.status == HARNESS_STATUS_FLIPPED) ? (i == 3U) : (i == 1U)){
|
||||
black_enable_can_transceiver(i, true);
|
||||
} else {
|
||||
black_enable_can_transceiver(i, enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void black_set_led(uint8_t color, bool enabled) {
|
||||
switch (color){
|
||||
case LED_RED:
|
||||
set_gpio_output(GPIOC, 9, !enabled);
|
||||
break;
|
||||
case LED_GREEN:
|
||||
set_gpio_output(GPIOC, 7, !enabled);
|
||||
break;
|
||||
case LED_BLUE:
|
||||
set_gpio_output(GPIOC, 6, !enabled);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void black_set_usb_load_switch(bool enabled) {
|
||||
set_gpio_output(GPIOB, 1, !enabled);
|
||||
}
|
||||
@@ -75,12 +102,41 @@ static void black_init(void) {
|
||||
set_gpio_alternate(GPIOA, 8, GPIO_AF11_CAN3);
|
||||
set_gpio_alternate(GPIOA, 15, GPIO_AF11_CAN3);
|
||||
|
||||
// C0: OBD_SBU1 (orientation detection)
|
||||
// C3: OBD_SBU2 (orientation detection)
|
||||
set_gpio_mode(GPIOC, 0, MODE_ANALOG);
|
||||
set_gpio_mode(GPIOC, 3, MODE_ANALOG);
|
||||
|
||||
// GPS OFF
|
||||
set_gpio_output(GPIOC, 5, 0);
|
||||
set_gpio_output(GPIOC, 12, 0);
|
||||
|
||||
// C10: OBD_SBU1_RELAY (harness relay driving output)
|
||||
// C11: OBD_SBU2_RELAY (harness relay driving output)
|
||||
set_gpio_mode(GPIOC, 10, MODE_OUTPUT);
|
||||
set_gpio_mode(GPIOC, 11, MODE_OUTPUT);
|
||||
set_gpio_output_type(GPIOC, 10, OUTPUT_TYPE_OPEN_DRAIN);
|
||||
set_gpio_output_type(GPIOC, 11, OUTPUT_TYPE_OPEN_DRAIN);
|
||||
set_gpio_output(GPIOC, 10, 1);
|
||||
set_gpio_output(GPIOC, 11, 1);
|
||||
|
||||
// Turn on USB load switch.
|
||||
black_set_usb_load_switch(true);
|
||||
|
||||
// Initialize harness
|
||||
harness_init();
|
||||
|
||||
|
||||
// Enable CAN transceivers
|
||||
black_enable_can_transceivers(true);
|
||||
|
||||
// Disable LEDs
|
||||
black_set_led(LED_RED, false);
|
||||
black_set_led(LED_GREEN, false);
|
||||
black_set_led(LED_BLUE, false);
|
||||
|
||||
// Set normal CAN mode
|
||||
black_set_can_mode(CAN_MODE_NORMAL);
|
||||
}
|
||||
|
||||
static void black_init_bootloader(void) {
|
||||
@@ -106,6 +162,7 @@ static harness_configuration black_harness_config = {
|
||||
board board_black = {
|
||||
.set_bootkick = unused_set_bootkick,
|
||||
.harness_config = &black_harness_config,
|
||||
.has_obd = true,
|
||||
.has_spi = false,
|
||||
.has_canfd = false,
|
||||
.fan_max_rpm = 0U,
|
||||
@@ -116,8 +173,8 @@ board board_black = {
|
||||
.init = black_init,
|
||||
.init_bootloader = black_init_bootloader,
|
||||
.enable_can_transceiver = black_enable_can_transceiver,
|
||||
.led_GPIO = {GPIOC, GPIOC, GPIOC},
|
||||
.led_pin = {9, 7, 6},
|
||||
.enable_can_transceivers = black_enable_can_transceivers,
|
||||
.set_led = black_set_led,
|
||||
.set_can_mode = black_set_can_mode,
|
||||
.check_ignition = black_check_ignition,
|
||||
.read_voltage_mV = white_read_voltage_mV,
|
||||
|
||||
@@ -13,6 +13,8 @@ typedef enum {
|
||||
typedef void (*board_init)(void);
|
||||
typedef void (*board_init_bootloader)(void);
|
||||
typedef void (*board_enable_can_transceiver)(uint8_t transceiver, bool enabled);
|
||||
typedef void (*board_enable_can_transceivers)(bool enabled);
|
||||
typedef void (*board_set_led)(uint8_t color, bool enabled);
|
||||
typedef void (*board_set_can_mode)(uint8_t mode);
|
||||
typedef bool (*board_check_ignition)(void);
|
||||
typedef uint32_t (*board_read_voltage_mV)(void);
|
||||
@@ -26,8 +28,7 @@ typedef void (*board_set_amp_enabled)(bool enabled);
|
||||
|
||||
struct board {
|
||||
harness_configuration *harness_config;
|
||||
GPIO_TypeDef * const led_GPIO[3];
|
||||
const uint8_t led_pin[3];
|
||||
const bool has_obd;
|
||||
const bool has_spi;
|
||||
const bool has_canfd;
|
||||
const uint16_t fan_max_rpm;
|
||||
@@ -38,6 +39,8 @@ struct board {
|
||||
board_init init;
|
||||
board_init_bootloader init_bootloader;
|
||||
board_enable_can_transceiver enable_can_transceiver;
|
||||
board_enable_can_transceivers enable_can_transceivers;
|
||||
board_set_led set_led;
|
||||
board_set_can_mode set_can_mode;
|
||||
board_check_ignition check_ignition;
|
||||
board_read_voltage_mV read_voltage_mV;
|
||||
@@ -64,6 +67,11 @@ struct board {
|
||||
#define HW_TYPE_TRES 9U
|
||||
#define HW_TYPE_CUATRO 10U
|
||||
|
||||
// LED colors
|
||||
#define LED_RED 0U
|
||||
#define LED_GREEN 1U
|
||||
#define LED_BLUE 2U
|
||||
|
||||
// USB power modes (from cereal.log.health)
|
||||
#define USB_POWER_NONE 0U
|
||||
#define USB_POWER_CLIENT 1U
|
||||
|
||||
@@ -6,6 +6,22 @@
|
||||
// Cuatro (STM32H7) + Harness //
|
||||
// ////////////////////////// //
|
||||
|
||||
static void cuatro_set_led(uint8_t color, bool enabled) {
|
||||
switch (color) {
|
||||
case LED_RED:
|
||||
set_gpio_output(GPIOC, 6, !enabled);
|
||||
break;
|
||||
case LED_GREEN:
|
||||
set_gpio_output(GPIOC, 7, !enabled);
|
||||
break;
|
||||
case LED_BLUE:
|
||||
set_gpio_output(GPIOC, 9, !enabled);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void cuatro_enable_can_transceiver(uint8_t transceiver, bool enabled) {
|
||||
switch (transceiver) {
|
||||
case 1U:
|
||||
@@ -25,6 +41,18 @@ static void cuatro_enable_can_transceiver(uint8_t transceiver, bool enabled) {
|
||||
}
|
||||
}
|
||||
|
||||
static void cuatro_enable_can_transceivers(bool enabled) {
|
||||
uint8_t main_bus = (harness.status == HARNESS_STATUS_FLIPPED) ? 3U : 1U;
|
||||
for (uint8_t i=1U; i<=4U; i++) {
|
||||
// Leave main CAN always on for CAN-based ignition detection
|
||||
if (i == main_bus) {
|
||||
cuatro_enable_can_transceiver(i, true);
|
||||
} else {
|
||||
cuatro_enable_can_transceiver(i, enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t cuatro_read_voltage_mV(void) {
|
||||
return adc_get_mV(8) * 11U;
|
||||
}
|
||||
@@ -40,7 +68,7 @@ static void cuatro_set_fan_enabled(bool enabled) {
|
||||
static void cuatro_set_bootkick(BootState state) {
|
||||
set_gpio_output(GPIOA, 0, state != BOOT_BOOTKICK);
|
||||
// TODO: confirm we need this
|
||||
//set_gpio_output(GPIOC, 12, state != BOOT_RESET);
|
||||
set_gpio_output(GPIOC, 12, state != BOOT_RESET);
|
||||
}
|
||||
|
||||
static void cuatro_set_amp_enabled(bool enabled){
|
||||
@@ -48,9 +76,14 @@ static void cuatro_set_amp_enabled(bool enabled){
|
||||
}
|
||||
|
||||
static void cuatro_init(void) {
|
||||
common_init_gpio();
|
||||
red_chiplet_init();
|
||||
|
||||
// open drain
|
||||
// init LEDs as open drain
|
||||
set_gpio_output_type(GPIOC, 6, OUTPUT_TYPE_OPEN_DRAIN);
|
||||
set_gpio_output_type(GPIOC, 7, OUTPUT_TYPE_OPEN_DRAIN);
|
||||
set_gpio_output_type(GPIOC, 9, OUTPUT_TYPE_OPEN_DRAIN);
|
||||
|
||||
// more open drain
|
||||
set_gpio_output_type(GPIOD, 3, OUTPUT_TYPE_OPEN_DRAIN); // FAN_EN
|
||||
set_gpio_output_type(GPIOC, 12, OUTPUT_TYPE_OPEN_DRAIN); // VBAT_EN
|
||||
|
||||
@@ -81,6 +114,9 @@ static void cuatro_init(void) {
|
||||
gpio_uart7_init();
|
||||
uart_init(&uart_ring_som_debug, 115200);
|
||||
|
||||
// SPI init
|
||||
gpio_spi_init();
|
||||
|
||||
// fan setup
|
||||
set_gpio_alternate(GPIOC, 8, GPIO_AF2_TIM3);
|
||||
register_set_bits(&(GPIOC->OTYPER), GPIO_OTYPER_OT8); // open drain
|
||||
@@ -106,7 +142,8 @@ static void cuatro_init(void) {
|
||||
}
|
||||
|
||||
board board_cuatro = {
|
||||
.harness_config = &tres_harness_config,
|
||||
.harness_config = &red_chiplet_harness_config,
|
||||
.has_obd = true,
|
||||
.has_spi = true,
|
||||
.has_canfd = true,
|
||||
.fan_max_rpm = 12500U,
|
||||
@@ -117,9 +154,9 @@ board board_cuatro = {
|
||||
.init = cuatro_init,
|
||||
.init_bootloader = unused_init_bootloader,
|
||||
.enable_can_transceiver = cuatro_enable_can_transceiver,
|
||||
.led_GPIO = {GPIOC, GPIOC, GPIOC},
|
||||
.led_pin = {6, 7, 9},
|
||||
.set_can_mode = tres_set_can_mode,
|
||||
.enable_can_transceivers = cuatro_enable_can_transceivers,
|
||||
.set_led = cuatro_set_led,
|
||||
.set_can_mode = red_chiplet_set_can_mode,
|
||||
.check_ignition = red_check_ignition,
|
||||
.read_voltage_mV = cuatro_read_voltage_mV,
|
||||
.read_current_mA = cuatro_read_current_mA,
|
||||
|
||||
@@ -26,6 +26,33 @@ static void dos_enable_can_transceiver(uint8_t transceiver, bool enabled) {
|
||||
}
|
||||
}
|
||||
|
||||
static void dos_enable_can_transceivers(bool enabled) {
|
||||
for(uint8_t i=1U; i<=4U; i++){
|
||||
// Leave main CAN always on for CAN-based ignition detection
|
||||
if((harness.status == HARNESS_STATUS_FLIPPED) ? (i == 3U) : (i == 1U)){
|
||||
dos_enable_can_transceiver(i, true);
|
||||
} else {
|
||||
dos_enable_can_transceiver(i, enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void dos_set_led(uint8_t color, bool enabled) {
|
||||
switch (color){
|
||||
case LED_RED:
|
||||
set_gpio_output(GPIOC, 9, !enabled);
|
||||
break;
|
||||
case LED_GREEN:
|
||||
set_gpio_output(GPIOC, 7, !enabled);
|
||||
break;
|
||||
case LED_BLUE:
|
||||
set_gpio_output(GPIOC, 6, !enabled);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void dos_set_bootkick(BootState state) {
|
||||
set_gpio_output(GPIOC, 4, state != BOOT_BOOTKICK);
|
||||
}
|
||||
@@ -90,6 +117,25 @@ static void dos_init(void) {
|
||||
set_gpio_alternate(GPIOA, 8, GPIO_AF11_CAN3);
|
||||
set_gpio_alternate(GPIOA, 15, GPIO_AF11_CAN3);
|
||||
|
||||
// C0: OBD_SBU1 (orientation detection)
|
||||
// C3: OBD_SBU2 (orientation detection)
|
||||
set_gpio_mode(GPIOC, 0, MODE_ANALOG);
|
||||
set_gpio_mode(GPIOC, 3, MODE_ANALOG);
|
||||
|
||||
// C10: OBD_SBU1_RELAY (harness relay driving output)
|
||||
// C11: OBD_SBU2_RELAY (harness relay driving output)
|
||||
set_gpio_mode(GPIOC, 10, MODE_OUTPUT);
|
||||
set_gpio_mode(GPIOC, 11, MODE_OUTPUT);
|
||||
set_gpio_output_type(GPIOC, 10, OUTPUT_TYPE_OPEN_DRAIN);
|
||||
set_gpio_output_type(GPIOC, 11, OUTPUT_TYPE_OPEN_DRAIN);
|
||||
set_gpio_output(GPIOC, 10, 1);
|
||||
set_gpio_output(GPIOC, 11, 1);
|
||||
|
||||
#ifdef ENABLE_SPI
|
||||
// SPI init
|
||||
gpio_spi_init();
|
||||
#endif
|
||||
|
||||
// C8: FAN PWM aka TIM3_CH3
|
||||
set_gpio_alternate(GPIOC, 8, GPIO_AF2_TIM3);
|
||||
|
||||
@@ -102,9 +148,24 @@ static void dos_init(void) {
|
||||
pwm_init(TIM4, 2);
|
||||
dos_set_ir_power(0U);
|
||||
|
||||
// Initialize harness
|
||||
harness_init();
|
||||
|
||||
|
||||
// Enable CAN transceivers
|
||||
dos_enable_can_transceivers(true);
|
||||
|
||||
// Disable LEDs
|
||||
dos_set_led(LED_RED, false);
|
||||
dos_set_led(LED_GREEN, false);
|
||||
dos_set_led(LED_BLUE, false);
|
||||
|
||||
// Bootkick
|
||||
dos_set_bootkick(true);
|
||||
|
||||
// Set normal CAN mode
|
||||
dos_set_can_mode(CAN_MODE_NORMAL);
|
||||
|
||||
// Init clock source (camera strobe) using PWM
|
||||
clock_source_init();
|
||||
}
|
||||
@@ -125,6 +186,7 @@ static harness_configuration dos_harness_config = {
|
||||
|
||||
board board_dos = {
|
||||
.harness_config = &dos_harness_config,
|
||||
.has_obd = true,
|
||||
#ifdef ENABLE_SPI
|
||||
.has_spi = true,
|
||||
#else
|
||||
@@ -139,8 +201,8 @@ board board_dos = {
|
||||
.init = dos_init,
|
||||
.init_bootloader = unused_init_bootloader,
|
||||
.enable_can_transceiver = dos_enable_can_transceiver,
|
||||
.led_GPIO = {GPIOC, GPIOC, GPIOC},
|
||||
.led_pin = {9, 7, 6},
|
||||
.enable_can_transceivers = dos_enable_can_transceivers,
|
||||
.set_led = dos_set_led,
|
||||
.set_can_mode = dos_set_can_mode,
|
||||
.check_ignition = dos_check_ignition,
|
||||
.read_voltage_mV = white_read_voltage_mV,
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
board board_grey = {
|
||||
.set_bootkick = unused_set_bootkick,
|
||||
.harness_config = &white_harness_config,
|
||||
.has_obd = false,
|
||||
.has_spi = false,
|
||||
.has_canfd = false,
|
||||
.fan_max_rpm = 0U,
|
||||
@@ -21,8 +22,8 @@ board board_grey = {
|
||||
.init = white_grey_init,
|
||||
.init_bootloader = white_grey_init_bootloader,
|
||||
.enable_can_transceiver = white_enable_can_transceiver,
|
||||
.led_GPIO = {GPIOC, GPIOC, GPIOC},
|
||||
.led_pin = {9, 7, 6},
|
||||
.enable_can_transceivers = white_enable_can_transceivers,
|
||||
.set_led = white_set_led,
|
||||
.set_can_mode = white_set_can_mode,
|
||||
.check_ignition = white_check_ignition,
|
||||
.read_voltage_mV = white_read_voltage_mV,
|
||||
|
||||
@@ -25,6 +25,34 @@ static void red_enable_can_transceiver(uint8_t transceiver, bool enabled) {
|
||||
}
|
||||
}
|
||||
|
||||
static void red_enable_can_transceivers(bool enabled) {
|
||||
uint8_t main_bus = (harness.status == HARNESS_STATUS_FLIPPED) ? 3U : 1U;
|
||||
for (uint8_t i=1U; i<=4U; i++) {
|
||||
// Leave main CAN always on for CAN-based ignition detection
|
||||
if (i == main_bus) {
|
||||
red_enable_can_transceiver(i, true);
|
||||
} else {
|
||||
red_enable_can_transceiver(i, enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void red_set_led(uint8_t color, bool enabled) {
|
||||
switch (color) {
|
||||
case LED_RED:
|
||||
set_gpio_output(GPIOE, 4, !enabled);
|
||||
break;
|
||||
case LED_GREEN:
|
||||
set_gpio_output(GPIOE, 3, !enabled);
|
||||
break;
|
||||
case LED_BLUE:
|
||||
set_gpio_output(GPIOE, 2, !enabled);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void red_set_can_mode(uint8_t mode) {
|
||||
red_enable_can_transceiver(2U, false);
|
||||
red_enable_can_transceiver(4U, false);
|
||||
@@ -79,6 +107,17 @@ static uint32_t red_read_voltage_mV(void){
|
||||
static void red_init(void) {
|
||||
common_init_gpio();
|
||||
|
||||
//C10,C11 : OBD_SBU1_RELAY, OBD_SBU2_RELAY
|
||||
set_gpio_output_type(GPIOC, 10, OUTPUT_TYPE_OPEN_DRAIN);
|
||||
set_gpio_pullup(GPIOC, 10, PULL_NONE);
|
||||
set_gpio_mode(GPIOC, 10, MODE_OUTPUT);
|
||||
set_gpio_output(GPIOC, 10, 1);
|
||||
|
||||
set_gpio_output_type(GPIOC, 11, OUTPUT_TYPE_OPEN_DRAIN);
|
||||
set_gpio_pullup(GPIOC, 11, PULL_NONE);
|
||||
set_gpio_mode(GPIOC, 11, MODE_OUTPUT);
|
||||
set_gpio_output(GPIOC, 11, 1);
|
||||
|
||||
// G11,B3,D7,B4: transceiver enable
|
||||
set_gpio_pullup(GPIOG, 11, PULL_NONE);
|
||||
set_gpio_mode(GPIOG, 11, MODE_OUTPUT);
|
||||
@@ -101,6 +140,21 @@ static void red_init(void) {
|
||||
set_gpio_pullup(GPIOB, 14, PULL_UP);
|
||||
set_gpio_mode(GPIOB, 14, MODE_OUTPUT);
|
||||
set_gpio_output(GPIOB, 14, 1);
|
||||
|
||||
// Initialize harness
|
||||
harness_init();
|
||||
|
||||
|
||||
// Enable CAN transceivers
|
||||
red_enable_can_transceivers(true);
|
||||
|
||||
// Disable LEDs
|
||||
red_set_led(LED_RED, false);
|
||||
red_set_led(LED_GREEN, false);
|
||||
red_set_led(LED_BLUE, false);
|
||||
|
||||
// Set normal CAN mode
|
||||
red_set_can_mode(CAN_MODE_NORMAL);
|
||||
}
|
||||
|
||||
static harness_configuration red_harness_config = {
|
||||
@@ -120,6 +174,7 @@ static harness_configuration red_harness_config = {
|
||||
board board_red = {
|
||||
.set_bootkick = unused_set_bootkick,
|
||||
.harness_config = &red_harness_config,
|
||||
.has_obd = true,
|
||||
.has_spi = false,
|
||||
.has_canfd = true,
|
||||
.fan_max_rpm = 0U,
|
||||
@@ -130,8 +185,8 @@ board board_red = {
|
||||
.init = red_init,
|
||||
.init_bootloader = unused_init_bootloader,
|
||||
.enable_can_transceiver = red_enable_can_transceiver,
|
||||
.led_GPIO = {GPIOE, GPIOE, GPIOE},
|
||||
.led_pin = {4, 3, 2},
|
||||
.enable_can_transceivers = red_enable_can_transceivers,
|
||||
.set_led = red_set_led,
|
||||
.set_can_mode = red_set_can_mode,
|
||||
.check_ignition = red_check_ignition,
|
||||
.read_voltage_mV = red_read_voltage_mV,
|
||||
|
||||
+11
-82
@@ -9,7 +9,7 @@
|
||||
static bool tres_ir_enabled;
|
||||
static bool tres_fan_enabled;
|
||||
static void tres_update_fan_ir_power(void) {
|
||||
set_gpio_output(GPIOD, 3, tres_ir_enabled || tres_fan_enabled);
|
||||
red_chiplet_set_fan_or_usb_load_switch(tres_ir_enabled || tres_fan_enabled);
|
||||
}
|
||||
|
||||
static void tres_set_ir_power(uint8_t percentage){
|
||||
@@ -29,67 +29,6 @@ static void tres_set_fan_enabled(bool enabled) {
|
||||
tres_update_fan_ir_power();
|
||||
}
|
||||
|
||||
static void tres_enable_can_transceiver(uint8_t transceiver, bool enabled) {
|
||||
switch (transceiver) {
|
||||
case 1U:
|
||||
set_gpio_output(GPIOG, 11, !enabled);
|
||||
break;
|
||||
case 2U:
|
||||
set_gpio_output(GPIOB, 10, !enabled);
|
||||
break;
|
||||
case 3U:
|
||||
set_gpio_output(GPIOD, 7, !enabled);
|
||||
break;
|
||||
case 4U:
|
||||
set_gpio_output(GPIOB, 11, !enabled);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void tres_set_can_mode(uint8_t mode) {
|
||||
current_board->enable_can_transceiver(2U, false);
|
||||
current_board->enable_can_transceiver(4U, false);
|
||||
switch (mode) {
|
||||
case CAN_MODE_NORMAL:
|
||||
case CAN_MODE_OBD_CAN2:
|
||||
if ((bool)(mode == CAN_MODE_NORMAL) != (bool)(harness.status == HARNESS_STATUS_FLIPPED)) {
|
||||
// B12,B13: disable normal mode
|
||||
set_gpio_pullup(GPIOB, 12, PULL_NONE);
|
||||
set_gpio_mode(GPIOB, 12, MODE_ANALOG);
|
||||
|
||||
set_gpio_pullup(GPIOB, 13, PULL_NONE);
|
||||
set_gpio_mode(GPIOB, 13, MODE_ANALOG);
|
||||
|
||||
// B5,B6: FDCAN2 mode
|
||||
set_gpio_pullup(GPIOB, 5, PULL_NONE);
|
||||
set_gpio_alternate(GPIOB, 5, GPIO_AF9_FDCAN2);
|
||||
|
||||
set_gpio_pullup(GPIOB, 6, PULL_NONE);
|
||||
set_gpio_alternate(GPIOB, 6, GPIO_AF9_FDCAN2);
|
||||
current_board->enable_can_transceiver(2U, true);
|
||||
} else {
|
||||
// B5,B6: disable normal mode
|
||||
set_gpio_pullup(GPIOB, 5, PULL_NONE);
|
||||
set_gpio_mode(GPIOB, 5, MODE_ANALOG);
|
||||
|
||||
set_gpio_pullup(GPIOB, 6, PULL_NONE);
|
||||
set_gpio_mode(GPIOB, 6, MODE_ANALOG);
|
||||
// B12,B13: FDCAN2 mode
|
||||
set_gpio_pullup(GPIOB, 12, PULL_NONE);
|
||||
set_gpio_alternate(GPIOB, 12, GPIO_AF9_FDCAN2);
|
||||
|
||||
set_gpio_pullup(GPIOB, 13, PULL_NONE);
|
||||
set_gpio_alternate(GPIOB, 13, GPIO_AF9_FDCAN2);
|
||||
current_board->enable_can_transceiver(4U, true);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static bool tres_read_som_gpio (void) {
|
||||
return (get_gpio_input(GPIOC, 2) != 0);
|
||||
}
|
||||
@@ -100,7 +39,7 @@ static void tres_init(void) {
|
||||
register_set_bits(&(PWR->CR3), PWR_CR3_USB33DEN);
|
||||
while ((PWR->CR3 & PWR_CR3_USB33RDY) == 0U);
|
||||
|
||||
common_init_gpio();
|
||||
red_chiplet_init();
|
||||
|
||||
// C2: SOM GPIO used as input (fan control at boot)
|
||||
set_gpio_mode(GPIOC, 2, MODE_INPUT);
|
||||
@@ -115,6 +54,9 @@ static void tres_init(void) {
|
||||
gpio_uart7_init();
|
||||
uart_init(&uart_ring_som_debug, 115200);
|
||||
|
||||
// SPI init
|
||||
gpio_spi_init();
|
||||
|
||||
// fan setup
|
||||
set_gpio_alternate(GPIOC, 8, GPIO_AF2_TIM3);
|
||||
|
||||
@@ -132,22 +74,9 @@ static void tres_init(void) {
|
||||
clock_source_init();
|
||||
}
|
||||
|
||||
static harness_configuration tres_harness_config = {
|
||||
.has_harness = true,
|
||||
.GPIO_SBU1 = GPIOC,
|
||||
.GPIO_SBU2 = GPIOA,
|
||||
.GPIO_relay_SBU1 = GPIOA,
|
||||
.GPIO_relay_SBU2 = GPIOA,
|
||||
.pin_SBU1 = 4,
|
||||
.pin_SBU2 = 1,
|
||||
.pin_relay_SBU1 = 8,
|
||||
.pin_relay_SBU2 = 3,
|
||||
.adc_channel_SBU1 = 4, // ADC12_INP4
|
||||
.adc_channel_SBU2 = 17 // ADC1_INP17
|
||||
};
|
||||
|
||||
board board_tres = {
|
||||
.harness_config = &tres_harness_config,
|
||||
.harness_config = &red_chiplet_harness_config,
|
||||
.has_obd = true,
|
||||
.has_spi = true,
|
||||
.has_canfd = true,
|
||||
.fan_max_rpm = 6600U,
|
||||
@@ -157,10 +86,10 @@ board board_tres = {
|
||||
.fan_enable_cooldown_time = 3U,
|
||||
.init = tres_init,
|
||||
.init_bootloader = unused_init_bootloader,
|
||||
.enable_can_transceiver = tres_enable_can_transceiver,
|
||||
.led_GPIO = {GPIOE, GPIOE, GPIOE},
|
||||
.led_pin = {4, 3, 2},
|
||||
.set_can_mode = tres_set_can_mode,
|
||||
.enable_can_transceiver = red_chiplet_enable_can_transceiver,
|
||||
.enable_can_transceivers = red_chiplet_enable_can_transceivers,
|
||||
.set_led = red_set_led,
|
||||
.set_can_mode = red_chiplet_set_can_mode,
|
||||
.check_ignition = red_check_ignition,
|
||||
.read_voltage_mV = red_read_voltage_mV,
|
||||
.read_current_mA = unused_read_current,
|
||||
|
||||
@@ -26,6 +26,33 @@ static void uno_enable_can_transceiver(uint8_t transceiver, bool enabled) {
|
||||
}
|
||||
}
|
||||
|
||||
static void uno_enable_can_transceivers(bool enabled) {
|
||||
for(uint8_t i=1U; i<=4U; i++){
|
||||
// Leave main CAN always on for CAN-based ignition detection
|
||||
if((harness.status == HARNESS_STATUS_FLIPPED) ? (i == 3U) : (i == 1U)){
|
||||
uno_enable_can_transceiver(i, true);
|
||||
} else {
|
||||
uno_enable_can_transceiver(i, enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void uno_set_led(uint8_t color, bool enabled) {
|
||||
switch (color){
|
||||
case LED_RED:
|
||||
set_gpio_output(GPIOC, 9, !enabled);
|
||||
break;
|
||||
case LED_GREEN:
|
||||
set_gpio_output(GPIOC, 7, !enabled);
|
||||
break;
|
||||
case LED_BLUE:
|
||||
set_gpio_output(GPIOC, 6, !enabled);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void uno_set_bootkick(BootState state) {
|
||||
if (state == BOOT_BOOTKICK) {
|
||||
set_gpio_output(GPIOB, 14, false);
|
||||
@@ -91,11 +118,25 @@ static void uno_init(void) {
|
||||
set_gpio_alternate(GPIOA, 8, GPIO_AF11_CAN3);
|
||||
set_gpio_alternate(GPIOA, 15, GPIO_AF11_CAN3);
|
||||
|
||||
// C0: OBD_SBU1 (orientation detection)
|
||||
// C3: OBD_SBU2 (orientation detection)
|
||||
set_gpio_mode(GPIOC, 0, MODE_ANALOG);
|
||||
set_gpio_mode(GPIOC, 3, MODE_ANALOG);
|
||||
|
||||
// GPS off
|
||||
set_gpio_output(GPIOB, 1, 0);
|
||||
set_gpio_output(GPIOC, 5, 0);
|
||||
set_gpio_output(GPIOC, 12, 0);
|
||||
|
||||
// C10: OBD_SBU1_RELAY (harness relay driving output)
|
||||
// C11: OBD_SBU2_RELAY (harness relay driving output)
|
||||
set_gpio_mode(GPIOC, 10, MODE_OUTPUT);
|
||||
set_gpio_mode(GPIOC, 11, MODE_OUTPUT);
|
||||
set_gpio_output_type(GPIOC, 10, OUTPUT_TYPE_OPEN_DRAIN);
|
||||
set_gpio_output_type(GPIOC, 11, OUTPUT_TYPE_OPEN_DRAIN);
|
||||
set_gpio_output(GPIOC, 10, 1);
|
||||
set_gpio_output(GPIOC, 11, 1);
|
||||
|
||||
// C8: FAN PWM aka TIM3_CH3
|
||||
set_gpio_alternate(GPIOC, 8, GPIO_AF2_TIM3);
|
||||
|
||||
@@ -107,6 +148,21 @@ static void uno_init(void) {
|
||||
pwm_init(TIM4, 2);
|
||||
uno_set_ir_power(0U);
|
||||
|
||||
// Initialize harness
|
||||
harness_init();
|
||||
|
||||
|
||||
// Enable CAN transceivers
|
||||
uno_enable_can_transceivers(true);
|
||||
|
||||
// Disable LEDs
|
||||
uno_set_led(LED_RED, false);
|
||||
uno_set_led(LED_GREEN, false);
|
||||
uno_set_led(LED_BLUE, false);
|
||||
|
||||
// Set normal CAN mode
|
||||
uno_set_can_mode(CAN_MODE_NORMAL);
|
||||
|
||||
// Switch to phone usb mode if harness connection is powered by less than 7V
|
||||
if(white_read_voltage_mV() < 7000U){
|
||||
uno_set_usb_switch(true);
|
||||
@@ -141,6 +197,7 @@ static harness_configuration uno_harness_config = {
|
||||
|
||||
board board_uno = {
|
||||
.harness_config = &uno_harness_config,
|
||||
.has_obd = true,
|
||||
.has_spi = false,
|
||||
.has_canfd = false,
|
||||
.fan_max_rpm = 5100U,
|
||||
@@ -151,8 +208,8 @@ board board_uno = {
|
||||
.init = uno_init,
|
||||
.init_bootloader = uno_init_bootloader,
|
||||
.enable_can_transceiver = uno_enable_can_transceiver,
|
||||
.led_GPIO = {GPIOC, GPIOC, GPIOC},
|
||||
.led_pin = {9, 7, 6},
|
||||
.enable_can_transceivers = uno_enable_can_transceivers,
|
||||
.set_led = uno_set_led,
|
||||
.set_can_mode = uno_set_can_mode,
|
||||
.check_ignition = uno_check_ignition,
|
||||
.read_voltage_mV = white_read_voltage_mV,
|
||||
|
||||
@@ -17,6 +17,30 @@ static void white_enable_can_transceiver(uint8_t transceiver, bool enabled) {
|
||||
case 3U:
|
||||
set_gpio_output(GPIOA, 0, !enabled);
|
||||
break;
|
||||
default:
|
||||
print("Invalid CAN transceiver ("); puth(transceiver); print("): enabling failed\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void white_enable_can_transceivers(bool enabled) {
|
||||
uint8_t t1 = enabled ? 1U : 2U; // leave transceiver 1 enabled to detect CAN ignition
|
||||
for(uint8_t i=t1; i<=3U; i++) {
|
||||
white_enable_can_transceiver(i, enabled);
|
||||
}
|
||||
}
|
||||
|
||||
static void white_set_led(uint8_t color, bool enabled) {
|
||||
switch (color){
|
||||
case LED_RED:
|
||||
set_gpio_output(GPIOC, 9, !enabled);
|
||||
break;
|
||||
case LED_GREEN:
|
||||
set_gpio_output(GPIOC, 7, !enabled);
|
||||
break;
|
||||
case LED_BLUE:
|
||||
set_gpio_output(GPIOC, 6, !enabled);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -128,6 +152,18 @@ static void white_grey_init(void) {
|
||||
set_gpio_alternate(GPIOC, 11, GPIO_AF7_USART3);
|
||||
set_gpio_pullup(GPIOC, 11, PULL_UP);
|
||||
|
||||
|
||||
// Enable CAN transceivers
|
||||
white_enable_can_transceivers(true);
|
||||
|
||||
// Disable LEDs
|
||||
white_set_led(LED_RED, false);
|
||||
white_set_led(LED_GREEN, false);
|
||||
white_set_led(LED_BLUE, false);
|
||||
|
||||
// Set normal CAN mode
|
||||
white_set_can_mode(CAN_MODE_NORMAL);
|
||||
|
||||
// Init usb power mode
|
||||
// Init in CDP mode only if panda is powered by 12V.
|
||||
// Otherwise a PC would not be able to flash a standalone panda
|
||||
@@ -155,6 +191,7 @@ static harness_configuration white_harness_config = {
|
||||
board board_white = {
|
||||
.set_bootkick = unused_set_bootkick,
|
||||
.harness_config = &white_harness_config,
|
||||
.has_obd = false,
|
||||
.has_spi = false,
|
||||
.has_canfd = false,
|
||||
.fan_max_rpm = 0U,
|
||||
@@ -165,8 +202,8 @@ board board_white = {
|
||||
.init = white_grey_init,
|
||||
.init_bootloader = white_grey_init_bootloader,
|
||||
.enable_can_transceiver = white_enable_can_transceiver,
|
||||
.led_GPIO = {GPIOC, GPIOC, GPIOC},
|
||||
.led_pin = {9, 7, 6},
|
||||
.enable_can_transceivers = white_enable_can_transceivers,
|
||||
.set_led = white_set_led,
|
||||
.set_can_mode = white_set_can_mode,
|
||||
.check_ignition = white_check_ignition,
|
||||
.read_voltage_mV = white_read_voltage_mV,
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
// ********************* Includes *********************
|
||||
#include "config.h"
|
||||
|
||||
#include "drivers/led.h"
|
||||
#include "drivers/pwm.h"
|
||||
#include "drivers/usb.h"
|
||||
|
||||
|
||||
@@ -178,7 +178,7 @@ void can_rx(uint8_t can_number) {
|
||||
safety_rx_invalid += safety_rx_hook(&to_push) ? 0U : 1U;
|
||||
ignition_can_hook(&to_push);
|
||||
|
||||
led_set(LED_BLUE, true);
|
||||
current_board->set_led(LED_BLUE, true);
|
||||
rx_buffer_overflow += can_push(&can_rx_q, &to_push) ? 0U : 1U;
|
||||
|
||||
// next
|
||||
|
||||
@@ -209,12 +209,6 @@ void ignition_can_hook(CANPacket_t *to_push) {
|
||||
ignition_can_cnt = 0U;
|
||||
}
|
||||
|
||||
// Volkswagen MEB exception
|
||||
if ((addr == 0x3C0) && (len == 4)) {
|
||||
ignition_can = GET_BIT(to_push, 17U);
|
||||
ignition_can_cnt = 0U;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -223,7 +223,7 @@ void can_rx(uint8_t can_number) {
|
||||
safety_rx_invalid += safety_rx_hook(&to_push) ? 0U : 1U;
|
||||
ignition_can_hook(&to_push);
|
||||
|
||||
led_set(LED_BLUE, true);
|
||||
current_board->set_led(LED_BLUE, true);
|
||||
rx_buffer_overflow += can_push(&can_rx_q, &to_push) ? 0U : 1U;
|
||||
|
||||
// Enable CAN FD and BRS if CAN FD message was received
|
||||
|
||||
@@ -94,12 +94,6 @@ void harness_tick(void) {
|
||||
}
|
||||
|
||||
void harness_init(void) {
|
||||
// init OBD_SBUx_RELAY
|
||||
set_gpio_output_type(current_board->harness_config->GPIO_relay_SBU1, current_board->harness_config->pin_relay_SBU1, OUTPUT_TYPE_OPEN_DRAIN);
|
||||
set_gpio_output_type(current_board->harness_config->GPIO_relay_SBU2, current_board->harness_config->pin_relay_SBU2, OUTPUT_TYPE_OPEN_DRAIN);
|
||||
set_gpio_output(current_board->harness_config->GPIO_relay_SBU1, current_board->harness_config->pin_relay_SBU1, 1);
|
||||
set_gpio_output(current_board->harness_config->GPIO_relay_SBU2, current_board->harness_config->pin_relay_SBU2, 1);
|
||||
|
||||
// try to detect orientation
|
||||
harness.status = harness_detect_orientation();
|
||||
if (harness.status != HARNESS_STATUS_NC) {
|
||||
|
||||
@@ -56,11 +56,10 @@ void early_initialization(void) {
|
||||
detect_board_type();
|
||||
|
||||
if (enter_bootloader_mode == ENTER_BOOTLOADER_MAGIC) {
|
||||
led_init();
|
||||
#ifdef PANDA
|
||||
current_board->init_bootloader();
|
||||
#endif
|
||||
led_set(LED_GREEN, 1);
|
||||
current_board->set_led(LED_GREEN, 1);
|
||||
jump_to_bootloader();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,5 +31,3 @@ uint32_t microsecond_timer_get(void);
|
||||
uint32_t microsecond_timer_get(void) {
|
||||
return MICROSECOND_TIMER->CNT;
|
||||
}
|
||||
|
||||
typedef uint32_t GPIO_TypeDef;
|
||||
|
||||
@@ -35,7 +35,7 @@ int comms_control_handler(ControlPacket_t *req, uint8_t *resp) {
|
||||
flash_unlock();
|
||||
resp[1] = 0xff;
|
||||
}
|
||||
led_set(LED_GREEN, 1);
|
||||
current_board->set_led(LED_GREEN, 1);
|
||||
unlocked = true;
|
||||
prog_ptr = (uint32_t *)APP_START_ADDRESS;
|
||||
break;
|
||||
@@ -112,14 +112,14 @@ int comms_can_read(uint8_t *data, uint32_t max_len) {
|
||||
void refresh_can_tx_slots_available(void) {}
|
||||
|
||||
void comms_endpoint2_write(const uint8_t *data, uint32_t len) {
|
||||
led_set(LED_RED, 0);
|
||||
current_board->set_led(LED_RED, 0);
|
||||
for (uint32_t i = 0; i < len/4; i++) {
|
||||
flash_write_word(prog_ptr, *(uint32_t*)(data+(i*4)));
|
||||
|
||||
//*(uint64_t*)(&spi_tx_buf[0x30+(i*4)]) = *prog_ptr;
|
||||
prog_ptr++;
|
||||
}
|
||||
led_set(LED_RED, 1);
|
||||
current_board->set_led(LED_RED, 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -132,7 +132,6 @@ void soft_flasher_start(void) {
|
||||
|
||||
gpio_usart2_init();
|
||||
gpio_usb_init();
|
||||
led_init();
|
||||
|
||||
// enable USB
|
||||
usb_init();
|
||||
@@ -144,15 +143,15 @@ void soft_flasher_start(void) {
|
||||
}
|
||||
|
||||
// green LED on for flashing
|
||||
led_set(LED_GREEN, 1);
|
||||
current_board->set_led(LED_GREEN, 1);
|
||||
|
||||
enable_interrupts();
|
||||
|
||||
for (;;) {
|
||||
// blink the green LED fast
|
||||
led_set(LED_GREEN, 0);
|
||||
current_board->set_led(LED_GREEN, 0);
|
||||
delay(500000);
|
||||
led_set(LED_GREEN, 1);
|
||||
current_board->set_led(LED_GREEN, 1);
|
||||
delay(500000);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// ******************** Prototypes ********************
|
||||
typedef void (*board_init)(void);
|
||||
typedef void (*board_set_led)(uint8_t color, bool enabled);
|
||||
typedef void (*board_board_tick)(void);
|
||||
typedef bool (*board_get_button)(void);
|
||||
typedef void (*board_set_panda_power)(bool enabled);
|
||||
@@ -14,12 +15,11 @@ typedef float (*board_get_channel_power)(uint8_t channel);
|
||||
typedef uint16_t (*board_get_sbu_mV)(uint8_t channel, uint8_t sbu);
|
||||
|
||||
struct board {
|
||||
GPIO_TypeDef * const led_GPIO[3];
|
||||
const uint8_t led_pin[3];
|
||||
const bool has_canfd;
|
||||
const bool has_sbu_sense;
|
||||
const uint16_t avdd_mV;
|
||||
board_init init;
|
||||
board_set_led set_led;
|
||||
board_board_tick board_tick;
|
||||
board_get_button get_button;
|
||||
board_set_panda_power set_panda_power;
|
||||
@@ -42,6 +42,11 @@ struct board {
|
||||
#define HW_TYPE_V1 1U
|
||||
#define HW_TYPE_V2 2U
|
||||
|
||||
// LED colors
|
||||
#define LED_RED 0U
|
||||
#define LED_GREEN 1U
|
||||
#define LED_BLUE 2U
|
||||
|
||||
// CAN modes
|
||||
#define CAN_MODE_NORMAL 0U
|
||||
#define CAN_MODE_OBD_CAN2 3U
|
||||
|
||||
@@ -2,6 +2,22 @@
|
||||
// Jungle board v1 (STM32F4) //
|
||||
// ///////////////////////// //
|
||||
|
||||
void board_v1_set_led(uint8_t color, bool enabled) {
|
||||
switch (color) {
|
||||
case LED_RED:
|
||||
set_gpio_output(GPIOC, 9, !enabled);
|
||||
break;
|
||||
case LED_GREEN:
|
||||
set_gpio_output(GPIOC, 7, !enabled);
|
||||
break;
|
||||
case LED_BLUE:
|
||||
set_gpio_output(GPIOC, 6, !enabled);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void board_v1_enable_can_transceiver(uint8_t transceiver, bool enabled) {
|
||||
switch (transceiver) {
|
||||
case 1U:
|
||||
@@ -124,6 +140,11 @@ void board_v1_init(void) {
|
||||
board_v1_enable_can_transceiver(i, true);
|
||||
}
|
||||
|
||||
// Disable LEDs
|
||||
board_v1_set_led(LED_RED, false);
|
||||
board_v1_set_led(LED_GREEN, false);
|
||||
board_v1_set_led(LED_BLUE, false);
|
||||
|
||||
// Set normal CAN mode
|
||||
board_v1_set_can_mode(CAN_MODE_NORMAL);
|
||||
|
||||
@@ -141,8 +162,7 @@ board board_v1 = {
|
||||
.has_sbu_sense = false,
|
||||
.avdd_mV = 3300U,
|
||||
.init = &board_v1_init,
|
||||
.led_GPIO = {GPIOC, GPIOC, GPIOC},
|
||||
.led_pin = {9, 7, 6},
|
||||
.set_led = &board_v1_set_led,
|
||||
.board_tick = &board_v1_tick,
|
||||
.get_button = &board_v1_get_button,
|
||||
.set_panda_power = &board_v1_set_panda_power,
|
||||
|
||||
@@ -65,6 +65,22 @@ adc_channel_t sbu2_channels[] = {
|
||||
{.adc = ADC3, .channel = 11},
|
||||
};
|
||||
|
||||
void board_v2_set_led(uint8_t color, bool enabled) {
|
||||
switch (color) {
|
||||
case LED_RED:
|
||||
set_gpio_output(GPIOE, 4, !enabled);
|
||||
break;
|
||||
case LED_GREEN:
|
||||
set_gpio_output(GPIOE, 3, !enabled);
|
||||
break;
|
||||
case LED_BLUE:
|
||||
set_gpio_output(GPIOE, 2, !enabled);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void board_v2_set_harness_orientation(uint8_t orientation) {
|
||||
switch (orientation) {
|
||||
case HARNESS_ORIENTATION_NONE:
|
||||
@@ -236,6 +252,11 @@ uint16_t board_v2_get_sbu_mV(uint8_t channel, uint8_t sbu) {
|
||||
void board_v2_init(void) {
|
||||
common_init_gpio();
|
||||
|
||||
// Disable LEDs
|
||||
board_v2_set_led(LED_RED, false);
|
||||
board_v2_set_led(LED_GREEN, false);
|
||||
board_v2_set_led(LED_BLUE, false);
|
||||
|
||||
// Normal CAN mode
|
||||
board_v2_set_can_mode(CAN_MODE_NORMAL);
|
||||
|
||||
@@ -291,8 +312,7 @@ board board_v2 = {
|
||||
.has_sbu_sense = true,
|
||||
.avdd_mV = 3300U,
|
||||
.init = &board_v2_init,
|
||||
.led_GPIO = {GPIOE, GPIOE, GPIOE},
|
||||
.led_pin = {4, 3, 2},
|
||||
.set_led = &board_v2_set_led,
|
||||
.board_tick = &board_v2_tick,
|
||||
.get_button = &board_v2_get_button,
|
||||
.set_panda_power = &board_v2_set_panda_power,
|
||||
|
||||
+10
-11
@@ -3,7 +3,6 @@
|
||||
|
||||
#include "safety.h"
|
||||
|
||||
#include "board/drivers/led.h"
|
||||
#include "board/drivers/pwm.h"
|
||||
#include "board/drivers/usb.h"
|
||||
|
||||
@@ -77,7 +76,7 @@ void tick_handler(void) {
|
||||
check_registers();
|
||||
|
||||
// turn off the blue LED, turned on by CAN
|
||||
led_set(LED_BLUE, false);
|
||||
current_board->set_led(LED_BLUE, false);
|
||||
|
||||
// Blink and OBD CAN
|
||||
#ifdef FINAL_PROVISIONING
|
||||
@@ -88,7 +87,7 @@ void tick_handler(void) {
|
||||
uptime_cnt += 1U;
|
||||
}
|
||||
|
||||
led_set(LED_GREEN, green_led_enabled);
|
||||
current_board->set_led(LED_GREEN, green_led_enabled);
|
||||
|
||||
// Check on button
|
||||
bool current_button_status = current_board->get_button();
|
||||
@@ -147,8 +146,8 @@ int main(void) {
|
||||
peripherals_init();
|
||||
detect_board_type();
|
||||
// red+green leds enabled until succesful USB init, as a debug indicator
|
||||
led_set(LED_RED, true);
|
||||
led_set(LED_GREEN, true);
|
||||
current_board->set_led(LED_RED, true);
|
||||
current_board->set_led(LED_GREEN, true);
|
||||
|
||||
// print hello
|
||||
print("\n\n\n************************ MAIN START ************************\n");
|
||||
@@ -177,8 +176,8 @@ int main(void) {
|
||||
// enable USB (right before interrupts or enum can fail!)
|
||||
usb_init();
|
||||
|
||||
led_set(LED_RED, false);
|
||||
led_set(LED_GREEN, false);
|
||||
current_board->set_led(LED_RED, false);
|
||||
current_board->set_led(LED_GREEN, false);
|
||||
|
||||
print("**** INTERRUPTS ON ****\n");
|
||||
enable_interrupts();
|
||||
@@ -224,16 +223,16 @@ int main(void) {
|
||||
|
||||
// useful for debugging, fade breaks = panda is overloaded
|
||||
for (uint32_t fade = 0U; fade < MAX_LED_FADE; fade += 1U) {
|
||||
led_set(LED_RED, true);
|
||||
current_board->set_led(LED_RED, true);
|
||||
delay(fade >> 4);
|
||||
led_set(LED_RED, false);
|
||||
current_board->set_led(LED_RED, false);
|
||||
delay((MAX_LED_FADE - fade) >> 4);
|
||||
}
|
||||
|
||||
for (uint32_t fade = MAX_LED_FADE; fade > 0U; fade -= 1U) {
|
||||
led_set(LED_RED, true);
|
||||
current_board->set_led(LED_RED, true);
|
||||
delay(fade >> 4);
|
||||
led_set(LED_RED, false);
|
||||
current_board->set_led(LED_RED, false);
|
||||
delay((MAX_LED_FADE - fade) >> 4);
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+17
-25
@@ -1,7 +1,6 @@
|
||||
// ********************* Includes *********************
|
||||
#include "config.h"
|
||||
|
||||
#include "drivers/led.h"
|
||||
#include "drivers/pwm.h"
|
||||
#include "drivers/usb.h"
|
||||
#include "drivers/simple_watchdog.h"
|
||||
@@ -77,14 +76,14 @@ void set_safety_mode(uint16_t mode, uint16_t param) {
|
||||
switch (mode_copy) {
|
||||
case SAFETY_SILENT:
|
||||
set_intercept_relay(false, false);
|
||||
if (current_board->harness_config->has_harness) {
|
||||
if (current_board->has_obd) {
|
||||
current_board->set_can_mode(CAN_MODE_NORMAL);
|
||||
}
|
||||
can_silent = ALL_CAN_SILENT;
|
||||
break;
|
||||
case SAFETY_NOOUTPUT:
|
||||
set_intercept_relay(false, false);
|
||||
if (current_board->harness_config->has_harness) {
|
||||
if (current_board->has_obd) {
|
||||
current_board->set_can_mode(CAN_MODE_NORMAL);
|
||||
}
|
||||
can_silent = ALL_CAN_LIVE;
|
||||
@@ -93,7 +92,7 @@ void set_safety_mode(uint16_t mode, uint16_t param) {
|
||||
set_intercept_relay(false, false);
|
||||
heartbeat_counter = 0U;
|
||||
heartbeat_lost = false;
|
||||
if (current_board->harness_config->has_harness) {
|
||||
if (current_board->has_obd) {
|
||||
// Clear any pending messages in the can core (i.e. sending while comma power is unplugged)
|
||||
// TODO: rewrite using hardware queues rather than fifo to cancel specific messages
|
||||
can_clear_send(CANIF_FROM_CAN_NUM(1), 1);
|
||||
@@ -109,7 +108,7 @@ void set_safety_mode(uint16_t mode, uint16_t param) {
|
||||
set_intercept_relay(true, false);
|
||||
heartbeat_counter = 0U;
|
||||
heartbeat_lost = false;
|
||||
if (current_board->harness_config->has_harness) {
|
||||
if (current_board->has_obd) {
|
||||
current_board->set_can_mode(CAN_MODE_NORMAL);
|
||||
}
|
||||
can_silent = ALL_CAN_LIVE;
|
||||
@@ -190,11 +189,11 @@ static void tick_handler(void) {
|
||||
#endif
|
||||
|
||||
// set green LED to be controls allowed
|
||||
led_set(LED_GREEN, controls_allowed | green_led_enabled);
|
||||
current_board->set_led(LED_GREEN, controls_allowed | green_led_enabled);
|
||||
|
||||
// turn off the blue LED, turned on by CAN
|
||||
// unless we are in power saving mode
|
||||
led_set(LED_BLUE, (uptime_cnt & 1U) && (power_save_status == POWER_SAVE_STATUS_ENABLED));
|
||||
current_board->set_led(LED_BLUE, (uptime_cnt & 1U) && (power_save_status == POWER_SAVE_STATUS_ENABLED));
|
||||
|
||||
const bool recent_heartbeat = heartbeat_counter == 0U;
|
||||
|
||||
@@ -304,10 +303,9 @@ int main(void) {
|
||||
clock_init();
|
||||
peripherals_init();
|
||||
detect_board_type();
|
||||
led_init();
|
||||
// red+green leds enabled until succesful USB/SPI init, as a debug indicator
|
||||
led_set(LED_RED, true);
|
||||
led_set(LED_GREEN, true);
|
||||
current_board->set_led(LED_RED, true);
|
||||
current_board->set_led(LED_GREEN, true);
|
||||
adc_init();
|
||||
|
||||
// print hello
|
||||
@@ -321,10 +319,6 @@ int main(void) {
|
||||
|
||||
// init board
|
||||
current_board->init();
|
||||
current_board->set_can_mode(CAN_MODE_NORMAL);
|
||||
if (current_board->harness_config->has_harness) {
|
||||
harness_init();
|
||||
}
|
||||
|
||||
// panda has an FPU, let's use it!
|
||||
enable_fpu();
|
||||
@@ -340,7 +334,7 @@ int main(void) {
|
||||
set_safety_mode(SAFETY_SILENT, 0U);
|
||||
|
||||
// enable CAN TXs
|
||||
enable_can_transceivers(true);
|
||||
current_board->enable_can_transceivers(true);
|
||||
|
||||
// init watchdog for heartbeat loop, fed at 8Hz
|
||||
simple_watchdog_init(FAULT_HEARTBEAT_LOOP_WATCHDOG, (3U * 1000000U / 8U));
|
||||
@@ -357,14 +351,12 @@ int main(void) {
|
||||
|
||||
#ifdef ENABLE_SPI
|
||||
if (current_board->has_spi) {
|
||||
gpio_spi_init();
|
||||
spi_init();
|
||||
}
|
||||
#endif
|
||||
|
||||
led_set(LED_RED, false);
|
||||
led_set(LED_GREEN, false);
|
||||
led_set(LED_BLUE, false);
|
||||
current_board->set_led(LED_RED, false);
|
||||
current_board->set_led(LED_GREEN, false);
|
||||
|
||||
print("**** INTERRUPTS ON ****\n");
|
||||
enable_interrupts();
|
||||
@@ -377,24 +369,24 @@ int main(void) {
|
||||
#endif
|
||||
// useful for debugging, fade breaks = panda is overloaded
|
||||
for (uint32_t fade = 0U; fade < MAX_LED_FADE; fade += 1U) {
|
||||
led_set(LED_RED, true);
|
||||
current_board->set_led(LED_RED, true);
|
||||
delay(fade >> 4);
|
||||
led_set(LED_RED, false);
|
||||
current_board->set_led(LED_RED, false);
|
||||
delay((MAX_LED_FADE - fade) >> 4);
|
||||
}
|
||||
|
||||
for (uint32_t fade = MAX_LED_FADE; fade > 0U; fade -= 1U) {
|
||||
led_set(LED_RED, true);
|
||||
current_board->set_led(LED_RED, true);
|
||||
delay(fade >> 4);
|
||||
led_set(LED_RED, false);
|
||||
current_board->set_led(LED_RED, false);
|
||||
delay((MAX_LED_FADE - fade) >> 4);
|
||||
}
|
||||
|
||||
#ifdef DEBUG_FAULTS
|
||||
} else {
|
||||
led_set(LED_RED, 1);
|
||||
current_board->set_led(LED_RED, 1);
|
||||
delay(512000U);
|
||||
led_set(LED_RED, 0);
|
||||
current_board->set_led(LED_RED, 0);
|
||||
delay(512000U);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -212,7 +212,7 @@ int comms_control_handler(ControlPacket_t *req, uint8_t *resp) {
|
||||
break;
|
||||
// **** 0xdb: set OBD CAN multiplexing mode
|
||||
case 0xdb:
|
||||
if (current_board->harness_config->has_harness) {
|
||||
if (current_board->has_obd) {
|
||||
if (req->param1 == 1U) {
|
||||
// Enable OBD CAN
|
||||
current_board->set_can_mode(CAN_MODE_OBD_CAN2);
|
||||
|
||||
@@ -5,15 +5,8 @@
|
||||
|
||||
int power_save_status = POWER_SAVE_STATUS_DISABLED;
|
||||
|
||||
void enable_can_transceivers(bool enabled) {
|
||||
// Leave main CAN always on for CAN-based ignition detection
|
||||
uint8_t main_bus = (current_board->harness_config->has_harness && (harness.status == HARNESS_STATUS_FLIPPED)) ? 3U : 1U;
|
||||
for(uint8_t i=1U; i<=4U; i++){
|
||||
current_board->enable_can_transceiver(i, (i == main_bus) || enabled);
|
||||
}
|
||||
}
|
||||
|
||||
void set_power_save_state(int state) {
|
||||
|
||||
bool is_valid_state = (state == POWER_SAVE_STATUS_ENABLED) || (state == POWER_SAVE_STATUS_DISABLED);
|
||||
if (is_valid_state && (state != power_save_status)) {
|
||||
bool enable = false;
|
||||
@@ -40,7 +33,7 @@ void set_power_save_state(int state) {
|
||||
enable = true;
|
||||
}
|
||||
|
||||
enable_can_transceivers(enable);
|
||||
current_board->enable_can_transceivers(enable);
|
||||
|
||||
// Switch off IR when in power saving
|
||||
if(!enable){
|
||||
|
||||
@@ -39,7 +39,4 @@ void detect_board_type(void) {
|
||||
hw_type = HW_TYPE_BLACK_PANDA;
|
||||
current_board = &board_black;
|
||||
}
|
||||
|
||||
// Return A13 to the alt mode to fix SWD
|
||||
set_gpio_alternate(GPIOA, 13, GPIO_AF0_SWJ);
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
void early_gpio_float(void) {
|
||||
RCC->AHB1ENR = RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIOBEN | RCC_AHB1ENR_GPIOCEN;
|
||||
|
||||
GPIOB->MODER = 0; GPIOC->MODER = 0;
|
||||
GPIOA->MODER = 0; GPIOB->MODER = 0; GPIOC->MODER = 0;
|
||||
GPIOA->ODR = 0; GPIOB->ODR = 0; GPIOC->ODR = 0;
|
||||
GPIOA->PUPDR = 0; GPIOB->PUPDR = 0; GPIOC->PUPDR = 0;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "stm32h7/sound.h"
|
||||
#include "drivers/clock_source.h"
|
||||
#include "boards/red.h"
|
||||
#include "boards/red_chiplet.h"
|
||||
#include "boards/tres.h"
|
||||
#include "boards/cuatro.h"
|
||||
|
||||
|
||||
@@ -31,6 +31,26 @@ void gpio_uart7_init(void) {
|
||||
|
||||
// Common GPIO initialization
|
||||
void common_init_gpio(void) {
|
||||
/// E2,E3,E4: RGB LED
|
||||
set_gpio_pullup(GPIOE, 2, PULL_NONE);
|
||||
set_gpio_mode(GPIOE, 2, MODE_OUTPUT);
|
||||
set_gpio_output_type(GPIOE, 2, OUTPUT_TYPE_OPEN_DRAIN);
|
||||
|
||||
set_gpio_pullup(GPIOE, 3, PULL_NONE);
|
||||
set_gpio_mode(GPIOE, 3, MODE_OUTPUT);
|
||||
set_gpio_output_type(GPIOE, 3, OUTPUT_TYPE_OPEN_DRAIN);
|
||||
|
||||
set_gpio_pullup(GPIOE, 4, PULL_NONE);
|
||||
set_gpio_mode(GPIOE, 4, MODE_OUTPUT);
|
||||
set_gpio_output_type(GPIOE, 4, OUTPUT_TYPE_OPEN_DRAIN);
|
||||
|
||||
//C4,A1: OBD_SBU1, OBD_SBU2
|
||||
set_gpio_pullup(GPIOC, 4, PULL_NONE);
|
||||
set_gpio_mode(GPIOC, 4, MODE_ANALOG);
|
||||
|
||||
set_gpio_pullup(GPIOA, 1, PULL_NONE);
|
||||
set_gpio_mode(GPIOA, 1, MODE_ANALOG);
|
||||
|
||||
//F11: VOLT_S
|
||||
set_gpio_pullup(GPIOF, 11, PULL_NONE);
|
||||
set_gpio_mode(GPIOF, 11, MODE_ANALOG);
|
||||
|
||||
Reference in New Issue
Block a user