psx.wiki

Serial Interfaces (SIO)

Registers of the two serial interfaces of the PlayStation.

Summary

The PlayStation has two serial interfaces. SIO0 at 1F801040h drives the controller ports and Memory Card slots and is hardwired to a synchronous master mode similar to SPI. SIO1 at 1F801050h drives the serial port on the back of the unit and is hardwired to asynchronous (UART) mode.1 The two units are alike but not identical, and psx-spx describes them as loosely based on the Intel 8251A USART.1

The serial port connects two PlayStations with a link cable, which Sony's libcomb supports for two-player games, and libsio uses it for standard input and output to a PC during development.2 3 The controller protocol page describes the byte exchange on SIO0.

Each unit has the following registers. The base is 1F801040h for SIO0 and 1F801050h for SIO1:1

Table 1: SIO registers
Offset Name Access Content
+0 DR R/W Data register
+4 SR R Status register
+8 MR R/W Mode register
+Ah CR R/W Control register
+Eh BR R/W Baud rate reload value

Sony's header libsio.h of Run-Time Library 4.7 defines names for the SIO1 status, control and mode bits. The bit names below are those names; SIO0 has no official names.4 1

DR - Data Register

A read returns the oldest byte of the receive FIFO in bits 0 to 7, and bits 8 to 31 preview the next three entries. A byte can be read when SR bit 1 is set. psx-spx recommends 8-bit access only, because some emulators handle 16-bit and 32-bit reads incorrectly.5

A write to bits 0 to 7 starts a transfer once TXEN is 1, CTS is on and SR bit 2 shows the transmitter ready. A write while SR bit 0 is 0 overwrites the waiting byte.5 The write also latches the current TXEN, and the transfer starts if either the current or the latched value is set. A transfer can therefore still start after TXEN is cleared, which psx-spx reports Wipeout 2097 relies on.5

The transmitter holds nearly 2 bytes. One byte is being sent, and once its start bit has gone out one more can wait in DR. A write to DR clears SR bits 0 and 2, bit 0 is set again when the transfer starts, and bit 2 is set when the last written byte has been sent.6

The receive FIFO holds 8 bytes. A byte received while the FIFO is full overwrites the last entry and sets the overrun bit, and the hardware does not drop RTS by itself.7 Sony's link cable manual describes the same controller with a 1-byte transmission buffer and an 8-byte receiving buffer, and an interrupt after 1, 2, 4 or 8 received bytes.8 9

psx-spx reports two read quirks. A 16-bit read returns two FIFO entries but removes only one, while a 32-bit read removes four. A read from the empty FIFO returns the last byte received, or zero once the copies run out.7

SR - Status Register

Table 2: SR bits
Bit libsio.h name Content
0 SR_TXRDY TX FIFO not full (1 = ready for a new byte); requires CTS
1 SR_RXRDY RX FIFO not empty (1 = data available)
2 SR_TXU TX idle (1 = all bits sent); depends on TXEN and CTS
3 SR_PERROR RX parity error (sticky)
4 SR_OE RX FIFO overrun, more than 8 bytes (SIO1 only, sticky)
5 SR_FE RX framing error, bad stop bit (SIO1 only, sticky)
6 RX input level (SIO1 only)
7 SR_DSR DSR input level (1 = on)
8 SR_CTS CTS input level (SIO1 only)
9 SR_IRQ Interrupt request (sticky)
10 Not used, always zero
11 to 31 Baud rate timer, decrementing at 33 MHz

Bit 0 is set after the start bit has been sent, and bit 2 after all bits including the stop bit.10 The same bits appear in Sony's driver status table for the link cable, with bit 9 as interrupt on, bit 8 CTS, bit 7 DSR, bit 5 frame error, bit 4 overrun, bit 3 parity error, bit 2 no sending data, bit 1 receive data readable and bit 0 send data writable.9

On SIO0 the DSR input is wired to the /ACK pin of the controller ports. Bit 7 is therefore 1 while /ACK is low, and bits 4 to 6 and 8 are always zero.10

MR - Mode Register

Table 3: MR bits
Bits libsio.h names Content
0 to 1 MR_BR_1, MR_BR_16, MR_BR_64 Baud rate reload factor: 1 = x1, 2 = x16, 3 = x64 (0 = x1 on SIO0, stop on SIO1)
2 to 3 MR_CHLEN_5 to MR_CHLEN_8 Character length: 0 = 5 bits, 1 = 6, 2 = 7, 3 = 8
4 MR_PEN Parity enable
5 MR_P_EVEN Parity type: 0 = odd, 1 = even
6 to 7 MR_SB_00 to MR_SB_11 Stop bit length (SIO1 only): 1 = 1 bit, 2 = 1.5 bits, 3 = 2 bits
8 Clock polarity (SIO0 only): 0 = high when idle, 1 = low when idle
9 to 15 Not used, always zero

Sony's communication mode table for the link cable gives the same layout but reverses bit 5, with 1 for odd parity and 0 for even. libsio.h names bit 5 MR_P_EVEN, and psx-spx gives 1 for even.9 4 11

On SIO0 the character length must be 8 bits, the clock high when idle and parity disabled, because all controllers and Memory Cards expect these settings.11 libcomb accepts only 8-bit characters without parity and uses 2 stop bits by default.12

CR - Control Register

