board.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. * 2019-07-23 tyustli first version
  9. *
  10. */
  11. #include <stddef.h>
  12. #include <rtthread.h>
  13. #include <rtdevice.h>
  14. #include "board.h"
  15. #ifdef RT_USING_SERIAL
  16. #include <drv_usart.h>
  17. #endif
  18. /* System Tick Configuration */
  19. static void systick_config(rt_uint32_t ticks) {
  20. /* set value */
  21. *(rt_uint64_t *) (TMR_CTRL_ADDR + TMR_MTIMECMP) = ticks;
  22. /* enable interrupt */
  23. eclic_irq_enable(CLIC_INT_TMR, 0, 0);
  24. /* clear value */
  25. *(rt_uint64_t *) (TMR_CTRL_ADDR + TMR_MTIME) = 0;
  26. }
  27. /* This is the timer interrupt service routine. */
  28. void eclic_mtip_handler(void) {
  29. /* clear value */
  30. *(rt_uint64_t *) (TMR_CTRL_ADDR + TMR_MTIME) = 0;
  31. /* enter interrupt */
  32. rt_interrupt_enter();
  33. /* tick increase */
  34. rt_tick_increase();
  35. /* leave interrupt */
  36. rt_interrupt_leave();
  37. }
  38. /* fixed misaligned bug for qemu */
  39. void *__wrap_memset(void *s, int c, size_t n)
  40. {
  41. return rt_memset(s, c, n);
  42. }
  43. void rt_hw_board_init(void) {
  44. extern void riscv_clock_init(void);
  45. riscv_clock_init();
  46. systick_config(TMR_FREQ / RT_TICK_PER_SECOND);
  47. #ifdef RT_USING_HEAP
  48. rt_system_heap_init((void *) HEAP_BEGIN, (void *) HEAP_END);
  49. #endif
  50. /* USART driver initialization is open by default */
  51. #ifdef RT_USING_SERIAL
  52. rt_hw_usart_init();
  53. #endif
  54. /* Set the shell console output device */
  55. #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
  56. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  57. #endif
  58. /* Board underlying hardware initialization */
  59. #ifdef RT_USING_COMPONENTS_INIT
  60. rt_components_board_init();
  61. #endif
  62. }
  63. /******************** end of file *******************/