static void sc16is752_uarts_open(uid_type uid, uint32_t baudrate, uint32_t format)
{
uint8_t DLL_value;
vuart_map_t *vuart = get_uart(uid);
uint8_t channel = uid % 2;
NVIC_DisableIRQ(EINT1_IRQn);
#if BSP_EINT2_EN == 1
NVIC_DisableIRQ(EINT2_IRQn);
#endif
//Most common baud rates values
//divisor = 1.8432MHz / (baud rate * 16 * prescaler), prescaler = 1
spi_wr_sc16is752(SC16IS752_LCR, 0x80, channel, vuart); /* 0x80 to program baud-rate */
switch (baudrate)
{
case 1200: DLL_value = 0x60; break;
case 1800: DLL_value = 0x40; break;
case 2400: DLL_value = 0x30; break;
case 3600: DLL_value = 0x20; break;
case 4800: DLL_value = 0x18; break;
case 7200: DLL_value = 0x10; break;
case 9600: DLL_value = 0x0C; break;
case 19200: DLL_value = 0x06; break;
case 38400: DLL_value = 0x03; break;
case 115200: DLL_value = 0x01; break;
default: /* default baud rate is 9600 */
DLL_value = 0x0C;
}
spi_wr_sc16is752(SC16IS752_DLL, DLL_value, channel, vuart);
spi_wr_sc16is752(SC16IS752_DLH, 0x0, channel, vuart);
spi_wr_sc16is752(SC16IS752_LCR, 0xBF, channel, vuart); /* 0xBF to access EFR register */
spi_wr_sc16is752(SC16IS752_EFR, 0x10, channel, vuart); /* Enable enhanced registers */
// spi_wr_sc16is752(SC16IS752_MCR, 0x04, channel, vuart); /* Enable TLR register writing */
// spi_wr_sc16is752(SC16IS752_TLR, 0x20, channel, vuart); /* setting it to 0 uses the FCR levels */
// spi_wr_sc16is752(SC16IS752_MCR, 0x00, channel, vuart); /* Disable TLR register writing */
/* set UART data communication format */
spi_wr_sc16is752(SC16IS752_LCR, format, channel, vuart);
spi_wr_sc16is752(SC16IS752_EFCR, 0x30, channel, vuart); /* inverted, RS485 RTS dir control */
spi_wr_sc16is752(SC16IS752_IER, SC16IS752_IER_RHRI|SC16IS752_IER_RLSI, channel, vuart); /* enable reception interrupt */
/* Clears the contents of the receive and transmit FIFO, set trigger levels */
spi_wr_sc16is752(SC16IS752_FCR, SC16IS752_FCR_FIFO_FLSH, channel, vuart);
spi_wr_sc16is752(SC16IS752_FCR, SC16IS752_FCR_FIFO_CONF, channel, vuart);
/* Enable FIFO mode */
// spi_wr_sc16is752(SC16IS752_FCR, SC16IS752_FCR_FIFO_EN, channel, vuart);
NVIC_EnableIRQ(EINT1_IRQn);
#if BSP_EINT2_EN == 1
NVIC_EnableIRQ(EINT2_IRQn);
#endif
}
|