Merge remote-tracking branch 'mjb/altoslib_mjb'
authorKeith Packard <keithp@keithp.com>
Sun, 9 Sep 2012 20:03:47 +0000 (13:03 -0700)
committerKeith Packard <keithp@keithp.com>
Sun, 9 Sep 2012 20:03:47 +0000 (13:03 -0700)
23 files changed:
altosdroid/res/menu/option_menu.xml
altosdroid/res/values/strings.xml
altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java
altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java
altoslib/AltosConfigData.java
altoslib/AltosLib.java
altosui/Altos.java
altosui/AltosEepromDownload.java
altosui/AltosFlightStatsTable.java
altosui/AltosScanUI.java
ao-tools/ao-send-telem/ao-send-telem.c
src/avr/ao_pwmin.c [deleted file]
src/avr/ao_pwmin.h [deleted file]
src/core/ao.h
src/core/ao_panic.c
src/drivers/ao_cc1120.c
src/drivers/ao_mma655x.c
src/drivers/ao_mpu6000.c
src/drivers/ao_ms5607.c
src/drivers/ao_radio_slave.c
src/megametrum-v0.1/ao_pins.h
src/product/ao_telescience.c
src/telescience-v0.1/Makefile

index 6946e29..d7ba830 100644 (file)
@@ -17,4 +17,7 @@
     <item android:id="@+id/connect_scan"
           android:icon="@android:drawable/ic_menu_search"
           android:title="@string/connect_device" />
+    <item android:id="@+id/select_freq"
+          android:icon="@android:drawable/ic_menu_preferences"
+          android:title="@string/select_freq" />
 </menu>
index f803840..1b28284 100644 (file)
@@ -25,6 +25,7 @@
 
     <!-- Options Menu -->
     <string name="connect_device">Connect a device</string>
+    <string name="select_freq">Select radio frequency</string>
 
     <!--  DeviceListActivity -->
     <string name="scanning">scanning for devices…</string>
index 20904d2..0068968 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2012 Mike Beattie <mike@ethernal.org>
+ * Copyright Â© 2012 Mike Beattie <mike@ethernal.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -26,6 +26,7 @@ import android.content.Intent;
 import android.content.Context;
 import android.content.ComponentName;
 import android.content.ServiceConnection;
+import android.content.DialogInterface;
 import android.os.IBinder;
 import android.os.Bundle;
 import android.os.Handler;
@@ -40,6 +41,7 @@ import android.view.MenuItem;
 import android.view.Window;
 import android.widget.TextView;
 import android.widget.Toast;
+import android.app.AlertDialog;
 
 import org.altusmetrum.AltosLib.*;
 
@@ -188,12 +190,12 @@ public class AltosDroid extends Activity {
                if (!state.ascent)
                        speed = state.baro_speed;
                mSpeedView.setText(String.format("%6.0f m/s", speed));
-               mAccelView.setText(String.format("%6.0f m/s²", state.acceleration));
+               mAccelView.setText(String.format("%6.0f m/s²", state.acceleration));
                mRangeView.setText(String.format("%6.0f m", state.range));
                mHeightView.setText(String.format("%6.0f m", state.height));
-               mElevationView.setText(String.format("%3.0f°", state.elevation));
+               mElevationView.setText(String.format("%3.0f°", state.elevation));
                if (state.from_pad != null)
-                       mBearingView.setText(String.format("%3.0f°", state.from_pad.bearing));
+                       mBearingView.setText(String.format("%3.0f°", state.from_pad.bearing));
                mLatitudeView.setText(pos(state.gps.lat, "N", "S"));
                mLongitudeView.setText(pos(state.gps.lon, "W", "E"));
 
@@ -208,7 +210,7 @@ public class AltosDroid extends Activity {
                }
                int deg = (int) Math.floor(p);
                double min = (p - Math.floor(p)) * 60.0;
-               return String.format("%d° %9.6f\" %s", deg, min, h);
+               return String.format("%d° %9.6f\" %s", deg, min, h);
        }
 
        @Override
@@ -352,6 +354,20 @@ public class AltosDroid extends Activity {
                return true;
        }
 
+       void setFrequency(double freq) {
+               try {
+                       mService.send(Message.obtain(null, TelemetryService.MSG_SETFREQUENCY, freq));
+               } catch (RemoteException e) {
+               }
+       }
+
+       void setFrequency(String freq) {
+               try {
+                       setFrequency (Double.parseDouble(freq.substring(11, 17)));
+               } catch (NumberFormatException e) {
+               }
+       }
+
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
                Intent serverIntent = null;
@@ -361,6 +377,33 @@ public class AltosDroid extends Activity {
                        serverIntent = new Intent(this, DeviceListActivity.class);
                        startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE);
                        return true;
