From 35e9ec0c03a150e3fe6a3350549573e4c02be67b Mon Sep 17 00:00:00 2001 From: Leo C Date: Sun, 24 Aug 2014 14:16:18 +0200 Subject: getenv_ulong(), TWI int opt --- avr/i2c.c | 91 +++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 50 insertions(+), 41 deletions(-) (limited to 'avr/i2c.c') diff --git a/avr/i2c.c b/avr/i2c.c index df97fea..3ab222a 100644 --- a/avr/i2c.c +++ b/avr/i2c.c @@ -99,12 +99,17 @@ uint8_t buf[CONFIG_SYS_I2C_BUFSIZE]; } i2c_msg_t; -static i2c_msg_t xmit; +static volatile i2c_msg_t xmit; ISR(TWI_vect) { - uint8_t next_twcr; + uint8_t tmp_stat; uint8_t tmp_idx; + uint8_t next_twcr; + uint8_t n; + + tmp_idx = xmit.idx; + tmp_stat = xmit.stat; uint8_t twsr = TWSR; @@ -112,62 +117,59 @@ ISR(TWI_vect) case TWI_START: case TWI_REP_START: - xmit.idx = 0; /* reset xmit_buf index */ - xmit.stat = BUSY | START; + tmp_stat = BUSY | START; + tmp_idx = 0; /* reset xmit_buf index */ - tmp_idx = xmit.idx; if (tmp_idx < xmit.len) { /* all bytes transmited? */ TWDR = xmit.buf[tmp_idx]; - xmit.idx = ++tmp_idx; + ++tmp_idx; next_twcr = (1< 255) { - tmptwbr >>= 4; + while (tmp_twbr > 255) { + tmp_twbr >>= 4; twps += 1; } - debug_cond((twps > 3), "TWCLK too low: %lu Hz\n", speed); + debug_cond((twps > 3), "*** TWCLK too low: %lu Hz\n", speed); + + twbr = (uint8_t) tmp_twbr; + + debug("*** i2c_init: i2c_speed: %lu, twbr: %u, twps: %u\n", + speed, twbr, twps); - twbr = (uint8_t) tmptwbr; _init(); } -- cgit v1.2.3