2
0

system.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. set_leds(-1U);
  42. /* Start ROM copy engine and unmask fatal exceptions */
  43. unmask_irqs((1U << ROMCOPY_IRQ)|(1U << EBREAK_IRQ)|(1U << BUSERR_IRQ));
  44. /* Enable internal timer */
  45. timer_irq_start = rdtime();
  46. unmask_irq(SYSCLOCK_IRQ);
  47. /* This needs to be done as early as possible!!! */
  48. abc_init_memmap();
  49. con_set_baudrate(115200);
  50. con_puts(hello);
  51. if (SYS_MAGIC != SYS_MAGIC_MAX80) {
  52. con_puts("Not a MAX80 board?!?!\n\n");
  53. } else {
  54. uint32_t boardcfg = SYS_BOARDCFG;
  55. con_printf("MAX80 ver %u.%u rework flags %04x\n\n",
  56. (uint8_t)(boardcfg >> 24),
  57. (uint8_t)(boardcfg >> 16),
  58. (uint16_t)boardcfg);
  59. }
  60. read_rtc();
  61. rtc_abc_init();
  62. abcdisk_init();
  63. abc_init();
  64. set_leds(0);
  65. /* Release WAIT# if asserted */
  66. ABC_BUSCTL = 0;
  67. }