|
KallistiOS git master
Independent SDK for the Sega Dreamcast
|
Driver for the Serial Communication Interface More...
Files | |
| file | sci.h |
| Serial Communication Interface functionality. | |
Macros | |
| #define | SCI_UART_BAUD_4800 4800 /* Error < 0.2%, very reliable */ |
| Preset baudrates for UART mode of SCI (internal clock) | |
| #define | SCI_UART_BAUD_9600 9600 /* Error < 0.2%, very reliable */ |
| #define | SCI_UART_BAUD_19200 19200 /* Error < 0.5%, very reliable */ |
| #define | SCI_UART_BAUD_38400 38400 /* Error < 0.8%, very reliable */ |
| #define | SCI_UART_BAUD_57600 57600 /* Error < 0.5%, very reliable */ |
| #define | SCI_UART_BAUD_76800 76800 /* Error ~1.7%, reliable */ |
| #define | SCI_UART_BAUD_115200 115200 /* Error ~3.1%, acceptable */ |
| #define | SCI_UART_BAUD_230400 230400 /* Error ~3.1%, acceptable */ |
| #define | SCI_UART_BAUD_256000 256000 /* Error ~1.7%, reliable */ |
| #define | SCI_UART_BAUD_312500 312500 /* Perfect match, error 0% */ |
| #define | SCI_UART_BAUD_390625 390625 /* Perfect match, error 0% */ |
| #define | SCI_UART_BAUD_460800 460800 /* Error ~13.0%, not recommended */ |
| #define | SCI_UART_BAUD_576000 576000 /* Error < 0.5%, very reliable */ |
| #define | SCI_UART_BAUD_781250 781250 /* Perfect match, error 0% */ |
| #define | SCI_UART_BAUD_921600 921600 /* Error ~15.2%, not recommended */ |
| #define | SCI_UART_BAUD_1562500 1562500 /* Theoretical max, n=0, BRR=0, error 0% */ |
| #define | SCI_SPI_BAUD_250K 250000 /* Perfect match, error 0% */ |
| Preset baudrates for SPI mode of SCI (internal clock) | |
| #define | SCI_SPI_BAUD_312K 312500 /* Perfect match, error 0% */ |
| #define | SCI_SPI_BAUD_500K 500000 /* Perfect match, error 0% */ |
| #define | SCI_SPI_BAUD_625K 625000 /* Perfect match, error 0% */ |
| #define | SCI_SPI_BAUD_781K 781250 /* Perfect match, error 0% */ |
| #define | SCI_SPI_BAUD_1M562K 1562500 /* Perfect match, error 0% */ |
| #define | SCI_SPI_BAUD_3M125K 3125000 /* Perfect match, error 0% */ |
| #define | SCI_SPI_BAUD_6M250K 6250000 /* Perfect match, error 0% */ |
| #define | SCI_SPI_BAUD_12M500K 12500000 /* Theoretical max, n=0, BRR=0, error 0% */ |
| #define | SCI_SPI_BAUD_INIT SCI_SPI_BAUD_312K /* Initialization baudrate for SPI */ |
| Default baudrate for SPI mode. | |
| #define | SCI_SPI_BAUD_MAX SCI_SPI_BAUD_12M500K /* Maximum baudrate for SPI */ |
Enumerations | |
| enum | sci_mode_t { SCI_MODE_NONE = -1 , SCI_MODE_UART = 0 , SCI_MODE_SPI = 1 } |
| SCI operating mode definitions. More... | |
| enum | sci_clock_t { SCI_CLK_INT = 0 , SCI_CLK_EXT = 1 } |
| Clock source options. More... | |
| enum | sci_uart_config_t { SCI_UART_8N1 = 0x00 , SCI_UART_8N2 = 0x08 , SCI_UART_8E1 = 0x10 , SCI_UART_8O1 = 0x30 , SCI_UART_7N1 = 0x40 , SCI_UART_7N2 = 0x48 , SCI_UART_7E1 = 0x50 , SCI_UART_7O1 = 0x70 } |
| UART configuration options. More... | |
| enum | sci_spi_cs_mode_t { SCI_SPI_CS_NONE = -1 , SCI_SPI_CS_GPIO = 0 , SCI_SPI_CS_RTS = 1 } |
| SPI CS pin options. More... | |
| enum | sci_result_t { SCI_OK = 0 , SCI_ERR_NOT_INITIALIZED = -1 , SCI_ERR_PARAM = -2 , SCI_ERR_TIMEOUT = -3 , SCI_ERR_OVERRUN = -4 , SCI_ERR_FRAMING = -5 , SCI_ERR_PARITY = -6 , SCI_ERR_DMA = -7 } |
| Error codes for SCI operations. More... | |
Functions | |
| sci_result_t | sci_init (uint32_t baud_rate, sci_mode_t mode, sci_clock_t clock_src) |
| Initialize the SCI port with specified parameters. | |
| void | sci_configure_uart (sci_uart_config_t config, uint8_t *scsmr1) |
| Configure UART parameters. | |
| void | sci_configure_spi (sci_spi_cs_mode_t cs, size_t buffer_size) |
| Configure SPI parameters. | |
| void | sci_shutdown () |
| Shutdown the SCI port. | |
| sci_result_t | sci_read_byte (uint8_t *data) |
| Read a single byte from the UART. | |
| sci_result_t | sci_write_byte (uint8_t data) |
| Write a single byte to the UART. | |
| sci_result_t | sci_write_data (uint8_t *data, size_t len) |
| Write multiple bytes to the UART. | |
| sci_result_t | sci_read_data (uint8_t *data, size_t len) |
| Read multiple bytes from the UART. | |
| sci_result_t | sci_dma_write_data (const uint8_t *data, size_t len, dma_callback_t callback, void *cb_data) |
| Transfer data using DMA from the UART. | |
| sci_result_t | sci_dma_read_data (uint8_t *data, size_t len, dma_callback_t callback, void *cb_data) |
| Receive data using DMA from the UART. | |
| sci_result_t | sci_dma_wait_complete (void) |
| Wait for DMA transfer to complete in both UART and SPI modes. | |
| void | sci_spi_set_cs (bool enabled) |
| Set or clear the SPI chip select line. | |
| sci_result_t | sci_spi_rw_byte (uint8_t tx_byte, uint8_t *rx_byte) |
| Read and write one byte to the SPI device simultaneously. | |
| sci_result_t | sci_spi_rw_data (const uint8_t *tx_data, uint8_t *rx_data, size_t len) |
| Read and write multiple bytes to/from the SPI device. | |
| sci_result_t | sci_spi_write_byte (uint8_t tx_byte) |
| Write one byte to the SPI device. | |
| sci_result_t | sci_spi_read_byte (uint8_t *rx_byte) |
| Read one byte from the SPI device. | |
| sci_result_t | sci_spi_write_data (const uint8_t *tx_data, size_t len) |
| Write multiple bytes to the SPI device. | |
| sci_result_t | sci_spi_read_data (uint8_t *rx_data, size_t len) |
| Read multiple bytes from the SPI device. | |
| sci_result_t | sci_spi_dma_write_data (const uint8_t *tx_data, size_t len, dma_callback_t callback, void *cb_data) |
| Write multiple bytes to the SPI device using DMA. | |
| sci_result_t | sci_spi_dma_read_data (uint8_t *rx_data, size_t len, dma_callback_t callback, void *cb_data) |
| Read multiple bytes from the SPI device using DMA. | |
Driver for the Serial Communication Interface
| #define SCI_SPI_BAUD_12M500K 12500000 /* Theoretical max, n=0, BRR=0, error 0% */ |
| #define SCI_SPI_BAUD_1M562K 1562500 /* Perfect match, error 0% */ |
| #define SCI_SPI_BAUD_250K 250000 /* Perfect match, error 0% */ |
Preset baudrates for SPI mode of SCI (internal clock)
| #define SCI_SPI_BAUD_312K 312500 /* Perfect match, error 0% */ |
| #define SCI_SPI_BAUD_3M125K 3125000 /* Perfect match, error 0% */ |
| #define SCI_SPI_BAUD_500K 500000 /* Perfect match, error 0% */ |
| #define SCI_SPI_BAUD_625K 625000 /* Perfect match, error 0% */ |
| #define SCI_SPI_BAUD_6M250K 6250000 /* Perfect match, error 0% */ |
| #define SCI_SPI_BAUD_781K 781250 /* Perfect match, error 0% */ |
| #define SCI_SPI_BAUD_INIT SCI_SPI_BAUD_312K /* Initialization baudrate for SPI */ |
Default baudrate for SPI mode.
| #define SCI_SPI_BAUD_MAX SCI_SPI_BAUD_12M500K /* Maximum baudrate for SPI */ |
| #define SCI_UART_BAUD_115200 115200 /* Error ~3.1%, acceptable */ |
| #define SCI_UART_BAUD_1562500 1562500 /* Theoretical max, n=0, BRR=0, error 0% */ |
| #define SCI_UART_BAUD_19200 19200 /* Error < 0.5%, very reliable */ |
| #define SCI_UART_BAUD_230400 230400 /* Error ~3.1%, acceptable */ |
| #define SCI_UART_BAUD_256000 256000 /* Error ~1.7%, reliable */ |
| #define SCI_UART_BAUD_312500 312500 /* Perfect match, error 0% */ |
| #define SCI_UART_BAUD_38400 38400 /* Error < 0.8%, very reliable */ |
| #define SCI_UART_BAUD_390625 390625 /* Perfect match, error 0% */ |
| #define SCI_UART_BAUD_460800 460800 /* Error ~13.0%, not recommended */ |
| #define SCI_UART_BAUD_4800 4800 /* Error < 0.2%, very reliable */ |
Preset baudrates for UART mode of SCI (internal clock)
| #define SCI_UART_BAUD_57600 57600 /* Error < 0.5%, very reliable */ |
| #define SCI_UART_BAUD_576000 576000 /* Error < 0.5%, very reliable */ |
| #define SCI_UART_BAUD_76800 76800 /* Error ~1.7%, reliable */ |
| #define SCI_UART_BAUD_781250 781250 /* Perfect match, error 0% */ |
| #define SCI_UART_BAUD_921600 921600 /* Error ~15.2%, not recommended */ |
| #define SCI_UART_BAUD_9600 9600 /* Error < 0.2%, very reliable */ |
| enum sci_clock_t |
| enum sci_mode_t |
| enum sci_result_t |
| enum sci_spi_cs_mode_t |
| enum sci_uart_config_t |
UART configuration options.
| void sci_configure_spi | ( | sci_spi_cs_mode_t | cs, |
| size_t | buffer_size ) |
Configure SPI parameters.
| cs | Chip select mode for SPI. |
| buffer_size | Size of DMA buffer to allocate, 0 for no DMA support, default is 512 bytes. |
| void sci_configure_uart | ( | sci_uart_config_t | config, |
| uint8_t * | scsmr1 ) |
Configure UART parameters.
| config | UART configuration (data bits, parity, stop bits). |
| scsmr1 | Pointer to store configuration value if needed. |
| sci_result_t sci_dma_read_data | ( | uint8_t * | data, |
| size_t | len, | ||
| dma_callback_t | callback, | ||
| void * | cb_data ) |
Receive data using DMA from the UART.
| data | Buffer to store received data. |
| len | Number of bytes to read. |
| callback | Optional callback function for completion notification. |
| cb_data | Data to pass to callback function. |
| sci_result_t sci_dma_wait_complete | ( | void | ) |
Wait for DMA transfer to complete in both UART and SPI modes.
| sci_result_t sci_dma_write_data | ( | const uint8_t * | data, |
| size_t | len, | ||
| dma_callback_t | callback, | ||
| void * | cb_data ) |
Transfer data using DMA from the UART.
| data | Buffer containing data to write. |
| len | Number of bytes to write. |
| callback | Optional callback function for completion notification. |
| cb_data | Data to pass to callback function. |
| sci_result_t sci_init | ( | uint32_t | baud_rate, |
| sci_mode_t | mode, | ||
| sci_clock_t | clock_src ) |
Initialize the SCI port with specified parameters.
| baud_rate | The baudrate to set. |
| mode | SCI_MODE_UART for UART mode, SCI_MODE_SPI for SPI mode. |
| clock_src | Clock source (internal or external). |
| sci_result_t sci_read_byte | ( | uint8_t * | data | ) |
Read a single byte from the UART.
| data | Pointer to store the read byte. |
| sci_result_t sci_read_data | ( | uint8_t * | data, |
| size_t | len ) |
Read multiple bytes from the UART.
| data | Buffer to store read data. |
| len | Number of bytes to read. |
| void sci_shutdown | ( | ) |
Shutdown the SCI port.
| sci_result_t sci_spi_dma_read_data | ( | uint8_t * | rx_data, |
| size_t | len, | ||
| dma_callback_t | callback, | ||
| void * | cb_data ) |
Read multiple bytes from the SPI device using DMA.
| rx_data | Buffer to store received data. |
| len | Number of bytes to transfer. |
| callback | Optional callback function for completion notification. |
| cb_data | Data to pass to callback function. |
| sci_result_t sci_spi_dma_write_data | ( | const uint8_t * | tx_data, |
| size_t | len, | ||
| dma_callback_t | callback, | ||
| void * | cb_data ) |
Write multiple bytes to the SPI device using DMA.
| tx_data | Buffer containing data to write. |
| len | Number of bytes to transfer. |
| callback | Optional callback function for completion notification. |
| cb_data | Data to pass to callback function. |
| sci_result_t sci_spi_read_byte | ( | uint8_t * | rx_byte | ) |
Read one byte from the SPI device.
| rx_byte | Pointer to store the received byte. |
| sci_result_t sci_spi_read_data | ( | uint8_t * | rx_data, |
| size_t | len ) |
Read multiple bytes from the SPI device.
| rx_data | Buffer to store received data. |
| len | Number of bytes to transfer. |
| sci_result_t sci_spi_rw_byte | ( | uint8_t | tx_byte, |
| uint8_t * | rx_byte ) |
Read and write one byte to the SPI device simultaneously.
| tx_byte | The byte to write out to the device. |
| rx_byte | Pointer to store the received byte. |
| sci_result_t sci_spi_rw_data | ( | const uint8_t * | tx_data, |
| uint8_t * | rx_data, | ||
| size_t | len ) |
Read and write multiple bytes to/from the SPI device.
| tx_data | Buffer containing data to write. |
| rx_data | Buffer to store received data. |
| len | Number of bytes to transfer. |
| void sci_spi_set_cs | ( | bool | enabled | ) |
Set or clear the SPI chip select line.
| enabled | true to assert CS (active low), false to deassert. |
| sci_result_t sci_spi_write_byte | ( | uint8_t | tx_byte | ) |
Write one byte to the SPI device.
| tx_byte | The byte to write out to the device. |
| sci_result_t sci_spi_write_data | ( | const uint8_t * | tx_data, |
| size_t | len ) |
Write multiple bytes to the SPI device.
| tx_data | Buffer containing data to write. |
| len | Number of bytes to transfer. |
| sci_result_t sci_write_byte | ( | uint8_t | data | ) |
Write a single byte to the UART.
| data | The byte to write. |
| sci_result_t sci_write_data | ( | uint8_t * | data, |
| size_t | len ) |
Write multiple bytes to the UART.
| data | Buffer containing data to write. |
| len | Number of bytes to write. |