1
0
mirror of https://github.com/sjlongland/cluster-powerctl.git synced 2025-09-13 12:03:14 +10:00

powerctl: Wait until t_cwarn expiry before clearing timer.

This commit is contained in:
Stuart Longland 2017-03-19 12:24:13 +10:00
parent 403bd5d58f
commit c2e6915996
Signed by: stuartl
GPG Key ID: F954BBBB7948D546

View File

@ -160,6 +160,31 @@ static inline void uart_tx_bool(const char* msg, uint8_t val) {
} }
#endif #endif
/*!
* Enter charger warning state. This indicates that the battery
* *should* be charging, but isn't due to insufficient input current from
* the charger.
*/
static inline void enter_warning() {
if (charger_warning)
LED_PORT |= LED_WARNING;
else
charger_warning = 1;
/* Reset our timer */
t_cwarn = T_CWARN_S;
}
/*!
* Leave the charger warning state. This indicates the charger has left
* the charging state or the battery has begun charging.
*/
static inline void exit_warning() {
charger_warning = 0;
t_cwarn = 0;
LED_PORT &= ~LED_WARNING;
}
/*! /*!
* Switch between chargers. This is does a "break-before-make" switchover * Switch between chargers. This is does a "break-before-make" switchover
* of charging sources to switch from mains to solar, solar to mains, or to * of charging sources to switch from mains to solar, solar to mains, or to
@ -168,7 +193,7 @@ static inline void uart_tx_bool(const char* msg, uint8_t val) {
* *
* Added is the ability to just alternate between sources. * Added is the ability to just alternate between sources.
*/ */
void select_src(uint8_t src) { static void select_src(uint8_t src) {
if (src == SRC_ALT) { if (src == SRC_ALT) {
if (charge_source == SRC_SOLAR) if (charge_source == SRC_SOLAR)
src = SRC_MAINS; src = SRC_MAINS;
@ -275,8 +300,7 @@ static void charge_check() {
/* Not yet charging, switch to primary source */ /* Not yet charging, switch to primary source */
select_src(SRC_SOLAR); select_src(SRC_SOLAR);
/* As we have just started charging, reset warning timer */ /* As we have just started charging, reset warning timer */
charger_warning = 0; exit_warning();
t_cwarn = T_CWARN_S;
} else if (v_bn_adc <= v_bl_adc) { } else if (v_bn_adc <= v_bl_adc) {
/* Check for high voltage threshold, are we there yet? */ /* Check for high voltage threshold, are we there yet? */
#ifdef DEBUG #ifdef DEBUG
@ -285,23 +309,22 @@ static void charge_check() {
if (v_bn_adc >= V_H_ADC) { if (v_bn_adc >= V_H_ADC) {
/* We are done now */ /* We are done now */
select_src(SRC_NONE); select_src(SRC_NONE);
charger_state = STATE_DIS_CHECK; exit_warning();
charger_warning = 0;
return; return;
} else if (charger_warning && (!t_cwarn)) {
/* Situation still not improving, switch sources */
select_src(SRC_ALT);
/* Reset our warning timer */
t_cwarn = T_CWARN_S;
} else if (!t_cwarn) { } else if (!t_cwarn) {
/* Not in warning state, enter warning */ if (charger_warning) {
charger_warning = 1; /*
t_cwarn = T_CWARN_S; * Situation still not improving,
* switch sources.
*/
select_src(SRC_ALT);
}
/* Reset our warning timer */
enter_warning();
} }
} else { } else if (!t_cwarn) {
/* Things are improving, reset warning if set. */ /* Things are improving, reset warning if set. */
charger_warning = 0; exit_warning();
t_cwarn = 0;
} }
v_bl_adc = v_bn_adc; v_bl_adc = v_bn_adc;
@ -317,10 +340,14 @@ static void charge_wait() {
/* Expire timer */ /* Expire timer */
t_charger = 0; t_charger = 0;
if (v_bn_adc > v_bl_adc) { if (!t_cwarn) {
/* Things are improving, so kill the warning */ if (v_bn_adc > v_bl_adc) {
charger_warning = 0; /* Things are improving, so kill the warning */
t_cwarn = 0; exit_warning();
} else {
/* Not improving, and timer is expired */
enter_warning();
}
} }
#ifdef DEBUG #ifdef DEBUG
@ -413,12 +440,6 @@ int main(void) {
LED_PORT &= ~LED_BATT_GOOD; LED_PORT &= ~LED_BATT_GOOD;
} }
if (charger_warning) {
LED_PORT |= LED_WARNING;
} else {
LED_PORT &= ~LED_WARNING;
}
if (temp_adc < TEMP_MIN) { if (temp_adc < TEMP_MIN) {
LED_PORT |= LED_TEMP_LOW; LED_PORT |= LED_TEMP_LOW;
LED_PORT &= ~LED_TEMP_HIGH; LED_PORT &= ~LED_TEMP_HIGH;