61 #define SC16_REG_RHR 0x00 62 #define SC16_REG_THR 0x00
63 #define SC16_REG_IER 0x01
64 #define SC16_REG_FCR 0x02
65 #define SC16_REG_IIR 0x02
66 #define SC16_REG_LCR 0x03
67 #define SC16_REG_MCR 0x04
68 #define SC16_REG_LSR 0x05
69 #define SC16_REG_MSR 0x06
70 #define SC16_REG_TCR 0x06
71 #define SC16_REG_TLR 0x07
72 #define SC16_REG_TXLVL 0x08
73 #define SC16_REG_RXLVL 0x09
74 #define SC16_REG_IODIR 0x0A
75 #define SC16_REG_IOSTATE 0x0B
76 #define SC16_REG_IOINT 0x0C
77 #define SC16_REG_IOCTRL 0x0E
78 #define SC16_REG_EFCR 0x0F
83 #define SC16_REG_DLL 0x00 84 #define SC16_REG_DLH 0x01
89 #define SC16_REG_EFR 0x02 90 #define SC16_REG_XON1 0x04
91 #define SC16_REG_XON2 0x05
92 #define SC16_REG_XOFF1 0x06
93 #define SC16_REG_XOFF2 0x07
98 #define SC16_BIT_IER_CTS (1 << 7) 99 #define SC16_BIT_IER_RTS (1 << 6)
100 #define SC16_BIT_IER_XOFF (1 << 5)
101 #define SC16_BIT_IER_SLEEP (1 << 4)
102 #define SC16_BIT_IER_MODEM (1 << 3)
103 #define SC16_BIT_IER_LINE (1 << 2)
104 #define SC16_BIT_IER_TX (1 << 1)
105 #define SC16_BIT_IER_RX (1 << 0)
110 #define SC16_SHIFT_FCR_RX_TRIGGER (6) 111 #define SC16_SHIFT_FCR_TX_TRIGGER (4)
112 #define SC16_BIT_FCR_RESET_TX (1 << 2)
113 #define SC16_BIT_FCR_RESET_RX (1 << 1)
114 #define SC16_BIT_FCR_FIFO_ENABLE (1 << 0)
119 #define SC16_BIT_IIR_NONE 0x01 120 #define SC16_BIT_IIR_THR 0x02
121 #define SC16_BIT_IIR_RHR 0x04
122 #define SC16_BIT_IIR_RXE 0x06
123 #define SC16_BIT_IIR_RTO 0x0C
124 #define SC16_BIT_IIR_IO 0x30
130 #define SC16_BIT_LCR_DIVISOR_LATCH (1 << 7) 131 #define SC16_BIT_LCR_BREAK (1 << 6)
132 #define SC16_BIT_LCR_PARITY_FORCED (1 << 5)
133 #define SC16_BIT_LCR_PARITY_EVEN (1 << 4)
134 #define SC16_BIT_LCR_PARITY_ENABLE (1 << 3)
135 #define SC16_BIT_LCR_STOPS (1 << 2)
136 #define SC16_SHIFT_LCR_WORD_LENGTH (0)
141 #define SC16_BIT_MCR_CLOCK_DIVISOR (1 << 7) 142 #define SC16_BIT_MCR_IRDA (1 << 6)
143 #define SC16_BIT_MCR_XON_ANY (1 << 5)
144 #define SC16_BIT_MCR_LOOPBACK (1 << 4)
145 #define SC16_BIT_MCR_TCR_ENABLE (1 << 2)
146 #define SC16_BIT_MCR_FORCE_RTS (1 << 1)
147 #define SC16_BIT_MCR_FORCE_DTR (1 << 0)
152 #define SC16_BIT_LSR_FIFO_ERR (1 << 7) 153 #define SC16_BIT_LSR_TX_EMPTY (1 << 6)
154 #define SC16_BIT_LSR_THR_EMPTY (1 << 5)
155 #define SC16_BIT_LSR_BREAK (1 << 4)
156 #define SC16_BIT_LSR_FRAME_ERR (1 << 3)
157 #define SC16_BIT_LSR_PARITY_ERR (1 << 2)
158 #define SC16_BIT_LSR_OVERRUN (1 << 1)
159 #define SC16_BIT_LSR_RX_READY (1 << 0)
164 #define SC16_SHIFT_TCR_FIFO_RESUME (4) 165 #define SC16_SHIFT_TCR_FIFO_HALT (0)
170 #define SC16_SHIFT_TLR_RX_FIFO (4) 171 #define SC16_SHIFT_TLR_TX_FIFO (0)
176 #define SC16_BIT_EFCR_IRDA_MODE (1 << 7) 177 #define SC16_BIT_EFCR_RTS_INVERT (1 << 5)
178 #define SC16_BIT_EFCR_RTS_AUTO (1 << 4)
179 #define SC16_BIT_EFCR_TX_OFF (1 << 2)
180 #define SC16_BIT_EFCR_RX_OFF (1 << 1)
181 #define SC16_BIT_EFCR_9BIT (1 << 0)
186 #define SC16_BIT_EFR_CTS_ON (1 << 7) 187 #define SC16_BIT_EFR_RTS_ON (1 << 6)
188 #define SC16_BIT_EFR_SPECIAL_CHAR (1 << 5)
189 #define SC16_BIT_EFR_ENHANCED_ON (1 << 4)
190 #define SC16_SHIFT_EFR_FLOW_CTRL (0)
191 #define SC16_EFR_ACCESS 0xBF
196 #define SC16_BIT_IOCTRL_SRESET (1 << 3) 197 #define SC16_BIT_IOCTRL_GPIO_ON (1 << 1)
198 #define SC16_BIT_IOCTRL_IOLATCH (1 << 0)
200 #define SC16_CHANNEL_A 0 201 #define SC16_CHANNEL_B 1
203 #define SC16_FIFO_SIZE 64 248 RS485_WORDLENGTH_8 = 0,
249 RS485_WORDLENGTH_9 = 1,
255 UART_STATUS_READY = 0,
257 UART_STATUS_BUSY_NOINT,
274 SC16_REGMACHINE_IDLE = 0,
275 SC16_REGMACHINE_START,
276 SC16_REGMACHINE_ADDRESS,
279 SC16_REGMACHINE_DONE,
292 SC16_TX_READ_LINE_STATUS,
360 uint32_t FifoRxTrigger : 4;
361 uint32_t FifoTxTrigger : 4;
362 uint32_t FifoRxWatermarkLow : 4;
363 uint32_t FifoRxWatermarkHigh : 4;
364 uint32_t RS485WordLength : 1;
365 uint32_t RS485RtsAuto : 1;
366 uint32_t RS485RtsInverse : 1;
367 uint32_t Channel : 1;
378 struct sc16_chip_state_t
384 struct dlist_t PendingRegWorks;
389 uint8_t InInterrupt : 1;
419 void UartSc16Init(
const struct uart_t *Uart);
420 void UartSc16Disable(
const struct uart_t *Uart);
421 bool UartSc16IsBusyTx(
const struct uart_t *Uart);
422 void UartSc16ResetFifo(
const struct uart_t* Uart,
bool Tx,
bool Rx);
423 void UartSc16SetBaudrate(
const struct uart_t *Uart);
424 void UartSc16SetRxTimeouts(
const struct uart_t *Uart, uint32_t RxStartTimeoutUs, uint32_t RxStopTimeoutUs);
428 void UartSc16CancelTx(
const struct uart_t *Uart);
429 void UartSc16StartBasicTx(
const struct uart_t *Uart, uint8_t *DataSrc, uint16_t DataSize,
uart_tx_callback_t Callback,
void *CallbackData);
430 void UartSc16StartBasicRx(
const struct uart_t *Uart, uint8_t *DataDest, uint16_t DataSize,
uart_rx_callback_t Callback,
void *CallbackData);
431 void UartSc16StartPingPongTx(
const struct uart_t *Uart, uint8_t *PrimDataSrc, uint16_t PrimDataSize, uint8_t *AltDataSrc, uint16_t AltDataSize,
uart_tx_callback_t Callback,
void *CallbackData);
432 void UartSc16StartPingPongRx(
const struct uart_t *Uart, uint8_t *PrimDataSrc, uint16_t PrimDataSize, uint8_t *AltDataSrc, uint16_t AltDataSize,
uart_rx_callback_t Callback,
void *CallbackData);
433 void UartSc16RefreshPingPongTx(
const struct uart_t *Uart, uint8_t *DataSrc, uint16_t DataSize,
bool Stop);
434 void UartSc16RefreshPingPongRx(
const struct uart_t *Uart, uint8_t *DataDest, uint16_t DataSize,
bool Stop);
435 void UartSc16CancelRx(
const struct uart_t *Uart);
436 bool UartSc16IsBusyRx(
const struct uart_t *Uart);
438 void UartSc16SetRts(
const struct uart_t *Uart,
bool Active);
439 void UartSc16InterruptHandler(
struct work_t* Work);
588 #endif // SC16IS7XX_H #define SC16_REG_IOCTRL
SC16_REG_CONTROL.
uint32_t SpiBaudrate
SPI speed.
Abstract UART driver header.
void Sc16OutPort(const struct gpio_ext_t *GpioExt, uint8_t Address, uint16_t Data)
Synchronous function writes SC16 register asynchronously and waits for the end of the operation...
void(* uart_rx_callback_t)(const struct uart_t *Uart, void *CallbackData, enum uart_rx_status_t RxStatus)
const struct sc16_chip_t * Chip
Address of SC16 chip descriptor.
static void GpioExtInitSc16(const struct gpio_ext_t *GpioExt)
Initialize GPIO expander.
uint8_t OverflowCounter
Holds the position in FIFO of an overflow error.
#define SC16_BIT_IOCTRL_IOLATCH
Enable/disable inputs latching (keep value caused interrupt in IOState until it is read) ...
struct sc16_uart_state_t * State
Address of struct with RAM variables used by the uart driver.
const struct spi_t * Spi
Pointer to the SPI interface instance.
const struct uart_t * Uart
Pointer to the parent structure.
const struct sc16_chip_t * Chip
Pointer to SC16 chip settings.
static void GpioExtSetPullEnableSc16(const struct gpio_ext_t *GpioExt, uint16_t PullEnable)
Enable pullup/pulldown to GPIO port.
Driver for the MCU's SPI blocks.
static uint16_t GpioExtInPortSc16(const struct gpio_ext_t *GpioExt)
Read 8-bits data from GPIO port.
#define SC16_REG_IOSTATE
SC16_REG_PORT.
static void GpioExtSetPullSelectSc16(const struct gpio_ext_t *GpioExt, uint16_t PullSelect)
Select pullup or pulldown for GPIO port.
uint8_t IrqPin
HW IRQ pin number.
Abstract IO extender driver.
static void GpioExtSetLatchSc16(const struct gpio_ext_t *GpioExt, uint16_t Mask)
Enable/disable latching values on input GPIO pins after interrupt until they are read.
uint8_t TxStatus
Holds the current operative Tx status.
void(* uart_tx_callback_t)(const struct uart_t *Uart, void *CallbackData)
static void GpioExtSetDriveSc16(const struct gpio_ext_t *GpioExt, uint8_t Values[])
Set drive level for output pins.
const struct uart_api_t UartSc16Func
static void GpioExtSetInterruptsSc16(const struct gpio_ext_t *GpioExt, uint16_t Mask)
Enable/disable interrupts on input GPIO pins.
static void GpioExtOutPortSc16(const struct gpio_ext_t *GpioExt, uint16_t Data)
Write 8-bits data to GPIO port.
uint32_t Xtal
SC16 quartz frequency.
uint8_t RxStatus
Holds the current operative Rx status.
#define SC16_REG_IODIR
SC16_REG_DIRECTION.
static void GpioExtSetDirectionSc16(const struct gpio_ext_t *GpioExt, uint16_t Direction)
Set pins direction to GPIO port.
uint16_t Sc16InPort(const struct gpio_ext_t *GpioExt, uint8_t Address)
Synchronous function reads SC16 register asynchronously and waits for the end of the operation...
const struct gpio_ext_api_t GpioSc16Func
static void GpioExtDisableSc16(const struct gpio_ext_t *GpioExt)
De-initialize IO expander.
void(* uart_break_callback_t)(const struct uart_t *Uart, void *CallbackData)
#define SC16_REG_IOINT
SC16_REG_INT_MASK.
struct sc16_chip_state_t * State
SC16 variables.