From aca84864981f9de17914a673bf1e5bb01a267c78 Mon Sep 17 00:00:00 2001 From: songyanguang <345810377@qq.com> Date: Wed, 9 Apr 2025 10:03:30 +0800 Subject: [PATCH] Modify uart --- .../XiZi_IIoT/arch/risc-v/ch569w/interrupt.c | 4 +-- Ubiquitous/XiZi_IIoT/board/ch569w/board.c | 2 +- .../third_party_driver/uart/connect_uart.c | 32 ++++--------------- 3 files changed, 10 insertions(+), 28 deletions(-) diff --git a/Ubiquitous/XiZi_IIoT/arch/risc-v/ch569w/interrupt.c b/Ubiquitous/XiZi_IIoT/arch/risc-v/ch569w/interrupt.c index dee4c75ab..0614e0281 100644 --- a/Ubiquitous/XiZi_IIoT/arch/risc-v/ch569w/interrupt.c +++ b/Ubiquitous/XiZi_IIoT/arch/risc-v/ch569w/interrupt.c @@ -26,12 +26,12 @@ extern x_ubase interrupt_new_task; void sw_setpend(void) { - PFIC_SetPendingIRQ(SWI_IRQn); + SysTick->CNTFG |= (1 << 0); } void sw_clearpend(void) { - PFIC_ClearPendingIRQ(SWI_IRQn); + SysTick->CNTFG &= ~(1 << 0); } x_base DisableLocalInterrupt() diff --git a/Ubiquitous/XiZi_IIoT/board/ch569w/board.c b/Ubiquitous/XiZi_IIoT/board/ch569w/board.c index b850acd38..03c951fa6 100644 --- a/Ubiquitous/XiZi_IIoT/board/ch569w/board.c +++ b/Ubiquitous/XiZi_IIoT/board/ch569w/board.c @@ -33,7 +33,7 @@ void InitBoardHardware() SystemInit(FREQ_SYS); Delay_Init(FREQ_SYS); - SysTick_Config(FREQ_SYS / 8 / TICK_PER_SECOND); + SysTick_Config(FREQ_SYS / TICK_PER_SECOND); PFIC_EnableIRQ(SWI_IRQn); /* initialize memory system */ diff --git a/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/uart/connect_uart.c b/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/uart/connect_uart.c index 28481d047..0d1c73dec 100644 --- a/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/uart/connect_uart.c +++ b/Ubiquitous/XiZi_IIoT/board/ch569w/third_party_driver/uart/connect_uart.c @@ -98,16 +98,14 @@ static uint32 SerialInit(struct SerialDriver *serial_drv, struct BusConfigureInf // config serial receive sem timeout dev_param->serial_timeout = serial_cfg->data_cfg.serial_timeout; - -#if 1 + // config serial reg struct uart_registers *uxreg = (struct uart_registers *)serial_cfg->hw_cfg.serial_register_base; - union _uart_fcr fcr; union _uart_lcr lcr; uint32_t x; uint32_t t = FREQ_SYS; -// x = 10 * sys_hclk_get() / 8 / serial_cfg->data_cfg.serial_baud_rate; + // x = 10 * sys_hclk_get() / 8 / serial_cfg->data_cfg.serial_baud_rate; x = 10 * t / 8 / serial_cfg->data_cfg.serial_baud_rate; x = (x + 5) / 10; uxreg->DL = x; @@ -166,8 +164,6 @@ static uint32 SerialInit(struct SerialDriver *serial_drv, struct BusConfigureInf /* TXD pin output enable */ uxreg->IER.txd_en = 1; -#endif - return EOK; } @@ -236,15 +232,12 @@ static int SerialPutChar(struct SerialHardwareDevice *serial_dev, char ch) { static int SerialGetChar(struct SerialHardwareDevice *serial_dev) { int ch = -1; struct SerialCfgParam *serial_cfg = (struct SerialCfgParam *)serial_dev->private_data; + volatile struct uart_registers *uxreg = (struct uart_registers *)serial_cfg->hw_cfg.serial_register_base; - if ( (UART1_GetLinSTA() & RB_LSR_DATA_RDY) == RB_LSR_DATA_RDY) { - ch = UART1_RecvByte(); + if (1 == uxreg->LSR.data_rdy) { + /* UART_II_RECV_RDY is cleared by reading RBR */ + ch = (uxreg->RFC > 0) ? uxreg->RBR : -1; } -#if 0 - if (RESET != USART_GetFlagStatus((USART_TypeDef *)serial_cfg->hw_cfg.serial_register_base, USART_FLAG_RXNE)) { - ch = USART_ReceiveData((USART_TypeDef *)serial_cfg->hw_cfg.serial_register_base) & 0xff; - } -#endif return ch; } @@ -326,9 +319,7 @@ struct SerialHardwareDevice serial_device_1; void UART1_IRQHandler(void) __attribute__((interrupt())); void UART1_IRQHandler(void) { -#if 1 GET_INT_SP(); - //isr_sp_enter(); x_base level; level = DisableLocalInterrupt(); isrManager.done->incCounter(); @@ -338,8 +329,6 @@ void UART1_IRQHandler(void) { isrManager.done->decCounter(); EnableLocalInterrupt(level); FREE_INT_SP(); - //isr_sp_leave(); -#endif } #endif @@ -386,18 +375,11 @@ int InitHwUart(void) { return ERROR; } - /* Configure the serial port */ GPIOA_SetBits(GPIO_Pin_8); GPIOA_ModeCfg(GPIO_Pin_7, GPIO_ModeIN_PU_NSMT); // RXD-pull-up input GPIOA_ModeCfg(GPIO_Pin_8, GPIO_Slowascent_PP_8mA); // TXD-push-pull output -// UART1_DefInit(); -/* - //Interrupt method - UART1_ByteTrigCfg( UART_1BYTE_TRIG ); - UART1_INTCfg( ENABLE, RB_IER_RECV_RDY|RB_IER_LINE_STAT ); - PFIC_EnableIRQ( UART1_IRQn ); -*/ + UART1_DefInit(); #endif return ret;