Skip to content
Snippets Groups Projects
Commit ee5e69a4 authored by schneider's avatar schneider
Browse files

change(ble): More reliability for ble uart

parent 15e030fc
No related branches found
No related tags found
1 merge request!446Initial MicroPython BLE support (GATTS)
...@@ -29,3 +29,16 @@ void bleValueUpdate(attEvt_t *pMsg); ...@@ -29,3 +29,16 @@ void bleValueUpdate(attEvt_t *pMsg);
void bleDiscCback(dmConnId_t connId, uint8_t status); void bleDiscCback(dmConnId_t connId, uint8_t status);
void ble_trigger_event(enum ble_event_type event); void ble_trigger_event(enum ble_event_type event);
void ble_epic_att_api_init(void); void ble_epic_att_api_init(void);
/**************************************************************************************************
Data Types
**************************************************************************************************/
/*! Application message type */
typedef union
{
wsfMsgHdr_t hdr;
dmEvt_t dm;
attsCccEvt_t ccc;
attEvt_t att;
} bleMsg_t;
...@@ -52,19 +52,6 @@ static struct epic_scan_report scan_reports[SCAN_REPORTS_NUM]; ...@@ -52,19 +52,6 @@ static struct epic_scan_report scan_reports[SCAN_REPORTS_NUM];
static int scan_reports_head; static int scan_reports_head;
static int scan_reports_tail; static int scan_reports_tail;
/**************************************************************************************************
Data Types
**************************************************************************************************/
/*! Application message type */
typedef union
{
wsfMsgHdr_t hdr;
dmEvt_t dm;
attsCccEvt_t ccc;
attEvt_t att;
} bleMsg_t;
/************************************************************************************************** /**************************************************************************************************
Configurable Parameters Configurable Parameters
**************************************************************************************************/ **************************************************************************************************/
...@@ -734,6 +721,7 @@ static void bleProcMsg(bleMsg_t *pMsg) ...@@ -734,6 +721,7 @@ static void bleProcMsg(bleMsg_t *pMsg)
case ATTS_HANDLE_VALUE_CNF: case ATTS_HANDLE_VALUE_CNF:
HidProcMsg(&pMsg->hdr); HidProcMsg(&pMsg->hdr);
UartProcMsg(pMsg);
break; break;
case ATTS_CCC_STATE_IND: case ATTS_CCC_STATE_IND:
...@@ -768,6 +756,7 @@ static void bleProcMsg(bleMsg_t *pMsg) ...@@ -768,6 +756,7 @@ static void bleProcMsg(bleMsg_t *pMsg)
connOpen->peerAddr[1], connOpen->peerAddr[0]); connOpen->peerAddr[1], connOpen->peerAddr[0]);
bleESS_ccc_update(); bleESS_ccc_update();
HidProcMsg(&pMsg->hdr); HidProcMsg(&pMsg->hdr);
UartProcMsg(pMsg);
e.hdr.event = ATT_CONNECTION_OPENED; e.hdr.param = connOpen->hdr.param; e.hdr.event = ATT_CONNECTION_OPENED; e.hdr.param = connOpen->hdr.param;
send_att_event(&e); send_att_event(&e);
break; break;
......
...@@ -126,6 +126,8 @@ static uint8_t UARTWriteCback( ...@@ -126,6 +126,8 @@ static uint8_t UARTWriteCback(
} }
static int ble_uart_lasttick = 0; static int ble_uart_lasttick = 0;
static bool done;
static bool again;
void ble_uart_flush(void) void ble_uart_flush(void)
{ {
...@@ -136,21 +138,23 @@ void ble_uart_flush(void) ...@@ -136,21 +138,23 @@ void ble_uart_flush(void)
dmConnId_t connId = AppConnIsOpen(); dmConnId_t connId = AppConnIsOpen();
if (connId != DM_CONN_ID_NONE) { if (connId != DM_CONN_ID_NONE) {
if (AttsCccEnabled(connId, UART_TX_CH_CCC_IDX)) { if (AttsCccEnabled(connId, UART_TX_CH_CCC_IDX)) {
int x = xTaskGetTickCount() - ble_uart_lasttick; done = false;
if (x < 100) { again = true;
/*
* TODO: Ugly hack if we already // TODO: Modify for no initial delay
* sent something recently. while (!done && ((xTaskGetTickCount() -
* Use ATTS_HANDLE_VALUE_CNF instead. ble_uart_lasttick) < 1000)) {
*/ if (again) {
vTaskDelay(100 - x); again = false;
AttsHandleValueNtf(
connId,
UART_TX_HDL,
ble_uart_buf_tx_fill,
ble_uart_tx_buf
);
}
vTaskDelay(5);
} }
AttsHandleValueNtf(
connId,
UART_TX_HDL,
ble_uart_buf_tx_fill,
ble_uart_tx_buf
);
ble_uart_lasttick = xTaskGetTickCount(); ble_uart_lasttick = xTaskGetTickCount();
} }
} }
...@@ -191,13 +195,18 @@ void bleuart_init(void) ...@@ -191,13 +195,18 @@ void bleuart_init(void)
AttsAddGroup(&uartCfgGroup); AttsAddGroup(&uartCfgGroup);
} }
void UartProcMsg(wsfMsgHdr_t *pMsg) void UartProcMsg(bleMsg_t *pMsg)
{ {
if (pMsg->event == ATTS_HANDLE_VALUE_CNF) { if (pMsg->hdr.event == ATTS_HANDLE_VALUE_CNF) {
if (pMsg->status == ATT_SUCCESS) { if (pMsg->att.handle == UART_TX_HDL) {
if (pMsg->hdr.status == ATT_SUCCESS) {
done = true;
} else if (pMsg->hdr.status == ATT_ERR_OVERFLOW) {
again = true;
}
} }
} }
if (pMsg->event == DM_CONN_OPEN_IND) { if (pMsg->hdr.event == DM_CONN_OPEN_IND) {
ble_uart_buf_tx_fill = 0; ble_uart_buf_tx_fill = 0;
} }
} }
#pragma once #pragma once
#include "ble_api.h"
#define UART_START_HDL 0x800 /*!< \brief Service start handle. */ #define UART_START_HDL 0x800 /*!< \brief Service start handle. */
#define UART_END_HDL (UART_MAX_HDL - 1) /*!< \brief Service end handle. */ #define UART_END_HDL (UART_MAX_HDL - 1) /*!< \brief Service end handle. */
...@@ -13,4 +15,5 @@ enum { UART_SVC_HDL = UART_START_HDL, /*!< \brief UART service declaration */ ...@@ -13,4 +15,5 @@ enum { UART_SVC_HDL = UART_START_HDL, /*!< \brief UART service declaration */
UART_MAX_HDL /*!< \brief Maximum handle. */ UART_MAX_HDL /*!< \brief Maximum handle. */
}; };
void UartProcMsg(bleMsg_t *pMsg);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment