board.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. edma_config_t userConfig = {0};
  35. EDMA_GetDefaultConfig(&userConfig);
  36. EDMA_Init(DMA0, &userConfig);
  37. /* This init has finished in secure side of TF-M */
  38. BOARD_InitBootClocks();
  39. SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
  40. /* set pend exception priority */
  41. NVIC_SetPriority(PendSV_IRQn, (1 << __NVIC_PRIO_BITS) - 1);
  42. /*init uart device*/
  43. rt_hw_uart_init();
  44. #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
  45. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  46. #endif
  47. #ifdef RT_USING_COMPONENTS_INIT
  48. /* initialization board with RT-Thread Components */
  49. rt_components_board_init();
  50. #endif
  51. #ifdef RT_USING_HEAP
  52. rt_kprintf("sram heap, begin: 0x%p, end: 0x%p\n", HEAP_BEGIN, HEAP_END);
  53. rt_system_heap_init((void *)HEAP_BEGIN, (void *)(HEAP_END));
  54. #endif
  55. }
  56. /**
  57. * This function will called when memory fault.
  58. */
  59. void MemManage_Handler(void)
  60. {
  61. extern void HardFault_Handler(void);
  62. rt_kprintf("Memory Fault!\n");
  63. HardFault_Handler();
  64. }
  65. void rt_hw_us_delay(rt_uint32_t us)
  66. {
  67. rt_uint32_t ticks;
  68. rt_uint32_t told, tnow, tcnt = 0;
  69. rt_uint32_t reload = SysTick->LOAD;
  70. ticks = us * reload / (1000000 / RT_TICK_PER_SECOND);
  71. told = SysTick->VAL;
  72. while (1)
  73. {
  74. tnow = SysTick->VAL;
  75. if (tnow != told)
  76. {
  77. if (tnow < told)
  78. {
  79. tcnt += told - tnow;
  80. }
  81. else
  82. {
  83. tcnt += reload - tnow + told;
  84. }
  85. told = tnow;
  86. if (tcnt >= ticks)
  87. {
  88. break;
  89. }
  90. }
  91. }
  92. }