We have developed a project for the customer. In order to obtain longer battery life, we need to save power consumption, so we turn on CONFIG_DEVICE_POWER_MANAGEMENT. In order not to affect other places that need Uart, we will wake up Uart regularly according to TAU time. But after 14 hours (our local TAU time is 30 minutes), the system crashes. Why?
Here are the sleep and wake operations I performed on the UART. Is there anything wrong with that?
void uart_sleep_out(void)
{
#ifdef CONFIG_DEVICE_POWER_MANAGEMENT
if(k_timer_remaining_get(&uart_sleep_in_timer) > 0)
k_timer_stop(&uart_sleep_in_timer);
k_timer_start(&uart_sleep_in_timer, K_SECONDS(UART_WAKE_HOLD_TIME_SEC), NULL);
if(uart_is_waked)
return;
device_set_power_state(uart_ble, DEVICE_PM_ACTIVE_STATE, NULL, NULL);
uart_irq_rx_enable(uart_ble);
uart_irq_tx_enable(uart_ble);
k_sleep(K_MSEC(10));
uart_is_waked = true;
#ifdef UART_DEBUG
LOGD("uart set active success!");
#endif
#endif
}
void uart_sleep_in(void)
{
#ifdef CONFIG_DEVICE_POWER_MANAGEMENT
if(!uart_is_waked)
return;
uart_irq_rx_disable(uart_ble);
uart_irq_tx_disable(uart_ble);
device_set_power_state(uart_ble, DEVICE_PM_LOW_POWER_STATE, NULL, NULL);
k_sleep(K_MSEC(10));
uart_is_waked = false;
#ifdef UART_DEBUG
LOGD("uart set low power success!");
#endif
#endif
}