board.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. */
  9. #include <interrupt.h>
  10. #include <rthw.h>
  11. #include <board.h>
  12. #include <platform.h>
  13. #include <encoding.h>
  14. #include <interrupt.h>
  15. extern void use_default_clocks(void);
  16. extern void use_pll(int refsel, int bypass, int r, int f, int q);
  17. #define TICK_COUNT (2 * RTC_FREQ / RT_TICK_PER_SECOND)
  18. #define MTIME (*((volatile uint64_t *)(CLINT_CTRL_ADDR + CLINT_MTIME)))
  19. #define MTIMECMP (*((volatile uint64_t *)(CLINT_CTRL_ADDR + CLINT_MTIMECMP)))
  20. /* system tick interrupt */
  21. void handle_m_time_interrupt()
  22. {
  23. MTIMECMP = MTIME + TICK_COUNT;
  24. rt_tick_increase();
  25. }
  26. /* fixed misaligned bug for qemu */
  27. void *__wrap_memset(void *s, int c, size_t n)
  28. {
  29. return rt_memset(s, c, n);
  30. }
  31. static void rt_hw_clock_init(void)
  32. {
  33. use_default_clocks();
  34. use_pll(0, 0, 1, 31, 1);
  35. }
  36. static void rt_hw_timer_init(void)
  37. {
  38. MTIMECMP = MTIME + TICK_COUNT;
  39. /* enable timer interrupt*/
  40. set_csr(mie, MIP_MTIP);
  41. }
  42. void rt_hw_board_init(void)
  43. {
  44. /* initialize the system clock */
  45. rt_hw_clock_init();
  46. /* initialize hardware interrupt */
  47. rt_hw_interrupt_init();
  48. /* initialize timer0 */
  49. rt_hw_timer_init();
  50. #ifdef RT_USING_HEAP
  51. rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
  52. #endif
  53. #ifdef RT_USING_COMPONENTS_INIT
  54. rt_components_board_init();
  55. #endif
  56. #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
  57. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  58. #endif
  59. return;
  60. }