board.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-04-22 hqfang first version
  9. *
  10. */
  11. #include <rtthread.h>
  12. #include <rtdevice.h>
  13. #include "board.h"
  14. #include "cpuport.h"
  15. #define SYSTICK_TICK_CONST (SOC_TIMER_FREQ / RT_TICK_PER_SECOND)
  16. #define RT_KERNEL_INTERRUPT_LEVEL 1
  17. #ifdef RT_USING_SERIAL
  18. #include <drv_uart.h>
  19. #endif
  20. /** _end symbol defined in linker script of Nuclei SDK */
  21. extern void *_end;
  22. /** _heap_end symbol defined in linker script of Nuclei SDK */
  23. extern void *_heap_end;
  24. #define HEAP_BEGIN &_end
  25. #define HEAP_END &_heap_end
  26. /*
  27. * - Implemented and defined in Nuclei SDK system_<Device>.c file
  28. * - Required macro NUCLEI_BANNER set to 0
  29. */
  30. extern void _init(void);
  31. rt_weak void rt_hw_ticksetup(void)
  32. {
  33. uint64_t ticks = SYSTICK_TICK_CONST;
  34. /* Make SWI and SysTick the lowest priority interrupts. */
  35. /* Stop and clear the SysTimer. SysTimer as Non-Vector Interrupt */
  36. SysTick_Config(ticks);
  37. ECLIC_DisableIRQ(SysTimer_IRQn);
  38. ECLIC_SetLevelIRQ(SysTimer_IRQn, RT_KERNEL_INTERRUPT_LEVEL);
  39. ECLIC_SetShvIRQ(SysTimer_IRQn, ECLIC_NON_VECTOR_INTERRUPT);
  40. ECLIC_EnableIRQ(SysTimer_IRQn);
  41. /* Set SWI interrupt level to lowest level/priority, SysTimerSW as Vector Interrupt */
  42. ECLIC_SetShvIRQ(SysTimerSW_IRQn, ECLIC_VECTOR_INTERRUPT);
  43. ECLIC_SetLevelIRQ(SysTimerSW_IRQn, RT_KERNEL_INTERRUPT_LEVEL);
  44. ECLIC_EnableIRQ(SysTimerSW_IRQn);
  45. }
  46. #define SysTick_Handler eclic_mtip_handler
  47. /**
  48. * @brief This is the timer interrupt service routine.
  49. *
  50. */
  51. void SysTick_Handler(void)
  52. {
  53. /* Reload systimer */
  54. SysTick_Reload(SYSTICK_TICK_CONST);
  55. /* enter interrupt */
  56. rt_interrupt_enter();
  57. /* tick increase */
  58. rt_tick_increase();
  59. /* leave interrupt */
  60. rt_interrupt_leave();
  61. }
  62. /**
  63. * @brief Setup hardware board for rt-thread
  64. *
  65. */
  66. void rt_hw_board_init(void)
  67. {
  68. /* OS Tick Configuration */
  69. rt_hw_ticksetup();
  70. #ifdef RT_USING_HEAP
  71. rt_system_heap_init((void *) HEAP_BEGIN, (void *) HEAP_END);
  72. #endif
  73. _init(); // __libc_init_array is not used in RT-Thread
  74. /* UART driver initialization is open by default */
  75. #ifdef RT_USING_SERIAL
  76. rt_hw_uart_init();
  77. #endif
  78. /* Set the shell console output device */
  79. #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
  80. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  81. #endif
  82. /* Board underlying hardware initialization */
  83. #ifdef RT_USING_COMPONENTS_INIT
  84. rt_components_board_init();
  85. #endif
  86. }
  87. /******************** end of file *******************/