component/bt : add bluetooth status check

1. add bluetooth controller/host initialize status check
2. separate bluetooth controller task schedule loop from controller init
pull/336/merge
Tian Hao 2017-02-21 01:05:37 +08:00
rodzic bb0298bc71
commit 12a7293b31
5 zmienionych plików z 53 dodań i 5 usunięć

Wyświetl plik

@ -16,6 +16,7 @@
#include "esp_bt_main.h" #include "esp_bt_main.h"
#include "btc_task.h" #include "btc_task.h"
#include "btc_main.h" #include "btc_main.h"
#include "bt.h"
#include "future.h" #include "future.h"
static bool esp_already_enable = false; static bool esp_already_enable = false;
@ -103,6 +104,11 @@ esp_err_t esp_bluedroid_init(void)
btc_msg_t msg; btc_msg_t msg;
future_t **future_p; future_t **future_p;
if (esp_bt_controller_get_status() != ESP_BT_CONTROLLER_STATUS_ENABLED) {
LOG_ERROR("%s conroller not init\n", __func__);
return ESP_ERR_INVALID_STATE;
}
if (esp_already_init) { if (esp_already_init) {
LOG_ERROR("%s already init\n", __func__); LOG_ERROR("%s already init\n", __func__);
return ESP_ERR_INVALID_STATE; return ESP_ERR_INVALID_STATE;

Wyświetl plik

@ -35,6 +35,7 @@
/* not for user call, so don't put to include file */ /* not for user call, so don't put to include file */
extern void btdm_osi_funcs_register(void *osi_funcs); extern void btdm_osi_funcs_register(void *osi_funcs);
extern void btdm_controller_init(void); extern void btdm_controller_init(void);
extern void btdm_controller_schedule(void);
extern void btdm_controller_deinit(void); extern void btdm_controller_deinit(void);
extern int btdm_controller_enable(esp_bt_mode_t mode); extern int btdm_controller_enable(esp_bt_mode_t mode);
extern int btdm_controller_disable(esp_bt_mode_t mode); extern int btdm_controller_disable(esp_bt_mode_t mode);
@ -77,6 +78,7 @@ struct osi_funcs_t {
/* Static variable declare */ /* Static variable declare */
static bool btdm_bb_init_flag = false; static bool btdm_bb_init_flag = false;
static esp_bt_controller_status_t btdm_controller_status = ESP_BT_CONTROLLER_STATUS_IDLE;
static xTaskHandle btControllerTaskHandle; static xTaskHandle btControllerTaskHandle;
@ -157,12 +159,18 @@ static void bt_controller_task(void *pvParam)
btdm_osi_funcs_register(&osi_funcs); btdm_osi_funcs_register(&osi_funcs);
btdm_controller_init(); btdm_controller_init();
btdm_controller_status = ESP_BT_CONTROLLER_STATUS_INITED;
/* Loop */
btdm_controller_schedule();
} }
static bool bb_inited;
void esp_bt_controller_init() void esp_bt_controller_init()
{ {
bb_inited = false; if (btdm_controller_status != ESP_BT_CONTROLLER_STATUS_IDLE) {
return;
}
xTaskCreatePinnedToCore(bt_controller_task, "btController", xTaskCreatePinnedToCore(bt_controller_task, "btController",
ESP_TASK_BT_CONTROLLER_STACK, NULL, ESP_TASK_BT_CONTROLLER_STACK, NULL,
ESP_TASK_BT_CONTROLLER_PRIO, &btControllerTaskHandle, 0); ESP_TASK_BT_CONTROLLER_PRIO, &btControllerTaskHandle, 0);
@ -171,13 +179,17 @@ void esp_bt_controller_init()
void esp_bt_controller_deinit(void) void esp_bt_controller_deinit(void)
{ {
vTaskDelete(btControllerTaskHandle); vTaskDelete(btControllerTaskHandle);
bb_inited = false; btdm_controller_status = ESP_BT_CONTROLLER_STATUS_IDLE;
} }
esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode) esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode)
{ {
int ret; int ret;
if (btdm_controller_status != ESP_BT_CONTROLLER_STATUS_INITED) {
return ESP_ERR_INVALID_STATE;
}
if (mode != ESP_BT_MODE_BTDM) { if (mode != ESP_BT_MODE_BTDM) {
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;
} }
@ -194,6 +206,8 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode)
return ESP_ERR_INVALID_STATE; return ESP_ERR_INVALID_STATE;
} }
btdm_controller_status = ESP_BT_CONTROLLER_STATUS_ENABLED;
return ESP_OK; return ESP_OK;
} }
@ -201,6 +215,10 @@ esp_err_t esp_bt_controller_disable(esp_bt_mode_t mode)
{ {
int ret; int ret;
if (btdm_controller_status != ESP_BT_CONTROLLER_STATUS_ENABLED) {
return ESP_ERR_INVALID_STATE;
}
if (mode != ESP_BT_MODE_BTDM) { if (mode != ESP_BT_MODE_BTDM) {
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;
} }
@ -212,7 +230,14 @@ esp_err_t esp_bt_controller_disable(esp_bt_mode_t mode)
esp_phy_rf_deinit(); esp_phy_rf_deinit();
btdm_controller_status = ESP_BT_CONTROLLER_STATUS_INITED;
return ESP_OK; return ESP_OK;
} }
esp_bt_controller_status_t esp_bt_controller_get_status(void)
{
return btdm_controller_status;
}
#endif #endif

