Nugget
Bare-metal libraries and examples for the original PlayStation
Loading...
Searching...
No Matches
link-atcons.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
28#pragma once
29
30#include <stdint.h>
31
34
35/* ATCONS register file (0x1F8020xx), from hwregs.h; the 16-bit word channel
36 lives one halfword past the byte FIFO.
37
38 STAT bit map, confirmed by disassembling the DTL-H2000 debug stub's four
39 transfer primitives (read/write byte, read/write word):
40 bit0 (0x01) = RX word available (host -> PS1, lhu 0x2004)
41 bit2 (0x04) = TX word ready (PS1 -> host, sh 0x2004)
42 bit3 (0x08) = TX byte ready (PS1 -> host, sb 0x2002)
43 bit4 (0x10) = RX byte available (host -> PS1, lbu 0x2002)
44 The word channel is polled on STAT alone; unlike the byte channel it takes
45 no per-word IRQ ack (the stub's word primitives are pure STAT-gated
46 lhu/sh). */
47
48#define STAT_RX_WORD 0x01
49#define STAT_TX_WORD 0x04
50
51static inline uint16_t linkGetWord(void) {
52 while ((ATCONS_STAT & STAT_RX_WORD) == 0) {
53 /* spin until the host has posted a word */
54 }
55 uint16_t w = ATCONS_WORD;
56 flushWriteQueue();
57 return w;
58}
59
60static inline void linkPutWord(uint16_t w) {
61 while ((ATCONS_STAT & STAT_TX_WORD) == 0) {
62 /* spin until the channel can accept a word */
63 }
64 ATCONS_WORD = w;
65 flushWriteQueue();
66}
67
68static inline void linkInit(void) {
69 /* Mirror dev_tty_init's ATCONS bring-up: clear the IRQ2 enable bit, then
70 prime the IRQ / IRQ2 handshake registers. This is the shared ATCONS IRQ
71 machinery; the word channel rides the same FPGA block as the byte TTY. */
72 ATCONS_IRQ2 &= 0xfe;
73 flushWriteQueue();
74 ATCONS_IRQ = 0x20;
75 ATCONS_IRQ2 |= 0x10;
76 flushWriteQueue();
77}
#define ATCONS_IRQ
Definition hwregs.h:58
#define ATCONS_STAT
Definition hwregs.h:55
#define ATCONS_WORD
Definition hwregs.h:57
#define ATCONS_IRQ2
Definition hwregs.h:59
list w
Definition gentable.py:108