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