f1c100s.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 <malloc.h>
  28. #include <irqflags.h>
  29. #include <f1c100s-irq.h>
  30. #include "bsp/board.h"
  31. #include "board.h"
  32. extern void sys_uart_putc(char c);
  33. //--------------------------------------------------------------------+
  34. // Board porting API
  35. //--------------------------------------------------------------------+
  36. static void timer_init(void);
  37. void board_init(void)
  38. {
  39. arch_local_irq_disable();
  40. do_init_mem_pool();
  41. f1c100s_intc_init();
  42. timer_init();
  43. printf("Timer INIT done\n");
  44. arch_local_irq_enable();
  45. }
  46. // No LED, no button
  47. void board_led_write(bool state)
  48. {
  49. }
  50. uint32_t board_button_read(void)
  51. {
  52. return 0;
  53. }
  54. int board_uart_read(uint8_t* buf, int len)
  55. {
  56. return 0;
  57. }
  58. int board_uart_write(void const * buf, int len)
  59. {
  60. int txsize = len;
  61. while (txsize--) {
  62. sys_uart_putc(*(uint8_t const*)buf);
  63. buf++;
  64. }
  65. return len;
  66. }
  67. #if CFG_TUSB_OS == OPT_OS_NONE
  68. volatile uint32_t system_ticks = 0;
  69. uint32_t board_millis(void)
  70. {
  71. return system_ticks;
  72. }
  73. static void timer_handler(void)
  74. {
  75. volatile uint32_t *temp_addr = (uint32_t *)(0x01C20C00 + 0x04);
  76. /* clear timer */
  77. *temp_addr |= 0x01;
  78. system_ticks++;
  79. }
  80. static void timer_init(void) {
  81. uint32_t temp;
  82. volatile uint32_t *temp_addr;
  83. /* reload value */
  84. temp = 12000000 / 1000;
  85. temp_addr = (uint32_t *)(0x01C20C00 + 0x14);
  86. *temp_addr = temp;
  87. /* continuous | /2 | 24Mhz | reload*/
  88. temp = (0x00 << 7) | (0x01 << 4) | (0x01 << 2) | (0x00 << 1);
  89. temp_addr = (uint32_t *)(0x01C20C00 + 0x10);
  90. *temp_addr &= 0xffffff00;
  91. *temp_addr |= temp;
  92. /* open timer irq */
  93. temp = 0x01 << 0;
  94. temp_addr = (uint32_t *)(0x01C20C00);
  95. *temp_addr |= temp;
  96. /* set init value */
  97. temp_addr = (uint32_t *)(0x01C20C00 + 0x18);
  98. *temp_addr = 0;
  99. /* begin run timer */
  100. temp = 0x01 << 0;
  101. temp_addr = (uint32_t *)(0x01C20C00 + 0x10);
  102. *temp_addr |= temp;
  103. f1c100s_intc_set_isr(F1C100S_IRQ_TIMER0, timer_handler);
  104. f1c100s_intc_enable_irq(F1C100S_IRQ_TIMER0);
  105. }
  106. #else
  107. static void timer_init(void) { }
  108. #endif