KallistiOS  ##version##
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
Functions | Variables
scif.h File Reference

Serial port functionality. More...

#include <sys/cdefs.h>
#include <arch/types.h>
#include <kos/dbgio.h>

Go to the source code of this file.

Functions

void scif_set_parameters (int baud, int fifo)
 Set serial parameters. More...
 
int scif_set_irq_usage (int on)
 Enable or disable SCIF IRQ usage. More...
 
int scif_detected ()
 Is the SCIF port detected? Of course it is! More...
 
int scif_init ()
 Initialize the SCIF port. More...
 
int scif_shutdown ()
 Shutdown the SCIF port. More...
 
int scif_read ()
 Read a single character from the SCIF port. More...
 
int scif_write (int c)
 Write a single character to the SCIF port. More...
 
int scif_flush ()
 Flush any FIFO'd bytes out of the buffer. More...
 
int scif_write_buffer (const uint8 *data, int len, int xlat)
 Write a whole buffer of data to the SCIF port. More...
 
int scif_read_buffer (uint8 *data, int len)
 Read a buffer of data from the SCIF port. More...
 
int scif_spi_init (void)
 Initialize the SCIF port for use of an SPI peripheral. More...
 
int scif_spi_shutdown (void)
 Shut down SPI card support over the SCIF port. More...
 
void scif_spi_set_cs (int v)
 Set or clear the SPI /CS line. More...
 
uint8 scif_spi_rw_byte (uint8 b)
 Read and write one byte from the SPI port. More...
 
uint8 scif_spi_slow_rw_byte (uint8 b)
 Read and write one byte from the SPI device, slowly. More...
 
void scif_spi_write_byte (uint8 b)
 Write a byte to the SPI device. More...
 
uint8 scif_spi_read_byte (void)
 Read a byte from the SPI device. More...
 

Variables

dbgio_handler_t dbgio_scif
 SCIF debug I/O handler. Do not modify! More...
 

Detailed Description

Serial port functionality.

This file deals with raw access to the serial port on the Dreamcast.

Author
Dan Potter
Lawrence Sebald

Function Documentation

int scif_detected ( )

Is the SCIF port detected? Of course it is!

Returns
1
int scif_flush ( )

Flush any FIFO'd bytes out of the buffer.

This function sends any bytes that have been queued up for transmission but have not left yet in FIFO mode.

Return values
0On success.
-1If the SCIF port is disabled (errno set to EIO).
int scif_init ( )

Initialize the SCIF port.

This function initializes the SCIF port to a sane state. If dcload-serial is in use, this is effectively a no-op.

Return values
0On success (no error conditions defined).
int scif_read ( )

Read a single character from the SCIF port.

Returns
The character read if one is available, otherwise -1 and errno is set to EAGAIN.
int scif_read_buffer ( uint8 data,
int  len 
)

Read a buffer of data from the SCIF port.

This function reads a whole buffer of data from the SCIF port, blocking until it has been filled.

Parameters
dataThe buffer to read into.
lenThe number of bytes to read.
Returns
The number of bytes read on success, -1 on error.
int scif_set_irq_usage ( int  on)

Enable or disable SCIF IRQ usage.

Parameters
on1 to enable IRQ usage, 0 for polled I/O.
Return values
0On success (no error conditions defined).
void scif_set_parameters ( int  baud,
int  fifo 
)

Set serial parameters.

Parameters
baudThe bitrate to set.
fifo1 to enable FIFO mode.
int scif_shutdown ( )

Shutdown the SCIF port.

This function disables SCIF IRQs, if they were enabled and cleans up.

Return values
0On success (no error conditions defined).
int scif_spi_init ( void  )

Initialize the SCIF port for use of an SPI peripheral.

This function initializes the SCIF port for accessing the an SPI peripheral that has been connected to the serial port. The design of the SCIF->SPI wiring follows the wiring of the SD card adapter which is (at least now) somewhat commonly available online and is the same as the one designed by jj1odm.

Return values
0On success.
-1On error (if dcload-serial is detected).
uint8 scif_spi_read_byte ( void  )

Read a byte from the SPI device.

This function reads a byte from the SPI device, one bit at a time. The timing follows that of the scif_spi_rw_byte() function.

Returns
The byte returned from the card.
uint8 scif_spi_rw_byte ( uint8  b)

Read and write one byte from the SPI port.

This function writes one byte and reads one back from the SPI device simultaneously.

Parameters
bThe byte to write out to the port.
Returns
The byte returned from the card.
void scif_spi_set_cs ( int  v)

Set or clear the SPI /CS line.

This function sets or clears the /CS line (connected to the RTS line of the SCIF port).

Parameters
vNon-zero to output 1 on the line, zero to output 0.
int scif_spi_shutdown ( void  )

Shut down SPI card support over the SCIF port.

This function shuts down SPI support on the SCIF port. If you want to get regular usage of the port back, you must call scif_init() after shutting down SPI support.

Return values
0On success (no errors defined).
uint8 scif_spi_slow_rw_byte ( uint8  b)

Read and write one byte from the SPI device, slowly.

This function does the same thing as the scif_sd_rw_byte() function, but with a 1.5usec delay between asserting the CLK line and reading back the bit and a 1.5usec delay between clearing the CLK line and writing the next bit out.

This ends up working out to a clock of about 333khz, or so.

Parameters
bThe byte to write out to the port.
Returns
The byte returned from the card.
void scif_spi_write_byte ( uint8  b)

Write a byte to the SPI device.

This function writes out the specified byte to the SPI device, one bit at a time. The timing follows that of the scif_spi_rw_byte() function.

Parameters
bThe byte to write out to the port.
int scif_write ( int  c)

Write a single character to the SCIF port.

Parameters
cThe character to write (only the low 8-bits are written).
Return values
1On success.
-1If the SCIF port is disabled (errno set to EIO).
int scif_write_buffer ( const uint8 data,
int  len,
int  xlat 
)

Write a whole buffer of data to the SCIF port.

This function writes a whole buffer of data to the SCIF port, optionally making all newlines into carriage return + newline pairs.

Parameters
dataThe buffer to write.
lenThe length of the buffer, in bytes.
xlatIf set to 1, all newlines will be written as CRLF.
Returns
The number of bytes written on success, -1 on error.

Variable Documentation

dbgio_handler_t dbgio_scif

SCIF debug I/O handler. Do not modify!