Fixed RTOS sleep.

Signed-off-by: Yilin Sun <imi415@imi.moe>
This commit is contained in:
Yilin Sun 2023-11-03 23:33:17 +08:00
parent 31447e4249
commit 0582c84036
Signed by: imi415
GPG Key ID: 17F01E106F9F5E0A
5 changed files with 24 additions and 5 deletions

View File

@ -59,6 +59,7 @@ set(TARGET_SOURCES
"src/app_ble_profiles/app_ble_bass.c"
"src/app_ble_profiles/app_ble_diss.c"
"src/app_freertos_support.c"
"src/app_lowpower.c"
"src/main.c"
)

View File

View File

@ -81,7 +81,10 @@ static void app_ble_task(void *parameters) {
uint32_t notification_value;
for (;;) {
rwip_schedule();
if (app_ble_lock(portMAX_DELAY) >= 0) {
rwip_schedule();
app_ble_unlock();
}
xTaskNotifyWait(0, 0, &notification_value, portMAX_DELAY);
}
}

View File

@ -15,6 +15,7 @@
#define MAX_SLEEP_DURATION_EXTERNAL_WAKEUP 0x7D00
extern uint32_t ns_sleep_lock;
extern volatile uint16_t *p_prevent_sleep;
extern void entry_sleep(void);
@ -23,6 +24,10 @@ static uint8_t app_check_stack_status(uint32_t msec);
void vPortSuppressTicksAndSleep(TickType_t xExpectedIdleTime) {
rwip_time_t sleep_start, sleep_end;
if (ns_sleep_lock == 1) {
return;
}
/* Stop SysTick timer */
SysTick->CTRL &= ~(SysTick_CTRL_ENABLE_Msk | SysTick_CTRL_TICKINT_Msk);
@ -45,7 +50,7 @@ void vPortSuppressTicksAndSleep(TickType_t xExpectedIdleTime) {
app_sleep_resume_proc();
/* Check whether BLE stack wake up completed */
while ((rwip_env.prevent_sleep & (RW_WAKE_UP_ONGOING | RW_DEEP_SLEEP))) {
while ((*p_prevent_sleep & (RW_WAKE_UP_ONGOING | RW_DEEP_SLEEP))) {
/* -- */
}
@ -66,7 +71,7 @@ void vPortSuppressTicksAndSleep(TickType_t xExpectedIdleTime) {
/* Elapsed time in half-slots */
int32_t elapsed_hs = CLK_DIFF(sleep_start.hs, sleep_end.hs);
if (elapsed_hs <= 0) {
if (elapsed_hs < 0) {
elapsed_ms = xExpectedIdleTime;
goto step_tick_exit;
}
@ -119,7 +124,7 @@ static uint8_t app_check_stack_status(uint32_t msec) {
************************************************************************/
// Check if some kernel processing is ongoing (during wakeup, kernel events are not processed)
if (((rwip_env.prevent_sleep & RW_WAKE_UP_ONGOING) == 0) && !ke_sleep_check()) {
if (((*p_prevent_sleep & RW_WAKE_UP_ONGOING) == 0) && !ke_sleep_check()) {
break;
}
@ -130,7 +135,7 @@ static uint8_t app_check_stack_status(uint32_t msec) {
************** CHECK RW FLAGS **************
************************************************************************/
// First check if no pending procedure prevent from going to sleep
if (rwip_env.prevent_sleep != 0) {
if (*p_prevent_sleep != 0) {
break;
}

10
src/app_lowpower.c Normal file
View File

@ -0,0 +1,10 @@
#include "n32wb03x.h"
void app_sleep_prepare_proc(void) {
/* -- */
}
void app_sleep_resume_proc(void) {
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE);
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE);
}