[FL-2399, FL-2261] Tickless sleep shenanigans (#1168)
* Disable USART in sleep * Restore UART state on suspend/resume * FuriHal: Enable stop mode and add insomnia to I2C and SPI * Remove IDLE interrupt * FuriHal: add FPU isr and disable all FPU interrupt, add core2 stop mode configuration on deep sleep * FuriHal: tie stop mode debug with debug rtc flag * FuriHal: adjust flash latency on clock switch, tie mcu debug with RTC debug flag * FuriHal: move resource init to early stage * Add EXTI pending check, enable debug traps with compile-time flag * Wrap sleep debug functions in conditional compilation * Remove erroneous changed * Do not use CSS, remove it from everywhere * Enable/disable USB on VBUS connect (prototype) * FuriHal: add LPMS and DEEPSLEEP magic, workaround state inconsistency between cores * FuriHal: honor c1 LMPS * USB mode switch fix * Applications: add flags and insomnia bypass system * Correct spelling * FuriHal: cleanup insomnia usage, reset sleep flags on wakeup, add shutdown api * FuriHal: extra check on reinit request * FuriHal: rename gpio_display_rst pin to gpio_display_rst_n * FuriHal: add debug HAL * FuriHal: add some magic to core2 reload procedure, fix issue with crash on ble keyboard exit * FuriHal: cleanup ble glue, add BLE_GLUE_DEBUG flag * FuriHal: ble reinit API, move os timer to LPTIM1 for deep sleep capability, shutdown that works * FuriHal: take insomnia while shutdown * Remove USB switch on/off on VBUS change * Better tick skew handling * Improve tick consistency under load * Add USB_HP dummy IRQ handler * Move interrupt check closer to sleep * Clean up includes * Re-enable Insomnia globally * FuriHal: enable CSS * FuriHal: remove questionable core2 clock shenanigans * FuriHal: use core1 RCC registers in idle timer config * FuriHal: return back CSS handlers, add lptim isr dispatching Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com> Co-authored-by: nminaylov <nm29719@gmail.com>
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
#include <furi.h>
|
||||
#include <furi_hal_delay.h>
|
||||
|
||||
static bool furi_hal_usart_prev_enabled[2];
|
||||
|
||||
static void (*irq_cb[2])(uint8_t ev, uint8_t data, void* context);
|
||||
static void* irq_ctx[2];
|
||||
|
||||
@@ -44,7 +46,6 @@ static void furi_hal_usart_init(uint32_t baud) {
|
||||
;
|
||||
|
||||
LL_USART_EnableIT_RXNE_RXFNE(USART1);
|
||||
LL_USART_EnableIT_IDLE(USART1);
|
||||
NVIC_SetPriority(USART1_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 5, 0));
|
||||
}
|
||||
|
||||
@@ -81,7 +82,6 @@ static void furi_hal_lpuart_init(uint32_t baud) {
|
||||
furi_hal_uart_set_br(FuriHalUartIdLPUART1, baud);
|
||||
|
||||
LL_LPUART_EnableIT_RXNE_RXFNE(LPUART1);
|
||||
LL_LPUART_EnableIT_IDLE(LPUART1);
|
||||
NVIC_SetPriority(LPUART1_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 5, 0));
|
||||
}
|
||||
|
||||
@@ -136,6 +136,28 @@ void furi_hal_uart_deinit(FuriHalUartId ch) {
|
||||
}
|
||||
}
|
||||
|
||||
void furi_hal_uart_suspend(FuriHalUartId channel) {
|
||||
if(channel == FuriHalUartIdLPUART1 && LL_LPUART_IsEnabled(LPUART1)) {
|
||||
LL_LPUART_Disable(LPUART1);
|
||||
furi_hal_usart_prev_enabled[channel] = true;
|
||||
} else if(channel == FuriHalUartIdUSART1 && LL_USART_IsEnabled(USART1)) {
|
||||
LL_USART_Disable(USART1);
|
||||
furi_hal_usart_prev_enabled[channel] = true;
|
||||
}
|
||||
}
|
||||
|
||||
void furi_hal_uart_resume(FuriHalUartId channel) {
|
||||
if(!furi_hal_usart_prev_enabled[channel]) {
|
||||
return;
|
||||
} else if(channel == FuriHalUartIdLPUART1) {
|
||||
LL_LPUART_Enable(LPUART1);
|
||||
} else if(channel == FuriHalUartIdUSART1) {
|
||||
LL_USART_Enable(USART1);
|
||||
}
|
||||
|
||||
furi_hal_usart_prev_enabled[channel] = false;
|
||||
}
|
||||
|
||||
void furi_hal_uart_tx(FuriHalUartId ch, uint8_t* buffer, size_t buffer_size) {
|
||||
if(ch == FuriHalUartIdUSART1) {
|
||||
if(LL_USART_IsEnabled(USART1) == 0) return;
|
||||
@@ -189,22 +211,15 @@ void LPUART1_IRQHandler(void) {
|
||||
if(LL_LPUART_IsActiveFlag_RXNE_RXFNE(LPUART1)) {
|
||||
uint8_t data = LL_LPUART_ReceiveData8(LPUART1);
|
||||
irq_cb[FuriHalUartIdLPUART1](UartIrqEventRXNE, data, irq_ctx[FuriHalUartIdLPUART1]);
|
||||
} else if(LL_LPUART_IsActiveFlag_IDLE(LPUART1)) {
|
||||
irq_cb[FuriHalUartIdLPUART1](UartIrqEventIDLE, 0, irq_ctx[FuriHalUartIdLPUART1]);
|
||||
LL_LPUART_ClearFlag_IDLE(LPUART1);
|
||||
} else if(LL_LPUART_IsActiveFlag_ORE(LPUART1)) {
|
||||
LL_LPUART_ClearFlag_ORE(LPUART1);
|
||||
}
|
||||
//TODO: more events
|
||||
}
|
||||
|
||||
void USART1_IRQHandler(void) {
|
||||
if(LL_USART_IsActiveFlag_RXNE_RXFNE(USART1)) {
|
||||
uint8_t data = LL_USART_ReceiveData8(USART1);
|
||||
irq_cb[FuriHalUartIdUSART1](UartIrqEventRXNE, data, irq_ctx[FuriHalUartIdUSART1]);
|
||||
} else if(LL_USART_IsActiveFlag_IDLE(USART1)) {
|
||||
irq_cb[FuriHalUartIdUSART1](UartIrqEventIDLE, 0, irq_ctx[FuriHalUartIdUSART1]);
|
||||
LL_USART_ClearFlag_IDLE(USART1);
|
||||
} else if(LL_USART_IsActiveFlag_ORE(USART1)) {
|
||||
LL_USART_ClearFlag_ORE(USART1);
|
||||
}
|
||||
|
Reference in New Issue
Block a user