paparazzi-commits
[Top][All Lists]
Advanced

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

[paparazzi-commits] [4244] add i2c support for GPS (to be tested)


From: Pascal Brisset
Subject: [paparazzi-commits] [4244] add i2c support for GPS (to be tested)
Date: Mon, 12 Oct 2009 09:00:32 +0000

Revision: 4244
          http://svn.sv.gnu.org/viewvc/?view=rev&root=paparazzi&revision=4244
Author:   hecto
Date:     2009-10-12 09:00:31 +0000 (Mon, 12 Oct 2009)
Log Message:
-----------
 add i2c support for GPS (to be tested)

Modified Paths:
--------------
    paparazzi3/trunk/conf/modules/gps_i2c.xml
    paparazzi3/trunk/sw/airborne/gps_ubx.c
    paparazzi3/trunk/sw/airborne/modules/gps_i2c/gps_i2c.c
    paparazzi3/trunk/sw/airborne/modules/gps_i2c/gps_i2c.h

Modified: paparazzi3/trunk/conf/modules/gps_i2c.xml
===================================================================
--- paparazzi3/trunk/conf/modules/gps_i2c.xml   2009-10-12 06:28:13 UTC (rev 
4243)
+++ paparazzi3/trunk/conf/modules/gps_i2c.xml   2009-10-12 09:00:31 UTC (rev 
4244)
@@ -1,12 +1,17 @@
 <!DOCTYPE module SYSTEM "module.dtd">
 
+<!-- to be configured with
+ap.CFLAGS += -DGPS -DUBX -DGPS_LINK=gps_i2c -DGPS_LED=2
+ap.CFLAGS += -DGPS_CONFIGURE -DGPS_PORT_ID=GPS_PORT_DDC
+-->
+
 <module name="gps_i2c">
   <header>
     <file name="gps_i2c.h"/>
   </header>
   <init fun="gps_i2c_init()"/>
   <periodic fun="gps_i2c_periodic()" freq="4." delay="4" autorun="TRUE"/>
-  <event fun="gps_i2c_event()"/>
+  <event fun="gps_i2cEvent()"/>
   <makefile target="ap">
     <file name="gps_i2c.c"/>
   </makefile>

Modified: paparazzi3/trunk/sw/airborne/gps_ubx.c
===================================================================
--- paparazzi3/trunk/sw/airborne/gps_ubx.c      2009-10-12 06:28:13 UTC (rev 
4243)
+++ paparazzi3/trunk/sw/airborne/gps_ubx.c      2009-10-12 09:00:31 UTC (rev 
4244)
@@ -40,7 +40,7 @@
 
 #define UbxInitCheksum() { send_ck_a = send_ck_b = 0; }
 #define UpdateChecksum(c) { send_ck_a += c; send_ck_b += send_ck_a; }
-#define UbxTrailer() { GpsUartSend1(send_ck_a);  GpsUartSend1(send_ck_b); }
+#define UbxTrailer() { GpsUartSend1(send_ck_a);  GpsUartSend1(send_ck_b); 
GpsUartSendMessage(); }
 
 #define UbxSend1(c) { uint8_t i8=c; GpsUartSend1(i8); UpdateChecksum(i8); }
 #define UbxSend2(c) { uint16_t i16=c; UbxSend1(i16&0xff); UbxSend1(i16 >> 8); }
@@ -121,20 +121,43 @@
 #define NMEA_PROTO_MASK 0x0002
 #define RTCM_PROTO_MASK 0x0004
 
+#define GPS_PORT_DDC   0x00
+#define GPS_PORT_UART1 0x01
+#define GPS_PORT_UART2 0x02
+#define GPS_PORT_USB   0x03
+#define GPS_PORT_SPI   0x04
+
+
 #ifdef GPS_CONFIGURE
 /* GPS dynamic configuration */
 
 #include "uart.h"
 
