fomu.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * The MIT License (MIT)
  3. *
  4. * Copyright (c) 2019 Ha Thach (tinyusb.org)
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. *
  24. * This file is part of the TinyUSB stack.
  25. */
  26. #include <stdint.h>
  27. #include <stdbool.h>
  28. #include "../board.h"
  29. #include "csr.h"
  30. #include "irq.h"
  31. //--------------------------------------------------------------------+
  32. // Board porting API
  33. //--------------------------------------------------------------------+
  34. void fomu_error(uint32_t line)
  35. {
  36. (void)line;
  37. TU_BREAKPOINT();
  38. }
  39. volatile uint32_t system_ticks = 0;
  40. static void timer_init(void)
  41. {
  42. int t;
  43. timer0_en_write(0);
  44. t = CONFIG_CLOCK_FREQUENCY / 1000; // 1000 kHz tick
  45. timer0_reload_write(t);
  46. timer0_load_write(t);
  47. timer0_en_write(1);
  48. timer0_ev_enable_write(1);
  49. timer0_ev_pending_write(1);
  50. irq_setmask(irq_getmask() | (1 << TIMER0_INTERRUPT));
  51. }
  52. void isr(void)
  53. {
  54. unsigned int irqs;
  55. irqs = irq_pending() & irq_getmask();
  56. #if CFG_TUD_ENABLED
  57. if (irqs & (1 << USB_INTERRUPT)) {
  58. tud_int_handler(0);
  59. }
  60. #endif
  61. if (irqs & (1 << TIMER0_INTERRUPT)) {
  62. system_ticks++;
  63. timer0_ev_pending_write(1);
  64. }
  65. }
  66. void board_init(void)
  67. {
  68. irq_setmask(0);
  69. irq_setie(1);
  70. timer_init();
  71. return;
  72. }
  73. void board_led_write(bool state)
  74. {
  75. rgb_ctrl_write(0xff);
  76. rgb_raw_write(state);
  77. }
  78. uint32_t board_button_read(void)
  79. {
  80. return 0;
  81. }
  82. int board_uart_read(uint8_t* buf, int len)
  83. {
  84. (void) buf;
  85. (void) len;
  86. return 0;
  87. }
  88. int board_uart_write(void const * buf, int len)
  89. {
  90. int32_t offset = 0;
  91. uint8_t const* buf8 = (uint8_t const*) buf;
  92. for (offset = 0; offset < len; offset++)
  93. {
  94. if (!(messible_status_read() & CSR_MESSIBLE_STATUS_FULL_OFFSET))
  95. {
  96. messible_in_write(buf8[offset]);
  97. }
  98. }
  99. return len;
  100. }
  101. #if CFG_TUSB_OS == OPT_OS_NONE
  102. uint32_t board_millis(void)
  103. {
  104. return system_ticks;
  105. }
  106. #endif