/** * Get a full configuration of the UART. **/ static BT_ERROR uartGetConfig(BT_HANDLE hUart, BT_UART_CONFIG *pConfig) { volatile LM3Sxx_UART_REGS *pRegs = hUart->pRegs; pConfig->eMode = hUart->eMode; BT_ERROR Error = BT_ERR_NONE; BT_u32 ulInputClk = BT_LM3Sxx_GetSystemFrequency(); // Compute the baud rate. pConfig->ulBaudrate = (ulInputClk * 4) / ((64 * pRegs->IBRD) + pRegs->FBRD); pConfig->ulTxBufferSize = BT_FifoSize(hUart->hTxFifo); pConfig->ulRxBufferSize = BT_FifoSize(hUart->hRxFifo); pConfig->ucDataBits = ((pRegs->LCRH >> 5) & 0x00000003) + 5; pConfig->ucStopBits = ((pRegs->LCRH >> 3) & 0x00000001) + 1; if ((pRegs->LCRH & 0x00000086) == LM3Sxx_UART_LCRH_EVEN) pConfig->ucParity = BT_UART_PARITY_EVEN; else if ((pRegs->LCRH & 0x00000086) == LM3Sxx_UART_LCRH_MARK) pConfig->ucParity = BT_UART_PARITY_MARK; else if ((pRegs->LCRH & 0x00000086) == LM3Sxx_UART_LCRH_SPACE) pConfig->ucParity = BT_UART_PARITY_SPACE; else if ((pRegs->LCRH & 0x00000086) == LM3Sxx_UART_LCRH_ODD) pConfig->ucParity = BT_UART_PARITY_ODD; else pConfig->ucParity = BT_UART_PARITY_NONE; pConfig->eMode = hUart->eMode; return Error; }
static BT_ERROR uartSetBaudrate(BT_HANDLE hUart, BT_u32 ulBaudrate) { volatile LM3Sxx_UART_REGS *pRegs = hUart->pRegs; BT_u32 ulInputClk; BT_u32 BaudRate = ulBaudrate; /* * We must determine the input clock frequency to the UART peripheral. */ ulInputClk = BT_LM3Sxx_GetSystemFrequency(); uartDisable(hUart); /* * Determine the Baud divider. It can be 4to 254. * Loop through all possible combinations */ // Is the required baud rate greater than the maximum rate supported // without the use of high speed mode? if((BaudRate * 16) > ulInputClk) { // Enable high speed mode. pRegs->CTL |= LM3Sxx_UART_CTL_HSE; // Half the supplied baud rate to compensate for enabling high speed // mode. This allows the following code to be common to both cases. BaudRate /= 2; } else { // Disable high speed mode. pRegs->CTL &= ~(LM3Sxx_UART_CTL_HSE); } // Compute the fractional baud rate divider. BT_u32 ulDiv = (((ulInputClk * 8) / BaudRate) + 1) / 2; // Set the baud rate. pRegs->IBRD = ulDiv / 64; pRegs->FBRD = ulDiv % 64; // Start the UART. uartEnable(hUart); return BT_ERR_NONE; }
static BT_u32 LM3Sxx_get_cpu_clock_frequency() { return BT_LM3Sxx_GetSystemFrequency(); }