From 255c51174a0571340ef470184064a5c75d261d27 Mon Sep 17 00:00:00 2001 From: WXK <287788329@qq.com> Date: 星期三, 22 一月 2025 15:06:27 +0800 Subject: [PATCH] 加入一开始不广播升级 中断触发gpio后广播升级 10分钟自动退出 --- 01_SDK/nimble/samples/bluetooth/ble_central_periph_ota/src/app_ble.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 104 insertions(+), 2 deletions(-) diff --git a/01_SDK/nimble/samples/bluetooth/ble_central_periph_ota/src/app_ble.c b/01_SDK/nimble/samples/bluetooth/ble_central_periph_ota/src/app_ble.c index e56710d..9e58682 100644 --- a/01_SDK/nimble/samples/bluetooth/ble_central_periph_ota/src/app_ble.c +++ b/01_SDK/nimble/samples/bluetooth/ble_central_periph_ota/src/app_ble.c @@ -14,7 +14,7 @@ #include "pan_ble.h" #include "app.h" #include "app_log.h" - +#include "soc_api.h" static void app_ble_set_mac_addr(void) { /** set public address*/ @@ -38,7 +38,7 @@ { #if CONFIG_BT_MAX_NUM_OF_PERIPHERAL /* Adv */ - app_ble_adv_start(); +// app_ble_adv_start(); #endif #if CONFIG_BT_MAX_NUM_OF_CENTRAL @@ -55,6 +55,7 @@ */ TimerHandle_t xTimerUser; uint16_t timer; +uint8_t shengji_flag; extern struct queue //结构体类型 { uint8_t totalnum;//基站总数 @@ -67,6 +68,8 @@ uint16_t u16id[anchor_max_num]; /*u16ID*/ }blequeue; uint8_t slave_send_buf[100]; +uint16_t shengji_time; +uint8_t only_one; void Spi_Zubao_Send(void) { if(blequeue.totalnum>10) @@ -91,9 +94,81 @@ { timer++; Spi_Zubao_Send(); + if (shengji_flag==1) + { + shengji_time++; + if(shengji_time>600) + { + NVIC_SystemReset(); + } + } +} +static TaskHandle_t xTaskToNotify = NULL; +static void gpio_p02_input_callback(HAL_GPIO_IntMode intMode) +{ + BaseType_t xHigherPriorityTaskWoken = pdTRUE; + + /* Notify the task that KEY1 is pressed (P06 falling edge detected). */ +// vTaskNotifyGiveFromISR(xTaskToNotify, &xHigherPriorityTaskWoken); + if (shengji_flag==0) + { + if (HAL_GPIO_ReadPin(P0_2) == HAL_GPIO_LEVEL_LOW) + { + APP_LOG_INFO("==== HAL_GPIO_LEVEL_LOW ,进入升级模式====\n"); + } + else + { + APP_LOG_INFO("==== HAL_GPIO_LEVEL_HIGH ,进入升级模式====\n"); + } + shengji_flag=1; + only_one=1; + #if CONFIG_BT_MAX_NUM_OF_PERIPHERAL + /* Adv */ +// app_ble_adv_start(); +// shengji_start(); + #endif + + } +} +static void gpio_init(void) +{ + /* Set pinmux of P06 to GPIO (default) */ + SYS_SET_MFP(P0, 2, GPIO); + + /* Init GPIO P06 to digital input mode */ + HAL_GPIO_InitTypeDef GPIO_InitStruct = { + .mode = HAL_GPIO_MODE_INPUT_DIGITAL, + .pull = HAL_GPIO_PULL_UP, + }; + HAL_GPIO_Init(P0_2, &GPIO_InitStruct); + + /* Wait a while for internal pull-up resistor stable to avoid later interrupt false triggering */ + soc_busy_wait(10000); + + /* Enable input interrupt of GPIO P06 */ + HAL_GPIO_IntInitTypeDef GPIO_IntInitStruct = { + .intMode = HAL_GPIO_INT_FALLING, // Change this option to see different interrupt behaviors + .callbackFunc = gpio_p02_input_callback, + .debounce = ENABLE, + }; + HAL_GPIO_InterruptInit(P0_2, &GPIO_IntInitStruct); + + /* Enable NVIC GPIO0 IRQn */ + NVIC_EnableIRQ(GPIO0_IRQn); } void app_ble_pre_init_cb(void) { + /* + * Configure clock of GPIO interrupt debouce + * NOTE: + * - This configuration affects all GPIOs with debounce enabled + * - This API should only be called once at app init flow for safe + */ + GPIO_SetDebounceTime(GPIO_DBCTL_DBCLKSRC_RCL, GPIO_DBCTL_DBCLKSEL_32); // Set debounce time to 32 cycles of 32K Clock (about 1ms) + + /* Init P06 to digital input mode with interrupt and debounce enabled */ + gpio_init(); + /* Set MAC address. */ app_ble_set_mac_addr(); @@ -109,6 +184,7 @@ img_mgmt_module_init(); smp_ble_pkg_init(); + app_ble_thread_init(); xTimerUser = xTimerCreate("Timer's name",pdMS_TO_TICKS(900),pdTRUE,( void * ) 0,vTimerCallback); if( xTimerUser != NULL ) { xTimerStart( xTimerUser, 0 ); @@ -121,4 +197,30 @@ pan_ble_stack_init(app_ble_pre_init_cb, app_ble_enabled_cb); } +void POLL(void) +{ + if(shengji_flag&&only_one) + { + app_ble_adv_start(); + only_one=0; + } +} +#define MYNEWT_VAL_APP_BLE_THREAD_STACK_SIZE 128 +static TaskHandle_t app_ble_task_h; +void app_ble_thread_entry(void *parameter) +{ + while(1) + { + POLL(); + vTaskDelay((pdMS_TO_TICKS(1000))); + } +vTaskDelete(NULL); + +} +void app_ble_thread_init(void) +{ + xTaskCreate(app_ble_thread_entry, "app", MYNEWT_VAL(APP_BLE_THREAD_STACK_SIZE), + NULL, configMAX_PRIORITIES - 3, &app_ble_task_h); + +} \ No newline at end of file -- Gitblit v1.9.3