1212
1313#include "../drv/gpio/gpio_ev3.h"
1414
15+ #include <tiam1808/hw/soc_AM1808.h>
1516#include <tiam1808/hw/hw_syscfg0_AM1808.h>
17+ #include <tiam1808/hw/hw_types.h>
18+ #include <tiam1808/timer.h>
19+
20+ #define BOOTLOADER_UPDATE_MODE_VALUE 0x5555AAAA
21+
22+ typedef struct {
23+ // 0xffff1ff0
24+ uint32_t _dummy0 ;
25+ // 0xffff1ff4
26+ // Pybricks uses this flag to determine software reset vs other resets
27+ uint32_t reset_reason_flag ;
28+ // 0xffff1ff8
29+ // Have not fully investigated this, but the bootloader seems to store
30+ // the result of (DDR) memory testing at 0xffff1ffa and 0xffff1ffb
31+ uint32_t _bootloader_unk_ram_test ;
32+ // 0xffff1ffc
33+ uint32_t bootloader_update_flag ;
34+ } persistent_data_t ;
35+ // This is defined as an extern variable so that its address can be specified
36+ // in the platform.ld linker script. This means that the linker script
37+ // contains information about *all* fixed memory locations.
38+ //
39+ // This lives at the very end of the ARM local RAM.
40+ extern volatile persistent_data_t ev3_persistent_data ;
1641
1742static const pbdrv_gpio_t poweroff_pin = PBDRV_GPIO_EV3_PIN (13 , 19 , 16 , 6 , 11 );
1843
@@ -23,11 +48,17 @@ void pbdrv_reset_init(void) {
2348void pbdrv_reset (pbdrv_reset_action_t action ) {
2449 for (;;) {
2550 switch (action ) {
26- case PBDRV_RESET_ACTION_RESET_IN_UPDATE_MODE :
27- // TODO
51+ case PBDRV_RESET_ACTION_POWER_OFF :
52+ pbdrv_reset_power_off ();
2853 break ;
29- // TODO: implement case PBDRV_RESET_ACTION_RESET
54+ case PBDRV_RESET_ACTION_RESET_IN_UPDATE_MODE :
55+ ev3_persistent_data .bootloader_update_flag = BOOTLOADER_UPDATE_MODE_VALUE ;
56+ __attribute__((fallthrough ));
3057 default :
58+ // PBDRV_RESET_ACTION_RESET
59+
60+ // Poke the watchdog timer with a bad value to immediately trigger it
61+ HWREG (SOC_TMR_1_REGS + TMR_WDTCR ) = 0 ;
3162 break ;
3263 }
3364 }
0 commit comments