1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-03-21 13:28:58 +01:00

OP-932 Moves the configuration of the com ports on the coordinator OPLink to startup.

This commit is contained in:
Brian Webb 2013-05-21 19:48:21 -07:00
parent dbce08a151
commit ac4847c8ac
4 changed files with 85 additions and 135 deletions

View File

@ -110,9 +110,8 @@ static int32_t RadioSendHandler(uint8_t *buf, int32_t length);
static void ProcessInputStream(UAVTalkConnection connectionHandle, uint8_t rxbyte);
static void queueEvent(xQueueHandle queue, void *obj, uint16_t instId, UAVObjEventType type);
static void configureComCallback(OPLinkSettingsRemoteMainPortOptions main_port, OPLinkSettingsRemoteFlexiPortOptions flexi_port,
OPLinkSettingsRemoteVCPPortOptions vcp_port, OPLinkSettingsComSpeedOptions com_speed,
uint32_t min_frequency, uint32_t max_frequency, uint32_t channel_spacing);
static void updateSettings();
OPLinkSettingsRemoteVCPPortOptions vcp_port, OPLinkSettingsComSpeedOptions com_speed);
static void updateSettings(OPLinkSettingsData *oplinkSettings);
// ****************
// Private variables
@ -127,9 +126,6 @@ static RadioComBridgeData *data;
static int32_t RadioComBridgeStart(void)
{
if (data) {
// Configure the com port configuration callback
PIOS_RFM22B_SetComConfigCallback(pios_rfm22b_id, &configureComCallback);
// Get the settings.
OPLinkSettingsData oplinkSettings;
OPLinkSettingsGet(&oplinkSettings);
@ -140,6 +136,9 @@ static int32_t RadioComBridgeStart(void)
// Set the frequency range.
PIOS_RFM22B_SetFrequencyRange(pios_rfm22b_id, oplinkSettings.MinFrequency, oplinkSettings.MaxFrequency, oplinkSettings.ChannelSpacing);
// Set the com baud rates.
updateSettings(&oplinkSettings);
// Reinitilize the modem.
PIOS_RFM22B_Reinit(pios_rfm22b_id);
@ -147,6 +146,9 @@ static int32_t RadioComBridgeStart(void)
data->parseUAVTalk = ((oplinkSettings.MainPort != OPLINKSETTINGS_MAINPORT_SERIAL) &&
(oplinkSettings.FlexiPort != OPLINKSETTINGS_FLEXIPORT_SERIAL) &&
(oplinkSettings.VCPPort != OPLINKSETTINGS_VCPPORT_SERIAL));
} else {
// Configure the com port configuration callback on the remote modem.
PIOS_RFM22B_SetComConfigCallback(pios_rfm22b_id, &configureComCallback);
}
// Set the maximum radio RF power.
@ -572,78 +574,65 @@ static void queueEvent(xQueueHandle queue, void *obj, uint16_t instId, UAVObjEve
* @param[in] com_speed The com port speed
*/
static void configureComCallback(OPLinkSettingsRemoteMainPortOptions main_port, OPLinkSettingsRemoteFlexiPortOptions flexi_port,
OPLinkSettingsRemoteVCPPortOptions vcp_port, OPLinkSettingsComSpeedOptions com_speed,
uint32_t min_frequency, uint32_t max_frequency, uint32_t channel_spacing)
OPLinkSettingsRemoteVCPPortOptions vcp_port, OPLinkSettingsComSpeedOptions com_speed)
{
// Update the com baud rate
data->comSpeed = com_speed;
// Set the output main/flexi/vcp port and speed.
bool is_coordinator = PIOS_RFM22B_IsCoordinator(pios_rfm22b_id);
if (!is_coordinator) {
// Get the settings.
OPLinkSettingsData oplinkSettings;
OPLinkSettingsGet(&oplinkSettings);
// Get the settings.
OPLinkSettingsData oplinkSettings;
OPLinkSettingsGet(&oplinkSettings);
switch (main_port) {
case OPLINKSETTINGS_REMOTEMAINPORT_DISABLED:
oplinkSettings.MainPort = OPLINKSETTINGS_MAINPORT_DISABLED;
break;
case OPLINKSETTINGS_REMOTEMAINPORT_SERIAL:
oplinkSettings.MainPort = OPLINKSETTINGS_MAINPORT_SERIAL;
break;
case OPLINKSETTINGS_REMOTEMAINPORT_PPM:
oplinkSettings.MainPort = OPLINKSETTINGS_MAINPORT_PPM;
break;
}
switch (flexi_port) {
case OPLINKSETTINGS_REMOTEFLEXIPORT_DISABLED:
oplinkSettings.FlexiPort = OPLINKSETTINGS_FLEXIPORT_DISABLED;
break;
case OPLINKSETTINGS_REMOTEFLEXIPORT_SERIAL:
oplinkSettings.FlexiPort = OPLINKSETTINGS_FLEXIPORT_SERIAL;
break;
case OPLINKSETTINGS_REMOTEFLEXIPORT_PPM:
oplinkSettings.FlexiPort = OPLINKSETTINGS_FLEXIPORT_PPM;
break;
}
switch (vcp_port) {
case OPLINKSETTINGS_REMOTEVCPPORT_DISABLED:
oplinkSettings.VCPPort = OPLINKSETTINGS_VCPPORT_DISABLED;
break;
case OPLINKSETTINGS_REMOTEVCPPORT_SERIAL:
oplinkSettings.VCPPort = OPLINKSETTINGS_VCPPORT_SERIAL;
break;
}
// Set the frequency range.
PIOS_RFM22B_SetFrequencyRange(pios_rfm22b_id, min_frequency, max_frequency, channel_spacing);
// We will not parse/send UAVTalk if any ports are configured as Serial (except for over the USB HID port).
data->parseUAVTalk = ((oplinkSettings.MainPort != OPLINKSETTINGS_MAINPORT_SERIAL) &&
(oplinkSettings.FlexiPort != OPLINKSETTINGS_FLEXIPORT_SERIAL) &&
(oplinkSettings.VCPPort != OPLINKSETTINGS_VCPPORT_SERIAL));
// Update the OPLinkSettings object.
OPLinkSettingsSet(&oplinkSettings);
switch (main_port) {
case OPLINKSETTINGS_REMOTEMAINPORT_DISABLED:
oplinkSettings.MainPort = OPLINKSETTINGS_MAINPORT_DISABLED;
break;
case OPLINKSETTINGS_REMOTEMAINPORT_SERIAL:
oplinkSettings.MainPort = OPLINKSETTINGS_MAINPORT_SERIAL;
break;
case OPLINKSETTINGS_REMOTEMAINPORT_PPM:
oplinkSettings.MainPort = OPLINKSETTINGS_MAINPORT_PPM;
break;
}
switch (flexi_port) {
case OPLINKSETTINGS_REMOTEFLEXIPORT_DISABLED:
oplinkSettings.FlexiPort = OPLINKSETTINGS_FLEXIPORT_DISABLED;
break;
case OPLINKSETTINGS_REMOTEFLEXIPORT_SERIAL:
oplinkSettings.FlexiPort = OPLINKSETTINGS_FLEXIPORT_SERIAL;
break;
case OPLINKSETTINGS_REMOTEFLEXIPORT_PPM:
oplinkSettings.FlexiPort = OPLINKSETTINGS_FLEXIPORT_PPM;
break;
}
switch (vcp_port) {
case OPLINKSETTINGS_REMOTEVCPPORT_DISABLED:
oplinkSettings.VCPPort = OPLINKSETTINGS_VCPPORT_DISABLED;
break;
case OPLINKSETTINGS_REMOTEVCPPORT_SERIAL:
oplinkSettings.VCPPort = OPLINKSETTINGS_VCPPORT_SERIAL;
break;
}
// We will not parse/send UAVTalk if any ports are configured as Serial (except for over the USB HID port).
data->parseUAVTalk = ((oplinkSettings.MainPort != OPLINKSETTINGS_MAINPORT_SERIAL) &&
(oplinkSettings.FlexiPort != OPLINKSETTINGS_FLEXIPORT_SERIAL) &&
(oplinkSettings.VCPPort != OPLINKSETTINGS_VCPPORT_SERIAL));
// Update the OPLinkSettings object.
OPLinkSettingsSet(&oplinkSettings);
// Perform the update.
updateSettings();
updateSettings(&oplinkSettings);
}
/**
* Update the oplink settings.
*/
static void updateSettings()
static void updateSettings(OPLinkSettingsData *oplinkSettings)
{
// Get the settings.
OPLinkSettingsData oplinkSettings;
OPLinkSettingsGet(&oplinkSettings);
// We can only configure the hardware once.
if (data->configured) {
return;
@ -652,7 +641,7 @@ static void updateSettings()
// Configure the main port
bool is_coordinator = PIOS_RFM22B_IsCoordinator(pios_rfm22b_id);
switch (oplinkSettings.MainPort) {
switch (oplinkSettings->MainPort) {
case OPLINKSETTINGS_MAINPORT_TELEMETRY:
case OPLINKSETTINGS_MAINPORT_SERIAL:
/* Configure the main port for uart serial */
@ -667,7 +656,7 @@ static void updateSettings()
}
// Configure the flexi port
switch (oplinkSettings.FlexiPort) {
switch (oplinkSettings->FlexiPort) {
case OPLINKSETTINGS_FLEXIPORT_TELEMETRY:
case OPLINKSETTINGS_FLEXIPORT_SERIAL:
/* Configure the flexi port as uart serial */
@ -682,7 +671,7 @@ static void updateSettings()
}
// Configure the USB VCP port
switch (oplinkSettings.VCPPort) {
switch (oplinkSettings->VCPPort) {
case OPLINKSETTINGS_VCPPORT_SERIAL:
PIOS_COM_TELEMETRY = PIOS_COM_TELEM_USB_VCP;
break;
@ -715,9 +704,6 @@ static void updateSettings()
comBaud = 115200;
break;
}
if (PIOS_COM_RADIO) {
PIOS_COM_ChangeBaud(PIOS_COM_RADIO, comBaud);
}
if (PIOS_COM_TELEMETRY) {
PIOS_COM_ChangeBaud(PIOS_COM_TELEMETRY, comBaud);
}

View File

@ -2464,12 +2464,37 @@ static void rfm22_setConnectionParameters(struct pios_rfm22b_dev *rfm22b_dev)
// Call the com port configuration function
if (rfm22b_dev->com_config_cb) {
rfm22b_dev->com_config_cb(cph->main_port, cph->flexi_port, cph->vcp_port, cph->com_speed,
cph->min_frequency, cph->max_frequency, cph->channel_spacing);
rfm22b_dev->com_config_cb(cph->main_port, cph->flexi_port, cph->vcp_port, cph->com_speed);
}
// Configure this modem from the connection request message.
// Configure this modem min an max frequency.
rfm22_setNominalCarrierFrequency(rfm22b_dev, cph->min_frequency, cph->max_frequency, cph->channel_spacing);
// Configure the modem datarate.
rfm22b_dev->datarate = RFM22_datarate_64000;
switch (cph->com_speed) {
case OPLINKSETTINGS_COMSPEED_2400:
rfm22b_dev->datarate = RFM22_datarate_8000;
break;
case OPLINKSETTINGS_COMSPEED_4800:
rfm22b_dev->datarate = RFM22_datarate_8000;
break;
case OPLINKSETTINGS_COMSPEED_9600:
rfm22b_dev->datarate = RFM22_datarate_16000;
break;
case OPLINKSETTINGS_COMSPEED_19200:
rfm22b_dev->datarate = RFM22_datarate_32000;
break;
case OPLINKSETTINGS_COMSPEED_38400:
rfm22b_dev->datarate = RFM22_datarate_57600;
break;
case OPLINKSETTINGS_COMSPEED_57600:
rfm22b_dev->datarate = RFM22_datarate_128000;
break;
case OPLINKSETTINGS_COMSPEED_115200:
rfm22b_dev->datarate = RFM22_datarate_192000;
break;
}
pios_rfm22_setDatarate(rfm22b_dev, rfm22b_dev->datarate, true);
}

View File

@ -106,8 +106,7 @@ struct rfm22b_stats {
/* Callback function prototypes */
typedef void (*PIOS_RFM22B_ComConfigCallback)(OPLinkSettingsRemoteMainPortOptions main_port, OPLinkSettingsRemoteFlexiPortOptions flexi_port,
OPLinkSettingsRemoteVCPPortOptions vcp_port, OPLinkSettingsComSpeedOptions com_speed,
uint32_t min_frequency, uint32_t max_frequency, uint32_t channel_spacing);
OPLinkSettingsRemoteVCPPortOptions vcp_port, OPLinkSettingsComSpeedOptions com_speed);
/* Public Functions */
extern int32_t PIOS_RFM22B_Init(uint32_t *rfb22b_id, uint32_t spi_id, uint32_t slave_num, const struct pios_rfm22b_cfg *cfg);

View File

@ -42,13 +42,6 @@
*/
#include "../board_hw_defs.c"
#if defined(PIOS_INCLUDE_RFM22B)
// Forward declarations
static void configureComCallback(OPLinkSettingsRemoteMainPortOptions main_port, OPLinkSettingsRemoteFlexiPortOptions flexi_port,
OPLinkSettingsRemoteVCPPortOptions vcp_port, OPLinkSettingsComSpeedOptions com_speed,
uint32_t min_frequency, uint32_t max_frequency, uint32_t channel_spacing);
#endif
/**
* Sensor configurations
*/
@ -785,10 +778,6 @@ void PIOS_Board_Init(void)
}
pios_rcvr_group_map[MANUALCONTROLSETTINGS_CHANNELGROUPS_OPLINK] = pios_rfm22b_rcvr_id;
#endif
// Set the com port configuration callback.
PIOS_RFM22B_SetComConfigCallback(pios_rfm22b_id, &configureComCallback);
break;
}
}
@ -881,55 +870,6 @@ void PIOS_Board_Init(void)
#endif
}
#if defined(PIOS_INCLUDE_RFM22B)
/**
* Configure the radio com port based on a configuration event from the remote coordinator.
* \param[in] main_port The main com port options
* \param[in] flexi_port The flexi com port options
* \param[in] vcp_port The USB virtual com port options
* \param[in] com_speed The com port speed
*/
static void configureComCallback(__attribute__((unused)) OPLinkSettingsRemoteMainPortOptions main_port,
__attribute__((unused)) OPLinkSettingsRemoteFlexiPortOptions flexi_port,
__attribute__((unused)) OPLinkSettingsRemoteVCPPortOptions vcp_port,
OPLinkSettingsComSpeedOptions com_speed,
uint32_t min_frequency, uint32_t max_frequency, uint32_t channel_spacing)
{
uint32_t comBaud = 9600;
switch (com_speed) {
case OPLINKSETTINGS_COMSPEED_2400:
comBaud = 2400;
break;
case OPLINKSETTINGS_COMSPEED_4800:
comBaud = 4800;
break;
case OPLINKSETTINGS_COMSPEED_9600:
comBaud = 9600;
break;
case OPLINKSETTINGS_COMSPEED_19200:
comBaud = 19200;
break;
case OPLINKSETTINGS_COMSPEED_38400:
comBaud = 38400;
break;
case OPLINKSETTINGS_COMSPEED_57600:
comBaud = 57600;
break;
case OPLINKSETTINGS_COMSPEED_115200:
comBaud = 115200;
break;
}
if (PIOS_COM_TELEM_RF) {
PIOS_COM_ChangeBaud(PIOS_COM_TELEM_RF, comBaud);
}
// Set the frequency range.
PIOS_RFM22B_SetFrequencyRange(pios_rfm22b_id, min_frequency, max_frequency, channel_spacing);
}
#endif /* if defined(PIOS_INCLUDE_RFM22B) */
/**
* @}
* @}