system.c 2.1 KB

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