altos: Move TeleMetrum v2.0 to using internal eeprom for config
authorKeith Packard <keithp@keithp.com>
Tue, 12 Nov 2013 07:06:59 +0000 (16:06 +0900)
committerKeith Packard <keithp@keithp.com>
Tue, 12 Nov 2013 07:27:31 +0000 (16:27 +0900)
This leaves the whole 8MB of flash for flight storage

Signed-off-by: Keith Packard <keithp@keithp.com>
src/core/ao_config.c
src/core/ao_config.h
src/core/ao_log.c
src/telemetrum-v2.0/Makefile
src/telemetrum-v2.0/ao_pins.h
src/telemetrum-v2.0/ao_telemetrum.c

index 5567587be382eca79a83155f361e2c80ac5c5340..a30ec64a5e8a9d0c1c4c8ea59d7766e363ae5ea2 100644 (file)
@@ -60,7 +60,8 @@ static void
 _ao_config_put(void)
 {
        ao_config_setup();
-       ao_config_write(&ao_config, sizeof (ao_config));
+       ao_config_erase();
+       ao_config_write(0, &ao_config, sizeof (ao_config));
 #if HAS_FLIGHT
        ao_log_write_erase(0);
 #endif
@@ -97,7 +98,7 @@ _ao_config_get(void)
         * need before calling ao_storage_read here
         */
        ao_config_setup();
-       ao_config_read(&ao_config, sizeof (ao_config));
+       ao_config_read(0, &ao_config, sizeof (ao_config));
 #endif
        if (ao_config.major != AO_CONFIG_MAJOR) {
                ao_config.major = AO_CONFIG_MAJOR;
@@ -466,7 +467,7 @@ void
 ao_config_log_set(void) __reentrant
 {
        uint16_t        block = (uint16_t) (ao_storage_block >> 10);
-       uint16_t        config = (uint16_t) (ao_storage_config >> 10);
+       uint16_t        log_max = (uint16_t) (ao_storage_log_max >> 10);
 
        ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
@@ -475,8 +476,8 @@ ao_config_log_set(void) __reentrant
                printf("Storage must be empty before changing log size\n");
        else if (block > 1024 && (ao_cmd_lex_i & (block - 1)))
                printf("Flight log size must be multiple of %d kB\n", block);
-       else if (ao_cmd_lex_i > config)
-               printf("Flight log max %d kB\n", config);
+       else if (ao_cmd_lex_i > log_max)
+               printf("Flight log max %d kB\n", log_max);
        else {
                _ao_config_edit_start();
                ao_config.flight_log_max = (uint32_t) ao_cmd_lex_i << 10;
index 5e38430e4f9092a49ba6158ee3fa77dd115f25b6..e101af8ee27fffa082fc524ff080fd146573b79e 100644 (file)
 #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_erase()              ao_storage_erase(ao_storage_config)
+#define ao_config_write(pos,bytes, len)        ao_storage_write(ao_storage_config+(pos), bytes, len)
+#define ao_config_read(pos,bytes, len) ao_storage_read(ao_storage_config+(pos), bytes, len)
 #define ao_config_flush()              ao_storage_flush()
 
 #endif
@@ -48,8 +43,9 @@
 #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_erase()
+#define ao_config_write(pos,bytes, len)        ao_eeprom_write(pos, bytes, len)
+#define ao_config_read(pos,bytes, len) ao_eeprom_read(pos, bytes, len)
 #define ao_config_flush()
 
 #endif
index 8bcb770763c0efe70ad1917c4d8caabc14ab257c..1a1f5ff6c37a7c56bd4f6944b59616d599c6da5a 100644 (file)
@@ -17,6 +17,7 @@
 
 #include "ao.h"
 #include <ao_log.h>
+#include <ao_config.h>
 
 __pdata uint32_t ao_log_current_pos;
 __pdata uint32_t ao_log_end_pos;
@@ -48,7 +49,7 @@ static __xdata struct ao_log_erase erase;
 static uint32_t
 ao_log_erase_pos(uint8_t i)
 {
-       return i * sizeof (struct ao_log_erase) + AO_STORAGE_ERASE_LOG;
+       return i * sizeof (struct ao_log_erase);
 }
 
 void
@@ -56,14 +57,14 @@ ao_log_write_erase(uint8_t pos)
 {
        erase.unused = 0x00;
        erase.flight = ao_flight_number;
-       ao_storage_write(ao_log_erase_pos(pos),  &erase, sizeof (erase));
-       ao_storage_flush();
+       ao_config_write(ao_log_erase_pos(pos),  &erase, sizeof (erase));
+       ao_config_flush();
 }
 
 static void
 ao_log_read_erase(uint8_t pos)
 {
-       ao_storage_read(ao_log_erase_pos(pos), &erase, sizeof (erase));
+       ao_config_read(ao_log_erase_pos(pos), &erase, sizeof (erase));
 }
 
 
@@ -87,7 +88,7 @@ ao_log_erase_mark(void)
 static uint8_t
 ao_log_slots()
 {
-       return (uint8_t) (ao_storage_config / ao_config.flight_log_max);
+       return (uint8_t) (ao_storage_log_max / ao_config.flight_log_max);
 }
 
 uint32_t
index be72d493b90064428536872e494195f5c9b07abe..a5370224cb172d0b48e722a4fb09171a919153c4 100644 (file)
@@ -70,6 +70,7 @@ ALTOS_SRC = \
        ao_m25.c \
        ao_usb_stm.c \
        ao_exti_stm.c \
+       ao_eeprom_stm.c \
        ao_report.c \
        ao_convert_pa.c \
        ao_log.c \
index a7236b808eb1f466ecc14494dec144bfe07ec922..02f0f5e3efecc9b3648f02f7b0ecc61b9a937016 100644 (file)
 #define SERIAL_3_PC10_PC11     0
 #define SERIAL_3_PD8_PD9       0
 
+#define AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX       (512 * 1024)
 #define HAS_EEPROM             1
 #define USE_INTERNAL_FLASH     0
+#define USE_EEPROM_CONFIG      1
+#define USE_STORAGE_CONFIG     0
 #define HAS_USB                        1
 #define HAS_BEEP               1
 #define BEEPER_CHANNEL         4
index d79aba5405552666fda821b3b877b450f98c4d69..23556c6c5cc9310c8e708a33b1d2e8de5702c7f1 100644 (file)
@@ -62,6 +62,8 @@ main(void)
        ao_mma655x_init();
 #endif
 
+       ao_eeprom_init();
+
        ao_storage_init();
        
        ao_flight_init();