diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/ao.h | 8 | ||||
| -rw-r--r-- | src/core/ao_cmd.c | 6 | ||||
| -rw-r--r-- | src/core/ao_config.c | 68 | ||||
| -rw-r--r-- | src/core/ao_freq.c | 52 | ||||
| -rw-r--r-- | src/product/Makefile.telebt | 3 | ||||
| -rw-r--r-- | src/product/Makefile.teledongle | 3 | ||||
| -rw-r--r-- | src/product/Makefile.telelaunch | 3 | ||||
| -rw-r--r-- | src/product/Makefile.telemetrum | 3 | ||||
| -rw-r--r-- | src/product/Makefile.telemini | 3 | ||||
| -rw-r--r-- | src/product/Makefile.telenano | 3 | ||||
| -rw-r--r-- | src/product/ao_terraui.c | 2 | ||||
| -rw-r--r-- | src/teleshield-v0.1/Makefile | 3 | ||||
| -rw-r--r-- | src/teleterra-v0.2/Makefile | 3 | ||||
| -rw-r--r-- | src/tidongle/Makefile | 3 | 
14 files changed, 117 insertions, 46 deletions
| diff --git a/src/core/ao.h b/src/core/ao.h index 8c5335c4..ce9a1f70 100644 --- a/src/core/ao.h +++ b/src/core/ao.h @@ -1539,7 +1539,6 @@ ao_igniter_init(void);  struct ao_radio_channel {  	char		name[AO_CHANNEL_NAME_LEN];  	uint32_t	kHz; -	uint32_t	radio_setting;  };  #endif @@ -1559,6 +1558,7 @@ struct ao_config {  	uint32_t	radio_setting;		/* minor version 7 */  	uint8_t		radio_enable;		/* minor version 8 */  	uint8_t		aes_key[AO_AES_LEN];	/* minor version 9 */ +	uint32_t	frequency;		/* minor version 10 */  #if HAS_RADIO_CHANNELS  	struct ao_radio_channel	radio_channels[AO_NUM_CHANNELS];	/* minor version 10 */  #endif @@ -1959,4 +1959,10 @@ ao_battery_init(void);  uint32_t  ao_sqrt(uint32_t op); +/* + * ao_freq.c + */ + +int32_t ao_freq_to_set(int32_t freq, int32_t cal); +  #endif /* _AO_H_ */ diff --git a/src/core/ao_cmd.c b/src/core/ao_cmd.c index 14cb7569..cde68b39 100644 --- a/src/core/ao_cmd.c +++ b/src/core/ao_cmd.c @@ -263,9 +263,9 @@ static __pdata uint8_t		ao_ncmds;  static void  help(void)  { -	register uint8_t cmds; -	register uint8_t cmd; -	register __code struct ao_cmds * cs; +	__pdata uint8_t cmds; +	__pdata uint8_t cmd; +	__code struct ao_cmds * __pdata cs;  	for (cmds = 0; cmds < ao_ncmds; cmds++) {  		cs = ao_cmds[cmds]; diff --git a/src/core/ao_config.c b/src/core/ao_config.c index 86bbc473..6fcebe1e 100644 --- a/src/core/ao_config.c +++ b/src/core/ao_config.c @@ -65,6 +65,12 @@ ao_config_put(void)  #endif  static void +ao_config_set_radio(void) +{ +	ao_config.radio_setting = ao_freq_to_set(ao_config.frequency, ao_config.radio_cal); +} + +static void  _ao_config_get(void)  {  	if (ao_config_loaded) @@ -105,24 +111,23 @@ _ao_config_get(void)  			ao_config.ignite_mode = AO_CONFIG_DEFAULT_IGNITE_MODE;  		if (ao_config.minor < 6)  			ao_config.pad_orientation = AO_CONFIG_DEFAULT_PAD_ORIENTATION; -		if (ao_config.minor < 7) -			ao_config.radio_setting = ao_config.radio_cal;  		if (ao_config.minor < 8)  			ao_config.radio_enable = TRUE;  		if (ao_config.minor < 9)  			memset(&ao_config.aes_key, 0, AO_AES_LEN); -#if HAS_RADIO_CHANNELS  		if (ao_config.minor < 10) { +			ao_config.frequency = 434550; +#if HAS_RADIO_CHANNELS  			ao_xmemset(&ao_config.radio_channels, '\0', sizeof (ao_config.radio_channels));  			ao_xmemcpy(&ao_config.radio_channels[0].name[0],  				   CODE_TO_XDATA("Channel 0"), sizeof("Channel 0"));  			ao_config.radio_channels[0].kHz = 434550; -			ao_config.radio_channels[0].radio_setting = ao_config.radio_cal; -		}  #endif				    +		}  		ao_config.minor = AO_CONFIG_MINOR;  		ao_config_dirty = 1;  	} +	ao_config_set_radio();  	ao_config_loaded = 1;  } @@ -196,6 +201,26 @@ ao_config_radio_channel_set(void) __reentrant  	ao_radio_recv_abort();  } +void +ao_config_frequency_show(void) __reentrant +{ +	printf("Frequency: %ld\n", +	       ao_config.frequency); +} + +void +ao_config_frequency_set(void) __reentrant +{ +	ao_cmd_decimal(); +	if (ao_cmd_status != ao_cmd_success) +		return; +	_ao_config_edit_start(); +	ao_config.frequency = ao_cmd_lex_u32; +	ao_config_set_radio(); +	_ao_config_edit_finish(); +	ao_radio_recv_abort(); +} +  #if HAS_ADC  void @@ -315,7 +340,8 @@ ao_config_radio_cal_set(void) __reentrant  	if (ao_cmd_status != ao_cmd_success)  		return;  	_ao_config_edit_start(); -	ao_config.radio_setting = ao_config.radio_cal = ao_cmd_lex_u32; +	ao_config.radio_cal = ao_cmd_lex_u32; +	ao_config_set_radio();  	_ao_config_edit_finish();  } @@ -395,25 +421,6 @@ ao_config_pad_orientation_set(void) __reentrant  #endif  void -ao_config_radio_setting_show(void) __reentrant -{ -	printf("Radio setting: %ld\n", ao_config.radio_setting); -} - -void -ao_config_radio_setting_set(void) __reentrant -{ -	ao_cmd_decimal(); -	if (ao_cmd_status != ao_cmd_success) -		return; -	_ao_config_edit_start(); -	ao_config.radio_setting = ao_cmd_lex_u32; -	ao_config.radio_channel = 0; -	_ao_config_edit_finish(); -	ao_radio_recv_abort(); -} - -void  ao_config_radio_enable_show(void) __reentrant  {  	printf("Radio enable: %d\n", ao_config.radio_enable); @@ -464,11 +471,10 @@ ao_config_radio_config_show(void) __reentrant  	uint8_t	i;  	for (i = 0; i < AO_NUM_CHANNELS; i++)  		if (ao_config.radio_channels[i].name[0]) { -			printf("%2d %-16.16s %ld %ld\n", +			printf("%2d %-16.16s %ld\n",  			       i,  			       ao_config.radio_channels[i].name, -			       ao_config.radio_channels[i].kHz, -			       ao_config.radio_channels[i].radio_setting); +			       ao_config.radio_channels[i].kHz);  		}  } @@ -498,8 +504,6 @@ ao_config_radio_config_set(void) __reentrant  	}  	ao_cmd_decimal();  	ch->kHz = ao_cmd_lex_u32; -	ao_cmd_decimal(); -	ch->radio_setting = ao_cmd_lex_u32;  	_ao_config_edit_finish();  }  #endif @@ -528,10 +532,10 @@ __code struct ao_config_var ao_config_vars[] = {  #endif /* HAS_ADC */  	{ "r <channel>\0Radio channel (freq = 434.550 + chan * .1)",  	  ao_config_radio_channel_set,	ao_config_radio_channel_show }, +	{ "F <freq>\0Frequency (kHz)", +	  ao_config_frequency_set, ao_config_frequency_show },  	{ "c <call>\0Callsign (8 char max)",  	  ao_config_callsign_set,	ao_config_callsign_show }, -	{ "R <setting>\0Radio freq control (freq = 434.550 * setting/cal)", -	  ao_config_radio_setting_set,	ao_config_radio_setting_show },  	{ "e <0 disable, 1 enable>\0Enable telemetry and RDF",  	  ao_config_radio_enable_set, ao_config_radio_enable_show },  #if HAS_ACCEL diff --git a/src/core/ao_freq.c b/src/core/ao_freq.c new file mode 100644 index 00000000..13bcb383 --- /dev/null +++ b/src/core/ao_freq.c @@ -0,0 +1,52 @@ +/* + * Copyright © 2012 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. + */ + +#include <ao.h> + +/* + * The provided 'calibration' value is + * that needed to tune the radio to precisely 434550kHz. + * Use that to 'walk' to the target frequency by following + * a 'bresenham' line from 434550kHz to the target + * frequency, and updating the radio setting along the way + */ + +int32_t ao_freq_to_set(int32_t freq, int32_t cal) { +	__pdata int32_t	set = 0; +	uint8_t	neg = 0; +	__pdata int32_t	error = -434550 / 2; + +	freq -= 434550; +	if (freq < 0) { +		neg = 1; +		freq = -freq; +	} +	for (;;) { +		if (freq == 0 && error <= 0) +			break; +		if (error > 0) { +			error -= 434550; +			set++; +		} else { +			error += cal; +			freq--; +		} +	} +	if (neg) +		set = -set; +	return cal + set; +} diff --git a/src/product/Makefile.telebt b/src/product/Makefile.telebt index ea18ff18..e53aa2c4 100644 --- a/src/product/Makefile.telebt +++ b/src/product/Makefile.telebt @@ -28,7 +28,8 @@ CORE_SRC = \  	ao_panic.c \  	ao_state.c \  	ao_stdio.c \ -	ao_task.c +	ao_task.c \ +	ao_freq.c  CC1111_SRC = \  	ao_aes.c \ diff --git a/src/product/Makefile.teledongle b/src/product/Makefile.teledongle index cf33d1f1..27e7d24b 100644 --- a/src/product/Makefile.teledongle +++ b/src/product/Makefile.teledongle @@ -31,7 +31,8 @@ CORE_SRC = \  	ao_rssi.c \  	ao_state.c \  	ao_stdio.c \ -	ao_task.c +	ao_task.c \ +	ao_freq.c  CC1111_SRC = \  	ao_aes.c \ diff --git a/src/product/Makefile.telelaunch b/src/product/Makefile.telelaunch index 97764517..8aab50e0 100644 --- a/src/product/Makefile.telelaunch +++ b/src/product/Makefile.telelaunch @@ -27,7 +27,8 @@ CORE_SRC = \  	ao_panic.c \  	ao_stdio.c \  	ao_storage.c \ -	ao_task.c +	ao_task.c \ +	ao_freq.c  CC1111_SRC = \  	ao_adc.c \ diff --git a/src/product/Makefile.telemetrum b/src/product/Makefile.telemetrum index 52c723ca..e4f55f88 100644 --- a/src/product/Makefile.telemetrum +++ b/src/product/Makefile.telemetrum @@ -40,7 +40,8 @@ CORE_SRC = \  	ao_log.c \  	ao_log_big.c \  	ao_report.c \ -	ao_telemetry.c +	ao_telemetry.c \ +	ao_freq.c  CC1111_SRC = \  	ao_adc.c \ diff --git a/src/product/Makefile.telemini b/src/product/Makefile.telemini index 75beeae4..82ec42a2 100644 --- a/src/product/Makefile.telemini +++ b/src/product/Makefile.telemini @@ -33,7 +33,8 @@ CORE_SRC = \  	ao_stdio.c \  	ao_storage.c \  	ao_task.c \ -	ao_telemetry.c +	ao_telemetry.c \ +	ao_freq.c  CC1111_SRC = \  	ao_adc.c \ diff --git a/src/product/Makefile.telenano b/src/product/Makefile.telenano index b30ca789..cf27527c 100644 --- a/src/product/Makefile.telenano +++ b/src/product/Makefile.telenano @@ -33,7 +33,8 @@ CORE_SRC = \  	ao_stdio.c \  	ao_storage.c \  	ao_task.c \ -	ao_telemetry.c +	ao_telemetry.c \ +	ao_freq.c  CC1111_SRC = \  	ao_adc.c \ diff --git a/src/product/ao_terraui.c b/src/product/ao_terraui.c index 05157cb1..9b40c42a 100644 --- a/src/product/ao_terraui.c +++ b/src/product/ao_terraui.c @@ -459,7 +459,7 @@ ao_terraui_config(void) __reentrant  	for (chan = 0; chan < AO_NUM_CHANNELS; chan++) -		if (ao_config.radio_channels[chan].radio_setting == ao_config.radio_setting) +		if (ao_config.radio_channels[chan].kHz == ao_config.frequency)  			break;  	if (chan == AO_NUM_CHANNELS)  		chan = 0; diff --git a/src/teleshield-v0.1/Makefile b/src/teleshield-v0.1/Makefile index a21a6052..44780476 100644 --- a/src/teleshield-v0.1/Makefile +++ b/src/teleshield-v0.1/Makefile @@ -41,7 +41,8 @@ CORE_SRC = \  	ao_state.c \  	ao_storage.c \  	ao_stdio.c \ -	ao_task.c +	ao_task.c \ +	ao_freq.c  CC1111_SRC = \  	ao_dbg.c \ diff --git a/src/teleterra-v0.2/Makefile b/src/teleterra-v0.2/Makefile index 0747bfbf..4967d187 100644 --- a/src/teleterra-v0.2/Makefile +++ b/src/teleterra-v0.2/Makefile @@ -28,7 +28,8 @@ CORE_SRC = \  	ao_sqrt.c \  	ao_stdio.c \  	ao_storage.c \ -	ao_task.c +	ao_task.c \ +	ao_freq.c  CC1111_SRC = \  	ao_battery.c \ diff --git a/src/tidongle/Makefile b/src/tidongle/Makefile index 698d612c..149b00c5 100644 --- a/src/tidongle/Makefile +++ b/src/tidongle/Makefile @@ -26,7 +26,8 @@ CORE_SRC = \  	ao_rssi.c \  	ao_state.c \  	ao_stdio.c \ -	ao_task.c +	ao_task.c \ +	ao_freq.c  CC1111_SRC = \  	ao_aes.c \ | 
