summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaurus Cuelenaere <mcuelenaere@gmail.com>2009-06-03 22:52:54 +0000
committerMaurus Cuelenaere <mcuelenaere@gmail.com>2009-06-03 22:52:54 +0000
commit398e1059c50a659b08b8a7bf997c24ee0217b8ee (patch)
tree8ab084975379557ea61fb0315e13f0232693556d
parent63bc7c9009045c7280e1b59577fca7e43c09112e (diff)
downloadrockbox-398e1059c50a659b08b8a7bf997c24ee0217b8ee.tar.gz
rockbox-398e1059c50a659b08b8a7bf997c24ee0217b8ee.zip
Ingenic Jz4740: should fix timer (thanks to Rafaël Carré)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21184 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/target/mips/ingenic_jz47xx/timer-jz4740.c50
-rw-r--r--firmware/target/mips/ingenic_jz47xx/timer-target.h4
2 files changed, 27 insertions, 27 deletions
diff --git a/firmware/target/mips/ingenic_jz47xx/timer-jz4740.c b/firmware/target/mips/ingenic_jz47xx/timer-jz4740.c
index 94ecc3afd4..54ea17a063 100644
--- a/firmware/target/mips/ingenic_jz47xx/timer-jz4740.c
+++ b/firmware/target/mips/ingenic_jz47xx/timer-jz4740.c
@@ -28,69 +28,67 @@
28void TCU1(void) 28void TCU1(void)
29{ 29{
30 __tcu_clear_full_match_flag(1); 30 __tcu_clear_full_match_flag(1);
31 31
32 if (pfn_timer != NULL) 32 if (pfn_timer != NULL)
33 pfn_timer(); 33 pfn_timer();
34} 34}
35 35
36/* TODO: figure out what cycles means */
37bool __timer_set(long cycles, bool start) 36bool __timer_set(long cycles, bool start)
38{ 37{
39 unsigned int latch, old_irq; 38 unsigned int divider = cycles, prescaler_bit = 0, prescaler = 1, old_irq;
40 39
41 if(cycles < 1) 40 if(cycles < 1)
42 return false; 41 return false;
43 42
44 if (start && pfn_unregister != NULL) 43 if(start && pfn_unregister != NULL)
45 { 44 {
46 pfn_unregister(); 45 pfn_unregister();
47 pfn_unregister = NULL; 46 pfn_unregister = NULL;
48 } 47 }
49 48
50 old_irq = disable_irq_save(); 49 old_irq = disable_irq_save();
51 50
52 __tcu_stop_counter(1); 51 __tcu_stop_counter(1);
53 __tcu_disable_pwm_output(1); 52 __tcu_disable_pwm_output(1);
54 53
55 __tcu_mask_half_match_irq(1); 54 __tcu_mask_half_match_irq(1);
56 __tcu_unmask_full_match_irq(1); 55 __tcu_unmask_full_match_irq(1);
57 56
58 /* EXTAL clock = 12Mhz */ 57 /* EXTAL clock = CFG_EXTAL (12Mhz in most targets) */
59 __tcu_select_extalclk(1); 58 __tcu_select_extalclk(1);
60 /* 12Mhz / 4 = 3Mhz */
61 __tcu_select_clk_div4(1);
62
63 latch = cycles;
64 59
60 /* Increase prescale values starting from 0 to make the cycle count fit */
61 while(divider > 65535 && prescaler <= 1024)
62 {
63 prescaler >>= 2; /* 1, 4, 16, 64, 256, 1024 */
64 prescaler_bit++;
65 divider = cycles / prescaler;
66 }
67
68 REG_TCU_TCSR(1) = (REG_TCU_TCSR(1) & ~TCU_TCSR_PRESCALE_MASK) | (prescaler_bit << TCU_TCSR_PRESCALE_BIT);
65 REG_TCU_TCNT(1) = 0; 69 REG_TCU_TCNT(1) = 0;
66 REG_TCU_TDFR(1) = latch; 70 REG_TCU_TDHR(1) = 0;
67 REG_TCU_TDHR(1) = latch; 71 REG_TCU_TDFR(1) = divider;
68 72
69 __tcu_clear_full_match_flag(1); 73 __tcu_clear_full_match_flag(1);
70 74
71 system_enable_irq(IRQ_TCU1); 75 system_enable_irq(IRQ_TCU1);
72 76
73 restore_irq(old_irq); 77 restore_irq(old_irq);
74 78
75 return true; 79 return true;
76} 80}
77 81
78bool __timer_register(void) 82bool __timer_register(void)
79{ 83{
80 unsigned int old_irq = disable_irq_save();
81
82 __tcu_start_counter(1); 84 __tcu_start_counter(1);
83 85
84 restore_irq(old_irq);
85
86 return true; 86 return true;
87} 87}
88 88
89void __timer_unregister(void) 89void __timer_unregister(void)
90{ 90{
91 unsigned int old_irq = disable_irq_save(); 91 unsigned int old_irq = disable_irq_save();
92
93 __tcu_stop_counter(1); 92 __tcu_stop_counter(1);
94
95 restore_irq(old_irq); 93 restore_irq(old_irq);
96} 94}
diff --git a/firmware/target/mips/ingenic_jz47xx/timer-target.h b/firmware/target/mips/ingenic_jz47xx/timer-target.h
index 202f941ce1..40942d4b4c 100644
--- a/firmware/target/mips/ingenic_jz47xx/timer-target.h
+++ b/firmware/target/mips/ingenic_jz47xx/timer-target.h
@@ -22,7 +22,9 @@
22#ifndef __TIMER_H_ 22#ifndef __TIMER_H_
23#define __TIMER_H_ 23#define __TIMER_H_
24 24
25#define TIMER_FREQ (27000000) 25#include "config.h"
26
27#define TIMER_FREQ (CFG_EXTAL) /* For full precision! */
26 28
27bool __timer_set(long cycles, bool set); 29bool __timer_set(long cycles, bool set);
28bool __timer_register(void); 30bool __timer_register(void);