mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-30 15:52:12 +01:00
com-bridge: Make com-bridge an optional (and configurable) module
This commit is contained in:
parent
5b3227d1ff
commit
ab135aa00b
@ -31,6 +31,7 @@
|
||||
// ****************
|
||||
|
||||
#include "openpilot.h"
|
||||
#include "hwsettings.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
@ -39,6 +40,7 @@
|
||||
|
||||
static void com2UsbBridgeTask(void *parameters);
|
||||
static void usb2ComBridgeTask(void *parameters);
|
||||
static void updateSettings();
|
||||
|
||||
// ****************
|
||||
// Private constants
|
||||
@ -60,6 +62,8 @@ static uint8_t * usb2com_buf;
|
||||
static uint32_t usart_port;
|
||||
static uint32_t vcp_port;
|
||||
|
||||
static bool bridge_enabled = false;
|
||||
|
||||
/**
|
||||
* Initialise the module
|
||||
* \return -1 if initialisation failed
|
||||
@ -68,13 +72,16 @@ static uint32_t vcp_port;
|
||||
|
||||
static int32_t comUsbBridgeStart(void)
|
||||
{
|
||||
if (usart_port && vcp_port) {
|
||||
if (bridge_enabled) {
|
||||
// Start tasks
|
||||
xTaskCreate(com2UsbBridgeTask, (signed char *)"Com2UsbBridge", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &com2UsbBridgeTaskHandle);
|
||||
TaskMonitorAdd(TASKINFO_RUNNING_COM2USBBRIDGE, com2UsbBridgeTaskHandle);
|
||||
xTaskCreate(usb2ComBridgeTask, (signed char *)"Usb2ComBridge", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &usb2ComBridgeTaskHandle);
|
||||
TaskMonitorAdd(TASKINFO_RUNNING_USB2COMBRIDGE, usb2ComBridgeTaskHandle);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
/**
|
||||
* Initialise the module
|
||||
@ -87,10 +94,25 @@ static int32_t comUsbBridgeInitialize(void)
|
||||
usart_port = PIOS_COM_BRIDGE;
|
||||
vcp_port = PIOS_COM_VCP;
|
||||
|
||||
com2usb_buf = pvPortMalloc(BRIDGE_BUF_LEN);
|
||||
PIOS_Assert(com2usb_buf);
|
||||
usb2com_buf = pvPortMalloc(BRIDGE_BUF_LEN);
|
||||
PIOS_Assert(usb2com_buf);
|
||||
HwSettingsInitialize();
|
||||
uint8_t optionalModules[HWSETTINGS_OPTIONALMODULES_NUMELEM];
|
||||
|
||||
HwSettingsOptionalModulesGet(optionalModules);
|
||||
|
||||
if (usart_port && vcp_port &&
|
||||
(optionalModules[HWSETTINGS_OPTIONALMODULES_COMUSBBRIDGE] == HWSETTINGS_OPTIONALMODULES_ENABLED))
|
||||
bridge_enabled = true;
|
||||
else
|
||||
bridge_enabled = false;
|
||||
|
||||
if (bridge_enabled) {
|
||||
com2usb_buf = pvPortMalloc(BRIDGE_BUF_LEN);
|
||||
PIOS_Assert(com2usb_buf);
|
||||
usb2com_buf = pvPortMalloc(BRIDGE_BUF_LEN);
|
||||
PIOS_Assert(usb2com_buf);
|
||||
|
||||
updateSettings();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -135,3 +157,39 @@ static void usb2ComBridgeTask(void * parameters)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void updateSettings()
|
||||
{
|
||||
if (usart_port) {
|
||||
|
||||
// Retrieve settings
|
||||
uint8_t speed;
|
||||
HwSettingsComUsbBridgeSpeedGet(&speed);
|
||||
|
||||
// Set port speed
|
||||
switch (speed) {
|
||||
case HWSETTINGS_COMUSBBRIDGESPEED_2400:
|
||||
PIOS_COM_ChangeBaud(usart_port, 2400);
|
||||
break;
|
||||
case HWSETTINGS_COMUSBBRIDGESPEED_4800:
|
||||
PIOS_COM_ChangeBaud(usart_port, 4800);
|
||||
break;
|
||||
case HWSETTINGS_COMUSBBRIDGESPEED_9600:
|
||||
PIOS_COM_ChangeBaud(usart_port, 9600);
|
||||
break;
|
||||
case HWSETTINGS_COMUSBBRIDGESPEED_19200:
|
||||
PIOS_COM_ChangeBaud(usart_port, 19200);
|
||||
break;
|
||||
case HWSETTINGS_COMUSBBRIDGESPEED_38400:
|
||||
PIOS_COM_ChangeBaud(usart_port, 38400);
|
||||
break;
|
||||
case HWSETTINGS_COMUSBBRIDGESPEED_57600:
|
||||
PIOS_COM_ChangeBaud(usart_port, 57600);
|
||||
break;
|
||||
case HWSETTINGS_COMUSBBRIDGESPEED_115200:
|
||||
PIOS_COM_ChangeBaud(usart_port, 115200);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,9 +11,10 @@
|
||||
|
||||
<field name="TelemetrySpeed" units="bps" type="enum" elements="1" options="2400,4800,9600,19200,38400,57600,115200" defaultvalue="57600"/>
|
||||
<field name="GPSSpeed" units="bps" type="enum" elements="1" options="2400,4800,9600,19200,38400,57600,115200" defaultvalue="57600"/>
|
||||
<field name="ComUsbBridgeSpeed" units="bps" type="enum" elements="1" options="2400,4800,9600,19200,38400,57600,115200" defaultvalue="57600"/>
|
||||
<field name="USB_TelemetryChannel" units="function" type="enum" elements="1" options="HID,CDC" defaultvalue="HID"/>
|
||||
|
||||
<field name="OptionalModules" units="" type="enum" elementnames="CameraStab,GPS" options="Disabled,Enabled" defaultvalue="Disabled"/>
|
||||
<field name="OptionalModules" units="" type="enum" elementnames="CameraStab,GPS,ComUsbBridge" options="Disabled,Enabled" defaultvalue="Disabled"/>
|
||||
<field name="DSMxBind" units="" type="uint8" elements="1" defaultvalue="0"/>
|
||||
|
||||
<access gcs="readwrite" flight="readwrite"/>
|
||||
|
@ -1,9 +1,9 @@
|
||||
<xml>
|
||||
<object name="TaskInfo" singleinstance="true" settings="false">
|
||||
<description>Task information</description>
|
||||
<field name="StackRemaining" units="bytes" type="uint16" elementnames="System,Actuator,Attitude,TelemetryTx,TelemetryTxPri,TelemetryRx,GPS,ManualControl,Altitude,AHRSComms,Stabilization,Guidance,FlightPlan"/>
|
||||
<field name="Running" units="bool" type="enum" options="False,True" elementnames="System,Actuator,Attitude,TelemetryTx,TelemetryTxPri,TelemetryRx,GPS,ManualControl,Altitude,AHRSComms,Stabilization,Guidance,FlightPlan"/>
|
||||
<field name="RunningTime" units="%" type="uint8" elementnames="System,Actuator,Attitude,TelemetryTx,TelemetryTxPri,TelemetryRx,GPS,ManualControl,Altitude,AHRSComms,Stabilization,Guidance,FlightPlan"/>
|
||||
<field name="StackRemaining" units="bytes" type="uint16" elementnames="System,Actuator,Attitude,TelemetryTx,TelemetryTxPri,TelemetryRx,GPS,ManualControl,Altitude,AHRSComms,Stabilization,Guidance,FlightPlan,Com2UsbBridge,Usb2ComBridge"/>
|
||||
<field name="Running" units="bool" type="enum" options="False,True" elementnames="System,Actuator,Attitude,TelemetryTx,TelemetryTxPri,TelemetryRx,GPS,ManualControl,Altitude,AHRSComms,Stabilization,Guidance,FlightPlan,Com2UsbBridge,Usb2ComBridge"/>
|
||||
<field name="RunningTime" units="%" type="uint8" elementnames="System,Actuator,Attitude,TelemetryTx,TelemetryTxPri,TelemetryRx,GPS,ManualControl,Altitude,AHRSComms,Stabilization,Guidance,FlightPlan,Com2UsbBridge,Usb2ComBridge"/>
|
||||
<access gcs="readwrite" flight="readwrite"/>
|
||||
<telemetrygcs acked="true" updatemode="onchange" period="0"/>
|
||||
<telemetryflight acked="true" updatemode="periodic" period="10000"/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user