-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsio.c
63 lines (52 loc) · 1.34 KB
/
sio.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* SIO communication library for PSXSDK.
* Shendo 2013/07/28.
* Thanks to Martin Korth of the NO$PSX for documentation.
*
* This library is accessing SIO registers directly, no BIOS routines are used.
*/
#include <psx.h>
#include <stdio.h>
#include "include/psxsio.h"
void StartSIO(int bitrate)
{
/*Set to 8N1 mode with desired bitrate*/
StartSIOEx(bitrate, SIO_DATA_LEN_8, SIO_PARITY_NONE, SIO_STOP_BIT_1);
}
void StartSIOEx(int bitrate, int datalenght, int parity, int stopbit)
{
/*Set SIO_MODE register, bitrate reload factor set to MUL16 by default*/
*SIO_MODE = SIO_REL_MUL16 | (datalenght << 2) | (parity << 4) | (stopbit << 6);
/*Reset SIO_CTRL register.*/
*SIO_CTRL = 0;
/*Set TX and RT to enabled, no handshaking signals.*/
*SIO_CTRL = 1 | (1 << 2);
/*Calculate bitrate reload value based on the given bitrate
* Reload = SystemClock (33 Mhz) / (Factor (MULI16) * bitrate)*/
*SIO_BPSV = 0x204CC00 / (16 * bitrate);
}
void StopSIO()
{
/*Set all SIO related registers to zero*/
*SIO_MODE = 0;
*SIO_CTRL = 0;
*SIO_BPSV = 0;
}
unsigned char ReadByteSIO()
{
return *(unsigned char*)SIO_TX_RX;
}
void SendByteSIO(unsigned char data)
{
*SIO_TX_RX = data;
}
int CheckSIOInBuffer()
{
/*Return status of RX FIFO*/
return (*SIO_STAT & 0x2)>>1;
}
int CheckSIOOutBuffer()
{
/*Return status of TX Ready flag*/
return (*SIO_STAT & 0x4)>>2;
}