From ab135aa00ba9c3c06f121df2ba7e7c201b42194a Mon Sep 17 00:00:00 2001 From: Stacey Sheldon Date: Wed, 28 Dec 2011 12:24:32 -0500 Subject: [PATCH] com-bridge: Make com-bridge an optional (and configurable) module --- flight/Modules/ComUsbBridge/ComUsbBridge.c | 70 ++++++++++++++++++++-- shared/uavobjectdefinition/hwsettings.xml | 3 +- shared/uavobjectdefinition/taskinfo.xml | 6 +- 3 files changed, 69 insertions(+), 10 deletions(-) diff --git a/flight/Modules/ComUsbBridge/ComUsbBridge.c b/flight/Modules/ComUsbBridge/ComUsbBridge.c index 3b52119ae..984a53944 100644 --- a/flight/Modules/ComUsbBridge/ComUsbBridge.c +++ b/flight/Modules/ComUsbBridge/ComUsbBridge.c @@ -31,6 +31,7 @@ // **************** #include "openpilot.h" +#include "hwsettings.h" #include @@ -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; + } + } +} diff --git a/shared/uavobjectdefinition/hwsettings.xml b/shared/uavobjectdefinition/hwsettings.xml index d259ee6c2..dbb605c51 100644 --- a/shared/uavobjectdefinition/hwsettings.xml +++ b/shared/uavobjectdefinition/hwsettings.xml @@ -11,9 +11,10 @@ + - + diff --git a/shared/uavobjectdefinition/taskinfo.xml b/shared/uavobjectdefinition/taskinfo.xml index cbccac73f..11b550089 100644 --- a/shared/uavobjectdefinition/taskinfo.xml +++ b/shared/uavobjectdefinition/taskinfo.xml @@ -1,9 +1,9 @@ Task information - - - + + +