board.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 "board.h"
  23. typedef struct
  24. {
  25. volatile rt_uint32_t LOAD;
  26. volatile rt_uint32_t COUNTER;
  27. volatile rt_uint32_t CONTROL;
  28. volatile rt_uint32_t ISR;
  29. } ptimer_reg_t;
  30. /* Values for control register */
  31. #define PRIVATE_TIMER_CONTROL_PRESCALER_MASK 0x0000FF00
  32. #define PRIVATE_TIMER_CONTROL_PRESCALER_SHIFT 8
  33. #define PRIVATE_TIMER_CONTROL_IRQ_ENABLE_MASK 0x00000004
  34. #define PRIVATE_TIMER_CONTROL_AUTO_RELOAD_MASK 0x00000002
  35. #define PRIVATE_TIMER_CONTROL_ENABLE_MASK 0x00000001
  36. /* Values for ISR register */
  37. #define PRIVATE_TIMER_ISR_EVENT_FLAG_MASK 0x00000001
  38. #define PRIVATE_TIMER_BASE 0xF8F00600
  39. #define PRIVATE_TIMER ((ptimer_reg_t*)PRIVATE_TIMER_BASE)
  40. static void rt_hw_timer_isr(int vector, void *param)
  41. {
  42. rt_tick_increase();
  43. /* clear interrupt */
  44. PRIVATE_TIMER->ISR = PRIVATE_TIMER_ISR_EVENT_FLAG_MASK;
  45. }
  46. int rt_hw_timer_init(void)
  47. {
  48. PRIVATE_TIMER->CONTROL &= ~PRIVATE_TIMER_CONTROL_ENABLE_MASK;
  49. {
  50. /* Clear the prescaler. */
  51. rt_uint32_t ctrl = PRIVATE_TIMER->CONTROL;
  52. ctrl &= ~PRIVATE_TIMER_CONTROL_PRESCALER_MASK;
  53. PRIVATE_TIMER->CONTROL = ctrl;
  54. }
  55. /* The processor timer is always clocked at 1/2 CPU frequency(CPU_3x2x). */
  56. PRIVATE_TIMER->COUNTER = APU_FREQ/2/RT_TICK_PER_SECOND;
  57. /* Set reload value. */
  58. PRIVATE_TIMER->LOAD = APU_FREQ/2/RT_TICK_PER_SECOND;
  59. PRIVATE_TIMER->CONTROL |= PRIVATE_TIMER_CONTROL_AUTO_RELOAD_MASK;
  60. PRIVATE_TIMER->CONTROL |= PRIVATE_TIMER_CONTROL_IRQ_ENABLE_MASK;
  61. PRIVATE_TIMER->ISR = PRIVATE_TIMER_ISR_EVENT_FLAG_MASK;
  62. rt_hw_interrupt_install(IRQ_Zynq7000_PTIMER, rt_hw_timer_isr, RT_NULL, "tick");
  63. rt_hw_interrupt_umask(IRQ_Zynq7000_PTIMER);
  64. PRIVATE_TIMER->CONTROL |= PRIVATE_TIMER_CONTROL_ENABLE_MASK;
  65. return 0;
  66. }
  67. INIT_BOARD_EXPORT(rt_hw_timer_init);
  68. void rt_hw_board_init()
  69. {
  70. rt_components_board_init();
  71. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  72. }