Skip to content

Commit

Permalink
init bootloader
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruce Wayne committed Aug 5, 2023
1 parent 177eb1c commit fbf87e0
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 17 deletions.
9 changes: 8 additions & 1 deletion board/boards/black.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ void black_init(void) {
set_gpio_mode(GPIOC, 3, MODE_ANALOG);

// GPS OFF
set_gpio_output(GPIOC, 12, 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)
Expand Down Expand Up @@ -137,6 +137,12 @@ void black_init(void) {
}
}

void black_init_bootloader(void) {
// GPS OFF
set_gpio_output(GPIOC, 5, 0);
set_gpio_output(GPIOC, 12, 0);
}

const harness_configuration black_harness_config = {
.has_harness = true,
.GPIO_SBU1 = GPIOC,
Expand Down Expand Up @@ -166,6 +172,7 @@ const board board_black = {
.fan_stall_recovery = false,
.fan_enable_cooldown_time = 0U,
.init = black_init,
.init_bootloader = black_init_bootloader,
.enable_can_transceiver = black_enable_can_transceiver,
.enable_can_transceivers = black_enable_can_transceivers,
.set_led = black_set_led,
Expand Down
2 changes: 2 additions & 0 deletions board/boards/board_declarations.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// ******************** Prototypes ********************
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);
Expand Down Expand Up @@ -27,6 +28,7 @@ struct board {
const bool fan_stall_recovery;
const uint8_t fan_enable_cooldown_time;
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;
Expand Down
1 change: 1 addition & 0 deletions board/boards/dos.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ const board board_dos = {
.fan_stall_recovery = true,
.fan_enable_cooldown_time = 3U,
.init = dos_init,
.init_bootloader = unused_init_bootloader,
.enable_can_transceiver = dos_enable_can_transceiver,
.enable_can_transceivers = dos_enable_can_transceivers,
.set_led = dos_set_led,
Expand Down
11 changes: 2 additions & 9 deletions board/boards/grey.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@

// Most hardware functionality is similar to white panda

void grey_init(void) {
white_grey_common_init();

// GPS off
set_gpio_output(GPIOC, 14, 0);
set_gpio_output(GPIOC, 5, 0);
}

const board board_grey = {
.board_type = "Grey",
.board_tick = unused_board_tick,
Expand All @@ -26,7 +18,8 @@ const board board_grey = {
.avdd_mV = 3300U,
.fan_stall_recovery = false,
.fan_enable_cooldown_time = 0U,
.init = grey_init,
.init = white_grey_init,
.init_bootloader = white_grey_init_bootloader,
.enable_can_transceiver = white_enable_can_transceiver,
.enable_can_transceivers = white_enable_can_transceivers,
.set_led = white_set_led,
Expand Down
1 change: 1 addition & 0 deletions board/boards/pedal.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const board board_pedal = {
.fan_stall_recovery = false,
.fan_enable_cooldown_time = 0U,
.init = pedal_init,
.init_bootloader = unused_init_bootloader,
.enable_can_transceiver = pedal_enable_can_transceiver,
.enable_can_transceivers = pedal_enable_can_transceivers,
.set_led = pedal_set_led,
Expand Down
1 change: 1 addition & 0 deletions board/boards/red.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ const board board_red = {
.fan_stall_recovery = false,
.fan_enable_cooldown_time = 0U,
.init = red_init,
.init_bootloader = unused_init_bootloader,
.enable_can_transceiver = red_enable_can_transceiver,
.enable_can_transceivers = red_enable_can_transceivers,
.set_led = red_set_led,
Expand Down
1 change: 1 addition & 0 deletions board/boards/red_v2.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const board board_red_v2 = {
.fan_stall_recovery = false,
.fan_enable_cooldown_time = 0U,
.init = red_panda_v2_init,
.init_bootloader = unused_init_bootloader,
.enable_can_transceiver = red_chiplet_enable_can_transceiver,
.enable_can_transceivers = red_chiplet_enable_can_transceivers,
.set_led = red_set_led,
Expand Down
1 change: 1 addition & 0 deletions board/boards/tres.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ const board board_tres = {
.fan_stall_recovery = false,
.fan_enable_cooldown_time = 3U,
.init = tres_init,
.init_bootloader = unused_init_bootloader,
.enable_can_transceiver = red_chiplet_enable_can_transceiver,
.enable_can_transceivers = red_chiplet_enable_can_transceivers,
.set_led = red_set_led,
Expand Down
8 changes: 8 additions & 0 deletions board/boards/uno.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ void uno_init(void) {
uno_bootkick();
}

void uno_init_bootloader(void) {
// GPS off
set_gpio_output(GPIOB, 1, 0);
set_gpio_output(GPIOC, 5, 0);
set_gpio_output(GPIOC, 12, 0);
}

const harness_configuration uno_harness_config = {
.has_harness = true,
.GPIO_SBU1 = GPIOC,
Expand Down Expand Up @@ -226,6 +233,7 @@ const board board_uno = {
.fan_stall_recovery = false,
.fan_enable_cooldown_time = 0U,
.init = uno_init,
.init_bootloader = uno_init_bootloader,
.enable_can_transceiver = uno_enable_can_transceiver,
.enable_can_transceivers = uno_enable_can_transceivers,
.set_led = uno_set_led,
Expand Down
3 changes: 3 additions & 0 deletions board/boards/unused_funcs.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
void unused_init_bootloader(void) {
}

void unused_set_ir_power(uint8_t percentage) {
UNUSED(percentage);
}
Expand Down
17 changes: 10 additions & 7 deletions board/boards/white.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ bool white_check_ignition(void){
return !get_gpio_input(GPIOA, 1);
}

void white_grey_common_init(void) {
void white_grey_init(void) {
common_init_gpio();

// C3: current sense
Expand Down Expand Up @@ -205,14 +205,16 @@ void white_grey_common_init(void) {
} else {
white_set_usb_power_mode(USB_POWER_CLIENT);
}
}

void white_init(void) {
white_grey_common_init();

// ESP OFF
// ESP/GPS off
set_gpio_output(GPIOC, 5, 0);
set_gpio_output(GPIOC, 14, 0);
}

void white_grey_init_bootloader(void) {
// ESP/GPS off
set_gpio_output(GPIOC, 5, 0);
set_gpio_output(GPIOC, 14, 0);
}

const harness_configuration white_harness_config = {
Expand All @@ -233,7 +235,8 @@ const board board_white = {
.avdd_mV = 3300U,
.fan_stall_recovery = false,
.fan_enable_cooldown_time = 0U,
.init = white_init,
.init = white_grey_init,
.init_bootloader = white_grey_init_bootloader,
.enable_can_transceiver = white_enable_can_transceiver,
.enable_can_transceivers = white_enable_can_transceivers,
.set_led = white_set_led,
Expand Down
3 changes: 3 additions & 0 deletions board/early_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ void early_initialization(void) {
detect_board_type();

if (enter_bootloader_mode == ENTER_BOOTLOADER_MAGIC) {
#ifdef PANDA
current_board->init_bootloader();
#endif
current_board->set_led(LED_GREEN, 1);
jump_to_bootloader();
}
Expand Down

0 comments on commit fbf87e0

Please sign in to comment.