Nugget
Bare-metal libraries and examples for the original PlayStation
Loading...
Searching...
No Matches
link-ft232h.h
Go to the documentation of this file.
1/*
2
3MIT License
4
5Copyright (c) 2026 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
32
33/* FT232H byte link, the FT232H EEPROM set to CPU-style FIFO (VCP on the host,
34 which sees an ordinary serial port; the rate there is ignored). The chip is
35 two byte registers: data with its A0 low, status with A0 high. Status bit 0
36 = received data waiting, bit 1 = room to send. USB flow control holds the
37 host back while the chip's buffers are full, so no receive window is needed.
38 Anything emulating that interface (Pico-Dev) works the same way.
39
40 Where the registers sit depends on the board, so both addresses are build
41 knobs, KSEG1 addresses:
42 psx232h, A0 on A20: MONITOR_FT232H_DATA=0xbf000000 STATUS=0xbf100000,
43 EXP1 widened to 8 MB (the default below)
44 Pico-Dev, USB: 0xbf000000 / 0xbf000001 (A1 high selects its UART
45 channel instead, 0xbf000002 / 0xbf000003)
46 MONITOR_FT232H_EXP1_CONFIG, when defined, is written to the EXP1 delay/size
47 register at init. Untested: no board here has one fitted. */
48
49#define MONITOR_LINK_IS_STREAM 1
50
51#ifndef MONITOR_FT232H_DATA
52#define MONITOR_FT232H_DATA 0xbf000000
53#define MONITOR_FT232H_STATUS 0xbf100000
54#define MONITOR_FT232H_EXP1_CONFIG ((23 << 16) | 0x2422) /* 8 MB, psx232h's timing */
55#endif
56
57#define FT232H_DATA (*(volatile uint8_t *)(MONITOR_FT232H_DATA))
58#define FT232H_STATUS (*(volatile uint8_t *)(MONITOR_FT232H_STATUS))
59#define FT232H_RXF 0x01
60#define FT232H_TXE 0x02
61
62static inline void linkInit(void) {
63#ifdef MONITOR_FT232H_EXP1_CONFIG
64 *(volatile uint32_t *)0xbf801008 = MONITOR_FT232H_EXP1_CONFIG;
65#endif
66}
67
68static inline void linkRxOpen(void) {}
69
70static inline void linkRxClose(void) {}
71
72static inline uint8_t linkGetByte(void) {
73 while ((FT232H_STATUS & FT232H_RXF) == 0) {
74 }
75 return FT232H_DATA;
76}
77
78static inline void linkPutByte(uint8_t b) {
79 while ((FT232H_STATUS & FT232H_TXE) == 0) {
80 }
81 FT232H_DATA = b;
82}
83
84/* The received-byte test the exception entry makes in assembly on every
85 interrupt (monitor.c, monitorSlotEntry): RXF in the status register. */
86#define LINK_RX_STAT_ADDR MONITOR_FT232H_STATUS
87#define LINK_RX_STAT_LOAD "lbu"
88#define LINK_RX_STAT_BIT FT232H_RXF
89
90static inline int linkTryGetByte(uint8_t *b) {
91 if ((FT232H_STATUS & FT232H_RXF) == 0) return 0;
92 *b = FT232H_DATA;
93 return 1;
94}
uint8_t b
Definition gte-depthcue.c:39
void uint32_t(classId, spec)