/* ** A wrapper function performing Baud Rate settings. */ static void UartBaudRateSet(void) { unsigned int divisorValue = 0; /* Computing the Divisor Value. */ divisorValue = UARTDivisorValCompute(UART_MODULE_INPUT_CLK, BAUD_RATE_115200, UART16x_OPER_MODE, UART_MIR_OVERSAMPLING_RATE_42); /* Programming the Divisor Latches. */ UARTDivisorLatchWrite(SOC_UART_0_REGS, divisorValue); }
/* Configure polling IO on default UART */ void bwio_uart_setup(void) { /* Set pin mux */ UARTPinMuxSetup(0); /* Reset the UART */ UARTModuleReset(BWIO_UART); /* Set the BAUD rate */ unsigned int divisorValue = 0; /* Computing the Divisor Value. */ divisorValue = UARTDivisorValCompute(UART_MODULE_INPUT_CLK, BAUD_RATE_115200, UART16x_OPER_MODE, UART_MIR_OVERSAMPLING_RATE_42); /* Programming the Divisor Latches. */ UARTDivisorLatchWrite(BWIO_UART, divisorValue); /* Switching to Configuration Mode B. */ UARTRegConfigModeEnable(BWIO_UART, UART_REG_CONFIG_MODE_B); /* Programming the Line Characteristics. */ UARTLineCharacConfig(BWIO_UART, (UART_FRAME_WORD_LENGTH_8 | UART_FRAME_NUM_STB_1), UART_PARITY_NONE); /* Disabling write access to Divisor Latches. */ UARTDivisorLatchDisable(BWIO_UART); /* Disabling Break Control. */ UARTBreakCtl(BWIO_UART, UART_BREAK_COND_DISABLE); /* Switching to UART16x operating mode. */ UARTOperatingModeSelect(BWIO_UART, UART16x_OPER_MODE); }
/* ** The main function */ int main() { unsigned int divisorValue = 0; /* Configuring the system clocks for UART0 instance. */ UART0ModuleClkConfig(); /* Initializing the ARM Interrupt Controller. */ IntAINTCInit(); /* Performing the Pin Multiplexing for UART0 instance. */ UARTPinMuxSetup(0); /* Performing a module reset. */ UARTModuleReset(UART_INST_BASE); UARTFIFOConfig(UART_INST_BASE, UART_FIFO_CONFIG(UART_TRIG_LVL_GRANULARITY_1, UART_TRIG_LVL_GRANULARITY_1, 1, 1, 1, 1, UART_DMA_EN_PATH_SCR, UART_DMA_MODE_0_ENABLE)); /* Computing the Divisor Value. */ divisorValue = UARTDivisorValCompute(UART_MODULE_INPUT_CLK, BAUD_RATE_115200, UART16x_OPER_MODE, UART_MIR_OVERSAMPLING_RATE_42); /* Programming the Divisor Latches. */ UARTDivisorLatchWrite(UART_INST_BASE, divisorValue); /* Switching to Configuration Mode B. */ UARTRegConfigModeEnable(UART_INST_BASE, UART_REG_CONFIG_MODE_B); /* Programming the Line Characteristics. */ UARTLineCharacConfig(UART_INST_BASE, (UART_FRAME_WORD_LENGTH_8 | UART_FRAME_NUM_STB_1), UART_PARITY_NONE); /* Disabe write access to Divisor Latches. */ UARTDivisorLatchDisable(UART_INST_BASE); /* Disable Break Control. */ UARTBreakCtl(UART_INST_BASE, UART_BREAK_COND_DISABLE); /* Switch to UART16x operating mode. */ UARTOperatingModeSelect(UART_INST_BASE, UART16x_OPER_MODE); UARTIntEnable(UART_INST_BASE, (UART_INT_LINE_STAT | UART_INT_THR | UART_INT_RHR_CTI)); /* Register the Interrupt Service Routines */ IntRegister(RTC_INT_NUM, RTCIsr); IntRegister(UART_INT_NUM, UARTIsr); IntRegister(TIMER_INT_NUM, DMTimerIsr); /* ** Setting the priority for the system interrupt in AINTC. ** Timer interrupt is given highest priority - 1 ** RTC interrupt is given medium priority - 2 ** UART interrupt is given lowest priority - 4 */ IntPrioritySet(TIMER_INT_NUM, IRQ_PRIORITY_TIMER, AINTC_HOSTINT_ROUTE_IRQ); IntPrioritySet(RTC_INT_NUM, IRQ_PRIORITY_RTC, AINTC_HOSTINT_ROUTE_IRQ); IntPrioritySet(UART_INT_NUM, IRQ_PRIORITY_UART, AINTC_HOSTINT_ROUTE_IRQ); /* Enabling the system interrupt in AINTC for UART */ IntSystemEnable(UART_INT_NUM); IntMasterIRQEnable(); while(1); }