system.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #ifdef TEST
  13. set_leds(count >> 3); /* 4 Hz */
  14. #endif
  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. 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. /* Start ROM copy engine */
  42. unmask_irqs((1U << ROMCOPY_IRQ)|(1U << EBREAK_IRQ)|(1U << BUSERR_IRQ));
  43. set_leds(-1U);
  44. con_set_baudrate(115200);
  45. con_puts(hello);
  46. if (SYS_MAGIC != SYS_MAGIC_MAX80) {
  47. con_puts("Not a MAX80 board?!?!\n\n");
  48. _die();
  49. } else {
  50. uint32_t boardcfg = SYS_BOARDCFG;
  51. con_printf("MAX80 ver %u.%u rework flags %04x\n\n",
  52. (uint8_t)(boardcfg >> 24),
  53. (uint8_t)(boardcfg >> 16),
  54. (uint16_t)boardcfg);
  55. }
  56. abc_init_memmap();
  57. abc_init();
  58. timer_irq_start = rdtime();
  59. unmask_irq(SYSCLOCK_IRQ);
  60. read_rtc();
  61. set_leds(0);
  62. abcdisk_init();
  63. }