From 04a63b0d5660f1c0c0b7e8123e4f56d188e52a5d Mon Sep 17 00:00:00 2001 From: Leo C Date: Wed, 17 Sep 2014 22:23:17 +0200 Subject: Disable all peripheral functions globally. Enable used functions when needed. --- avr/i2c.c | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) (limited to 'avr/i2c.c') diff --git a/avr/i2c.c b/avr/i2c.c index dbb5da1..e0e5a19 100644 --- a/avr/i2c.c +++ b/avr/i2c.c @@ -1,6 +1,6 @@ -/* - * I2C (TWI) master interface. +/* + * I2C (TWI) master interface. */ #include "common.h" @@ -48,33 +48,33 @@ * TWSTO: TWI STOP Condition Bit * TWEN: TWI Enable Bit * TWIE: TWI Interrupt Enable - * + * * (1< 255) { tmp_twbr >>= 4; twps += 1; @@ -231,6 +231,8 @@ void i2c_init(uint32_t speed) debug_cond((twps > 3), "*** TWCLK too low: %lu Hz\n", speed); twbr = (uint8_t) tmp_twbr; + + PRR0 &= ~_BV(PRTWI); _init(); } @@ -239,7 +241,7 @@ int_fast8_t i2c_waitready(void) { uint32_t timer = get_timer(0); uint8_t timeout = 0; - + do { if (get_timer(timer) >= 30) { timeout = TIMEOUT; @@ -252,7 +254,7 @@ int_fast8_t i2c_waitready(void) #if DEBUG_I2C dump_ram((uint8_t *) &xmit, 4, "=== i2c_wait ready: (done)"); _delay_ms(30); -#endif +#endif return xmit.stat; } @@ -275,11 +277,11 @@ int i2c_send(uint8_t chip, uint16_t addr, uint8_t alen, uint8_t *buffer, int8_t for (n = len + i; i < n; i++) xmit.buf[i] = *buffer++; xmit.len = i; - + #if DEBUG_I2C dump_ram((uint8_t *) &xmit, 0x20, "=== i2c_send"); _delay_ms(30); -#endif +#endif /* Enable TWI, TWI int and initiate start condition */ TWCR = (1< 2) || (1 + alen + len > CONFIG_SYS_I2C_BUFSIZE)) { debug("** i2c_write: buffer overflow, alen: %u, len: %u\n", alen, len); return -1; } - + i2c_send(chip, addr, alen, buffer, len); rc = i2c_waitready(); @@ -362,10 +364,10 @@ int i2c_read(uint8_t chip, unsigned int addr, uint_fast8_t alen, alen, len); return -1; } - + if (alen != 0) { i2c_send(chip, addr, alen, NULL, 0); - } + } rc = i2c_recv(chip, buffer, len); return !((rc & (XMIT_DONE|DATA_ACK)) == (XMIT_DONE|DATA_ACK)); -- cgit v1.2.3