Skip to content

Commit

Permalink
framework/src/iotbus: add new APIs in iotbus to test new UART TCs
Browse files Browse the repository at this point in the history
- add new APIs in iotbus to test UART TCs, APIs are:
	iotbus_uart_rxavailable()
	iotbus_uart_txready()
	iotbus_uart_txempty()

- add new TCs to test UART rxavailable, txready and txempty APIs.

Signed-off-by: Deepak Sharma <[email protected]>
  • Loading branch information
deepaksrma committed Sep 7, 2021
1 parent fba2b64 commit 700a0e3
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
66 changes: 66 additions & 0 deletions framework/src/iotbus/iotbus_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,72 @@ int iotbus_uart_set_flowcontrol(iotbus_uart_context_h hnd, int xonxoff, int rtsc
}
#endif

int iotbus_uart_rxavailable(iotbus_uart_context_h hnd)
{
int ret;
int fd;
struct _iotbus_uart_s *handle;

if (!hnd || !hnd->handle) {
return IOTBUS_ERROR_INVALID_PARAMETER;
}

handle = (struct _iotbus_uart_s *)hnd->handle;
fd = handle->fd;

ret = ioctl(fd, TIOCS_AVAIL, 0);
if (ret != true) {
ibdbg("ioctl failed: receive fifo is empty\n");
return IOTBUS_ERROR_UNKNOWN;
}

return IOTBUS_ERROR_NONE;
}

int iotbus_uart_txready(iotbus_uart_context_h hnd)
{
int ret;
int fd;
struct _iotbus_uart_s *handle;

if (!hnd || !hnd->handle) {
return IOTBUS_ERROR_INVALID_PARAMETER;
}

handle = (struct _iotbus_uart_s *)hnd->handle;
fd = handle->fd;

ret = ioctl(fd, TIOCS_READY, 0);
if (ret != true) {
ibdbg("ioctl failed: transmit fifo is full\n");
return IOTBUS_ERROR_UNKNOWN;
}

return IOTBUS_ERROR_NONE;
}

int iotbus_uart_txempty(iotbus_uart_context_h hnd)
{
int ret;
int fd;
struct _iotbus_uart_s *handle;

if (!hnd || !hnd->handle) {
return IOTBUS_ERROR_INVALID_PARAMETER;
}

handle = (struct _iotbus_uart_s *)hnd->handle;
fd = handle->fd;

ret = ioctl(fd, TIOCS_EMPTY, 0);
if (ret != true) {
ibdbg("ioctl failed: transmit fifo is not empty\n");
return IOTBUS_ERROR_UNKNOWN;
}

return IOTBUS_ERROR_NONE;
}

int iotbus_uart_read(iotbus_uart_context_h hnd, char *buf, unsigned int length)
{
int fd;
Expand Down
27 changes: 27 additions & 0 deletions os/arch/arm/src/amebad/amebad_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@
*/

static serial_t* sdrv[MAX_UART_INDEX + 1] = {NULL, NULL, NULL, NULL, NULL}; //uart 0~3, uart2 is configured as log uart
static bool g_tc_rxavailable;
static bool g_tc_rxavailable_res; // used to hold the result of rxavailable TC

struct rtl8721d_up_dev_s {
uint8_t parity; /* 0=none, 1=odd, 2=even */
Expand Down Expand Up @@ -571,6 +573,22 @@ static int rtl8721d_up_ioctl(FAR struct uart_dev_s *dev, int cmd, unsigned long
serial_control_loopback(sdrv[uart_index_get(priv->tx)], *(bool *)arg);
break;

case TIOCS_AVAIL:
g_tc_rxavailable = 1;
g_tc_rxavailable_res = 0;
rtl8721d_up_send(dev, 'a');
sleep(1);
ret = g_tc_rxavailable_res;
break;

case TIOCS_READY:
ret = rtl8721d_up_txready(dev);
break;

case TIOCS_EMPTY:
ret = rtl8721d_up_txempty(dev);
break;

default:
ret = -ENOTTY;
break;
Expand Down Expand Up @@ -628,8 +646,17 @@ static void rtl8721d_up_rxint(struct uart_dev_s *dev, bool enable)

static bool rtl8721d_up_rxavailable(struct uart_dev_s *dev)
{
bool ret = 0;
struct rtl8721d_up_dev_s *priv = (struct rtl8721d_up_dev_s *)dev->priv;
DEBUGASSERT(priv);
if (g_tc_rxavailable) {
ret = (serial_readable(sdrv[uart_index_get(priv->tx)]));
if (!g_tc_rxavailable_res) {
g_tc_rxavailable_res = ret;
g_tc_rxavailable = 0;
}
return ret;
}
return (serial_readable(sdrv[uart_index_get(priv->tx)]));
}

Expand Down

0 comments on commit 700a0e3

Please sign in to comment.