diff options
Diffstat (limited to 'bsp/tm4c129x/drivers/drv_uart.c')
| -rw-r--r-- | bsp/tm4c129x/drivers/drv_uart.c | 142 |
1 files changed, 71 insertions, 71 deletions
diff --git a/bsp/tm4c129x/drivers/drv_uart.c b/bsp/tm4c129x/drivers/drv_uart.c index 4b7ca48e6e..d1b26f3002 100644 --- a/bsp/tm4c129x/drivers/drv_uart.c +++ b/bsp/tm4c129x/drivers/drv_uart.c @@ -30,75 +30,75 @@ typedef struct hw_uart_device #define mUartGetHwPtr(serial) ((hw_uart_t*)(serial->parent.user_data)) static rt_err_t hw_configure(struct rt_serial_device *serial, struct serial_configure *cfg) -{ - uint32_t config = 0; - hw_uart_t* uart; +{ + uint32_t config = 0; + hw_uart_t* uart; RT_ASSERT(serial != RT_NULL); uart = mUartGetHwPtr(serial); - MAP_UARTDisable(uart->hw_base); - // build UART Configuration parameter structure + MAP_UARTDisable(uart->hw_base); + // build UART Configuration parameter structure switch(cfg->data_bits) - { - case DATA_BITS_9: - // enable 9bit address mode and set DATA_BIT_8 - MAP_UART9BitEnable(uart->hw_base); - case DATA_BITS_8: - config |= UART_CONFIG_WLEN_8; - break; - case DATA_BITS_7: - config |= UART_CONFIG_WLEN_7; - break; - case DATA_BITS_6: - config |= UART_CONFIG_WLEN_6; - break; - case DATA_BITS_5: - config |= UART_CONFIG_WLEN_5; - break; - default: - RT_ASSERT(0); - break; - } - switch(cfg->parity) - { - case PARITY_ODD: - config |= UART_CONFIG_PAR_ODD; - break; - case PARITY_EVEN: - config |= UART_CONFIG_PAR_EVEN; - break; - case PARITY_NONE: - config |= UART_CONFIG_PAR_NONE; - break; - default: - RT_ASSERT(0); - break; - } - switch(cfg->stop_bits) - { - case STOP_BITS_1: - config |= UART_CONFIG_STOP_ONE; - break; - case STOP_BITS_2: - config |= UART_CONFIG_STOP_TWO; - break; - default: - RT_ASSERT(0); - break; - } - - // Initialize UART0 peripheral with given to corresponding parameter + { + case DATA_BITS_9: + // enable 9bit address mode and set DATA_BIT_8 + MAP_UART9BitEnable(uart->hw_base); + case DATA_BITS_8: + config |= UART_CONFIG_WLEN_8; + break; + case DATA_BITS_7: + config |= UART_CONFIG_WLEN_7; + break; + case DATA_BITS_6: + config |= UART_CONFIG_WLEN_6; + break; + case DATA_BITS_5: + config |= UART_CONFIG_WLEN_5; + break; + default: + RT_ASSERT(0); + break; + } + switch(cfg->parity) + { + case PARITY_ODD: + config |= UART_CONFIG_PAR_ODD; + break; + case PARITY_EVEN: + config |= UART_CONFIG_PAR_EVEN; + break; + case PARITY_NONE: + config |= UART_CONFIG_PAR_NONE; + break; + default: + RT_ASSERT(0); + break; + } + switch(cfg->stop_bits) + { + case STOP_BITS_1: + config |= UART_CONFIG_STOP_ONE; + break; + case STOP_BITS_2: + config |= UART_CONFIG_STOP_TWO; + break; + default: + RT_ASSERT(0); + break; + } + + // Initialize UART0 peripheral with given to corresponding parameter MAP_UARTConfigSetExpClk(uart->hw_base, SystemCoreClock, cfg->baud_rate, config); - MAP_UARTFIFOEnable(uart->hw_base); + MAP_UARTFIFOEnable(uart->hw_base); - // Enable the UART. - MAP_UARTEnable(uart->hw_base); + // Enable the UART. + MAP_UARTEnable(uart->hw_base); return RT_EOK; } static rt_err_t hw_control(struct rt_serial_device *serial, int cmd, void *arg) { - hw_uart_t* uart; + hw_uart_t* uart; RT_ASSERT(serial != RT_NULL); uart = mUartGetHwPtr(serial); @@ -119,21 +119,21 @@ static rt_err_t hw_control(struct rt_serial_device *serial, int cmd, void *arg) static int hw_putc(struct rt_serial_device *serial, char c) { - hw_uart_t* uart; + hw_uart_t* uart; RT_ASSERT(serial != RT_NULL); uart = mUartGetHwPtr(serial); - + MAP_UARTCharPut(uart->hw_base, *((uint8_t *)&c)); return 1; } static int hw_getc(struct rt_serial_device *serial) { - hw_uart_t* uart; + hw_uart_t* uart; RT_ASSERT(serial != RT_NULL); uart = mUartGetHwPtr(serial); - - return MAP_UARTCharGetNonBlocking(uart->hw_base); + + return MAP_UARTCharGetNonBlocking(uart->hw_base); } static const struct rt_uart_ops hw_uart_ops = @@ -154,7 +154,7 @@ hw_uart_t uart0 = void UART0_IRQHandler(void) { - uint32_t intsrc; + uint32_t intsrc; hw_uart_t *uart = &uart0; /* enter interrupt */ @@ -169,7 +169,7 @@ void UART0_IRQHandler(void) MAP_UARTIntClear(uart->hw_base, intsrc); rt_hw_serial_isr(&serial0, RT_SERIAL_EVENT_RX_IND); } - + /* leave interrupt */ rt_interrupt_leave(); } @@ -187,7 +187,7 @@ int rt_hw_uart_init(void) config.stop_bits = STOP_BITS_1; config.invert = NRZ_NORMAL; config.bufsz = RT_SERIAL_RB_BUFSZ; - + #ifdef RT_USING_UART0 uart = &uart0; serial0.ops = &hw_uart_ops; @@ -196,7 +196,7 @@ int rt_hw_uart_init(void) MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); MAP_GPIOPinConfigure(GPIO_PA0_U0RX); MAP_GPIOPinConfigure(GPIO_PA1_U0TX); - + MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); @@ -204,15 +204,15 @@ int rt_hw_uart_init(void) //IntPrioritySet(INT_UART0, ((0x01 << 5) | 0x01)); /* Enable Interrupt for UART channel */ - UARTIntRegister(uart->hw_base, UART0_IRQHandler); - MAP_IntEnable(INT_UART0); - MAP_UARTEnable(uart->hw_base); + UARTIntRegister(uart->hw_base, UART0_IRQHandler); + MAP_IntEnable(INT_UART0); + MAP_UARTEnable(uart->hw_base); /* register UART0 device */ rt_hw_serial_register(&serial0, "uart0", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX, uart); #endif - return 0; + return 0; } INIT_BOARD_EXPORT(rt_hw_uart_init); |
