#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>
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
* 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;
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;
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
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 },
#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);
--- /dev/null
+/*
+ * 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_ */
--- /dev/null
+/*
+ * 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_ */
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);
}
/* 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;
*/
#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)
* 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)
{
}
/*
- * 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();
}
/*
- * 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 */
}
ao_fec_tx.c \
ao_rfpa0133.c \
ao_aprs.c \
- ao_storage.c \
ao_eeprom_stm.c \
ao_sdcard.c \
ao_bufio.c \
#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
#include <ao.h>
#include <ao_exti.h>
#include <ao_fat.h>
+#include <ao_eeprom.h>
uint16_t ao_flight_number = 1;
ao_dma_init();
ao_exti_init();
- ao_storage_init();
+ ao_eeprom_init();
ao_serial_init();
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 \
#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
#include <ao_lco.h>
#include <ao_lco_cmd.h>
#include <ao_radio_cmac_cmd.h>
+#include <ao_eeprom.h>
int
main(void)
ao_quadrature_init();
ao_button_init();
- ao_storage_init();
+ ao_eeprom_init();
ao_radio_init();