SGDK
A free and open development kit for the Sega Mega Drive
Loading...
Searching...
No Matches
16c550

Simple 16C550 UART chip driver. More...

Collaboration diagram for 16c550:

Topics

 UartRegs
 16C550 UART registers
 UartOuts
 Output pins controlled by the MCR UART register.
 UartIns
 Input pins readed in the MSR UART register.
 mw_ctrl_pins
 Pins used to control WiFi module.

Classes

struct  UartShadow
 Structure with the shadow registers. More...

Macros

#define UART_BASE   0xA130C1
 16C550 UART base address
#define UART_CLK   24000000LU
 Clock applied to 16C550 chip. Currently using 24 MHz crystal.
#define UART_BR   1500000LU
#define UART_TX_FIFO_LEN   16
 Length of the TX FIFO in bytes.
#define UART_BUFLEN   1460
#define DivWithRounding(dividend, divisor)
 Division with one bit rounding, useful for divisor calculations.
#define UART_DLM_VAL   (DivWithRounding(UART_CLK, 16 * UART_BR)>>8)
 Value to load on the UART divisor, high byte.
#define UART_DLL_VAL   (DivWithRounding(UART_CLK, 16 * UART_BR) & 0xFF)
 Value to load on the UART divisor, low byte.
#define uart_set(reg, val)
 Sets a value in IER, FCR, LCR or MCR register.
#define uart_get(reg)
 Gets value of IER, FCR, LCR or MCR register.
#define uart_set_bits(reg, val)
 Sets bits in IER, FCR, LCR or MCR register.
#define uart_clr_bits(reg, val)
 Clears bits in IER, FCR, LCR or MCR register.
#define uart_test(reg, val)
 Test Connection with registers.

Functions

void uart_init (void)
 Initializes the driver. The baud rate is set to UART_BR, and the UART FIFOs are enabled. This function must be called before using any other API call.
bool uart_is_present (void)
 Check if uart is present.
bool uart_tx_ready ()
 Checks if UART transmit register/FIFO is ready. In FIFO mode, up to 16 characters can be loaded each time transmitter is ready.
bool uart_rx_ready ()
 Checks if UART receive register/FIFO has data available.
void uart_putc (u8 c)
 Sends a character. Please make sure there is room in the transmit register/FIFO by calling uart_rx_ready() before using this function.
u8 uart_getc ()
 Returns a received character. Please make sure data is available by calling uart_rx_ready() before using this function.
void uart_reset_fifos ()
 Reset TX and RX FIFOs.
void uart_reset (void)
void uart_start (void)
void uart_line_sync (void)
 Sends syncrhonization frame.

Variables

UartShadow sh
 Uart shadow registers. Do NOT access directly!

Detailed Description

Simple 16C550 UART chip driver.

Author
Jesus Alonso (doragasu)
Date
2016

Macro Definition Documentation

◆ DivWithRounding

#define DivWithRounding ( dividend,
divisor )
Value:
((((dividend)*2/(divisor))+1)/2)

Division with one bit rounding, useful for divisor calculations.

◆ UART_BR

#define UART_BR   1500000LU

Desired baud rate. Maximum achievable baudrate with 24 MHz crystal is 24000000/16 = 1.5 Mbps

◆ uart_clr_bits

#define uart_clr_bits ( reg,
val )
Value:
do{sh.reg &= ~(val); \
UART_##reg = sh.reg;}while(0)
UartShadow sh
Uart shadow registers. Do NOT access directly!

Clears bits in IER, FCR, LCR or MCR register.

Parameters
[in]regRegister to modify (IER, FCR, LCR or MCR).
[in]valBits set in val, will be cleared in reg register.

◆ uart_get

#define uart_get ( reg)
Value:
(sh.reg)

Gets value of IER, FCR, LCR or MCR register.

Parameters
[in]regRegister to read (IER, FCR, LCR or MCR).
Returns
The value of the requested register.

◆ uart_set

#define uart_set ( reg,
val )
Value:
do{sh.reg = (val);UART_##reg = (val);}while(0)

Sets a value in IER, FCR, LCR or MCR register.

Parameters
[in]regRegister to modify (IER, FCR, LCR or MCR).
[in]valValue to set in IER, FCR, LCR or MCR register.

◆ uart_set_bits

#define uart_set_bits ( reg,
val )
Value:
do{sh.reg |= (val); \
UART_##reg = sh.reg;}while(0)

Sets bits in IER, FCR, LCR or MCR register.

Parameters
[in]regRegister to modify (IER, FCR, LCR or MCR).
[in]valBits set in val, will be set in reg register.

◆ uart_test

#define uart_test ( reg,
val )
Value:
reg = val;

Test Connection with registers.

Parameters
[in]regRegister to modify
[in]valBits set in val, will be readed from reg register.

Function Documentation

◆ uart_getc()

u8 uart_getc ( )

Returns a received character. Please make sure data is available by calling uart_rx_ready() before using this function.

Returns
Received character.

◆ uart_line_sync()

void uart_line_sync ( void )

Sends syncrhonization frame.

This function sends a chunk of 0x55 bytes to help physical layer to synchronize. It is usually not necessary to use this function, but might help some UART chips to compute an accurate clock.

◆ uart_putc()

void uart_putc ( u8 c)

Sends a character. Please make sure there is room in the transmit register/FIFO by calling uart_rx_ready() before using this function.

Returns
Received character.

◆ uart_rx_ready()

bool uart_rx_ready ( )

Checks if UART receive register/FIFO has data available.

Returns
TRUE if at least 1 byte is available, FALSE otherwise.

◆ uart_tx_ready()

bool uart_tx_ready ( )

Checks if UART transmit register/FIFO is ready. In FIFO mode, up to 16 characters can be loaded each time transmitter is ready.

Returns
TRUE if transmitter is ready, FALSE otherwise.