paparazzi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[paparazzi-commits] [5782] breaking I2C - don't update now, work in prog


From: antoine drouin
Subject: [paparazzi-commits] [5782] breaking I2C - don't update now, work in progress
Date: Thu, 02 Sep 2010 14:34:44 +0000

Revision: 5782
          http://svn.sv.gnu.org/viewvc/?view=rev&root=paparazzi&revision=5782
Author:   poine
Date:     2010-09-02 14:34:44 +0000 (Thu, 02 Sep 2010)
Log Message:
-----------
breaking I2C - don't update now, work in progress

Modified Paths:
--------------
    paparazzi3/trunk/sw/airborne/boards/lisa_l/baro_board.c
    paparazzi3/trunk/sw/airborne/boards/lisa_l/baro_board.h
    paparazzi3/trunk/sw/airborne/i2c.c
    paparazzi3/trunk/sw/airborne/i2c.h
    paparazzi3/trunk/sw/airborne/stm32/i2c_hw.c

Modified: paparazzi3/trunk/sw/airborne/boards/lisa_l/baro_board.c
===================================================================
--- paparazzi3/trunk/sw/airborne/boards/lisa_l/baro_board.c     2010-09-02 
14:18:52 UTC (rev 5781)
+++ paparazzi3/trunk/sw/airborne/boards/lisa_l/baro_board.c     2010-09-02 
14:34:44 UTC (rev 5782)
@@ -3,7 +3,9 @@
 
 struct Baro baro;
 struct BaroBoard baro_board;
+struct i2c_transaction baro_trans;
 
+
 static inline void baro_board_write_to_register(uint8_t baro_addr, uint8_t 
reg_addr, uint8_t val_msb, uint8_t val_lsb);
 static inline void baro_board_read_from_register(uint8_t baro_addr, uint8_t 
reg_addr);
 static inline void baro_board_set_current_register(uint8_t baro_addr, uint8_t 
reg_addr);
@@ -63,11 +65,6 @@
 }
 
 
-void baro_board_send_reset(void) {
-  i2c2.buf[0] = 0x06;
-  i2c2_transmit(0x00, 1, &baro_board.i2c_done);
-}
-
 void baro_board_send_config_abs(void) {
   baro_board_write_to_register(BARO_ABS_ADDR, 0x01, 0x86, 0x83);
 }
@@ -76,23 +73,49 @@
   baro_board_write_to_register(BARO_DIFF_ADDR, 0x01, 0x84, 0x83);
 }
 
+void baro_board_send_reset(void) {
+  baro_trans.type = I2CTransTx;
+  baro_trans.slave_addr = 0x00;
+  baro_trans.len_w = 1;
+  baro_trans.buf[0] = 0x06;
+  i2c_submit(&i2c2,&baro_trans);
+}
+
 static inline void baro_board_write_to_register(uint8_t baro_addr, uint8_t 
reg_addr, uint8_t val_msb, uint8_t val_lsb) {
-  i2c2.buf[0] = reg_addr;
-  i2c2.buf[1] = val_msb;
-  i2c2.buf[2] = val_lsb;
-  i2c2_transmit(baro_addr, 3, &baro_board.i2c_done);
+  baro_trans.type = I2CTransTx;
+  baro_trans.slave_addr = baro_addr;
+  baro_trans.len_w = 3;
+  baro_trans.buf[0] = reg_addr;
+  baro_trans.buf[1] = val_msb;
+  baro_trans.buf[2] = val_lsb;
+  i2c_submit(&i2c2,&baro_trans);
 }
 
 static inline void baro_board_read_from_register(uint8_t baro_addr, uint8_t 
reg_addr) {
-  i2c2.buf[0] = reg_addr;
-  i2c2_transceive(baro_addr, 1, 2, &baro_board.i2c_done);
+  baro_trans.type = I2CTransTxRx;
+  baro_trans.slave_addr = baro_addr;
+  baro_trans.len_w = 1;
+  baro_trans.len_r = 2;
+  baro_trans.buf[0] = reg_addr;
+  i2c_submit(&i2c2,&baro_trans);
+  //  i2c2.buf[0] = reg_addr;
+  //  i2c2_transceive(baro_addr, 1, 2, &baro_board.i2c_done);
 }
 
 static inline void baro_board_set_current_register(uint8_t baro_addr, uint8_t 
reg_addr) {
-  i2c2.buf[0] = reg_addr;
-  i2c2_transmit(baro_addr, 1, &baro_board.i2c_done);
+  baro_trans.type = I2CTransTx;
+  baro_trans.slave_addr = baro_addr;
+  baro_trans.len_w = 1;
+  baro_trans.buf[0] = reg_addr;
+  i2c_submit(&i2c2,&baro_trans);
+  //  i2c2.buf[0] = reg_addr;
+  //  i2c2_transmit(baro_addr, 1, &baro_board.i2c_done);
 }
 
 static inline void baro_board_read_from_current_register(uint8_t baro_addr) {
-  i2c2_receive(baro_addr, 2, &baro_board.i2c_done);
+  baro_trans.type = I2CTransRx;
+  baro_trans.slave_addr = baro_addr;
+  baro_trans.len_r = 2;
+  i2c_submit(&i2c2,&baro_trans);
+  //  i2c2_receive(baro_addr, 2, &baro_board.i2c_done);
 }

