static int timerBattery(TimerHandle timer, void *context) { // Initiate battery charging control BAT_CHARGE_OUT |= BAT_CHARGE_OPEN_DRAIN_BITS; BATTERY_CHARGE_ENABLE(); // Fire off another timer, to wait a while Timer_Create(timerChargingControl, NULL, 50, 0); return 0; }
/*! Read battery state and update charge output * \note Status can be used to update the LCD screen of a possible change * in battery charging state */ static void ChargingControl(void) { /* prepare to read status bits */ BAT_CHARGE_OUT |= BAT_CHARGE_STATUS_OPEN_DRAIN_BITS; /* always enable the charger (it may already be enabled) * status bits are not valid unless charger is enabled */ BATTERY_CHARGE_ENABLE(); /* wait until signals are valid - measured 400 us * during this delay we will also run the software FLL */ TaskDelayLpmDisable(); /* disable BT flow during FLL loop */ portENTER_CRITICAL(); unsigned char FlowDisabled = QueryFlowDisabled(); if (!FlowDisabled) DisableFlow(); portEXIT_CRITICAL(); EnableSoftwareFll(); vTaskDelay(1); DisableSoftwareFll(); portENTER_CRITICAL(); if (!FlowDisabled) EnableFlow(); portEXIT_CRITICAL(); TaskDelayLpmEnable(); /* Decode the battery state */ /* mask and shift to get the current battery charge status */ ChargeStatus = BAT_CHARGE_IN & (BAT_CHARGE_STAT1 | BAT_CHARGE_STAT2); switch (ChargeStatus) { case CHARGE_STATUS_PRECHARGE: PrintString("."); break; case CHARGE_STATUS_FAST_CHARGE: PrintString(":"); break; case CHARGE_STATUS_DONE: PrintString("|"); break; case CHARGE_STATUS_OFF: PrintString("ChargeOff"); break; default: PrintString("Charge???"); break; } }