board.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. /**
  19. * @addtogroup FM3
  20. */
  21. /*@{*/
  22. /**
  23. * This is the timer interrupt service routine.
  24. *
  25. */
  26. void SysTick_Handler(void)
  27. {
  28. /* enter interrupt */
  29. rt_interrupt_enter();
  30. rt_tick_increase();
  31. /* leave interrupt */
  32. rt_interrupt_leave();
  33. }
  34. /**
  35. * This fucntion returns milliseconds since system passed
  36. */
  37. rt_uint32_t rt_hw_tick_get_millisecond(void)
  38. {
  39. rt_tick_t tick;
  40. rt_uint32_t value;
  41. #define TICK_MS (1000/RT_TICK_PER_SECOND)
  42. tick = rt_tick_get();
  43. value = tick * TICK_MS + (SysTick->LOAD - SysTick->VAL) * TICK_MS / SysTick->LOAD;
  44. return value;
  45. }
  46. /**
  47. * This fucntion returns microseconds since system passed
  48. */
  49. rt_uint32_t rt_hw_tick_get_microsecond(void)
  50. {
  51. rt_tick_t tick;
  52. rt_uint32_t value;
  53. #define TICK_US (1000000/RT_TICK_PER_SECOND)
  54. tick = rt_tick_get();
  55. value = tick * TICK_US + (SysTick->LOAD - SysTick->VAL) * TICK_US / SysTick->LOAD;
  56. return value;
  57. }
  58. /**
  59. * This function will initial FM3 Easy Kit board.
  60. */
  61. void rt_hw_board_init(void)
  62. {
  63. /* disable all analog input. */
  64. FM3_GPIO->ADE = 0;
  65. /* init systick */
  66. SysTick_Config(SystemCoreClock/RT_TICK_PER_SECOND);
  67. /* initialize UART device */
  68. rt_hw_serial_init();
  69. /* set console as UART device */
  70. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  71. #ifdef RT_USING_COMPONENTS_INIT
  72. rt_components_board_init();
  73. #endif
  74. }
  75. /*@}*/