system.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #include "fw.h"
  2. #include "io.h"
  3. #include "sdcard.h"
  4. #include "abcio.h"
  5. #include "sys.h"
  6. #include "console.h"
  7. volatile uint32_t timer_irq_count;
  8. IRQHANDLER(sysclock)
  9. {
  10. uint32_t count = timer_irq_count;
  11. count++;
  12. timer_irq_count = count;
  13. if (!(count & ((1U << TIMER_SHIFT)-1)))
  14. CON_DATA = '.'; /* Console heartbeat */
  15. }
  16. static no_return killed(const char *how, size_t pc)
  17. {
  18. con_printf("ERROR: %s at 0x%08x\n", how, pc);
  19. con_flush();
  20. udelay(5000000);
  21. reset();
  22. }
  23. IRQHANDLER(buserr)
  24. {
  25. killed("misaligned", pc);
  26. }
  27. IRQHANDLER(ebreak)
  28. {
  29. killed("invalid instruction", pc);
  30. }
  31. volatile uint32_t __dram_bss test_dram[8];
  32. uint32_t timer_irq_start;
  33. void init(void)
  34. {
  35. static const char hello[] =
  36. "\n\n*** Hello, World! ***\n"
  37. "MAX80 "
  38. #ifdef TEST
  39. "testing"
  40. #endif
  41. "firmware compiled on: " __DATE__ " " __TIME__ "\n";
  42. timer_irq_start = rdtime();
  43. /* Start ROM copy engine, unmask timer and fatal exceptions */
  44. unmask_irqs((1U << ROMCOPY_IRQ)|(1U << EBREAK_IRQ)|
  45. (1U << BUSERR_IRQ)|(1U << SYSCLOCK_IRQ));
  46. set_leds(7);
  47. con_set_baudrate(115200);
  48. con_puts(hello);
  49. con_flush();
  50. /* Enable internal timer */
  51. unmask_irq(SYSCLOCK_IRQ);
  52. set_leds(6);
  53. wait_romcopy_done();
  54. set_leds(5);
  55. #if 1
  56. con_puts("Waiting 5 s for testing...");
  57. udelay(5000000);
  58. con_putc('\n');
  59. #endif
  60. /* This needs to be done as early as possible!!! */
  61. abc_init_memmap();
  62. if (SYS_MAGIC != SYS_MAGIC_MAX80) {
  63. con_puts("Not a MAX80 board?!?!\n\n");
  64. } else {
  65. uint32_t boardcfg = SYS_BOARDCFG;
  66. con_printf("MAX80 ver %u.%u rework flags %04x\n\n",
  67. (uint8_t)(boardcfg >> 24),
  68. (uint8_t)(boardcfg >> 16),
  69. (uint16_t)boardcfg);
  70. }
  71. if ( 1 ) {
  72. con_puts("Quick DRAM test:\n");
  73. for (int i = 0; i < 8; i++) {
  74. uint32_t v = (i*0x11111111) + 0x44332211;
  75. test_dram[i] = v;
  76. con_printf("%08x ", v);
  77. }
  78. con_putc('\n');
  79. for (int i = 0; i < 8; i++) {
  80. con_printf("%08x ", test_dram[i]);
  81. }
  82. con_puts("\n\n");
  83. udelay(1000000);
  84. }
  85. if ( 1 ) {
  86. con_puts("Random number generator test:\n");
  87. for (int i = 0; i < 8; i++) {
  88. uint32_t a = rdrand();
  89. uint32_t b = rdrand();
  90. con_printf("%08x %08x delta %08x\n", a, b, a^b);
  91. }
  92. }
  93. rom_get_serial();
  94. set_leds(4);
  95. read_rtc();
  96. rtc_abc_init();
  97. set_leds(3);
  98. sdcard_reset();
  99. disk_cache_init();
  100. abcdisk_init();
  101. set_leds(2);
  102. abc_init();
  103. set_leds(1);
  104. /* Release WAIT# if asserted */
  105. ABC_BUSCTL = 0;
  106. set_leds(0);
  107. }