drv_common.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (c) 2006-2024, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2024-04-08 QT-one first version
  9. */
  10. #include <rtdbg.h>
  11. #include "drv_common.h"
  12. #ifdef RT_USING_SERIAL
  13. #include "drv_usart.h"
  14. #endif
  15. #ifdef RT_USING_FINSH
  16. #include <finsh.h>
  17. static void reboot(uint8_t argc, char **argv)
  18. {
  19. rt_hw_cpu_reset();
  20. }
  21. MSH_CMD_EXPORT(reboot, Reboot System);
  22. #endif /* RT_USING_FINSH */
  23. /* SysTick configuration */
  24. void rt_hw_systick_init(void)
  25. {
  26. SYSTICK_ClockSourceConfig(SYSTICK_SRC_STCLK);
  27. SYSTICK_SetReloadValue(SystemCoreClock / 10 / RT_TICK_PER_SECOND);
  28. SYSTICK_IntConfig(ENABLE);
  29. SYSTICK_CounterCmd(SYSTICK_COUNTER_CLEAR);
  30. SYSTICK_CounterCmd(SYSTICK_COUNTER_ENABLE);
  31. }
  32. /* This is the timer interrupt service routine */
  33. void SysTick_Handler(void)
  34. {
  35. /* enter interrupt */
  36. rt_interrupt_enter();
  37. rt_tick_increase();
  38. /* leave interrupt */
  39. rt_interrupt_leave();
  40. }
  41. /* This function is executed in case of error occurrence */
  42. void _Error_Handler(char *s, int num)
  43. {
  44. /* User can add his own implementation to report the error return state */
  45. LOG_E("Error_Handler at file:%s num:%d", s, num);
  46. while (1)
  47. {
  48. }
  49. }
  50. /* This function will initial HT32 board */
  51. void rt_hw_board_init(void)
  52. {
  53. /* Configure the System clock */
  54. rt_hw_board_clock_init();
  55. /* Configure the SysTick */
  56. rt_hw_systick_init();
  57. /* heap initialization */
  58. #ifdef RT_USING_HEAP
  59. rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
  60. #endif
  61. /* board underlying hardware initialization */
  62. #ifdef RT_USING_COMPONENTS_INIT
  63. rt_components_board_init();
  64. #endif
  65. /* set the shell console output device */
  66. #ifdef RT_USING_CONSOLE
  67. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  68. #endif
  69. }