paparazzi-commits
[Top][All Lists]
Advanced

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

[paparazzi-commits] [5143] adding test code for aspirin


From: antoine drouin
Subject: [paparazzi-commits] [5143] adding test code for aspirin
Date: Fri, 23 Jul 2010 17:11:46 +0000

Revision: 5143
          http://svn.sv.gnu.org/viewvc/?view=rev&root=paparazzi&revision=5143
Author:   poine
Date:     2010-07-23 17:11:46 +0000 (Fri, 23 Jul 2010)
Log Message:
-----------
adding test code for aspirin

Added Paths:
-----------
    paparazzi3/trunk/sw/airborne/booz/peripherals/booz_hmc5843.c
    paparazzi3/trunk/sw/airborne/booz/peripherals/booz_hmc5843.h
    paparazzi3/trunk/sw/airborne/booz/peripherals/booz_itg3200.h

Added: paparazzi3/trunk/sw/airborne/booz/peripherals/booz_hmc5843.c
===================================================================
--- paparazzi3/trunk/sw/airborne/booz/peripherals/booz_hmc5843.c                
                (rev 0)
+++ paparazzi3/trunk/sw/airborne/booz/peripherals/booz_hmc5843.c        
2010-07-23 17:11:46 UTC (rev 5143)
@@ -0,0 +1,44 @@
+#include "peripherals/booz_hmc5843.h"
+
+#include "i2c.h"
+
+struct Hmc5843 hmc5843;
+
+void hmc5843_init(void) {
+  hmc5843.status = HMC5843_UNINITIALIZED1;
+  hmc5843.i2c_done = TRUE;
+}
+
+void hmc5843_periodic(void) {
+  
+  if (!hmc5843.i2c_done) return;
+  switch (hmc5843.status) {
+  case HMC5843_UNINITIALIZED1:
+    i2c2.buf[0] = HMC5843_REG_CFGA;  // set to rate to 50Hz
+    i2c2.buf[1] = 0x00 | (0x06 << 2);
+    i2c2_transmit(HMC5843_ADDR, 2, &hmc5843.i2c_done);
+    hmc5843.status = HMC5843_UNINITIALIZED2;
+    break;
+  case HMC5843_UNINITIALIZED2:
+    i2c2.buf[0] = HMC5843_REG_CFGB;  // set to gain to 1 Gauss
+    i2c2.buf[1] = 0x01<<5;
+    i2c2_transmit(HMC5843_ADDR, 2, &hmc5843.i2c_done);
+    hmc5843.status = HMC5843_UNINITIALIZED3;
+    break;
+  case HMC5843_UNINITIALIZED3:
+    i2c2.buf[0] = HMC5843_REG_MODE;  // set to continuous mode
+    i2c2.buf[1] = 0x00;
+    i2c2_transmit(HMC5843_ADDR, 2, &hmc5843.i2c_done);
+    hmc5843.status = HMC5843_IDLE;
+    break;
+  case HMC5843_IDLE:
+    i2c2_receive(HMC5843_ADDR, 6, &hmc5843.i2c_done);
+    hmc5843.status = HMC5843_READING;
+    break;
+  default:
+    /* FIXME : report error */
+    break;
+  }
+
+}
+

Added: paparazzi3/trunk/sw/airborne/booz/peripherals/booz_hmc5843.h
===================================================================
--- paparazzi3/trunk/sw/airborne/booz/peripherals/booz_hmc5843.h                
                (rev 0)
+++ paparazzi3/trunk/sw/airborne/booz/peripherals/booz_hmc5843.h        
2010-07-23 17:11:46 UTC (rev 5143)
@@ -0,0 +1,79 @@
+/*
+ * $Id$
+ *  
+ * Copyright (C) 2008-2009 Antoine Drouin <address@hidden>
+ *
+ * This file is part of paparazzi.
+ *
+ * paparazzi is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * paparazzi is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with paparazzi; see the file COPYING.  If not, write to
+ * the Free Software Foundation, 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA. 
+ */
+
+#ifndef BOOZ_HMC5843_H
+#define BOOZ_HMC5843_H
+
+#include "std.h"
+
+enum Hmc5843Status {
+  HMC5843_UNINITIALIZED1,
+  HMC5843_UNINITIALIZED2,
+  HMC5843_UNINITIALIZED3,
+  HMC5843_IDLE,
+  HMC5843_READING
+};
+
+struct Hmc5843 {
+  volatile enum Hmc5843Status status;
+  volatile uint8_t i2c_done;
+  union {
+    uint8_t buf[7];
+    int16_t value[3];
+  } data;
+};
+
+extern struct Hmc5843 hmc5843;
+
+extern void hmc5843_init(void);
+extern void hmc5843_periodic(void);
+
+/* default I2C address */
+#define HMC5843_ADDR 0x3C
+
+/* Registers */
+#define HMC5843_REG_CFGA   0x00
+#define HMC5843_REG_CFGB   0x01
+#define HMC5843_REG_MODE   0x02
+#define HMC5843_REG_DATXM  0x03
+#define HMC5843_REG_DATXL  0x04
+#define HMC5843_REG_DATYM  0x05
+#define HMC5843_REG_DATYL  0x06
+#define HMC5843_REG_DATZM  0x07
+#define HMC5843_REG_DATZL  0x08
+#define HMC5843_REG_STATUS 0x09
+#define HMC5843_REG_IDA    0x0A
+#define HMC5843_REG_IDB    0x0B
+#define HMC5843_REG_IDC    0x0C
+
+#include <string.h>
+
+#define MagEvent(_m_handler) {                                         \
+    if (hmc5843.status == HMC5843_READING && hmc5843.i2c_done) {       \
+      memcpy(hmc5843.data.buf, (const void*)i2c2.buf, 6);              \
+      _m_handler();                                                    \
+      hmc5843.status = HMC5843_IDLE;                                   \
+    }                                                                  \
+  }
+
+#endif /* BOOZ_HMC5843_H */

Added: paparazzi3/trunk/sw/airborne/booz/peripherals/booz_itg3200.h
===================================================================
--- paparazzi3/trunk/sw/airborne/booz/peripherals/booz_itg3200.h                
                (rev 0)
+++ paparazzi3/trunk/sw/airborne/booz/peripherals/booz_itg3200.h        
2010-07-23 17:11:46 UTC (rev 5143)
@@ -0,0 +1,25 @@
+#ifndef BOOZ_ITG3200
+#define BOOZ_ITG3200
+
+/* default I2C address */
+#define ITG3200_ADDR 0xD0
+
+/* Registers */
+#define ITG3200_REG_WHO_AM_I    0X00
+#define ITG3200_REG_SMPLRT_DIV  0X15
+#define ITG3200_REG_DLPF_FS     0X16
+#define ITG3200_REG_INT_CFG     0X17
+#define ITG3200_REG_INT_STATUS  0X1A
+#define ITG3200_REG_TEMP_OUT_H  0X1B
+#define ITG3200_REG_TEMP_OUT_L  0X1C
+#define ITG3200_REG_GYRO_XOUT_H 0X1D
+#define ITG3200_REG_GYRO_XOUT_L 0X1E
+#define ITG3200_REG_GYRO_YOUT_H 0X1F
+#define ITG3200_REG_GYRO_YOUT_L 0X20
+#define ITG3200_REG_GYRO_ZOUT_H 0X21
+#define ITG3200_REG_GYRO_ZOUT_L 0X22
+#define ITG3200_REG_PWR_MGM     0X3E
+
+
+
+#endif /* BOOZ_ITG3200 */




reply via email to

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