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
11 #include "timer0.h"
12 #include "asm9260t.h"
13 #include "rtthread.h"
hw_timer0_init(void)14 void hw_timer0_init(void)
15 {
16 uint32_t pclk;
17
18 // enable timer0's clock, reset timer0
19 outl((1<<4), REG_SET(HW_AHBCLKCTRL1));
20 outl((1<<4), REG_CLR(HW_PRESETCTRL1));
21 outl((1<<4), REG_SET(HW_PRESETCTRL1));
22
23 outl((1<<0), REG_CLR(HW_TIMER0_TCR));
24
25 outl((3<<0), REG_CLR(HW_TIMER0_CTCR));
26
27 outl((3<<0), REG_CLR(HW_TIMER0_DIR));
28
29 outl(0, REG_CLR(HW_TIMER0_PR));
30 outl(0, REG_CLR(HW_TIMER0_PC));
31
32 outl((7<<0), REG_CLR(HW_TIMER0_MCR));
33 outl((3<<0), REG_SET(HW_TIMER0_MCR));
34
35 pclk = (inl(HW_SYSPLLCTRL)&0x1FF)*1000000u/4u;
36 outl(pclk/RT_TICK_PER_SECOND, HW_TIMER0_MR0);
37
38 outl((1<<4), REG_SET(HW_TIMER0_TCR));
39 outl((1<<4), REG_CLR(HW_TIMER0_TCR));
40 outl((1<<0), REG_SET(HW_TIMER0_TCR));
41 }
42