/***************************************************************************** Function : LOS_EvbUartInit Description : enable the device on the dev baord Input : None Output : None Return : None *****************************************************************************/ void LOS_EvbUartWriteStr(const char* str) { #ifdef GD32F150R8 while (*str) { usart_data_transmit(EVAL_COM1, * str++); while (RESET == usart_flag_get(EVAL_COM1,USART_STAT_TBE)); } while(RESET == usart_flag_get(EVAL_COM1, USART_STAT_TC)){ } #endif return; }
static int gd32_putc(struct rt_serial_device *serial, char ch) { struct gd32_uart *uart; RT_ASSERT(serial != RT_NULL); uart = (struct gd32_uart *)serial->parent.user_data; usart_data_transmit(uart->uart_periph, ch); while((usart_flag_get(uart->uart_periph, USART_FLAG_TC) == RESET)); return 1; }
static int gd32_getc(struct rt_serial_device *serial) { int ch; struct gd32_uart *uart; RT_ASSERT(serial != RT_NULL); uart = (struct gd32_uart *)serial->parent.user_data; ch = -1; if (usart_flag_get(uart->uart_periph, USART_FLAG_RBNE) != RESET) ch = usart_data_receive(uart->uart_periph); return ch; }
/** Abort the ongoing RX transaction. It disables the enabled interrupt for RX and * flushes the RX hardware buffer if RX FIFO is used * * @param obj The serial object */ void serial_rx_abort_asynch(serial_t *obj) { struct serial_s *p_obj = GET_SERIAL_S(obj); /* disable interrupts */ usart_interrupt_disable(p_obj->uart, USART_INT_RBNE); usart_interrupt_disable(p_obj->uart, USART_INT_PERR); usart_interrupt_disable(p_obj->uart, USART_INT_ERR); /* clear USART_FLAG_RBNE flag */ usart_flag_clear(p_obj->uart, USART_FLAG_RBNE); /* clear errors flag by reading USART STATx register and then USART DATA register */ usart_flag_get(p_obj->uart, USART_FLAG_PERR); usart_flag_get(p_obj->uart, USART_FLAG_FERR); usart_flag_get(p_obj->uart, USART_FLAG_ORERR); USART_DATA(p_obj->uart); /* reset rx transfer count */ p_obj->rx_count = 0; /* reset rx state */ p_obj->rx_state = OP_STATE_READY; }
/** * Uart common interrupt process. This need add to uart ISR. * * @param serial serial device */ static void uart_isr(struct rt_serial_device *serial) { struct gd32_uart *uart = (struct gd32_uart *) serial->parent.user_data; RT_ASSERT(uart != RT_NULL); /* UART in mode Receiver */ if ((usart_interrupt_flag_get(uart->uart_periph, USART_INT_FLAG_RBNE) != RESET) && (usart_flag_get(uart->uart_periph, USART_FLAG_RBNE) != RESET)) { rt_hw_serial_isr(serial, RT_SERIAL_EVENT_RX_IND); /* Clear RXNE interrupt flag */ usart_flag_clear(uart->uart_periph, USART_FLAG_RBNE); } }
/***************************************************************************** Function : LosUart1Printf Description : enable the device on the dev baord Input : None Output : None Return : None *****************************************************************************/ void LOS_EvbUart1Printf(char* fmt, ...) { int i; va_list ap; va_start(ap, fmt); vsprintf(_buffer, fmt, ap); va_end(ap); for (i = 0; _buffer[i] != '\0'; i++) { LOS_EvbUartWriteByte(_buffer[i]); } while(RESET == usart_flag_get(EVAL_COM1, USART_STAT_TC)){ } return; }
/** Check if the serial peripheral is writable * * @param obj The serial object * @return Non-zero value if a character can be written, 0 otherwise. */ int serial_writable(serial_t *obj) { struct serial_s *p_obj = GET_SERIAL_S(obj); return (usart_flag_get(p_obj->uart, USART_FLAG_TBE) != RESET) ? 1 : 0; }
/* retarget the C library printf function to the usart */ int fputc(int ch, FILE *f) { usart_data_transmit(EVAL_COM2, (uint8_t) ch); while (RESET == usart_flag_get(EVAL_COM2,USART_STAT_TC)); return ch; }
/***************************************************************************** Function : LOS_EvbUartInit Description : enable the device on the dev baord Input : None Output : None Return : None *****************************************************************************/ void LOS_EvbUartWriteByte(char c) { usart_data_transmit(EVAL_COM1, c); while (RESET == usart_flag_get(EVAL_COM1, USART_STAT_TBE)); return; }
/***************************************************************************** Function : Los_Uart1ReadByte Description : enable the device on the dev baord Input : None Output : None Return : None *****************************************************************************/ void LOS_EvbUartReadByte(char* c) { while (RESET == usart_flag_get(EVAL_COM1,USART_STAT_RBNE)); *c = (usart_data_receive(EVAL_COM1)); return; }