@@ -32,9 +32,6 @@ typedef struct {
32
32
static port_config_t config = {0 , 0 , 0 , 0 };
33
33
34
34
#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)
38
35
39
36
static inline void sio_set_ctrl_m (uint16_t mask , uint16_t ctrl ) {
40
37
* R_PS1_SIO1_CTRL = ((* R_PS1_SIO1_CTRL ) & mask ) | ctrl ;
@@ -79,7 +76,7 @@ static inline uint16_t sio_get_ctrl(void) {
79
76
80
77
static inline uint16_t sio_get_mode (void ) { return * R_PS1_SIO1_MODE & 0x1FFF ; }
81
78
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 ); }
83
80
84
81
void sio_reset (void ) { * R_PS1_SIO1_CTRL = SIO_CTRL_RESET_INT | SIO_CTRL_RESET_ERR ; }
85
82
@@ -99,7 +96,7 @@ int sio_peek8(uint32_t timeout) {
99
96
100
97
// this may not be necessary. Some UARTs won't transfer if yout don't though.
101
98
102
- // assert RTR(Ready To Receive akia "RTS"/Request to Send)
99
+ // RTR(Ready To Receive akia "RTS"/Request to Send): on
103
100
sio_set_ctrl_m (~(SIO_CTRL_RTR_EN ), SIO_CTRL_RTR_EN );
104
101
105
102
// wait for data in the RX FIFO
@@ -118,7 +115,7 @@ int sio_peek8(uint32_t timeout) {
118
115
ret = * R_PS1_SIO1_DATA ;
119
116
120
117
_done :
121
- // deassert RTR
118
+ // RTR/RTS: off
122
119
sio_set_ctrl_m (~(SIO_CTRL_RTR_EN ), 0 );
123
120
124
121
return ret ;
@@ -141,7 +138,6 @@ uint32_t sio_peek32(uint32_t timeout) {
141
138
}
142
139
143
140
// FIXME: add sio_poke16 and 32
144
-
145
141
int sio_poke8 (uint8_t data , uint32_t timeout ) {
146
142
volatile uint8_t d ;
147
143
@@ -183,6 +179,33 @@ int sio_poke8(uint8_t data, uint32_t timeout) {
183
179
return data ;
184
180
}
185
181
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
+
186
209
void init_sio (uint32_t baud ) {
187
210
/* 8bit, no-parity, 1 stop-bit */
188
211
sio_put_mode (SIO_MODE_CHLEN_8 | SIO_MODE_P_NONE | SIO_MODE_SB_1 );
0 commit comments