diff options
author | Keith Packard <keithp@keithp.com> | 2012-05-18 20:13:05 -0700 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2012-05-18 20:19:18 -0700 |
commit | c1ad8f443d5a9780a9897c79deda61241c0e34c2 (patch) | |
tree | d00b897c91fbccc54e249d2682ed9273cf8986ff /src/stm/ao_i2c_stm.c | |
parent | 5d8b9d524d6424ff98dcc4155fe8b8bd892b6d8f (diff) |
altos: Provide ISR-based code paths for SPIserial-at-interrupt
This allows SPI to be entirely interrupt driven, with callbacks for
completion. It's not tested yet...
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/stm/ao_i2c_stm.c')
-rw-r--r-- | src/stm/ao_i2c_stm.c | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/stm/ao_i2c_stm.c b/src/stm/ao_i2c_stm.c index 763ae6cd..73587aac 100644 --- a/src/stm/ao_i2c_stm.c +++ b/src/stm/ao_i2c_stm.c @@ -32,6 +32,7 @@ struct ao_i2c_stm_info { static uint8_t ao_i2c_state[STM_NUM_I2C]; static uint16_t ao_i2c_addr[STM_NUM_I2C]; uint8_t ao_i2c_mutex[STM_NUM_I2C]; +static void (*ao_i2c_callback[STM_NUM_I2C])(uint8_t index); #define AO_STM_I2C_CR1 ((0 << STM_I2C_CR1_SWRST) | \ (0 << STM_I2C_CR1_ALERT) | \ @@ -182,8 +183,8 @@ static inline void out_dr(char *where, struct stm_i2c *stm_i2c, uint32_t dr) { stm_i2c->dr = dr; } -uint8_t -ao_i2c_start(uint8_t index, uint16_t addr) +void +ao_i2c_queue_start(uint8_t index, uint16_t addr) { struct stm_i2c *stm_i2c = ao_i2c_stm_info[index].stm_i2c; uint32_t sr1, sr2; @@ -196,9 +197,28 @@ ao_i2c_start(uint8_t index, uint16_t addr) AO_STM_I2C_CR1 | (1 << STM_I2C_CR1_START)); out_cr2("start", stm_i2c, AO_STM_I2C_CR2 | (1 << STM_I2C_CR2_ITEVTEN) | (1 << STM_I2C_CR2_ITERREN)); +} + +void +ao_i2c_set_start_callback(uint8_t index, void (*callback)(uint8_t index)) +{ + +} + +uint8_t +ao_i2c_is_idle(uint8_t index) +{ + return ao_i2c_state[index] == I2C_IDLE; +} + +uint8_t +ao_i2c_start(uint8_t index, uint16_t addr) +{ + ao_i2c_queue_start(index, addr); + ao_alarm(1); cli(); - while (ao_i2c_state[index] == I2C_IDLE) + while (ao_i2c_is_idle(index)) if (ao_sleep(&ao_i2c_state[index])) break; sei(); |