I2C. Fix one potential problem in driver, but main problem with stack overflow still not solved.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3124 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
2303c1542c
commit
ff535c27e6
|
@ -48,10 +48,6 @@ static void i2c_serve_event_interrupt(I2CDriver *i2cp) {
|
|||
#define txBuffp (i2cp->txbuff_p)
|
||||
#define rxBuffp (i2cp->rxbuff_p)
|
||||
|
||||
/* debug variables */
|
||||
uint16_t sr1 = 0;
|
||||
uint16_t sr2 = 0;
|
||||
|
||||
I2C_TypeDef *dp = i2cp->id_i2c;
|
||||
|
||||
switch(i2c_get_event(i2cp)) {
|
||||
|
@ -206,14 +202,24 @@ static void i2c_serve_event_interrupt(I2CDriver *i2cp) {
|
|||
/* Portable I2C ISR code defined in the high level driver, note, it is a macro.*/
|
||||
_i2c_isr_code(i2cp, i2cp->id_slave_config);
|
||||
break;
|
||||
case I2C_FLG_MASTER_RECEIVER:
|
||||
/* Here we trapped in case of interrupt "lost" when 2 bytes received.
|
||||
* because STM32 I2C has ORed interrupt sources */
|
||||
if (i2cp->rxbytes > 4){
|
||||
*rxBuffp = dp->DR;
|
||||
rxBuffp++;
|
||||
/* Decrement the number of readed bytes */
|
||||
(i2cp->rxbytes)--;
|
||||
}
|
||||
else{
|
||||
/* something going too wrong*/
|
||||
port_halt();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
sr1 = regSR1;
|
||||
sr2 = regSR2;
|
||||
// chDbgAssert(FALSE, "i2c_serve_event_interrupt(), #1", "unhandled flags");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
#undef rxBuffp
|
||||
#undef txBuffp
|
||||
}
|
||||
|
@ -668,7 +674,7 @@ void i2c_lld_master_receive(I2CDriver *i2cp, uint16_t slave_addr,
|
|||
}
|
||||
|
||||
|
||||
/* TODO: doxy strings or remove this redundant function */
|
||||
/** TODO: doxy strings or remove this redundant function */
|
||||
void i2c_lld_master_transceive(I2CDriver *i2cp){
|
||||
|
||||
i2cp->flags = I2C_FLG_MASTER_RECEIVER;
|
||||
|
|
|
@ -71,7 +71,7 @@
|
|||
#define I2C_EV8_2_MASTER_BYTE_TRANSMITTED ((uint32_t)(((I2C_SR2_MSL|I2C_SR2_BUSY|I2C_SR2_TRA)<< 16)|I2C_SR1_BTF|I2C_SR1_TXE)) /* TRA, BUSY, MSL, TXE and BTF flags */
|
||||
/** @brief EV9 */
|
||||
#define I2C_EV9_MASTER_ADDR_10BIT ((uint32_t)(((I2C_SR2_MSL|I2C_SR2_BUSY)<< 16)|I2C_SR1_ADD10)) /* BUSY, MSL and ADD10 flags */
|
||||
#define I2C_EV_MASK 0x00FFFFFF
|
||||
#define I2C_EV_MASK 0x00FFFFFF /* First byte zeroed because there is no need of PEC register part from SR2 */
|
||||
|
||||
#define I2C_FLG_1BTR 0x01 /* Single byte to be received and processed */
|
||||
#define I2C_FLG_2BTR 0x02 /* Two bytes to be received and processed */
|
||||
|
@ -164,15 +164,15 @@ struct I2CDriver{
|
|||
*/
|
||||
const I2CSlaveConfig *id_slave_config;
|
||||
|
||||
size_t txbytes; /*!< Number of bytes to be transmitted. */
|
||||
size_t rxbytes; /*!< Number of bytes to be received. */
|
||||
__IO size_t txbytes; /*!< Number of bytes to be transmitted. */
|
||||
__IO size_t rxbytes; /*!< Number of bytes to be received. */
|
||||
uint8_t *rxbuf; /*!< Pointer to receive buffer. */
|
||||
uint8_t *txbuf; /*!< Pointer to transmit buffer.*/
|
||||
uint8_t *rxbuff_p; /*!< Pointer to the current byte in slave rx buffer. */
|
||||
uint8_t *txbuff_p; /*!< Pointer to the current byte in slave tx buffer. */
|
||||
|
||||
i2cflags_t errors; /*!< Error flags.*/
|
||||
i2cflags_t flags; /*!< State flags.*/
|
||||
__IO i2cflags_t errors; /*!< Error flags.*/
|
||||
__IO i2cflags_t flags; /*!< State flags.*/
|
||||
|
||||
uint16_t slave_addr; /*!< Current slave address. */
|
||||
uint8_t slave_addr1;/*!< 7-bit address of the slave with r\w bit.*/
|
||||
|
|
Loading…
Reference in New Issue