1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-29 14:52:12 +01:00

100mW appears to be working again. A few bug fixes.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2745 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
pip 2011-02-06 21:21:50 +00:00 committed by pip
parent d7fc7646b0
commit b2eb141c10
7 changed files with 128 additions and 87 deletions

View File

@ -35,7 +35,7 @@
#include "main.h"
#if defined(PIOS_COM_DEBUG)
#define APICONFIG_DEBUG
// #define APICONFIG_DEBUG
#endif
// *****************************************************************************
@ -304,13 +304,14 @@ void apiconfig_processInputPacket(void *buf, uint16_t len)
saved_settings_save(); // save the new settings
ph_set_remote_serial_number(0, 0);
rfm22_setTxNormal();
PIOS_COM_ChangeBaud(PIOS_COM_SERIAL, saved_settings.serial_baudrate);
rfm22_setFreqCalibration(saved_settings.rf_xtal_cap);
ph_setNominalCarrierFrequency(saved_settings.frequency_Hz);
ph_setDatarate(saved_settings.max_rf_bandwidth);
ph_setTxPower(saved_settings.max_tx_power);
ph_set_remote_serial_number(0, saved_settings.destination_id);
ph_set_remote_encryption(0, saved_settings.aes_enable, (const void *)saved_settings.aes_key);
ph_set_remote_serial_number(0, saved_settings.destination_id);
switch (saved_settings.mode)
{
case MODE_NORMAL: // normal 2-way packet mode
@ -326,8 +327,10 @@ void apiconfig_processInputPacket(void *buf, uint16_t len)
case MODE_SCAN_SPECTRUM: // scan the receiver over the whole band
break;
case MODE_TX_BLANK_CARRIER_TEST: // blank carrier Tx mode (for calibrating the carrier frequency say)
rfm22_setTxCarrierMode();
break;
case MODE_TX_SPECTRUM_TEST: // pseudo random Tx data mode (for checking the Tx carrier spectrum)
rfm22_setTxPNMode();
break;
default: // unknown mode
saved_settings.mode = MODE_NORMAL;

View File

@ -33,7 +33,7 @@
// firmware version
#define VERSION_MAJOR 0 // 0 to 255
#define VERSION_MINOR 3 // 0 to 255
#define VERSION_MINOR 4 // 0 to 255
// macro's for reading internal flash memory
#define mem8(addr) (*((volatile uint8_t *)(addr)))

View File

@ -499,14 +499,14 @@ enum { RX_WAIT_PREAMBLE_MODE = 0,
//#define RFM22_gfsk_fir_coeff_value 0x6C // R/W
#define RFM22_tx_power 0x6D // R/W
#define RFM22_tx_pwr_txpow_0 0x00 // Lowest TX power
#define RFM22_tx_pwr_txpow_1 0x01 //
#define RFM22_tx_pwr_txpow_2 0x02 //
#define RFM22_tx_pwr_txpow_3 0x03 //
#define RFM22_tx_pwr_txpow_4 0x04 //
#define RFM22_tx_pwr_txpow_5 0x05 //
#define RFM22_tx_pwr_txpow_6 0x06 //
#define RFM22_tx_pwr_txpow_7 0x07 // Highest TX power
#define RFM22_tx_pwr_txpow_0 0x00 // +1dBm .. 1.25mW
#define RFM22_tx_pwr_txpow_1 0x01 // +2dBm .. 1.6mW
#define RFM22_tx_pwr_txpow_2 0x02 // +5dBm .. 3.16mW
#define RFM22_tx_pwr_txpow_3 0x03 // +8dBm .. 6.3mW
#define RFM22_tx_pwr_txpow_4 0x04 // +11dBm .. 12.6mW
#define RFM22_tx_pwr_txpow_5 0x05 // +14dBm .. 25mW
#define RFM22_tx_pwr_txpow_6 0x06 // +17dBm .. 50mW
#define RFM22_tx_pwr_txpow_7 0x07 // +20dBm .. 100mW
#define RFM22_tx_pwr_lna_sw 0x08 // LNA Switch Controller. If set, lna_sw control from the digital will go high during TX modes, and low during other times. If reset, the digital control signal is low at all times.
#define RFM22_tx_pwr_papeaklvl_0 0x10 // " "
#define RFM22_tx_pwr_papeaklvl_1 0x20 // PA Peak Detect Level (direct from register). 00 = 6.5, 01 = 7, 10 = 7.5, 11 = 8, 00 = default
@ -597,6 +597,7 @@ uint8_t rfm22_getFreqCalibration(void);
void rfm22_setTxPower(uint8_t tx_pwr);
uint8_t rfm22_getTxPower(void);
void rfm22_setTxNormal(void);
void rfm22_setTxCarrierMode(void);
void rfm22_setTxPNMode(void);

View File

@ -678,7 +678,7 @@ int main()
#if defined(PIOS_COM_DEBUG)
DEBUG_PRINTF("\r\n");
DEBUG_PRINTF("PipXtreme v%u.%u rebooted\r\n", version_major, version_minor);
DEBUG_PRINTF("PipXtreme v%u.%u rebooted\r\n", VERSION_MAJOR, VERSION_MINOR);
#endif
// *************
@ -706,7 +706,10 @@ int main()
else
if ( GPIO_IN(_868MHz_PIN) && !GPIO_IN(_915MHz_PIN)) saved_settings.frequency_band = FREQBAND_915MHz; // 915MHz band
if (saved_settings.mode == 0xff)
if (saved_settings.mode == 0xff ||
saved_settings.mode == MODE_TX_BLANK_CARRIER_TEST ||
saved_settings.mode == MODE_TX_SPECTRUM_TEST ||
saved_settings.mode == MODE_SCAN_SPECTRUM)
saved_settings.mode = MODE_NORMAL;
// set some defaults if they are not set
@ -738,14 +741,14 @@ int main()
}
if (saved_settings.max_tx_power == 0xff)
{
// saved_settings.max_tx_power = 0; // +1dBm ... 1.25mW
// saved_settings.max_tx_power = 1; // +2dBm ... 1.6mW
// saved_settings.max_tx_power = 2; // +5dBm ... 3.16mW
// saved_settings.max_tx_power = 3; // +8dBm ... 6.3mW
saved_settings.max_tx_power = 4; // +11dBm .. 12.6mW
// saved_settings.max_tx_power = 5; // +14dBm .. 25mW
// saved_settings.max_tx_power = 6; // +17dBm .. 50mW
// saved_settings.max_tx_power = 7; // +20dBm .. 100mW
// saved_settings.max_tx_power = RFM22_tx_pwr_txpow_0; // +1dBm ... 1.25mW
// saved_settings.max_tx_power = RFM22_tx_pwr_txpow_1; // +2dBm ... 1.6mW
// saved_settings.max_tx_power = RFM22_tx_pwr_txpow_2; // +5dBm ... 3.16mW
// saved_settings.max_tx_power = RFM22_tx_pwr_txpow_3; // +8dBm ... 6.3mW
saved_settings.max_tx_power = RFM22_tx_pwr_txpow_4; // +11dBm .. 12.6mW
// saved_settings.max_tx_power = RFM22_tx_pwr_txpow_5; // +14dBm .. 25mW
// saved_settings.max_tx_power = RFM22_tx_pwr_txpow_6; // +17dBm .. 50mW
// saved_settings.max_tx_power = RFM22_tx_pwr_txpow_7; // +20dBm .. 100mW
}
break;
@ -774,14 +777,14 @@ int main()
}
if (saved_settings.max_tx_power == 0xff)
{
// saved_settings.max_tx_power = 0; // +1dBm ... 1.25mW
// saved_settings.max_tx_power = 1; // +2dBm ... 1.6mW
// saved_settings.max_tx_power = 2; // +5dBm ... 3.16mW
// saved_settings.max_tx_power = 3; // +8dBm ... 6.3mW
saved_settings.max_tx_power = 4; // +11dBm .. 12.6mW
// saved_settings.max_tx_power = 5; // +14dBm .. 25mW
// saved_settings.max_tx_power = 6; // +17dBm .. 50mW
// saved_settings.max_tx_power = 7; // +20dBm .. 100mW
// saved_settings.max_tx_power = RFM22_tx_pwr_txpow_0; // +1dBm ... 1.25mW
// saved_settings.max_tx_power = RFM22_tx_pwr_txpow_1; // +2dBm ... 1.6mW
// saved_settings.max_tx_power = RFM22_tx_pwr_txpow_2; // +5dBm ... 3.16mW
// saved_settings.max_tx_power = RFM22_tx_pwr_txpow_3; // +8dBm ... 6.3mW
saved_settings.max_tx_power = RFM22_tx_pwr_txpow_4; // +11dBm .. 12.6mW
// saved_settings.max_tx_power = RFM22_tx_pwr_txpow_5; // +14dBm .. 25mW
// saved_settings.max_tx_power = RFM22_tx_pwr_txpow_6; // +17dBm .. 50mW
// saved_settings.max_tx_power = RFM22_tx_pwr_txpow_7; // +20dBm .. 100mW
}
break;
@ -810,14 +813,14 @@ int main()
}
if (saved_settings.max_tx_power == 0xff)
{
// saved_settings.max_tx_power = 0; // +1dBm ... 1.25mW
// saved_settings.max_tx_power = 1; // +2dBm ... 1.6mW
// saved_settings.max_tx_power = 2; // +5dBm ... 3.16mW
// saved_settings.max_tx_power = 3; // +8dBm ... 6.3mW
saved_settings.max_tx_power = 4; // +11dBm .. 12.6mW
// saved_settings.max_tx_power = 5; // +14dBm .. 25mW
// saved_settings.max_tx_power = 6; // +17dBm .. 50mW
// saved_settings.max_tx_power = 7; // +20dBm .. 100mW
// saved_settings.max_tx_power = RFM22_tx_pwr_txpow_0; // +1dBm ... 1.25mW
// saved_settings.max_tx_power = RFM22_tx_pwr_txpow_1; // +2dBm ... 1.6mW
// saved_settings.max_tx_power = RFM22_tx_pwr_txpow_2; // +5dBm ... 3.16mW
// saved_settings.max_tx_power = RFM22_tx_pwr_txpow_3; // +8dBm ... 6.3mW
saved_settings.max_tx_power = RFM22_tx_pwr_txpow_4; // +11dBm .. 12.6mW
// saved_settings.max_tx_power = RFM22_tx_pwr_txpow_5; // +14dBm .. 25mW
// saved_settings.max_tx_power = RFM22_tx_pwr_txpow_6; // +17dBm .. 50mW
// saved_settings.max_tx_power = RFM22_tx_pwr_txpow_7; // +20dBm .. 100mW
}
break;

