board.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * COPYRIGHT (C) 2013-2014, Shanghai Real-Thread Technology Co., Ltd
  3. *
  4. * All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. */
  20. #include <rthw.h>
  21. #include <rtthread.h>
  22. #include <components.h>
  23. #include "board.h"
  24. typedef struct
  25. {
  26. volatile rt_uint32_t LOAD;
  27. volatile rt_uint32_t COUNTER;
  28. volatile rt_uint32_t CONTROL;
  29. volatile rt_uint32_t ISR;
  30. } ptimer_reg_t;
  31. /* Values for control register */
  32. #define PRIVATE_TIMER_CONTROL_PRESCALER_MASK 0x0000FF00
  33. #define PRIVATE_TIMER_CONTROL_PRESCALER_SHIFT 8
  34. #define PRIVATE_TIMER_CONTROL_IRQ_ENABLE_MASK 0x00000004
  35. #define PRIVATE_TIMER_CONTROL_AUTO_RELOAD_MASK 0x00000002
  36. #define PRIVATE_TIMER_CONTROL_ENABLE_MASK 0x00000001
  37. /* Values for ISR register */
  38. #define PRIVATE_TIMER_ISR_EVENT_FLAG_MASK 0x00000001
  39. #define PRIVATE_TIMER_BASE 0xF8F00600
  40. #define PRIVATE_TIMER ((ptimer_reg_t*)PRIVATE_TIMER_BASE)
  41. static void rt_hw_timer_isr(int vector, void *param)
  42. {
  43. rt_tick_increase();
  44. /* clear interrupt */
  45. PRIVATE_TIMER->ISR = PRIVATE_TIMER_ISR_EVENT_FLAG_MASK;
  46. }
  47. int rt_hw_timer_init(void)
  48. {
  49. PRIVATE_TIMER->CONTROL &= ~PRIVATE_TIMER_CONTROL_ENABLE_MASK;
  50. {
  51. /* Clear the prescaler. */
  52. rt_uint32_t ctrl = PRIVATE_TIMER->CONTROL;
  53. ctrl &= ~PRIVATE_TIMER_CONTROL_PRESCALER_MASK;
  54. PRIVATE_TIMER->CONTROL = ctrl;
  55. }
  56. /* The processor timer is always clocked at 1/2 CPU frequency(CPU_3x2x). */
  57. PRIVATE_TIMER->COUNTER = APU_FREQ/2/RT_TICK_PER_SECOND;
  58. /* Set reload value. */
  59. PRIVATE_TIMER->LOAD = APU_FREQ/2/RT_TICK_PER_SECOND;
  60. PRIVATE_TIMER->CONTROL |= PRIVATE_TIMER_CONTROL_AUTO_RELOAD_MASK;
  61. PRIVATE_TIMER->CONTROL |= PRIVATE_TIMER_CONTROL_IRQ_ENABLE_MASK;
  62. PRIVATE_TIMER->ISR = PRIVATE_TIMER_ISR_EVENT_FLAG_MASK;
  63. rt_hw_interrupt_install(IRQ_Zynq7000_PTIMER, rt_hw_timer_isr, RT_NULL, "tick");
  64. rt_hw_interrupt_umask(IRQ_Zynq7000_PTIMER);
  65. PRIVATE_TIMER->CONTROL |= PRIVATE_TIMER_CONTROL_ENABLE_MASK;
  66. return 0;
  67. }
  68. INIT_BOARD_EXPORT(rt_hw_timer_init);
  69. void rt_hw_board_init()
  70. {
  71. rt_components_board_init();
  72. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  73. }