Skip to content

Commit 1cf7fae

Browse files
committed
Alternative serial I/O stuff.
1 parent 41447d5 commit 1cf7fae

File tree

3 files changed

+51
-14
lines changed

3 files changed

+51
-14
lines changed

src/mips/ps1sdk/include/serialio.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ void sio_clear_error(void);
135135
void sio_reset_driver(void);
136136
void init_sio(uint32_t baud);
137137

138+
uint8_t sio_get_byte(void);
139+
void sio_put_byte(uint8_t d);
140+
138141
//~ void sio_init(int port_no, int baud);
139142

140143
//~ int sio_reset(int port_no);

src/mips/sioload/src/main.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@
2525

2626
#include "common/hardware/cop0.h"
2727

28+
// switch between implementations
29+
#if 1
30+
#define SIO_PEEK8() sio_get_byte()
31+
#define SIO_POKE8(__d) sio_put_byte(__d)
32+
#else
33+
#define SIO_PEEK8() sio_peek8(0)
34+
#define SIO_POKE8(__d) sio_poke8(__d, 0)
35+
#endif
36+
37+
#define SIO_PEEK32() (((SIO_PEEK8() | (SIO_PEEK8() << 8) | (SIO_PEEK8() << 16) | (SIO_PEEK8() << 24))
38+
2839
void sioload(void) {
2940
int i;
3041
int sync;
@@ -35,24 +46,24 @@ void sioload(void) {
3546
write_addr, n_load;
3647

3748
while (1) {
38-
sio_poke8('X', 0); // sends an X to pc
49+
SIO_POKE8('X'); // sends an X to pc
3950
}
4051

4152
do {
42-
sync = sio_peek8(10000);
53+
sync = SIO_PEEK8();
4354
} while (sync != 99);
4455

4556
for (i = 0; i < sizeof(header_buf); i++) {
46-
header_buf[i] = sio_peek8(0);
57+
header_buf[i] = SIO_PEEK8();
4758
}
4859

4960
// ignored
50-
x_addr = sio_peek32(0);
51-
write_addr = sio_peek32(0);
52-
n_load = sio_peek32(0);
61+
x_addr = SIO_PEEK32();
62+
write_addr = SIO_PEEK32();
63+
n_load = SIO_PEEK32();
5364

5465
for (i = 0; i < n_load; i++) {
55-
((uint8_t*)write_addr)[i] = sio_peek8(0);
66+
((uint8_t*)write_addr)[i] = SIO_PEEK8();
5667
}
5768

5869
// could at least send back a kiss goodbye...

src/mips/sioload/src/serialio.c

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ typedef struct {
3232
static port_config_t config = {0, 0, 0, 0};
3333

3434
#define SIO1_BAUD_DIV (2073600)
35-
// I don't understand this... PsyQ says "bps must be in the range 9600 - 2073600 and evenly divisible into 2073600"
36-
// but reversing libsio shows 2116800 being divided by baud, not 2073600??
37-
//#define SIO1_BAUD_DIV (2116800)
3835

3936
static inline void sio_set_ctrl_m(uint16_t mask, uint16_t ctrl) {
4037
*R_PS1_SIO1_CTRL = ((*R_PS1_SIO1_CTRL) & mask) | ctrl;
@@ -79,7 +76,7 @@ static inline uint16_t sio_get_ctrl(void) {
7976

8077
static inline uint16_t sio_get_mode(void) { return *R_PS1_SIO1_MODE & 0x1FFF; }
8178

82-
static inline uint16_t sio_get_baud(void) { return SIO1_BAUD_DIV / (*R_PS1_SIO1_BAUD); }
79+
static inline uint32_t sio_get_baud(void) { return SIO1_BAUD_DIV / (*R_PS1_SIO1_BAUD); }
8380

8481
void sio_reset(void) { *R_PS1_SIO1_CTRL = SIO_CTRL_RESET_INT | SIO_CTRL_RESET_ERR; }
8582

@@ -99,7 +96,7 @@ int sio_peek8(uint32_t timeout) {
9996

10097
// this may not be necessary. Some UARTs won't transfer if yout don't though.
10198

102-
// assert RTR(Ready To Receive akia "RTS"/Request to Send)
99+
// RTR(Ready To Receive akia "RTS"/Request to Send): on
103100
sio_set_ctrl_m(~(SIO_CTRL_RTR_EN), SIO_CTRL_RTR_EN);
104101

105102
// wait for data in the RX FIFO
@@ -118,7 +115,7 @@ int sio_peek8(uint32_t timeout) {
118115
ret = *R_PS1_SIO1_DATA;
119116

120117
_done:
121-
// deassert RTR
118+
// RTR/RTS: off
122119
sio_set_ctrl_m(~(SIO_CTRL_RTR_EN), 0);
123120

124121
return ret;
@@ -141,7 +138,6 @@ uint32_t sio_peek32(uint32_t timeout) {
141138
}
142139

143140
// FIXME: add sio_poke16 and 32
144-
145141
int sio_poke8(uint8_t data, uint32_t timeout) {
146142
volatile uint8_t d;
147143

@@ -183,6 +179,33 @@ int sio_poke8(uint8_t data, uint32_t timeout) {
183179
return data;
184180
}
185181

182+
uint8_t sio_get_byte(void) {
183+
uint8_t t ret;
184+
185+
// RTR(Ready To Receive akia "RTS"/Request to Send): on
186+
sio_set_ctrl_m(~(SIO_CTRL_RTR_EN), SIO_CTRL_RTR_EN);
187+
188+
// wait for data in the RX FIFO
189+
190+
while (!(sio_get_stat() & SIO_STAT_RX_RDY))
191+
;
192+
193+
// pop a byte from the RX FIFO
194+
ret = *R_PS1_SIO1_DATA;
195+
196+
_done:
197+
// RTR/RTS: off
198+
sio_set_ctrl_m(~(SIO_CTRL_RTR_EN), 0);
199+
200+
return ret;
201+
}
202+
203+
void sio_put_byte(uint8_t d) {
204+
while ((sio_get_stat() & (SR_TXU | SR_TXRDY)) != (SR_TXU | SR_TXRDY))
205+
;
206+
*R_PS1_SIO1_DATA = d;
207+
}
208+
186209
void init_sio(uint32_t baud) {
187210
/* 8bit, no-parity, 1 stop-bit */
188211
sio_put_mode(SIO_MODE_CHLEN_8 | SIO_MODE_P_NONE | SIO_MODE_SB_1);

0 commit comments

Comments
 (0)