board.c 1.7 KB

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