-/* Configure the GPS baud rate\xF3< using the current uart baud rate. Busy
+#ifndef GPS_PORT_ID
+#define GPS_PORT_ID GPS_PORT_UART1
+#endif
+
+
+/* Configure the GPS baud rate using the current uart baud rate. Busy
    wait for the end of the transmit. Then, BEFORE waiting for the ACK,
    change the uart rate. */
+#if GPS_PORT_ID == GPS_PORT_UART1 || GPS_PORT_ID == GPS_PORT_UART2
 void gps_configure_uart ( void ) {
-  UbxSend_CFG_PRT(0x01, 0x0, 0x0, 0x000008D0, GPS_BAUD, UBX_PROTO_MASK, 
UBX_PROTO_MASK, 0x0, 0x0);  
+  UbxSend_CFG_PRT(GPS_PORT_ID, 0x0, 0x0, 0x000008D0, GPS_BAUD, UBX_PROTO_MASK, 
UBX_PROTO_MASK, 0x0, 0x0);
+
   while (GpsUartRunning) ; /* FIXME */
   GpsUartInitParam( UART_BAUD(GPS_BAUD),  UART_8N1, UART_FIFO_8);
 }
+#endif
 
+#if GPS_PORT_ID == GPS_PORT_DDC
+void gps_configure_uart ( void ) {
+  UbxSend_CFG_PRT(GPS_PORT_ID, 0x0, 0x0, (GPS_I2C_SLAVE_ADDR<<1), 0x0, 
UBX_PROTO_MASK, UBX_PROTO_MASK, 0x0, 0x0);
+}
+#endif
+
+
+
 #ifdef USER_GPS_CONFIGURE
 #include USER_GPS_CONFIGURE
 #else 

Modified: paparazzi3/trunk/sw/airborne/modules/gps_i2c/gps_i2c.c
===================================================================
--- paparazzi3/trunk/sw/airborne/modules/gps_i2c/gps_i2c.c      2009-10-12 
06:28:13 UTC (rev 4243)
+++ paparazzi3/trunk/sw/airborne/modules/gps_i2c/gps_i2c.c      2009-10-12 
09:00:31 UTC (rev 4244)
@@ -1,12 +1,35 @@
+/*
+ * Copyright (C) 2009  ENAC, Pascal Brisset, Michel Gorraz
+ *
+ * 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. 
+ *
+ */
+
 #include "gps_i2c.h"
 #include "i2c.h"
 
-uint8_t gps_i2c_buf[GPS_I2C_BUF_SIZE];
-uint8_t gps_i2c_insert_idx, gps_i2c_extract_idx;
+uint8_t gps_i2c_rx_buf[GPS_I2C_BUF_SIZE];
+uint8_t gps_i2c_rx_insert_idx, gps_i2c_rx_extract_idx;
+uint8_t gps_i2c_tx_buf[GPS_I2C_BUF_SIZE];
+uint8_t gps_i2c_tx_insert_idx, gps_i2c_tx_extract_idx;
+bool_t gps_i2c_done, gps_i2c_data_ready_to_transmit;
 
-
 /* u-blox5 protocole, page 4 */
-#define GPS_I2C_SLAVE_ADDR 0x42
 #define GPS_I2C_ADDR_NB_AVAIL_BYTES 0xFD
 #define GPS_I2C_ADDR_DATA 0xFF
 
@@ -15,9 +38,14 @@
 #define GPS_I2C_STATUS_ASKING_NB_AVAIL_BYTES  2
 #define GPS_I2C_STATUS_READING_NB_AVAIL_BYTES 3
 #define GPS_I2C_STATUS_READING_DATA           4
+#define GPS_I2C_STATUS_WRITING_DATA           5
 
+#define gps_i2c_AddCharToRxBuf(_x) { \
+  gps_i2c_rx_buf[gps_i2c_rx_insert_idx] = _x; \
+  gps_i2c_rx_insert_idx++; /* size=256, No check for buf overflow */ \
+}
+
 static uint8_t gps_i2c_status;