Modified: paparazzi3/trunk/sw/airborne/boards/lisa_l/baro_board.h
===================================================================
--- paparazzi3/trunk/sw/airborne/boards/lisa_l/baro_board.h     2010-09-02 
14:18:52 UTC (rev 5781)
+++ paparazzi3/trunk/sw/airborne/boards/lisa_l/baro_board.h     2010-09-02 
14:34:44 UTC (rev 5782)
@@ -26,24 +26,26 @@
 
 struct BaroBoard {
   enum LisaBaroStatus status;
-  bool_t i2c_done;
 };
 
 extern struct BaroBoard baro_board;
+extern struct i2c_transaction baro_trans;
 
 extern void baro_board_send_reset(void);
 extern void baro_board_send_config_abs(void);
 extern void baro_board_send_config_diff(void);
 
 #define BaroEvent(_b_abs_handler, _b_diff_handler) {                   \
-    if (baro_board.status == LBS_READING_ABS && baro_board.i2c_done) { \
-      int16_t tmp = i2c2.buf[0]<<8 | i2c2.buf[1];                      \
+    if (baro_board.status == LBS_READING_ABS &&                                
\
+       baro_trans.result == I2CTransSuccess) {                         \
+      int16_t tmp = baro_trans.buf[0]<<8 | baro_trans.buf[1];          \
       baro.absolute = tmp;                                             \
       baro_board.status = LBS_READ_ABS;                                        
\
       _b_abs_handler();                                                        
\
     }                                                                  \
-    else  if (baro_board.status == LBS_READING_DIFF && baro_board.i2c_done) { \
-      int16_t tmp = i2c2.buf[0]<<8 | i2c2.buf[1];                      \
+    else  if (baro_board.status == LBS_READING_DIFF &&                 \
+             baro_trans.result == I2CTransSuccess) {                   \
+      int16_t tmp = baro_trans.buf[0]<<8 | baro_trans.buf[1];          \
       baro.differential = tmp;                                         \
       baro_board.status = LBS_READ_DIFF;                               \
       _b_diff_handler();                                               \

Modified: paparazzi3/trunk/sw/airborne/i2c.c
===================================================================
--- paparazzi3/trunk/sw/airborne/i2c.c  2010-09-02 14:18:52 UTC (rev 5781)
+++ paparazzi3/trunk/sw/airborne/i2c.c  2010-09-02 14:34:44 UTC (rev 5782)
@@ -124,14 +124,19 @@
 
 #include "booz/booz2_debug.h"
 
-struct i2c i2c2;
+struct i2c_periph i2c2;
 
+//struct i2c i2c2;
+
 void i2c2_init(void) {
-  i2c2.status = I2CIdle;
-  i2c2.finished = NULL;
+  //  i2c2.status = I2CIdle;
+  //  i2c2.finished = NULL;
+  //  i2c2_hw_init();
+  i2c_init(&i2c2);
   i2c2_hw_init();
 }
 
+#if 0
 void i2c2_receive(uint8_t slave_addr, uint8_t len, volatile bool_t* finished) {
   i2c2.transaction = I2CTransRx;
   i2c2.slave_addr = slave_addr;
@@ -178,9 +183,16 @@
   I2C_ITConfig(I2C2, I2C_IT_EVT, ENABLE);
   I2C_GenerateSTART(I2C2, ENABLE);
 }
+#endif
 
-struct i2c_periph i2c2;
+void   i2c_init(struct i2c_periph* p) {
 
+  p->trans_insert_idx = 0;
+  p->trans_extract_idx = 0;
+  p->status = I2CIdle;
 
+}
+
+
 #endif /* USE_I2C2 */
 

Modified: paparazzi3/trunk/sw/airborne/i2c.h
===================================================================
--- paparazzi3/trunk/sw/airborne/i2c.h  2010-09-02 14:18:52 UTC (rev 5781)
+++ paparazzi3/trunk/sw/airborne/i2c.h  2010-09-02 14:34:44 UTC (rev 5782)
@@ -52,8 +52,8 @@
 struct i2c_periph {
   /* circular buffer holding transactions */
   struct i2c_transaction* trans[I2C_TRANSACTION_QUEUE_LEN];
-  uint8_t trans_insert_index;
-  uint8_t trans_extract_index;
+  uint8_t trans_insert_idx;
+  uint8_t trans_extract_idx;
   /* internal state of the peripheral */
   volatile enum I2CStatus status;
   volatile uint8_t idx_buf;
@@ -248,19 +248,20 @@
 #ifdef USE_I2C2
 
 
-extern struct i2c_periph i2c2;
+//extern struct i2c i2c2;
 
 extern void i2c2_init(void);
-extern void i2c2_receive(uint8_t slave_addr, uint8_t len, volatile bool_t* 
finished);
-extern void i2c2_transmit(uint8_t slave_addr, uint8_t len, volatile bool_t* 
finished);
-extern void i2c2_transceive(uint8_t slave_addr, uint8_t len_w, uint16_t len_r, 
volatile bool_t* finished);
+//extern void i2c2_receive(uint8_t slave_addr, uint8_t len, volatile bool_t* 
finished);
+//extern void i2c2_transmit(uint8_t slave_addr, uint8_t len, volatile bool_t* 
finished);
+//extern void i2c2_transceive(uint8_t slave_addr, uint8_t len_w, uint16_t 
len_r, volatile bool_t* finished);
 
+extern struct i2c_periph i2c2;
+
+
+
 #endif /* USE_I2C2 */
 
-extern struct i2c_periph i2c2;
-
 extern void   i2c_init(struct i2c_periph* p);
 extern bool_t i2c_submit(struct i2c_periph* p, struct i2c_transaction* t);
 
-
 #endif /* I2C_H */

Modified: paparazzi3/trunk/sw/airborne/stm32/i2c_hw.c
===================================================================
--- paparazzi3/trunk/sw/airborne/stm32/i2c_hw.c 2010-09-02 14:18:52 UTC (rev 
5781)
+++ paparazzi3/trunk/sw/airborne/stm32/i2c_hw.c 2010-09-02 14:34:44 UTC (rev 
5782)
@@ -340,17 +340,18 @@
  */
 static inline void on_status_start_requested(uint32_t event) {
   if (event & I2C_FLAG_SB) {
-    if(i2c2.transaction == I2CTransRx) {
-      I2C_Send7bitAddress(I2C2, i2c2.slave_addr, I2C_Direction_Receiver);
+    struct i2c_transaction* trans = i2c2.trans[i2c2.trans_extract_idx];
+    if(trans->type == I2CTransRx) {
+      I2C_Send7bitAddress(I2C2, trans->slave_addr, I2C_Direction_Receiver);
       i2c2.status = I2CAddrRdSent;
     }
-    else {                                             
-      I2C_Send7bitAddress(I2C2, i2c2.slave_addr, I2C_Direction_Transmitter);
-      i2c2.status = I2CAddrWrSent;             
-    }                                          
-  }                                            
-  else                                 
-    SPURIOUS_INTERRUPT(I2CStartRequested, event);      
+    else {
+      I2C_Send7bitAddress(I2C2, trans->slave_addr, I2C_Direction_Transmitter);
+      i2c2.status = I2CAddrWrSent;
+    }                          
+  }                            
+  else
+    SPURIOUS_INTERRUPT(I2CStartRequested, event);
 }
 
 /*
@@ -359,16 +360,17 @@
  */
 static inline void on_status_addr_wr_sent(uint32_t event) {
   if ((event & I2C_FLAG_ADDR) && (event & I2C_FLAG_TRA)) {
-    I2C_SendData(I2C2, i2c2.buf[0]);
-    if (i2c2.len_w > 1) {
-      I2C_SendData(I2C2, i2c2.buf[1]);
-      i2c2.index = 2;
+    struct i2c_transaction* trans = i2c2.trans[i2c2.trans_extract_idx];
+    I2C_SendData(I2C2, trans->buf[0]);
+    if (trans->len_w > 1) {
+      I2C_SendData(I2C2, trans->buf[1]);
+      i2c2.idx_buf = 2;
       I2C_ITConfig(I2C2, I2C_IT_BUF, ENABLE);
       i2c2.status = I2CSendingByte;
     }
     else {
-      i2c2.index = 1;
-      if (i2c2.transaction == I2CTransTx) {
+      i2c2.idx_buf = 1;
+      if (trans->type == I2CTransTx) {
        I2C_GenerateSTOP(I2C2, ENABLE); 
        i2c2.status = I2CStopRequested;
       }
@@ -388,13 +390,14 @@
  */
 static inline void on_status_sending_byte(uint32_t event) {
   if (event & I2C_FLAG_TXE) {
-    if (i2c2.index < i2c2.len_w) {                         
-      I2C_SendData(I2C2, i2c2.buf[i2c2.index]);
-      i2c2.index++;
+    struct i2c_transaction* trans = i2c2.trans[i2c2.trans_extract_idx];
+    if (i2c2.idx_buf < trans->len_w) {                         
+      I2C_SendData(I2C2, trans->buf[i2c2.idx_buf]);
+      i2c2.idx_buf++;
     }
     else { 
       I2C_ITConfig(I2C2, I2C_IT_BUF, DISABLE);
-      if (i2c2.transaction == I2CTransTx) {
+      if (trans->type == I2CTransTx) {
        I2C_GenerateSTOP(I2C2, ENABLE); 
        i2c2.status = I2CStopRequested;
       }
@@ -415,7 +418,8 @@
  */
 static inline void on_status_sending_last_byte(uint32_t event) {
   if (event & I2C_FLAG_TXE) {     // should really be BTF as we're supposed to 
have disabled buf it already
-    if (i2c2.transaction == I2CTransTx) {
+    struct i2c_transaction* trans = i2c2.trans[i2c2.trans_extract_idx];
+    if (trans->type == I2CTransTx) {
       I2C_GenerateSTOP(I2C2, ENABLE);
       i2c2.status = I2CStopRequested;
     }
@@ -437,15 +441,17 @@
  */
 static inline void on_status_stop_requested(uint32_t event) {
   /* bummer.... */
+  struct i2c_transaction* trans = i2c2.trans[i2c2.trans_extract_idx];
   if (event & I2C_FLAG_RXNE) {     
     uint8_t read_byte =  I2C_ReceiveData(I2C2);
-    if (i2c2.index < i2c2.len_r) {                               
-      i2c2.buf[i2c2.index] = read_byte;
+    if (i2c2.idx_buf < trans->len_r) {                               
+      trans->buf[i2c2.idx_buf] = read_byte;
     }
   }
   I2C_ITConfig(I2C2, I2C_IT_EVT|I2C_IT_BUF, DISABLE);  // should only need to 
disable evt, buf already disabled
-  if (i2c2.finished) *i2c2.finished = TRUE;
-  i2c2.status = I2CComplete;
+  // FIXME : lancer la transaction suivante
+  trans->result = I2CTransSuccess;
+  i2c2.status = I2CIdle;
 }
 
 /*
@@ -454,8 +460,9 @@
  */
 static inline void on_status_addr_rd_sent(uint32_t event) {
   if ((event & I2C_FLAG_ADDR) && !(event & I2C_FLAG_TRA)) {
-    i2c2.index = 0;  
-    if(i2c2.len_r == 1) {                                         // If we're 
going to read only one byte
+    struct i2c_transaction* trans = i2c2.trans[i2c2.trans_extract_idx];
+    i2c2.idx_buf = 0;  
+    if(trans->len_r == 1) {                                         // If 
we're going to read only one byte
       I2C_AcknowledgeConfig(I2C2, DISABLE);                       // make sure 
it's gonna be nacked 
       I2C_GenerateSTOP(I2C2, ENABLE);                             // and 
followed by a stop
       i2c2.status = I2CReadingLastByte;                           // and 
remember we did
@@ -477,11 +484,12 @@
  */
 static inline void on_status_reading_byte(uint32_t event) {
   if (event & I2C_FLAG_RXNE) {          
+    struct i2c_transaction* trans = i2c2.trans[i2c2.trans_extract_idx];
     uint8_t read_byte =  I2C_ReceiveData(I2C2);
-    if (i2c2.index < i2c2.len_r) {                               
-      i2c2.buf[i2c2.index] = read_byte;
-      i2c2.index++;
-      if (i2c2.index >= i2c2.len_r-1) {                        // We're 
reading our last byte
+    if (i2c2.idx_buf < trans->len_r) {                               
+      trans->buf[i2c2.idx_buf] = read_byte;
+      i2c2.idx_buf++;
+      if (i2c2.idx_buf >= trans->len_r-1) {                    // We're 
reading our last byte
        I2C_AcknowledgeConfig(I2C2, DISABLE);                  // give them a 
nack once it's done
        I2C_GenerateSTOP(I2C2, ENABLE);                        // and follow 
with a stop
        i2c2.status = I2CStopRequested;                        // remember we 
already trigered the stop
@@ -497,15 +505,16 @@
  *
  */
 static inline void on_status_reading_last_byte(uint32_t event) {
+  struct i2c_transaction* trans = i2c2.trans[i2c2.trans_extract_idx];
   if (event & I2C_FLAG_BTF) {
     uint8_t read_byte =  I2C_ReceiveData(I2C2);
-    i2c2.buf[i2c2.index] = read_byte;
+    trans->buf[i2c2.idx_buf] = read_byte;
     I2C_GenerateSTOP(I2C2, ENABLE);
     i2c2.status = I2CStopRequested;   
   }
   else if (event & I2C_FLAG_RXNE) {       // should really be BTF ?   
     uint8_t read_byte =  I2C_ReceiveData(I2C2);
-    i2c2.buf[i2c2.index] = read_byte;
+    trans->buf[i2c2.idx_buf] = read_byte;
     i2c2.status = I2CStopRequested;   
   }
   else
@@ -517,10 +526,11 @@
  *
  */
 static inline void on_status_restart_requested(uint32_t event) {
+  struct i2c_transaction* trans = i2c2.trans[i2c2.trans_extract_idx];
   //  DEBUG_S6_ON();
   if (event & I2C_FLAG_SB) {
     //    DEBUG_S2_ON();
-    I2C_Send7bitAddress(I2C2, i2c2.slave_addr, I2C_Direction_Receiver);
+    I2C_Send7bitAddress(I2C2, trans->slave_addr, I2C_Direction_Receiver);
     i2c2.status = I2CAddrRdSent;
     //    DEBUG_S2_OFF();
   }
@@ -610,9 +620,8 @@
 
 
 #define I2C2_ABORT_AND_RESET() {                                       \
-                                                                       \
-    if (i2c2.finished)                                                 \
-      *(i2c2.finished) = TRUE;                                         \
+    struct i2c_transaction* trans = i2c2.trans[i2c2.trans_extract_idx];        
\
+    trans->result = I2CTransFailed;                                    \
     i2c2.status = I2CFailed;                                           \
     I2C_ITConfig(I2C2, I2C_IT_EVT | I2C_IT_BUF | I2C_IT_ERR, DISABLE); \
     I2C_Cmd(I2C2, DISABLE);                                            \
@@ -796,12 +805,11 @@
 
 
 
-void   i2c_init(struct i2c_periph* p) {
-
-
-}
-
 bool_t i2c_submit(struct i2c_periph* p, struct i2c_transaction* t) {
-
-
+  p->trans[p->trans_insert_idx] = t;
+  p->idx_buf = 0;
+  p->status = I2CStartRequested;
+  I2C_ZERO_EVENTS();
+  I2C_ITConfig(I2C2, I2C_IT_EVT, ENABLE);
+  I2C_GenerateSTART(I2C2, ENABLE);
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]