board.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2011-02-24 Bernard first implementation
  9. */
  10. #include <rthw.h>
  11. #include <rtthread.h>
  12. #include "board.h"
  13. #include "serial.h"
  14. /**
  15. * @addtogroup FM4
  16. */
  17. /*@{*/
  18. /**
  19. * This is the timer interrupt service routine.
  20. *
  21. */
  22. void SysTick_Handler(void)
  23. {
  24. /* enter interrupt */
  25. rt_interrupt_enter();
  26. rt_tick_increase();
  27. /* leave interrupt */
  28. rt_interrupt_leave();
  29. }
  30. /**
  31. * This fucntion returns milliseconds since system passed
  32. */
  33. rt_uint32_t rt_hw_tick_get_millisecond(void)
  34. {
  35. rt_tick_t tick;
  36. rt_uint32_t value;
  37. #define TICK_MS (1000/RT_TICK_PER_SECOND)
  38. tick = rt_tick_get();
  39. value = tick * TICK_MS + (SysTick->LOAD - SysTick->VAL) * TICK_MS / SysTick->LOAD;
  40. return value;
  41. }
  42. /**
  43. * This fucntion returns microseconds since system passed
  44. */
  45. rt_uint32_t rt_hw_tick_get_microsecond(void)
  46. {
  47. rt_tick_t tick;
  48. rt_uint32_t value;
  49. #define TICK_US (1000000/RT_TICK_PER_SECOND)
  50. tick = rt_tick_get();
  51. value = tick * TICK_US + (SysTick->LOAD - SysTick->VAL) * TICK_US / SysTick->LOAD;
  52. return value;
  53. }
  54. /**
  55. * This function will initial FM3 Easy Kit board.
  56. */
  57. void rt_hw_board_init(void)
  58. {
  59. /* disable all analog input. */
  60. FM4_GPIO->ADE = 0x00u;
  61. /* init systick */
  62. SysTick_Config(SystemCoreClock/RT_TICK_PER_SECOND);
  63. /* initialize UART device */
  64. rt_hw_serial_init();
  65. /* set console as UART device */
  66. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  67. #ifdef RT_USING_COMPONENTS_INIT
  68. rt_components_board_init();
  69. #endif
  70. }
  71. /*@}*/