diff options
author | Steve Gotthardt <gotthardt@rockbox.org> | 2007-01-20 22:16:01 +0000 |
---|---|---|
committer | Steve Gotthardt <gotthardt@rockbox.org> | 2007-01-20 22:16:01 +0000 |
commit | f97d24ff667472c08f365494ad9396b1253a34d6 (patch) | |
tree | 885d478de3a891773f302159994de07dee7ac378 | |
parent | a398f35fccc3e23500bf030c1a8d10b4e44dfef1 (diff) | |
download | rockbox-f97d24ff667472c08f365494ad9396b1253a34d6.tar.gz rockbox-f97d24ff667472c08f365494ad9396b1253a34d6.zip |
Retimed the i2c delay loops since we can be boosted or not
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12084 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | firmware/target/arm/gigabeat/meg-fx/i2c-meg-fx.c | 12 | ||||
-rw-r--r-- | firmware/target/arm/gigabeat/meg-fx/sc606-meg-fx.c | 33 |
2 files changed, 27 insertions, 18 deletions
diff --git a/firmware/target/arm/gigabeat/meg-fx/i2c-meg-fx.c b/firmware/target/arm/gigabeat/meg-fx/i2c-meg-fx.c index 7667c03e38..fd5d9577a3 100644 --- a/firmware/target/arm/gigabeat/meg-fx/i2c-meg-fx.c +++ b/firmware/target/arm/gigabeat/meg-fx/i2c-meg-fx.c | |||
@@ -81,18 +81,24 @@ static void i2c_scl_hi(void) | |||
81 | } | 81 | } |
82 | 82 | ||
83 | 83 | ||
84 | |||
84 | static void i2c_delay(void) | 85 | static void i2c_delay(void) |
85 | { | 86 | { |
86 | volatile int _x; | 87 | unsigned _x; |
87 | 88 | ||
88 | /* The i2c can clock at 500KHz: 2uS period -> 1uS half period */ | 89 | /* The i2c can clock at 500KHz: 2uS period -> 1uS half period */ |
89 | /* At 300Mhz - if loop takes 10 cycles @ 3.3nS each -> 1uS / 33nS -> 30 */ | 90 | /* about 30 cycles overhead + X * 7 */ |
90 | for (_x=0; _x<30; _x++) | 91 | /* 300MHz: 1000nS @3.36nS/cyc = 297cyc: X = 38*/ |
92 | /* 100MHz: 1000nS @10nS/cyc = 100cyc : X = 10 */ | ||
93 | for (_x = get_cpu_boost_counter() ? 38 : 10; _x; _x--) | ||
91 | { | 94 | { |
92 | /* burn CPU cycles */ | 95 | /* burn CPU cycles */ |
96 | /* gcc makes it an inc loop - check with objdump for asm timing */ | ||
93 | } | 97 | } |
94 | } | 98 | } |
95 | 99 | ||
100 | |||
101 | |||
96 | struct i2c_interface s3c2440_i2c = { | 102 | struct i2c_interface s3c2440_i2c = { |
97 | 0x34, /* Address */ | 103 | 0x34, /* Address */ |
98 | 104 | ||
diff --git a/firmware/target/arm/gigabeat/meg-fx/sc606-meg-fx.c b/firmware/target/arm/gigabeat/meg-fx/sc606-meg-fx.c index 6ca64a0437..d4e061a0c7 100644 --- a/firmware/target/arm/gigabeat/meg-fx/sc606-meg-fx.c +++ b/firmware/target/arm/gigabeat/meg-fx/sc606-meg-fx.c | |||
@@ -24,12 +24,15 @@ | |||
24 | 24 | ||
25 | #define SCL_SDA_HI (GPHDAT |= (3 << 9)) | 25 | #define SCL_SDA_HI (GPHDAT |= (3 << 9)) |
26 | 26 | ||
27 | /* The SC606 can clock at 400KHz: 2.5uS period -> 1.25uS half period */ | 27 | /* The SC606 can clock at 400KHz: */ |
28 | /* Clock period high is 600nS and low is 1300nS */ | ||
28 | /* The high and low times are different enough to need different timings */ | 29 | /* The high and low times are different enough to need different timings */ |
29 | /* At 300Mhz - one loop takes about 10 cycles */ | 30 | /* cycles delayed = 30 + 7 * loops */ |
30 | #define DELAY_LO do { volatile int _x; for(_x=0;_x<20;_x++);} while (0) | 31 | /* 100MHz = 10nS per cycle: LO:1300nS=130:14 HI:600nS=60:9 */ |
31 | #define DELAY do { volatile int _x; for(_x=0;_x<15;_x++);} while (0) | 32 | /* 300MHz = 3.36nS per cycle: LO:1300nS=387:51 HI:600nS=179:21 */ |
32 | #define DELAY_HI do { volatile int _x; for(_x=0;_x<10;_x++);} while (0) | 33 | #define DELAY_LO do{int x;for(x=get_cpu_boost_counter()?51:14;x;x--);} while (0) |
34 | #define DELAY do{int x;for(x=get_cpu_boost_counter()?35:10;x;x--);} while (0) | ||
35 | #define DELAY_HI do{int x;for(x=get_cpu_boost_counter()?21: 9;x;x--);} while (0) | ||
33 | 36 | ||
34 | 37 | ||
35 | 38 | ||
@@ -99,13 +102,13 @@ static void sc606_i2c_outb(unsigned char byte) | |||
99 | int i; | 102 | int i; |
100 | 103 | ||
101 | /* clock out each bit, MSB first */ | 104 | /* clock out each bit, MSB first */ |
102 | for (i = 0x80; i; i >>= 1) | 105 | for (i = 0x80; i; i >>= 1) |
103 | { | 106 | { |
104 | if (i & byte) | 107 | if (i & byte) |
105 | { | 108 | { |
106 | SDA_HI; | 109 | SDA_HI; |
107 | } | 110 | } |
108 | else | 111 | else |
109 | { | 112 | { |
110 | SDA_LO; | 113 | SDA_LO; |
111 | } | 114 | } |
@@ -154,10 +157,10 @@ int sc606_write(unsigned char reg, unsigned char data) | |||
154 | int x; | 157 | int x; |
155 | 158 | ||
156 | sc606_i2c_start(); | 159 | sc606_i2c_start(); |
157 | 160 | ||
158 | sc606_i2c_outb(SLAVE_ADDRESS); | 161 | sc606_i2c_outb(SLAVE_ADDRESS); |
159 | x = sc606_i2c_getack(); | 162 | x = sc606_i2c_getack(); |
160 | 163 | ||
161 | sc606_i2c_outb(reg); | 164 | sc606_i2c_outb(reg); |
162 | x += sc606_i2c_getack(); | 165 | x += sc606_i2c_getack(); |
163 | 166 | ||
@@ -168,7 +171,7 @@ int sc606_write(unsigned char reg, unsigned char data) | |||
168 | 171 | ||
169 | sc606_i2c_outb(data); | 172 | sc606_i2c_outb(data); |
170 | x += sc606_i2c_getack(); | 173 | x += sc606_i2c_getack(); |
171 | 174 | ||
172 | sc606_i2c_stop(); | 175 | sc606_i2c_stop(); |
173 | 176 | ||
174 | return x; | 177 | return x; |
@@ -183,10 +186,10 @@ int sc606_read(unsigned char reg, unsigned char* data) | |||
183 | sc606_i2c_start(); | 186 | sc606_i2c_start(); |
184 | sc606_i2c_outb(SLAVE_ADDRESS); | 187 | sc606_i2c_outb(SLAVE_ADDRESS); |
185 | x = sc606_i2c_getack(); | 188 | x = sc606_i2c_getack(); |
186 | 189 | ||
187 | sc606_i2c_outb(reg); | 190 | sc606_i2c_outb(reg); |
188 | x += sc606_i2c_getack(); | 191 | x += sc606_i2c_getack(); |
189 | 192 | ||
190 | sc606_i2c_restart(); | 193 | sc606_i2c_restart(); |
191 | sc606_i2c_outb(SLAVE_ADDRESS | 1); | 194 | sc606_i2c_outb(SLAVE_ADDRESS | 1); |
192 | x += sc606_i2c_getack(); | 195 | x += sc606_i2c_getack(); |
@@ -202,7 +205,7 @@ int sc606_read(unsigned char reg, unsigned char* data) | |||
202 | void sc606_init(void) | 205 | void sc606_init(void) |
203 | { | 206 | { |
204 | volatile int i; | 207 | volatile int i; |
205 | 208 | ||
206 | /* Set GPB2 (EN) to 1 */ | 209 | /* Set GPB2 (EN) to 1 */ |
207 | GPBCON = (GPBCON & ~(3<<4)) | 1<<4; | 210 | GPBCON = (GPBCON & ~(3<<4)) | 1<<4; |
208 | 211 | ||