main.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. /* Configure ABC memory map */
  15. static void init_abc_memmap(void)
  16. {
  17. volatile uint32_t *pg = &ABCMEMMAP_PAGE(0);
  18. for (unsigned int addr = 0; addr < 0x10000; addr += 512) {
  19. if (addr >= 0x5800 && addr < 0x6000) {
  20. *pg++ = ABCMEMMAP_RD | addr;
  21. } else if (addr >= 0x8000 && addr < 0xc000) {
  22. *pg++ = ABCMEMMAP_RD | ABCMEMMAP_WR | addr;
  23. } else {
  24. *pg++ = addr; /* Disabled */
  25. }
  26. }
  27. }
  28. static no_return killed(const char *how, size_t pc)
  29. {
  30. con_printf("ERROR: %s at 0x%08x\n", how, pc);
  31. con_flush();
  32. udelay(5000000);
  33. reset();
  34. }
  35. IRQHANDLER(BUSERR)
  36. {
  37. killed("misaligned", pc);
  38. }
  39. IRQHANDLER(EBREAK)
  40. {
  41. killed("invalid instruction", pc);
  42. }
  43. static uint32_t timer_irq_start;
  44. static void init(void)
  45. {
  46. static const char hello[] =
  47. "\n*** Hello, World! ***\n"
  48. "Firmware compiled on: " __DATE__ " " __TIME__ "\n\n";
  49. /* Start ROM copy engine */
  50. unmask_irqs((1U << ROMCOPY_IRQ)|(1U << EBREAK_IRQ)|(1U << BUSERR_IRQ));
  51. set_led(0);
  52. con_set_baudrate(115200);
  53. con_puts(hello);
  54. abc_init();
  55. init_abc_memmap();
  56. timer_irq_count = 0;
  57. timer_irq_start = rdtime();
  58. unmask_irq(SYSCLOCK_IRQ);
  59. read_rtc();
  60. abcdisk_init();
  61. }
  62. bool dont_gc; /* Keep things from linker gc */
  63. void main(void)
  64. {
  65. init();
  66. if (dont_gc)
  67. run_test_image();
  68. while (1) {
  69. wait_for_irq();
  70. abcdisk_io_poll();
  71. }
  72. }