Wyświetl plik

@ -33,6 +33,16 @@ typedef enum {
ESP_BT_MODE_BTDM = 0x03, /*!< Run dual mode */ ESP_BT_MODE_BTDM = 0x03, /*!< Run dual mode */
} esp_bt_mode_t; } esp_bt_mode_t;
/**
* @brief Bluetooth controller enable/disable/initialised/de-initialised status
*/
typedef enum {
ESP_BT_CONTROLLER_STATUS_IDLE = 0,
ESP_BT_CONTROLLER_STATUS_INITED,
ESP_BT_CONTROLLER_STATUS_ENABLED,
ESP_BT_CONTROLLER_STATUS_NUM,
} esp_bt_controller_status_t;
/** /**
* @brief Initialize BT controller to allocate task and other resource. * @brief Initialize BT controller to allocate task and other resource.
* *
@ -52,6 +62,7 @@ void esp_bt_controller_deinit(void);
* @brief Enable BT controller * @brief Enable BT controller
* @param mode : the mode(BLE/BT/BTDM) to enable. * @param mode : the mode(BLE/BT/BTDM) to enable.
* Now only support BTDM. * Now only support BTDM.
* @return ESP_OK - success, other - failed
*/ */
esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode); esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode);
@ -59,10 +70,15 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode);
* @brief Disable BT controller * @brief Disable BT controller
* @param mode : the mode(BLE/BT/BTDM) to disable. * @param mode : the mode(BLE/BT/BTDM) to disable.
* Now only support BTDM. * Now only support BTDM.
* @return ESP_OK - success, other - failed
*/ */
esp_err_t esp_bt_controller_disable(esp_bt_mode_t mode); esp_err_t esp_bt_controller_disable(esp_bt_mode_t mode);
/**
* @brief Get BT controller is initialised/de-initialised/enabled/disabled
* @return status value
*/
esp_bt_controller_status_t esp_bt_controller_get_status(void);
/** @brief esp_vhci_host_callback /** @brief esp_vhci_host_callback
* used for vhci call host function to notify what host need to do * used for vhci call host function to notify what host need to do

@ -1 +1 @@
Subproject commit 69616af7653f4de6e3b78f475dc10e73f0a20ece Subproject commit dbac82b5c2694f2639161b0a2b3c0bd8c7d3efc5

Wyświetl plik

@ -49,6 +49,7 @@ Functions
.. doxygenfunction:: esp_bt_controller_deinit .. doxygenfunction:: esp_bt_controller_deinit
.. doxygenfunction:: esp_bt_controller_enable .. doxygenfunction:: esp_bt_controller_enable
.. doxygenfunction:: esp_bt_controller_disable .. doxygenfunction:: esp_bt_controller_disable
.. doxygenfunction:: esp_bt_controller_get_status
.. doxygenfunction:: esp_vhci_host_check_send_available .. doxygenfunction:: esp_vhci_host_check_send_available
.. doxygenfunction:: esp_vhci_host_send_packet .. doxygenfunction:: esp_vhci_host_send_packet
.. doxygenfunction:: esp_vhci_host_register_callback .. doxygenfunction:: esp_vhci_host_register_callback