Skip to content

Commit

Permalink
Dev (#17)
Browse files Browse the repository at this point in the history
* Add retry

* missing UART_RETRY_MAX

* move device name setting
  • Loading branch information
Hoan Hoang authored and hnhoan committed May 17, 2017
1 parent 944624a commit 0906d17
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 31 deletions.
16 changes: 8 additions & 8 deletions ARM/Nordic/src/ble_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1172,21 +1172,21 @@ bool BleAppInit(const BLEAPP_CFG *pBleAppCfg, bool bEraseBond)
err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
APP_ERROR_CHECK(err_code);

if (pBleAppCfg->pDevName != NULL)
{
err_code = sd_ble_gap_device_name_set(&s_gap_conn_mode,
(const uint8_t *) pBleAppCfg->pDevName,
strlen(pBleAppCfg->pDevName));
APP_ERROR_CHECK(err_code);
}

if (pBleAppCfg->AppMode != BLEAPP_MODE_NOCONNECT)
{
BleAppConnectable(pBleAppCfg, bEraseBond);
}

BleAppInitUserData();

if (pBleAppCfg->pDevName != NULL)
{
err_code = sd_ble_gap_device_name_set(&s_gap_conn_mode,
(const uint8_t *) pBleAppCfg->pDevName,
strlen(pBleAppCfg->pDevName));
APP_ERROR_CHECK(err_code);
}

BleAppAdvInit(pBleAppCfg);

return true;
Expand Down
50 changes: 27 additions & 23 deletions ARM/Nordic/src/uart_nrf5x.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,33 +335,37 @@ int nRFUARTTxData(DEVINTRF *pDev, uint8_t *pData, int Datalen)
{
NRFUARTDEV *dev = (NRFUARTDEV *)pDev->pDevData;
int cnt = 0;
int rtry = pDev->MaxRetry;

uint32_t state = DisableInterrupt();

while (Datalen > 0)
while (Datalen > 0 && rtry-- > 0)
{
int l = Datalen;
uint8_t *p = CFifoPutMultiple(dev->pUartDev->hTxFifo, &l);
if (p == NULL)
break;
memcpy(p, pData, l);
Datalen -= l;
pData += l;
cnt += l;
}
EnableInterrupt(state);
uint32_t state = DisableInterrupt();

if (dev->bTxReady)
{
//if (nRFUARTWaitForTxReady(dev, 1000))
while (Datalen > 0)
{
int l = Datalen;
uint8_t *p = CFifoPutMultiple(dev->pUartDev->hTxFifo, &l);
if (p == NULL)
break;
memcpy(p, pData, l);
Datalen -= l;
pData += l;
cnt += l;
}
EnableInterrupt(state);

if (dev->bTxReady)
{
dev->pReg->EVENTS_TXDRDY = 0;
dev->bTxReady = true;
uint8_t *p = CFifoGet(dev->pUartDev->hTxFifo);
if (p)
//if (nRFUARTWaitForTxReady(dev, 1000))
{
dev->bTxReady = false;
dev->pReg->TXD = *p;
dev->pReg->EVENTS_TXDRDY = 0;
dev->bTxReady = true;
uint8_t *p = CFifoGet(dev->pUartDev->hTxFifo);
if (p)
{
dev->bTxReady = false;
dev->pReg->TXD = *p;
}
}
}
}
Expand Down Expand Up @@ -482,7 +486,7 @@ bool UARTInit(UARTDEV *pDev, const UARTCFG *pCfg)
pDev->DevIntrf.TxData = nRFUARTTxData;
pDev->DevIntrf.StopTx = nRFUARTStopTx;
pDev->DevIntrf.Busy = false;
pDev->DevIntrf.MaxRetry = 0;
pDev->DevIntrf.MaxRetry = UART_RETRY_MAX;

NRF_UART0->TASKS_STARTTX = 1;
NRF_UART0->TASKS_STARTRX = 1;
Expand Down
2 changes: 2 additions & 0 deletions include/uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ typedef enum {
#define UARTPIN_DTR_IDX 6
#define UARTPIN_RI_IDX 7

#define UART_RETRY_MAX 5

typedef struct __Uart_Dev UARTDEV;

typedef enum {
Expand Down

0 comments on commit 0906d17

Please sign in to comment.