main.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. static uint32_t timer_irq_start;
  30. static void init(void)
  31. {
  32. static const char hello[] =
  33. "\n*** Hello, World! ***\n"
  34. "Firmware compiled on: " __DATE__ " " __TIME__ "\n\n";
  35. /* Start ROM copy engine */
  36. unmask_irqs((1U << ROMCOPY_IRQ)|(1U << EBREAK_IRQ)|(1U << BUSERR_IRQ));
  37. set_led(0);
  38. con_set_baudrate(115200);
  39. con_puts(hello);
  40. abc_init_memmap();
  41. abc_init();
  42. timer_irq_count = 0;
  43. timer_irq_start = rdtime();
  44. unmask_irq(SYSCLOCK_IRQ);
  45. read_rtc();
  46. abcdisk_init();
  47. }
  48. bool dont_gc; /* Keep things from linker gc */
  49. void main(void)
  50. {
  51. init();
  52. if (dont_gc)
  53. run_test_image();
  54. while (1) {
  55. wait_for_irq();
  56. abcdisk_io_poll();
  57. }
  58. }