timer0.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * File : timer0.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006-2015, RT-Thread Development Team
  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. * Change Logs:
  21. * Date Author Notes
  22. * 2015-04-29 ArdaFu first version
  23. */
  24. #include "timer0.h"
  25. #include "asm9260t.h"
  26. #include "rtthread.h"
  27. void hw_timer0_init(void)
  28. {
  29. uint32_t pclk;
  30. // enable timer0's clock, reset timer0
  31. outl((1<<4), REG_SET(HW_AHBCLKCTRL1));
  32. outl((1<<4), REG_CLR(HW_PRESETCTRL1));
  33. outl((1<<4), REG_SET(HW_PRESETCTRL1));
  34. outl((1<<0), REG_CLR(HW_TIMER0_TCR));
  35. outl((3<<0), REG_CLR(HW_TIMER0_CTCR));
  36. outl((3<<0), REG_CLR(HW_TIMER0_DIR));
  37. outl(0, REG_CLR(HW_TIMER0_PR));
  38. outl(0, REG_CLR(HW_TIMER0_PC));
  39. outl((7<<0), REG_CLR(HW_TIMER0_MCR));
  40. outl((3<<0), REG_SET(HW_TIMER0_MCR));
  41. pclk = (inl(HW_SYSPLLCTRL)&0x1FF)*1000000u/4u;
  42. outl(pclk/RT_TICK_PER_SECOND, HW_TIMER0_MR0);
  43. outl((1<<4), REG_SET(HW_TIMER0_TCR));
  44. outl((1<<4), REG_CLR(HW_TIMER0_TCR));
  45. outl((1<<0), REG_SET(HW_TIMER0_TCR));
  46. }