altos: Allow use of internal EEPROM for config storage
authorKeith Packard <keithp@keithp.com>
Tue, 12 Nov 2013 06:45:32 +0000 (15:45 +0900)
committerKeith Packard <keithp@keithp.com>
Tue, 12 Nov 2013 07:27:31 +0000 (16:27 +0900)
This stops exposing eeprom as 'storage' and instead exposes it with a
separate eeprom API so that it can be used for config storage without
also using it for flight log storage.

The config code has been changed to allow it to either use storage for
configuration data or eeprom.

Signed-off-by: Keith Packard <keithp@keithp.com>
12 files changed:
src/core/ao_config.c
src/core/ao_config.h [new file with mode: 0644]
src/core/ao_eeprom.h [new file with mode: 0644]
src/core/ao_storage.c
src/core/ao_storage.h
src/stm/ao_eeprom_stm.c
src/telegps-v0.1/Makefile
src/telegps-v0.1/ao_pins.h
src/telegps-v0.1/ao_telegps.c
src/telelco-v0.2/Makefile
src/telelco-v0.2/ao_pins.h
src/telelco-v0.2/ao_telelco.c

index 82faf32bbb904b22517fb814f86d829f30231d3f..5567587be382eca79a83155f361e2c80ac5c5340 100644 (file)
@@ -17,7 +17,7 @@
 
 #include "ao.h"
 #include "ao_log.h"
-#include <ao_storage.h>
+#include <ao_config.h>
 #if HAS_FLIGHT
 #include <ao_sample.h>
 #include <ao_data.h>
@@ -59,13 +59,12 @@ __xdata uint8_t ao_config_mutex;
 static void
 _ao_config_put(void)
 {
-       ao_storage_setup();
-       ao_storage_erase(ao_storage_config);
-       ao_storage_write(ao_storage_config, &ao_config, sizeof (ao_config));
+       ao_config_setup();
+       ao_config_write(&ao_config, sizeof (ao_config));
 #if HAS_FLIGHT
        ao_log_write_erase(0);
 #endif
-       ao_storage_flush();
+       ao_config_flush();
 }
 
 void
@@ -97,8 +96,8 @@ _ao_config_get(void)
         * but ao_storage_setup *also* sets ao_storage_config, which we
         * need before calling ao_storage_read here
         */
-       ao_storage_setup();
-       ao_storage_read(ao_storage_config, &ao_config, sizeof (ao_config));
+       ao_config_setup();
+       ao_config_read(&ao_config, sizeof (ao_config));
 #endif
        if (ao_config.major != AO_CONFIG_MAJOR) {
                ao_config.major = AO_CONFIG_MAJOR;
@@ -127,8 +126,10 @@ _ao_config_get(void)
                        ao_config.radio_cal = ao_radio_cal;
 #endif
                /* Fixups for minor version 4 */
+#if HAS_FLIGHT
                if (minor < 4)
                        ao_config.flight_log_max = AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX;
+#endif
                /* Fixupes for minor version 5 */
                if (minor < 5)
                        ao_config.ignite_mode = AO_CONFIG_DEFAULT_IGNITE_MODE;
@@ -655,7 +656,7 @@ static void
 ao_config_show(void) __reentrant;
 
 static void
-ao_config_write(void) __reentrant;
+ao_config_save(void) __reentrant;
 
 __code struct ao_config_var ao_config_vars[] = {
 #if HAS_FLIGHT
@@ -714,7 +715,7 @@ __code struct ao_config_var ao_config_vars[] = {
          ao_config_show,               0 },
 #if HAS_EEPROM
        { "w\0Write to eeprom",
-         ao_config_write,              0 },
+         ao_config_save,               0 },
 #endif
        { "?\0Help",
          ao_config_help,               0 },
@@ -766,7 +767,7 @@ ao_config_show(void) __reentrant
 
 #if HAS_EEPROM
 static void
-ao_config_write(void) __reentrant
+ao_config_save(void) __reentrant
 {
        uint8_t saved = 0;
        ao_mutex_get(&ao_config_mutex);
diff --git a/src/core/ao_config.h b/src/core/ao_config.h
new file mode 100644 (file)
index 0000000..5e38430
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright © 2013 Keith Packard <keithp@keithp.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.
+ */
+
+#ifndef _AO_CONFIG_H_
+#define _AO_CONFIG_H_
+
+#ifndef USE_STORAGE_CONFIG
+#define USE_STORAGE_CONFIG 1
+#endif
+
+#ifndef USE_EEPROM_CONFIG
+#define USE_EEPROM_CONFIG 0
+#endif
+
+#if USE_STORAGE_CONFIG
+
+#include <ao_storage.h>
+
+#define ao_config_setup()              ao_storage_setup()
+
+#define ao_config_write(bytes, len)    do {                            \
+               ao_storage_erase(ao_storage_config);                    \
+               ao_storage_write(ao_storage_config, bytes, len);        \
+       } while (0)
+
+#define ao_config_read(bytes, len)     ao_storage_read(ao_storage_config, bytes, len)
+
+#define ao_config_flush()              ao_storage_flush()
+
+#endif
+
+#if USE_EEPROM_CONFIG
+
+#include <ao_eeprom.h>
+
+#define ao_config_setup()
+#define ao_config_write(bytes, len)    ao_eeprom_write(0, bytes, len)
+#define ao_config_read(bytes, len)     ao_eeprom_read(0, bytes, len)
+#define ao_config_flush()
+
+#endif
+
+#endif /* _AO_CONFIG_H_ */
diff --git a/src/core/ao_eeprom.h b/src/core/ao_eeprom.h
new file mode 100644 (file)
index 0000000..915522b
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright © 2013 Keith Packard <keithp@keithp.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.
+ */
+
+#ifndef _AO_EEPROM_H_
+#define _AO_EEPROM_H_
+
+extern const ao_pos_t  ao_eeprom_total;
+
+/*
+ * Write to eeprom
+ */
+
+uint8_t
+ao_eeprom_write(ao_pos_t pos32, __xdata void *v, uint16_t len);
+
+/*
+ * Read from eeprom
+ */
+uint8_t
+ao_eeprom_read(ao_pos_t pos, __xdata void *v, uint16_t len);
+
+/*
+ * Initialize eeprom
+ */
+
+void
+ao_eeprom_init(void);
+
+#endif /* _AO_EEPROM_H_ */
index adf7e4d4949491f99a5609b2f22dc4fd650466b4..6eddae7f84dcdd754b8c46d54972d352f19fc754 100644 (file)
@@ -154,7 +154,7 @@ ao_storage_zapall(void) __reentrant
        ao_cmd_white();
        if (!ao_match_word("DoIt"))
                return;
-       for (pos = 0; pos < ao_storage_config; pos += ao_storage_block)
+       for (pos = 0; pos < ao_storage_log_max; pos += ao_storage_block)
                ao_storage_erase(pos);
 }
 
