diff options
| -rw-r--r-- | src/ao.h | 9 | ||||
| -rw-r--r-- | src/ao_config.c | 34 | ||||
| -rw-r--r-- | src/ao_radio.c | 52 | 
3 files changed, 62 insertions, 33 deletions
@@ -938,17 +938,18 @@ ao_igniter_init(void);   */  #define AO_CONFIG_MAJOR	1 -#define AO_CONFIG_MINOR	2 +#define AO_CONFIG_MINOR	3  struct ao_config {  	uint8_t		major;  	uint8_t		minor;  	uint16_t	main_deploy; -	int16_t		accel_plus_g; +	int16_t		accel_plus_g;		/* changed for minor version 2 */  	uint8_t		radio_channel;  	char		callsign[AO_MAX_CALLSIGN + 1]; -	uint8_t		apogee_delay; -	int16_t		accel_minus_g; +	uint8_t		apogee_delay;		/* minor version 1 */ +	int16_t		accel_minus_g;		/* minor version 2 */ +	uint32_t	radio_frequency;	/* minor version 3 */  };  extern __xdata struct ao_config ao_config; diff --git a/src/ao_config.c b/src/ao_config.c index 7f76a585..27a60ac1 100644 --- a/src/ao_config.c +++ b/src/ao_config.c @@ -27,6 +27,12 @@ __xdata uint8_t ao_config_mutex;  #define AO_CONFIG_DEFAULT_CALLSIGN	"N0CALL"  #define AO_CONFIG_DEFAULT_ACCEL_ZERO_G	16000  #define AO_CONFIG_DEFAULT_APOGEE_DELAY	0 +/* + * For 434.550MHz, the frequency value is: + * + * 434.550e6 / (24e6 / 2**16) = 1186611.2 + */ +#define AO_CONFIG_DEFAULT_RADIO_FREQUENCY	1186611  static void  _ao_config_put(void) @@ -51,17 +57,21 @@ _ao_config_get(void)  		memcpy(&ao_config.callsign, AO_CONFIG_DEFAULT_CALLSIGN,  		       sizeof(AO_CONFIG_DEFAULT_CALLSIGN) - 1);  		ao_config.apogee_delay = AO_CONFIG_DEFAULT_APOGEE_DELAY; +		ao_config.radio_frequency = AO_CONFIG_DEFAULT_RADIO_FREQUENCY;  		ao_config_dirty = 1;  	}  	if (ao_config.minor < AO_CONFIG_MINOR) {  		/* Fixups for minor version 1 */  		if (ao_config.minor < 1)  			ao_config.apogee_delay = AO_CONFIG_DEFAULT_APOGEE_DELAY; -		/* Fixupes for minor version 2 */ +		/* Fixups for minor version 2 */  		if (ao_config.minor < 2) {  			ao_config.accel_plus_g = 0;  			ao_config.accel_minus_g = 0;  		} +		/* Fixups for minor version 3 */ +		if (ao_config.minor < 3) +			ao_config.radio_frequency = AO_CONFIG_DEFAULT_RADIO_FREQUENCY;  		ao_config.minor = AO_CONFIG_MINOR;  		ao_config_dirty = 1;  	} @@ -245,6 +255,26 @@ ao_config_apogee_delay_set(void) __reentrant  	ao_config_apogee_delay_show();  } +void +ao_config_radio_frequency_show(void) __reentrant +{ +	printf("Radio frequency: %ld\n", ao_config.radio_frequency); +} + +void +ao_config_radio_frequency_set(void) __reentrant +{ +	ao_cmd_decimal(); +	if (ao_cmd_status != ao_cmd_success) +		return; +	ao_mutex_get(&ao_config_mutex); +	_ao_config_get(); +	ao_config.radio_frequency = ao_cmd_lex_u32; +	ao_config_dirty = 1; +	ao_mutex_put(&ao_config_mutex); +	ao_config_radio_frequency_show(); +} +  struct ao_config_var {  	char		cmd;  	void		(*set)(void) __reentrant; @@ -268,6 +298,8 @@ __code struct ao_config_var ao_config_vars[] = {  		"a <+g> <-g> Set accelerometer calibration (0 for auto)" },  	{ 'r',	ao_config_radio_channel_set,	ao_config_radio_channel_show,  		"r <channel> Set radio channel (freq = 434.550 + channel * .1)" }, +	{ 'f',  ao_config_radio_frequency_set,  ao_config_radio_frequency_show, +		"f <cal>     Set radio calibration value (cal = rf/(xtal/2^16))" },  	{ 'c',	ao_config_callsign_set,		ao_config_callsign_show,  		"c <call>    Set callsign broadcast in each packet (8 char max)" },  	{ 'd',	ao_config_apogee_delay_set,	ao_config_apogee_delay_show, diff --git a/src/ao_radio.c b/src/ao_radio.c index c7c8dc8d..6d25df39 100644 --- a/src/ao_radio.c +++ b/src/ao_radio.c @@ -29,14 +29,6 @@   */  /* - * For 434.550MHz, the frequency value is: - * - * 434.550e6 / (24e6 / 2**16) = 1186611.2 - */ - -#define FREQ_CONTROL	1186611 - -/*   * For IF freq of 140.62kHz, the IF value is:   *   * 140.62e3 / (24e6 / 2**10) = 6 @@ -124,10 +116,6 @@ static __code uint8_t radio_setup[] = {  	RF_PA_TABLE1_OFF,	RF_POWER,  	RF_PA_TABLE0_OFF,	RF_POWER, -	RF_FREQ2_OFF,		(FREQ_CONTROL >> 16) & 0xff, -	RF_FREQ1_OFF,		(FREQ_CONTROL >> 8) & 0xff, -	RF_FREQ0_OFF,		(FREQ_CONTROL >> 0) & 0xff, -  	RF_FSCTRL1_OFF,		(IF_FREQ_CONTROL << RF_FSCTRL1_FREQ_IF_SHIFT),  	RF_FSCTRL0_OFF,		(0 << RF_FSCTRL0_FREQOFF_SHIFT), @@ -336,14 +324,25 @@ ao_radio_idle(void)  	}  } -void -ao_radio_send(__xdata struct ao_telemetry *telemetry) __reentrant +static void +ao_radio_get(void)  {  	ao_config_get();  	ao_mutex_get(&ao_radio_mutex);  	ao_radio_idle(); -	ao_radio_done = 0;  	RF_CHANNR = ao_config.radio_channel; +	RF_FREQ2 = (uint8_t) (ao_config.radio_frequency >> 16); +	RF_FREQ1 = (uint8_t) (ao_config.radio_frequency >> 8); +	RF_FREQ0 = (uint8_t) (ao_config.radio_frequency); +} + +#define ao_radio_put() ao_mutex_put(&ao_radio_mutex) + +void +ao_radio_send(__xdata struct ao_telemetry *telemetry) __reentrant +{ +	ao_radio_get(); +	ao_radio_done = 0;  	ao_dma_set_transfer(ao_radio_dma,  			    telemetry,  			    &RFDXADDR, @@ -358,16 +357,13 @@ ao_radio_send(__xdata struct ao_telemetry *telemetry) __reentrant  	RFST = RFST_STX;  	__critical while (!ao_radio_done)  		ao_sleep(&ao_radio_done); -	ao_mutex_put(&ao_radio_mutex); +	ao_radio_put();  }  uint8_t  ao_radio_recv(__xdata struct ao_radio_recv *radio) __reentrant  { -	ao_config_get(); -	ao_mutex_get(&ao_radio_mutex); -	ao_radio_idle(); -	RF_CHANNR = ao_config.radio_channel; +	ao_radio_get();  	ao_dma_set_transfer(ao_radio_dma,  			    &RFDXADDR,  			    radio, @@ -382,7 +378,7 @@ ao_radio_recv(__xdata struct ao_radio_recv *radio) __reentrant  	RFST = RFST_SRX;  	__critical while (!ao_radio_dma_done)  		ao_sleep(&ao_radio_dma_done); -	ao_mutex_put(&ao_radio_mutex); +	ao_radio_put();  	return (ao_radio_dma_done & AO_DMA_DONE);  } @@ -394,8 +390,8 @@ ao_radio_rdf(int ms)  {  	uint8_t i;  	uint8_t pkt_len; -	ao_mutex_get(&ao_radio_mutex); -	ao_radio_idle(); + +	ao_radio_get();  	ao_radio_rdf_running = 1;  	for (i = 0; i < sizeof (rdf_setup); i += 2)  		RF[rdf_setup[i]] = rdf_setup[i+1]; @@ -431,7 +427,7 @@ ao_radio_rdf(int ms)  	ao_radio_idle();  	for (i = 0; i < sizeof (telemetry_setup); i += 2)  		RF[telemetry_setup[i]] = telemetry_setup[i+1]; -	ao_mutex_put(&ao_radio_mutex); +	ao_radio_put();  }  void @@ -448,18 +444,18 @@ ao_radio_rdf_abort(void)  		ao_radio_abort();  } +  /* Output carrier */  void  ao_radio_test(void)  { -	ao_config_get(); -	ao_mutex_get(&ao_radio_mutex); -	ao_radio_idle(); +	ao_packet_slave_stop(); +	ao_radio_get();  	printf ("Hit a character to stop..."); flush();  	RFST = RFST_STX;  	getchar();  	ao_radio_idle(); -	ao_mutex_put(&ao_radio_mutex); +	ao_radio_put();  	putchar('\n');  }  | 
