source codes

master
oniku_taro 3 years ago
parent 146ffbcee0
commit 98a12dd920
  1. 34
      system573_lib/ksys573_sio.c
  2. 45
      system573_lib/ksys573_sio.h

@ -1,41 +1,10 @@
/*
* SIO communication library for PSXSDK.
* Originally written by Shendo.
* 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 "ksys573_sio.h"
#include <stdio.h>
#include "ksys573_psx_gpu.h"
void SIOStart(int bitrate)
{
/*Set to 8N1 mode with desired bitrate*/
SIOStartEx(bitrate, SIO_DATA_LEN_8, SIO_PARITY_NONE, SIO_STOP_BIT_1);
}
void SIOStartEx(int bitrate, int datalength, int parity, int stopbit)
{
/*Set SIO_MODE register, bitrate reload factor set to MUL16 by default*/
SIO_MODE = SIO_REL_MUL16 | (datalength << 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 SIOStop()
{
/*Set all SIO related registers to zero*/
SIO_MODE = 0;
SIO_CTRL = 0;
SIO_BPSV = 0;
@ -79,19 +48,16 @@ int SIOSendByte_wait_txen(unsigned char data,int timeout)
int SIOCheckInBuffer()
{
/*Return status of RX FIFO*/
return (SIO_STAT & 0x2)>0;
}
int SIOCheckOutBuffer()
{
/*Return status of TX Ready flag*/
return (SIO_STAT & 0x4)>0;
}
void SIOStart_Ksys573()
{
/*Set all SIO related registers to zero*/
SIO_MODE = 0x004e;
SIO_CTRL = 0x0c37;
SIO_BPSV = 0x0012;

@ -65,55 +65,12 @@ enum sio_parity
#define SIO_BPSV *((volatile unsigned short*)0x1F80105E)
/**
* Initialize SIO communication at the specified bitrate (baud rate).
* Mode is 8N1. (Data Length = 8 bit, No parity, Stop bit Length = 1 bit)
* @param bitrate Bitrate (baud rate)
*/
void SIOStart(int bitrate);
/**
* Same as SIOStart() but with more control.
* IMPORTANT: Must use defined macros.
* For example setting datalength to 5 should be done with "SIO_DATA_LEN_5"
* and not by simply passing 5 as an argument.
*
* @param bitrate Bit rate (baud rate)
* @param datalength Character (data) length
* @param parity Parity
* @param stopbit Stop bit length
*/
void SIOStartEx(int bitrate, int datalength, int parity, int stopbit);
/**
* Shuts down SIO communication.
*/
void SIOStop(void);
/**
* Read a single byte from the input buffer.
* @return Data byte from input buffer
*/
unsigned char SIOReadByte(void);
/**
* Send a single byte to the output buffer.
* @param data Byte to send
*/
unsigned char SIOReadByte(void);
void SIOSendByte(unsigned char data);
/**
* Check if any data is waiting in the input buffer.
* Must be used when fetching data otherwise incorrect data could be read (usually 0x00).
* @return Non-zero if there is data waiting in the input buffer, zero otherwise.
*/
int SIOCheckInBuffer(void);
/**
* Check if port is ready to send data (previous operation finished).
* Must be used when sending data as the output buffer is only 2 bytes long.
* @return Non-zero if port is ready to send data, zero otherwise.
*/
int SIOCheckOutBuffer(void);
unsigned short SIOSTATUS(void);
void SIOtest(void);

Loading…
Cancel
Save