index ea94639980c0574105a280844f948c394780e538..d6e95605e7e6265e3bc8e17c8ff4ae3e2f3bdcb7 100644 (file)
@@ -35,9 +35,19 @@ extern __pdata ao_pos_t      ao_storage_total;
 /* Block size - device is erased in these units. At least 256 bytes */
 extern __pdata ao_pos_t        ao_storage_block;
 
+#ifndef USE_STORAGE_CONFIG
+#define USE_STORAGE_CONFIG 1
+#endif
+
+#if USE_STORAGE_CONFIG
 /* Byte offset of config block. Will be ao_storage_block bytes long */
 extern __pdata ao_pos_t        ao_storage_config;
 
+#define ao_storage_log_max     ao_storage_config
+#else
+#define ao_storage_log_max     ao_storage_total
+#endif
+
 /* Storage unit size - device reads and writes must be within blocks of this size. Usually 256 bytes. */
 extern __pdata uint16_t ao_storage_unit;
 
index 58783f1a0771262f6c573abc81162d8f09c0401f..4207a8607e3d593df3482505ad5ca42eb411d385 100644 (file)
  */
 
 #include <ao.h>
-#include <ao_storage.h>
+#include <ao_eeprom.h>
 
 /* Total bytes of available storage */
-ao_pos_t       ao_storage_total = 4096;
-
-/* Block size - device is erased in these units. */
-ao_pos_t       ao_storage_block = 1024;
-
-/* Byte offset of config block. Will be ao_storage_block bytes long */
-ao_pos_t       ao_storage_config = 0;
-
-/* Storage unit size - device reads and writes must be within blocks of this size. */
-uint16_t       ao_storage_unit = 1024;
+const ao_pos_t ao_eeprom_total = 4096;
 
 /* Location of eeprom in address space */
 #define stm_eeprom     ((uint8_t *) 0x08080000)
@@ -42,16 +33,6 @@ uint16_t     ao_storage_unit = 1024;
  * the same contents, or append to an existing page easily enough
  */
 
-/*
- * Erase the specified sector
- */
-uint8_t
-ao_storage_erase(ao_pos_t pos) __reentrant
-{
-       /* Not necessary */
-       return 1;
-}
-
 static void
 ao_intflash_unlock(void)
 {
@@ -131,16 +112,16 @@ ao_intflash_read(uint16_t pos)
 }
 
 /*
- * Write to flash
+ * Write to eeprom
  */
 
 uint8_t
