Hi,
我现在正在学习ch573的透传代码(BLE_UART),准备将他们移植到CH579上使用,但是遇到了以下一些疑问,帮忙解答下。
1.UART_TO_BLE_SEND_EVT这个事件中是将手机发送给蓝牙的数据又通过蓝牙发送给手机了吗?因为我有看到ble_uart_WriteAttrCB中似乎是将接收到的数据处理后直接BLE_UART_EVT_BLE_DATA_RECIEVED事件。
uint16 Peripheral_ProcessEvent( uint8 task_id, uint16 events ) { ; ; ; //这个地方在处理什么? if(events & UART_TO_BLE_SEND_EVT) { static uint16_t read_length=0;; uint8_t result=0xff; switch(send_to_ble_state){ case SEND_TO_BLE_TO_SEND: //notify is not enabled,判断当前连接notify是否打开。 if(!ble_uart_notify_is_ready(peripheralConnList.connHandle)){ if(peripheralConnList.connHandle == GAP_CONNHANDLE_INIT){//如果当前连接丢失,则刷新(初始化)rx fifo //connection lost, flush rx fifo here app_drv_fifo_flush(&app_uart_rx_fifo); } break; } read_length = ATT_GetMTU(peripheralConnList.connHandle)-3;//获取MTU大小 //app_drv_fifo_length指RX结束帧减去帧头获取数据长度 if(app_drv_fifo_length(&app_uart_rx_fifo)>= read_length){ PRINT("FIFO_LEN:%d\r\n",app_drv_fifo_length(&app_uart_rx_fifo)); //计算数据长度,再将app_uart_rx_fifo数据传递给to_test_buffer,并将状态转换为APP_DRV_FIFO_RESULT_SUCCESS。 result = app_drv_fifo_read(&app_uart_rx_fifo,to_test_buffer,&read_length); uart_to_ble_send_evt_cnt = 0; }else{ if(uart_to_ble_send_evt_cnt>10){//数据处理中止条件 result = app_drv_fifo_read(&app_uart_rx_fifo,to_test_buffer,&read_length); uart_to_ble_send_evt_cnt =0; }else{//再次启动UART_TO_BLE_SEND_EVT事件,此时状态为APP_DRV_FIFO_RESULT_SUCCESS。 tmos_start_task( Peripheral_TaskID, UART_TO_BLE_SEND_EVT,4); uart_to_ble_send_evt_cnt ++; PRINT("NO TIME OUT\r\n"); } } if(APP_DRV_FIFO_RESULT_SUCCESS == result){ noti.len = read_length; noti.pValue = GATT_bm_alloc( peripheralConnList.connHandle, ATT_HANDLE_VALUE_NOTI, noti.len, NULL, 0 ); if(noti.pValue != NULL){ tmos_memcpy( noti.pValue, to_test_buffer, noti.len );//将notify数据copy出来 result = ble_uart_notify( peripheralConnList.connHandle, ¬i,0 );//发起通知 //判断notif发送是否成功。 if( result != SUCCESS ) { PRINT("R1:%02x\r\n",result); send_to_ble_state = SEND_TO_BLE_SEND_FAILED; GATT_bm_free( (gattMsg_t *)¬i, ATT_HANDLE_VALUE_NOTI );//释放GATT消息 tmos_start_task( Peripheral_TaskID, UART_TO_BLE_SEND_EVT,2); }else{ send_to_ble_state = SEND_TO_BLE_TO_SEND; //app_fifo_write(&app_uart_tx_fifo,to_test_buffer,&read_length); //app_drv_fifo_write(&app_uart_tx_fifo,to_test_buffer,&read_length); read_length = 0; tmos_start_task( Peripheral_TaskID, UART_TO_BLE_SEND_EVT,2); } }else{ send_to_ble_state = SEND_TO_BLE_ALLOC_FAILED; tmos_start_task( Peripheral_TaskID, UART_TO_BLE_SEND_EVT,2); } }else{ //send_to_ble_state = SEND_TO_BLE_FIFO_EMPTY; } break; ; ; ; return 0; } static bStatus_t ble_uart_WriteAttrCB( uint16 connHandle, gattAttribute_t *pAttr, uint8 *pValue, uint16 len, uint16 offset,uint8 method ) { ; ; ; // UUID if(pAttr->handle == ble_uart_ProfileAttrTbl[RAWPASS_RX_VALUE_HANDLE].handle) { if(ble_uart_AppCBs) { ble_uart_evt_t evt; evt.type = BLE_UART_EVT_BLE_DATA_RECIEVED; evt.data.length = (uint16_t)len; evt.data.p_data = pValue; ble_uart_AppCBs(connHandle,&evt); } } ; ; ; return ( status ); }
2.能简要说明下在app_drv_fifo.h里这几个函数功能吗?确定下是否和我理解的功能意思是否一样,或者后期能加上注释最好了。
app_drv_fifo_result_t app_drv_fifo_write(app_drv_fifo_t *fifo, uint8_t *data, uint16_t *p_write_length); app_drv_fifo_result_t app_drv_fifo_write_from_same_addr(app_drv_fifo_t *fifo, uint8_t *data, uint16_t write_length); app_drv_fifo_result_t app_drv_fifo_read(app_drv_fifo_t *fifo, uint8_t *data, uint16_t *p_read_length); app_drv_fifo_result_t app_drv_fifo_read_to_same_addr(app_drv_fifo_t *fifo, uint8_t *data, uint16_t read_length);
3.你们的BLE上相关外设API有PDF文档吗?在哪里获取?
热门产品 :
CH397: 高集成度、低功耗USB网卡芯片