board.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * File : board.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2009 - 2011 RT-Thread Develop Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2011-02-24 Bernard first implementation
  13. */
  14. #include <rthw.h>
  15. #include <rtthread.h>
  16. #include "board.h"
  17. #include "serial.h"
  18. #ifdef RT_USING_COMPONENTS_INIT
  19. #include <components.h>
  20. #endif /* RT_USING_COMPONENTS_INIT */
  21. /**
  22. * @addtogroup FM3
  23. */
  24. /*@{*/
  25. /**
  26. * This is the timer interrupt service routine.
  27. *
  28. */
  29. void SysTick_Handler(void)
  30. {
  31. /* enter interrupt */
  32. rt_interrupt_enter();
  33. rt_tick_increase();
  34. /* leave interrupt */
  35. rt_interrupt_leave();
  36. }
  37. /**
  38. * This fucntion returns milliseconds since system passed
  39. */
  40. rt_uint32_t rt_hw_tick_get_millisecond(void)
  41. {
  42. rt_tick_t tick;
  43. rt_uint32_t value;
  44. #define TICK_MS (1000/RT_TICK_PER_SECOND)
  45. tick = rt_tick_get();
  46. value = tick * TICK_MS + (SysTick->LOAD - SysTick->VAL) * TICK_MS / SysTick->LOAD;
  47. return value;
  48. }
  49. /**
  50. * This fucntion returns microseconds since system passed
  51. */
  52. rt_uint32_t rt_hw_tick_get_microsecond(void)
  53. {
  54. rt_tick_t tick;
  55. rt_uint32_t value;
  56. #define TICK_US (1000000/RT_TICK_PER_SECOND)
  57. tick = rt_tick_get();
  58. value = tick * TICK_US + (SysTick->LOAD - SysTick->VAL) * TICK_US / SysTick->LOAD;
  59. return value;
  60. }
  61. /**
  62. * This function will initial FM3 Easy Kit board.
  63. */
  64. void rt_hw_board_init(void)
  65. {
  66. /* disable all analog input. */
  67. FM3_GPIO->ADE = 0;
  68. /* init systick */
  69. SysTick_Config(SystemCoreClock/RT_TICK_PER_SECOND);
  70. /* initialize UART device */
  71. rt_hw_serial_init();
  72. /* set console as UART device */
  73. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  74. #ifdef RT_USING_COMPONENTS_INIT
  75. rt_components_board_init();
  76. #endif
  77. }
  78. /*@}*/