GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — corememoryshield/corememoryshield.ino at main · joschal/corememoryshield Expand file tree/ Copy pathcorememoryshield.inoMore file actions 695 lines (632 loc) · 14.5 KB / Copy pathcorememoryshield.inoFile metadata and controls695 lines (632 loc) · 14.5 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 // Rough-and-ready Arduino code for testing, calibrating and using core memory shield. // // Copyright 2011 Ben North and Oliver Nash. // // Modified by Jussi Kilpeläinen 2019-10-31 for his own core memory shield (http://jussikilpelainen.kapsi.fi/?p=213) // Modified by joschal in 2020 do make the code more readable and therefore accessible to a wider audience // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. #define ADDRSIZE 5 #define WORDSIZE (1 << ADDRSIZE) static unsigned int WRITE_ON_US = 3; static unsigned int WRITE_OFF_US = 25; // Gives the capacitor on the 5V rail a while to recharge static unsigned long errs = 0; static unsigned int sense_test_addr = 0; static int n_test_iters = 1000; static char report_errors_p = 0; static char trace_core_calls_p = 0; /* n address to write to v value to write */ void write_bit(char n, const int v) { if (trace_core_calls_p) { char buf[64]; sprintf(buf, "writing value %d to address x[0%02d]", v, n); Serial.println(buf); } // Assert 0 <= n <= 31, v == 0 or 1. noInterrupts(); if(v == 0) { digitalWrite(8, LOW); } else { digitalWrite(8, HIGH); } // Disable digitalWrite(2,LOW); //Write address digitalWrite(3,bitRead(n, 0)); digitalWrite(4,bitRead(n, 1)); digitalWrite(5,bitRead(n, 2)); digitalWrite(6,bitRead(n, 3)); digitalWrite(7,bitRead(n, 4)); // Toggle enable pin digitalWrite(2, HIGH); delayMicroseconds(WRITE_ON_US); digitalWrite(2, LOW); delayMicroseconds(WRITE_OFF_US); interrupts(); } int exchg_bit(char n, const int v) { write_bit(n, v); // If pin 9 is high, the value was a 1 if(digitalRead(9)) { // Switching occurred so core held opposite of // what we just set it to. if (trace_core_calls_p) Serial.println("___ -> CHANGE"); return !v; } else { // No switching occurred so core held whatever // we just wrote to it. if (trace_core_calls_p) Serial.println("___ -> NO-CHANGE"); return v; } } int read_bit(const int n) { char buf[64]; if (trace_core_calls_p) { sprintf(buf, "x[0%02d] -> ___", n); Serial.println(buf); } write_bit(n, 0); // If pin 9 is high, the core held a 1 int digitalPinValue = digitalRead(9); if (digitalPinValue){ // Switching occurred so core held 1. if (trace_core_calls_p) Serial.println("___ -> 1"); write_bit(n, 1); // Put it back! return 1; } else { // No switching occurred so core held 0 (and still holds it). if (trace_core_calls_p) Serial.println("___ -> 0"); return 0; } } void write_word(unsigned long v) { int n; for(n = 0; n < WORDSIZE; n++) { write_bit(n, v & 1); v >>= 1; } } unsigned long read_word(void) { unsigned long v = 0; int n; for(n = WORDSIZE-1; n >= 0; n--) { v <<= 1; v |= read_bit(n); } return v; } unsigned long exchg_word(unsigned long v) { unsigned long v_prev; int n; for (n = 0; n < WORDSIZE; ++n) { unsigned long b = exchg_bit(n, v & 1); v >>= 1; v_prev >>= 1; v_prev |= (b << 31); } return v_prev; } static void maybe_report_error(int i, int j, const char * lbl) { char buf[64]; if (!report_errors_p) return; sprintf(buf, "(%o, %o): %s", i, j, lbl); Serial.println(buf); } static void toggle_error_reporting() { char buf[64]; report_errors_p = !report_errors_p; sprintf(buf, "report-errors-p now %d", report_errors_p); Serial.println(buf); } static void toggle_tracing() { char buf[64]; trace_core_calls_p = !trace_core_calls_p; sprintf(buf, "trace-core-calls-p now %d", trace_core_calls_p); Serial.println(buf); } static void current_calibration() { Serial.print("pulsing for current calibration..."); while (Serial.available() == 0) { int i; for (i = 0; i < WORDSIZE; ++i) { write_bit(i, 0); write_bit(i, 1); } delayMicroseconds(100); } Serial.println(" stopped"); Serial.read(); /* discard typed character */ } static void timing_exchange_word() { unsigned long val_0 = read_word(); unsigned long i; Serial.print("start..."); for (i = 0; i < 12000; ++i) { exchg_word(val_0); exchg_word(val_0); exchg_word(val_0); exchg_word(val_0); exchg_word(val_0); exchg_word(val_0); exchg_word(val_0); exchg_word(val_0); exchg_word(val_0); exchg_word(val_0); } Serial.println("stop"); } static void echo_comment() { Serial.print("# "); char c; do { while (Serial.available() == 0); c = Serial.read(); Serial.print(c); } while (c != '\r'); Serial.println(""); } static void corewise_set_test() { char buf[64]; for (int b = 0; b < 2; ++b) { errs = 0; for (int n = 0; n < n_test_iters; ++n) for (int i = 0; i < WORDSIZE; ++i) { write_bit(i, b); if (read_bit(i) != b) ++errs; } sprintf(buf, "set %d %lu %d", b, errs, n_test_iters); Serial.println(buf); } } static void corewise_interfere_test() { char buf[64]; for (int b0 = 0; b0 < 2; ++b0) { for (int b1 = 0; b1 < 2; ++b1) { errs = 0; for (int n = 0; n < n_test_iters; ++n) { for (int i = 0; i < WORDSIZE; ++i) { for (int j = 0; j < WORDSIZE; ++j) { if (j == i) continue; write_bit(i, b0); write_bit(j, b1); if (read_bit(i) != b0) { if (report_errors_p) { // Redundant test but sprintf() takes time. sprintf(buf, "%d %d", b0, b1); maybe_report_error(i, j, buf); } ++errs; } } } } sprintf(buf, "interfere %d %d %lu %d", b0, b1, errs, n_test_iters); Serial.println(buf); } } } static void corewise_tests() { corewise_set_test(); corewise_interfere_test(); } static void R_test() { unsigned long d = read_word(); Serial.print("Core data read: 0x"); Serial.print(d, HEX); Serial.print(" = B"); Serial.println(d, BIN); } static void s_test() { char buf[64]; write_bit(sense_test_addr, 0); write_bit(sense_test_addr, 0); write_bit(sense_test_addr, 1); write_bit(sense_test_addr, 1); sprintf(buf, "Pulsed core 0%02d", sense_test_addr); Serial.println(buf); } static void report_sense_addr() { char buf[64]; sprintf(buf, "Ready to pulse core 0%02d", sense_test_addr); Serial.println(buf); } static void a_test() { sense_test_addr += 1; sense_test_addr %= 32; report_sense_addr(); } static void A_test() { sense_test_addr -= 1; sense_test_addr %= 32; report_sense_addr(); } static void W_test() { int i, x; unsigned long d = 0; Serial.print("Please enter 8 hexadecimal digits: "); for(i = 0; i < 8; i++) { d <<= 4; while(Serial.available() == 0) ; x = Serial.read(); if('0' <= x && x <= '9') { d += x - '0'; } else if('A' <= x && x <= 'F') { d += x - 'A' + 10; } else if('a' <= x && x <= 'f') { d += x - 'a' + 10; } else { Serial.print("Assuming 0 for non-hexadecimal digit: "); Serial.println(x); } } write_word(d); Serial.print("\r\nCore data write: 0x"); Serial.print(d, HEX); Serial.print(" = B"); Serial.println(d, BIN); } static void X_test() { char buf[64]; int i, x; unsigned long d1, d = 0; Serial.print("Please enter 8 hexadecimal digits: "); for(i = 0; i < 8; i++) { d <<= 4; while(Serial.available() == 0) ; x = Serial.read(); if('0' <= x && x <= '9') { d += x - '0'; } else if('A' <= x && x <= 'F') { d += x - 'A' + 10; } else if ('a' <= x && x <= 'f') { d += x - 'a' + 10; } else { Serial.print("Assuming 0 for non-hexadecimal digit: "); Serial.println(x); } } d1 = exchg_word(d); Serial.print("\r\nCore data write: 0x"); sprintf(buf, "%08lx; read 0x%08lx", d, d1); Serial.println(buf); } static void r_test() { int i, x, a = 0; Serial.print("Please enter address of bit to read: "); for(i = 0; i < ADDRSIZE; i++) { a <<= 1; while(Serial.available() == 0) ; x = Serial.read(); if(x != '0') // Assert x == '1' { a += 1; } } Serial.print("\r\nCore data read from address: "); Serial.print(a, BIN); Serial.print(" found: "); Serial.println(read_bit(a)); } static void w_test() { int i, x, a = 0; Serial.print("Please enter address of bit to write: "); for(i = 0; i < ADDRSIZE; i++) { a <<= 1; while(Serial.available() == 0) ; x = Serial.read(); if(x != '0') // Assert x == '1' { a += 1; } } Serial.print("\r\nPlease enter bit to write: "); while(Serial.available() == 0) ; x = Serial.read(); Serial.print("\r\nCore data write to address: "); Serial.print(a, BIN); Serial.print(" value: "); if(x == '0') { write_bit(a, 0); Serial.println("0"); } else // Assert x == '1' { write_bit(a, 1); Serial.println("1"); } } static void t_test() { int i; unsigned long d; for(i = 0; i < WORDSIZE; i++) { write_bit(i, 0); d = read_bit(i); Serial.print("Address ("); Serial.print(i >> 3); Serial.print(i & 7); Serial.print(") "); Serial.print(i, BIN); Serial.print(" wrote 0 read "); Serial.print(d); write_bit(i, 1); d = read_bit(i); Serial.print(" wrote 1 read "); Serial.println(d); } } static void T_test() { unsigned long d; int i, j; Serial.print("log10(iters)? "); while(Serial.available() == 0) ; int n = Serial.read() - '0'; if (n < 0 || n > 9) Serial.println("bad power-of-10 arg to T"); else { unsigned long n_iters = 1, n_iters_done = 0; while (n--) n_iters *= 10; errs = 0; for (n_iters_done = 0; n_iters_done < n_iters; ++n_iters_done) { for(i = 0; i < WORDSIZE; i++) { for(j = 0; j < WORDSIZE; j++) { if(j == i) { continue; } write_bit(i, 0); d = read_bit(i); if(d != 0) { errs++; maybe_report_error(i, j, "0-0"); } d = read_bit(i); if(d != 0) { errs++; maybe_report_error(i, j, "0-1"); } write_bit(i, 0); write_bit(j, 0); d = read_bit(i); if(d != 0) { errs++; maybe_report_error(i, j, "000"); } d = read_bit(i); if(d != 0) { errs++; maybe_report_error(i, j, "001"); } write_bit(i, 0); write_bit(j, 1); d = read_bit(i); if(d != 0) { errs++; maybe_report_error(i, j, "010"); } d = read_bit(i); if(d != 0) { errs++; maybe_report_error(i, j, "011"); } write_bit(i, 1); d = read_bit(i); if(d != 1) { errs++; maybe_report_error(i, j, "1-0"); } d = read_bit(i); if(d != 1) { errs++; maybe_report_error(i, j, "1-1"); } write_bit(i, 1); write_bit(j, 0); d = read_bit(i); if(d != 1) { errs++; maybe_report_error(i, j, "100"); } d = read_bit(i); if(d != 1) { errs++; maybe_report_error(i, j, "101"); } write_bit(i, 1); write_bit(j, 1); d = read_bit(i); if(d != 1) { errs++; maybe_report_error(i, j, "110"); } d = read_bit(i); if(d != 1) { errs++; maybe_report_error(i, j, "111"); } } } if (n_iters_done % 100 == 0) { Serial.print(n_iters_done, DEC); Serial.print(" iters; "); Serial.print(errs, DEC); Serial.println(" errors"); } } Serial.print(n_iters_done, DEC); Serial.print(" iters; "); Serial.print(errs, DEC); Serial.println(" errors"); } } static void U_test() { unsigned long n_iters_done = 0; unsigned long prev_datum = 0UL; errs = 0; write_word(prev_datum); while (1) { if (Serial.available() > 0) { (void)Serial.read(); Serial.println("stopping"); break; } unsigned rnd_0 = random(0x10000); unsigned rnd_1 = random(0x10000); unsigned long rnd = (unsigned long)(rnd_1) << 16 | rnd_0; unsigned long read_datum = exchg_word(rnd); // sprintf(buf, "rnd %08lx; read %08lx", rnd, read_datum); // Serial.println(buf); if (read_datum != prev_datum) ++errs; prev_datum = rnd; if (n_iters_done % 20000 == 0) { char buf[64]; sprintf(buf, "%lu iters-done; %lu errors", n_iters_done, errs); Serial.println(buf); } ++n_iters_done; } } void setup(void) { // set OUTPUT pins pinMode(2, OUTPUT); pinMode(3, OUTPUT); pinMode(4, OUTPUT); pinMode(5, OUTPUT); pinMode(6, OUTPUT); pinMode(7, OUTPUT); pinMode(8, OUTPUT); // Set INPUT pins pinMode(9, INPUT); // Set write pin to LOW -> disable digitalWrite(2,LOW); Serial.begin(115200); randomSeed(0xcafecafe); Serial.println("Welcome! If you're new, try using the commands 'r', 'w', 't' and 'R', 'W', 'T' to get started."); } void loop(void) { char c; if(Serial.available() > 0) { c = Serial.read(); switch(c) { case 'c': current_calibration(); break; case '#': echo_comment(); break; case 'e': corewise_tests(); break; case 'v': toggle_tracing(); break; case 'f': toggle_error_reporting(); break; case 'm': timing_exchange_word(); break; case 'R': R_test(); break; case 's': s_test(); break; case 'a': a_test(); break; case 'A': A_test(); break; case 'W': W_test(); break; case 'X': X_test(); break; case 'r': r_test(); break; case 'w': w_test(); break; case 't': t_test(); break; case 'T': T_test(); break; case 'U': U_test(); break; case 'z': errs = 0; Serial.println("error-count = 0"); break; default: Serial.print("Ignoring unknown command: "); Serial.print(c, HEX); Serial.print(" "); Serial.println(c); } } } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |