diff options
| author | Keith Packard <keithp@keithp.com> | 2012-03-26 23:35:35 -0700 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2012-03-26 23:35:35 -0700 | 
| commit | c1d12a117b36de7fe8dd992959b890bfd1163e81 (patch) | |
| tree | a2be474737f3f3fb062b60ca6ea26301706151f6 /src/core | |
| parent | c2550d72aee371676d2f09316051567681e53a7c (diff) | |
Do radio settings solely by frequency
Compute the radio setting needed based on the calibration value
provided and the requested frequency.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/core')
| -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 | 
4 files changed, 98 insertions, 36 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; +} | 
