main.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // This file is Copyright (c) 2023 Victor Suarez Rovere <suarezvictor@gmail.com>
  2. // SPDX-License-Identifier: AGPL-3.0-only
  3. #include <stdint.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <stdlib.h>
  7. #include <irq.h>
  8. #include <uart.h>
  9. typedef void (*func_ptr) (void);
  10. extern func_ptr __init_array_start, __init_array_end;
  11. extern func_ptr __fini_array_start, __fini_array_end;
  12. static void _init_array(void)
  13. {
  14. for (func_ptr *f = &__init_array_start; f != &__init_array_end; ++f)
  15. (*f)();
  16. }
  17. static void _fini_array(void)
  18. {
  19. for (func_ptr *f = &__fini_array_start; f != &__fini_array_end; ++f)
  20. (*f)();
  21. }
  22. void graphics_app(void);
  23. int main(int argc, char **argv)
  24. {
  25. irq_setmask(0);
  26. irq_setie(1);
  27. uart_init();
  28. _init_array(); //call constructors and initializers
  29. void graphics_app(void);
  30. graphics_app();
  31. _fini_array();
  32. irq_setie(0);
  33. irq_setmask(~0);
  34. return 0;
  35. }
  36. void isr_handler(void)
  37. {
  38. __attribute__((unused)) unsigned int irqs;
  39. irqs = irq_pending() & irq_getmask();
  40. #ifndef UART_POLLING
  41. if(irqs & (1 << UART_INTERRUPT))
  42. uart_isr();
  43. #endif
  44. }
  45. // helpers -----------------------------------------------------------------------------------------
  46. void _putchar(char c) { uart_write(c); } //this is to make printf work
  47. void assert(int c)
  48. {
  49. if(c)
  50. return;
  51. printf("ASSERTION FAILURE\n");
  52. for(;;);
  53. }
  54. int __errno; //FIXME: this is just to avoid linker errors