Nugget
Bare-metal libraries and examples for the original PlayStation
Loading...
Searching...
No Matches
cdlinit.c
Go to the documentation of this file.
1/*
2
3MIT License
4
5Copyright (c) 2022 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// clang-format off
28
31
32 CDROM_REG0 = 1;
33 CDROM_REG3 = 0x1f;
34 CDROM_REG0 = 1;
35 CDROM_REG2 = 0x1f;
36 CDROM_REG0 = 0;
38
40 uint8_t cause1 = ackCDRomCause();
41 uint8_t ctrl1 = CDROM_REG0 & ~3;
42 uint8_t response1[16];
44 uint8_t ctrl2 = CDROM_REG0 & ~3;
45 CDROM_REG0 = 1;
46 uint8_t cause1b = CDROM_REG3_UC;
47
49 uint8_t cause2 = ackCDRomCause();
50 uint8_t ctrl3 = CDROM_REG0 & ~3;
51 uint8_t response2[16];
53 uint8_t ctrl4 = CDROM_REG0 & ~3;
54 CDROM_REG0 = 1;
55 uint8_t cause2b = CDROM_REG3_UC;
56
69 // Typical value seems to be around 2ms.
72 // These may be a bit flaky on real hardware, depending on the motors status when starting.
73 // Typical value seems to be around 120ms.
76 ramsyscall_printf("Basic initialization: CD-Rom controller initialized, ack in %ius, complete in %ius\n", ackTime, completeTime);
77)
78
79CESTER_TEST(cdlInitDelayed, test_instance,
81
83 CDROM_REG3 = 0x1f;
84 CDROM_REG0 = 1;
85 CDROM_REG2 = 0x1f;
86 CDROM_REG0 = 0;
88
90
91 // We shouldn't get another IRQ until we acknowledge the previous one
92 // directly to the controller. But the initialization will continue
93 // in the background nonetheless. Wait 500ms, since the controller
94 // finishes its initialization in roughly 120ms.
96 do {
97 delayedTime = updateTime();
98 } while (((IREG & IRQ_CDROM) == 0) && (delayedTime <= 500000));
99 int gotIRQ = (IREG & IRQ_CDROM) != 0;
100 if (gotIRQ) IREG &= ~IRQ_CDROM;
101
102 uint8_t cause1 = ackCDRomCause();
104 uint8_t ctrl1 = CDROM_REG0 & ~3;
105
106
108
110 uint8_t cause2 = ackCDRomCause();
112 uint8_t ctrl2 = CDROM_REG0 & ~3;
113
114
121 // This still takes about 2ms.
124 // Since the initialization completes in the background of the controller
125 // waiting its ack, we're really only measuring the roundtrip of the
126 // communication between the CPU and the mechacon. It typically takes 350us
127 // to do this roundtrip.
130 ramsyscall_printf("Delayed initialization: CD-Rom controller initialized, ack in %ius, complete in %ius\n", ackTime, completeTime);
131)
132
133CESTER_TEST(cdlInitWithArgs, test_instance,
135
136 CDROM_REG0 = 1;
137 CDROM_REG3 = 0x1f;
138 CDROM_REG0 = 1;
139 CDROM_REG2 = 0x1f;
140 CDROM_REG0 = 0;
141 CDROM_REG2 = 0xff;
142 CDROM_REG2 = 0xff;
143 CDROM_REG2 = 0xff;
144 CDROM_REG2 = 0xff;
146
148 uint8_t cause1 = ackCDRomCause();
149 uint8_t ctrl1 = CDROM_REG0 & ~3;
150 uint8_t response1[16];
152 uint8_t ctrl2 = CDROM_REG0 & ~3;
153 CDROM_REG0 = 1;
154 uint8_t cause1b = CDROM_REG3_UC;
155
156 CDROM_REG0 = 0;
159 uint8_t cause2 = ackCDRomCause();
160 uint8_t ctrl3 = CDROM_REG0 & ~3;
161 uint8_t response2[16];
163 uint8_t ctrl4 = CDROM_REG0 & ~3;
164 CDROM_REG0 = 1;
165 uint8_t cause2b = CDROM_REG3_UC;
166
180 // Typical value seems to be around 1ms.
183 // Typical value seems to be around 1.5ms.
186 ramsyscall_printf("Initialization with args: CD-Rom controller errored, error in %ius\n", errorTime);
187 ramsyscall_printf("Initialization with args: requested status, ack in %ius\n", ackTime);
188)
189
190
cester_assert_uint_ge(errorTime, 500)
uint8_t ctrl2
Definition cdlgetlocl.c:86
uint8_t cause1
Definition cdlgetlocl.c:82
uint32_t errorTime
Definition cdlgetlocl.c:81
cester_assert_uint_eq(5, cause1)
uint8_t cause1b
Definition cdlgetlocl.c:88
uint8_t ctrl1
Definition cdlgetlocl.c:83
cester_assert_uint_lt(errorTime, 7000)
uint8_t response1[16]
Definition cdlgettd.c:80
uint8_t responseSize1
Definition cdlgettd.c:81
uint8_t response2[17]
Definition cdlid.c:204
waitCDRomIRQ()
uint8_t ctrl4
Definition cdlid.c:208
uint8_t cause2b
Definition cdlid.c:210
uint32_t completeTime
Definition cdlid.c:201
uint8_t cause2
Definition cdlid.c:202
uint8_t ctrl3
Definition cdlid.c:203
CDROM_REG0
Definition cdlinit.c:82
uint32_t ackTime
Definition cdlinit.c:89
int gotIRQ
Definition cdlinit.c:99
CDROM_REG3
Definition cdlinit.c:83
test_instance
Definition cdlinit.c:79
uint32_t delayedTime
Definition cdlinit.c:95
CESTER_TEST(cdlInit, test_instance, initializeTime();CDROM_REG0=1;CDROM_REG3=0x1f;CDROM_REG0=1;CDROM_REG2=0x1f;CDROM_REG0=0;CDROM_REG1=CDL_INIT;uint32_t ackTime=waitCDRomIRQ();uint8_t cause1=ackCDRomCause();uint8_t ctrl1=CDROM_REG0 &~3;uint8_t response1[16];uint8_t responseSize1=readResponse(response1);uint8_t ctrl2=CDROM_REG0 &~3;CDROM_REG0=1;uint8_t cause1b=CDROM_REG3_UC;uint32_t completeTime=waitCDRomIRQ() - ackTime;uint8_t cause2=ackCDRomCause();uint8_t ctrl3=CDROM_REG0 &~3;uint8_t response2[16];uint8_t responseSize2=readResponse(response2);uint8_t ctrl4=CDROM_REG0 &~3;CDROM_REG0=1;uint8_t cause2b=CDROM_REG3_UC;cester_assert_uint_eq(3, cause1);cester_assert_uint_eq(2, cause2);cester_assert_uint_eq(0xe0, cause1b);cester_assert_uint_eq(0xe0, cause2b);cester_assert_uint_eq(2, response1[0]);cester_assert_uint_eq(1, responseSize1);cester_assert_uint_eq(2, response2[0]);cester_assert_uint_eq(1, responseSize2);cester_assert_uint_eq(0x38, ctrl1);cester_assert_uint_eq(0x18, ctrl2);cester_assert_uint_eq(0x38, ctrl3);cester_assert_uint_eq(0x18, ctrl4);cester_assert_uint_ge(ackTime, 500);cester_assert_uint_lt(ackTime, 7000);cester_assert_uint_ge(completeTime, 50000);cester_assert_uint_lt(completeTime, 150000);ramsyscall_printf("Basic initialization: CD-Rom controller initialized, ack in %ius, complete in %ius\n", ackTime, completeTime);) CESTER_TEST(cdlInitDelayed
CDROM_REG2
Definition cdlinit.c:85
initializeTime()
CDROM_REG1
Definition cdlinit.c:87
uint8_t responseSize2
Definition cdlreadn.c:167
@ CDL_NOP
Definition cdrom.h:43
@ CDL_INIT
Definition cdrom.h:52
#define CDROM_REG3_UC
Definition cdrom.h:39
ramsyscall_printf("=== e01_kseg1_reads_no_fill ===\n")
#define IREG
Definition hwregs.h:46
@ IRQ_CDROM
Definition irq.h:37
cester_assert_false(gotIRQ)
ackCDRomCause()
readResponse(response)
void uint32_t(classId, spec)