View File

@ -48,7 +48,7 @@
#include "rfm22b.h"
#if defined(PIOS_COM_DEBUG)
// #define RFM22_DEBUG
#define RFM22_DEBUG
// #define RFM22_INT_TIMEOUT_DEBUG
#endif
@ -214,7 +214,7 @@ volatile uint8_t osc_load_cap; // xtal frequency calibration value
volatile uint8_t rssi; // the current RSSI (register value)
volatile int16_t rssi_dBm; // dBm value
uint8_t tx_power; // the transmit power to use for data transmissions
uint8_t tx_power; // the transmit power to use for data transmissions
volatile uint8_t tx_pwr; // the tx power register read back
volatile uint8_t rx_buffer_current; // the current receive buffer in use (double buffer)
@ -393,32 +393,6 @@ uint8_t rfm22_read(uint8_t addr)
#endif
// ************************************
// set/get the frequency calibration value
void rfm22_setFreqCalibration(uint8_t value)
{
osc_load_cap = value;
if (!initialized || power_on_reset)
return; // we haven't yet been initialized
#if defined(RFM22_EXT_INT_USE)
exec_using_spi = TRUE;
#endif
rfm22_write(RFM22_xtal_osc_load_cap, osc_load_cap);
#if defined(RFM22_EXT_INT_USE)
exec_using_spi = FALSE;
#endif
}
uint8_t rfm22_getFreqCalibration(void)
{
return osc_load_cap;
}
// ************************************
// set/get the current tx power setting
@ -458,8 +432,6 @@ void rfm22_setNominalCarrierFrequency(uint32_t frequency_hz)
else
if (frequency_hz > upper_carrier_frequency_limit_Hz) frequency_hz = upper_carrier_frequency_limit_Hz;
carrier_frequency_hz = frequency_hz;
if (frequency_hz < 480000000)
hbsel = 1;
else
@ -471,6 +443,9 @@ void rfm22_setNominalCarrierFrequency(uint32_t frequency_hz)
fc = (fc * 64u) / (10000ul * hbsel);
fb -= 24;
// carrier_frequency_hz = frequency_hz;
carrier_frequency_hz = ((uint32_t)fb + 24 + ((float)fc / 64000)) * 10000000 * hbsel;
if (hbsel > 1)
fb |= RFM22_fbs_hbsel;
@ -490,7 +465,8 @@ void rfm22_setNominalCarrierFrequency(uint32_t frequency_hz)
// *******
#if defined(RFM22_DEBUG)
DEBUG_PRINTF("rf setFreq: %0.2f\r\n", carrier_frequency_hz);
DEBUG_PRINTF("rf setFreq: %u\r\n", carrier_frequency_hz);
// DEBUG_PRINTF("rf setFreq frequency_step_size: %0.2f\r\n", frequency_step_size);
#endif
#if defined(RFM22_EXT_INT_USE)
@ -753,7 +729,7 @@ void rfm22_setRxMode(void)
void rfm22_setTxMode(uint8_t mode)
{
if (mode != TX_DATA_MODE && mode != TX_CARRIER_MODE && rf_mode != TX_PN_MODE)
if (mode != TX_DATA_MODE && mode != TX_CARRIER_MODE && mode != TX_PN_MODE)
return; // invalid mode
#if defined(RFM22_EXT_INT_USE)
@ -771,22 +747,23 @@ void rfm22_setTxMode(uint8_t mode)
RX_LED_OFF;
// set the tx power
// rfm22_write(RFM22_tx_power, RFM22_tx_pwr_lna_sw | tx_power);
// rfm22_write(RFM22_tx_power, RFM22_tx_pwr_papeaken | RFM22_tx_pwr_papeaklvl_0 | RFM22_tx_pwr_lna_sw | tx_power);
rfm22_write(RFM22_tx_power, RFM22_tx_pwr_papeaken | RFM22_tx_pwr_papeaklvl_1 | RFM22_tx_pwr_papeaklvl_0 | RFM22_tx_pwr_lna_sw | tx_power);
uint8_t fd_bit = rfm22_read(RFM22_modulation_mode_control2) & RFM22_mmc2_fd;
if (mode == TX_CARRIER_MODE)
{ // blank carrier mode - for testing
rfm22_write(RFM22_tx_power, RFM22_tx_pwr_papeaken | RFM22_tx_pwr_papeaklvl_0 | RFM22_tx_pwr_lna_sw | RFM22_tx_pwr_txpow_0); // tx power +1dBm ... 1.25mW
rfm22_write(RFM22_modulation_mode_control2, fd_bit | RFM22_mmc2_dtmod_pn9 | RFM22_mmc2_modtyp_none); // FIFO mode, Blank carrier
}
else
if (mode == TX_PN_MODE)
{ // psuedo random data carrier mode - for testing
rfm22_write(RFM22_tx_power, RFM22_tx_pwr_papeaken | RFM22_tx_pwr_papeaklvl_0 | RFM22_tx_pwr_lna_sw | RFM22_tx_pwr_txpow_0); // tx power +1dBm ... 1.25mW
rfm22_write(RFM22_modulation_mode_control2, fd_bit | RFM22_mmc2_dtmod_pn9 | RFM22_mmc2_modtyp_gfsk); // FIFO mode, PN9 carrier
}
else
{ // data transmission
// rfm22_write(RFM22_tx_power, RFM22_tx_pwr_lna_sw | tx_power); // set the tx power
rfm22_write(RFM22_tx_power, RFM22_tx_pwr_papeaken | RFM22_tx_pwr_papeaklvl_0 | RFM22_tx_pwr_lna_sw | tx_power); // set the tx power
rfm22_write(RFM22_modulation_mode_control2, fd_bit | RFM22_mmc2_dtmod_fifo | RFM22_mmc2_modtyp_gfsk); // FIFO mode, GFSK modulation
}
@ -1375,12 +1352,12 @@ void rfm22_processInt(void)
case TX_CARRIER_MODE:
case TX_PN_MODE:
if (timer_ms >= TX_TEST_MODE_TIMELIMIT_MS) // 'nn'ms limit
{
rfm22_setRxMode(); // back to rx mode
tx_data_rd = tx_data_wr = 0; // wipe TX buffer
break;
}
// if (timer_ms >= TX_TEST_MODE_TIMELIMIT_MS) // 'nn'ms limit
// {
// rfm22_setRxMode(); // back to rx mode
// tx_data_rd = tx_data_wr = 0; // wipe TX buffer
// break;
// }
break;
@ -1496,6 +1473,24 @@ int32_t rfm22_sendData(void *data, uint16_t length, bool send_immediately)
// ************************************
void rfm22_setTxNormal(void)
{
if (!initialized)
return;
// if (rf_mode == TX_CARRIER_MODE || rf_mode == TX_PN_MODE)
{
rfm22_setRxMode();
tx_data_rd = tx_data_wr = 0;
rx_packet_wr = 0;
rx_packet_start_rssi_dBm = 0;
rx_packet_start_afc_Hz = 0;
rx_packet_rssi_dBm = 0;
rx_packet_afc_Hz = 0;
}
}
// enable a blank tx carrier (for frequency alignment)
void rfm22_setTxCarrierMode(void)
{
@ -1552,6 +1547,43 @@ bool rfm22_txReady(void)
return (tx_data_rd == 0 && tx_data_wr == 0 && rf_mode != TX_DATA_MODE && rf_mode != TX_CARRIER_MODE && rf_mode != TX_PN_MODE);
}
// ************************************
// set/get the frequency calibration value
void rfm22_setFreqCalibration(uint8_t value)
{
osc_load_cap = value;
if (!initialized || power_on_reset)
return; // we haven't yet been initialized
uint8_t prev_rf_mode = rf_mode;
if (rf_mode == TX_CARRIER_MODE || rf_mode == TX_PN_MODE)
{
rfm22_setRxMode();
tx_data_rd = tx_data_wr = 0;
}
#if defined(RFM22_EXT_INT_USE)
exec_using_spi = TRUE;
#endif
rfm22_write(RFM22_xtal_osc_load_cap, osc_load_cap);
#if defined(RFM22_EXT_INT_USE)
exec_using_spi = FALSE;
#endif
if (prev_rf_mode == TX_CARRIER_MODE || prev_rf_mode == TX_PN_MODE)
rfm22_setTxMode(prev_rf_mode);
}
uint8_t rfm22_getFreqCalibration(void)
{
return osc_load_cap;
}
// ************************************
// can be called from an interrupt if you wish
@ -1642,12 +1674,12 @@ void rfm22_process(void)
case TX_CARRIER_MODE:
case TX_PN_MODE:
if (rfm22_int_timer >= TX_TEST_MODE_TIMELIMIT_MS)
{
rfm22_setRxMode(); // back to rx mode
tx_data_rd = tx_data_wr = 0; // wipe TX buffer
break;
}
// if (rfm22_int_timer >= TX_TEST_MODE_TIMELIMIT_MS)
// {
// rfm22_setRxMode(); // back to rx mode
// tx_data_rd = tx_data_wr = 0; // wipe TX buffer
// break;
// }
break;
@ -1923,6 +1955,7 @@ int rfm22_init(uint32_t min_frequency_hz, uint32_t max_frequency_hz, uint32_t fr
rfm22_setNominalCarrierFrequency((min_frequency_hz + max_frequency_hz) / 2); // set our nominal carrier frequency
rfm22_write(RFM22_tx_power, RFM22_tx_pwr_papeaken | RFM22_tx_pwr_papeaklvl_0 | RFM22_tx_pwr_lna_sw | tx_power); // set the tx power
// rfm22_write(RFM22_tx_power, RFM22_tx_pwr_lna_sw | tx_power); // set the tx power
// rfm22_write(RFM22_vco_current_trimming, 0x7f);
// rfm22_write(RFM22_vco_calibration_override, 0x40);

View File

@ -453,7 +453,7 @@
<number>-120</number>
</property>
<property name="maximum">
<number>-20</number>
<number>0</number>
</property>
<property name="value">
<number>-60</number>

View File

@ -202,7 +202,7 @@ PipXtremeGadgetWidget::PipXtremeGadgetWidget(QWidget *parent) :
m_widget->doubleSpinBox_Frequency->setSingleStep(0.00015625);
m_widget->progressBar_RSSI->setMinimum(-120);
m_widget->progressBar_RSSI->setMaximum(-20);
m_widget->progressBar_RSSI->setMaximum(0);
m_widget->progressBar_RSSI->setValue(m_widget->progressBar_RSSI->minimum());
m_widget->label_RSSI->setText("RSSI");
@ -902,6 +902,7 @@ void PipXtremeGadgetWidget::processRxPacket(quint8 *packet, int packet_size)
m_widget->doubleSpinBox_Frequency->setMinimum((double)pipx_config_details.min_frequency_Hz / 1e6);
m_widget->doubleSpinBox_Frequency->setMaximum((double)pipx_config_details.max_frequency_Hz / 1e6);
m_widget->doubleSpinBox_Frequency->setSingleStep(((double)pipx_config_details.frequency_step_size * 4) / 1e6);
m_widget->lineEdit_FrequencyStepSize->setText(QString::number(pipx_config_details.frequency_step_size, 'f', 2) + "Hz");