1 // SPDX-License-Identifier: MIT
17 #include <sys/types.h>
19 #include <sys/ioctl.h>
21 #include "gpio/ps_protocol.h"
23 #define SIZE_KILO 1024
24 #define SIZE_MEGA (1024 * 1024)
25 #define SIZE_GIGA (1024 * 1024 * 1024)
27 uint8_t garbege_datas[2 * SIZE_MEGA];
34 uint8_t loop_tests = 0, total_errors = 0;
36 void sigint_handler(int sig_num) {
37 printf("Received sigint %d, exiting.\n", sig_num);
38 printf("Total number of transaction errors occured: %d\n", total_errors);
45 int main(int argc, char *argv[]) {
46 uint32_t test_size = 512 * SIZE_KILO, cur_loop = 0;
48 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &f2);
49 srand((unsigned int)f2.tv_nsec);
51 signal(SIGINT, sigint_handler);
54 ps_reset_state_machine();
59 write8(0xbfe201, 0x0101); //CIA OVL
60 write8(0xbfe001, 0x0000); //CIA OVL LOW
63 test_size = atoi(argv[1]) * SIZE_KILO;
64 if (test_size == 0 || test_size > 2 * SIZE_MEGA) {
65 test_size = 512 * SIZE_KILO;
67 printf("Testing %d KB of memory.\n", test_size / SIZE_KILO);
69 if (strcmp(argv[2], "l") == 0) {
70 printf("Looping tests.\n");
77 printf("Writing garbege datas.\n");
78 for (uint32_t i = 0; i < test_size; i++) {
79 while(garbege_datas[i] == 0x00)
80 garbege_datas[i] = (uint8_t)(rand() % 0xFF);
81 write8(i, (uint32_t)garbege_datas[i]);
84 printf("Reading back garbege datas, read8()...\n");
85 for (uint32_t i = 0; i < test_size; i++) {
86 uint32_t c = read8(i);
87 if (c != garbege_datas[i]) {
89 printf("READ8: Garbege data mismatch at $%.6X: %.2X should be %.2X.\n", i, c, garbege_datas[i]);
93 printf("read8 errors total: %d.\n", errors);
94 total_errors += errors;
98 printf("Reading back garbege datas, read16(), even addresses...\n");
99 for (uint32_t i = 0; i < (test_size) - 2; i += 2) {
100 uint32_t c = be16toh(read16(i));
101 if (c != *((uint16_t *)&garbege_datas[i])) {
103 printf("READ16_EVEN: Garbege data mismatch at $%.6X: %.4X should be %.4X.\n", i, c, *((uint16_t *)&garbege_datas[i]));
107 printf("read16 even errors total: %d.\n", errors);
108 total_errors += errors;
112 printf("Reading back garbege datas, read16(), odd addresses...\n");
113 for (uint32_t i = 1; i < (test_size) - 2; i += 2) {
114 uint32_t c = be16toh((read8(i) << 8) | read8(i + 1));
115 if (c != *((uint16_t *)&garbege_datas[i])) {
117 printf("READ16_ODD: Garbege data mismatch at $%.6X: %.4X should be %.4X.\n", i, c, *((uint16_t *)&garbege_datas[i]));
121 printf("read16 odd errors total: %d.\n", errors);
125 printf("Reading back garbege datas, read32(), even addresses...\n");
126 for (uint32_t i = 0; i < (test_size) - 4; i += 2) {
127 uint32_t c = be32toh(read32(i));
128 if (c != *((uint32_t *)&garbege_datas[i])) {
130 printf("READ32_EVEN: Garbege data mismatch at $%.6X: %.8X should be %.8X.\n", i, c, *((uint32_t *)&garbege_datas[i]));
134 printf("read32 even errors total: %d.\n", errors);
135 total_errors += errors;
139 printf("Reading back garbege datas, read32(), odd addresses...\n");
140 for (uint32_t i = 1; i < (test_size) - 4; i += 2) {
141 uint32_t c = read8(i);
142 c |= (be16toh(read16(i + 1)) << 8);
143 c |= (read8(i + 3) << 24);
144 if (c != *((uint32_t *)&garbege_datas[i])) {
146 printf("READ32_ODD: Garbege data mismatch at $%.6X: %.8X should be %.8X.\n", i, c, *((uint32_t *)&garbege_datas[i]));
150 printf("read32 odd errors total: %d.\n", errors);
151 total_errors += errors;
155 printf("Clearing %d KB of Chip again\n", test_size / SIZE_KILO);
156 for (uint32_t i = 0; i < test_size; i++) {
157 write8(i, (uint32_t)0x0);
160 printf("[WORD] Writing garbege datas to Chip, unaligned...\n");
161 for (uint32_t i = 1; i < (test_size) - 2; i += 2) {
162 uint16_t v = *((uint16_t *)&garbege_datas[i]);
163 write8(i, (v & 0x00FF));
164 write8(i + 1, (v >> 8));
168 printf("Reading back garbege datas, read16(), odd addresses...\n");
169 for (uint32_t i = 1; i < (test_size) - 2; i += 2) {
170 uint32_t c = be16toh((read8(i) << 8) | read8(i + 1));
171 if (c != *((uint16_t *)&garbege_datas[i])) {
173 printf("READ16_ODD: Garbege data mismatch at $%.6X: %.4X should be %.4X.\n", i, c, *((uint16_t *)&garbege_datas[i]));
177 printf("read16 odd errors total: %d.\n", errors);
178 total_errors += errors;
181 printf("Clearing %d KB of Chip again\n", test_size / SIZE_KILO);
182 for (uint32_t i = 0; i < test_size; i++) {
183 write8(i, (uint32_t)0x0);
186 printf("[LONG] Writing garbege datas to Chip, unaligned...\n");
187 for (uint32_t i = 1; i < (test_size) - 4; i += 4) {
188 uint32_t v = *((uint32_t *)&garbege_datas[i]);
189 write8(i , v & 0x0000FF);
190 write16(i + 1, htobe16(((v & 0x00FFFF00) >> 8)));
191 write8(i + 3 , (v & 0xFF000000) >> 24);
195 printf("Reading back garbege datas, read32(), odd addresses...\n");
196 for (uint32_t i = 1; i < (test_size) - 4; i += 4) {
197 uint32_t c = read8(i);
198 c |= (be16toh(read16(i + 1)) << 8);
199 c |= (read8(i + 3) << 24);
200 if (c != *((uint32_t *)&garbege_datas[i])) {
202 printf("READ32_ODD: Garbege data mismatch at $%.6X: %.8X should be %.8X.\n", i, c, *((uint32_t *)&garbege_datas[i]));
206 printf("read32 odd errors total: %d.\n", errors);
207 total_errors += errors;
211 printf ("Loop %d done. Begin loop %d.\n", cur_loop + 1, cur_loop + 2);
212 printf ("Current total errors: %d.\n", total_errors);
219 void m68k_set_irq(unsigned int level) {