summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2014-08-17 20:59:45 -0700
committerKeith Packard <keithp@keithp.com>2014-08-17 20:59:45 -0700
commitbb7522acf040f41740ecd059e3d5d2480b652420 (patch)
tree9c174cdac4493d3e2ab0fdec0ca065df0d25f2ed /src
parent1530c24cc75cdf9ba87c7e153ff28bf7beb4384c (diff)
telegps-v1.0: Provide one log and append to it
Instead of creating per-flight logs, create a single log and append data to it each time TeleGPS is powered on. This avoids potentially running out of log space just because the device is powered off/on. Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src')
-rw-r--r--src/kernel/ao_config.c38
-rw-r--r--src/kernel/ao_config.h7
-rw-r--r--src/kernel/ao_log.c134
-rw-r--r--src/kernel/ao_log.h5
-rw-r--r--src/kernel/ao_log_gps.c14
-rw-r--r--src/telegps-v1.0/ao_pins.h2
6 files changed, 160 insertions, 40 deletions
diff --git a/src/kernel/ao_config.c b/src/kernel/ao_config.c
index d73a3733..d1b93122 100644
--- a/src/kernel/ao_config.c
+++ b/src/kernel/ao_config.c
@@ -50,13 +50,19 @@ __xdata uint8_t ao_config_mutex;
#error Please define USE_INTERNAL_FLASH
#endif
#endif
+
#ifndef AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX
-#if USE_INTERNAL_FLASH
-#define AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX ao_storage_config
-#else
-#define AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX ((uint32_t) 192 * (uint32_t) 1024)
-#endif
+# if FLIGHT_LOG_APPEND
+# define AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX ao_storage_log_max
+# else
+# if USE_INTERNAL_FLASH
+# define AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX ao_storage_config
+# else
+# define AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX ((uint32_t) 192 * (uint32_t) 1024)
+# endif
+# endif
#endif
+
#ifndef AO_CONFIG_DEFAULT_RADIO_POWER
#define AO_CONFIG_DEFAULT_RADIO_POWER 0x60
#endif
@@ -525,15 +531,36 @@ ao_config_radio_rate_set(void) __reentrant
#endif
#if HAS_LOG
+
void
ao_config_log_show(void) __reentrant
{
printf("Max flight log: %d kB\n", (int16_t) (ao_config.flight_log_max >> 10));
+#if FLIGHT_LOG_APPEND
+ printf("Log fixed: 1\n");
+#endif
+}
+
+#if FLIGHT_LOG_APPEND
+void
+ao_config_log_fix_append(void)
+{
+ _ao_config_edit_start();
+ ao_config.flight_log_max = ao_storage_log_max;
+ _ao_config_edit_finish();
+ ao_mutex_get(&ao_config_mutex);
+ _ao_config_put();
+ ao_config_dirty = 0;
+ ao_mutex_put(&ao_config_mutex);
}
+#endif
void
ao_config_log_set(void) __reentrant
{
+#if FLIGHT_LOG_APPEND
+ printf("Flight log fixed size %d kB\n", ao_storage_log_max >> 10);
+#else
uint16_t block = (uint16_t) (ao_storage_block >> 10);
uint16_t log_max = (uint16_t) (ao_storage_log_max >> 10);
@@ -551,6 +578,7 @@ ao_config_log_set(void) __reentrant
ao_config.flight_log_max = (uint32_t) ao_cmd_lex_i << 10;
_ao_config_edit_finish();
}
+#endif
}
#endif /* HAS_LOG */
diff --git a/src/kernel/ao_config.h b/src/kernel/ao_config.h
index a650ffc6..0be3e14d 100644
--- a/src/kernel/ao_config.h
+++ b/src/kernel/ao_config.h
@@ -28,6 +28,10 @@
#define USE_EEPROM_CONFIG 0
#endif
+#ifndef FLIGHT_LOG_APPEND
+#define FLIGHT_LOG_APPEND 0
+#endif
+
#if USE_STORAGE_CONFIG
#include <ao_storage.h>
@@ -147,6 +151,9 @@ void
ao_config_set_radio(void);
void
+ao_config_log_fix_append(void);
+
+void
ao_config_init(void);
#endif /* _AO_CONFIG_H_ */
diff --git a/src/kernel/ao_log.c b/src/kernel/ao_log.c
index 91617d93..dc3b6486 100644
--- a/src/kernel/ao_log.c
+++ b/src/kernel/ao_log.c
@@ -142,19 +142,39 @@ ao_log_max_flight(void)
return max_flight;
}
-void
-ao_log_scan(void) __reentrant
+static void
+ao_log_erase(uint8_t slot) __reentrant
{
- uint8_t log_slot;
- uint8_t log_slots;
- uint8_t log_want;
+ uint32_t log_current_pos, log_end_pos;
- ao_config_get();
+ ao_log_erase_mark();
+ log_current_pos = ao_log_pos(slot);
+ log_end_pos = log_current_pos + ao_config.flight_log_max;
+ while (log_current_pos < log_end_pos) {
+ uint8_t i;
+ static __xdata uint8_t b;
+
+ /*
+ * Check to see if we've reached the end of
+ * the used memory to avoid re-erasing the same
+ * memory over and over again
+ */
+ for (i = 0; i < 16; i++) {
+ if (ao_storage_read(log_current_pos + i, &b, 1))
+ if (b != 0xff)
+ break;
+ }
+ if (i == 16)
+ break;
+ ao_storage_erase(log_current_pos);
+ log_current_pos += ao_storage_block;
+ }
+}
- ao_flight_number = ao_log_max_flight();
- if (ao_flight_number)
- if (++ao_flight_number == 0)
- ao_flight_number = 1;
+static void
+ao_log_find_max_erase_flight(void) __reentrant
+{
+ uint8_t log_slot;
/* Now look through the log of flight numbers from erase operations and
* see if the last one is bigger than what we found above
@@ -170,6 +190,74 @@ ao_log_scan(void) __reentrant
}
if (ao_flight_number == 0)
ao_flight_number = 1;
+}
+
+void
+ao_log_scan(void) __reentrant
+{
+ uint8_t log_slot;
+ uint8_t log_slots;
+#if !FLIGHT_LOG_APPEND
+ uint8_t log_want;
+#endif
+
+ ao_config_get();
+
+ /* Get any existing flight number */
+ ao_flight_number = ao_log_max_flight();
+
+#if FLIGHT_LOG_APPEND
+
+ /* Deal with older OS versions which stored multiple
+ * flights in rom by erasing everything after the first
+ * slot
+ */
+ if (ao_config.flight_log_max != ao_storage_log_max) {
+ log_slots = ao_log_slots();
+ for (log_slot = 1; log_slot < log_slots; log_slot++) {
+ if (ao_log_flight(log_slot) != 0)
+ ao_log_erase(log_slot);
+ }
+ ao_config_log_fix_append();
+ }
+ ao_log_current_pos = ao_log_pos(0);
+ ao_log_end_pos = ao_log_current_pos + ao_storage_log_max;
+
+ if (ao_flight_number) {
+ uint32_t full = ao_log_current_pos;
+ uint32_t empty = ao_log_end_pos - ao_log_size;
+
+ /* If there's already a flight started, then find the
+ * end of it
+ */
+ for (;;) {
+ ao_log_current_pos = (full + empty) >> 1;
+ ao_log_current_pos -= ao_log_current_pos % ao_log_size;
+
+ if (ao_log_current_pos == full) {
+ if (ao_log_check(ao_log_current_pos))
+ ao_log_current_pos += ao_log_size;
+ break;
+ }
+ if (ao_log_current_pos == empty)
+ break;
+
+ if (ao_log_check(ao_log_current_pos)) {
+ full = ao_log_current_pos;
+ } else {
+ empty = ao_log_current_pos;
+ }
+ }
+ } else {
+ ao_log_find_max_erase_flight();
+ }
+#else
+
+ if (ao_flight_number)
+ if (++ao_flight_number == 0)
+ ao_flight_number = 1;
+
+ ao_log_find_max_erase_flight();
/* With a flight number in hand, find a place to write a new log,
* use the target flight number to index the available log slots so
@@ -190,7 +278,7 @@ ao_log_scan(void) __reentrant
if (++log_slot >= log_slots)
log_slot = 0;
} while (log_slot != log_want);
-
+#endif
ao_wakeup(&ao_flight_number);
}
@@ -254,7 +342,6 @@ ao_log_delete(void) __reentrant
{
uint8_t slot;
uint8_t slots;
- uint32_t log_current_pos, log_end_pos;
ao_cmd_decimal();
if (ao_cmd_status != ao_cmd_success)
@@ -268,28 +355,7 @@ ao_log_delete(void) __reentrant
#if HAS_TRACKER
ao_tracker_erase_start(ao_cmd_lex_i);
#endif
- ao_log_erase_mark();
- log_current_pos = ao_log_pos(slot);
- log_end_pos = log_current_pos + ao_config.flight_log_max;
- while (log_current_pos < log_end_pos) {
- uint8_t i;
- static __xdata uint8_t b;
-
- /*
- * Check to see if we've reached the end of
- * the used memory to avoid re-erasing the same
- * memory over and over again
- */
- for (i = 0; i < 16; i++) {
- if (ao_storage_read(log_current_pos + i, &b, 1))
- if (b != 0xff)
- break;
- }
- if (i == 16)
- break;
- ao_storage_erase(log_current_pos);
- log_current_pos += ao_storage_block;
- }
+ ao_log_erase(slot);
#if HAS_TRACKER
ao_tracker_erase_end();
#endif
diff --git a/src/kernel/ao_log.h b/src/kernel/ao_log.h
index da20e067..c5fa7fab 100644
--- a/src/kernel/ao_log.h
+++ b/src/kernel/ao_log.h
@@ -51,11 +51,16 @@ extern __pdata enum ao_flight_state ao_log_state;
#define AO_LOG_FORMAT_NONE 127 /* No log at all */
extern __code uint8_t ao_log_format;
+extern __code uint8_t ao_log_size;
/* Return the flight number from the given log slot, 0 if none */
uint16_t
ao_log_flight(uint8_t slot);
+/* Check if there is valid log data at the specified location */
+uint8_t
+ao_log_check(uint32_t pos);
+
/* Flush the log */
void
ao_log_flush(void);
diff --git a/src/kernel/ao_log_gps.c b/src/kernel/ao_log_gps.c
index a5a6358b..7643091c 100644
--- a/src/kernel/ao_log_gps.c
+++ b/src/kernel/ao_log_gps.c
@@ -26,6 +26,7 @@
static __xdata struct ao_log_gps log;
__code uint8_t ao_log_format = AO_LOG_FORMAT_TELEGPS;
+__code uint8_t ao_log_size = sizeof (struct ao_log_gps);
static uint8_t
ao_log_csum(__xdata uint8_t *b) __reentrant
@@ -136,3 +137,16 @@ ao_log_flight(uint8_t slot)
return log.u.flight.flight;
return 0;
}
+
+uint8_t
+ao_log_check(uint32_t pos)
+{
+ if (!ao_storage_read(pos,
+ &log,
+ sizeof (struct ao_log_gps)))
+ return 0;
+
+ if (ao_log_dump_check_data())
+ return 1;
+ return 0;
+}
diff --git a/src/telegps-v1.0/ao_pins.h b/src/telegps-v1.0/ao_pins.h
index 5f53dd9d..d2382a56 100644
--- a/src/telegps-v1.0/ao_pins.h
+++ b/src/telegps-v1.0/ao_pins.h
@@ -71,11 +71,11 @@
#define HAS_GPS 1
#define HAS_FLIGHT 0
#define HAS_LOG 1
+#define FLIGHT_LOG_APPEND 1
#define HAS_TRACKER 1
#define AO_CONFIG_DEFAULT_APRS_INTERVAL 0
#define AO_CONFIG_DEFAULT_RADIO_POWER 0xc0
-#define AO_CONFIG_DEFAULT_FLIGHT_LOG_MAX 496 * 1024
/*
* GPS