Nugget
Loading...
Searching...
No Matches
sio.h
Go to the documentation of this file.
1/*
2
3MIT License
4
5Copyright (c) 2020 PCSX-Redux authors
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26
27#pragma once
28
29#include <stdint.h>
30#include "common/hardware/irq.h"
31
32struct SIOPort {
33 uint8_t fifo;
34 uint8_t preview[3];
35 uint16_t stat;
36 uint16_t padding;
37 uint16_t mode;
38 uint16_t ctrl;
39 uint16_t reserved;
40 uint16_t baudRate;
41};
42
43#define SIOS ((volatile struct SIOPort *)0x1f801040)
44
45enum {
46 SIO_CTRL_TXEN = (1 << 0), // Transmit Enable
47 SIO_CTRL_DTR = (1 << 1), // Data Terminal Ready, aka Select (output)
48 SIO_CTRL_RXE = (1 << 2), // Receive Enable
49 SIO_CTRL_SBRK = (1 << 3), // Send Break character
50 SIO_CTRL_ERRRES = (1 << 4), // Error Reset
51 SIO_CTRL_RTS = (1 << 5), // Request to Send (output)
52 SIO_CTRL_IR = (1 << 6), // Internal Reset, resets most SIO registers
53 SIO_CTRL_RXIRQMODE = (1 << 8), // Receive IRQ Mode (0..3 = IRQ when RX FIFO contains 1,2,4,8 bytes)
54 SIO_CTRL_TXIRQEN = (1 << 10), // Transmit IRQ Enable
55 SIO_CTRL_RXIRQEN = (1 << 11), // Receive IRQ Enable
56 SIO_CTRL_ACKIRQEN = (1 << 12), // Acknowledge IRQ Enable
57 SIO_CTRL_PORTSEL = (1 << 13), // Port Select
58};
59
60enum {
61 SIO_STAT_TXRDY = (1 << 0), // TX buffer is empty
62 SIO_STAT_RXRDY = (1 << 1), // RX buffer has data
63 SIO_STAT_TXEMPTY = (1 << 2), // No data in TX buffer
64 SIO_STAT_PE = (1 << 3), // Parity Error
65 SIO_STAT_OE = (1 << 4), // Overrun Error
66 SIO_STAT_FE = (1 << 5), // Framing Error
67 SIO_STAT_SYNDET = (1 << 6), // Sync Detect
68 SIO_STAT_ACK = (1 << 7), // ACK signal level (input)
69 SIO_STAT_CTS = (1 << 8), // Clear to Send (output), unused on SIO0
70 SIO_STAT_IRQ = (1 << 9), // Interrupt Request
71};
72
73static inline uint8_t __attribute__((always_inline)) exchangeByte(uint8_t b) {
74 uint8_t ret = SIOS[0].fifo; // may throw away
75 SIOS[0].fifo = b;
76 SIOS[0].ctrl |= SIO_CTRL_ERRRES;
77 IREG = ~IRQ_CONTROLLER;
78 return ret;
79}
fptr __preinit_array_start[] __attribute__((weak))
Definition cxxglue.c:76
#define IREG
Definition hwregs.h:46
#define SIOS
Definition sio.h:43
@ SIO_STAT_TXEMPTY
Definition sio.h:63
@ SIO_STAT_PE
Definition sio.h:64
@ SIO_STAT_SYNDET
Definition sio.h:67
@ SIO_STAT_ACK
Definition sio.h:68
@ SIO_STAT_RXRDY
Definition sio.h:62
@ SIO_STAT_CTS
Definition sio.h:69
@ SIO_STAT_OE
Definition sio.h:65
@ SIO_STAT_TXRDY
Definition sio.h:61
@ SIO_STAT_IRQ
Definition sio.h:70
@ SIO_STAT_FE
Definition sio.h:66
@ SIO_CTRL_ACKIRQEN
Definition sio.h:56
@ SIO_CTRL_PORTSEL
Definition sio.h:57
@ SIO_CTRL_RTS
Definition sio.h:51
@ SIO_CTRL_TXIRQEN
Definition sio.h:54
@ SIO_CTRL_IR
Definition sio.h:52
@ SIO_CTRL_SBRK
Definition sio.h:49
@ SIO_CTRL_ERRRES
Definition sio.h:50
@ SIO_CTRL_RXE
Definition sio.h:48
@ SIO_CTRL_RXIRQEN
Definition sio.h:55
@ SIO_CTRL_DTR
Definition sio.h:47
@ SIO_CTRL_RXIRQMODE
Definition sio.h:53
@ SIO_CTRL_TXEN
Definition sio.h:46
char b[9]
Definition string.c:47
Definition sio.h:32
uint16_t stat
Definition sio.h:35
uint8_t preview[3]
Definition sio.h:34
uint16_t padding
Definition sio.h:36
uint8_t fifo
Definition sio.h:33
uint16_t mode
Definition sio.h:37
uint16_t baudRate
Definition sio.h:40
uint16_t ctrl
Definition sio.h:38
uint16_t reserved
Definition sio.h:39
static int ret
Definition syscalls.h:72