accumulated hacks
[fw/altos] / src / kernel / ao_flight.c
index 170396ff160ab41473f656d8b125d9b8f593b623..ba1f00d0abc72196b89cdf9ca76b778ff3150eb9 100644 (file)
@@ -21,6 +21,8 @@
 #include <ao_log.h>
 #endif
 
+#include <ao_flight.h>
+
 #if HAS_MPU6000 || HAS_MPU9250
 #include <ao_quaternion.h>
 #endif
 
 /* Main flight thread. */
 
-__pdata enum ao_flight_state   ao_flight_state;        /* current flight state */
-__pdata uint16_t               ao_boost_tick;          /* time of most recent boost detect */
-__pdata uint16_t               ao_launch_tick;         /* time of first boost detect */
-__pdata uint16_t               ao_motor_number;        /* number of motors burned so far */
+enum ao_flight_state   ao_flight_state;        /* current flight state */
+uint16_t               ao_boost_tick;          /* time of most recent boost detect */
+uint16_t               ao_launch_tick;         /* time of first boost detect */
+uint16_t               ao_motor_number;        /* number of motors burned so far */
 
 #if HAS_SENSOR_ERRORS
 /* Any sensor can set this to mark the flight computer as 'broken' */
-__xdata uint8_t                        ao_sensor_errors;
+uint8_t                        ao_sensor_errors;
 #endif
 
 /*
  * track min/max data over a long interval to detect
  * resting
  */
-static __data uint16_t         ao_interval_end;
-static __data ao_v_t           ao_interval_min_height;
-static __data ao_v_t           ao_interval_max_height;
+static uint16_t                ao_interval_end;
+static ao_v_t          ao_interval_min_height;
+static ao_v_t          ao_interval_max_height;
 #if HAS_ACCEL
-static __data ao_v_t           ao_coast_avg_accel;
+static ao_v_t          ao_coast_avg_accel;
 #endif
 
-__pdata uint8_t                        ao_flight_force_idle;
+uint8_t                        ao_flight_force_idle;
 
 /* We also have a clock, which can be used to sanity check things in
  * case of other failures
@@ -108,10 +110,12 @@ ao_flight(void)
 #if HAS_ACCEL
                        if (ao_config.accel_plus_g == 0 ||
                            ao_config.accel_minus_g == 0 ||
-                           ao_ground_accel < ao_config.accel_plus_g - ACCEL_NOSE_UP ||
-                           ao_ground_accel > ao_config.accel_minus_g + ACCEL_NOSE_UP ||
-                           ao_ground_height < -1000 ||
-                           ao_ground_height > 7000)
+                           ao_ground_accel < ao_config.accel_plus_g - ACCEL_NOSE_UP
+#if HAS_BARO
+                           || ao_ground_accel > ao_config.accel_minus_g + ACCEL_NOSE_UP
+                           || ao_ground_height < -1000 || ao_ground_height > 7000
+#endif
+                               )
                        {
                                /* Detected an accel value outside -1.5g to 1.5g
                                 * (or uncalibrated values), so we go into invalid mode
@@ -203,7 +207,9 @@ ao_flight(void)
                                ao_launch_tick = ao_boost_tick = ao_sample_tick;
 
                                /* start logging data */
+#if HAS_LOG
                                ao_log_start();
+#endif
 
 #if HAS_TELEMETRY
                                /* Increase telemetry rate */
@@ -444,7 +450,9 @@ ao_flight_dump(void)
        printf ("  max_height  %d\n", ao_max_height);
        printf ("  avg_height  %d\n", ao_avg_height);
        printf ("  error_h     %d\n", ao_error_h);
+#if !HAS_ACCEL
        printf ("  error_avg   %d\n", ao_error_h_sq_avg);
+#endif
 }
 
 static void
@@ -463,7 +471,7 @@ ao_orient_test_select(void)
        ao_orient_test = !ao_orient_test;
 }
 
-__code struct ao_cmds ao_flight_cmds[] = {
+const struct ao_cmds ao_flight_cmds[] = {
        { ao_flight_dump,       "F\0Dump flight status" },
        { ao_gyro_test,         "G\0Test gyro code" },
        { ao_orient_test_select,"O\0Test orientation code" },
@@ -471,7 +479,7 @@ __code struct ao_cmds ao_flight_cmds[] = {
 };
 #endif
 
-static __xdata struct ao_task  flight_task;
+static struct ao_task  flight_task;
 
 void
 ao_flight_init(void)