Table 4: CR bits
Bit libsio.h name Content
0 CR_TXEN TX enable
1 CR_DTR DTR output level (1 = on)
2 CR_RXEN RX enable; on SIO1 clearing it also clears the RX FIFO
3 CR_BRK TX output level inverted during idle and stop bits (SIO1 only)
4 CR_ERRRST Write 1 to reset SR bits 3, 4, 5 and 9
5 CR_RTS RTS output level (SIO1 only)
6 CR_INTRST Write 1 to reset most registers to zero
7 Unknown (SIO1 only)
8 to 9 CR_BUFSZ_1 to CR_BUFSZ_8 RX interrupt after 1, 2, 4 or 8 bytes in the FIFO
10 CR_TXIEN TX interrupt enable
11 CR_RXIEN RX interrupt enable
12 CR_DSRIEN DSR interrupt enable (DSR high, or /ACK low on SIO0)
13 Port select (SIO0 only): 0 = port 1, 1 = port 2
14 to 15 Not used, always zero

On SIO0 the DTR output is wired to /CS. Bit 1 pulls /CS low on the port that bit 13 selects, and all other signals are shared by both ports.13 Bit 2 also works differently on SIO0: when it is 0 a byte is received only while bit 1 is set, and when it is 1 one byte is received regardless of /CS and the bit then clears itself.13

psx-spx notes that the kernel's controller driver uses only the DSR (/ACK) interrupt of SIO0.13

The interrupt is acknowledged by first clearing the interrupt controller flag (bit 8 for SIO1) and then setting CR bit 4. In the other order a new interrupt that occurs just after bit 4 is set may be missed. The interrupt returns almost at once if the enabled condition is still true when bit 4 is set.14

BR - Baud Rate Register

BR holds a 16-bit reload value for the baud rate timer. The timer is decremented on every clock cycle and reloaded when BR is written and when it reaches zero, and on reload the value is multiplied by the MR factor and divided by 2. The bit rate is therefore:15

SIO0: BitsPerSecond = 33868800 / MAX(((Reload*Factor) AND NOT 1),1)
SIO1: BitsPerSecond = 33868800 / MAX(((Reload*Factor) AND NOT 1),Factor)

Controllers and Memory Cards run at about 250 kHz, which the kernel sets with BR = 0088h: the clock is high for 44h cycles and low for 44h cycles.15 libcomb sets the link cable to a rate from 1 to 2,073,600 bps that divides 2,073,600. The default is 9600 bps.12

SIO1 Control Lines

The serial controller has two pairs of control lines, DTR/DSR and RTS/CTS. libcomb uses both pairs for synchronous read() and write().9 psx-spx reports that the transmitter sends only while CTS is on.10

Table 5: Link cable control lines
Transmission name Receiving name Receiving function
DTR DSR Unusable during communication
RTS CTS Receiving functions automatically halt when off

1F80105Ch is an internal SIO1 register that software should not access. psx-spx reports that a value written there reads back rotated by 8 bits and partly masked. SIO0 has no such register.16

References


  1. ^ a b c d psx-spx. Serial Interfaces (SIO). https://psx-spx.consoledev.net/serialinterfacessio/

  2. ^ Sony Computer Entertainment Inc. Run-Time Library Overview. Run-Time Library 4.4. January 1999. Page 14-3.

  3. ^ Sony Computer Entertainment Inc. Run-Time Library Overview. Run-Time Library 4.4. January 1999. Page 17-3.

  4. ^ a b Sony Computer Entertainment Inc. Run-Time Library Release 4.7. INCLUDE/LIBSIO.H.

  5. ^ a b c psx-spx. Serial Interfaces (SIO), DR (data register). https://psx-spx.consoledev.net/serialinterfacessio/

  6. ^ psx-spx. Serial Interfaces (SIO), DR Write Notes. https://psx-spx.consoledev.net/serialinterfacessio/

  7. ^ a b psx-spx. Serial Interfaces (SIO), DR Read Notes. https://psx-spx.consoledev.net/serialinterfacessio/

  8. ^ Sony Computer Entertainment Inc. Run-Time Library Overview. Run-Time Library 4.4. January 1999. Page 14-4.

  9. ^ a b c d Sony Computer Entertainment Inc. Run-Time Library Overview. Run-Time Library 4.4. January 1999. Page 14-6, Tables 14-4 to 14-7.

  10. ^ a b c psx-spx. Serial Interfaces (SIO), SR (status register). https://psx-spx.consoledev.net/serialinterfacessio/

  11. ^ a b psx-spx. Serial Interfaces (SIO), MR (mode register). https://psx-spx.consoledev.net/serialinterfacessio/

  12. ^ a b Sony Computer Entertainment Inc. Run-Time Library Overview. Run-Time Library 4.4. January 1999. Page 14-7, Table 14-8.

  13. ^ a b c psx-spx. Serial Interfaces (SIO), CR (control register). https://psx-spx.consoledev.net/serialinterfacessio/

  14. ^ psx-spx. Serial Interfaces (SIO), Interrupt Acknowledge Notes. https://psx-spx.consoledev.net/serialinterfacessio/

  15. ^ a b psx-spx. Serial Interfaces (SIO), BR (baud rate register). https://psx-spx.consoledev.net/serialinterfacessio/

  16. ^ psx-spx. Serial Interfaces (SIO), SIO1 unknown. https://psx-spx.consoledev.net/serialinterfacessio/

Categories: Hardware