generated from Embedded_Projects/N32WB031_Template
Fixed tickless idle.
Signed-off-by: Yilin Sun <imi415@imi.moe>
This commit is contained in:
parent
02a525aca1
commit
5a511eb211
|
@ -55,6 +55,7 @@ set(TARGET_SOURCES
|
|||
"src/app_ble_support.c"
|
||||
"src/app_ble_profiles/app_ble_diss.c"
|
||||
"src/app_freertos_support.c"
|
||||
"src/app_lowpower.c"
|
||||
"src/main.c"
|
||||
)
|
||||
|
||||
|
|
|
@ -19,8 +19,8 @@ extern uint32_t SystemCoreClock;
|
|||
#define configIDLE_SHOULD_YIELD 1
|
||||
#define configUSE_TASK_NOTIFICATIONS 1
|
||||
#define configTASK_NOTIFICATION_ARRAY_ENTRIES 3
|
||||
#define configUSE_MUTEXES 0
|
||||
#define configUSE_RECURSIVE_MUTEXES 0
|
||||
#define configUSE_MUTEXES 1
|
||||
#define configUSE_RECURSIVE_MUTEXES 1
|
||||
#define configUSE_COUNTING_SEMAPHORES 0
|
||||
#define configUSE_ALTERNATIVE_API 0 /* Deprecated! */
|
||||
#define configQUEUE_REGISTRY_SIZE 10
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
/* Board */
|
||||
#include "board.h"
|
||||
|
||||
static TaskHandle_t s_ble_task_handle;
|
||||
static TaskHandle_t s_ble_task_handle;
|
||||
static SemaphoreHandle_t s_ble_lock_handle;
|
||||
|
||||
static void app_ble_task(void *parameters);
|
||||
static void app_ble_msg_handler(struct ble_msg_t const *p_ble_msg);
|
||||
|
@ -24,7 +25,7 @@ static void app_ble_adv_init(void);
|
|||
static void app_ble_sec_init(void);
|
||||
static void app_ble_prf_init(void);
|
||||
|
||||
void app_ble_init(void) {
|
||||
int app_ble_init(void) {
|
||||
struct ns_stack_cfg_t app_handler = {0};
|
||||
app_handler.ble_msg_handler = app_ble_msg_handler;
|
||||
app_handler.user_msg_handler = app_user_msg_handler;
|
||||
|
@ -40,14 +41,33 @@ void app_ble_init(void) {
|
|||
// start advertising
|
||||
ns_ble_adv_start();
|
||||
|
||||
s_ble_lock_handle = xSemaphoreCreateMutex();
|
||||
if (s_ble_lock_handle == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (xTaskCreate(app_ble_task, "BLE", 1536, NULL, 5, &s_ble_task_handle) != pdPASS) {
|
||||
for (;;) {
|
||||
/* -- */
|
||||
}
|
||||
return -2;
|
||||
}
|
||||
|
||||
NVIC_SetPriority(RESERVED_IRQn, 2);
|
||||
NVIC_EnableIRQ(RESERVED_IRQn);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int app_ble_lock(uint32_t block_ms) {
|
||||
if (xSemaphoreTake(s_ble_lock_handle, pdMS_TO_TICKS(block_ms)) != pdPASS) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int app_ble_unlock(void) {
|
||||
xSemaphoreGive(s_ble_lock_handle);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void RESERVED_IRQHandler(void) {
|
||||
|
@ -60,7 +80,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, ¬ification_value, portMAX_DELAY);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
Loading…
Reference in New Issue