From 8fa79377c329068325f9ea64bf1f6de45f300954 Mon Sep 17 00:00:00 2001 From: Werner Backes Date: Tue, 30 Apr 2013 11:08:14 +0200 Subject: [PATCH 1/7] Lowered rfm22b_rcvr supervisor timeout. Timeout values above 159 exceed uint8_t range during timeout calculation and effectively disable the supervisor. --- flight/targets/boards/revolution/pios_board.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flight/targets/boards/revolution/pios_board.h b/flight/targets/boards/revolution/pios_board.h index f58ace784..d7fed3b47 100644 --- a/flight/targets/boards/revolution/pios_board.h +++ b/flight/targets/boards/revolution/pios_board.h @@ -228,7 +228,7 @@ extern uint32_t pios_packet_handler; #define PIOS_RCVR_MAX_DEVS 3 #define PIOS_RCVR_MAX_CHANNELS 12 #define PIOS_GCSRCVR_TIMEOUT_MS 100 -#define PIOS_RFM22B_RCVR_TIMEOUT_MS 200 +#define PIOS_RFM22B_RCVR_TIMEOUT_MS 150 //------------------------- // Receiver PPM input From b48665e59b2eb5bff36670e60e4fa63e3c404f82 Mon Sep 17 00:00:00 2001 From: Werner Backes Date: Tue, 30 Apr 2013 11:24:43 +0200 Subject: [PATCH 2/7] rfm22b receiver supervisor now properly indicates a timeout condition. This allows upper layers to recognize control signal loss. --- flight/pios/common/pios_rfm22b_rcvr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flight/pios/common/pios_rfm22b_rcvr.c b/flight/pios/common/pios_rfm22b_rcvr.c index faa21b604..3ea942103 100644 --- a/flight/pios/common/pios_rfm22b_rcvr.c +++ b/flight/pios/common/pios_rfm22b_rcvr.c @@ -110,7 +110,7 @@ static void PIOS_RFM22B_RCVR_Supervisor(uint32_t rcvr_id) { // 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] = 0; + rfm22b_dev->ppm_channel[i] = PIOS_RCVR_TIMEOUT; } } rfm22b_dev->ppm_fresh = false; From 84e1a81f8bacb2b5565bb3d381b2cd883dff1eff Mon Sep 17 00:00:00 2001 From: "Richard Flay (Hyper)" Date: Fri, 3 May 2013 07:01:14 +0930 Subject: [PATCH 3/7] OP-936: Moves the task monitor code out of the flight library and into PiOS. This move and rework also breaks the dependency of the task monitor on the UAVO subsystem, and pushes the responsibility for updating the TaskInfo UAVO into the System module. +review OPReview --- flight/libraries/inc/taskmonitor.h | 44 ----- flight/libraries/sanitycheck.c | 10 +- flight/libraries/taskmonitor.c | 159 ------------------ flight/modules/Actuator/actuator.c | 6 +- flight/modules/Airspeed/revolution/airspeed.c | 6 +- flight/modules/Altitude/altitude.c | 6 +- flight/modules/Altitude/revolution/altitude.c | 6 +- flight/modules/AltitudeHold/altitudehold.c | 7 +- flight/modules/Attitude/attitude.c | 15 +- flight/modules/Attitude/revolution/attitude.c | 9 +- flight/modules/Autotune/autotune.c | 6 +- flight/modules/ComUsbBridge/ComUsbBridge.c | 8 +- flight/modules/Extensions/MagBaro/magbaro.c | 6 +- flight/modules/FirmwareIAP/firmwareiap.c | 6 +- .../fixedwingpathfollower.c | 11 +- flight/modules/FlightPlan/flightplan.c | 13 +- flight/modules/GPS/GPS.c | 12 +- flight/modules/ManualControl/manualcontrol.c | 6 +- flight/modules/OPLink/oplinkmod.c | 7 +- flight/modules/Osd/osdgen/osdgen.c | 7 +- flight/modules/Osd/osdinput/osdinput.c | 8 +- flight/modules/OveroSync/overosync.c | 9 +- .../modules/OveroSync/simulated/overosync.c | 7 +- flight/modules/PathPlanner/pathplanner.c | 7 +- flight/modules/Sensors/sensors.c | 5 +- flight/modules/Sensors/simulated/sensors.c | 7 +- flight/modules/Stabilization/stabilization.c | 6 +- flight/modules/System/systemmod.c | 27 ++- flight/modules/Telemetry/telemetry.c | 11 +- .../VtolPathFollower/vtolpathfollower.c | 10 +- flight/pios/common/pios_flashfs_logfs.c | 1 - flight/pios/common/pios_task_monitor.c | 144 ++++++++++++++++ flight/pios/inc/pios_task_monitor.h | 107 ++++++++++++ flight/pios/pios.h | 9 + flight/pios/pios_sim_posix.h | 7 + .../STM32_USB_OTG_Driver/inc/usb_defines.h | 2 + flight/pios/stm32f4xx/pios_usb_hid.c | 3 - .../coptercontrol/firmware/inc/openpilot.h | 1 - .../coptercontrol/firmware/inc/pios_config.h | 1 + .../firmware/inc/pios_config_posix.h | 1 + .../coptercontrol/firmware/pios_board.c | 7 +- .../coptercontrol/firmware/pios_board_posix.c | 6 +- .../oplinkmini/firmware/inc/openpilot.h | 1 - .../oplinkmini/firmware/inc/pios_config.h | 1 + .../firmware/inc/pios_config_posix.h | 1 + .../boards/oplinkmini/firmware/pios_board.c | 7 +- .../oplinkmini/firmware/pios_board_posix.c | 6 +- .../boards/osd/firmware/inc/openpilot.h | 1 - .../boards/osd/firmware/inc/pios_config.h | 1 + .../targets/boards/osd/firmware/pios_board.c | 7 +- .../boards/revolution/firmware/Makefile.osx | 1 - .../revolution/firmware/inc/openpilot.h | 1 - .../revolution/firmware/inc/pios_config.h | 1 + .../revolution/firmware/inc/pios_config_sim.h | 1 + .../boards/revolution/firmware/pios_board.c | 7 +- .../revolution/firmware/pios_board_sim.c | 6 +- .../boards/revoproto/firmware/Makefile.osx | 1 - .../boards/revoproto/firmware/inc/openpilot.h | 1 - .../revoproto/firmware/inc/pios_config.h | 1 + .../revoproto/firmware/inc/pios_config_sim.h | 1 + .../boards/revoproto/firmware/pios_board.c | 7 +- .../revoproto/firmware/pios_board_sim.c | 6 +- .../targets/boards/simposix/firmware/Makefile | 4 +- .../boards/simposix/firmware/inc/openpilot.h | 1 - .../simposix/firmware/inc/pios_config.h | 1 + .../boards/simposix/firmware/pios_board.c | 7 +- flight/uavobjects/eventdispatcher.c | 6 +- make/apps-defs.mk | 4 +- 68 files changed, 493 insertions(+), 325 deletions(-) delete mode 100644 flight/libraries/inc/taskmonitor.h delete mode 100644 flight/libraries/taskmonitor.c create mode 100644 flight/pios/common/pios_task_monitor.c create mode 100644 flight/pios/inc/pios_task_monitor.h diff --git a/flight/libraries/inc/taskmonitor.h b/flight/libraries/inc/taskmonitor.h deleted file mode 100644 index 73987f2b1..000000000 --- a/flight/libraries/inc/taskmonitor.h +++ /dev/null @@ -1,44 +0,0 @@ -/** - ****************************************************************************** - * @addtogroup OpenPilotSystem OpenPilot System - * @{ - * @addtogroup OpenPilotLibraries OpenPilot System Libraries - * @{ - * @file taskmonitor.h - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * @brief Include file of the task monitoring library - * @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 TASKMONITOR_H -#define TASKMONITOR_H - -#include "taskinfo.h" - -int32_t TaskMonitorInitialize(void); -int32_t TaskMonitorAdd(TaskInfoRunningElem task, xTaskHandle handle); -int32_t TaskMonitorRemove(TaskInfoRunningElem task); -bool TaskMonitorQueryRunning(TaskInfoRunningElem task); -void TaskMonitorUpdateAll(void); - -#endif // TASKMONITOR_H - -/** - * @} - * @} - */ diff --git a/flight/libraries/sanitycheck.c b/flight/libraries/sanitycheck.c index 75c1fd6b2..e0aaa362c 100644 --- a/flight/libraries/sanitycheck.c +++ b/flight/libraries/sanitycheck.c @@ -30,12 +30,12 @@ #include // Private includes -#include "inc/taskmonitor.h" #include "inc/sanitycheck.h" // UAVOs #include #include +#include /**************************** * Current checks: @@ -103,28 +103,28 @@ int32_t configuration_check() severity = (severity == SYSTEMALARMS_ALARM_OK) ? check_stabilization_settings(3, multirotor) : severity; break; case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_AUTOTUNE: - if (!TaskMonitorQueryRunning(TASKINFO_RUNNING_AUTOTUNE)) { + if (!PIOS_TASK_MONITOR_IsRunning(TASKINFO_RUNNING_AUTOTUNE)) { severity = SYSTEMALARMS_ALARM_ERROR; } break; case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_ALTITUDEHOLD: if (coptercontrol) { severity = SYSTEMALARMS_ALARM_ERROR; - } else if (!TaskMonitorQueryRunning(TASKINFO_RUNNING_ALTITUDEHOLD)) { // Revo supports altitude hold + } else if (!PIOS_TASK_MONITOR_IsRunning(TASKINFO_RUNNING_ALTITUDEHOLD)) { // Revo supports altitude hold severity = SYSTEMALARMS_ALARM_ERROR; } break; case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_VELOCITYCONTROL: if (coptercontrol) { severity = SYSTEMALARMS_ALARM_ERROR; - } else if (!TaskMonitorQueryRunning(TASKINFO_RUNNING_PATHFOLLOWER)) { // Revo supports altitude hold + } else if (!PIOS_TASK_MONITOR_IsRunning(TASKINFO_RUNNING_PATHFOLLOWER)) { // Revo supports altitude hold severity = SYSTEMALARMS_ALARM_ERROR; } break; case MANUALCONTROLSETTINGS_FLIGHTMODEPOSITION_POSITIONHOLD: if (coptercontrol){ severity = SYSTEMALARMS_ALARM_ERROR; - } else if (!TaskMonitorQueryRunning(TASKINFO_RUNNING_PATHFOLLOWER)) { // Revo supports altitude hold + } else if (!PIOS_TASK_MONITOR_IsRunning(TASKINFO_RUNNING_PATHFOLLOWER)) { // Revo supports altitude hold severity = SYSTEMALARMS_ALARM_ERROR; } break; diff --git a/flight/libraries/taskmonitor.c b/flight/libraries/taskmonitor.c deleted file mode 100644 index ba9fad228..000000000 --- a/flight/libraries/taskmonitor.c +++ /dev/null @@ -1,159 +0,0 @@ -/** - ****************************************************************************** - * @addtogroup OpenPilotSystem OpenPilot System - * @{ - * @addtogroup OpenPilotLibraries OpenPilot System Libraries - * @{ - * @file taskmonitor.h - * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. - * @brief Task monitoring library - * @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 "openpilot.h" -//#include "taskmonitor.h" - -// Private constants - -// Private types - -// Private variables -static xSemaphoreHandle lock; -static xTaskHandle handles[TASKINFO_RUNNING_NUMELEM]; -static uint32_t lastMonitorTime; - -// Private functions - -/** - * Initialize library - */ -int32_t TaskMonitorInitialize(void) -{ - lock = xSemaphoreCreateRecursiveMutex(); - memset(handles, 0, sizeof(xTaskHandle)*TASKINFO_RUNNING_NUMELEM); - lastMonitorTime = 0; -#ifdef DIAG_TASKS - lastMonitorTime = portGET_RUN_TIME_COUNTER_VALUE(); -#endif - return 0; -} - -/** - * Register a task handle with the library - */ -int32_t TaskMonitorAdd(TaskInfoRunningElem task, xTaskHandle handle) -{ - if (task < TASKINFO_RUNNING_NUMELEM) - { - xSemaphoreTakeRecursive(lock, portMAX_DELAY); - handles[task] = handle; - xSemaphoreGiveRecursive(lock); - return 0; - } - else - { - return -1; - } -} - -/** - * Remove a task handle from the library - */ -int32_t TaskMonitorRemove(TaskInfoRunningElem task) -{ - if (task < TASKINFO_RUNNING_NUMELEM) - { - xSemaphoreTakeRecursive(lock, portMAX_DELAY); - handles[task] = 0; - xSemaphoreGiveRecursive(lock); - return 0; - } - else - { - return -1; - } -} - -/** - * Query if a task is running - */ -bool TaskMonitorQueryRunning(TaskInfoRunningElem task) -{ - if (task < TASKINFO_RUNNING_NUMELEM && handles[task] != 0) - return true; - return false; -} - -/** - * Update the status of all tasks - */ -void TaskMonitorUpdateAll(void) -{ -#ifdef DIAG_TASKS - TaskInfoData data; - int n; - - // Lock - xSemaphoreTakeRecursive(lock, portMAX_DELAY); - -#if ( configGENERATE_RUN_TIME_STATS == 1 ) - uint32_t currentTime; - uint32_t deltaTime; - - /* - * Calculate the amount of elapsed run time between the last time we - * measured and now. Scale so that we can convert task run times - * directly to percentages. - */ - currentTime = portGET_RUN_TIME_COUNTER_VALUE(); - deltaTime = ((currentTime - lastMonitorTime) / 100) ? : 1; /* avoid divide-by-zero if the interval is too small */ - lastMonitorTime = currentTime; -#endif - - // Update all task information - for (n = 0; n < TASKINFO_RUNNING_NUMELEM; ++n) - { - if (handles[n] != 0) - { - data.Running[n] = TASKINFO_RUNNING_TRUE; -#if defined(ARCH_POSIX) || defined(ARCH_WIN32) - data.StackRemaining[n] = 10000; -#else - data.StackRemaining[n] = uxTaskGetStackHighWaterMark(handles[n]) * 4; -#endif -#if ( configGENERATE_RUN_TIME_STATS == 1 ) - /* Generate run time stats */ - data.RunningTime[n] = uxTaskGetRunTime(handles[n]) / deltaTime; -#endif - - } - else - { - data.Running[n] = TASKINFO_RUNNING_FALSE; - data.StackRemaining[n] = 0; - data.RunningTime[n] = 0; - } - } - - // Update object - TaskInfoSet(&data); - - // Done - xSemaphoreGiveRecursive(lock); -#endif -} diff --git a/flight/modules/Actuator/actuator.c b/flight/modules/Actuator/actuator.c index 4ceba8bfb..12e250392 100644 --- a/flight/modules/Actuator/actuator.c +++ b/flight/modules/Actuator/actuator.c @@ -31,7 +31,8 @@ */ -#include "openpilot.h" +#include + #include "accessorydesired.h" #include "actuator.h" #include "actuatorsettings.h" @@ -43,6 +44,7 @@ #include "mixerstatus.h" #include "cameradesired.h" #include "manualcontrolcommand.h" +#include "taskinfo.h" // Private constants #define MAX_QUEUE_SIZE 2 @@ -100,7 +102,7 @@ int32_t ActuatorStart() { // Start main task xTaskCreate(actuatorTask, (signed char*)"Actuator", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &taskHandle); - TaskMonitorAdd(TASKINFO_RUNNING_ACTUATOR, taskHandle); + PIOS_TASK_MONITOR_RegisterTask(TASKINFO_RUNNING_ACTUATOR, taskHandle); PIOS_WDG_RegisterFlag(PIOS_WDG_ACTUATOR); return 0; diff --git a/flight/modules/Airspeed/revolution/airspeed.c b/flight/modules/Airspeed/revolution/airspeed.c index fd1479d0f..8b37eee6f 100644 --- a/flight/modules/Airspeed/revolution/airspeed.c +++ b/flight/modules/Airspeed/revolution/airspeed.c @@ -36,12 +36,14 @@ * */ -#include "openpilot.h" +#include + #include "hwsettings.h" #include "airspeedsettings.h" #include "airspeedsensor.h" // object that will be updated by the module #include "baro_airspeed_etasv3.h" #include "baro_airspeed_mpxv.h" +#include "taskinfo.h" // Private constants @@ -79,7 +81,7 @@ int32_t AirspeedStart() // Start main task xTaskCreate(airspeedTask, (signed char *)"Airspeed", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &taskHandle); - TaskMonitorAdd(TASKINFO_RUNNING_AIRSPEED, taskHandle); + PIOS_TASK_MONITOR_RegisterTask(TASKINFO_RUNNING_AIRSPEED, taskHandle); return 0; } diff --git a/flight/modules/Altitude/altitude.c b/flight/modules/Altitude/altitude.c index 4e11848e7..55e14c222 100644 --- a/flight/modules/Altitude/altitude.c +++ b/flight/modules/Altitude/altitude.c @@ -36,13 +36,15 @@ * */ -#include "openpilot.h" +#include + #include "hwsettings.h" #include "altitude.h" #include "baroaltitude.h" // object that will be updated by the module #if defined(PIOS_INCLUDE_HCSR04) #include "sonaraltitude.h" // object that will be updated by the module #endif +#include "taskinfo.h" // Private constants #define STACK_SIZE_BYTES 500 @@ -80,7 +82,7 @@ int32_t AltitudeStart() // Start main task xTaskCreate(altitudeTask, (signed char *)"Altitude", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &taskHandle); - TaskMonitorAdd(TASKINFO_RUNNING_ALTITUDE, taskHandle); + PIOS_TASK_MONITOR_RegisterTask(TASKINFO_RUNNING_ALTITUDE, taskHandle); return 0; } return -1; diff --git a/flight/modules/Altitude/revolution/altitude.c b/flight/modules/Altitude/revolution/altitude.c index 54b241408..a1c07a5c2 100644 --- a/flight/modules/Altitude/revolution/altitude.c +++ b/flight/modules/Altitude/revolution/altitude.c @@ -36,12 +36,14 @@ * */ -#include "openpilot.h" +#include + #include "altitude.h" #include "baroaltitude.h" // object that will be updated by the module #if defined(PIOS_INCLUDE_HCSR04) #include "sonaraltitude.h" // object that will be updated by the module #endif +#include "taskinfo.h" // Private constants #define STACK_SIZE_BYTES 500 @@ -67,7 +69,7 @@ int32_t AltitudeStart() // Start main task xTaskCreate(altitudeTask, (signed char *)"Altitude", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &taskHandle); - TaskMonitorAdd(TASKINFO_RUNNING_ALTITUDE, taskHandle); + PIOS_TASK_MONITOR_RegisterTask(TASKINFO_RUNNING_ALTITUDE, taskHandle); return 0; } diff --git a/flight/modules/AltitudeHold/altitudehold.c b/flight/modules/AltitudeHold/altitudehold.c index 69c617d46..8be26162d 100644 --- a/flight/modules/AltitudeHold/altitudehold.c +++ b/flight/modules/AltitudeHold/altitudehold.c @@ -43,8 +43,8 @@ * */ -#include "openpilot.h" -#include +#include + #include "CoordinateConversions.h" #include "altholdsmoothed.h" #include "attitudeactual.h" @@ -55,6 +55,7 @@ #include "flightstatus.h" #include "stabilizationdesired.h" #include "accels.h" +#include "taskinfo.h" // Private constants #define MAX_QUEUE_SIZE 2 @@ -80,7 +81,7 @@ int32_t AltitudeHoldStart() { // Start main task xTaskCreate(altitudeHoldTask, (signed char *)"AltitudeHold", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &altitudeHoldTaskHandle); - TaskMonitorAdd(TASKINFO_RUNNING_ALTITUDEHOLD, altitudeHoldTaskHandle); + PIOS_TASK_MONITOR_RegisterTask(TASKINFO_RUNNING_ALTITUDEHOLD, altitudeHoldTaskHandle); return 0; } diff --git a/flight/modules/Attitude/attitude.c b/flight/modules/Attitude/attitude.c index 7d4a01b6c..c5d24c54a 100644 --- a/flight/modules/Attitude/attitude.c +++ b/flight/modules/Attitude/attitude.c @@ -48,7 +48,10 @@ * */ -#include "pios.h" +#include + +#include + #include "attitude.h" #include "gyros.h" #include "accels.h" @@ -56,11 +59,11 @@ #include "attitudesettings.h" #include "flightstatus.h" #include "manualcontrolcommand.h" -#include "CoordinateConversions.h" -#include -#include +#include "taskinfo.h" + +#include "CoordinateConversions.h" + - // Private constants #define STACK_SIZE_BYTES 540 #define TASK_PRIORITY (tskIDLE_PRIORITY+3) @@ -119,7 +122,7 @@ int32_t AttitudeStart(void) // Start main task xTaskCreate(AttitudeTask, (signed char *)"Attitude", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &taskHandle); - TaskMonitorAdd(TASKINFO_RUNNING_ATTITUDE, taskHandle); + PIOS_TASK_MONITOR_RegisterTask(TASKINFO_RUNNING_ATTITUDE, taskHandle); PIOS_WDG_RegisterFlag(PIOS_WDG_ATTITUDE); return 0; diff --git a/flight/modules/Attitude/revolution/attitude.c b/flight/modules/Attitude/revolution/attitude.c index ec8efa503..30d74321a 100644 --- a/flight/modules/Attitude/revolution/attitude.c +++ b/flight/modules/Attitude/revolution/attitude.c @@ -48,10 +48,9 @@ * */ -#include "pios.h" +#include #include "attitude.h" - #include "accels.h" #include "airspeedsensor.h" #include "airspeedactual.h" @@ -69,8 +68,10 @@ #include "revocalibration.h" #include "revosettings.h" #include "velocityactual.h" +#include "taskinfo.h" + #include "CoordinateConversions.h" -#include + // Private constants #define STACK_SIZE_BYTES 2048 #define TASK_PRIORITY (tskIDLE_PRIORITY+3) @@ -184,7 +185,7 @@ int32_t AttitudeStart(void) // Start main task xTaskCreate(AttitudeTask, (signed char *)"Attitude", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &attitudeTaskHandle); - TaskMonitorAdd(TASKINFO_RUNNING_ATTITUDE, attitudeTaskHandle); + PIOS_TASK_MONITOR_RegisterTask(TASKINFO_RUNNING_ATTITUDE, attitudeTaskHandle); PIOS_WDG_RegisterFlag(PIOS_WDG_ATTITUDE); GyrosConnectQueue(gyroQueue); diff --git a/flight/modules/Autotune/autotune.c b/flight/modules/Autotune/autotune.c index 260f70750..170731d71 100644 --- a/flight/modules/Autotune/autotune.c +++ b/flight/modules/Autotune/autotune.c @@ -48,7 +48,7 @@ * */ -#include "openpilot.h" +#include #include "flightstatus.h" #include "hwsettings.h" @@ -58,7 +58,7 @@ #include "relaytuningsettings.h" #include "stabilizationdesired.h" #include "stabilizationsettings.h" -#include +#include "taskinfo.h" // Private constants #define STACK_SIZE_BYTES 1024 @@ -109,7 +109,7 @@ int32_t AutotuneStart(void) if(autotuneEnabled) { xTaskCreate(AutotuneTask, (signed char *)"Autotune", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &taskHandle); - TaskMonitorAdd(TASKINFO_RUNNING_AUTOTUNE, taskHandle); + PIOS_TASK_MONITOR_RegisterTask(TASKINFO_RUNNING_AUTOTUNE, taskHandle); PIOS_WDG_RegisterFlag(PIOS_WDG_AUTOTUNE); } return 0; diff --git a/flight/modules/ComUsbBridge/ComUsbBridge.c b/flight/modules/ComUsbBridge/ComUsbBridge.c index 13c9f6ee4..0258b8089 100644 --- a/flight/modules/ComUsbBridge/ComUsbBridge.c +++ b/flight/modules/ComUsbBridge/ComUsbBridge.c @@ -30,8 +30,10 @@ // **************** -#include "openpilot.h" +#include + #include "hwsettings.h" +#include "taskinfo.h" #include @@ -75,9 +77,9 @@ static int32_t comUsbBridgeStart(void) if (bridge_enabled) { // Start tasks xTaskCreate(com2UsbBridgeTask, (signed char *)"Com2UsbBridge", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &com2UsbBridgeTaskHandle); - TaskMonitorAdd(TASKINFO_RUNNING_COM2USBBRIDGE, com2UsbBridgeTaskHandle); + PIOS_TASK_MONITOR_RegisterTask(TASKINFO_RUNNING_COM2USBBRIDGE, com2UsbBridgeTaskHandle); xTaskCreate(usb2ComBridgeTask, (signed char *)"Usb2ComBridge", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &usb2ComBridgeTaskHandle); - TaskMonitorAdd(TASKINFO_RUNNING_USB2COMBRIDGE, usb2ComBridgeTaskHandle); + PIOS_TASK_MONITOR_RegisterTask(TASKINFO_RUNNING_USB2COMBRIDGE, usb2ComBridgeTaskHandle); return 0; } diff --git a/flight/modules/Extensions/MagBaro/magbaro.c b/flight/modules/Extensions/MagBaro/magbaro.c index fbd6cc92e..5fa0d5a51 100644 --- a/flight/modules/Extensions/MagBaro/magbaro.c +++ b/flight/modules/Extensions/MagBaro/magbaro.c @@ -36,11 +36,13 @@ * */ -#include "openpilot.h" +#include + #include "hwsettings.h" #include "magbaro.h" #include "baroaltitude.h" // object that will be updated by the module #include "magnetometer.h" +#include "taskinfo.h" // Private constants #define STACK_SIZE_BYTES 620 @@ -75,7 +77,7 @@ int32_t MagBaroStart() if (magbaroEnabled) { // Start main task xTaskCreate(magbaroTask, (signed char *)"MagBaro", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &taskHandle); - //TaskMonitorAdd(TASKINFO_RUNNING_MAGBARO, taskHandle); + //PIOS_TASK_MONITOR_RegisterTask(TASKINFO_RUNNING_MAGBARO, taskHandle); return 0; } return -1; diff --git a/flight/modules/FirmwareIAP/firmwareiap.c b/flight/modules/FirmwareIAP/firmwareiap.c index f8e6fd231..506b8c62b 100644 --- a/flight/modules/FirmwareIAP/firmwareiap.c +++ b/flight/modules/FirmwareIAP/firmwareiap.c @@ -24,11 +24,11 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include -#include "pios.h" +#include + #include -#include "openpilot.h" + #include "firmwareiap.h" #include "firmwareiapobj.h" #include "flightstatus.h" diff --git a/flight/modules/FixedWingPathFollower/fixedwingpathfollower.c b/flight/modules/FixedWingPathFollower/fixedwingpathfollower.c index 1624d5246..dd35b0747 100644 --- a/flight/modules/FixedWingPathFollower/fixedwingpathfollower.c +++ b/flight/modules/FixedWingPathFollower/fixedwingpathfollower.c @@ -43,8 +43,7 @@ * */ -#include "openpilot.h" -#include "paths.h" +#include #include "accels.h" #include "hwsettings.h" @@ -65,9 +64,11 @@ #include "systemsettings.h" #include "velocitydesired.h" #include "velocityactual.h" +#include "taskinfo.h" + +#include "paths.h" #include "CoordinateConversions.h" -#include -#include + // Private constants #define MAX_QUEUE_SIZE 4 #define STACK_SIZE_BYTES 1548 @@ -98,7 +99,7 @@ int32_t FixedWingPathFollowerStart() if (followerEnabled) { // Start main task xTaskCreate(pathfollowerTask, (signed char *)"PathFollower", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &pathfollowerTaskHandle); - TaskMonitorAdd(TASKINFO_RUNNING_PATHFOLLOWER, pathfollowerTaskHandle); + PIOS_TASK_MONITOR_RegisterTask(TASKINFO_RUNNING_PATHFOLLOWER, pathfollowerTaskHandle); } return 0; diff --git a/flight/modules/FlightPlan/flightplan.c b/flight/modules/FlightPlan/flightplan.c index e919dd41e..d93c93671 100644 --- a/flight/modules/FlightPlan/flightplan.c +++ b/flight/modules/FlightPlan/flightplan.c @@ -29,12 +29,15 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "openpilot.h" -#include "pm.h" +#include + #include "flightplan.h" #include "flightplanstatus.h" #include "flightplancontrol.h" #include "flightplansettings.h" +#include "taskinfo.h" + +#include "pm.h" // Private constants #define STACK_SIZE_BYTES 1500 @@ -63,7 +66,7 @@ int32_t FlightPlanStart() // Start VM thread xTaskCreate(flightPlanTask, (signed char *)"FlightPlan", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &taskHandle); - TaskMonitorAdd(TASKINFO_RUNNING_FLIGHTPLAN, taskHandle); + PIOS_TASK_MONITOR_RegisterTask(TASKINFO_RUNNING_FLIGHTPLAN, taskHandle); return 0; } @@ -258,7 +261,7 @@ static void objectUpdatedCb(UAVObjEvent * ev) if ( taskHandle == NULL ) { xTaskCreate(flightPlanTask, (signed char *)"FlightPlan", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &taskHandle); - TaskMonitorAdd(TASKINFO_RUNNING_FLIGHTPLAN, taskHandle); + PIOS_TASK_MONITOR_RegisterTask(TASKINFO_RUNNING_FLIGHTPLAN, taskHandle); } } else if ( controlData.Command == FLIGHTPLANCONTROL_COMMAND_KILL ) @@ -268,7 +271,7 @@ static void objectUpdatedCb(UAVObjEvent * ev) if ( taskHandle != NULL ) { // Kill VM - TaskMonitorRemove(TASKINFO_RUNNING_FLIGHTPLAN); + PIOS_TASK_MONITOR_UnregisterTask(TASKINFO_RUNNING_FLIGHTPLAN); vTaskDelete(taskHandle); taskHandle = NULL; // Update status object diff --git a/flight/modules/GPS/GPS.c b/flight/modules/GPS/GPS.c index c9a2422fd..3ebed004c 100644 --- a/flight/modules/GPS/GPS.c +++ b/flight/modules/GPS/GPS.c @@ -30,8 +30,7 @@ // **************** -#include "openpilot.h" -#include "GPS.h" +#include #include "gpsposition.h" #include "homelocation.h" @@ -39,10 +38,13 @@ #include "gpssatellites.h" #include "gpsvelocity.h" #include "systemsettings.h" -#include "WorldMagModel.h" -#include "CoordinateConversions.h" +#include "taskinfo.h" #include "hwsettings.h" +#include "WorldMagModel.h" +#include "CoordinateConversions.h" + +#include "GPS.h" #include "NMEA.h" #include "UBX.h" @@ -107,7 +109,7 @@ int32_t GPSStart(void) if (gpsPort) { // Start gps task xTaskCreate(gpsTask, (signed char *)"GPS", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &gpsTaskHandle); - TaskMonitorAdd(TASKINFO_RUNNING_GPS, gpsTaskHandle); + PIOS_TASK_MONITOR_RegisterTask(TASKINFO_RUNNING_GPS, gpsTaskHandle); return 0; } diff --git a/flight/modules/ManualControl/manualcontrol.c b/flight/modules/ManualControl/manualcontrol.c index 912d67f73..12c680c94 100644 --- a/flight/modules/ManualControl/manualcontrol.c +++ b/flight/modules/ManualControl/manualcontrol.c @@ -33,7 +33,8 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "openpilot.h" +#include + #include "accessorydesired.h" #include "actuatordesired.h" #include "altitudeholddesired.h" @@ -50,6 +51,7 @@ #include "stabilizationdesired.h" #include "receiveractivity.h" #include "systemsettings.h" +#include "taskinfo.h" #if defined(PIOS_INCLUDE_USB_RCTX) #include "pios_usb_rctx.h" @@ -132,7 +134,7 @@ int32_t ManualControlStart() { // Start main task xTaskCreate(manualControlTask, (signed char *)"ManualControl", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &taskHandle); - TaskMonitorAdd(TASKINFO_RUNNING_MANUALCONTROL, taskHandle); + PIOS_TASK_MONITOR_RegisterTask(TASKINFO_RUNNING_MANUALCONTROL, taskHandle); PIOS_WDG_RegisterFlag(PIOS_WDG_MANUAL); return 0; diff --git a/flight/modules/OPLink/oplinkmod.c b/flight/modules/OPLink/oplinkmod.c index 26be45c62..c201c1c74 100644 --- a/flight/modules/OPLink/oplinkmod.c +++ b/flight/modules/OPLink/oplinkmod.c @@ -39,10 +39,13 @@ */ #include + #include +#include +#include + #include #include -#include // Private constants #define SYSTEM_UPDATE_PERIOD_MS 1000 @@ -79,7 +82,7 @@ int32_t OPLinkModStart(void) // Create oplink system task xTaskCreate(systemTask, (signed char *)"OPLink", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &systemTaskHandle); // Register task - TaskMonitorAdd(TASKINFO_RUNNING_SYSTEM, systemTaskHandle); + PIOS_TASK_MONITOR_RegisterTask(TASKINFO_RUNNING_SYSTEM, systemTaskHandle); return 0; } diff --git a/flight/modules/Osd/osdgen/osdgen.c b/flight/modules/Osd/osdgen/osdgen.c index e46308183..3627023e9 100644 --- a/flight/modules/Osd/osdgen/osdgen.c +++ b/flight/modules/Osd/osdgen/osdgen.c @@ -30,8 +30,10 @@ // **************** -#include "openpilot.h" +#include + #include "osdgen.h" + #include "attitudeactual.h" #include "gpsposition.h" #include "homelocation.h" @@ -39,6 +41,7 @@ #include "gpssatellites.h" #include "osdsettings.h" #include "baroaltitude.h" +#include "taskinfo.h" #include "fonts.h" #include "font12x18.h" @@ -2420,7 +2423,7 @@ int32_t osdgenStart(void) // Start gps task vSemaphoreCreateBinary( osdSemaphore); xTaskCreate(osdgenTask, (signed char *)"OSDGEN", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &osdgenTaskHandle); - //TaskMonitorAdd(TASKINFO_RUNNING_GPS, osdgenTaskHandle); + //PIOS_TASK_MONITOR_RegisterTask(TASKINFO_RUNNING_GPS, osdgenTaskHandle); return 0; } diff --git a/flight/modules/Osd/osdinput/osdinput.c b/flight/modules/Osd/osdinput/osdinput.c index b0a6acd89..ebd7eb904 100644 --- a/flight/modules/Osd/osdinput/osdinput.c +++ b/flight/modules/Osd/osdinput/osdinput.c @@ -30,9 +30,13 @@ // **************** -#include "openpilot.h" +#include + #include "osdinput.h" + #include "attitudeactual.h" +#include "taskinfo.h" + #include "fifo_buffer.h" @@ -85,7 +89,7 @@ int32_t OpOsdStart(void) { // Start gps task xTaskCreate(OpOsdTask, (signed char *)"OSD", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &OpOsdTaskHandle); - //TaskMonitorAdd(TASKINFO_RUNNING_GPS, OpOsdTaskHandle); + //PIOS_TASK_MONITOR_RegisterTask(TASKINFO_RUNNING_GPS, OpOsdTaskHandle); return 0; } diff --git a/flight/modules/OveroSync/overosync.c b/flight/modules/OveroSync/overosync.c index 639082fce..6d4bd5099 100644 --- a/flight/modules/OveroSync/overosync.c +++ b/flight/modules/OveroSync/overosync.c @@ -30,11 +30,14 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "openpilot.h" -#include "hwsettings.h" +#include + #include "overosync.h" + +#include "hwsettings.h" #include "overosyncstats.h" #include "systemstats.h" +#include "taskinfo.h" // Private constants #define MAX_QUEUE_SIZE 200 @@ -128,7 +131,7 @@ int32_t OveroSyncStart(void) // Start overosync tasks xTaskCreate(overoSyncTask, (signed char *)"OveroSync", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &overoSyncTaskHandle); - TaskMonitorAdd(TASKINFO_RUNNING_OVEROSYNC, overoSyncTaskHandle); + PIOS_TASK_MONITOR_RegisterTask(TASKINFO_RUNNING_OVEROSYNC, overoSyncTaskHandle); return 0; } diff --git a/flight/modules/OveroSync/simulated/overosync.c b/flight/modules/OveroSync/simulated/overosync.c index a8bf6c769..be1e39b6d 100644 --- a/flight/modules/OveroSync/simulated/overosync.c +++ b/flight/modules/OveroSync/simulated/overosync.c @@ -30,10 +30,13 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "openpilot.h" +#include + #include "overosync.h" + #include "overosyncstats.h" #include "systemstats.h" +#include "taskinfo.h" // Private constants #define OVEROSYNC_PACKET_SIZE 1024 @@ -127,7 +130,7 @@ int32_t OveroSyncStart(void) // Start telemetry tasks xTaskCreate(overoSyncTask, (signed char *)"OveroSync", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &overoSyncTaskHandle); - TaskMonitorAdd(TASKINFO_RUNNING_OVEROSYNC, overoSyncTaskHandle); + PIOS_TASK_MONITOR_RegisterTask(TASKINFO_RUNNING_OVEROSYNC, overoSyncTaskHandle); return 0; } diff --git a/flight/modules/PathPlanner/pathplanner.c b/flight/modules/PathPlanner/pathplanner.c index 223925c74..1f3768c95 100644 --- a/flight/modules/PathPlanner/pathplanner.c +++ b/flight/modules/PathPlanner/pathplanner.c @@ -30,8 +30,6 @@ */ #include "openpilot.h" -#include -#include "paths.h" #include "flightstatus.h" #include "airspeedactual.h" @@ -42,6 +40,9 @@ #include "velocityactual.h" #include "waypoint.h" #include "waypointactive.h" +#include "taskinfo.h" + +#include "paths.h" // Private constants #define STACK_SIZE_BYTES 1024 @@ -86,7 +87,7 @@ int32_t PathPlannerStart() // Start VM thread xTaskCreate(pathPlannerTask, (signed char *)"PathPlanner", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &taskHandle); - TaskMonitorAdd(TASKINFO_RUNNING_PATHPLANNER, taskHandle); + PIOS_TASK_MONITOR_RegisterTask(TASKINFO_RUNNING_PATHPLANNER, taskHandle); return 0; } diff --git a/flight/modules/Sensors/sensors.c b/flight/modules/Sensors/sensors.c index 8f09a93a1..6e9d93f9b 100644 --- a/flight/modules/Sensors/sensors.c +++ b/flight/modules/Sensors/sensors.c @@ -58,9 +58,10 @@ #include #include #include +#include + #include -#include #include // Private constants @@ -130,7 +131,7 @@ int32_t SensorsStart(void) { // Start main task xTaskCreate(SensorsTask, (signed char *)"Sensors", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &sensorsTaskHandle); - TaskMonitorAdd(TASKINFO_RUNNING_SENSORS, sensorsTaskHandle); + PIOS_TASK_MONITOR_RegisterTask(TASKINFO_RUNNING_SENSORS, sensorsTaskHandle); PIOS_WDG_RegisterFlag(PIOS_WDG_SENSORS); return 0; diff --git a/flight/modules/Sensors/simulated/sensors.c b/flight/modules/Sensors/simulated/sensors.c index fef692598..5411ea57c 100644 --- a/flight/modules/Sensors/simulated/sensors.c +++ b/flight/modules/Sensors/simulated/sensors.c @@ -46,9 +46,9 @@ * */ -#include "pios.h" -#include "attitude.h" +#include +#include "attitude.h" #include "accels.h" #include "actuatordesired.h" #include "attitudeactual.h" @@ -67,6 +67,7 @@ #include "ratedesired.h" #include "revocalibration.h" #include "systemsettings.h" +#include "taskinfo.h" #include "CoordinateConversions.h" @@ -132,7 +133,7 @@ int32_t SensorsStart(void) { // Start main task xTaskCreate(SensorsTask, (signed char *)"Sensors", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &sensorsTaskHandle); - TaskMonitorAdd(TASKINFO_RUNNING_SENSORS, sensorsTaskHandle); + PIOS_TASK_MONITOR_RegisterTask(TASKINFO_RUNNING_SENSORS, sensorsTaskHandle); PIOS_WDG_RegisterFlag(PIOS_WDG_SENSORS); return 0; diff --git a/flight/modules/Stabilization/stabilization.c b/flight/modules/Stabilization/stabilization.c index edca0f06d..30f207422 100644 --- a/flight/modules/Stabilization/stabilization.c +++ b/flight/modules/Stabilization/stabilization.c @@ -31,7 +31,8 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "openpilot.h" +#include + #include "stabilization.h" #include "stabilizationsettings.h" #include "actuatordesired.h" @@ -43,6 +44,7 @@ #include "gyros.h" #include "flightstatus.h" #include "manualcontrol.h" // Just to get a macro +#include "taskinfo.h" // Math libraries #include "CoordinateConversions.h" @@ -107,7 +109,7 @@ int32_t StabilizationStart() // Start main task xTaskCreate(stabilizationTask, (signed char*)"Stabilization", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &taskHandle); - TaskMonitorAdd(TASKINFO_RUNNING_STABILIZATION, taskHandle); + PIOS_TASK_MONITOR_RegisterTask(TASKINFO_RUNNING_STABILIZATION, taskHandle); PIOS_WDG_RegisterFlag(PIOS_WDG_STABILIZATION); return 0; } diff --git a/flight/modules/System/systemmod.c b/flight/modules/System/systemmod.c index 98411ede1..a0538531c 100644 --- a/flight/modules/System/systemmod.c +++ b/flight/modules/System/systemmod.c @@ -51,7 +51,7 @@ #include #include #include -#include +#include #include // Flight Libraries @@ -98,6 +98,9 @@ static HwSettingsData bootHwSettings; // Private functions static void objectUpdatedCb(UAVObjEvent * ev); static void hwSettingsUpdatedCb(UAVObjEvent * ev); +#ifdef DIAG_TASKS +static void taskMonitorForEachCallback(uint16_t task_id, const struct pios_task_info *task_info, void *context); +#endif static void updateStats(); static void updateSystemAlarms(); static void systemTask(void *parameters); @@ -117,7 +120,7 @@ int32_t SystemModStart(void) // Create system task xTaskCreate(systemTask, (signed char *)"System", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &systemTaskHandle); // Register task - TaskMonitorAdd(TASKINFO_RUNNING_SYSTEM, systemTaskHandle); + PIOS_TASK_MONITOR_RegisterTask(TASKINFO_RUNNING_SYSTEM, systemTaskHandle); return 0; } @@ -185,6 +188,10 @@ static void systemTask(void *parameters) // Whenever the configuration changes, make sure it is safe to fly HwSettingsConnectCallback(hwSettingsUpdatedCb); +#ifdef DIAG_TASKS + TaskInfoData taskInfoData; +#endif + // Main system loop while (1) { // Update the system statistics @@ -199,7 +206,8 @@ static void systemTask(void *parameters) #ifdef DIAG_TASKS // Update the task status object - TaskMonitorUpdateAll(); + PIOS_TASK_MONITOR_ForEachTask(taskMonitorForEachCallback, &taskInfoData); + TaskInfoSet(&taskInfoData); #endif // Flash the heartbeat LED @@ -348,6 +356,19 @@ static void hwSettingsUpdatedCb(UAVObjEvent * ev) } } +#ifdef DIAG_TASKS +static void taskMonitorForEachCallback(uint16_t task_id, const struct pios_task_info *task_info, void *context) +{ + TaskInfoData *taskData = (TaskInfoData *)context; + // By convention, there is a direct mapping between task monitor task_id's and members + // of the TaskInfoXXXXElem enums + PIOS_DEBUG_Assert(task_id < TASKINFO_RUNNING_NUMELEM); + taskData->Running[task_id] = task_info->is_running? TASKINFO_RUNNING_TRUE: TASKINFO_RUNNING_FALSE; + taskData->StackRemaining[task_id] = task_info->stack_remaining; + taskData->RunningTime[task_id] = task_info->running_time_percentage; +} +#endif + /** * Called periodically to update the I2C statistics */ diff --git a/flight/modules/Telemetry/telemetry.c b/flight/modules/Telemetry/telemetry.c index 64d093d32..0270ed3b2 100644 --- a/flight/modules/Telemetry/telemetry.c +++ b/flight/modules/Telemetry/telemetry.c @@ -30,11 +30,14 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "openpilot.h" +#include + #include "telemetry.h" + #include "flighttelemetrystats.h" #include "gcstelemetrystats.h" #include "hwsettings.h" +#include "taskinfo.h" // Private constants #define MAX_QUEUE_SIZE TELEM_QUEUE_SIZE @@ -96,13 +99,13 @@ int32_t TelemetryStart(void) // Start telemetry tasks xTaskCreate(telemetryTxTask, (signed char *)"TelTx", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY_TX, &telemetryTxTaskHandle); + PIOS_TASK_MONITOR_RegisterTask(TASKINFO_RUNNING_TELEMETRYTX, telemetryTxTaskHandle); xTaskCreate(telemetryRxTask, (signed char *)"TelRx", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY_RX, &telemetryRxTaskHandle); - TaskMonitorAdd(TASKINFO_RUNNING_TELEMETRYTX, telemetryTxTaskHandle); - TaskMonitorAdd(TASKINFO_RUNNING_TELEMETRYRX, telemetryRxTaskHandle); + PIOS_TASK_MONITOR_RegisterTask(TASKINFO_RUNNING_TELEMETRYRX, telemetryRxTaskHandle); #if defined(PIOS_TELEM_PRIORITY_QUEUE) xTaskCreate(telemetryTxPriTask, (signed char *)"TelPriTx", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY_TXPRI, &telemetryTxPriTaskHandle); - TaskMonitorAdd(TASKINFO_RUNNING_TELEMETRYTXPRI, telemetryTxPriTaskHandle); + PIOS_TASK_MONITOR_RegisterTask(TASKINFO_RUNNING_TELEMETRYTXPRI, telemetryTxPriTaskHandle); #endif return 0; diff --git a/flight/modules/VtolPathFollower/vtolpathfollower.c b/flight/modules/VtolPathFollower/vtolpathfollower.c index 2d7b3ae1f..03c0e024f 100644 --- a/flight/modules/VtolPathFollower/vtolpathfollower.c +++ b/flight/modules/VtolPathFollower/vtolpathfollower.c @@ -46,11 +46,10 @@ * */ -#include "openpilot.h" -#include -#include "paths.h" +#include #include "vtolpathfollower.h" + #include "accels.h" #include "attitudeactual.h" #include "hwsettings.h" @@ -69,6 +68,9 @@ #include "systemsettings.h" #include "velocitydesired.h" #include "velocityactual.h" +#include "taskinfo.h" + +#include "paths.h" #include "CoordinateConversions.h" // Private constants @@ -103,7 +105,7 @@ int32_t VtolPathFollowerStart() if (vtolpathfollower_enabled) { // Start main task xTaskCreate(vtolPathFollowerTask, (signed char *)"VtolPathFollower", STACK_SIZE_BYTES/4, NULL, TASK_PRIORITY, &pathfollowerTaskHandle); - TaskMonitorAdd(TASKINFO_RUNNING_PATHFOLLOWER, pathfollowerTaskHandle); + PIOS_TASK_MONITOR_RegisterTask(TASKINFO_RUNNING_PATHFOLLOWER, pathfollowerTaskHandle); } return 0; diff --git a/flight/pios/common/pios_flashfs_logfs.c b/flight/pios/common/pios_flashfs_logfs.c index 4fdef16db..673d5773f 100644 --- a/flight/pios/common/pios_flashfs_logfs.c +++ b/flight/pios/common/pios_flashfs_logfs.c @@ -35,7 +35,6 @@ #include -#define MIN(x,y) ((x) < (y) ? (x) : (y)) /* * Filesystem state data tracked in RAM diff --git a/flight/pios/common/pios_task_monitor.c b/flight/pios/common/pios_task_monitor.c new file mode 100644 index 000000000..c3e3f27d0 --- /dev/null +++ b/flight/pios/common/pios_task_monitor.c @@ -0,0 +1,144 @@ +/** + ****************************************************************************** + * @addtogroup OpenPilotSystem OpenPilot System + * @{ + * @addtogroup OpenPilotLibraries OpenPilot System Libraries + * @{ + * @file pios_task_monitor.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Task monitoring functions + * @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 + +#ifdef PIOS_INCLUDE_TASK_MONITOR + +// Private variables +static xSemaphoreHandle mLock; +static xTaskHandle *mTaskHandles; +static uint32_t mLastMonitorTime; +static uint16_t mMaxTasks; + +/** + * Initialize the Task Monitor + */ +int32_t PIOS_TASK_MONITOR_Initialize(uint16_t max_tasks) +{ + mLock = xSemaphoreCreateRecursiveMutex(); + if (!mLock) { return -1; } + + mTaskHandles = (xTaskHandle*)pvPortMalloc(max_tasks * sizeof(xTaskHandle)); + if (!mTaskHandles) { return -1; } + memset(mTaskHandles, 0, max_tasks * sizeof(xTaskHandle)); + + mMaxTasks = max_tasks; +#if (configGENERATE_RUN_TIME_STATS == 1) + mLastMonitorTime = portGET_RUN_TIME_COUNTER_VALUE(); +#else + mLastMonitorTime = 0; +#endif + return 0; +} + +/** + * Register a task handle + */ +int32_t PIOS_TASK_MONITOR_RegisterTask(uint16_t task_id, xTaskHandle handle) +{ + if (mTaskHandles && task_id < mMaxTasks) { + xSemaphoreTakeRecursive(mLock, portMAX_DELAY); + mTaskHandles[task_id] = handle; + xSemaphoreGiveRecursive(mLock); + return 0; + } else { + return -1; + } +} + +/** + * Unregister a task handle + */ +int32_t PIOS_TASK_MONITOR_UnregisterTask(uint16_t task_id) +{ + if (mTaskHandles && task_id < mMaxTasks) { + xSemaphoreTakeRecursive(mLock, portMAX_DELAY); + mTaskHandles[task_id] = 0; + xSemaphoreGiveRecursive(mLock); + return 0; + } else { + return -1; + } +} + +/** + * Query if a task is running + */ +bool PIOS_TASK_MONITOR_IsRunning(uint16_t task_id) +{ + return (mTaskHandles && task_id <= mMaxTasks && mTaskHandles[task_id]); +} + +/** + * Tell the caller the status of all tasks via a task-by-task callback + */ +void PIOS_TASK_MONITOR_ForEachTask(TaskMonitorTaskInfoCallback callback, void *context) +{ + if (!mTaskHandles) { return; } + + xSemaphoreTakeRecursive(mLock, portMAX_DELAY); + +#if (configGENERATE_RUN_TIME_STATS == 1) + /* Calculate the amount of elapsed run time between the last time we + * measured and now. Scale so that we can convert task run times + * directly to percentages. */ + uint32_t currentTime = portGET_RUN_TIME_COUNTER_VALUE(); + /* avoid divide-by-zero if the interval is too small */ + uint32_t deltaTime = ((currentTime - mLastMonitorTime)/100) ? : 1; + mLastMonitorTime = currentTime; +#endif + /* Update all task information */ + for (uint16_t n = 0; n < mMaxTasks; ++n) { + struct pios_task_info info; + if (mTaskHandles[n]) { + info.is_running = true; +#if defined(ARCH_POSIX) || defined(ARCH_WIN32) + info.stack_remaining = 10000; +#else + info.stack_remaining = uxTaskGetStackHighWaterMark(mTaskHandles[n]) * 4; +#endif +#if (configGENERATE_RUN_TIME_STATS == 1) + /* Generate run time percentage stats */ + info.running_time_percentage = uxTaskGetRunTime(mTaskHandles[n])/deltaTime; +#else + info.running_time_percentage = 0; +#endif + } else { + info.is_running = false; + info.stack_remaining = 0; + info.running_time_percentage = 0; + } + /* Pass the information for this task back to the caller */ + callback(n, &info, context); + } + + xSemaphoreGiveRecursive(mLock); +} + +#endif // PIOS_INCLUDE_TASK_MONITOR + diff --git a/flight/pios/inc/pios_task_monitor.h b/flight/pios/inc/pios_task_monitor.h new file mode 100644 index 000000000..e969af3d8 --- /dev/null +++ b/flight/pios/inc/pios_task_monitor.h @@ -0,0 +1,107 @@ +/** + ****************************************************************************** + * @addtogroup OpenPilotSystem OpenPilot System + * @{ + * @addtogroup OpenPilotLibraries OpenPilot System Libraries + * @{ + * @file task_monitor.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2013. + * @brief Task monitoring functions + * @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_TASK_MONITOR_H +#define PIOS_TASK_MONITOR_H + +#include + +/** + * Initializes the Task Monitor. + * + * For correct results, this must be called prior to any calls to other + * task monitoring functions. The task_ids of the monitored tasks must + * be in the range [0, max_tasks-1]. + * Initially, all tasks are marked as not running. + * + * @param max_tasks The maximum number of tasks that will be monitored. + * @return 0 on success, -1 on failure. + */ +extern int32_t PIOS_TASK_MONITOR_Initialize(uint16_t max_tasks); + +/** + * Registers a task with the task monitor. + * A task that has been registered will be marked as running. + * + * @param task_id The id of the task to register. Must be in the range [0, max_tasks-1]. + * @param handle The FreeRTOS xTaskHandle of the running task. + * @return 0 on success, -1 on failure. + */ +extern int32_t PIOS_TASK_MONITOR_RegisterTask(uint16_t task_id, xTaskHandle handle); + +/** + * Unregisters a task with the task monitor. + * A task that has been unregistered will be marked as not running. + * + * @param task_id The id of the task to unregister. Must be in the range [0, max_tasks-1]. + * @return 0 on success, -1 on failure. + */ +extern int32_t PIOS_TASK_MONITOR_UnregisterTask(uint16_t task_id); + +/** + * Checks if a given task is running. + * A task that has not been registered will be marked as not running. + * + * @param task_id The id of the task to check. Must be in the range [0, max_tasks-1]. + * @return true if the task is running. + */ +extern bool PIOS_TASK_MONITOR_IsRunning(uint16_t task_id); + +/** + * Information about a running task that has been registered + * via a call to PIOS_TASK_MONITOR_Add(). + */ +struct pios_task_info { + /** Remaining task stack in bytes. */ + uint32_t stack_remaining; + /** Flag indicating whether or not the task is running. */ + bool is_running; + /** Percentage of cpu time used by the task since the last call + * to PIOS_TASK_MONITOR_ForEachTask(). Low-load tasks may + * report 0% load even though they have run during the interval. */ + uint8_t running_time_percentage; +}; + +/** + * Iterator callback, called for each monitored task by PIOS_TASK_MONITOR_TasksIterate(). + * + * @param task_id The id of the task the task_info refers to. + * @param task_info Information about the task identified by task_id. + * @param context Context information optionally provided by the caller to PIOS_TASK_MONITOR_TasksIterate() + */ +typedef void (*TaskMonitorTaskInfoCallback)(uint16_t task_id, const struct pios_task_info *task_info, void *context); + +/** + * Iterator callback, called for each monitored task by PIOS_TASK_MONITOR_TasksIterate(). + * + * @param task_id The id of the task the task_info refers to. + * @param task_info Information about the task identified by task_id. + * @param context Context information optionally provided by the caller to PIOS_TASK_MONITOR_TasksIterate() + */ +extern void PIOS_TASK_MONITOR_ForEachTask(TaskMonitorTaskInfoCallback callback, void *context); + +#endif // PIOS_TASK_MONITOR_H diff --git a/flight/pios/pios.h b/flight/pios/pios.h index 5e581b345..0b9d2da9b 100644 --- a/flight/pios/pios.h +++ b/flight/pios/pios.h @@ -35,6 +35,8 @@ #define PIOS_H #include +#include +#include #ifdef USE_SIM_POSIX /* SimPosix version of this file. This will probably be removed later */ @@ -78,6 +80,13 @@ #include "semphr.h" #endif +#ifdef PIOS_INCLUDE_TASK_MONITOR +#ifndef PIOS_INCLUDE_FREERTOS +#error PiOS Task Monitor requires PIOS_INCLUDE_FREERTOS to be defined +#endif +#include +#endif + /* PIOS bootloader helper */ #ifdef PIOS_INCLUDE_BL_HELPER /* #define PIOS_INCLUDE_BL_HELPER_WRITE_SUPPORT */ diff --git a/flight/pios/pios_sim_posix.h b/flight/pios/pios_sim_posix.h index d1ba3e22b..86fb8bf41 100644 --- a/flight/pios/pios_sim_posix.h +++ b/flight/pios/pios_sim_posix.h @@ -40,6 +40,13 @@ #include "semphr.h" #endif +#ifdef PIOS_INCLUDE_TASK_MONITOR +#ifndef PIOS_INCLUDE_FREERTOS +#error PiOS Task Monitor requires PIOS_INCLUDE_FREERTOS to be defined +#endif +#include +#endif + /* C Lib Includes */ #include #include diff --git a/flight/pios/stm32f4xx/libraries/STM32_USB_OTG_Driver/inc/usb_defines.h b/flight/pios/stm32f4xx/libraries/STM32_USB_OTG_Driver/inc/usb_defines.h index b119c2586..82d116d7a 100644 --- a/flight/pios/stm32f4xx/libraries/STM32_USB_OTG_Driver/inc/usb_defines.h +++ b/flight/pios/stm32f4xx/libraries/STM32_USB_OTG_Driver/inc/usb_defines.h @@ -169,7 +169,9 @@ #define HCCHAR_BULK 2 #define HCCHAR_INTR 3 +#ifndef MIN #define MIN(a, b) (((a) < (b)) ? (a) : (b)) +#endif /** * @} diff --git a/flight/pios/stm32f4xx/pios_usb_hid.c b/flight/pios/stm32f4xx/pios_usb_hid.c index 88f45978b..e85270177 100644 --- a/flight/pios/stm32f4xx/pios_usb_hid.c +++ b/flight/pios/stm32f4xx/pios_usb_hid.c @@ -37,9 +37,6 @@ #include "pios_usb_board_data.h" /* PIOS_BOARD_*_DATA_LENGTH */ #include "pios_usbhook.h" /* PIOS_USBHOOK_* */ -#define MIN(x,y) (((x) < (y)) ? (x) : (y)) -#define MAX(x,y) (((x) > (y)) ? (x) : (y)) - static void PIOS_USB_HID_RegisterTxCallback(uint32_t usbhid_id, pios_com_callback tx_out_cb, uint32_t context); static void PIOS_USB_HID_RegisterRxCallback(uint32_t usbhid_id, pios_com_callback rx_in_cb, uint32_t context); static void PIOS_USB_HID_TxStart(uint32_t usbhid_id, uint16_t tx_bytes_avail); diff --git a/flight/targets/boards/coptercontrol/firmware/inc/openpilot.h b/flight/targets/boards/coptercontrol/firmware/inc/openpilot.h index 58420e789..7c6045305 100644 --- a/flight/targets/boards/coptercontrol/firmware/inc/openpilot.h +++ b/flight/targets/boards/coptercontrol/firmware/inc/openpilot.h @@ -36,7 +36,6 @@ #include #include #include -#include #include #include "alarms.h" diff --git a/flight/targets/boards/coptercontrol/firmware/inc/pios_config.h b/flight/targets/boards/coptercontrol/firmware/inc/pios_config.h index ea4f2ae1d..b2f5534c1 100644 --- a/flight/targets/boards/coptercontrol/firmware/inc/pios_config.h +++ b/flight/targets/boards/coptercontrol/firmware/inc/pios_config.h @@ -50,6 +50,7 @@ #define PIOS_INCLUDE_DELAY #define PIOS_INCLUDE_INITCALL #define PIOS_INCLUDE_SYS +#define PIOS_INCLUDE_TASK_MONITOR /* PIOS hardware peripherals */ #define PIOS_INCLUDE_IRQ diff --git a/flight/targets/boards/coptercontrol/firmware/inc/pios_config_posix.h b/flight/targets/boards/coptercontrol/firmware/inc/pios_config_posix.h index 12dc1c6da..49f94d7f0 100644 --- a/flight/targets/boards/coptercontrol/firmware/inc/pios_config_posix.h +++ b/flight/targets/boards/coptercontrol/firmware/inc/pios_config_posix.h @@ -34,6 +34,7 @@ #define PIOS_INCLUDE_DELAY #define PIOS_INCLUDE_LED #define PIOS_INCLUDE_FREERTOS +#define PIOS_INCLUDE_TASK_MONITOR #define PIOS_INCLUDE_COM #define PIOS_INCLUDE_UDP #define PIOS_INCLUDE_SERVO diff --git a/flight/targets/boards/coptercontrol/firmware/pios_board.c b/flight/targets/boards/coptercontrol/firmware/pios_board.c index d620acfee..f7d146e07 100644 --- a/flight/targets/boards/coptercontrol/firmware/pios_board.c +++ b/flight/targets/boards/coptercontrol/firmware/pios_board.c @@ -31,6 +31,7 @@ #include #include #include +#include /* * Pull in the board-specific static HW definitions. @@ -228,8 +229,10 @@ void PIOS_Board_Init(void) { AlarmsSet(SYSTEMALARMS_ALARM_BOOTFAULT, SYSTEMALARMS_ALARM_CRITICAL); } - /* Initialize the task monitor library */ - TaskMonitorInitialize(); + /* Initialize the task monitor */ + if (PIOS_TASK_MONITOR_Initialize(TASKINFO_RUNNING_NUMELEM)) { + PIOS_Assert(0); + } /* Set up pulse timers */ PIOS_TIM_InitClock(&tim_1_cfg); diff --git a/flight/targets/boards/coptercontrol/firmware/pios_board_posix.c b/flight/targets/boards/coptercontrol/firmware/pios_board_posix.c index d567a7436..3f92b020b 100644 --- a/flight/targets/boards/coptercontrol/firmware/pios_board_posix.c +++ b/flight/targets/boards/coptercontrol/firmware/pios_board_posix.c @@ -45,8 +45,10 @@ void PIOS_Board_Init(void) { /* Initialize the alarms library */ AlarmsInitialize(); - /* Initialize the task monitor library */ - TaskMonitorInitialize(); + /* Initialize the task monitor */ + if (PIOS_TASK_MONITOR_Initialize(TASKINFO_RUNNING_NUMELEM)) { + PIOS_Assert(0); + } /* Initialize the PiOS library */ PIOS_COM_Init(); diff --git a/flight/targets/boards/oplinkmini/firmware/inc/openpilot.h b/flight/targets/boards/oplinkmini/firmware/inc/openpilot.h index c77374ecc..a831f9a39 100644 --- a/flight/targets/boards/oplinkmini/firmware/inc/openpilot.h +++ b/flight/targets/boards/oplinkmini/firmware/inc/openpilot.h @@ -37,7 +37,6 @@ #include #include #include -#include #include #include "alarms.h" diff --git a/flight/targets/boards/oplinkmini/firmware/inc/pios_config.h b/flight/targets/boards/oplinkmini/firmware/inc/pios_config.h index 1da5edbe0..fc7563aeb 100644 --- a/flight/targets/boards/oplinkmini/firmware/inc/pios_config.h +++ b/flight/targets/boards/oplinkmini/firmware/inc/pios_config.h @@ -50,6 +50,7 @@ #define PIOS_INCLUDE_DELAY #define PIOS_INCLUDE_INITCALL #define PIOS_INCLUDE_SYS +#define PIOS_INCLUDE_TASK_MONITOR /* PIOS hardware peripherals */ #define PIOS_INCLUDE_IRQ diff --git a/flight/targets/boards/oplinkmini/firmware/inc/pios_config_posix.h b/flight/targets/boards/oplinkmini/firmware/inc/pios_config_posix.h index 5747c0e3b..5e744a381 100644 --- a/flight/targets/boards/oplinkmini/firmware/inc/pios_config_posix.h +++ b/flight/targets/boards/oplinkmini/firmware/inc/pios_config_posix.h @@ -34,6 +34,7 @@ #define PIOS_INCLUDE_DELAY #define PIOS_INCLUDE_LED #define PIOS_INCLUDE_FREERTOS +#define PIOS_INCLUDE_TASK_MONITOR #define PIOS_INCLUDE_COM #define PIOS_INCLUDE_UDP #define PIOS_INCLUDE_SERVO diff --git a/flight/targets/boards/oplinkmini/firmware/pios_board.c b/flight/targets/boards/oplinkmini/firmware/pios_board.c index e3e8b51c8..63f6e9db0 100644 --- a/flight/targets/boards/oplinkmini/firmware/pios_board.c +++ b/flight/targets/boards/oplinkmini/firmware/pios_board.c @@ -30,6 +30,7 @@ #include "inc/openpilot.h" #include #include +#include /* * Pull in the board-specific static HW definitions. @@ -138,8 +139,10 @@ void PIOS_Board_Init(void) { OPLinkSettingsGet(&oplinkSettings); #endif /* PIOS_INCLUDE_FLASH_EEPROM */ - /* Initialize the task monitor library */ - TaskMonitorInitialize(); + /* Initialize the task monitor */ + if (PIOS_TASK_MONITOR_Initialize(TASKINFO_RUNNING_NUMELEM)) { + PIOS_Assert(0); + } #if defined(PIOS_INCLUDE_TIM) /* Set up pulse timers */ diff --git a/flight/targets/boards/oplinkmini/firmware/pios_board_posix.c b/flight/targets/boards/oplinkmini/firmware/pios_board_posix.c index d567a7436..3f92b020b 100644 --- a/flight/targets/boards/oplinkmini/firmware/pios_board_posix.c +++ b/flight/targets/boards/oplinkmini/firmware/pios_board_posix.c @@ -45,8 +45,10 @@ void PIOS_Board_Init(void) { /* Initialize the alarms library */ AlarmsInitialize(); - /* Initialize the task monitor library */ - TaskMonitorInitialize(); + /* Initialize the task monitor */ + if (PIOS_TASK_MONITOR_Initialize(TASKINFO_RUNNING_NUMELEM)) { + PIOS_Assert(0); + } /* Initialize the PiOS library */ PIOS_COM_Init(); diff --git a/flight/targets/boards/osd/firmware/inc/openpilot.h b/flight/targets/boards/osd/firmware/inc/openpilot.h index be91a9846..45cb70c73 100644 --- a/flight/targets/boards/osd/firmware/inc/openpilot.h +++ b/flight/targets/boards/osd/firmware/inc/openpilot.h @@ -36,7 +36,6 @@ #include #include #include -#include #include #include "alarms.h" diff --git a/flight/targets/boards/osd/firmware/inc/pios_config.h b/flight/targets/boards/osd/firmware/inc/pios_config.h index c08dda8b5..9cad8dbd5 100644 --- a/flight/targets/boards/osd/firmware/inc/pios_config.h +++ b/flight/targets/boards/osd/firmware/inc/pios_config.h @@ -50,6 +50,7 @@ #define PIOS_INCLUDE_DELAY #define PIOS_INCLUDE_INITCALL #define PIOS_INCLUDE_SYS +#define PIOS_INCLUDE_TASK_MONITOR /* PIOS hardware peripherals */ #define PIOS_INCLUDE_IRQ diff --git a/flight/targets/boards/osd/firmware/pios_board.c b/flight/targets/boards/osd/firmware/pios_board.c index 927a7160d..971f615df 100644 --- a/flight/targets/boards/osd/firmware/pios_board.c +++ b/flight/targets/boards/osd/firmware/pios_board.c @@ -29,6 +29,7 @@ #include #include #include +#include /* * Pull in the board-specific static HW definitions. @@ -133,8 +134,10 @@ void PIOS_Board_Init(void) { /* Initialize the alarms library */ AlarmsInitialize(); - /* Initialize the task monitor library */ - TaskMonitorInitialize(); + /* Initialize the task monitor */ + if (PIOS_TASK_MONITOR_Initialize(TASKINFO_RUNNING_NUMELEM)) { + PIOS_Assert(0); + } /* IAP System Setup */ PIOS_IAP_Init(); diff --git a/flight/targets/boards/revolution/firmware/Makefile.osx b/flight/targets/boards/revolution/firmware/Makefile.osx index 41b5ab938..732164a60 100644 --- a/flight/targets/boards/revolution/firmware/Makefile.osx +++ b/flight/targets/boards/revolution/firmware/Makefile.osx @@ -186,7 +186,6 @@ SRC += $(FLIGHTLIB)/WorldMagModel.c SRC += $(FLIGHTLIB)/CoordinateConversions.c SRC += $(FLIGHTLIB)/paths.c SRC += $(FLIGHTLIB)/insgps13state.c -SRC += $(FLIGHTLIB)/taskmonitor.c ## RTOS and RTOS Portable SRC += $(RTOSSRCDIR)/list.c diff --git a/flight/targets/boards/revolution/firmware/inc/openpilot.h b/flight/targets/boards/revolution/firmware/inc/openpilot.h index c77374ecc..a831f9a39 100644 --- a/flight/targets/boards/revolution/firmware/inc/openpilot.h +++ b/flight/targets/boards/revolution/firmware/inc/openpilot.h @@ -37,7 +37,6 @@ #include #include #include -#include #include #include "alarms.h" diff --git a/flight/targets/boards/revolution/firmware/inc/pios_config.h b/flight/targets/boards/revolution/firmware/inc/pios_config.h index 1df7180b3..3fb557bce 100644 --- a/flight/targets/boards/revolution/firmware/inc/pios_config.h +++ b/flight/targets/boards/revolution/firmware/inc/pios_config.h @@ -50,6 +50,7 @@ #define PIOS_INCLUDE_DELAY #define PIOS_INCLUDE_INITCALL #define PIOS_INCLUDE_SYS +#define PIOS_INCLUDE_TASK_MONITOR /* PIOS hardware peripherals */ #define PIOS_INCLUDE_IRQ diff --git a/flight/targets/boards/revolution/firmware/inc/pios_config_sim.h b/flight/targets/boards/revolution/firmware/inc/pios_config_sim.h index 79dba8ef8..763587c02 100644 --- a/flight/targets/boards/revolution/firmware/inc/pios_config_sim.h +++ b/flight/targets/boards/revolution/firmware/inc/pios_config_sim.h @@ -35,6 +35,7 @@ #define PIOS_INCLUDE_LED #define PIOS_INCLUDE_SDCARD #define PIOS_INCLUDE_FREERTOS +#define PIOS_INCLUDE_TASK_MONITOR #define PIOS_INCLUDE_COM //#define PIOS_INCLUDE_GPS #define PIOS_INCLUDE_IRQ diff --git a/flight/targets/boards/revolution/firmware/pios_board.c b/flight/targets/boards/revolution/firmware/pios_board.c index 5263da346..ea74c875d 100644 --- a/flight/targets/boards/revolution/firmware/pios_board.c +++ b/flight/targets/boards/revolution/firmware/pios_board.c @@ -30,6 +30,7 @@ #include #include #include +#include /* * Pull in the board-specific static HW definitions. @@ -379,8 +380,10 @@ void PIOS_Board_Init(void) { /* Initialize the alarms library */ AlarmsInitialize(); - /* Initialize the task monitor library */ - TaskMonitorInitialize(); + /* Initialize the task monitor */ + if (PIOS_TASK_MONITOR_Initialize(TASKINFO_RUNNING_NUMELEM)) { + PIOS_Assert(0); + } /* Set up pulse timers */ PIOS_TIM_InitClock(&tim_1_cfg); diff --git a/flight/targets/boards/revolution/firmware/pios_board_sim.c b/flight/targets/boards/revolution/firmware/pios_board_sim.c index f58f9523e..cfab4fdd2 100644 --- a/flight/targets/boards/revolution/firmware/pios_board_sim.c +++ b/flight/targets/boards/revolution/firmware/pios_board_sim.c @@ -149,8 +149,10 @@ void PIOS_Board_Init(void) { /* Initialize the alarms library */ AlarmsInitialize(); - /* Initialize the task monitor library */ - TaskMonitorInitialize(); + /* Initialize the task monitor */ + if (PIOS_TASK_MONITOR_Initialize(TASKINFO_RUNNING_NUMELEM)) { + PIOS_Assert(0); + } #if defined(PIOS_INCLUDE_COM) #if defined(PIOS_INCLUDE_TELEMETRY_RF) && 1 diff --git a/flight/targets/boards/revoproto/firmware/Makefile.osx b/flight/targets/boards/revoproto/firmware/Makefile.osx index 6fdfecf98..d7f29ee4c 100644 --- a/flight/targets/boards/revoproto/firmware/Makefile.osx +++ b/flight/targets/boards/revoproto/firmware/Makefile.osx @@ -184,7 +184,6 @@ SRC += $(FLIGHTLIB)/WorldMagModel.c SRC += $(FLIGHTLIB)/CoordinateConversions.c SRC += $(FLIGHTLIB)/paths.c SRC += $(FLIGHTLIB)/insgps13state.c -SRC += $(FLIGHTLIB)/taskmonitor.c SRC += $(MATHLIB)/pid.c SRC += $(MATHLIB)/sin_lookup.c diff --git a/flight/targets/boards/revoproto/firmware/inc/openpilot.h b/flight/targets/boards/revoproto/firmware/inc/openpilot.h index c77374ecc..a831f9a39 100644 --- a/flight/targets/boards/revoproto/firmware/inc/openpilot.h +++ b/flight/targets/boards/revoproto/firmware/inc/openpilot.h @@ -37,7 +37,6 @@ #include #include #include -#include #include #include "alarms.h" diff --git a/flight/targets/boards/revoproto/firmware/inc/pios_config.h b/flight/targets/boards/revoproto/firmware/inc/pios_config.h index c148d9142..f00350b08 100644 --- a/flight/targets/boards/revoproto/firmware/inc/pios_config.h +++ b/flight/targets/boards/revoproto/firmware/inc/pios_config.h @@ -50,6 +50,7 @@ #define PIOS_INCLUDE_DELAY #define PIOS_INCLUDE_INITCALL #define PIOS_INCLUDE_SYS +#define PIOS_INCLUDE_TASK_MONITOR /* PIOS hardware peripherals */ #define PIOS_INCLUDE_IRQ diff --git a/flight/targets/boards/revoproto/firmware/inc/pios_config_sim.h b/flight/targets/boards/revoproto/firmware/inc/pios_config_sim.h index ab313d0a1..973ec4c72 100644 --- a/flight/targets/boards/revoproto/firmware/inc/pios_config_sim.h +++ b/flight/targets/boards/revoproto/firmware/inc/pios_config_sim.h @@ -35,6 +35,7 @@ #define PIOS_INCLUDE_LED #define PIOS_INCLUDE_SDCARD #define PIOS_INCLUDE_FREERTOS +#define PIOS_INCLUDE_TASK_MONITOR #define PIOS_INCLUDE_COM //#define PIOS_INCLUDE_GPS #define PIOS_INCLUDE_IRQ diff --git a/flight/targets/boards/revoproto/firmware/pios_board.c b/flight/targets/boards/revoproto/firmware/pios_board.c index d4b390b72..a5013b525 100644 --- a/flight/targets/boards/revoproto/firmware/pios_board.c +++ b/flight/targets/boards/revoproto/firmware/pios_board.c @@ -30,6 +30,7 @@ #include #include #include +#include /* * Pull in the board-specific static HW definitions. @@ -428,8 +429,10 @@ void PIOS_Board_Init(void) { /* Initialize the alarms library */ AlarmsInitialize(); - /* Initialize the task monitor library */ - TaskMonitorInitialize(); + /* Initialize the task monitor */ + if (PIOS_TASK_MONITOR_Initialize(TASKINFO_RUNNING_NUMELEM)) { + PIOS_Assert(0); + } /* Set up pulse timers */ PIOS_TIM_InitClock(&tim_1_cfg); diff --git a/flight/targets/boards/revoproto/firmware/pios_board_sim.c b/flight/targets/boards/revoproto/firmware/pios_board_sim.c index 61bc4d70f..064905ea2 100644 --- a/flight/targets/boards/revoproto/firmware/pios_board_sim.c +++ b/flight/targets/boards/revoproto/firmware/pios_board_sim.c @@ -149,8 +149,10 @@ void PIOS_Board_Init(void) { /* Initialize the alarms library */ AlarmsInitialize(); - /* Initialize the task monitor library */ - TaskMonitorInitialize(); + /* Initialize the task monitor */ + if (PIOS_TASK_MONITOR_Initialize(TASKINFO_RUNNING_NUMELEM)) { + PIOS_Assert(0); + } #if defined(PIOS_INCLUDE_COM) #if defined(PIOS_INCLUDE_TELEMETRY_RF) && 1 diff --git a/flight/targets/boards/simposix/firmware/Makefile b/flight/targets/boards/simposix/firmware/Makefile index 9086033ef..b5fc47e9e 100644 --- a/flight/targets/boards/simposix/firmware/Makefile +++ b/flight/targets/boards/simposix/firmware/Makefile @@ -56,6 +56,7 @@ MATHLIB = $(FLIGHTLIB)/math MATHLIBINC = $(FLIGHTLIB)/math PIOSPOSIX = $(PIOS)/posix PIOSCOMMON = $(PIOS)/posix +PIOSCORECOMMON = $(PIOS)/common PIOSCOMMONLIB = $(PIOS)/common/libraries BOOT = BOOTINC = @@ -85,13 +86,14 @@ SRC += $(FLIGHTLIB)/CoordinateConversions.c SRC += $(FLIGHTLIB)/fifo_buffer.c SRC += $(FLIGHTLIB)/WorldMagModel.c SRC += $(FLIGHTLIB)/insgps13state.c -SRC += $(FLIGHTLIB)/taskmonitor.c SRC += $(FLIGHTLIB)/paths.c SRC += $(FLIGHTLIB)/sanitycheck.c SRC += $(MATHLIB)/sin_lookup.c SRC += $(MATHLIB)/pid.c +SRC += $(PIOSCORECOMMON)/pios_task_monitor.c + ## PIOS Hardware include $(PIOS)/posix/library.mk diff --git a/flight/targets/boards/simposix/firmware/inc/openpilot.h b/flight/targets/boards/simposix/firmware/inc/openpilot.h index c77374ecc..a831f9a39 100644 --- a/flight/targets/boards/simposix/firmware/inc/openpilot.h +++ b/flight/targets/boards/simposix/firmware/inc/openpilot.h @@ -37,7 +37,6 @@ #include #include #include -#include #include #include "alarms.h" diff --git a/flight/targets/boards/simposix/firmware/inc/pios_config.h b/flight/targets/boards/simposix/firmware/inc/pios_config.h index c2413f6c0..a2ce66ba0 100644 --- a/flight/targets/boards/simposix/firmware/inc/pios_config.h +++ b/flight/targets/boards/simposix/firmware/inc/pios_config.h @@ -49,6 +49,7 @@ #define PIOS_INCLUDE_SERVO #define PIOS_INCLUDE_SPI #define PIOS_INCLUDE_SYS +#define PIOS_INCLUDE_TASK_MONITOR #define PIOS_INCLUDE_USART //#define PIOS_INCLUDE_USB #define PIOS_INCLUDE_USB_HID diff --git a/flight/targets/boards/simposix/firmware/pios_board.c b/flight/targets/boards/simposix/firmware/pios_board.c index 98f97823e..44f2e4b58 100644 --- a/flight/targets/boards/simposix/firmware/pios_board.c +++ b/flight/targets/boards/simposix/firmware/pios_board.c @@ -32,6 +32,7 @@ #include #include #include +#include /* * Pull in the board-specific static HW definitions. @@ -126,8 +127,10 @@ void PIOS_Board_Init(void) { /* Initialize the alarms library */ AlarmsInitialize(); - /* Initialize the task monitor library */ - TaskMonitorInitialize(); + /* Initialize the task monitor */ + if (PIOS_TASK_MONITOR_Initialize(TASKINFO_RUNNING_NUMELEM)) { + PIOS_Assert(0); + } /* Configure IO ports */ diff --git a/flight/uavobjects/eventdispatcher.c b/flight/uavobjects/eventdispatcher.c index e0ffbc99a..de74927c8 100644 --- a/flight/uavobjects/eventdispatcher.c +++ b/flight/uavobjects/eventdispatcher.c @@ -24,7 +24,9 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "openpilot.h" +#include + +#include // Private constants #if defined(PIOS_EVENTDISAPTCHER_QUEUE) @@ -281,7 +283,7 @@ static void eventTask() EventCallbackInfo evInfo; /* Must do this in task context to ensure that TaskMonitor has already finished its init */ - TaskMonitorAdd(TASKINFO_RUNNING_EVENTDISPATCHER, eventTaskHandle); + PIOS_TASK_MONITOR_RegisterTask(TASKINFO_RUNNING_EVENTDISPATCHER, eventTaskHandle); // Initialize time timeToNextUpdateMs = xTaskGetTickCount()*portTICK_RATE_MS; diff --git a/make/apps-defs.mk b/make/apps-defs.mk index 59b22ce1c..0b764e898 100644 --- a/make/apps-defs.mk +++ b/make/apps-defs.mk @@ -92,9 +92,11 @@ SRC += $(PIOSCOMMON)/pios_usb_desc_hid_cdc.c SRC += $(PIOSCOMMON)/pios_usb_desc_hid_only.c SRC += $(PIOSCOMMON)/pios_usb_util.c +## PIOS system code +SRC += $(PIOSCOMMON)/pios_task_monitor.c + ## Misc library functions SRC += $(FLIGHTLIB)/fifo_buffer.c -SRC += $(FLIGHTLIB)/taskmonitor.c SRC += $(FLIGHTLIB)/sanitycheck.c SRC += $(FLIGHTLIB)/CoordinateConversions.c SRC += $(MATHLIB)/sin_lookup.c From bb87e6390e6d8fbca05f36659eaca17259622c40 Mon Sep 17 00:00:00 2001 From: Werner Backes Date: Mon, 6 May 2013 12:00:58 +0200 Subject: [PATCH 4/7] Update ppm_fresh if we receive a new PPM packet in order to keep the rfm22b receiver supervisor happy. --- flight/pios/common/pios_rfm22b.c | 1 + 1 file changed, 1 insertion(+) diff --git a/flight/pios/common/pios_rfm22b.c b/flight/pios/common/pios_rfm22b.c index 203d8b1bb..a3542d946 100644 --- a/flight/pios/common/pios_rfm22b.c +++ b/flight/pios/common/pios_rfm22b.c @@ -2017,6 +2017,7 @@ static enum pios_radio_event radio_receivePacket(struct pios_rfm22b_dev *radio_d #endif #if defined(PIOS_INCLUDE_RFM22B_RCVR) ppm_output = true; + radio_dev->ppm_fresh = true; for (uint8_t i = 0; i < PIOS_RFM22B_RCVR_MAX_CHANNELS; ++i) { radio_dev->ppm_channel[i] = ppmp->channels[i]; } From 938ed589180d1cf02005c3178296b65bf7f88fdf Mon Sep 17 00:00:00 2001 From: Werner Backes Date: Mon, 6 May 2013 14:20:53 +0200 Subject: [PATCH 5/7] Corrected timout calculation formula. --- flight/pios/common/pios_rfm22b_rcvr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flight/pios/common/pios_rfm22b_rcvr.c b/flight/pios/common/pios_rfm22b_rcvr.c index 3ea942103..e718e8481 100644 --- a/flight/pios/common/pios_rfm22b_rcvr.c +++ b/flight/pios/common/pios_rfm22b_rcvr.c @@ -102,7 +102,7 @@ static void PIOS_RFM22B_RCVR_Supervisor(uint32_t rcvr_id) { } // RTC runs at 625Hz. - if (++(rfm22b_dev->ppm_supv_timer) < (PIOS_RFM22B_RCVR_TIMEOUT_MS * 1000 / 625)) { + if (++(rfm22b_dev->ppm_supv_timer) < (PIOS_RFM22B_RCVR_TIMEOUT_MS * 625 / 1000)) { return; } rfm22b_dev->ppm_supv_timer = 0; From cc38ba0bdbde5a22320d67122d65676b5362da91 Mon Sep 17 00:00:00 2001 From: Werner Backes Date: Mon, 6 May 2013 14:26:25 +0200 Subject: [PATCH 6/7] Revert 8fa793 because it's obsoleted by 938ed5. --- flight/targets/boards/revolution/pios_board.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flight/targets/boards/revolution/pios_board.h b/flight/targets/boards/revolution/pios_board.h index ccf1effca..ef1434754 100644 --- a/flight/targets/boards/revolution/pios_board.h +++ b/flight/targets/boards/revolution/pios_board.h @@ -228,7 +228,7 @@ extern uint32_t pios_packet_handler; #define PIOS_RCVR_MAX_DEVS 3 #define PIOS_RCVR_MAX_CHANNELS 12 #define PIOS_GCSRCVR_TIMEOUT_MS 100 -#define PIOS_RFM22B_RCVR_TIMEOUT_MS 150 +#define PIOS_RFM22B_RCVR_TIMEOUT_MS 200 //------------------------- // Receiver PPM input From b76df471ee5bc0dace9b78383f78b457ff6283c7 Mon Sep 17 00:00:00 2001 From: Corvus Corax Date: Fri, 10 May 2013 19:53:51 +0200 Subject: [PATCH 7/7] bugfix on revo proto. STM32F4 A revision has a hardware bug and cannot do flash prefetching properly --- .../Device/ST/STM32F4xx/Source/revoproto/system_stm32f4xx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flight/pios/stm32f4xx/libraries/CMSIS2/Device/ST/STM32F4xx/Source/revoproto/system_stm32f4xx.c b/flight/pios/stm32f4xx/libraries/CMSIS2/Device/ST/STM32F4xx/Source/revoproto/system_stm32f4xx.c index f98b4a14b..bb7776d4b 100644 --- a/flight/pios/stm32f4xx/libraries/CMSIS2/Device/ST/STM32F4xx/Source/revoproto/system_stm32f4xx.c +++ b/flight/pios/stm32f4xx/libraries/CMSIS2/Device/ST/STM32F4xx/Source/revoproto/system_stm32f4xx.c @@ -393,7 +393,7 @@ static void SetSysClock(void) } /* Configure Flash prefetch, Instruction cache, Data cache and wait state */ - FLASH->ACR = FLASH_ACR_PRFTEN | FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS; + FLASH->ACR = FLASH_ACR_ICEN |FLASH_ACR_DCEN |FLASH_ACR_LATENCY_5WS; /* Select the main PLL as system clock source */ RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));