From 774a74884a0a0b909107d4d02d6c4614d890bd02 Mon Sep 17 00:00:00 2001 From: Brian Webb Date: Sun, 16 Jun 2013 08:48:18 -0700 Subject: [PATCH] OP-932 Replaces the RFM22B PPM/receiver code with an OPLinkReceiver UAVObject. This object is generated on a coordinator OPLink, and is used by both the OPLink to generate PPM output, and the OPLinkReceiver on the Revo. --- .../modules/RadioComBridge/RadioComBridge.c | 97 +++++++++++-- flight/pios/common/pios_rfm22b.c | 16 --- flight/pios/common/pios_rfm22b_rcvr.c | 130 ------------------ flight/pios/inc/pios_rfm22b.h | 1 - flight/pios/inc/pios_rfm22b_priv.h | 8 -- flight/pios/inc/pios_rfm22b_rcvr.h | 40 ------ flight/pios/pios.h | 4 - .../coptercontrol/firmware/inc/pios_config.h | 1 - .../boards/oplinkmini/firmware/Makefile | 2 +- .../oplinkmini/firmware/inc/pios_config.h | 3 +- .../boards/oplinkmini/firmware/pios_board.c | 35 ++++- flight/targets/boards/oplinkmini/pios_board.h | 3 +- .../boards/osd/firmware/inc/pios_config.h | 1 - .../boards/revolution/firmware/UAVObjects.inc | 1 + .../revolution/firmware/inc/pios_config.h | 1 - .../boards/revolution/firmware/pios_board.c | 25 ++-- .../revoproto/firmware/inc/pios_config.h | 1 - make/apps-defs.mk | 1 - shared/uavobjectdefinition/oplinksettings.xml | 2 +- 19 files changed, 139 insertions(+), 233 deletions(-) delete mode 100644 flight/pios/common/pios_rfm22b_rcvr.c delete mode 100644 flight/pios/inc/pios_rfm22b_rcvr.h diff --git a/flight/modules/RadioComBridge/RadioComBridge.c b/flight/modules/RadioComBridge/RadioComBridge.c index 9724f6e3f..eafb4e30b 100644 --- a/flight/modules/RadioComBridge/RadioComBridge.c +++ b/flight/modules/RadioComBridge/RadioComBridge.c @@ -35,7 +35,9 @@ #include #include #include +#include #include +#include #include #include #if defined(PIOS_INCLUDE_FLASH_EEPROM) @@ -65,6 +67,7 @@ typedef struct { xTaskHandle telemetryRxTaskHandle; xTaskHandle radioTxTaskHandle; xTaskHandle radioRxTaskHandle; + xTaskHandle PPMInputTaskHandle; // The UAVTalk connection on the com side. UAVTalkConnection telemUAVTalkCon; @@ -94,11 +97,13 @@ static void telemetryTxTask(void *parameters); static void telemetryRxTask(void *parameters); static void radioTxTask(void *parameters); static void radioRxTask(void *parameters); +static void PPMInputTask(void *parameters); static int32_t UAVTalkSendHandler(uint8_t *buf, int32_t length); static int32_t RadioSendHandler(uint8_t *buf, int32_t length); static void ProcessTelemetryStream(UAVTalkConnection inConnectionHandle, UAVTalkConnection outConnectionHandle, uint8_t rxbyte); static void ProcessRadioStream(UAVTalkConnection inConnectionHandle, UAVTalkConnection outConnectionHandle, uint8_t rxbyte); static void objectPersistenceUpdatedCb(UAVObjEvent *objEv); +static void oplinkReceiverUpdatedCb(UAVObjEvent *objEv); // **************** // Private variables @@ -116,6 +121,7 @@ static int32_t RadioComBridgeStart(void) // Get the settings. OPLinkSettingsData oplinkSettings; OPLinkSettingsGet(&oplinkSettings); + bool is_coordinator = (oplinkSettings.Coordinator == OPLINKSETTINGS_COORDINATOR_TRUE); // 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) && @@ -156,12 +162,29 @@ static int32_t RadioComBridgeStart(void) // Configure our UAVObjects for updates. UAVObjConnectQueue(UAVObjGetByID(OPLINKSTATUS_OBJID), data->uavtalkEventQueue, EV_UPDATED | EV_UPDATED_MANUAL | EV_UPDATE_REQ); UAVObjConnectQueue(UAVObjGetByID(OBJECTPERSISTENCE_OBJID), data->uavtalkEventQueue, EV_UPDATED | EV_UPDATED_MANUAL); + if (is_coordinator) { + UAVObjConnectQueue(UAVObjGetByID(OPLINKRECEIVER_OBJID), data->radioEventQueue, EV_UPDATED | EV_UPDATED_MANUAL | EV_UPDATE_REQ); + } else { + UAVObjConnectQueue(UAVObjGetByID(OPLINKRECEIVER_OBJID), data->uavtalkEventQueue, EV_UPDATED | EV_UPDATED_MANUAL | EV_UPDATE_REQ); + } + + // Configure the UAVObject callbacks + ObjectPersistenceConnectCallback(&objectPersistenceUpdatedCb); + if (!is_coordinator) { + OPLinkReceiverConnectCallback(&oplinkReceiverUpdatedCb); + } // Start the primary tasks for receiving/sending UAVTalk packets from the GCS. xTaskCreate(telemetryTxTask, (signed char *)"telemetryTxTask", STACK_SIZE_BYTES, NULL, TASK_PRIORITY, &(data->telemetryTxTaskHandle)); xTaskCreate(telemetryRxTask, (signed char *)"telemetryRxTask", STACK_SIZE_BYTES, NULL, TASK_PRIORITY, &(data->telemetryRxTaskHandle)); xTaskCreate(radioTxTask, (signed char *)"radioTxTask", STACK_SIZE_BYTES, NULL, TASK_PRIORITY, &(data->radioTxTaskHandle)); xTaskCreate(radioRxTask, (signed char *)"radioRxTask", STACK_SIZE_BYTES, NULL, TASK_PRIORITY, &(data->radioRxTaskHandle)); + if (PIOS_PPM_RECEIVER != 0) { + xTaskCreate(PPMInputTask, (signed char *)"PPMInputTask", STACK_SIZE_BYTES, NULL, TASK_PRIORITY, &(data->PPMInputTaskHandle)); +#ifdef PIOS_INCLUDE_WDG + PIOS_WDG_RegisterFlag(PIOS_WDG_PPMINPUT); +#endif + } // Register the watchdog timers. #ifdef PIOS_INCLUDE_WDG @@ -192,9 +215,7 @@ static int32_t RadioComBridgeInitialize(void) // Initialize the UAVObjects that we use OPLinkStatusInitialize(); ObjectPersistenceInitialize(); - - // Configure the UAVObject callbacks - ObjectPersistenceConnectCallback(&objectPersistenceUpdatedCb); + OPLinkReceiverInitialize(); // Initialise UAVTalk data->telemUAVTalkCon = UAVTalkInitialize(&UAVTalkSendHandler); @@ -204,13 +225,6 @@ static int32_t RadioComBridgeInitialize(void) data->uavtalkEventQueue = xQueueCreate(EVENT_QUEUE_SIZE, sizeof(UAVObjEvent)); data->radioEventQueue = xQueueCreate(EVENT_QUEUE_SIZE, sizeof(UAVObjEvent)); - // Configure our UAVObjects for updates. - UAVObjConnectQueue(UAVObjGetByID(OPLINKSTATUS_OBJID), data->uavtalkEventQueue, EV_UPDATED | EV_UPDATED_MANUAL | EV_UPDATE_REQ); - UAVObjConnectQueue(UAVObjGetByID(OBJECTPERSISTENCE_OBJID), data->uavtalkEventQueue, EV_UPDATED | EV_UPDATED_MANUAL); -#if defined(PIOS_INCLUDE_RFM22B_GCSRECEIVER) - UAVObjConnectQueue(UAVObjGetByID(GCSRECEIVER_OBJID), data->uavtalkEventQueue, EV_UPDATED | EV_UPDATED_MANUAL | EV_UPDATE_REQ); -#endif - // Initialize the statistics. data->comTxErrors = 0; data->comTxRetries = 0; @@ -389,6 +403,42 @@ static void telemetryRxTask(__attribute__((unused)) void *parameters) } } + +/** + * @brief Reads the PPM input device and sends out OPLinkReceiver objects. + * + * @param[in] parameters The task parameters (unused) + */ +static void PPMInputTask(__attribute__((unused)) void *parameters) +{ + xSemaphoreHandle sem = PIOS_RCVR_GetSemaphore(PIOS_PPM_RECEIVER, 1); + OPLinkReceiverData opl_rcvr; + + // Task loop + while (1) { +#ifdef PIOS_INCLUDE_WDG + PIOS_WDG_UpdateFlag(PIOS_WDG_PPMINPUT); +#endif + + // Wait for the receiver semaphore. + bool valid_input_detected = false; + if (xSemaphoreTake(sem, MAX_PORT_DELAY) == pdTRUE) { + // Read the receiver inputs. + for (uint8_t i = 0; i < OPLINKRECEIVER_CHANNEL_NUMELEM; ++i) { + opl_rcvr.Channel[i] = PIOS_RCVR_Read(PIOS_PPM_RECEIVER, i + 1); + if ((opl_rcvr.Channel[i] != PIOS_RCVR_INVALID) && (opl_rcvr.Channel[i] != PIOS_RCVR_TIMEOUT)) { + valid_input_detected = true; + } + } + } + + // Set the receiver UAVO if we detected valid input. + if (valid_input_detected) { + OPLinkReceiverSet(&opl_rcvr); + } + } +} + /** * @brief Transmit data buffer to the com port. * @@ -471,8 +521,15 @@ static void ProcessRadioStream(UAVTalkConnection inConnectionHandle, UAVTalkConn } else if (state == UAVTALK_STATE_COMPLETE) { // We only want to unpack certain objects from the remote modem. uint32_t objId = UAVTalkGetPacketObjId(inConnectionHandle); - if (objId != OPLINKSTATUS_OBJID) { + switch (objId) { + case OPLINKSTATUS_OBJID: + break; + case OPLINKRECEIVER_OBJID: + UAVTalkReceiveObject(inConnectionHandle); + break; + default: UAVTalkRelayPacket(inConnectionHandle, outConnectionHandle); + break; } } } @@ -491,7 +548,7 @@ static void objectPersistenceUpdatedCb(__attribute__((unused)) UAVObjEvent *objE // Is this concerning or setting object? if (obj_per.ObjectID == OPLINKSETTINGS_OBJID) { // Is this a save, load, or delete? - bool success = true; + bool success = false; switch (obj_per.Operation) { case OBJECTPERSISTENCE_OPERATION_LOAD: { @@ -542,3 +599,19 @@ static void objectPersistenceUpdatedCb(__attribute__((unused)) UAVObjEvent *objE } } } + +/** + * @brief Callback that is called when the OPLinkReceiver UAVObject is changed. + * @param[in] objEv The event that precipitated the callback. + */ +static void oplinkReceiverUpdatedCb(__attribute__((unused)) UAVObjEvent *objEv) +{ + // Get the OPLinkReceiver object. + OPLinkReceiverData opl_rcvr; + + OPLinkReceiverGet(&opl_rcvr); + + for (uint8_t i = 0; i < OPLINKRECEIVER_CHANNEL_NUMELEM; ++i) { + PIOS_PPM_OUT_Set(PIOS_PPM_OUTPUT, i, opl_rcvr.Channel[i]); + } +} diff --git a/flight/pios/common/pios_rfm22b.c b/flight/pios/common/pios_rfm22b.c index 94538607d..4266f40fc 100644 --- a/flight/pios/common/pios_rfm22b.c +++ b/flight/pios/common/pios_rfm22b.c @@ -482,22 +482,6 @@ static bool rfm22_isConnected(struct pios_rfm22b_dev *rfm22b_dev) return (rfm22b_dev->stats.link_state == OPLINKSTATUS_LINKSTATE_CONNECTED) || (rfm22b_dev->stats.link_state == OPLINKSTATUS_LINKSTATE_CONNECTING); } -/** - * Returns true if the modem is configured as a coordinator. - * - * @param[in] rfm22b_id The RFM22B device index. - * @return True if the modem is configured as a coordinator. - */ -bool PIOS_RFM22B_IsCoordinator(uint32_t rfm22b_id) -{ - struct pios_rfm22b_dev *rfm22b_dev = (struct pios_rfm22b_dev *)rfm22b_id; - - if (PIOS_RFM22B_Validate(rfm22b_dev)) { - return rfm22_isCoordinator(rfm22b_dev); - } - return false; -} - /** * Returns true if the modem is not actively sending or receiving a packet. * diff --git a/flight/pios/common/pios_rfm22b_rcvr.c b/flight/pios/common/pios_rfm22b_rcvr.c deleted file mode 100644 index f0dbc3bc4..000000000 --- a/flight/pios/common/pios_rfm22b_rcvr.c +++ /dev/null @@ -1,130 +0,0 @@ -/** - ****************************************************************************** - * @addtogroup PIOS PIOS Core hardware abstraction layer - * @{ - * @addtogroup PIOS_RFM22B_RCVR RFM22B Receiver Input Functions - * @brief Code to output the PPM signal from the RFM22B - * @{ - * - * @file pios_rfm22b_rcvr.c - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. - * @brief Implements a receiver interface to the RFM22B device - * @see The GNU Public License (GPL) Version 3 - * - *****************************************************************************/ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "pios.h" - -#ifdef PIOS_INCLUDE_RFM22B_RCVR - -#include "pios_rfm22b_priv.h" - -#include - -/* Provide a RCVR driver */ -static int32_t PIOS_RFM22B_RCVR_Get(uint32_t rcvr_id, uint8_t channel); -static void PIOS_RFM22B_RCVR_Supervisor(uint32_t rcvr_id); - -const struct pios_rcvr_driver pios_rfm22b_rcvr_driver = { - .read = PIOS_RFM22B_RCVR_Get, -}; - -/** - * Initialize the receiver. - * - * @param[in] rfm22b_dev The receiver ID. - * @return < 0 on failure. - */ -int32_t PIOS_RFM22B_RCVR_Init(uint32_t rcvr_id) -{ - struct pios_rfm22b_dev *rfm22b_dev = (struct pios_rfm22b_dev *)rcvr_id; - - if (!PIOS_RFM22B_Validate(rfm22b_dev)) { - return -1; - } - - // Initialize - for (uint8_t i = 0; i < PIOS_RFM22B_RCVR_MAX_CHANNELS; ++i) { - rfm22b_dev->ppm_channel[i] = PIOS_RCVR_TIMEOUT; - } - rfm22b_dev->ppm_supv_timer = 0; - - // Register the failsafe timer callback. - if (!PIOS_RTC_RegisterTickCallback(PIOS_RFM22B_RCVR_Supervisor, rcvr_id)) { - PIOS_DEBUG_Assert(0); - } - - return 0; -} - -/** - * Get a channel from the receiver. - * - * @param[in] rcvr_id The receiver ID. - * @return The channel value, or -1 on failure. - */ -static int32_t PIOS_RFM22B_RCVR_Get(uint32_t rcvr_id, uint8_t channel) -{ - struct pios_rfm22b_dev *rfm22b_dev = (struct pios_rfm22b_dev *)rcvr_id; - - if (!PIOS_RFM22B_Validate(rfm22b_dev)) { - return -1; - } - - if (channel >= GCSRECEIVER_CHANNEL_NUMELEM) { - /* channel is out of range */ - return -1; - } - - return rfm22b_dev->ppm_channel[channel]; -} - -/** - * The supervisor function that ensures that the data is current. - * - * @param[in] rcvr_id The receiver ID. - */ -static void PIOS_RFM22B_RCVR_Supervisor(uint32_t rcvr_id) -{ - struct pios_rfm22b_dev *rfm22b_dev = (struct pios_rfm22b_dev *)rcvr_id; - - if (!PIOS_RFM22B_Validate(rfm22b_dev)) { - return; - } - - // RTC runs at 625Hz. - if (++(rfm22b_dev->ppm_supv_timer) < (PIOS_RFM22B_RCVR_TIMEOUT_MS * 625 / 1000)) { - return; - } - rfm22b_dev->ppm_supv_timer = 0; - - // Have we received fresh values since the last update? - if (!rfm22b_dev->ppm_fresh) { - for (uint8_t i = 0; i < PIOS_RFM22B_RCVR_MAX_CHANNELS; ++i) { - rfm22b_dev->ppm_channel[i] = PIOS_RCVR_TIMEOUT; - } - } - rfm22b_dev->ppm_fresh = false; -} - -#endif /* PIOS_INCLUDE_RFM22B_RCVR */ - -/** - * @} - * @} - */ diff --git a/flight/pios/inc/pios_rfm22b.h b/flight/pios/inc/pios_rfm22b.h index b28f8ff6b..1bb23395e 100644 --- a/flight/pios/inc/pios_rfm22b.h +++ b/flight/pios/inc/pios_rfm22b.h @@ -112,7 +112,6 @@ extern void PIOS_RFM22B_SetChannelConfig(uint32_t rfm22b_id, uint8_t num_chan, u extern void PIOS_RFM22B_SetCoordinator(uint32_t rfm22b_id, bool coordinator); extern void PIOS_RFM22B_SetCoordinatorID(uint32_t rfm22b_id, uint32_t coord_id); extern uint32_t PIOS_RFM22B_DeviceID(uint32_t rfb22b_id); -extern bool PIOS_RFM22B_IsCoordinator(uint32_t rfb22b_id); extern void PIOS_RFM22B_GetStats(uint32_t rfm22b_id, struct rfm22b_stats *stats); extern uint8_t PIOS_RFM2B_GetPairStats(uint32_t rfm22b_id, uint32_t *device_ids, int8_t *RSSIs, uint8_t max_pairs); extern bool PIOS_RFM22B_InRxWait(uint32_t rfb22b_id); diff --git a/flight/pios/inc/pios_rfm22b_priv.h b/flight/pios/inc/pios_rfm22b_priv.h index ad21e68a9..3823fbcc4 100644 --- a/flight/pios/inc/pios_rfm22b_priv.h +++ b/flight/pios/inc/pios_rfm22b_priv.h @@ -36,7 +36,6 @@ #include #include #include "pios_rfm22b.h" -#include "pios_rfm22b_rcvr.h" // ************************************ @@ -770,13 +769,6 @@ struct pios_rfm22b_dev { portTickType tx_complete_ticks; portTickType time_delta; bool on_sync_channel; - -#ifdef PIOS_INCLUDE_RFM22B_RCVR - // The PPM channel values - uint16_t ppm_channel[PIOS_RFM22B_RCVR_MAX_CHANNELS]; - uint32_t ppm_supv_timer; - bool ppm_fresh; -#endif }; diff --git a/flight/pios/inc/pios_rfm22b_rcvr.h b/flight/pios/inc/pios_rfm22b_rcvr.h deleted file mode 100644 index 74d176c4e..000000000 --- a/flight/pios/inc/pios_rfm22b_rcvr.h +++ /dev/null @@ -1,40 +0,0 @@ -/** - ****************************************************************************** - * @addtogroup PIOS PIOS Core hardware abstraction layer - * @{ - * @addtogroup PIOS RFM22B Receiver Input Functions - * @{ - * - * @file pios_rfm22b_rcvr.h - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * @brief RFM22B Receiver Input functions header. - * @see The GNU Public License (GPL) Version 3 - * - *****************************************************************************/ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef PIOS_RFM22B_RCVR_H - -#define PIOS_RFM22B_RCVR_MAX_CHANNELS 12 - -extern const struct pios_rcvr_driver pios_rfm22b_rcvr_driver; - -extern int32_t PIOS_RFM22B_RCVR_Init(uint32_t rcvr_id); - -#define PIOS_RFM22B_RCVR_H - -#endif /* PIOS_RFM22B_RCVR_H */ diff --git a/flight/pios/pios.h b/flight/pios/pios.h index 6ac38703b..59875f3bc 100644 --- a/flight/pios/pios.h +++ b/flight/pios/pios.h @@ -241,10 +241,6 @@ #include #endif -#ifdef PIOS_INCLUDE_GCSRCVR -/* only priv header */ -#endif - /* PIOS abstract receiver interface */ #ifdef PIOS_INCLUDE_RCVR #include diff --git a/flight/targets/boards/coptercontrol/firmware/inc/pios_config.h b/flight/targets/boards/coptercontrol/firmware/inc/pios_config.h index 26527d716..09f9b0b51 100644 --- a/flight/targets/boards/coptercontrol/firmware/inc/pios_config.h +++ b/flight/targets/boards/coptercontrol/firmware/inc/pios_config.h @@ -116,7 +116,6 @@ /* PIOS radio modules */ /* #define PIOS_INCLUDE_RFM22B */ /* #define PIOS_INCLUDE_RFM22B_COM */ -/* #define PIOS_INCLUDE_RFM22B_RCVR */ /* #define PIOS_INCLUDE_PPM_OUT */ /* #define PIOS_RFM22B_DEBUG_ON_TELEM */ diff --git a/flight/targets/boards/oplinkmini/firmware/Makefile b/flight/targets/boards/oplinkmini/firmware/Makefile index c36788a60..12a491df5 100644 --- a/flight/targets/boards/oplinkmini/firmware/Makefile +++ b/flight/targets/boards/oplinkmini/firmware/Makefile @@ -49,10 +49,10 @@ ifndef TESTAPP SRC += $(OPUAVOBJ)/callbackscheduler.c ## UAVObjects - SRC += $(OPUAVSYNTHDIR)/gcsreceiver.c SRC += $(OPUAVSYNTHDIR)/oplinkstatus.c SRC += $(OPUAVSYNTHDIR)/oplinksettings.c SRC += $(OPUAVSYNTHDIR)/objectpersistence.c + SRC += $(OPUAVSYNTHDIR)/oplinkreceiver.c else ## Test Code SRC += $(OPTESTS)/test_common.c diff --git a/flight/targets/boards/oplinkmini/firmware/inc/pios_config.h b/flight/targets/boards/oplinkmini/firmware/inc/pios_config.h index da5b7d039..76b3860e7 100644 --- a/flight/targets/boards/oplinkmini/firmware/inc/pios_config.h +++ b/flight/targets/boards/oplinkmini/firmware/inc/pios_config.h @@ -116,9 +116,8 @@ /* PIOS radio modules */ #define PIOS_INCLUDE_RFM22B #define PIOS_INCLUDE_RFM22B_COM -/* #define PIOS_INCLUDE_RFM22B_RCVR */ #define PIOS_INCLUDE_PPM_OUT -#define PIOS_RFM22B_DEBUG_ON_TELEM +/* #define PIOS_RFM22B_DEBUG_ON_TELEM */ /* PIOS misc peripherals */ /* #define PIOS_INCLUDE_VIDEO */ diff --git a/flight/targets/boards/oplinkmini/firmware/pios_board.c b/flight/targets/boards/oplinkmini/firmware/pios_board.c index ec865d3a6..01d141ab0 100644 --- a/flight/targets/boards/oplinkmini/firmware/pios_board.c +++ b/flight/targets/boards/oplinkmini/firmware/pios_board.c @@ -221,6 +221,7 @@ void PIOS_Board_Init(void) /* Initalize the RFM22B radio COM device. */ #if defined(PIOS_INCLUDE_RFM22B) + bool is_coordinator = (oplinkSettings.Coordinator == OPLINKSETTINGS_COORDINATOR_TRUE); { // Configure the RFM22B device const struct pios_board_info *bdinfo = &pios_board_info_blob; @@ -265,10 +266,41 @@ void PIOS_Board_Init(void) } PIOS_COM_ChangeBaud(pios_com_rfm22b_id, comBaud); + /* Set the modem Tx poer level */ + switch (oplinkSettings.MaxRFPower) { + case OPLINKSETTINGS_MAXRFPOWER_125: + PIOS_RFM22B_SetTxPower(pios_rfm22b_id, RFM22_tx_pwr_txpow_0); + break; + case OPLINKSETTINGS_MAXRFPOWER_16: + PIOS_RFM22B_SetTxPower(pios_rfm22b_id, RFM22_tx_pwr_txpow_1); + break; + case OPLINKSETTINGS_MAXRFPOWER_316: + PIOS_RFM22B_SetTxPower(pios_rfm22b_id, RFM22_tx_pwr_txpow_2); + break; + case OPLINKSETTINGS_MAXRFPOWER_63: + PIOS_RFM22B_SetTxPower(pios_rfm22b_id, RFM22_tx_pwr_txpow_3); + break; + case OPLINKSETTINGS_MAXRFPOWER_126: + PIOS_RFM22B_SetTxPower(pios_rfm22b_id, RFM22_tx_pwr_txpow_4); + break; + case OPLINKSETTINGS_MAXRFPOWER_25: + PIOS_RFM22B_SetTxPower(pios_rfm22b_id, RFM22_tx_pwr_txpow_5); + break; + case OPLINKSETTINGS_MAXRFPOWER_50: + PIOS_RFM22B_SetTxPower(pios_rfm22b_id, RFM22_tx_pwr_txpow_6); + break; + case OPLINKSETTINGS_MAXRFPOWER_100: + PIOS_RFM22B_SetTxPower(pios_rfm22b_id, RFM22_tx_pwr_txpow_7); + break; + default: + // do nothing + break; + } + // Set the radio configuration parameters. PIOS_RFM22B_SetChannelConfig(pios_rfm22b_id, oplinkSettings.NumChannels, oplinkSettings.MinChannel, oplinkSettings.MaxChannel, oplinkSettings.ChannelSet, oplinkSettings.PacketTime, (oplinkSettings.OneWayLink == OPLINKSETTINGS_ONEWAYLINK_TRUE)); - PIOS_RFM22B_SetCoordinator(pios_rfm22b_id, (oplinkSettings.Coordinator == OPLINKSETTINGS_COORDINATOR_TRUE)); + PIOS_RFM22B_SetCoordinator(pios_rfm22b_id, is_coordinator); PIOS_RFM22B_SetCoordinatorID(pios_rfm22b_id, oplinkSettings.CoordID); // Reinitilize the modem to affect te changes. @@ -281,7 +313,6 @@ void PIOS_Board_Init(void) pios_uart_tx_buffer = (uint8_t *)pvPortMalloc(PIOS_COM_TELEM_TX_BUF_LEN); // Configure the main port - bool is_coordinator = PIOS_RFM22B_IsCoordinator(pios_rfm22b_id); switch (oplinkSettings.MainPort) { case OPLINKSETTINGS_MAINPORT_TELEMETRY: case OPLINKSETTINGS_MAINPORT_SERIAL: diff --git a/flight/targets/boards/oplinkmini/pios_board.h b/flight/targets/boards/oplinkmini/pios_board.h index 9d2ae2b6e..bfb69dab9 100644 --- a/flight/targets/boards/oplinkmini/pios_board.h +++ b/flight/targets/boards/oplinkmini/pios_board.h @@ -75,7 +75,8 @@ #define PIOS_WDG_TELEMETRYRX 0x0002 #define PIOS_WDG_RADIOTX 0x0004 #define PIOS_WDG_RADIORX 0x0008 -#define PIOS_WDG_RFM22B 0x0016 +#define PIOS_WDG_RFM22B 0x000f +#define PIOS_WDG_PPMINPUT 0x0010 // ------------------------ // TELEMETRY diff --git a/flight/targets/boards/osd/firmware/inc/pios_config.h b/flight/targets/boards/osd/firmware/inc/pios_config.h index f4fbdf4be..a6400957f 100644 --- a/flight/targets/boards/osd/firmware/inc/pios_config.h +++ b/flight/targets/boards/osd/firmware/inc/pios_config.h @@ -117,7 +117,6 @@ /* PIOS radio modules */ /* #define PIOS_INCLUDE_RFM22B */ /* #define PIOS_INCLUDE_RFM22B_COM */ -/* #define PIOS_INCLUDE_RFM22B_RCVR */ /* #define PIOS_INCLUDE_PPM_OUT */ /* #define PIOS_RFM22B_DEBUG_ON_TELEM */ diff --git a/flight/targets/boards/revolution/firmware/UAVObjects.inc b/flight/targets/boards/revolution/firmware/UAVObjects.inc index a8f47f8ba..3c8fcc238 100644 --- a/flight/targets/boards/revolution/firmware/UAVObjects.inc +++ b/flight/targets/boards/revolution/firmware/UAVObjects.inc @@ -59,6 +59,7 @@ UAVOBJSRCFILENAMES += mixersettings UAVOBJSRCFILENAMES += mixerstatus UAVOBJSRCFILENAMES += nedaccel UAVOBJSRCFILENAMES += objectpersistence +UAVOBJSRCFILENAMES += oplinkreceiver UAVOBJSRCFILENAMES += overosyncstats UAVOBJSRCFILENAMES += overosyncsettings UAVOBJSRCFILENAMES += pathaction diff --git a/flight/targets/boards/revolution/firmware/inc/pios_config.h b/flight/targets/boards/revolution/firmware/inc/pios_config.h index 7ef8dc475..528ae6278 100644 --- a/flight/targets/boards/revolution/firmware/inc/pios_config.h +++ b/flight/targets/boards/revolution/firmware/inc/pios_config.h @@ -116,7 +116,6 @@ /* PIOS radio modules */ #define PIOS_INCLUDE_RFM22B #define PIOS_INCLUDE_RFM22B_COM -#define PIOS_INCLUDE_RFM22B_RCVR /* #define PIOS_INCLUDE_PPM_OUT */ #define PIOS_RFM22B_DEBUG_ON_TELEM diff --git a/flight/targets/boards/revolution/firmware/pios_board.c b/flight/targets/boards/revolution/firmware/pios_board.c index 855d9a849..89d675e24 100644 --- a/flight/targets/boards/revolution/firmware/pios_board.c +++ b/flight/targets/boards/revolution/firmware/pios_board.c @@ -32,6 +32,8 @@ #include #include #include +#include +#include #include /* @@ -787,16 +789,6 @@ void PIOS_Board_Init(void) /* Reinitialize the modem. */ PIOS_RFM22B_Reinit(pios_rfm22b_id); -#ifdef PIOS_INCLUDE_RFM22B_RCVR - if (PIOS_RFM22B_RCVR_Init(pios_rfm22b_id) != 0) { - PIOS_Assert(0); - } - uint32_t pios_rfm22b_rcvr_id; - if (PIOS_RCVR_Init(&pios_rfm22b_rcvr_id, &pios_rfm22b_rcvr_driver, pios_rfm22b_id)) { - PIOS_Assert(0); - } - pios_rcvr_group_map[MANUALCONTROLSETTINGS_CHANNELGROUPS_OPLINK] = pios_rfm22b_rcvr_id; -#endif break; } } @@ -858,6 +850,19 @@ void PIOS_Board_Init(void) pios_rcvr_group_map[MANUALCONTROLSETTINGS_CHANNELGROUPS_GCS] = pios_gcsrcvr_rcvr_id; #endif /* PIOS_INCLUDE_GCSRCVR */ +#if defined(PIOS_INCLUDE_OPLINKRCVR) + { + OPLinkReceiverInitialize(); + uint32_t pios_oplinkrcvr_id; + PIOS_OPLinkRCVR_Init(&pios_oplinkrcvr_id); + uint32_t pios_oplinkrcvr_rcvr_id; + if (PIOS_RCVR_Init(&pios_oplinkrcvr_rcvr_id, &pios_oplinkrcvr_rcvr_driver, pios_oplinkrcvr_id)) { + PIOS_Assert(0); + } + pios_rcvr_group_map[MANUALCONTROLSETTINGS_CHANNELGROUPS_OPLINK] = pios_oplinkrcvr_rcvr_id; + } +#endif /* PIOS_INCLUDE_OPLINKRCVR */ + #ifndef PIOS_ENABLE_DEBUG_PINS // pios_servo_cfg points to the correct configuration based on input port settings PIOS_Servo_Init(pios_servo_cfg); diff --git a/flight/targets/boards/revoproto/firmware/inc/pios_config.h b/flight/targets/boards/revoproto/firmware/inc/pios_config.h index 8c5268885..a4c2042df 100644 --- a/flight/targets/boards/revoproto/firmware/inc/pios_config.h +++ b/flight/targets/boards/revoproto/firmware/inc/pios_config.h @@ -116,7 +116,6 @@ /* PIOS radio modules */ /* #define PIOS_INCLUDE_RFM22B */ /* #define PIOS_INCLUDE_RFM22B_COM */ -/* #define PIOS_INCLUDE_RFM22B_RCVR */ /* #define PIOS_INCLUDE_PPM_OUT */ /* #define PIOS_RFM22B_DEBUG_ON_TELEM */ diff --git a/make/apps-defs.mk b/make/apps-defs.mk index dd7c3dc77..bfbb66c2a 100644 --- a/make/apps-defs.mk +++ b/make/apps-defs.mk @@ -84,7 +84,6 @@ SRC += $(PIOSCOMMON)/pios_flash_jedec.c SRC += $(PIOSCOMMON)/pios_rcvr.c SRC += $(PIOSCOMMON)/pios_rfm22b.c SRC += $(PIOSCOMMON)/pios_rfm22b_com.c -SRC += $(PIOSCOMMON)/pios_rfm22b_rcvr.c SRC += $(PIOSCOMMON)/pios_sbus.c SRC += $(PIOSCOMMON)/pios_sdcard.c diff --git a/shared/uavobjectdefinition/oplinksettings.xml b/shared/uavobjectdefinition/oplinksettings.xml index e0969e9dd..08c116ba1 100644 --- a/shared/uavobjectdefinition/oplinksettings.xml +++ b/shared/uavobjectdefinition/oplinksettings.xml @@ -13,7 +13,7 @@ - +