[update] update ble os port

This commit is contained in:
jzlv 2023-09-19 10:50:35 +08:00
parent 551c58b349
commit 819d25434c
13 changed files with 477 additions and 88 deletions

View File

@ -2,7 +2,7 @@ sdk_add_include_directories(btble_inc)
sdk_add_include_directories(btblecontroller_port) sdk_add_include_directories(btblecontroller_port)
# use default port built by lib # use default port built by lib
#target_sources(app PRIVATE btblecontroller_port/btblecontroller_port_os.c) #target_sources(app PRIVATE btblecontroller_port/btblecontroller_port_freertos_os.c)
#target_sources(app PRIVATE btblecontroller_port/btblecontroller_port.c) #target_sources(app PRIVATE btblecontroller_port/btblecontroller_port.c)
#target_sources(app PRIVATE btblecontroller_port/btblecontroller_port_uart.c) #target_sources(app PRIVATE btblecontroller_port/btblecontroller_port_uart.c)

View File

@ -44,10 +44,12 @@ struct hci_vs_tx_test_cmd
}; };
#endif #endif
void btble_controller_set_task_stack_size(uint16_t stack_size);
void btble_controller_init(uint8_t task_priority); void btble_controller_init(uint8_t task_priority);
void btble_controller_deinit(void); void ble_controller_deinit(void);
#if defined(CFG_NUTTX) #if defined(CFG_NUTTX)
void bbtlecontroller_main(void); void btblecontroller_main(void *arg);
uint8_t btblecontroller_change_scan_itl_win(uint16_t interval, uint16_t window);
#endif #endif
extern int32_t btble_controller_sleep(int32_t max_sleep_cycles); extern int32_t btble_controller_sleep(int32_t max_sleep_cycles);
@ -64,8 +66,23 @@ bool ble_controller_sleep_is_ongoing(void);
char *btble_controller_get_lib_ver(void); char *btble_controller_get_lib_ver(void);
void btble_controller_remaining_mem(uint8_t** addr, int* size); void btble_controller_remaining_mem(uint8_t** addr, int* size);
void btble_controller_set_cs2(uint8_t enable); // cs2 is enabled by default
#if defined(BL702L) #if defined(BL702L)
void ble_controller_set_tx_pwr(int ble_tx_power); void btble_controller_sleep_init(void);
typedef int (*btble_before_sleep_cb_t)(void);
typedef void (*btble_after_sleep_cb_t)(void);
typedef void (*btble_sleep_aborted_cb_t)(void);
int8_t btble_controller_get_tx_pwr(void);
void btble_set_before_sleep_callback(btble_before_sleep_cb_t cb);
void btble_set_after_sleep_callback(btble_after_sleep_cb_t cb);
#if !defined(CONFIG_BLE_MFG)
/*
If ble sleep preparation is aborted before sleep, this callback will be trigerred. Please be noticed,
this callback is triggerd after before_sleep_callback.
e.g. Application disables something before sleep, application needs to enable these when sleep is aborted.
*/
void btble_set_sleep_aborted_callback(btble_sleep_aborted_cb_t cb);
#endif
#endif #endif
#if defined (CONFIG_BLE_MFG) || defined (CONFIG_BT_MFG) #if defined (CONFIG_BLE_MFG) || defined (CONFIG_BT_MFG)

View File

