board.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (c) 2006-2020, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-02-11 supperthomas first version
  9. *
  10. */
  11. #include <rtthread.h>
  12. #include <rthw.h>
  13. #include <stdio.h>
  14. #include "board.h"
  15. #include "mxc_sys.h"
  16. #ifdef RT_USING_SERIAL
  17. #include "drv_usart.h"
  18. #endif
  19. /**
  20. * This is the timer interrupt service routine.
  21. *
  22. */
  23. void SysTick_Handler(void)
  24. {
  25. /* enter interrupt */
  26. rt_interrupt_enter();
  27. rt_tick_increase();
  28. /* leave interrupt */
  29. rt_interrupt_leave();
  30. }
  31. void rt_hw_systick_init(void)
  32. {
  33. uint32_t error;
  34. error = SYS_SysTick_Config(SYS_SysTick_GetFreq() / RT_TICK_PER_SECOND, 1, MXC_TMR0);
  35. if (error != E_NO_ERROR)
  36. {
  37. rt_kprintf("ERROR: Ticks is not valid");
  38. }
  39. }
  40. void rt_hw_board_init(void)
  41. {
  42. rt_hw_systick_init();
  43. #if defined(RT_USING_HEAP)
  44. rt_system_heap_init((void *)(HEAP_BEGIN), (void *)(HEAP_END));
  45. #endif
  46. #ifdef RT_USING_SERIAL
  47. rt_hw_usart_init();
  48. #endif
  49. #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
  50. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  51. #endif
  52. #ifdef RT_USING_COMPONENTS_INIT
  53. rt_components_board_init();
  54. #endif
  55. }
  56. void rt_hw_us_delay(rt_uint32_t us)
  57. {
  58. rt_uint32_t start, now, delta, reload, us_tick;
  59. start = SysTick->VAL;
  60. reload = SysTick->LOAD;
  61. us_tick = SystemCoreClock / 1000000UL;
  62. do
  63. {
  64. now = SysTick->VAL;
  65. delta = start >= now ? start - now : reload + start - now;
  66. }
  67. while (delta < us_tick * us);
  68. }