altos: Save some memory.
authorKeith Packard <keithp@keithp.com>
Wed, 11 Jul 2012 03:32:31 +0000 (20:32 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 11 Jul 2012 03:32:31 +0000 (20:32 -0700)
A few minor space savings in ao_cmd.c and ao_config.c.  Don't build
unused conversion functions ao_altitude_to_pres and ao_temp_to_dC

Signed-off-by: Keith Packard <keithp@keithp.com>
src/core/ao_cmd.c
src/core/ao_config.c
src/core/ao_convert.c
src/core/ao_convert_test.c
src/test/ao_flight_test.c

index fbf0c34778094ae08ec176525bc58d49318a2ec8..05dbfb51f04a57d6281de37ee92d19c8928d1d4e 100644 (file)
@@ -36,10 +36,16 @@ put_string(__code char *s)
                putchar(c);
 }
 
+static void
+backspace(void)
+{
+       put_string ("\010 \010");
+}
+
 static void
 readline(void)
 {
-       __pdata char c;
+       char c;
        if (ao_echo())
                put_string("> ");
        cmd_len = 0;
@@ -50,7 +56,7 @@ readline(void)
                if (c == '\010' || c == '\177') {
                        if (cmd_len != 0) {
                                if (ao_echo())
-                                       put_string("\010 \010");
+                                       backspace();
                                --cmd_len;
                        }
                        continue;
@@ -60,7 +66,7 @@ readline(void)
                if (c == '\025') {
                        while (cmd_len != 0) {
                                if (ao_echo())
-                                       put_string("\010 \010");
+                                       backspace();
                                --cmd_len;
                        }
                        continue;
@@ -76,11 +82,8 @@ readline(void)
                        break;
                }
 
-               if (cmd_len >= CMD_LEN - 2) {
-                       if (ao_echo())
-                               putchar('\007');
+               if (cmd_len >= CMD_LEN - 2)
                        continue;
-               }
                cmd_line[cmd_len++] = c;
                if (ao_echo())
                        putchar(c);
@@ -271,13 +274,12 @@ help(void)
        __pdata uint8_t cmds;
        __pdata uint8_t cmd;
        __code struct ao_cmds * __pdata cs;
+       const char *h;
 
        for (cmds = 0; cmds < ao_ncmds; cmds++) {
                cs = ao_cmds[cmds];
-               for (cmd = 0; cs[cmd].func; cmd++)
-                       printf("%-45s %s\n",
-                              cs[cmd].help,
-                              cs[cmd].help+1+strlen(cs[cmd].help));
+               for (cmd = 0; (h = cs[cmd].help); cmd++)
+                       printf("%-45s %s\n", h, h + 1 + strlen(h));
        }
 }
 
index cc580d666ede29b97dce87cccbec54b205719485..e0dabcd9cc60120ac9dfa153bc80c3a9ca433626 100644 (file)
@@ -78,6 +78,8 @@ ao_config_set_radio(void)
 static void
 _ao_config_get(void)
 {
+       uint8_t minor;
+
        if (ao_config_loaded)
                return;
 #if HAS_EEPROM
@@ -97,37 +99,37 @@ _ao_config_get(void)
                ao_xmemset(&ao_config.callsign, '\0', sizeof (ao_config.callsign));
                ao_xmemcpy(&ao_config.callsign, CODE_TO_XDATA(AO_CONFIG_DEFAULT_CALLSIGN),
                       sizeof(AO_CONFIG_DEFAULT_CALLSIGN) - 1);
-               ao_config_dirty = 1;
        }
-       if (ao_config.minor != AO_CONFIG_MINOR) {
+       minor = ao_config.minor;
+       if (minor != AO_CONFIG_MINOR) {
                /* Fixups for minor version 1 */
-               if (ao_config.minor < 1)
+               if (minor < 1)
                        ao_config.apogee_delay = AO_CONFIG_DEFAULT_APOGEE_DELAY;
                /* Fixups for minor version 2 */
-               if (ao_config.minor < 2) {
+               if (minor < 2) {
                        ao_config.accel_plus_g = 0;
                        ao_config.accel_minus_g = 0;
                }
                /* Fixups for minor version 3 */
 #if HAS_RADIO
-               if (ao_config.minor < 3)
+               if (minor < 3)
                        ao_config.radio_cal = ao_radio_cal;
 #endif
                /* Fixups for minor version 4 */
-               if (ao_config.minor < 4)
+               if (minor < 4)
                        ao_config.flight_log_max = AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX;
                /* Fixupes for minor version 5 */
-               if (ao_config.minor < 5)
+               if (minor < 5)
                        ao_config.ignite_mode = AO_CONFIG_DEFAULT_IGNITE_MODE;
-               if (ao_config.minor < 6)
+               if (minor < 6)
                        ao_config.pad_orientation = AO_CONFIG_DEFAULT_PAD_ORIENTATION;
-               if (ao_config.minor < 8)
+               if (minor < 8)
                        ao_config.radio_enable = TRUE;
-               if (ao_config.minor < 9)
+               if (minor < 9)
                        ao_xmemset(&ao_config.aes_key, '\0', AO_AES_LEN);
-               if (ao_config.minor < 10)
+               if (minor < 10)
                        ao_config.frequency = 434550;
-               if (ao_config.minor < 11)
+               if (minor < 11)
                        ao_config.apogee_lockout = 0;
                ao_config.minor = AO_CONFIG_MINOR;
                ao_config_dirty = 1;
index 0969f107928272e18f04990a428cebc3ba2dcc63..aa9b5f484b438e0871aa395a1cd37d7979237a11 100644 (file)
@@ -41,6 +41,7 @@ ao_pres_to_altitude(int16_t pres) __reentrant
                (int32_t) altitude_table[o+1] * part + (ALT_FRAC_SCALE >> 1)) >> ALT_FRAC_BITS;
 }
 
+#if AO_NEED_ALTITUDE_TO_PRES
 int16_t
 ao_altitude_to_pres(int16_t alt) __reentrant
 {
@@ -66,7 +67,9 @@ ao_altitude_to_pres(int16_t alt) __reentrant
                pres = 0;
        return (int16_t) pres;
 }
+#endif
 
+#if 0
 int16_t
 ao_temp_to_dC(int16_t temp) __reentrant
 {
@@ -83,3 +86,4 @@ ao_temp_to_dC(int16_t temp) __reentrant
        ret = ((temp - 19791) * 1012L) >> 16;
        return ret;
 }
+#endif
index e2c28b73e06058bf84359d09b74c58a9dba1ee6f..87e7684114915c1fd24ea766fd4f28110b6f82cc 100644 (file)
 
 #include <stdint.h>
 #define AO_CONVERT_TEST
+#define AO_NEED_ALTITUDE_TO_PRES 1
 #include "ao_host.h"
 #include "ao_convert.c"
 
 #define STEP   1
 
-static inline i_abs(int i) { return i < 0 ? -i : i; }
+static inline int i_abs(int i) { return i < 0 ? -i : i; }
 
-main ()
+int main (int argc, char **argv)
 {
        int     i;
        int16_t p_to_a, p_to_a_to_p;
index 9bb03d682f55c3c97fe2de9da639fdee5aecdb2c..a4ef8dc097c4bb127f6a47f25a9db2fa64c5f177 100644 (file)
@@ -180,6 +180,7 @@ struct ao_cmds {
 #define ao_xmemset(d,v,c) memset(d,v,c)
 #define ao_xmemcmp(d,s,c) memcmp(d,s,c)
 
+#define AO_NEED_ALTITUDE_TO_PRES 1
 #include "ao_convert.c"
 
 struct ao_config {