+               case R.id.select_freq:
+                       // Set the TBT radio frequency
+
+                       final String[] frequencies = {
+                               "Channel 0 (434.550MHz)",
+                               "Channel 1 (434.650MHz)",
+                               "Channel 2 (434.750MHz)",
+                               "Channel 3 (434.850MHz)",
+                               "Channel 4 (434.950MHz)",
+                               "Channel 5 (435.050MHz)",
+                               "Channel 6 (435.150MHz)",
+                               "Channel 7 (435.250MHz)",
+                               "Channel 8 (435.350MHz)",
+                               "Channel 9 (435.450MHz)"
+                       };
+
+                       AlertDialog.Builder builder = new AlertDialog.Builder(this);
+                       builder.setTitle("Pick a frequency");
+                       builder.setItems(frequencies,
+                                        new DialogInterface.OnClickListener() {
+                                                public void onClick(DialogInterface dialog, int item) {
+                                                        setFrequency(frequencies[item]);
+                                                }
+                                        });
+                       AlertDialog alert = builder.create();
+                       alert.show();
+                       return true;
                }
                return false;
        }
index ffe9694..6a1f1c5 100644 (file)
@@ -52,6 +52,7 @@ public class TelemetryService extends Service {
        static final int MSG_CONNECT_FAILED    = 5;
        static final int MSG_DISCONNECTED      = 6;
        static final int MSG_TELEMETRY         = 7;
+       static final int MSG_SETFREQUENCY      = 8;
 
        public static final int STATE_NONE       = 0;
        public static final int STATE_READY      = 1;
@@ -126,6 +127,15 @@ public class TelemetryService extends Service {
                        case MSG_TELEMETRY:
                                s.sendMessageToClients(Message.obtain(null, AltosDroid.MSG_TELEMETRY, msg.obj));
                                break;
+                       case MSG_SETFREQUENCY:
+                               if (s.state == STATE_CONNECTED) {
+                                       try {
+                                               s.mAltosBluetooth.set_radio_frequency((Double) msg.obj);
+                                       } catch (InterruptedException e) {
+                                       } catch (TimeoutException e) {
+                                       }
+                               }
+                               break;
                        default:
                                super.handleMessage(msg);
                        }
index c6e92e6..6f34363 100644 (file)
@@ -167,6 +167,7 @@ public class AltosConfigData implements Iterable<String> {
                        try { callsign = get_string(line, "Callsign:"); } catch (Exception e) {}
                        try { version = get_string(line,"software-version"); } catch (Exception e) {}
                        try { product = get_string(line,"product"); } catch (Exception e) {}
+                       try { manufacturer = get_string(line,"manufacturer"); } catch (Exception e) {}
 
                        try { get_int(line, "flight"); stored_flight++; }  catch (Exception e) {}
                        try { storage_size = get_int(line, "Storage size:"); } catch (Exception e) {}
index 8d383f1..192c445 100644 (file)
@@ -109,7 +109,7 @@ public class AltosLib {
        public static final int ao_telemetry_0_8 = 3;
        public static final int ao_telemetry_max = 3;
 
-       public static final String[] ao_telemetry_name = {
+       private static final String[] ao_telemetry_name = {
                "Off", "Standard Telemetry", "TeleMetrum v0.9", "TeleMetrum v0.8"
        };
 
@@ -119,13 +119,13 @@ public class AltosLib {
        public static final int ao_telemetry_0_9_len = 95;
        public static final int ao_telemetry_0_8_len = 94;
 
-       public static final int[] ao_telemetry_len = {
+       private static final int[] ao_telemetry_len = {
                0, 32, 95, 94
        };
 
-       public static HashMap<String,Integer>   string_to_state = new HashMap<String,Integer>();
+       private static HashMap<String,Integer>  string_to_state = new HashMap<String,Integer>();
 
-       public static boolean map_initialized = false;
+       private static boolean map_initialized = false;
 
        public static void initialize_map()
        {
@@ -157,7 +157,7 @@ public class AltosLib {
                                                                 telemetry));
        }
        
-       public static String[] state_to_string = {
+       private static String[] state_to_string = {
                "startup",
                "idle",
                "pad",
@@ -170,7 +170,7 @@ public class AltosLib {
                "invalid",
        };
 
-       public static String[] state_to_string_capital = {
+       private static String[] state_to_string_capital = {
                "Startup",
                "Idle",
                "Pad",
@@ -197,6 +197,12 @@ public class AltosLib {
                return state_to_string[state];
        }
 
+       public static String state_name_capital(int state) {
+               if (state < 0 || state_to_string.length <= state)
+                       return "invalid";
+               return state_to_string_capital[state];
+       }
+
        public static final int AO_GPS_VALID = (1 << 4);
        public static final int AO_GPS_RUNNING = (1 << 5);
        public static final int AO_GPS_DATE_VALID = (1 << 6);
index e60b3aa..cd17a93 100644 (file)
@@ -72,20 +72,6 @@ public class Altos extends AltosLib {
 
        static final int text_width = 20;
 
-       static public int state(String state) {
-               if (!map_initialized)
-                       initialize_map();
-               if (string_to_state.containsKey(state))
-                       return string_to_state.get(state);
-               return ao_flight_invalid;
-       }
-
-       static public String state_name(int state) {
-               if (state < 0 || state_to_string.length <= state)
-                       return "invalid";
-               return state_to_string[state];
-       }
-
        static public boolean initialized = false;
        static public boolean loaded_library = false;
 
index 4a35c2f..b04890c 100644 (file)
@@ -336,7 +336,7 @@ public class AltosEepromDownload implements Runnable {
 
                state = 0; state_block = log.start_block;
                for (block = log.start_block; !done && block < log.end_block; block++) {
-                       monitor.set_value(Altos.state_to_string[state], state, block - state_block);
+                       monitor.set_value(AltosLib.state_name(state), state, block - state_block);
 
                        AltosEepromChunk        eechunk = new AltosEepromChunk(serial_line, block, block == log.start_block);
 
index c311b23..14e3bf8 100644 (file)
@@ -103,7 +103,7 @@ public class AltosFlightStatsTable extends JComponent {
                               String.format("%5.0f m/s", stats.state_baro_speed[Altos.ao_flight_main]),
                               String.format("%5.0f ft/s", AltosConvert.meters_to_feet(stats.state_baro_speed[Altos.ao_flight_main])));
                for (int s = Altos.ao_flight_boost; s <= Altos.ao_flight_main; s++) {
-                       new FlightStat(layout, y++, String.format("%s time", Altos.state_to_string_capital[s]),
+                       new FlightStat(layout, y++, String.format("%s time", AltosLib.state_name_capital(s)),
                                       String.format("%6.2f s", stats.state_end[s] - stats.state_start[s]));
                }
                new FlightStat(layout, y++, "Flight Time",
index ef6389b..9da1290 100644 (file)
@@ -427,7 +427,7 @@ public class AltosScanUI
                telemetry_boxes = new JCheckBox[Altos.ao_telemetry_max - Altos.ao_telemetry_min + 1];
                for (int k = Altos.ao_telemetry_min; k <= Altos.ao_telemetry_max; k++) {
                        int j = k - Altos.ao_telemetry_min;
-                       telemetry_boxes[j] = new JCheckBox(Altos.ao_telemetry_name[k]);
+                       telemetry_boxes[j] = new JCheckBox(AltosLib.telemetry_name(k));
                        c.gridy = 3 + j;
                        pane.add(telemetry_boxes[j], c);
                        telemetry_boxes[j].setActionCommand("telemetry");
index c6cc51a..db06137 100644 (file)
@@ -199,7 +199,7 @@ main (int argc, char **argv)
                exit (1);
 
        cc_usb_printf(cc, "m 0\n");
-       cc_usb_printf(cc, "F %d\n", freq);
+       cc_usb_printf(cc, "F %d\n", freq);
        for (i = optind; i < argc; i++) {
                file = fopen(argv[i], "r");
                if (!file) {
diff --git a/src/avr/ao_pwmin.c b/src/avr/ao_pwmin.c
deleted file mode 100644 (file)
index 8439735..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright © 2012 Robert D. Garbee <robert@gag.com>
- *
- * This program 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; version 2 of the License.
- *
- * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- */
-
-#include "ao.h"
-#include "ao_pwmin.h"
-
-/* 
- * This code implements a PWM input using ICP3.  
- *
- * The initial use is to measure wind speed in the ULA/Ball summer intern 
- * project payload developed at Challenger Middle School.  
- */
-
-volatile __data uint16_t ao_icp3_count = 0;
-volatile __data uint16_t ao_icp3_last = 0;
-
-uint16_t ao_icp3(void)
-{
-       uint16_t        v;
-       ao_arch_critical(
-               v = ao_icp3_count;
-               );
-       return v;
-}
-
-static void
-ao_pwmin_display(void) __reentrant
-{
-       /* display the most recent value */
-       printf("icp 3: %5u\n", ao_icp3());
-
-}
-
-
-ISR(TIMER3_CAPT_vect)
-{
-       
-       uint8_t lo = ICR3L; 
-       uint8_t hi = ICR3H;
-       uint16_t ao_icp3_this = (hi <<8) | lo;
-       
-       /* handling counter rollovers */
-       if (ao_icp3_this >= ao_icp3_last)
-               ao_icp3_count = ao_icp3_this - ao_icp3_last;
-       else 
-               ao_icp3_count = ao_icp3_this + (65536 - ao_icp3_last);
-       ao_icp3_last = ao_icp3_this;
-}
-
-__code struct ao_cmds ao_pwmin_cmds[] = {
-       { ao_pwmin_display,     "p\0PWM input" },
-       { 0, NULL },
-};
-
-void
-ao_pwmin_init(void)
-{
-       /* do hardware setup here */
-       TCCR3A = ((0 << WGM31) |        /* normal mode, OCR3A */
-                  (0 << WGM30));        /* normal mode, OCR3A */
-        TCCR3B = ((1 << ICNC3) |        /* input capture noise canceler on */
-                  (0 << ICES3) |        /* input capture on falling edge (don't care) */
-                  (0 << WGM33) |        /* normal mode, OCR3A */
-                  (0 << WGM32) |        /* normal mode, OCR3A */
-                  (3 << CS30));         /* clk/64 from prescaler */
-
-       
-
-        TIMSK3 = (1 << ICIE3);         /* Interrupt on input compare */
-
-               /* set the spike filter bit in the TCCR3B register */
-
-       ao_cmd_register(&ao_pwmin_cmds[0]);
-}
-
-
diff --git a/src/avr/ao_pwmin.h b/src/avr/ao_pwmin.h
deleted file mode 100644 (file)
index bbab4dd..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * Copyright © 2012 Robert D. Garbee <robert@gag.com>
- *
- * This program 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; version 2 of the License.
- *
- * This program 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 this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- */
-
-void ao_pwmin_init(void);
index 66c0881..4f4779e 100644 (file)
@@ -115,7 +115,10 @@ ao_start_scheduler(void);
 #define AO_PANIC_BT            11      /* Communications with bluetooth device failed */
 #define AO_PANIC_STACK         12      /* Stack overflow */
 #define AO_PANIC_SPI           13      /* SPI communication failure */
-#define AO_PANIC_SELF_TEST     14      /* Self test failure */
+#define AO_PANIC_SELF_TEST_CC1120      0x40 | 1        /* Self test failure */
+#define AO_PANIC_SELF_TEST_HMC5883     0x40 | 2        /* Self test failure */
+#define AO_PANIC_SELF_TEST_MPU6000     0x40 | 3        /* Self test failure */
+#define AO_PANIC_SELF_TEST_MS5607      0x40 | 4        /* Self test failure */
 
 /* Stop the operating system, beeping and blinking the reason */
 void
index 25dc145..5243304 100644 (file)
@@ -65,7 +65,15 @@ ao_panic(uint8_t reason)
 #ifdef SDCC
 #pragma disable_warning 126
 #endif
-               for (n = 0; n < reason; n++) {
+               if (reason & 0x40) {
+                       ao_led_on(AO_LED_RED);
+                       ao_beep(AO_BEEP_HIGH);
+                       ao_panic_delay(40);
+                       ao_led_off(AO_LED_RED);
+                       ao_beep(AO_BEEP_OFF);
+                       ao_panic_delay(10);
+               }
+               for (n = 0; n < (reason & 0x3f); n++) {
                        ao_led_on(AO_LED_RED);
                        ao_beep(AO_BEEP_MID);
                        ao_panic_delay(10);
index 4df931b..2f9c296 100644 (file)
@@ -1028,12 +1028,12 @@ ao_radio_init(void)
 
        AO_CC1120_SPI_CS_PORT->bsrr = ((uint32_t) (1 << AO_CC1120_SPI_CS_PIN));
        for (i = 0; i < 10000; i++) {
-               if ((SPI_2_GPIO->idr & (1 << SPI_2_MISO)) == 0)
+               if ((SPI_2_PORT->idr & (1 << SPI_2_MISO_PIN)) == 0)
                        break;
        }
        AO_CC1120_SPI_CS_PORT->bsrr = (1 << AO_CC1120_SPI_CS_PIN);
        if (i == 10000)
-               ao_panic(AO_PANIC_SELF_TEST);
+               ao_panic(AO_PANIC_SELF_TEST_CC1120);
 
        /* Enable the EXTI interrupt for the appropriate pin */
        ao_enable_port(AO_CC1120_INT_PORT);
index cd304d8..0642220 100644 (file)
 
 #if HAS_MMA655X
 
+#if 1
+#define PRINTD(...) do { printf ("\r%5u %s: ", ao_tick_count, __func__); printf(__VA_ARGS__); } while(0)
+#else
+#define PRINTD(...) 
+#endif
+
 static uint8_t mma655x_configured;
 
+uint8_t        ao_mma655x_spi_index = AO_MMA655X_SPI_INDEX;
+
 static void
 ao_mma655x_start(void) {
-       ao_spi_get_bit(AO_MMA655X_CS_GPIO,
-                      AO_MMA655X_CS,
+       ao_spi_get_bit(AO_MMA655X_CS_PORT,
                       AO_MMA655X_CS_PIN,
+                      AO_MMA655X_CS,
                       AO_MMA655X_SPI_INDEX,
                       AO_SPI_SPEED_FAST);
 }
 
 static void
 ao_mma655x_stop(void) {
-       ao_spi_put_bit(AO_MMA655X_CS_GPIO,
-                      AO_MMA655X_CS,
+       ao_spi_put_bit(AO_MMA655X_CS_PORT,
                       AO_MMA655X_CS_PIN,
+                      AO_MMA655X_CS,
                       AO_MMA655X_SPI_INDEX);
 }
 
+static void
+ao_mma655x_restart(void) {
+       uint8_t i;
+       ao_gpio_set(AO_MMA655X_CS_PORT, AO_MMA655X_CS_PIN, AO_MMA655X_CS, 1);
+
+       /* Emperical testing on STM32L151 at 32MHz for this delay amount */
+       for (i = 0; i < 9; i++)
+               ao_arch_nop();
+       ao_gpio_set(AO_MMA655X_CS_PORT, AO_MMA655X_CS_PIN, AO_MMA655X_CS, 0);
+}
+
 static uint8_t
 ao_parity(uint8_t v)
 {
+       uint8_t p;
        /* down to four bits */
-       v = (v ^ (v >> 4)) & 0xf;
+       p = (v ^ (v >> 4)) & 0xf;
 
        /* Cute lookup hack -- 0x6996 encodes the sixteen
         * even parity values in order.
         */
-       return (~0x6996 >> v) & 1;
+       p = (~0x6996 >> p) & 1;
+       return p;
 }
 
 static void
 ao_mma655x_cmd(uint8_t d[2])
 {
        ao_mma655x_start();
-       ao_spi_send(d, 2, AO_MMA655X_SPI_INDEX);
-       ao_spi_recv(d, 2, AO_MMA655X_SPI_INDEX);
+       PRINTD("\tSEND %02x %02x\n", d[0], d[1]);
+       ao_spi_duplex(d, d, 2, AO_MMA655X_SPI_INDEX);
+       PRINTD("\t\tRECV %02x %02x\n", d[0], d[1]);
        ao_mma655x_stop();
 }
 
 static uint8_t
-ao_mma655x_reg_write(uint8_t addr, uint8_t value)
+ao_mma655x_reg_read(uint8_t addr)
 {
        uint8_t d[2];
+       ao_mma655x_start();
+       d[0] = addr | (ao_parity(addr) << 7);
+       d[1] = 0;
+       ao_spi_send(&d, 2, AO_MMA655X_SPI_INDEX);
+       ao_mma655x_restart();
 
-       addr |= (1 << 6);       /* write mode */
-       d[0] = addr | (ao_parity(addr^value) << 7);
-       d[1] = value;
-       ao_mma655x_cmd(d);
+       /* Send a dummy read of 00 to clock out the SPI data */
+       d[0] = 0x80;
+       d[1] = 0x00;
+       ao_spi_duplex(&d, &d, 2, AO_MMA655X_SPI_INDEX);
+       ao_mma655x_stop();
        return d[1];
 }
 
-static uint8_t
-ao_mma655x_reg_read(uint8_t addr)
+static void
+ao_mma655x_reg_write(uint8_t addr, uint8_t value)
 {
        uint8_t d[2];
 
-       d[0] = addr | (ao_parity(addr) << 7);
-       d[1] = 0;
-       ao_mma655x_cmd(d);
-       return d[1];
+       addr |= (1 << 6);       /* write mode */
+       d[0] = addr | (ao_parity(addr^value) << 7);
+       d[1] = value;
+       ao_mma655x_start();
+       ao_spi_send(d, 2, AO_MMA655X_SPI_INDEX);
+       ao_mma655x_stop();
+
+       addr &= ~(1 << 6);
+       PRINTD("write %x %x = %x\n",
+              addr, value, ao_mma655x_reg_read(addr));
 }
 
 static uint16_t
@@ -89,14 +123,23 @@ ao_mma655x_value(void)
        uint8_t         d[2];
        uint16_t        v;
 
-       d[0] = ((0 << 7) |      /* Axis selection (X) */
-               (1 << 6) |      /* Acceleration operation */
-               (1 << 5));      /* Raw data */
+       d[0] = ((0 << 6) |      /* Axis selection (X) */
+               (1 << 5) |      /* Acceleration operation */
+               (1 << 4));      /* Raw data */
        d[1] = ((1 << 3) |      /* must be one */
                (1 << 2) |      /* Unsigned data */
                (0 << 1) |      /* Arm disabled */
                (1 << 0));      /* Odd parity */
-       ao_mma655x_cmd(d);
+       ao_mma655x_start();
+       PRINTD("value SEND %02x %02x\n", d[0], d[1]);
+       ao_spi_send(d, 2, AO_MMA655X_SPI_INDEX);
+       ao_mma655x_restart();
+       d[0] = 0x80;
+       d[1] = 0x00;
+       ao_spi_duplex(d, d, 2, AO_MMA655X_SPI_INDEX);
+       ao_mma655x_stop();
+       PRINTD("value RECV %02x %02x\n", d[0], d[1]);
+
        v = (uint16_t) d[1] << 2;
        v |= d[0] >> 6;
        v |= (uint16_t) (d[0] & 3) << 10;
@@ -132,6 +175,12 @@ ao_mma655x_setup(void)
        uint8_t         v;
        uint16_t        a, a_st;
        uint8_t         stdefl;
+       uint8_t         i;
+       uint8_t s0, s1, s2, s3;
+       uint8_t pn;
+       uint32_t        lot;
+       uint16_t        serial;
+
 
        if (mma655x_configured)
                return;
@@ -157,7 +206,10 @@ ao_mma655x_setup(void)
        ao_mma655x_reg_write(AO_MMA655X_AXISCFG,
                             AXISCFG_VALUE |
                             (1 << AO_MMA655X_AXISCFG_ST));
-       a_st = ao_mma655x_value();
+       for (i = 0; i < 10; i++) {
+               a_st = ao_mma655x_value();
+               printf ("SELF-TEST %2d = %6d\n", i, a_st);
+       }
 
        stdefl = ao_mma655x_reg_read(AO_MMA655X_STDEFL);
 
@@ -165,22 +217,14 @@ ao_mma655x_setup(void)
                             AXISCFG_VALUE |
                             (0 << AO_MMA655X_AXISCFG_ST));
        a = ao_mma655x_value();
-       printf ("normal: %u self_test: %u stdefl: %u\n",
-               a, a_st, stdefl);
+
+       for (i = 0; i < 10; i++) {
+               a = ao_mma655x_value();
+               printf("NORMAL   %2d = %6d\n", i, a);
+       }
 
        ao_mma655x_reg_write(AO_MMA655X_DEVCFG,
                             DEVCFG_VALUE | (1 << AO_MMA655X_DEVCFG_ENDINIT));
-}
-
-static void
-ao_mma655x_dump(void)
-{
-       uint8_t s0, s1, s2, s3;
-       uint32_t        lot;
-       uint16_t        serial;
-
-       ao_mma655x_setup();
-
        s0 = ao_mma655x_reg_read(AO_MMA655X_SN0);
        s1 = ao_mma655x_reg_read(AO_MMA655X_SN1);
        s2 = ao_mma655x_reg_read(AO_MMA655X_SN2);
@@ -189,8 +233,16 @@ ao_mma655x_dump(void)
                ((uint32_t) s1 << 8) | ((uint32_t) s0);
        serial = lot & 0x1fff;
        lot >>= 12;
-       printf ("MMA655X lot %d serial %d\n", lot, serial);
-       mma655x_configured = 0;
+       pn = ao_mma655x_reg_read(AO_MMA655X_PN);
+       printf ("MMA655X lot %d serial %d number %d\n", lot, serial, pn);
+
+}
+
+static void
+ao_mma655x_dump(void)
+{
+       ao_mma655x_setup();
+       printf ("MMA655X value %d\n", ao_mma655x_value());
 }
 
 __code struct ao_cmds ao_mma655x_cmds[] = {
@@ -219,9 +271,9 @@ ao_mma655x_init(void)
        mma655x_configured = 0;
 
        ao_cmd_register(&ao_mma655x_cmds[0]);
-       ao_spi_init_cs(AO_MMA655X_CS_GPIO, (1 << AO_MMA655X_CS));
+       ao_spi_init_cs(AO_MMA655X_CS_PORT, (1 << AO_MMA655X_CS_PIN));
 
-       ao_add_task(&ao_mma655x_task, ao_mma655x, "mma655x");
+//     ao_add_task(&ao_mma655x_task, ao_mma655x, "mma655x");
 }
 
 #endif
index e8c80f1..b3e284e 100644 (file)
@@ -225,7 +225,7 @@ ao_mpu6000_setup(void)
        errors += ao_mpu6000_gyro_check(normal_mode.gyro_z, test_mode.gyro_z, "z");
 
        if (errors)
-               ao_panic(AO_PANIC_SELF_TEST);
+               ao_panic(AO_PANIC_SELF_TEST_MPU6000);
 
        /* Filter to about 100Hz, which also sets the gyro rate to 1000Hz */
        ao_mpu6000_reg_write(MPU6000_CONFIG,
index ec0d220..704b458 100644 (file)
@@ -27,12 +27,12 @@ static uint8_t                      ms5607_configured;
 static void
 ao_ms5607_start(void) {
        ao_spi_get(AO_MS5607_SPI_INDEX,AO_SPI_SPEED_FAST);
-       stm_gpio_set(AO_MS5607_CS_GPIO, AO_MS5607_CS, 0);
+       stm_gpio_set(AO_MS5607_CS_PORT, AO_MS5607_CS_PIN, 0);
 }
 
 static void
 ao_ms5607_stop(void) {
-       stm_gpio_set(AO_MS5607_CS_GPIO, AO_MS5607_CS, 1);
+       stm_gpio_set(AO_MS5607_CS_PORT, AO_MS5607_CS_PIN, 1);
        ao_spi_put(AO_MS5607_SPI_INDEX);
 }
 
@@ -92,7 +92,7 @@ ao_ms5607_prom_read(struct ao_ms5607_prom *prom)
                printf ("MS5607 PROM CRC error (computed %x actual %x)\n",
                        crc, (((uint8_t *) prom)[15] & 0xf));
                flush();
-               ao_panic(AO_PANIC_SELF_TEST);
+//             ao_panic(AO_PANIC_SELF_TEST_MS5607);
        }
 
 #if __BYTE_ORDER == __LITTLE_ENDIAN
@@ -120,7 +120,7 @@ static uint8_t      ao_ms5607_done;
 static void
 ao_ms5607_isr(void)
 {
-       ao_exti_disable(AO_MS5607_MISO_GPIO, AO_MS5607_MISO);
+       ao_exti_disable(AO_MS5607_MISO_PORT, AO_MS5607_MISO_PIN);
        ao_ms5607_done = 1;
        ao_wakeup(&ao_ms5607_done);
 }
@@ -135,7 +135,7 @@ ao_ms5607_get_sample(uint8_t cmd) {
 
        ao_ms5607_start();
        ao_spi_send(&cmd, 1, AO_MS5607_SPI_INDEX);
-       ao_exti_enable(AO_MS5607_MISO_GPIO, AO_MS5607_MISO);
+       ao_exti_enable(AO_MS5607_MISO_PORT, AO_MS5607_MISO_PIN);
 #if AO_MS5607_PRIVATE_PINS
        ao_spi_put(AO_MS5607_SPI_INDEX);
 #endif
@@ -144,7 +144,7 @@ ao_ms5607_get_sample(uint8_t cmd) {
                ao_sleep(&ao_ms5607_done);
        sei();
 #if AO_MS5607_PRIVATE_PINS
-       stm_gpio_set(AO_MS5607_CS_GPIO, AO_MS5607_CS, 1);
+       stm_gpio_set(AO_MS5607_CS_PORT, AO_MS5607_CS_PIN, 1);
 #else
        ao_ms5607_stop();
 #endif
@@ -235,13 +235,14 @@ ao_ms5607_info(void)
 static void
 ao_ms5607_dump(void)
 {
-       struct ao_data  sample;
+       struct ao_ms5607_sample sample;
        struct ao_ms5607_value value;
 
-       ao_data_get(&sample);
-       ao_ms5607_convert(&sample.ms5607_raw, &value);
-       printf ("Pressure:    %8u %8d\n", sample.ms5607_raw.pres, value.pres);
-       printf ("Temperature: %8u %8d\n", sample.ms5607_raw.temp, value.temp);
+       ao_ms5607_setup();
+       ao_ms5607_sample(&sample);
+       ao_ms5607_convert(&sample, &value);
+       printf ("Pressure:    %8u %8d\n", sample.pres, value.pres);
+       printf ("Temperature: %8u %8d\n", sample.temp, value.temp);
        printf ("Altitude: %ld\n", ao_pa_to_altitude(value.pres));
 }
 
@@ -255,24 +256,24 @@ ao_ms5607_init(void)
 {
        ms5607_configured = 0;
        ao_cmd_register(&ao_ms5607_cmds[0]);
-       ao_spi_init_cs(AO_MS5607_CS_GPIO, (1 << AO_MS5607_CS));
+       ao_spi_init_cs(AO_MS5607_CS_PORT, (1 << AO_MS5607_CS_PIN));
 
-       ao_add_task(&ao_ms5607_task, ao_ms5607, "ms5607");
+//     ao_add_task(&ao_ms5607_task, ao_ms5607, "ms5607");
 
        /* Configure the MISO pin as an interrupt; when the
         * conversion is complete, the MS5607 will raise this
         * pin as a signal
         */
-       ao_exti_setup(AO_MS5607_MISO_GPIO,
-                     AO_MS5607_MISO,
+       ao_exti_setup(AO_MS5607_MISO_PORT,
+                     AO_MS5607_MISO_PIN,
                      AO_EXTI_MODE_RISING,
                      ao_ms5607_isr);
 
        /* Reset the pin from INPUT to ALTERNATE so that SPI works
         * This needs an abstraction at some point...
         */
-       stm_moder_set(AO_MS5607_MISO_GPIO,
-                     AO_MS5607_MISO,
+       stm_moder_set(AO_MS5607_MISO_PORT,
+                     AO_MS5607_MISO_PIN,
                      STM_MODER_ALTERNATE);
 }
 
index 9a01bbf..1d1f16f 100644 (file)
@@ -32,7 +32,6 @@ ao_radio_slave_low(void)
 
        if (slave_state != 1)
                ao_panic(1);
-       ao_led_toggle(AO_LED_GREEN);
        ao_gpio_set(AO_RADIO_SLAVE_INT_PORT, AO_RADIO_SLAVE_INT_BIT, AO_RADIO_SLAVE_INT_PIN, 0);
        for (i = 0; i < 1000; i++)
                ao_arch_nop();
@@ -44,7 +43,6 @@ ao_radio_slave_high(void)
 {
        if (slave_state != 0)
                ao_panic(2);
-       ao_led_toggle(AO_LED_RED);
        ao_gpio_set(AO_RADIO_SLAVE_INT_PORT, AO_RADIO_SLAVE_INT_BIT, AO_RADIO_SLAVE_INT_PIN, 1);
        slave_state = 1;
 }
@@ -65,8 +63,10 @@ ao_radio_slave_spi(void)
                        /* XXX monitor CS to interrupt the receive */
 
                        ao_config.radio_setting = ao_radio_spi_request.setting;
+                       ao_led_on(AO_LED_RX);
                        ao_radio_spi_reply.status = ao_radio_recv(&ao_radio_spi_reply.payload,
                                                                  ao_radio_spi_request.recv_len);
+                       ao_led_off(AO_LED_RX);
                        ao_radio_spi_reply.rssi = 0;
                        ao_spi_send(&ao_radio_spi_reply,
                                    AO_RADIO_SPI_REPLY_HEADER_LEN + ao_radio_spi_request.recv_len,
@@ -76,9 +76,11 @@ ao_radio_slave_spi(void)
                        continue;
                case AO_RADIO_SPI_CMAC_RECV:
                        ao_config.radio_setting = ao_radio_spi_request.setting;
+                       ao_led_on(AO_LED_RX);
                        ao_radio_spi_reply.status = ao_radio_cmac_recv(&ao_radio_spi_reply.payload,
                                                                       ao_radio_spi_request.recv_len,
                                                                       ao_radio_spi_request.timeout);
+                       ao_led_off(AO_LED_RX);
                        ao_radio_spi_reply.rssi = ao_radio_cmac_rssi;
                        ao_spi_send(&ao_radio_spi_reply,
                                    AO_RADIO_SPI_REPLY_HEADER_LEN + ao_radio_spi_request.recv_len,
@@ -88,14 +90,18 @@ ao_radio_slave_spi(void)
                        continue;
                case AO_RADIO_SPI_SEND:
                        ao_config.radio_setting = ao_radio_spi_request.setting;
+                       ao_led_on(AO_LED_TX);
                        ao_radio_send(&ao_radio_spi_request.payload,
                                      ao_radio_spi_request.len - AO_RADIO_SPI_REQUEST_HEADER_LEN);
+                       ao_led_off(AO_LED_TX);
                        break;
 
                case AO_RADIO_SPI_CMAC_SEND:
                        ao_config.radio_setting = ao_radio_spi_request.setting;
+                       ao_led_on(AO_LED_TX);
                        ao_radio_cmac_send(&ao_radio_spi_request.payload,
                                           ao_radio_spi_request.len - AO_RADIO_SPI_REQUEST_HEADER_LEN);
+                       ao_led_off(AO_LED_TX);
                        break;
                        
                case AO_RADIO_SPI_CMAC_KEY:
index 8b631ae..af8eeba 100644 (file)
 #define SPI_2_PB13_PB14_PB15   1       /* Flash, Companion */
 #define SPI_2_PD1_PD3_PD4      0
 
-#define SPI_2_GPIO             (&stm_gpiob)
-#define SPI_2_SCK              13
-#define SPI_2_MISO             14
-#define SPI_2_MOSI             15
+#define SPI_2_PORT             (&stm_gpiob)
+#define SPI_2_SCK_PIN          13
+#define SPI_2_MISO_PIN         14
+#define SPI_2_MOSI_PIN         15
 
 #define HAS_I2C_1              1
 #define I2C_1_PB8_PB9          1
@@ -249,11 +249,11 @@ struct ao_adc {
  */
 #define HAS_MS5607             1
 #define AO_MS5607_PRIVATE_PINS 1
-#define AO_MS5607_CS_GPIO      (&stm_gpioc)
-#define AO_MS5607_CS           4
+#define AO_MS5607_CS_PORT      (&stm_gpioc)
+#define AO_MS5607_CS_PIN       4
 #define AO_MS5607_CS_MASK      (1 << AO_MS5607_CS)
-#define AO_MS5607_MISO_GPIO    (&stm_gpioa)
-#define AO_MS5607_MISO         6
+#define AO_MS5607_MISO_PORT    (&stm_gpioa)
+#define AO_MS5607_MISO_PIN     6
 #define AO_MS5607_MISO_MASK    (1 << AO_MS5607_MISO)
 #define AO_MS5607_SPI_INDEX    AO_SPI_1_PA5_PA6_PA7
 
@@ -309,10 +309,10 @@ struct ao_adc {
  * mma655x
  */
 
-#define HAS_MMA655X            0
-#define AO_MMA655X_SPI_INDEX   AO_SPI_1_PA5_PA6_PA7
-#define AO_MMA655X_CS_GPIO     (&stm_gpiod)
-#define AO_MMA655X_CS          4
+#define HAS_MMA655X            1
+#define AO_MMA655X_SPI_INDEX   AO_SPI_1_PE13_PE14_PE15
+#define AO_MMA655X_CS_PORT     (&stm_gpiod)
+#define AO_MMA655X_CS_PIN      4
 
 #define NUM_CMDS               16
 
index 2d594d7..45b6d40 100644 (file)
@@ -16,7 +16,6 @@
  */
 
 #include "ao.h"
-#include "ao_pwmin.h"
 
 int
 main(void)
@@ -35,7 +34,6 @@ main(void)
        ao_usb_init();
        ao_adc_init();
        ao_log_single_init();
-       ao_pwmin_init();
        ao_start_scheduler();
        return 0;
 }
index 5542913..d24128e 100644 (file)
@@ -53,7 +53,6 @@ ALTOS_SRC = \
        ao_adc_avr.c \
        ao_science_slave.c \
        ao_spi_slave.c \
-       ao_pwmin.c \
        $(TELESCIENCE_STORAGE)\
        $(TELESCIENCE_LOG)