Browse Source

platform/asterix: turn off the WDT / boot timer in the PMIC

Some versions of the OS could leave it on, and this causes us to
repeatedly reboot.  Make sure it's off.

Signed-off-by: Joshua Wise <joshua@accelerated.tech>
Joshua Wise 3 months ago
parent
commit
2854242f95
1 changed files with 21 additions and 0 deletions
  1. 21 0
      platform/asterix/boot/src/drivers/pmic.c

+ 21 - 0
platform/asterix/boot/src/drivers/pmic.c

@@ -4,7 +4,9 @@
 
 #define CHARGER_BASE 0x03U
 #define ADC_BASE 0x05U
+#define TIMER_BASE 0x07U
 #define LDSW_BASE 0x08U
+#define ERRLOG_BASE 0x0EU
 
 // CHARGER
 #define BCHGENABLESET 0x04U
@@ -27,6 +29,10 @@
 #define ADCNTCRSEL 0x0AU
 #define ADCNTCRSEL_10K 0x1U
 
+// TIMER
+#define TIMERCLR 0x01U
+#define TIMERCLR_TASKTIMERDIS 0x01U
+
 // LDO
 #define TASKLDSW2SET 0x02U
 
@@ -36,6 +42,10 @@
 #define LDSW2VOUTSEL 0x0DU
 #define LDSW2VOUTSEL_1V8 0x08U
 
+// ERRLOG
+#define SCRATCH0 0x1U
+#define SCRATCH0_BOOTTIMEREN 0x01U
+
 static const nrfx_twi_t twi = NRFX_TWI_INSTANCE(BOARD_PMIC_I2C);
 static const nrfx_twi_config_t config =
     NRFX_TWI_DEFAULT_CONFIG(BOARD_PMIC_I2C_SCL_PIN, BOARD_PMIC_I2C_SDA_PIN);
@@ -67,6 +77,17 @@ int pmic_init(void) {
   }
 
   nrfx_twi_enable(&twi);
+  
+  // Turn off any watchdog / boot timer right away.
+  ret = prv_pmic_write(TIMER_BASE, TIMERCLR, TIMERCLR_TASKTIMERDIS);
+  if (ret != 0) {
+    return ret;
+  }
+
+  ret = prv_pmic_write(ERRLOG_BASE, SCRATCH0, 0x00);
+  if (ret != 0) {
+    return ret;
+  }
 
   // Configure charger (TODO: values are board/battery dependent)
   // - Thermistor: 10K NTC