timer0.c 1009 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2015-04-29 ArdaFu first version
  9. */
  10. #include "timer0.h"
  11. #include "asm9260t.h"
  12. #include "rtthread.h"
  13. void hw_timer0_init(void)
  14. {
  15. uint32_t pclk;
  16. // enable timer0's clock, reset timer0
  17. outl((1<<4), REG_SET(HW_AHBCLKCTRL1));
  18. outl((1<<4), REG_CLR(HW_PRESETCTRL1));
  19. outl((1<<4), REG_SET(HW_PRESETCTRL1));
  20. outl((1<<0), REG_CLR(HW_TIMER0_TCR));
  21. outl((3<<0), REG_CLR(HW_TIMER0_CTCR));
  22. outl((3<<0), REG_CLR(HW_TIMER0_DIR));
  23. outl(0, REG_CLR(HW_TIMER0_PR));
  24. outl(0, REG_CLR(HW_TIMER0_PC));
  25. outl((7<<0), REG_CLR(HW_TIMER0_MCR));
  26. outl((3<<0), REG_SET(HW_TIMER0_MCR));
  27. pclk = (inl(HW_SYSPLLCTRL)&0x1FF)*1000000u/4u;
  28. outl(pclk/RT_TICK_PER_SECOND, HW_TIMER0_MR0);
  29. outl((1<<4), REG_SET(HW_TIMER0_TCR));
  30. outl((1<<4), REG_CLR(HW_TIMER0_TCR));
  31. outl((1<<0), REG_SET(HW_TIMER0_TCR));
  32. }