@ -7,7 +7,9 @@ enum{
BT_HCI_CMD_CMP_EVT, BT_HCI_CMD_CMP_EVT,
BT_HCI_CMD_STAT_EVT, BT_HCI_CMD_STAT_EVT,
BT_HCI_LE_EVT, BT_HCI_LE_EVT,
BT_HCI_EVT BT_HCI_EVT,
BT_HCI_SYNC_DATA,
BT_HCI_DBG_EVT,
}; };
typedef struct{ typedef struct{

View File

@ -1,55 +1,113 @@
#include "btblecontroller_port.h" #include "btblecontroller_port.h"
#if defined(CFG_IOT_SDK)
#include "bl_irq.h"
#else
#include "bflb_irq.h" #include "bflb_irq.h"
#include "bflb_efuse.h" #include "bflb_efuse.h"
#endif
#if defined(BL616) #if defined(BL616)
#include "bl616_glb.h" #include "bl616_glb.h"
#include "wl_api.h"
#include "bl616_pds.h"
#if defined(CFG_IOT_SDK)
#include "bl_efuse.h"
#endif #endif
#define WL_API_RMEM_ADDR 0x20010600
#endif
#if defined(BL808)
#include "bl808_glb.h"
#endif
#if defined(BL702L) #if defined(BL702L)
#include "bl702l_glb.h" #include "bl702l_glb.h"
#endif #endif
#if defined(BL616) #if defined(CFG_IOT_SDK)
#include "wl_api.h" extern void bl_irq_pending_clear(unsigned int source);
#define WL_API_RMEM_ADDR 0x20010600
#endif #endif
__attribute__((weak)) void btblecontroller_ble_irq_init(void *handler) __attribute__((weak)) void btblecontroller_ble_irq_init(void *handler)
{ {
#if defined(CFG_IOT_SDK)
bl_irq_pending_clear(BLE_IRQn);
bl_irq_register(BLE_IRQn, handler);
bl_irq_enable(BLE_IRQn);
#else
bflb_irq_clear_pending(BLE_IRQn); bflb_irq_clear_pending(BLE_IRQn);
bflb_irq_attach(BLE_IRQn, (irq_callback)handler, NULL); bflb_irq_attach(BLE_IRQn, (irq_callback)handler, NULL);
bflb_irq_enable(BLE_IRQn); bflb_irq_enable(BLE_IRQn);
#endif
} }
#if !defined(BL702L)
__attribute__((weak)) void btblecontroller_bt_irq_init(void *handler) __attribute__((weak)) void btblecontroller_bt_irq_init(void *handler)
{ {
#if defined(CFG_IOT_SDK)
bl_irq_pending_clear(BT_IRQn);
bl_irq_register(BT_IRQn, handler);
bl_irq_enable(BT_IRQn);
#else
bflb_irq_clear_pending(BT_IRQn); bflb_irq_clear_pending(BT_IRQn);
bflb_irq_attach(BT_IRQn, (irq_callback)handler, NULL); bflb_irq_attach(BT_IRQn, (irq_callback)handler, NULL);
bflb_irq_enable(BT_IRQn); bflb_irq_enable(BT_IRQn);
#endif
} }
__attribute__((weak)) void btblecontroller_dm_irq_init(void *handler) __attribute__((weak)) void btblecontroller_dm_irq_init(void *handler)
{ {
#if defined(CFG_IOT_SDK)
bl_irq_pending_clear(DM_IRQn);
bl_irq_register(DM_IRQn, handler);
bl_irq_enable(DM_IRQn);
#else
bflb_irq_clear_pending(DM_IRQn); bflb_irq_clear_pending(DM_IRQn);
bflb_irq_attach(DM_IRQn, (irq_callback)handler, NULL); bflb_irq_attach(DM_IRQn, (irq_callback)handler, NULL);
bflb_irq_enable(DM_IRQn); bflb_irq_enable(DM_IRQn);
#endif
} }
#endif
__attribute__((weak)) void btblecontroller_ble_irq_enable(uint8_t enable) __attribute__((weak)) void btblecontroller_ble_irq_enable(uint8_t enable)
{ {
#if defined(CFG_IOT_SDK)
if(enable) if(enable)
{ {
bl_irq_enable(BLE_IRQn);
}
else
{
bl_irq_disable(BLE_IRQn);
}
#else
if(enable)
{
bflb_irq_enable(BLE_IRQn); bflb_irq_enable(BLE_IRQn);
} }
else else
{ {
bflb_irq_disable(BLE_IRQn); bflb_irq_disable(BLE_IRQn);
} }
#endif
} }
#if !defined(BL702L)
__attribute__((weak)) void btblecontroller_bt_irq_enable(uint8_t enable) __attribute__((weak)) void btblecontroller_bt_irq_enable(uint8_t enable)
{ {
#if defined(CFG_IOT_SDK)
if(enable)
{
bl_irq_enable(BT_IRQn);
}
else
{
bl_irq_disable(BT_IRQn);
}
#else
if(enable) if(enable)
{ {
bflb_irq_enable(BT_IRQn); bflb_irq_enable(BT_IRQn);
@ -58,10 +116,21 @@ __attribute__((weak)) void btblecontroller_bt_irq_enable(uint8_t enable)
{ {
bflb_irq_disable(BT_IRQn); bflb_irq_disable(BT_IRQn);
} }
#endif
} }
__attribute__((weak)) void btblecontroller_dm_irq_enable(uint8_t enable) __attribute__((weak)) void btblecontroller_dm_irq_enable(uint8_t enable)
{ {
#if defined(CFG_IOT_SDK)
if(enable)
{
bl_irq_enable(DM_IRQn);
}
else
{
bl_irq_disable(DM_IRQn);
}
#else
if(enable) if(enable)
{ {
bflb_irq_enable(DM_IRQn); bflb_irq_enable(DM_IRQn);
@ -70,11 +139,13 @@ __attribute__((weak)) void btblecontroller_dm_irq_enable(uint8_t enable)
{ {
bflb_irq_disable(DM_IRQn); bflb_irq_disable(DM_IRQn);
} }
#endif
} }
#endif
__attribute__((weak)) void btblecontroller_enable_ble_clk(uint8_t enable) __attribute__((weak)) void btblecontroller_enable_ble_clk(uint8_t enable)
{ {
#if defined(BL702L) || defined(BL702) #if defined(BL702L)
GLB_Set_BLE_CLK(enable); GLB_Set_BLE_CLK(enable);
#endif #endif
} }
@ -92,14 +163,43 @@ __attribute__((weak)) void btblecontroller_rf_restore()
__attribute__((weak)) int btblecontroller_efuse_read_mac(uint8_t mac[6]) __attribute__((weak)) int btblecontroller_efuse_read_mac(uint8_t mac[6])
{ {
int status = 0;
uint8_t tmp[8]; uint8_t tmp[8];
bflb_efuse_get_chipid(tmp);
#if defined(CFG_IOT_SDK)
#if defined(BL702L)
extern int bl_wireless_mac_addr_get(uint8_t mac[8]);
bl_wireless_mac_addr_get(tmp);
#else
extern int bl_efuse_read_mac(uint8_t mac[6]);
status = bl_efuse_read_mac(tmp);
#endif
#else
bflb_efuse_get_chipid(tmp);
#endif
mac[0] = tmp[0]; mac[0] = tmp[0];
mac[1] = tmp[1]; mac[1] = tmp[1];
mac[2] = tmp[2]; mac[2] = tmp[2];
mac[3] = tmp[3]; mac[3] = tmp[3];
mac[4] = tmp[4]; mac[4] = tmp[4];
mac[5] = tmp[5]; mac[5] = tmp[5];
return 0; return status;
} }
#if defined(BL616)
__attribute__((weak)) void btblecontroller_software_btdm_reset()
{
GLB_AHB_MCU_Software_Reset(GLB_AHB_MCU_SW_BTDM);
}
__attribute__((weak)) void btblecontroller_software_pds_reset()
{
GLB_AHB_MCU_Software_Reset(GLB_AHB_MCU_SW_PDS);
}
__attribute__((weak)) void btblecontroller_pds_trim_rc32m()
{
PDS_Trim_RC32M();
}
#endif

View File

@ -6,17 +6,13 @@
void btblecontroller_ble_irq_init(void *handler); void btblecontroller_ble_irq_init(void *handler);
void btblecontroller_bt_irq_init(void *handler); void btblecontroller_bt_irq_init(void *handler);
void btblecontroller_dm_irq_init(void *handler); void btblecontroller_dm_irq_init(void *handler);
void btblecontroller_ble_irq_register(void *handler);
void btblecontroller_bt_irq_register(void *handler);
void btblecontroller_dm_irq_register(void *handler);
void btblecontroller_ble_irq_enable(uint8_t enable); void btblecontroller_ble_irq_enable(uint8_t enable);
void btblecontroller_bt_irq_enable(uint8_t enable); void btblecontroller_bt_irq_enable(uint8_t enable);
void btblecontroller_dm_irq_enable(uint8_t enable); void btblecontroller_dm_irq_enable(uint8_t enable);
void btblecontroller_irq_pending_clear(int irq_num);
void btblecontroller_irq_register(int irq_num, void *handler);
void btblecontroller_irq_enable(int irq_num);
void btblecontroller_enable_ble_clk(uint8_t enable); void btblecontroller_enable_ble_clk(uint8_t enable);
void btblecontroller_rf_restore(); void btblecontroller_rf_restore();
int btblecontroller_efuse_read_mac(uint8_t mac[6]); int btblecontroller_efuse_read_mac(uint8_t mac[6]);
void btblecontroller_software_btdm_reset();
void btblecontroller_software_pds_reset();
void btblecontroller_pds_trim_rc32m();
#endif #endif

View File

@ -0,0 +1,76 @@
#include "btblecontroller_port_os.h"
#include <aos/kernel.h>
#include <aos/aos.h>
#include <k_api.h>
__attribute__((weak)) int btblecontroller_task_new(btblecontroller_TaskFunction_t taskFunction,const char *name, int stack_size, void *arg, int prio,void *taskHandler)
{
return aos_task_new_ext((aos_task_t*)taskHandler, name, taskFunction, arg, stack_size, prio);
}
__attribute__((weak)) void btblecontroller_task_delete(uint32_t taskHandler)
{
void* hdl = ((aos_task_t*)taskHandler)->hdl;
krhino_task_dyn_del((ktask_t *)hdl);
hdl = NULL;
}
__attribute__((weak)) int btblecontroller_queue_new(uint32_t size, uint32_t max_msg,btblecontroller_QueueHandle_t *queue)
{
uint32_t buf_size = size*max_msg;
void *msg_start = (void*)aos_malloc(buf_size);
aos_queue_new(queue, msg_start, buf_size, max_msg);
if ( *queue == NULL )
return -1;
return 0;
}
__attribute__((weak)) void btblecontroller_queue_free(btblecontroller_QueueHandle_t q)
{
kbuf_queue_t *buf_queue = q.hdl;
aos_free(buf_queue->buf);
aos_queue_free(&q);
}
__attribute__((weak)) int btblecontroller_queue_send(btblecontroller_QueueHandle_t q, void *msg, uint32_t size, uint32_t timeout)
{
int status = aos_queue_send(q, msg, size);
if(status == 0)
{
return 1;
}
else
{
return 0;
}
}
__attribute__((weak)) int btblecontroller_queue_recv(btblecontroller_QueueHandle_t q, void *msg, uint32_t timeout)
{
unsigned int len;
unsigned int delay = 0xffffffff;
int status = aos_queue_recv(&q,delay,msg,&len);
if(status == 0)
{
return 1;
}
else
{
return 0;
}
}
__attribute__((weak)) int btblecontroller_queue_send_from_isr(btblecontroller_QueueHandle_t q, void *msg, uint32_t size)
{
aos_queue_send(q, msg, size);
}
__attribute__((weak)) int btblecontroller_xport_is_inside_interrupt()
{
return 0;
}
__attribute__((weak)) void btblecontroller_task_delay(uint32_t ms)
{
vTaskDelay(pdMS_TO_TICKS(ms));
}

View File

@ -0,0 +1,71 @@
#include "btblecontroller_port_os.h"
#include "FreeRTOS.h"
#define BTBLE_OS_PORT_ASSERT(x) \
if ((x) == 0) { \
printf("[BTBLE ASSERT] %s in function %s\r\n", (const char *)(#x), __FUNCTION__); \
while (1) {} \
}
__attribute__((weak)) int btblecontroller_task_new(btblecontroller_TaskFunction_t taskFunction, const char *name, int stack_size, void *arg, int prio, void *taskHandler)
{
return xTaskCreate((TaskFunction_t)taskFunction, name, stack_size, arg, prio, (TaskHandle_t *const)taskHandler);
}
__attribute__((weak)) void btblecontroller_task_delete(uint32_t taskHandler)
{
vTaskDelete((TaskHandle_t)taskHandler);
}
__attribute__((weak)) int btblecontroller_queue_new(uint32_t size, uint32_t max_msg, btblecontroller_QueueHandle_t *queue)
{
*queue = xQueueCreate(size, max_msg);
BTBLE_OS_PORT_ASSERT(*queue);
if (*queue == NULL)
return -1;
return 0;
}
__attribute__((weak)) void btblecontroller_queue_free(btblecontroller_QueueHandle_t q)
{
BTBLE_OS_PORT_ASSERT(q);
vQueueDelete(q);
}
__attribute__((weak)) int btblecontroller_queue_send(btblecontroller_QueueHandle_t q, void *msg, uint32_t size, uint32_t timeout)
{
BTBLE_OS_PORT_ASSERT(q);
return xQueueSend(q, msg, timeout);
}
__attribute__((weak)) int btblecontroller_queue_recv(btblecontroller_QueueHandle_t q, void *msg, uint32_t timeout)
{
BTBLE_OS_PORT_ASSERT(q);
return xQueueReceive(q, msg, timeout);
}
__attribute__((weak)) int btblecontroller_queue_send_from_isr(btblecontroller_QueueHandle_t q, void *msg, uint32_t size)
{
BaseType_t xHigherPriorityTaskWoken;
int ret;
xHigherPriorityTaskWoken = pdFALSE;
BTBLE_OS_PORT_ASSERT(q);
ret = xQueueSendFromISR(q, msg, &xHigherPriorityTaskWoken);
if (xHigherPriorityTaskWoken == pdTRUE) {
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
return ret;
}
__attribute__((weak)) int btblecontroller_xport_is_inside_interrupt()
{
return xPortIsInsideInterrupt();
}
__attribute__((weak)) void btblecontroller_task_delay(uint32_t ms)
{
vTaskDelay(pdMS_TO_TICKS(ms));
}

View File

@ -0,0 +1,101 @@
#include "btblecontroller_port.h"
#include "bflb_efuse.h"
#if defined(BL702L)
#include "bl702l_glb.h"
#endif
#if defined(BL616)
#include "wl_api.h"
#define WL_API_RMEM_ADDR 0x20010600
#endif
__attribute__((weak)) void btblecontroller_ble_irq_init(void *handler)
{
ClicIrqPendingClear(BLE_IRQn);
HalHwiCreate(BLE_IRQn, 1, 0, handler, 0);
ClicIrqEnable(BLE_IRQn);
}
__attribute__((weak)) void btblecontroller_bt_irq_init(void *handler)
{
ClicIrqPendingClear(BT_IRQn);
HalHwiCreate(BT_IRQn, 1, 0, handler, 0);
ClicIrqEnable(BT_IRQn);
}
__attribute__((weak)) void btblecontroller_dm_irq_init(void *handler)
{
ClicIrqPendingClear(DM_IRQn);
HalHwiCreate(DM_IRQn, 1, 0, handler, 0);
ClicIrqEnable(DM_IRQn);
}
__attribute__((weak)) void btblecontroller_ble_irq_enable(uint8_t enable)
{
if(enable)
{
ClicIrqEnable(BLE_IRQn);
}
else
{
ClicIrqDisable(BLE_IRQn);
}
}
__attribute__((weak)) void btblecontroller_bt_irq_enable(uint8_t enable)
{
if(enable)
{
ClicIrqEnable(BT_IRQn);
}
else
{
ClicIrqDisable(BT_IRQn);
}
}
__attribute__((weak)) void btblecontroller_dm_irq_enable(uint8_t enable)
{
if(enable)
{
ClicIrqEnable(DM_IRQn);
}
else
{
ClicIrqDisable(DM_IRQn);
}
}
__attribute__((weak)) void btblecontroller_enable_ble_clk(uint8_t enable)
{
#if defined(BL702L) || defined(BL702)
GLB_Set_BLE_CLK(enable);
#endif
}
__attribute__((weak)) void btblecontroller_rf_restore()
{
#if defined(BL616)
struct wl_cfg_t *wl_cfg;
wl_cfg = wl_cfg_get((uint8_t *)WL_API_RMEM_ADDR);
wl_cfg->mode = WL_API_MODE_BZ;
wl_lp_init((uint8_t*)WL_API_RMEM_ADDR,2412);
#endif
}
__attribute__((weak)) int btblecontroller_efuse_read_mac(uint8_t mac[6])
{
uint8_t tmp[8];
bflb_efuse_get_chipid(tmp);
mac[0] = tmp[0];
mac[1] = tmp[1];
mac[2] = tmp[2];
mac[3] = tmp[3];
mac[4] = tmp[4];
mac[5] = tmp[5];
return 0;
}

View File

@ -0,0 +1,66 @@
#include "btblecontroller_port_os.h"
#include "FreeRTOS.h"
#include "rtos_al.h"
#include "task.h"
__attribute__((weak)) int btblecontroller_task_new(btblecontroller_TaskFunction_t taskFunction,const char *name, int stack_size, void *arg, int prio,void *taskHandler)
{
return rtos_task_create( (rtos_task_fct)taskFunction, name, 0, stack_size, arg, prio,(rtos_task_handle * const)taskHandler);
}
__attribute__((weak)) void btblecontroller_task_delete(uint32_t taskHandler)
{
rtos_task_delete((TaskHandle_t)taskHandler);
}
__attribute__((weak)) int btblecontroller_queue_new(uint32_t size, uint32_t max_msg,btblecontroller_QueueHandle_t *queue)
{
return rtos_queue_create(max_msg,size,queue);
}
__attribute__((weak)) void btblecontroller_queue_free(btblecontroller_QueueHandle_t q)
{
rtos_queue_delete(q);
}
__attribute__((weak)) int btblecontroller_queue_send(btblecontroller_QueueHandle_t q, void *msg, uint32_t size, uint32_t timeout)
{
int status = rtos_queue_write(q, msg, timeout,false);
if(status != 0)
{
return 0;
}
else
{
return 1;
}
}
__attribute__((weak)) int btblecontroller_queue_recv(btblecontroller_QueueHandle_t q, void *msg, uint32_t timeout)
{
int status = rtos_queue_read(q, msg, timeout,false);
if(status == 0)
{
return 1;
}
else
{
return 0;
}
}
__attribute__((weak)) int btblecontroller_queue_send_from_isr(btblecontroller_QueueHandle_t q, void *msg, uint32_t size)
{
rtos_queue_write(q, msg, 0, true);
return 0;
}
__attribute__((weak)) int btblecontroller_xport_is_inside_interrupt()
{
return HalIsIntActive();
}
__attribute__((weak)) void btblecontroller_task_delay(uint32_t ms)
{
rtos_task_suspend(ms);
}

View File

@ -1,59 +0,0 @@
#include "btblecontroller_port_os.h"
#include "FreeRTOS.h"
__attribute__((weak)) int btblecontroller_task_new(btblecontroller_TaskFunction_t taskFunction,const char *name, int stack_size, void *arg, int prio,void *taskHandler)
{
return xTaskCreate( taskFunction, name, stack_size, arg, prio,(TaskHandle_t * const)taskHandler);
}
__attribute__((weak)) void btblecontroller_task_delete(uint32_t taskHandler)
{
vTaskDelete((TaskHandle_t)taskHandler);
}
__attribute__((weak)) btblecontroller_QueueHandle_t btblecontroller_queue_new(uint32_t size, uint32_t max_msg)
{
btblecontroller_QueueHandle_t q;
q = xQueueCreate(size, max_msg);
return q;
}
__attribute__((weak)) void btblecontroller_queue_free(btblecontroller_QueueHandle_t q)
{
vQueueDelete(q);
}
__attribute__((weak)) int btblecontroller_queue_send(btblecontroller_QueueHandle_t q, void *msg, uint32_t timeout)
{
return xQueueSend(q, msg, timeout);
}
__attribute__((weak)) int btblecontroller_queue_recv(btblecontroller_QueueHandle_t q, void *msg, uint32_t timeout)
{
return xQueueReceive(q, msg, timeout);
}
__attribute__((weak)) int btblecontroller_queue_send_fromisr(btblecontroller_QueueHandle_t q, void *msg)
{
BaseType_t xHigherPriorityTaskWoken;
int ret;
xHigherPriorityTaskWoken = pdFALSE;
ret = xQueueSendFromISR(q, msg, &xHigherPriorityTaskWoken);
if(xHigherPriorityTaskWoken == pdTRUE)
{
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}
return ret;
}
__attribute__((weak)) int btblecontroller_xPortIsInsideInterrupt()
{
return xPortIsInsideInterrupt();
}
__attribute__((weak)) void btblecontroller_TaskDelay(uint32_t ms)
{
vTaskDelay(pdMS_TO_TICKS(ms));
}

View File

@ -3,17 +3,24 @@
#include "FreeRTOS.h" #include "FreeRTOS.h"
#include "queue.h" #include "queue.h"
#if defined(CFG_FREERTOS)
typedef QueueHandle_t btblecontroller_QueueHandle_t; typedef QueueHandle_t btblecontroller_QueueHandle_t;
typedef TaskFunction_t btblecontroller_TaskFunction_t; #elif defined(CFG_OPENHARMONY)
typedef rtos_queue btblecontroller_QueueHandle_t;
#elif defined(CFG_AOS)
typedef aos_queue_t btblecontroller_QueueHandle_t;
#endif
typedef void (*btblecontroller_TaskFunction_t)(void *);
int btblecontroller_task_new(btblecontroller_TaskFunction_t taskFunction,const char *name, int stack_size, void *arg, int prio,void *taskHandler); int btblecontroller_task_new(btblecontroller_TaskFunction_t taskFunction,const char *name, int stack_size, void *arg, int prio,void *taskHandler);
void btblecontroller_task_delete(uint32_t taskHandler); void btblecontroller_task_delete(uint32_t taskHandler);
btblecontroller_QueueHandle_t btblecontroller_queue_new(uint32_t size, uint32_t max_msg); int btblecontroller_queue_new(uint32_t size, uint32_t max_msg,btblecontroller_QueueHandle_t *queue);
void btblecontroller_queue_free(btblecontroller_QueueHandle_t q); void btblecontroller_queue_free(btblecontroller_QueueHandle_t q);
int btblecontroller_queue_send(btblecontroller_QueueHandle_t q, void *msg, uint32_t timeout); int btblecontroller_queue_send(btblecontroller_QueueHandle_t q, void *msg, uint32_t size, uint32_t timeout);
int btblecontroller_queue_recv(btblecontroller_QueueHandle_t q, void *msg, uint32_t timeout); int btblecontroller_queue_recv(btblecontroller_QueueHandle_t q, void *msg, uint32_t timeout);
int btblecontroller_queue_send_fromisr(btblecontroller_QueueHandle_t q, void *msg); int btblecontroller_queue_send_from_isr(btblecontroller_QueueHandle_t q, void *msg, uint32_t size);
int btblecontroller_xPortIsInsideInterrupt(); int btblecontroller_xport_is_inside_interrupt();
void btblecontroller_TaskDelay(uint32_t ms); void btblecontroller_task_delay(uint32_t ms);
#endif #endif

View File

@ -22,6 +22,13 @@
**************************************************************************************** ****************************************************************************************
*/ */
#include "btblecontroller_port_uart.h" // uart definition #include "btblecontroller_port_uart.h" // uart definition
#include "bflb_uart.h"
#include "bflb_gpio.h"
#if defined(CFG_IOT_SDK)
#include "bl_irq.h"
#endif
#include <stdint.h>
#include <stdbool.h>
/* /*
* DEFINES * DEFINES
@ -214,11 +221,16 @@ __attribute__((weak)) void btble_uart_init(uint8_t uartid)
cfg.tx_fifo_threshold = 7; cfg.tx_fifo_threshold = 7;
cfg.rx_fifo_threshold = 7; cfg.rx_fifo_threshold = 7;
bflb_uart_init(btble_uart, &cfg); bflb_uart_init(btble_uart, &cfg);
#ifdef UART_GLITCH_TEST_ENABLE #ifdef UART_GLITCH_TEST_ENABLE
bflb_uart_feature_control(btble_uart, UART_CMD_SET_GLITCH_VALUE, 12); bflb_uart_feature_control(btble_uart, UART_CMD_SET_GLITCH_VALUE, 12);
#endif #endif
#if defined(CFG_IOT_SDK)
bl_irq_register_with_ctx(btble_uart->irq_num, uart_isr, NULL);
bl_irq_enable(btble_uart->irq_num);
#else
bflb_irq_attach(btble_uart->irq_num, uart_isr, NULL); bflb_irq_attach(btble_uart->irq_num, uart_isr, NULL);
bflb_irq_enable(btble_uart->irq_num); bflb_irq_enable(btble_uart->irq_num);
#endif
} }
__attribute__((weak)) int8_t btble_uart_reconfig(uint32_t baudrate, uint8_t flow_ctl_en, uint8_t cts_pin, uint8_t rts_pin) __attribute__((weak)) int8_t btble_uart_reconfig(uint32_t baudrate, uint8_t flow_ctl_en, uint8_t cts_pin, uint8_t rts_pin)

View File

@ -14,6 +14,8 @@
#ifndef _UART_H_ #ifndef _UART_H_
#define _UART_H_ #define _UART_H_
#include <stdint.h>
#include <stdbool.h>
/** /**
**************************************************************************************** ****************************************************************************************
* @defgroup UART UART * @defgroup UART UART
@ -30,8 +32,6 @@
**************************************************************************************** ****************************************************************************************
*/ */
#include "bflb_uart.h"
#include "bflb_gpio.h"
/* /*
* ENUMERATION DEFINITIONS * ENUMERATION DEFINITIONS
***************************************************************************************** *****************************************************************************************