board.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Copyright (c) 2006-2024, RT-Thread Development Team
  3. * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0
  6. *
  7. * Change Logs:
  8. * Date Author Notes
  9. * 2024-02-06 yandld first implementation
  10. */
  11. #include <rthw.h>
  12. #include <rtthread.h>
  13. #include "board.h"
  14. #include "clock_config.h"
  15. #include "drv_uart.h"
  16. /**
  17. * This is the timer interrupt service routine.
  18. *
  19. */
  20. void SysTick_Handler(void)
  21. {
  22. /* enter interrupt */
  23. rt_interrupt_enter();
  24. rt_tick_increase();
  25. /* leave interrupt */
  26. rt_interrupt_leave();
  27. }
  28. /**
  29. * This function will initial board.
  30. */
  31. void rt_hw_board_init()
  32. {
  33. BOARD_InitBootPins();
  34. /* This init has finished in secure side of TF-M */
  35. BOARD_InitBootClocks();
  36. SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
  37. /* set pend exception priority */
  38. NVIC_SetPriority(PendSV_IRQn, (1 << __NVIC_PRIO_BITS) - 1);
  39. /*init uart device*/
  40. rt_hw_uart_init();
  41. #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
  42. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  43. #endif
  44. #ifdef RT_USING_COMPONENTS_INIT
  45. /* initialization board with RT-Thread Components */
  46. rt_components_board_init();
  47. #endif
  48. #ifdef RT_USING_HEAP
  49. rt_kprintf("sram heap, begin: 0x%p, end: 0x%p\n", HEAP_BEGIN, HEAP_END);
  50. rt_system_heap_init((void *)HEAP_BEGIN, (void *)(HEAP_END));
  51. #endif
  52. }
  53. /**
  54. * This function will called when memory fault.
  55. */
  56. void MemManage_Handler(void)
  57. {
  58. extern void HardFault_Handler(void);
  59. rt_kprintf("Memory Fault!\n");
  60. HardFault_Handler();
  61. }
  62. void rt_hw_us_delay(rt_uint32_t us)
  63. {
  64. rt_uint32_t ticks;
  65. rt_uint32_t told, tnow, tcnt = 0;
  66. rt_uint32_t reload = SysTick->LOAD;
  67. ticks = us * reload / (1000000 / RT_TICK_PER_SECOND);
  68. told = SysTick->VAL;
  69. while (1)
  70. {
  71. tnow = SysTick->VAL;
  72. if (tnow != told)
  73. {
  74. if (tnow < told)
  75. {
  76. tcnt += told - tnow;
  77. }
  78. else
  79. {
  80. tcnt += reload - tnow + told;
  81. }
  82. told = tnow;
  83. if (tcnt >= ticks)
  84. {
  85. break;
  86. }
  87. }
  88. }
  89. }