Skip to content

Commit 0e881a7

Browse files
authored
Optimize UART data transmission. && Adjust service change notification sending conditions. (#58)
* Optimize UART data transmission. * Adjust service change notification sending conditions.
1 parent c97aae4 commit 0e881a7

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

app/fido.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ static uint16_t fido_recv_len, fido_recv_offset;
1111

1212
void fido_write_data_to_st(void* data, uint16_t len)
1313
{
14-
static uint16_t count = 0;
15-
NRF_LOG_INFO("fido_write_data_to_st %d", count++);
1614
// usr_spi_write(data, len);
1715
usr_spi_write(fido_recv_buf, fido_recv_len);
1816
}

app/main.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,11 @@ static void pm_evt_handler(const pm_evt_t* p_evt)
666666
switch ( p_evt->evt_id )
667667
{
668668

669+
case PM_EVT_BONDED_PEER_CONNECTED:
670+
NRF_LOG_INFO("%s ---> PM_EVT_BONDED_PEER_CONNECTED", __func__);
671+
request_service_changed = true;
672+
break;
673+
669674
case PM_EVT_CONN_SEC_CONFIG_REQ:
670675
NRF_LOG_INFO("%s ---> PM_EVT_CONN_SEC_CONFIG_REQ", __func__);
671676
{
@@ -729,7 +734,6 @@ static void pm_evt_handler(const pm_evt_t* p_evt)
729734
break;
730735
case PM_EVT_LOCAL_DB_CACHE_APPLY_FAILED:
731736
NRF_LOG_INFO("%s ---> PM_EVT_LOCAL_DB_CACHE_APPLY_FAILED", __func__);
732-
request_service_changed = true;
733737
break;
734738

735739
case PM_EVT_PEER_DATA_UPDATE_SUCCEEDED:
@@ -1894,20 +1898,7 @@ static uint8_t calcXor(uint8_t* buf, uint8_t len)
18941898
}
18951899
static void uart_put_data(uint8_t* pdata, uint8_t lenth)
18961900
{
1897-
uint32_t err_code;
1898-
1899-
while ( lenth-- )
1900-
{
1901-
do
1902-
{
1903-
err_code = app_uart_put(*pdata++);
1904-
if ( (err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY) )
1905-
{
1906-
APP_ERROR_CHECK(err_code);
1907-
}
1908-
}
1909-
while ( err_code == NRF_ERROR_BUSY );
1910-
}
1901+
app_uart_put_data(pdata, lenth);
19111902
}
19121903

19131904
static void send_stm_data(uint8_t* pdata, uint8_t lenth)

ble-firmware/components/libraries/uart/app_uart.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ uint32_t app_uart_flush(void);
251251
*/
252252
uint32_t app_uart_close(void);
253253

254-
254+
uint32_t app_uart_put_data(uint8_t* pdata, uint8_t lenth);
255255

256256
#ifdef __cplusplus
257257
}

ble-firmware/components/libraries/uart/app_uart_fifo.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "app_fifo.h"
4444
#include "nrf_drv_uart.h"
4545
#include "nrf_assert.h"
46+
#include "nrf_delay.h"
4647

4748
static nrf_drv_uart_t app_uart_inst = NRF_DRV_UART_INSTANCE(APP_UART_DRIVER_INSTANCE);
4849

@@ -243,6 +244,22 @@ uint32_t app_uart_put(uint8_t byte)
243244
return err_code;
244245
}
245246

247+
uint32_t app_uart_put_data(uint8_t* pdata, uint8_t lenth)
248+
{
249+
uint32_t count = 0;
250+
while (nrf_drv_uart_tx_in_progress(&app_uart_inst))
251+
{
252+
nrf_delay_ms(10);
253+
count++;
254+
}
255+
if (count > 50)
256+
{
257+
return NRF_ERROR_BUSY;
258+
}
259+
ret_code_t ret = nrf_drv_uart_tx(&app_uart_inst, pdata, lenth);
260+
return ret;
261+
}
262+
246263

247264
uint32_t app_uart_close(void)
248265
{

0 commit comments

Comments
 (0)