1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

LP-346 RFM22 tuning: Allow XtalCap value changes without reboot.

This commit is contained in:
Laurent Lalanne 2016-10-04 00:41:40 +02:00
parent 54fa56d421
commit 1e920ec67c
5 changed files with 69 additions and 3 deletions

View File

@ -67,9 +67,11 @@ static xTaskHandle systemTaskHandle;
static bool stackOverflow;
static bool mallocFailed;
volatile int initTaskDone = 0;
static OPLinkSettingsData previousOPLinkSettings;
// Private functions
static void systemTask(void *parameters);
static void checkOPLinkSettingsUpdatedCb(UAVObjEvent *ev);
/**
* Create the module task.
@ -133,6 +135,8 @@ static void systemTask(__attribute__((unused)) void *parameters)
PIOS_SYS_Reset();
}
OPLinkSettingsConnectCallback(checkOPLinkSettingsUpdatedCb);
// Initialize vars
lastSysTime = xTaskGetTickCount();
@ -242,6 +246,22 @@ void vApplicationMallocFailedHook(void)
#endif
}
/**
* Called whenever OPLink settings changed
*/
static void checkOPLinkSettingsUpdatedCb(__attribute__((unused)) UAVObjEvent *ev)
{
OPLinkSettingsData currentOPLinkSettings;
OPLinkSettingsGet(&currentOPLinkSettings);
// Check if RFXtalCap value changed
if (currentOPLinkSettings.RFXtalCap != previousOPLinkSettings.RFXtalCap) {
PIOS_RFM22B_SetXtalCap(pios_rfm22b_id, currentOPLinkSettings.RFXtalCap);
PIOS_RFM22B_Reinit(pios_rfm22b_id);
previousOPLinkSettings = currentOPLinkSettings;
}
}
/**
* @}
* @}

View File

@ -129,6 +129,11 @@ static void updateWDGstats();
static uint8_t i2c_error_activity[PIOS_I2C_ERROR_COUNT_NUMELEM];
#endif
#ifdef PIOS_INCLUDE_RFM22B
static OPLinkSettingsData previousOPLinkSettings;
static void checkOPLinkSettingsUpdatedCb(UAVObjEvent *ev);
#endif
extern uintptr_t pios_uavo_settings_fs_id;
extern uintptr_t pios_user_fs_id;
@ -231,6 +236,10 @@ static void systemTask(__attribute__((unused)) void *parameters)
HwSettingsConnectCallback(checkSettingsUpdatedCb);
SystemSettingsConnectCallback(checkSettingsUpdatedCb);
#ifdef PIOS_INCLUDE_RFM22B
OPLinkSettingsConnectCallback(checkOPLinkSettingsUpdatedCb);
#endif
#ifdef DIAG_TASKS
TaskInfoData taskInfoData;
CallbackInfoData callbackInfoData;
@ -454,6 +463,24 @@ static void checkSettingsUpdatedCb(__attribute__((unused)) UAVObjEvent *ev)
}
}
#ifdef PIOS_INCLUDE_RFM22B
/**
* Called whenever OPLink settings changed
*/
static void checkOPLinkSettingsUpdatedCb(__attribute__((unused)) UAVObjEvent *ev)
{
OPLinkSettingsData currentOPLinkSettings;
OPLinkSettingsGet(&currentOPLinkSettings);
// Check if RFXtalCap value changed
if (currentOPLinkSettings.RFXtalCap != previousOPLinkSettings.RFXtalCap) {
PIOS_RFM22B_SetXtalCap(pios_rfm22b_id, currentOPLinkSettings.RFXtalCap);
PIOS_RFM22B_Reinit(pios_rfm22b_id);
previousOPLinkSettings = currentOPLinkSettings;
}
}
#endif /* ifdef PIOS_INCLUDE_RFM22B */
#ifdef DIAG_TASKS
static void taskMonitorForEachCallback(uint16_t task_id, const struct pios_task_info *task_info, void *context)
{

View File

@ -652,6 +652,21 @@ void PIOS_RFM22B_SetChannelConfig(uint32_t rfm22b_id, enum rfm22b_datarate datar
}
}
/**
* Set a XtalCap
*
* @param[in] rfm22b_id The RFM22B device index.
* @param[in] XtalCap Value.
*/
void PIOS_RFM22B_SetXtalCap(uint32_t rfm22b_id, uint8_t xtal_cap)
{
struct pios_rfm22b_dev *rfm22b_dev = (struct pios_rfm22b_dev *)rfm22b_id;
if (PIOS_RFM22B_Validate(rfm22b_dev)) {
rfm22b_dev->cfg.RFXtalCap = xtal_cap;
}
}
/**
* Set a modem to be a coordinator or not.
*

View File

@ -105,6 +105,7 @@ extern int32_t PIOS_RFM22B_Init(uint32_t *rfb22b_id, uint32_t spi_id, uint32_t s
extern void PIOS_RFM22B_Reinit(uint32_t rfb22b_id);
extern void PIOS_RFM22B_SetTxPower(uint32_t rfm22b_id, enum rfm22b_tx_power tx_pwr);
extern void PIOS_RFM22B_SetChannelConfig(uint32_t rfm22b_id, enum rfm22b_datarate datarate, uint8_t min_chan, uint8_t max_chan, bool coordinator, bool ppm_mode, bool ppm_only);
extern void PIOS_RFM22B_SetXtalCap(uint32_t rfm22b_id, uint8_t xtal_cap);
extern void PIOS_RFM22B_SetCoordinatorID(uint32_t rfm22b_id, uint32_t coord_id);
extern void PIOS_RFM22B_SetDeviceID(uint32_t rfm22b_id, uint32_t device_id);
extern uint32_t PIOS_RFM22B_DeviceID(uint32_t rfb22b_id);

View File

@ -1923,7 +1923,8 @@ Leave blank to use autogenerated Device ID.</string>
<item row="1" column="1">
<widget class="QSlider" name="RFXtalCapSlider">
<property name="toolTip">
<string>The xtal capacitor value for fine tune frequency and get a AFC value close to zero. Default value is 127.</string>
<string>Adjust the xtal capacitor value to fine tune frequency and
get an AFC value close to zero. Default value is 127.</string>
</property>
<property name="maximum">
<number>171</number>
@ -1942,7 +1943,8 @@ Leave blank to use autogenerated Device ID.</string>
<item row="1" column="2">
<widget class="QSpinBox" name="RFXtalCapValue">
<property name="toolTip">
<string>The xtal capacitor value for fine tune frequency and get a AFC value close to zero. Default value is 127.</string>
<string>Adjust the xtal capacitor value to fine tune frequency and
get an AFC value close to zero. Default value is 127.</string>
</property>
<property name="maximum">
<number>171</number>
@ -1959,7 +1961,8 @@ Leave blank to use autogenerated Device ID.</string>
<item row="0" column="1" colspan="2">
<widget class="QProgressBar" name="AFCCorrectionBar">
<property name="toolTip">
<string>The Automatic Frequency Correction: How much the modem will correct a frequency misalignement between the two modems.</string>
<string>The Automatic Frequency Correction: How much the modem will correct
a frequency misalignement between the two modems.</string>
</property>
<property name="minimum">
<number>-50</number>