diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/target/mips/ingenic_jz47xx/timer-jz4740.c | 70 |
1 files changed, 67 insertions, 3 deletions
diff --git a/firmware/target/mips/ingenic_jz47xx/timer-jz4740.c b/firmware/target/mips/ingenic_jz47xx/timer-jz4740.c index 00c8abcdbd..dc02aede0e 100644 --- a/firmware/target/mips/ingenic_jz47xx/timer-jz4740.c +++ b/firmware/target/mips/ingenic_jz47xx/timer-jz4740.c | |||
@@ -21,8 +21,72 @@ | |||
21 | 21 | ||
22 | #include "config.h" | 22 | #include "config.h" |
23 | #include "jz4740.h" | 23 | #include "jz4740.h" |
24 | #include "system.h" | ||
25 | #include "timer.h" | ||
24 | 26 | ||
27 | /* Interrupt handler */ | ||
28 | void TCU1(void) | ||
29 | { | ||
30 | __tcu_clear_full_match_flag(1); | ||
31 | |||
32 | if (pfn_timer != NULL) | ||
33 | pfn_timer(); | ||
34 | } | ||
25 | 35 | ||
26 | bool __timer_set(long cycles, bool set); | 36 | /* TODO: figure out what cycles means */ |
27 | bool __timer_register(void); | 37 | bool __timer_set(long cycles, bool start) |
28 | void __timer_unregister(void); | 38 | { |
39 | unsigned int latch, old_irq; | ||
40 | |||
41 | if(cycles < 1) | ||
42 | return false; | ||
43 | |||
44 | if (start && pfn_unregister != NULL) | ||
45 | { | ||
46 | pfn_unregister(); | ||
47 | pfn_unregister = NULL; | ||
48 | } | ||
49 | |||
50 | old_irq = disable_irq_save(); | ||
51 | |||
52 | __tcu_stop_counter(1); | ||
53 | __tcu_disable_pwm_output(1); | ||
54 | |||
55 | __tcu_mask_half_match_irq(1); | ||
56 | __tcu_unmask_full_match_irq(1); | ||
57 | |||
58 | /* EXTAL clock = 12Mhz */ | ||
59 | __tcu_select_extalclk(1); | ||
60 | /* 12Mhz / 4 = 3Mhz */ | ||
61 | __tcu_select_clk_div4(1); | ||
62 | |||
63 | latch = cycles; | ||
64 | |||
65 | REG_TCU_TCNT(1) = 0; | ||
66 | REG_TCU_TDFR(1) = latch; | ||
67 | REG_TCU_TDHR(1) = latch; | ||
68 | |||
69 | __tcu_clear_full_match_flag(1); | ||
70 | |||
71 | system_enable_irq(IRQ_TCU1); | ||
72 | |||
73 | restore_irq(old_irq); | ||
74 | } | ||
75 | |||
76 | bool __timer_register(void) | ||
77 | { | ||
78 | unsigned int old_irq = disable_irq_save(); | ||
79 | |||
80 | __tcu_start_counter(1); | ||
81 | |||
82 | restore_irq(old_irq); | ||
83 | } | ||
84 | |||
85 | void __timer_unregister(void) | ||
86 | { | ||
87 | unsigned int old_irq = disable_irq_save(); | ||
88 | |||
89 | __tcu_stop_counter(1); | ||
90 | |||
91 | restore_irq(old_irq); | ||
92 | } | ||