mirror of
https://github.com/hathach/tinyusb.git
synced 2026-08-18 02:53:35 +00:00
implement board_uart_read()/write() as non-blocking for all families
This commit is contained in:
@ -205,22 +205,18 @@ int board_uart_read(uint8_t *buf, int len) {
|
||||
int board_uart_write(void const *buf, int len)
|
||||
{
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
int txsize = len;
|
||||
u16 timeout = 0xffff;
|
||||
while (txsize--)
|
||||
{
|
||||
while(usart_flag_get(PRINT_UART, USART_TDBE_FLAG) == RESET)
|
||||
{
|
||||
timeout--;
|
||||
if(timeout == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
uint8_t const *p = (uint8_t const *) buf;
|
||||
int count = 0;
|
||||
while (count < len) {
|
||||
if (usart_flag_get(PRINT_UART, USART_TDBE_FLAG) != RESET) {
|
||||
PRINT_UART->dt = (*p & 0x01FF);
|
||||
p++;
|
||||
count++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
PRINT_UART->dt = (*((uint8_t const *)buf) & 0x01FF);
|
||||
buf++;
|
||||
}
|
||||
return len;
|
||||
return count;
|
||||
#else
|
||||
(void) buf;
|
||||
(void) len;
|
||||
|
||||
@ -223,19 +223,18 @@ int board_uart_read(uint8_t *buf, int len) {
|
||||
|
||||
int board_uart_write(void const *buf, int len) {
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
int txsize = len;
|
||||
u16 timeout = 0xffff;
|
||||
while (txsize--) {
|
||||
while (usart_flag_get(PRINT_UART, USART_TDBE_FLAG) == RESET) {
|
||||
timeout--;
|
||||
if (timeout == 0) {
|
||||
return 0;
|
||||
}
|
||||
uint8_t const *p = (uint8_t const *) buf;
|
||||
int count = 0;
|
||||
while (count < len) {
|
||||
if (usart_flag_get(PRINT_UART, USART_TDBE_FLAG) != RESET) {
|
||||
PRINT_UART->dt = (*p & 0x01FF);
|
||||
p++;
|
||||
count++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
PRINT_UART->dt = (*((uint8_t const *) buf) & 0x01FF);
|
||||
buf++;
|
||||
}
|
||||
return len;
|
||||
return count;
|
||||
#else
|
||||
(void) buf;
|
||||
(void) len;
|
||||
|
||||
@ -223,19 +223,18 @@ int board_uart_read(uint8_t *buf, int len) {
|
||||
|
||||
int board_uart_write(void const *buf, int len) {
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
int txsize = len;
|
||||
u16 timeout = 0xffff;
|
||||
while (txsize--) {
|
||||
while (usart_flag_get(PRINT_UART, USART_TDBE_FLAG) == RESET) {
|
||||
timeout--;
|
||||
if (timeout == 0) {
|
||||
return 0;
|
||||
}
|
||||
uint8_t const *p = (uint8_t const *) buf;
|
||||
int count = 0;
|
||||
while (count < len) {
|
||||
if (usart_flag_get(PRINT_UART, USART_TDBE_FLAG) != RESET) {
|
||||
PRINT_UART->dt = (*p & 0x01FF);
|
||||
p++;
|
||||
count++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
PRINT_UART->dt = (*((uint8_t const *) buf) & 0x01FF);
|
||||
buf++;
|
||||
}
|
||||
return len;
|
||||
return count;
|
||||
#else
|
||||
(void) buf;
|
||||
(void) len;
|
||||
|
||||
@ -197,19 +197,18 @@ int board_uart_read(uint8_t *buf, int len) {
|
||||
// Send characters to UART. Return number of sent bytes
|
||||
int board_uart_write(void const *buf, int len) {
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
int txsize = len;
|
||||
u16 timeout = 0xffff;
|
||||
while (txsize--) {
|
||||
while (usart_flag_get(PRINT_UART, USART_TDBE_FLAG) == RESET) {
|
||||
timeout--;
|
||||
if (timeout == 0) {
|
||||
return 0;
|
||||
}
|
||||
uint8_t const *p = (uint8_t const *) buf;
|
||||
int count = 0;
|
||||
while (count < len) {
|
||||
if (usart_flag_get(PRINT_UART, USART_TDBE_FLAG) != RESET) {
|
||||
PRINT_UART->dt = (*p & 0x01FF);
|
||||
p++;
|
||||
count++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
PRINT_UART->dt = (*((uint8_t const *) buf) & 0x01FF);
|
||||
buf++;
|
||||
}
|
||||
return len;
|
||||
return count;
|
||||
#else
|
||||
(void) buf;
|
||||
(void) len;
|
||||
|
||||
@ -224,19 +224,18 @@ int board_uart_read(uint8_t *buf, int len) {
|
||||
|
||||
int board_uart_write(void const *buf, int len) {
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
int txsize = len;
|
||||
u16 timeout = 0xffff;
|
||||
while (txsize--) {
|
||||
while (usart_flag_get(PRINT_UART, USART_TDBE_FLAG) == RESET) {
|
||||
timeout--;
|
||||
if (timeout == 0) {
|
||||
return 0;
|
||||
}
|
||||
uint8_t const *p = (uint8_t const *) buf;
|
||||
int count = 0;
|
||||
while (count < len) {
|
||||
if (usart_flag_get(PRINT_UART, USART_TDBE_FLAG) != RESET) {
|
||||
PRINT_UART->dt = (*p & 0x01FF);
|
||||
p++;
|
||||
count++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
PRINT_UART->dt = (*((uint8_t const *) buf) & 0x01FF);
|
||||
buf++;
|
||||
}
|
||||
return len;
|
||||
return count;
|
||||
#else
|
||||
(void) buf;
|
||||
(void) len;
|
||||
|
||||
@ -205,19 +205,18 @@ int board_uart_read(uint8_t *buf, int len) {
|
||||
// Send characters to UART. Return number of sent bytes
|
||||
int board_uart_write(void const *buf, int len) {
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
int txsize = len;
|
||||
u16 timeout = 0xffff;
|
||||
while (txsize--) {
|
||||
while (usart_flag_get(PRINT_UART, USART_TDBE_FLAG) == RESET) {
|
||||
timeout--;
|
||||
if (timeout == 0) {
|
||||
return 0;
|
||||
}
|
||||
uint8_t const *p = (uint8_t const *) buf;
|
||||
int count = 0;
|
||||
while (count < len) {
|
||||
if (usart_flag_get(PRINT_UART, USART_TDBE_FLAG) != RESET) {
|
||||
PRINT_UART->dt = (*p & 0x01FF);
|
||||
p++;
|
||||
count++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
PRINT_UART->dt = (*((uint8_t const *) buf) & 0x01FF);
|
||||
buf++;
|
||||
}
|
||||
return len;
|
||||
return count;
|
||||
#else
|
||||
(void) buf;
|
||||
(void) len;
|
||||
|
||||
@ -250,19 +250,18 @@ int board_uart_read(uint8_t *buf, int len) {
|
||||
// Send characters to UART. Return number of sent bytes
|
||||
int board_uart_write(void const *buf, int len) {
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
int txsize = len;
|
||||
u16 timeout = 0xffff;
|
||||
while (txsize--) {
|
||||
while (usart_flag_get(PRINT_UART, USART_TDBE_FLAG) == RESET) {
|
||||
timeout--;
|
||||
if (timeout == 0) {
|
||||
return 0;
|
||||
}
|
||||
uint8_t const *p = (uint8_t const *) buf;
|
||||
int count = 0;
|
||||
while (count < len) {
|
||||
if (usart_flag_get(PRINT_UART, USART_TDBE_FLAG) != RESET) {
|
||||
PRINT_UART->dt = (*p & 0x01FF);
|
||||
p++;
|
||||
count++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
PRINT_UART->dt = (*((uint8_t const *) buf) & 0x01FF);
|
||||
buf++;
|
||||
}
|
||||
return len;
|
||||
return count;
|
||||
#else
|
||||
(void) buf;
|
||||
(void) len;
|
||||
|
||||
@ -201,19 +201,18 @@ int board_uart_read(uint8_t *buf, int len) {
|
||||
|
||||
int board_uart_write(void const *buf, int len) {
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
int txsize = len;
|
||||
uint16_t timeout = 0xffff;
|
||||
while (txsize--) {
|
||||
while (usart_flag_get(PRINT_UART, USART_TDBE_FLAG) == RESET) {
|
||||
timeout--;
|
||||
if (timeout == 0) {
|
||||
return 0;
|
||||
}
|
||||
uint8_t const *p = (uint8_t const *) buf;
|
||||
int count = 0;
|
||||
while (count < len) {
|
||||
if (usart_flag_get(PRINT_UART, USART_TDBE_FLAG) != RESET) {
|
||||
PRINT_UART->dt = (*p & 0x01FF);
|
||||
p++;
|
||||
count++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
PRINT_UART->dt = (*((uint8_t const *) buf) & 0x01FF);
|
||||
buf++;
|
||||
}
|
||||
return len;
|
||||
return count;
|
||||
#else
|
||||
(void) buf;
|
||||
(void) len;
|
||||
|
||||
@ -125,16 +125,16 @@ int board_uart_read(uint8_t* buf, int len) {
|
||||
}
|
||||
|
||||
int board_uart_write(void const* buf, int len) {
|
||||
for (int i = 0; i < len; i++) {
|
||||
const char* cbuf = buf;
|
||||
while (!UART1->STAT_b.TX_READY) {}
|
||||
if (cbuf[i] == '\n') {
|
||||
UART1->IO = '\r';
|
||||
while (!UART1->STAT_b.TX_READY) {}
|
||||
const uint8_t* p = (const uint8_t*) buf;
|
||||
int count = 0;
|
||||
while (count < len) {
|
||||
if (!UART1->STAT_b.TX_READY) {
|
||||
break;
|
||||
}
|
||||
UART1->IO = cbuf[i];
|
||||
UART1->IO = p[count];
|
||||
count++;
|
||||
}
|
||||
return len;
|
||||
return count;
|
||||
}
|
||||
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
|
||||
@ -125,16 +125,16 @@ int board_uart_read(uint8_t* buf, int len) {
|
||||
}
|
||||
|
||||
int board_uart_write(void const* buf, int len) {
|
||||
for (int i = 0; i < len; i++) {
|
||||
const char* cbuf = buf;
|
||||
while (!UART1->STAT_b.TX_READY) {}
|
||||
if (cbuf[i] == '\n') {
|
||||
UART1->IO = '\r';
|
||||
while (!UART1->STAT_b.TX_READY) {}
|
||||
const uint8_t* p = (const uint8_t*) buf;
|
||||
int count = 0;
|
||||
while (count < len) {
|
||||
if (!UART1->STAT_b.TX_READY) {
|
||||
break;
|
||||
}
|
||||
UART1->IO = cbuf[i];
|
||||
UART1->IO = p[count];
|
||||
count++;
|
||||
}
|
||||
return len;
|
||||
return count;
|
||||
}
|
||||
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
|
||||
@ -136,11 +136,9 @@ int board_uart_read(uint8_t *buf, int len)
|
||||
|
||||
int board_uart_write(void const *buf, int len)
|
||||
{
|
||||
int txsize = len;
|
||||
while ( txsize-- )
|
||||
{
|
||||
uart_write(*(uint8_t const*) buf);
|
||||
buf++;
|
||||
uint8_t const *p = (uint8_t const *) buf;
|
||||
for (int i = 0; i < len; i++) {
|
||||
uart_write(p[i]);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
@ -143,11 +143,15 @@ int board_uart_read(uint8_t *buf, int len) {
|
||||
}
|
||||
|
||||
int board_uart_write(void const *buf, int len) {
|
||||
const char *bufc = (const char *) buf;
|
||||
for (int i = 0; i < len; i++) {
|
||||
while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
|
||||
USART_SendData(USART1, *bufc++);
|
||||
uint8_t const *p = (uint8_t const *) buf;
|
||||
int count = 0;
|
||||
while (count < len) {
|
||||
if (USART_GetFlagStatus(USART1, USART_FLAG_TC) != RESET) {
|
||||
USART_SendData(USART1, p[count]);
|
||||
count++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return len;
|
||||
return count;
|
||||
}
|
||||
|
||||
@ -207,14 +207,19 @@ int board_uart_read(uint8_t *buf, int len) {
|
||||
|
||||
int board_uart_write(void const *buf, int len) {
|
||||
#ifdef UART_DEV
|
||||
const char *bufc = (const char *) buf;
|
||||
for (int i = 0; i < len; i++) {
|
||||
while (USART_GetFlagStatus(UART_DEV, USART_FLAG_TC) == RESET);
|
||||
USART_SendData(UART_DEV, *bufc++);
|
||||
uint8_t const *p = (uint8_t const *) buf;
|
||||
int count = 0;
|
||||
while (count < len) {
|
||||
if (USART_GetFlagStatus(UART_DEV, USART_FLAG_TC) != RESET) {
|
||||
USART_SendData(UART_DEV, p[count]);
|
||||
count++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
#else
|
||||
(void) buf; (void) len;
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
@ -173,12 +173,10 @@ int board_uart_read(uint8_t* buf, int len) {
|
||||
}
|
||||
|
||||
int board_uart_write(void const* buf, int len) {
|
||||
int txsize = len;
|
||||
const char* bufc = (const char*) buf;
|
||||
while (txsize--) {
|
||||
uart_write(*bufc++);
|
||||
uint8_t const *p = (uint8_t const *) buf;
|
||||
for (int i = 0; i < len; i++) {
|
||||
uart_write(p[i]);
|
||||
}
|
||||
uart_sync();
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
@ -68,12 +68,20 @@ int board_uart_read(uint8_t* buf, int len) {
|
||||
}
|
||||
|
||||
int board_uart_write(void const* buf, int len) {
|
||||
int txsize = len;
|
||||
while (txsize--) {
|
||||
sys_uart_putc(*(uint8_t const*) buf);
|
||||
buf++;
|
||||
// UART0 base = 0x01c25000, USR register at +0x7c, bit 1 = TFNF (TX FIFO not full)
|
||||
volatile uint32_t *uart_usr = (volatile uint32_t *) (0x01c25000 + 0x7c);
|
||||
volatile uint32_t *uart_thr = (volatile uint32_t *) (0x01c25000 + 0x00);
|
||||
const uint8_t *p = (const uint8_t *) buf;
|
||||
int count = 0;
|
||||
while (count < len) {
|
||||
if (*uart_usr & (1 << 1)) {
|
||||
*uart_thr = p[count];
|
||||
count++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return len;
|
||||
return count;
|
||||
}
|
||||
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
|
||||
@ -104,16 +104,18 @@ int board_uart_read(uint8_t* buf, int len)
|
||||
|
||||
int board_uart_write(void const * buf, int len)
|
||||
{
|
||||
int32_t offset = 0;
|
||||
uint8_t const* buf8 = (uint8_t const*) buf;
|
||||
for (offset = 0; offset < len; offset++)
|
||||
int count = 0;
|
||||
while (count < len)
|
||||
{
|
||||
if (!(messible_status_read() & CSR_MESSIBLE_STATUS_FULL_OFFSET))
|
||||
if (messible_status_read() & CSR_MESSIBLE_STATUS_FULL_OFFSET)
|
||||
{
|
||||
messible_in_write(buf8[offset]);
|
||||
break;
|
||||
}
|
||||
messible_in_write(buf8[count]);
|
||||
count++;
|
||||
}
|
||||
return len;
|
||||
return count;
|
||||
}
|
||||
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
|
||||
@ -221,16 +221,21 @@ int board_uart_read(uint8_t *buf, int len)
|
||||
// Send characters to UART
|
||||
int board_uart_write(void const *buf, int len)
|
||||
{
|
||||
int r = 0;
|
||||
|
||||
int count = 0;
|
||||
#ifdef BOARD_UART
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wcast-qual" // uart_writen does not have const for buffer parameter.
|
||||
r = uart_writen(BOARD_UART, (uint8_t *)((const void *)buf), len);
|
||||
#pragma GCC diagnostic pop
|
||||
uint8_t const *p = (uint8_t const *) buf;
|
||||
while (count < len) {
|
||||
if (BOARD_UART->LSR_ICR_XON2 & MASK_UART_LSR_THRE) {
|
||||
BOARD_UART->RHR_THR_DLL = p[count];
|
||||
count++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
#else
|
||||
(void) buf; (void) len;
|
||||
#endif
|
||||
|
||||
return r;
|
||||
return count;
|
||||
}
|
||||
|
||||
// Get current milliseconds
|
||||
|
||||
@ -160,12 +160,17 @@ int board_uart_read(uint8_t* buf, int len) {
|
||||
|
||||
int board_uart_write(void const* buf, int len) {
|
||||
#if defined(UART_DEV)
|
||||
int txsize = len;
|
||||
while (txsize--) {
|
||||
usart_write(UART_DEV, *(uint8_t const*)buf);
|
||||
buf++;
|
||||
uint8_t const *p = (uint8_t const *) buf;
|
||||
int count = 0;
|
||||
while (count < len) {
|
||||
if (usart_flag_get(UART_DEV, USART_FLAG_TBE) != RESET) {
|
||||
usart_data_transmit(UART_DEV, p[count]);
|
||||
count++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return len;
|
||||
return count;
|
||||
#else
|
||||
(void)buf;
|
||||
(void)len;
|
||||
|
||||
@ -125,13 +125,21 @@ int board_uart_read(uint8_t *buf, int len) {
|
||||
}
|
||||
|
||||
int board_uart_write(void const *buf, int len) {
|
||||
#ifdef UART_DEV
|
||||
const uint8_t *p = (const uint8_t *) buf;
|
||||
int count = 0;
|
||||
while (count < len) {
|
||||
if (UART_DEV->S1 & UART_S1_TDRE_MASK) {
|
||||
UART_DEV->D = p[count];
|
||||
count++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
#else
|
||||
(void) buf;
|
||||
(void) len;
|
||||
|
||||
#ifdef UART_DEV
|
||||
UART_WriteBlocking(UART_DEV, (uint8_t const*) buf, len);
|
||||
return len;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -117,28 +117,30 @@ uint32_t board_button_read(void) {
|
||||
}
|
||||
|
||||
int board_uart_read(uint8_t* buf, int len) {
|
||||
#if 0 /*
|
||||
Use this version if want the LED to blink during BOARD=board_test,
|
||||
without having to hit a key.
|
||||
*/
|
||||
if( 0U != (kLPUART_RxDataRegFullFlag & LPUART_GetStatusFlags( UART_PORT )) )
|
||||
{
|
||||
LPUART_ReadBlocking(UART_PORT, buf, len);
|
||||
return len;
|
||||
int count = 0;
|
||||
while (count < len) {
|
||||
if (UART_PORT->STAT & LPUART_STAT_RDRF_MASK) {
|
||||
buf[count] = (uint8_t) UART_PORT->DATA;
|
||||
count++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
#else /* Wait for 'len' characters to come in */
|
||||
|
||||
LPUART_ReadBlocking(UART_PORT, buf, len);
|
||||
return len;
|
||||
|
||||
#endif
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
int board_uart_write(void const* buf, int len) {
|
||||
LPUART_WriteBlocking(UART_PORT, (uint8_t const*) buf, len);
|
||||
return len;
|
||||
const uint8_t *p = (const uint8_t *) buf;
|
||||
int count = 0;
|
||||
while (count < len) {
|
||||
if (UART_PORT->STAT & LPUART_STAT_TDRE_MASK) {
|
||||
UART_PORT->DATA = p[count];
|
||||
count++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
|
||||
@ -125,14 +125,31 @@ uint32_t board_button_read(void)
|
||||
|
||||
int board_uart_read(uint8_t* buf, int len)
|
||||
{
|
||||
LPSCI_ReadBlocking(UART_PORT, buf, len);
|
||||
return len;
|
||||
int count = 0;
|
||||
while (count < len) {
|
||||
if (UART_PORT->S1 & UART0_S1_RDRF_MASK) {
|
||||
buf[count] = UART_PORT->D;
|
||||
count++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
int board_uart_write(void const * buf, int len)
|
||||
{
|
||||
LPSCI_WriteBlocking(UART_PORT, (uint8_t const*) buf, len);
|
||||
return len;
|
||||
const uint8_t *p = (const uint8_t *) buf;
|
||||
int count = 0;
|
||||
while (count < len) {
|
||||
if (UART_PORT->S1 & UART0_S1_TDRE_MASK) {
|
||||
UART_PORT->D = p[count];
|
||||
count++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
|
||||
@ -130,7 +130,17 @@ int board_uart_read(uint8_t* buf, int len)
|
||||
|
||||
int board_uart_write(void const * buf, int len)
|
||||
{
|
||||
return Chip_UART_SendBlocking(UART_PORT, buf, len);
|
||||
uint8_t const *p = (uint8_t const *) buf;
|
||||
int count = 0;
|
||||
while (count < len) {
|
||||
if (Chip_UART_GetStatus(UART_PORT) & UART_STAT_TXRDY) {
|
||||
Chip_UART_SendByte(UART_PORT, p[count]);
|
||||
count++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
|
||||
@ -128,12 +128,16 @@ int board_uart_read(uint8_t *buf, int len) {
|
||||
|
||||
int board_uart_write(void const *buf, int len) {
|
||||
uint8_t const *buf8 = (uint8_t const *) buf;
|
||||
for (int i = 0; i < len; i++) {
|
||||
while ((Chip_UART_ReadLineStatus(UART_DEV) & UART_LSR_THRE) == 0) {}
|
||||
Chip_UART_SendByte(UART_DEV, buf8[i]);
|
||||
int count = 0;
|
||||
while (count < len) {
|
||||
if (Chip_UART_ReadLineStatus(UART_DEV) & UART_LSR_THRE) {
|
||||
Chip_UART_SendByte(UART_DEV, buf8[count]);
|
||||
count++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return len;
|
||||
return count;
|
||||
}
|
||||
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
|
||||
@ -244,12 +244,16 @@ int board_uart_read(uint8_t *buf, int len) {
|
||||
|
||||
int board_uart_write(void const *buf, int len) {
|
||||
uint8_t const *buf8 = (uint8_t const *) buf;
|
||||
for ( int i = 0; i < len; i++ ) {
|
||||
while ( (Chip_UART_ReadLineStatus(UART_DEV) & UART_LSR_THRE) == 0 ) {}
|
||||
Chip_UART_SendByte(UART_DEV, buf8[i]);
|
||||
int count = 0;
|
||||
while (count < len) {
|
||||
if (Chip_UART_ReadLineStatus(UART_DEV) & UART_LSR_THRE) {
|
||||
Chip_UART_SendByte(UART_DEV, buf8[count]);
|
||||
count++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return len;
|
||||
return count;
|
||||
}
|
||||
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
|
||||
@ -228,8 +228,23 @@ int board_uart_read(uint8_t* buf, int len) {
|
||||
}
|
||||
|
||||
int board_uart_write(void const* buf, int len) {
|
||||
USART_WriteBlocking(UART_DEV, (uint8_t const*) buf, len);
|
||||
#ifdef UART_DEV
|
||||
const uint8_t *p = (const uint8_t *) buf;
|
||||
int count = 0;
|
||||
while (count < len) {
|
||||
if (UART_DEV->FIFOSTAT & USART_FIFOSTAT_TXNOTFULL_MASK) {
|
||||
UART_DEV->FIFOWR = p[count];
|
||||
count++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
#else
|
||||
(void) buf;
|
||||
(void) len;
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
|
||||
@ -177,8 +177,23 @@ int board_uart_read(uint8_t* buf, int len) {
|
||||
}
|
||||
|
||||
int board_uart_write(void const* buf, int len) {
|
||||
USART_WriteBlocking(UART_DEV, (uint8_t const*) buf, len);
|
||||
return len;
|
||||
#ifdef UART_DEV
|
||||
const uint8_t *p = (const uint8_t *) buf;
|
||||
int count = 0;
|
||||
while (count < len) {
|
||||
if (UART_DEV->FIFOSTAT & USART_FIFOSTAT_TXNOTFULL_MASK) {
|
||||
UART_DEV->FIFOWR = p[count];
|
||||
count++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
#else
|
||||
(void) buf;
|
||||
(void) len;
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
|
||||
@ -186,13 +186,17 @@ int board_uart_read(uint8_t *buf, int len) {
|
||||
}
|
||||
|
||||
int board_uart_write(void const *buf, int len) {
|
||||
int act_len = 0;
|
||||
const uint8_t *ch_ptr = (const uint8_t *) buf;
|
||||
while (act_len < len) {
|
||||
MXC_UART_WriteCharacter(ConsoleUart, *ch_ptr++);
|
||||
act_len++;
|
||||
const uint8_t *p = (const uint8_t *) buf;
|
||||
int count = 0;
|
||||
while (count < len) {
|
||||
if (MXC_UART_GetTXFIFOAvailable(ConsoleUart) > 0) {
|
||||
MXC_UART_WriteCharacterRaw(ConsoleUart, p[count]);
|
||||
count++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return len;
|
||||
return count;
|
||||
}
|
||||
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
|
||||
@ -204,8 +204,17 @@ int board_uart_read(uint8_t* buf, int len) {
|
||||
|
||||
int board_uart_write(void const* buf, int len) {
|
||||
#ifdef UART_DEV
|
||||
LPUART_WriteBlocking(UART_DEV, (uint8_t const*) buf, len);
|
||||
return len;
|
||||
const uint8_t *p = (const uint8_t *) buf;
|
||||
int count = 0;
|
||||
while (count < len) {
|
||||
if (UART_DEV->STAT & LPUART_STAT_TDRE_MASK) {
|
||||
UART_DEV->DATA = p[count];
|
||||
count++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
#else
|
||||
(void) buf; (void) len;
|
||||
return 0;
|
||||
|
||||
@ -153,14 +153,17 @@ int board_uart_read(uint8_t* buf, int len) {
|
||||
|
||||
int board_uart_write(void const* buf, int len) {
|
||||
#ifdef UART_DEV
|
||||
const char* buff = buf;
|
||||
while (len) {
|
||||
while ((UART1->CSR & UART_IT_TXIEN) == 0); //The loop is sent until it is finished
|
||||
UART1->TDR = (*buff & 0xFF);
|
||||
buff++;
|
||||
len--;
|
||||
uint8_t const *p = (uint8_t const *) buf;
|
||||
int count = 0;
|
||||
while (count < len) {
|
||||
if (UART1->CSR & UART_IT_TXIEN) {
|
||||
UART1->TDR = (p[count] & 0xFF);
|
||||
count++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return len;
|
||||
return count;
|
||||
#else
|
||||
(void) buf;
|
||||
(void) len;
|
||||
|
||||
@ -186,16 +186,18 @@ int board_uart_read(uint8_t * buf, int len)
|
||||
|
||||
int board_uart_write(void const * buf, int len)
|
||||
{
|
||||
const char * char_buf = (const char *) buf;
|
||||
|
||||
for(int i = 0; i < len; i++)
|
||||
uint8_t const *p = (uint8_t const *) buf;
|
||||
int count = 0;
|
||||
while (count < len)
|
||||
{
|
||||
// Wait until TX buffer is empty (cleared by writing buffer).
|
||||
while(!(UCA1IFG & UCTXIFG));
|
||||
UCA1TXBUF = char_buf[i];
|
||||
if (UCA1IFG & UCTXIFG) {
|
||||
UCA1TXBUF = p[count];
|
||||
count++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return len;
|
||||
return count;
|
||||
}
|
||||
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
|
||||
@ -188,11 +188,16 @@ int board_uart_read(uint8_t * buf, int len)
|
||||
int board_uart_write(void const * buf, int len)
|
||||
{
|
||||
uint8_t const *p = (uint8_t const *)buf;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
while (UART0->FR & UART_FR_TXFF) ;
|
||||
UART0->DR = *p++;
|
||||
int count = 0;
|
||||
while (count < len) {
|
||||
if (!(UART0->FR & UART_FR_TXFF)) {
|
||||
UART0->DR = p[count];
|
||||
count++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return len;
|
||||
return count;
|
||||
}
|
||||
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
|
||||
@ -113,8 +113,17 @@ int board_uart_read(uint8_t* buf, int len) {
|
||||
|
||||
int board_uart_write(void const* buf, int len) {
|
||||
#ifdef UART_DEV
|
||||
USART_WriteBlocking(UART_DEV, (uint8_t const*) buf, len);
|
||||
return len;
|
||||
const uint8_t *p = (const uint8_t *) buf;
|
||||
int count = 0;
|
||||
while (count < len) {
|
||||
if (UART_DEV->FIFOSTAT & USART_FIFOSTAT_TXNOTFULL_MASK) {
|
||||
UART_DEV->FIFOWR = p[count];
|
||||
count++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
#else
|
||||
(void) buf; (void) len;
|
||||
return 0;
|
||||
|
||||
@ -3,6 +3,8 @@ set(SAM_FAMILY samd51)
|
||||
set(JLINK_DEVICE ATSAMD51J19)
|
||||
set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/${BOARD}.ld)
|
||||
|
||||
set(MAX3421_HOST 1)
|
||||
|
||||
function(update_board TARGET)
|
||||
target_compile_definitions(${TARGET} PUBLIC
|
||||
__SAMD51J19A__
|
||||
|
||||
@ -2,6 +2,8 @@ SAM_FAMILY = samd51
|
||||
|
||||
CFLAGS += -D__SAMD51J19A__
|
||||
|
||||
MAX3421_HOST = 1
|
||||
|
||||
# All source paths should be relative to the top level.
|
||||
LD_FILE = $(BOARD_PATH)/$(BOARD).ld
|
||||
|
||||
|
||||
@ -134,11 +134,16 @@ int board_uart_read(uint8_t* buf, int len) {
|
||||
|
||||
int board_uart_write(void const* buf, int len) {
|
||||
uint8_t const* buf8 = (uint8_t const*) buf;
|
||||
for (int i = 0; i < len; i++) {
|
||||
while (!_usart_sync_is_ready_to_send(&edbg_com)) {}
|
||||
_usart_sync_write_byte(&edbg_com, buf8[i]);
|
||||
int count = 0;
|
||||
while (count < len) {
|
||||
if (_usart_sync_is_ready_to_send(&edbg_com)) {
|
||||
_usart_sync_write_byte(&edbg_com, buf8[count]);
|
||||
count++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return len;
|
||||
return count;
|
||||
}
|
||||
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
|
||||
@ -162,8 +162,17 @@ int board_uart_read(uint8_t* buf, int len) {
|
||||
|
||||
int board_uart_write(void const* buf, int len) {
|
||||
#ifdef UART_ID
|
||||
HAL_UART_Transmit(&UartHandle, (uint8_t*)(uintptr_t) buf, len, 0xffff);
|
||||
return len;
|
||||
const uint8_t *p = (const uint8_t *) buf;
|
||||
int count = 0;
|
||||
while (count < len) {
|
||||
if (UartHandle.Instance->ISR & USART_ISR_TXE) {
|
||||
UartHandle.Instance->TDR = p[count];
|
||||
count++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
#else
|
||||
(void) buf;
|
||||
(void) len;
|
||||
|
||||
@ -189,13 +189,16 @@ size_t board_get_unique_id(uint8_t id[], size_t max_len) {
|
||||
|
||||
int board_uart_write(void const* buf, int len) {
|
||||
uint8_t const* data = buf;
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
while ((UART0->FR & (1 << 5)) != 0) {} // Poll until previous data was shofted out
|
||||
UART0->DR = data[i]; // Write UART0 DATA REGISTER
|
||||
int count = 0;
|
||||
while (count < len) {
|
||||
if ((UART0->FR & (1 << 5)) == 0) { // TX FIFO not full
|
||||
UART0->DR = data[count];
|
||||
count++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return len;
|
||||
return count;
|
||||
}
|
||||
|
||||
int board_uart_read(uint8_t* buf, int len) {
|
||||
|
||||
@ -128,11 +128,25 @@ int board_uart_read(uint8_t* buf, int len) {
|
||||
|
||||
int board_uart_write(void const* buf, int len) {
|
||||
#ifdef UART_DEV
|
||||
char const* bufch = (char const*) buf;
|
||||
for(int i=0;i<len;i++) {
|
||||
XMC_UART_CH_Transmit(UART_DEV, bufch[i]);
|
||||
uint8_t const *p = (uint8_t const *) buf;
|
||||
int count = 0;
|
||||
bool fifo_enabled = (UART_DEV->TBCTR & USIC_CH_TBCTR_SIZE_Msk) != 0UL;
|
||||
while (count < len) {
|
||||
if (fifo_enabled) {
|
||||
if (XMC_USIC_CH_TXFIFO_IsFull(UART_DEV)) {
|
||||
break;
|
||||
}
|
||||
UART_DEV->IN[0U] = p[count];
|
||||
} else {
|
||||
if (XMC_USIC_CH_GetTransmitBufferStatus(UART_DEV) == XMC_USIC_CH_TBUF_STATUS_BUSY) {
|
||||
break;
|
||||
}
|
||||
XMC_UART_CH_ClearStatusFlag(UART_DEV, (uint32_t)XMC_UART_CH_STATUS_FLAG_TRANSMIT_BUFFER_INDICATION);
|
||||
UART_DEV->TBUF[0U] = p[count];
|
||||
}
|
||||
count++;
|
||||
}
|
||||
return len;
|
||||
return count;
|
||||
#else
|
||||
(void) buf;
|
||||
(void) len;
|
||||
|
||||
@ -62,11 +62,10 @@
|
||||
{
|
||||
"name": "metro_m4_express",
|
||||
"uid": "9995AD485337433231202020FF100A34",
|
||||
"build" : {
|
||||
"args": ["MAX3421_HOST=1"]
|
||||
},
|
||||
"tests": {
|
||||
"device": true, "host": false, "dual": true,
|
||||
"device": true,
|
||||
"host": false,
|
||||
"dual": true,
|
||||
"dev_attached": [{"vid_pid": "067b_2303", "serial": "0", "is_cdc": true}],
|
||||
"comment": "pl23x"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user