diff options
| -rw-r--r-- | src/core/ao_config.c | 21 | ||||
| -rw-r--r-- | src/core/ao_config.h | 57 | ||||
| -rw-r--r-- | src/core/ao_eeprom.h | 43 | ||||
| -rw-r--r-- | src/core/ao_storage.c | 2 | ||||
| -rw-r--r-- | src/core/ao_storage.h | 10 | ||||
| -rw-r--r-- | src/stm/ao_eeprom_stm.c | 57 | ||||
| -rw-r--r-- | src/telegps-v0.1/Makefile | 1 | ||||
| -rw-r--r-- | src/telegps-v0.1/ao_pins.h | 5 | ||||
| -rw-r--r-- | src/telegps-v0.1/ao_telegps.c | 3 | ||||
| -rw-r--r-- | src/telelco-v0.2/Makefile | 1 | ||||
| -rw-r--r-- | src/telelco-v0.2/ao_pins.h | 2 | ||||
| -rw-r--r-- | src/telelco-v0.2/ao_telelco.c | 3 | 
12 files changed, 145 insertions, 60 deletions
diff --git a/src/core/ao_config.c b/src/core/ao_config.c index 82faf32b..5567587b 100644 --- a/src/core/ao_config.c +++ b/src/core/ao_config.c @@ -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 index 00000000..5e38430e --- /dev/null +++ b/src/core/ao_config.h @@ -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 index 00000000..915522bf --- /dev/null +++ b/src/core/ao_eeprom.h @@ -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_ */ diff --git a/src/core/ao_storage.c b/src/core/ao_storage.c index adf7e4d4..6eddae7f 100644 --- a/src/core/ao_storage.c +++ b/src/core/ao_storage.c @@ -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);  } diff --git a/src/core/ao_storage.h b/src/core/ao_storage.h index ea946399..d6e95605 100644 --- a/src/core/ao_storage.h +++ b/src/core/ao_storage.h @@ -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; diff --git a/src/stm/ao_eeprom_stm.c b/src/stm/ao_eeprom_stm.c index 58783f1a..4207a860 100644 --- a/src/stm/ao_eeprom_stm.c +++ b/src/stm/ao_eeprom_stm.c @@ -16,19 +16,10 @@   */  #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 */  } diff --git a/src/telegps-v0.1/Makefile b/src/telegps-v0.1/Makefile index 170294e6..f5533d51 100644 --- a/src/telegps-v0.1/Makefile +++ b/src/telegps-v0.1/Makefile @@ -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 \ diff --git a/src/telegps-v0.1/ao_pins.h b/src/telegps-v0.1/ao_pins.h index 5bea2681..7ff59956 100644 --- a/src/telegps-v0.1/ao_pins.h +++ b/src/telegps-v0.1/ao_pins.h @@ -65,7 +65,10 @@  #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 diff --git a/src/telegps-v0.1/ao_telegps.c b/src/telegps-v0.1/ao_telegps.c index 68116bfb..bc37b504 100644 --- a/src/telegps-v0.1/ao_telegps.c +++ b/src/telegps-v0.1/ao_telegps.c @@ -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(); diff --git a/src/telelco-v0.2/Makefile b/src/telelco-v0.2/Makefile index bc5f8571..2fb4db5e 100644 --- a/src/telelco-v0.2/Makefile +++ b/src/telelco-v0.2/Makefile @@ -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 \ diff --git a/src/telelco-v0.2/ao_pins.h b/src/telelco-v0.2/ao_pins.h index d86782f3..62f221a1 100644 --- a/src/telelco-v0.2/ao_pins.h +++ b/src/telelco-v0.2/ao_pins.h @@ -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 diff --git a/src/telelco-v0.2/ao_telelco.c b/src/telelco-v0.2/ao_telelco.c index 66bf0ba1..d9f7c693 100644 --- a/src/telelco-v0.2/ao_telelco.c +++ b/src/telelco-v0.2/ao_telelco.c @@ -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();  | 
