KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
sci.h File Reference

Serial Communication Interface functionality. More...

#include <sys/cdefs.h>
#include <arch/types.h>
#include <arch/dmac.h>
#include <stdint.h>
#include <stdbool.h>

Go to the source code of this file.

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.
 

Detailed Description

Serial Communication Interface functionality.

This file provides access to the Dreamcast/Naomi SCI module, which can operate in both UART and SPI modes.

Author
Ruslan Rostovtsev