ao_i2c_state[index] = I2C_IDLE;
ao_i2c_addr[index] = addr;
- printf ("start sr1: %x\n", stm_i2c->sr1);
out_cr2("start", stm_i2c, AO_STM_I2C_CR2);
out_cr1("start", stm_i2c,
AO_STM_I2C_CR1 | (1 << STM_I2C_CR1_START));
}
static void
-ao_i2c_stop(uint8_t index)
+ao_i2c_wait_stop(uint8_t index)
{
struct stm_i2c *stm_i2c = ao_i2c_stm_info[index].stm_i2c;
-
- ao_i2c_state[index] = I2C_IDLE;
- out_cr2("enable isr", stm_i2c,
- AO_STM_I2C_CR2 | (1 << STM_I2C_CR2_ITEVTEN) | (1 << STM_I2C_CR2_ITERREN));
- ev_count = 0;
- out_cr1("stop", stm_i2c, AO_STM_I2C_CR1 | (1 << STM_I2C_CR1_STOP));
+ int t;
- /* XXX check to see if there is an interrupt here */
- while (in_cr1("stop", stm_i2c) & (1 << STM_I2C_CR1_STOP))
+ for (t = 0; t < I2C_TIMEOUT; t++) {
+ if (!(in_cr1("wait stop", stm_i2c) & (1 << STM_I2C_CR1_STOP)))
+ break;
ao_yield();
- printf ("ev_count in stop: %d\n", ev_count);
+ }
+ ao_i2c_state[index] = I2C_IDLE;
}
uint8_t
ao_alarm(1 + len);
cli();
while (!ao_dma_done[tx_dma_index])
- if (ao_sleep(&ao_dma_done[tx_dma_index])) {
- printf ("send timeout\n");
+ if (ao_sleep(&ao_dma_done[tx_dma_index]))
break;
- }
+ ao_clear_alarm();
ao_dma_done_transfer(tx_dma_index);
out_cr2("send enable isr", stm_i2c,
AO_STM_I2C_CR2 | (1 << STM_I2C_CR2_ITEVTEN) | (1 << STM_I2C_CR2_ITERREN));
break;
out_cr2("send disable isr", stm_i2c, AO_STM_I2C_CR2);
sei();
- if (stop)
- ao_i2c_stop(index);
+ if (stop) {
+ out_cr1("stop", stm_i2c, AO_STM_I2C_CR1 | (1 << STM_I2C_CR1_STOP));
+ ao_i2c_wait_stop(index);
+ }
return TRUE;
}
ao_dma_done_transfer(rx_dma_index);
out_cr1("stop recv > 1", stm_i2c, AO_STM_I2C_CR1 | (1 << STM_I2C_CR1_STOP));
}
- if (stop) {
- for (t = 0; t < I2C_TIMEOUT; t++) {
- if (!(in_cr1("recv stop", stm_i2c) & (1 << STM_I2C_CR1_STOP)))
- break;
- ao_yield();
- }
- if (t == I2C_TIMEOUT)
- return FALSE;
- }
+ if (stop)
+ ao_i2c_wait_stop(index);
return ret;
}
ao_i2c_channel_init(uint8_t index)
{
struct stm_i2c *stm_i2c = ao_i2c_stm_info[index].stm_i2c;
+ int i;
/* Turn I2C off while configuring */
+ stm_i2c->cr1 = (1 << STM_I2C_CR1_SWRST);
+ for (i = 0; i < 100; i++)
+ asm("nop");
stm_i2c->cr1 = 0;
stm_i2c->cr2 = AO_STM_I2C_CR2;