-ao_storage_device_write(ao_pos_t pos32, __xdata void *v, uint16_t len) __reentrant
+ao_eeprom_write(ao_pos_t pos32, __xdata void *v, uint16_t len)
 {
        uint16_t pos = pos32;
        __xdata uint8_t *d = v;
 
-       if (pos >= ao_storage_total || pos + len > ao_storage_total)
+       if (pos >= ao_eeprom_total || pos + len > ao_eeprom_total)
                return 0;
 
        ao_intflash_unlock();
@@ -166,38 +147,26 @@ ao_storage_device_write(ao_pos_t pos32, __xdata void *v, uint16_t len) __reentra
 }
 
 /*
- * Read from flash
+ * Read from eeprom
  */
 uint8_t
-ao_storage_device_read(ao_pos_t pos, __xdata void *v, uint16_t len) __reentrant
+ao_eeprom_read(ao_pos_t pos, __xdata void *v, uint16_t len)
 {
        uint8_t *d = v;
        
-       if (pos >= ao_storage_total || pos + len > ao_storage_total)
+       if (pos >= ao_eeprom_total || pos + len > ao_eeprom_total)
                return 0;
        while (len--)
                *d++ = ao_intflash_read(pos++);
        return 1;
 }
 
-void
-ao_storage_flush(void) __reentrant
-{
-}
-
-void
-ao_storage_setup(void)
-{
-}
-
-void
-ao_storage_device_info(void) __reentrant
-{
-       uint8_t i;
-       printf ("Using internal flash\n");
-}
+/*
+ * Initialize eeprom
+ */
 
 void
-ao_storage_device_init(void)
+ao_eeprom_init(void)
 {
+       /* Nothing to do here */
 }
index 170294e6468b08094f796516bcdb41033ec681b8..f5533d51a9f34d4c63d1b5be947757f0e58cdb24 100644 (file)
@@ -57,7 +57,6 @@ ALTOS_SRC = \
        ao_fec_tx.c \
        ao_rfpa0133.c \
        ao_aprs.c \
-       ao_storage.c \
        ao_eeprom_stm.c \
        ao_sdcard.c \
        ao_bufio.c \
index 5bea2681b24657ebd160e313c86ffbffab51cb74..7ff599562dff637263528423901c38df70aab36f 100644 (file)
 #define ao_gps_fifo            (ao_stm_usart2.rx_fifo)
 
 #define HAS_EEPROM             1
-#define USE_INTERNAL_FLASH     1
+#define USE_INTERNAL_FLASH     0
+#define USE_EEPROM_CONFIG      1
+#define USE_STORAGE_CONFIG     0
+
 #define HAS_USB                        1
 #define HAS_BEEP               0
 #define HAS_RADIO              1
index 68116bfb0f2a5af0a569ed708a2e898c57811ac5..bc37b504fd43da32f247d93a8d2b087891cb950e 100644 (file)
@@ -18,6 +18,7 @@
 #include <ao.h>
 #include <ao_exti.h>
 #include <ao_fat.h>
+#include <ao_eeprom.h>
 
 uint16_t       ao_flight_number = 1;
 
@@ -40,7 +41,7 @@ main(void)
        ao_dma_init();
        ao_exti_init();
 
-       ao_storage_init();
+       ao_eeprom_init();
 
        ao_serial_init();
 
index bc5f8571969210507b25f7198b11e3d09be6b45f..2fb4db5e6cda4de8fe1efffd0329d3db6ebf9056 100644 (file)
@@ -48,7 +48,6 @@ ALTOS_SRC = \
        ao_dma_stm.c \
        ao_spi_stm.c \
        ao_beep_stm.c \
-       ao_storage.c \
        ao_eeprom_stm.c \
        ao_fast_timer.c \
        ao_lcd_stm.c \
index d86782f3393b4d64754dc350490ba7cc0a43fc5e..62f221a1da8979402697e6da3dfbebe94db05bbe 100644 (file)
@@ -43,6 +43,8 @@
 
 #define HAS_EEPROM             1
 #define USE_INTERNAL_FLASH     1
+#define USE_EEPROM_CONFIG      1
+#define USE_STORAGE_CONFIG     0
 #define HAS_USB                        1
 #define HAS_BEEP               1
 #define HAS_RADIO              1
index 66bf0ba18e6ee7d7007b36baefd08e2a73974a10..d9f7c693823da1b8bb168452b9b412d56a16c6cc 100644 (file)
@@ -28,6 +28,7 @@
 #include <ao_lco.h>
 #include <ao_lco_cmd.h>
 #include <ao_radio_cmac_cmd.h>
+#include <ao_eeprom.h>
 
 int
 main(void)
@@ -52,7 +53,7 @@ main(void)
        ao_quadrature_init();
        ao_button_init();
 
-       ao_storage_init();
+       ao_eeprom_init();
        
        ao_radio_init();