From f97d24ff667472c08f365494ad9396b1253a34d6 Mon Sep 17 00:00:00 2001 From: Steve Gotthardt Date: Sat, 20 Jan 2007 22:16:01 +0000 Subject: 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 --- firmware/target/arm/gigabeat/meg-fx/i2c-meg-fx.c | 12 ++++++-- firmware/target/arm/gigabeat/meg-fx/sc606-meg-fx.c | 33 ++++++++++++---------- 2 files changed, 27 insertions(+), 18 deletions(-) (limited to 'firmware/target/arm') 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) } + 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 */ 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 @@ #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) @@ -99,13 +102,13 @@ static void sc606_i2c_outb(unsigned char byte) int i; /* clock out each bit, MSB first */ - for (i = 0x80; i; i >>= 1) + for (i = 0x80; i; i >>= 1) { - if (i & byte) + if (i & byte) { SDA_HI; - } - else + } + else { SDA_LO; } @@ -154,10 +157,10 @@ int sc606_write(unsigned char reg, unsigned char data) int x; sc606_i2c_start(); - + sc606_i2c_outb(SLAVE_ADDRESS); x = sc606_i2c_getack(); - + sc606_i2c_outb(reg); x += sc606_i2c_getack(); @@ -168,7 +171,7 @@ int sc606_write(unsigned char reg, unsigned char data) sc606_i2c_outb(data); x += sc606_i2c_getack(); - + sc606_i2c_stop(); return x; @@ -183,10 +186,10 @@ int sc606_read(unsigned char reg, unsigned char* data) sc606_i2c_start(); sc606_i2c_outb(SLAVE_ADDRESS); x = sc606_i2c_getack(); - + sc606_i2c_outb(reg); x += sc606_i2c_getack(); - + sc606_i2c_restart(); sc606_i2c_outb(SLAVE_ADDRESS | 1); x += sc606_i2c_getack(); @@ -202,7 +205,7 @@ int sc606_read(unsigned char reg, unsigned char* data) void sc606_init(void) { volatile int i; - + /* Set GPB2 (EN) to 1 */ GPBCON = (GPBCON & ~(3<<4)) | 1<<4; -- cgit v1.2.3