-static bool_t gps_i2c_done;
 static uint8_t gps_i2c_nb_avail_bytes;
 static uint8_t data_buf_len;
 
@@ -25,6 +53,10 @@
 gps_i2c_init(void) {
   gps_i2c_status = GPS_I2C_STATUS_IDLE;
   gps_i2c_done = TRUE;
+  gps_i2c_data_ready_to_transmit = FALSE;
+  gps_i2c_rx_insert_idx = 0;
+  gps_i2c_rx_extract_idx = 0;
+  gps_i2c_tx_insert_idx = 0;
 }
 
 static inline void
@@ -53,36 +85,57 @@
 
 void
 gps_i2c_event(void) {
-  if (gps_i2c_done) {
-    switch (gps_i2c_status) {
-    case GPS_I2C_STATUS_ASKING_NB_AVAIL_BYTES:
-      i2c0_receive(GPS_I2C_SLAVE_ADDR, 2, &gps_i2c_done);
+  switch (gps_i2c_status) {
+  case GPS_I2C_STATUS_IDLE:
+    if (gps_i2c_data_ready_to_transmit) {
+      /* Copy data from our buffer to the i2c buffer */
+      uint8_t data_size = Min(gps_i2c_tx_insert_idx-gps_i2c_tx_extract_idx, 
I2C0_BUF_LEN);
+      uint8_t i;
+      for(i = 0; i < data_size; i++, gps_i2c_tx_extract_idx++)
+       i2c0_buf[i] = gps_i2c_tx_buf[gps_i2c_tx_extract_idx];
+
+      /* Start i2c transmit */
+      i2c0_transmit(GPS_I2C_SLAVE_ADDR, data_size, &gps_i2c_done);
       gps_i2c_done = FALSE;
-      gps_i2c_status = GPS_I2C_STATUS_READING_NB_AVAIL_BYTES;
-      break;
 
-    case GPS_I2C_STATUS_READING_NB_AVAIL_BYTES:
-      gps_i2c_nb_avail_bytes = (i2c0_buf[0]<<8) | i2c0_buf[1];
-      continue_reading();
-      break;
-
-    case GPS_I2C_STATUS_ASKING_DATA:
-      data_buf_len = Min(gps_i2c_nb_avail_bytes, I2C0_BUF_LEN);
-      gps_i2c_nb_avail_bytes -= data_buf_len;
-
-      i2c0_receive(GPS_I2C_SLAVE_ADDR, data_buf_len, &gps_i2c_done);
-      gps_i2c_done = FALSE;
-      gps_i2c_status = GPS_I2C_STATUS_READING_DATA;
-      break;
-      
-    case GPS_I2C_STATUS_READING_DATA: {
-      uint8_t i;
-      for(i = 0; i < data_buf_len; i++) {
-       gps_i2c_AddCharToBuf(i2c0_buf[i]);
+      /* Reset flag if finished */
+      if (gps_i2c_tx_extract_idx < gps_i2c_tx_insert_idx) {
+       gps_i2c_data_ready_to_transmit = FALSE;
+       gps_i2c_tx_insert_idx = 0;
       }
-      continue_reading();
-      break;
     }
+    break;
+
+  case GPS_I2C_STATUS_ASKING_NB_AVAIL_BYTES:
+    i2c0_receive(GPS_I2C_SLAVE_ADDR, 2, &gps_i2c_done);
+    gps_i2c_done = FALSE;
+    gps_i2c_status = GPS_I2C_STATUS_READING_NB_AVAIL_BYTES;
+    break;
+    
+  case GPS_I2C_STATUS_READING_NB_AVAIL_BYTES:
+    gps_i2c_nb_avail_bytes = (i2c0_buf[0]<<8) | i2c0_buf[1];
+    continue_reading();
+    break;
+    
+  case GPS_I2C_STATUS_ASKING_DATA:
+    data_buf_len = Min(gps_i2c_nb_avail_bytes, I2C0_BUF_LEN);
+    gps_i2c_nb_avail_bytes -= data_buf_len;
+    
+    i2c0_receive(GPS_I2C_SLAVE_ADDR, data_buf_len, &gps_i2c_done);
+    gps_i2c_done = FALSE;
+    gps_i2c_status = GPS_I2C_STATUS_READING_DATA;
+    break;
+    
+  case GPS_I2C_STATUS_READING_DATA: {
+    uint8_t i;
+    for(i = 0; i < data_buf_len; i++) {
+      gps_i2c_AddCharToRxBuf(i2c0_buf[i]);
     }
+    continue_reading();
+    break;
   }
+  case GPS_I2C_STATUS_WRITING_DATA: 
+    gps_i2c_status = GPS_I2C_STATUS_IDLE;
+    break;
+  }
 }

Modified: paparazzi3/trunk/sw/airborne/modules/gps_i2c/gps_i2c.h
===================================================================
--- paparazzi3/trunk/sw/airborne/modules/gps_i2c/gps_i2c.h      2009-10-12 
06:28:13 UTC (rev 4243)
+++ paparazzi3/trunk/sw/airborne/modules/gps_i2c/gps_i2c.h      2009-10-12 
09:00:31 UTC (rev 4244)
@@ -1,19 +1,56 @@
+/*
+ * Copyright (C) 2009  ENAC, Pascal Brisset, Michel Gorraz
+ *
+ * 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 GPS_I2C
 #define GPS_I2C
 
-#include <inttypes.h>
+#include "std.h"
 
+#define GPS_I2C_SLAVE_ADDR 0x42
+
 #define GPS_I2C_BUF_SIZE 256
-extern uint8_t gps_i2c_buf[GPS_I2C_BUF_SIZE];
-extern uint8_t gps_i2c_insert_idx, gps_i2c_extract_idx;
+extern uint8_t gps_i2c_rx_buf[GPS_I2C_BUF_SIZE];
+extern uint8_t gps_i2c_rx_insert_idx, gps_i2c_rx_extract_idx;
+extern uint8_t gps_i2c_tx_buf[GPS_I2C_BUF_SIZE];
+extern uint8_t gps_i2c_tx_insert_idx, gps_i2c_tx_extract_idx;
 
+extern bool_t gps_i2c_done, gps_i2c_data_ready_to_transmit;
+
 void gps_i2c_init(void);
 void gps_i2c_event(void);
 void gps_i2c_periodic(void);
 
-#define gps_i2c_AddCharToBuf(_x) { \
-  gps_i2c_buf[gps_i2c_insert_idx] = _x; \
-  gps_i2c_insert_idx++; /* size=256, No check for buf overflow */ \
+#define gps_i2cEvent() { if (gps_i2c_done) gps_i2c_event(); }
+#define gps_i2cChAvailable() (gps_i2c_rx_insert_idx != gps_i2c_rx_extract_idx)
+#define gps_i2cGetch() (gps_i2c_rx_buf[gps_i2c_rx_extract_idx++])
+#define gps_i2cTransmit(_char) {             \
+  if (! gps_i2c_data_ready_to_transmit)  /* Else transmitting, overrun*/     \
+    gps_i2c_tx_buf[gps_i2c_tx_insert_idx++] = _char; \
 }
+#define gps_i2cSendMessage() {           \
+  gps_i2c_data_ready_to_transmit = TRUE; \
+  gps_i2c_tx_extract_idx = 0;            \
+}
+#define gps_i2cTxRunning (gps_i2c_data_ready_to_transmit)
+#define gps_i2cInitParam(_baud, _uart_prm1, _uart_prm2) {}
 
 #endif // GPS_I2C





reply via email to

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