1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Steve Gotthardt 2007-01-20 22:16:01 +00:00
parent a398f35fcc
commit f97d24ff66
2 changed files with 27 additions and 18 deletions

View file

@ -81,18 +81,24 @@ static void i2c_scl_hi(void)
}
static void i2c_delay(void)
{
volatile int _x;
unsigned _x;
/* The i2c can clock at 500KHz: 2uS period -> 1uS half period */
/* At 300Mhz - if loop takes 10 cycles @ 3.3nS each -> 1uS / 33nS -> 30 */
for (_x=0; _x<30; _x++)
/* about 30 cycles overhead + X * 7 */
/* 300MHz: 1000nS @3.36nS/cyc = 297cyc: X = 38*/
/* 100MHz: 1000nS @10nS/cyc = 100cyc : X = 10 */
for (_x = get_cpu_boost_counter() ? 38 : 10; _x; _x--)
{
/* burn CPU cycles */
/* gcc makes it an inc loop - check with objdump for asm timing */
}
}
struct i2c_interface s3c2440_i2c = {
0x34, /* Address */

View file

@ -24,12 +24,15 @@
#define SCL_SDA_HI (GPHDAT |= (3 << 9))
/* The SC606 can clock at 400KHz: 2.5uS period -> 1.25uS half period */
/* The SC606 can clock at 400KHz: */
/* Clock period high is 600nS and low is 1300nS */
/* The high and low times are different enough to need different timings */
/* At 300Mhz - one loop takes about 10 cycles */
#define DELAY_LO do { volatile int _x; for(_x=0;_x<20;_x++);} while (0)
#define DELAY do { volatile int _x; for(_x=0;_x<15;_x++);} while (0)
#define DELAY_HI do { volatile int _x; for(_x=0;_x<10;_x++);} while (0)
/* cycles delayed = 30 + 7 * loops */
/* 100MHz = 10nS per cycle: LO:1300nS=130:14 HI:600nS=60:9 */
/* 300MHz = 3.36nS per cycle: LO:1300nS=387:51 HI:600nS=179:21 */
#define DELAY_LO do{int x;for(x=get_cpu_boost_counter()?51:14;x;x--);} while (0)
#define DELAY do{int x;for(x=get_cpu_boost_counter()?35:10;x;x--);} while (0)
#define DELAY_HI do{int x;for(x=get_cpu_boost_counter()?21: 9;x;x--);} while (0)