commit 932aaf28ef709f7cdc797d498eefee2da47a25f9
parent 0ef65dbcb58a87cbffeb06a72aca4dcab4faed45
Author: Lukas F. Hartmann <lukas@mntre.com>
Date: Mon, 30 Oct 2023 17:52:15 +0100
lpc-fw: disable brownout reset during sleep; clean up status prints
Diffstat:
1 file changed, 22 insertions(+), 12 deletions(-)
diff --git a/reform2-lpc-fw/src/boards/reform2/board_reform2.c b/reform2-lpc-fw/src/boards/reform2/board_reform2.c
@@ -39,7 +39,7 @@
// don't forget to set this to the correct rev for your motherboard!
// if you have a motherboard made in 2023 (2.5 R-2):
-#define REFORM_MOTHERBOARD_REV REFORM_MBREV_25_R2
+//#define REFORM_MOTHERBOARD_REV REFORM_MBREV_25_R2
// if you have a motherboard made before 2023 (2.0 R-3):
//#define REFORM_MOTHERBOARD_REV REFORM_MBREV_20_R3
@@ -526,12 +526,17 @@ void turn_aux_power_off(void) {
//LPC_GPIO->CLR[0] = (1 << 7); // AUX 3v3 off (R1+)
}
-void brownout_setup(void) {
+void brownout_enable(void) {
// Set brownout threshold to 1.46-1.63V (lowest level)
// and enable brownout reset (BODRSTENA)
LPC_SYSCON->BODCTRL = 0x0 | (1<<4);
}
+void brownout_disable(void) {
+ // disable brownout reset (BODRSTENA)
+ LPC_SYSCON->BODCTRL = 0x0;
+}
+
void watchdog_feed(void) {
__disable_irq();
LPC_WWDT->FEED = 0xAA;
@@ -544,7 +549,7 @@ void watchdog_feed(void) {
void boardInit(void)
{
- brownout_setup();
+ brownout_enable();
SystemCoreClockUpdate();
GPIOInit();
@@ -748,26 +753,27 @@ void handle_commands() {
uartSend((uint8_t*)uartBuffer, strlen(uartBuffer));
}
else if (remote_cmd == 's') {
- int acc_mah = (int)(capacity_accu_ampsecs/3.6);
int min_mah = (int)(capacity_min_ampsecs/3.6);
+ int acc_mah = (int)(capacity_accu_ampsecs/3.6);
+ int max_mah = (int)(capacity_max_ampsecs/3.6);
// get charger system state
if (state == ST_CHARGE) {
- sprintf(uartBuffer,"norm(%d) min:%d mAh:%d up:%d rev:"FW_REV"\r",cycles_in_state,min_mah,acc_mah,cycles_uptime);
+ sprintf(uartBuffer,"norm:%d mAh:%d:%d:%d up:%d "FW_REV"\r",cycles_in_state,min_mah,acc_mah,max_mah,cycles_uptime);
} else if (state == ST_OVERVOLTED) {
- sprintf(uartBuffer,"baln(%d) min:%d mAh:%d up:%d rev:"FW_REV"\r",cycles_in_state,min_mah,acc_mah,cycles_uptime);
+ sprintf(uartBuffer,"baln:%d mAh:%d:%d:%d up:%d "FW_REV"\r",cycles_in_state,min_mah,acc_mah,max_mah,cycles_uptime);
} else if (state == ST_COOLDOWN) {
- sprintf(uartBuffer,"cool(%d) min:%d mAh:%d up:%d rev:"FW_REV"\r",cycles_in_state,min_mah,acc_mah,cycles_uptime);
+ sprintf(uartBuffer,"cool:%d mAh:%d:%d:%d up:%d "FW_REV"\r",cycles_in_state,min_mah,acc_mah,max_mah,cycles_uptime);
} else if (state == ST_UNDERVOLTED) {
- sprintf(uartBuffer,"uvol(%d) min:%d mAh:%d up:%d rev:"FW_REV"\r",cycles_in_state,min_mah,acc_mah,cycles_uptime);
+ sprintf(uartBuffer,"uvol:%d mAh:%d:%d:%d up:%d "FW_REV"\r",cycles_in_state,min_mah,acc_mah,max_mah,cycles_uptime);
} else if (state == ST_MISSING) {
- sprintf(uartBuffer,"miss:%d(%d) min:%d mAh:%d up:%d rev:"FW_REV"\r",missing_reason,cycles_in_state,min_mah,acc_mah,cycles_uptime);
+ sprintf(uartBuffer,"miss:%d:%d mAh:%d:%d:%d up:%d "FW_REV"\r",missing_reason,cycles_in_state,min_mah,acc_mah,max_mah,cycles_uptime);
} else if (state == ST_FULLY_CHARGED) {
- sprintf(uartBuffer,"full(%d) min:%d mAh:%d up:%d rev:"FW_REV"\r",cycles_in_state,min_mah,acc_mah,cycles_uptime);
+ sprintf(uartBuffer,"full:%d mAh:%d:%d:%d up:%d "FW_REV"\r",cycles_in_state,min_mah,acc_mah,max_mah,cycles_uptime);
} else if (state == ST_POWERSAVE) {
- sprintf(uartBuffer,"psav(%d) min:%d mAh:%d up:%d rev:"FW_REV"\r",cycles_in_state,min_mah,acc_mah,cycles_uptime);
+ sprintf(uartBuffer,"psav:%d mAh:%d:%d:%d up:%d "FW_REV"\r",cycles_in_state,min_mah,acc_mah,max_mah,cycles_uptime);
} else {
- sprintf(uartBuffer,"unkn:%d(%d) min:%d mAh:%d up:%d rev:"FW_REV"\r",state,cycles_in_state,min_mah,acc_mah,cycles_uptime);
+ sprintf(uartBuffer,"unkn:%d:%d mAh:%d:%d:%d up:%d "FW_REV"\r",state,cycles_in_state,min_mah,acc_mah,max_mah,cycles_uptime);
}
uartSend((uint8_t*)uartBuffer, strlen(uartBuffer));
@@ -1089,6 +1095,8 @@ void WDT_IRQHandler(void) {
// WARNING: take care not to overflow TC (11786 * secs)
void deep_sleep_seconds(int secs) {
+ // brownout reset seems to interfere with deep sleep
+ brownout_disable();
// make WWDTINT wake the LPC up from sleep
// STARTERP1 WWDTINT bit 12
@@ -1140,6 +1148,8 @@ void deep_sleep_seconds(int secs) {
NVIC_DisableIRQ(WDT_IRQn);
LPC_WWDT->MOD = 0;
+
+ brownout_enable();
}
int main(void) {