generated from Embedded_Projects/N32WB031_RTOS_BLE
Added global lock for BLE stack.
Signed-off-by: Yilin Sun <imi415@imi.moe>
This commit is contained in:
parent
35170da6ab
commit
31447e4249
|
@ -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
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
#ifndef APP_BLE_SUPPORT_H
|
||||
#define APP_BLE_SUPPORT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
int app_ble_init(void);
|
||||
int app_ble_lock(uint32_t block_ms);
|
||||
int app_ble_unlock(void);
|
||||
|
||||
#endif // APP_BLE_SUPPORT_H
|
|
@ -15,7 +15,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);
|
||||
|
@ -25,7 +26,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;
|
||||
|
@ -41,14 +42,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) {
|
||||
|
|
24
src/main.c
24
src/main.c
|
@ -11,7 +11,8 @@
|
|||
/* Profiles */
|
||||
#include "app_ble_profiles/app_ble_bass.h"
|
||||
|
||||
void app_ble_init(void);
|
||||
/* App */
|
||||
#include "app_ble_support.h"
|
||||
|
||||
static void task_initialize(void *parameters);
|
||||
|
||||
|
@ -19,7 +20,9 @@ int main(void) {
|
|||
board_led_init(0);
|
||||
board_led_init(1);
|
||||
|
||||
app_ble_init();
|
||||
if (app_ble_init() < 0) {
|
||||
goto dead_loop;
|
||||
}
|
||||
|
||||
if (xTaskCreate(task_initialize, "INIT", 256, NULL, 4, NULL) != pdTRUE) {
|
||||
goto dead_loop;
|
||||
|
@ -37,13 +40,18 @@ dead_loop:
|
|||
static void task_initialize(void *parameters) {
|
||||
uint8_t battery_level = 0U;
|
||||
for (;;) {
|
||||
board_led_toggle(0);
|
||||
app_ble_bass_update_level(battery_level);
|
||||
if (app_ble_lock(100) >= 0) {
|
||||
board_led_set(0, true);
|
||||
app_ble_bass_update_level(battery_level);
|
||||
battery_level++;
|
||||
if (battery_level > 100) {
|
||||
battery_level = 0;
|
||||
}
|
||||
|
||||
battery_level++;
|
||||
if (battery_level > 100) {
|
||||
battery_level = 0;
|
||||
board_led_set(0, false);
|
||||
app_ble_unlock();
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(500));
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(5000));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue