system.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. set_led(count >> 3); /* 4 Hz */
  13. }
  14. static no_return killed(const char *how, size_t pc)
  15. {
  16. con_printf("ERROR: %s at 0x%08x\n", how, pc);
  17. con_flush();
  18. udelay(5000000);
  19. reset();
  20. }
  21. IRQHANDLER(BUSERR)
  22. {
  23. killed("misaligned", pc);
  24. }
  25. IRQHANDLER(EBREAK)
  26. {
  27. killed("invalid instruction", pc);
  28. }
  29. uint32_t timer_irq_start;
  30. void init(void)
  31. {
  32. static const char hello[] =
  33. "\n*** Hello, World! ***\n"
  34. "MAX80 "
  35. #ifdef TEST
  36. "testing"
  37. #endif
  38. "firmware compiled on: " __DATE__ " " __TIME__ "\n";
  39. /* Start ROM copy engine */
  40. unmask_irqs((1U << ROMCOPY_IRQ)|(1U << EBREAK_IRQ)|(1U << BUSERR_IRQ));
  41. set_led(0);
  42. con_set_baudrate(115200);
  43. con_puts(hello);
  44. if (SYS_MAGIC != SYS_MAGIC_MAX80) {
  45. con_puts("Not a MAX80 board?!?!\n\n");
  46. _die();
  47. } else {
  48. uint32_t boardcfg = SYS_BOARDCFG;
  49. con_printf("MAX80 ver %u.%u rework flags %04x\n\n",
  50. (uint8_t)(boardcfg >> 24),
  51. (uint8_t)(boardcfg >> 16),
  52. (uint16_t)boardcfg);
  53. }
  54. abc_init_memmap();
  55. abc_init();
  56. timer_irq_start = rdtime();
  57. unmask_irq(SYSCLOCK_IRQ);
  58. read_rtc();
  59. abcdisk_init();
  60. }