aboutsummaryrefslogtreecommitdiffstats
path: root/os
diff options
context:
space:
mode:
authorbarthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4>2011-07-06 13:54:56 +0000
committerbarthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4>2011-07-06 13:54:56 +0000
commitff535c27e64be34157fa37908bac9b9d460eaf57 (patch)
tree02454302ff2a9854d8fe6ef5acbe8aa8942d0eeb /os
parent2303c1542cc8d15b960272a90a48780da126a584 (diff)
downloadChibiOS-ff535c27e64be34157fa37908bac9b9d460eaf57.tar.gz
ChibiOS-ff535c27e64be34157fa37908bac9b9d460eaf57.tar.bz2
ChibiOS-ff535c27e64be34157fa37908bac9b9d460eaf57.zip
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
Diffstat (limited to 'os')
-rw-r--r--os/hal/platforms/STM32/i2c_lld.c26
-rw-r--r--os/hal/platforms/STM32/i2c_lld.h12
2 files changed, 22 insertions, 16 deletions
diff --git a/os/hal/platforms/STM32/i2c_lld.c b/os/hal/platforms/STM32/i2c_lld.c
index 5a07630ae..1c80cdb2f 100644
--- a/os/hal/platforms/STM32/i2c_lld.c
+++ b/os/hal/platforms/STM32/i2c_lld.c
@@ -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;
}
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;
diff --git a/os/hal/platforms/STM32/i2c_lld.h b/os/hal/platforms/STM32/i2c_lld.h
index 8285cddcf..b41f8f6fa 100644
--- a/os/hal/platforms/STM32/i2c_lld.h
+++ b/os/hal/platforms/STM32/i2c_lld.h
@@ -63,7 +63,7 @@
#define I2C_EV6_MASTER_TRA_MODE_SELECTED ((uint32_t)(((I2C_SR2_MSL|I2C_SR2_BUSY|I2C_SR2_TRA)<< 16)|I2C_SR1_ADDR|I2C_SR1_TXE)) /* BUSY, MSL, ADDR, TXE and TRA flags */
#define I2C_EV6_MASTER_REC_MODE_SELECTED ((uint32_t)(((I2C_SR2_MSL|I2C_SR2_BUSY)<< 16)|I2C_SR1_ADDR)) /* BUSY, MSL and ADDR flags */
/** @brief EV7 */
-#define I2C_EV7_MASTER_REC_BYTE_RECEIVED ((uint32_t)(((I2C_SR2_MSL|I2C_SR2_BUSY)<< 16)|I2C_SR1_RXNE)) /* BUSY, MSL and RXNE flags */
+#define I2C_EV7_MASTER_REC_BYTE_RECEIVED ((uint32_t)(((I2C_SR2_MSL|I2C_SR2_BUSY)<< 16)|I2C_SR1_RXNE)) /* BUSY, MSL and RXNE flags */
#define I2C_EV7_MASTER_REC_BYTE_QUEUED ((uint32_t)(((I2C_SR2_MSL|I2C_SR2_BUSY)<< 16)|I2C_SR1_BTF|I2C_SR1_RXNE)) /* BUSY, MSL, RXNE and BTF flags*/
/** @brief EV8 */
#define I2C_EV8_MASTER_BYTE_TRANSMITTING ((uint32_t)(((I2C_SR2_MSL|I2C_SR2_BUSY|I2C_SR2_TRA)<< 16)|I2C_SR1_TXE)) /* TRA, BUSY, MSL, TXE flags */
@@ -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.*/