2011-01-14 02:38:19 +01:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
* @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];
|
2011-06-13 06:04:35 +02:00
|
|
|
static uint32_t lastMonitorTime;
|
2011-01-14 02:38:19 +01:00
|
|
|
|
|
|
|
// Private functions
|
|
|
|
|
|
|
|
/**
|
2011-06-13 06:04:35 +02:00
|
|
|
* Initialize library
|
2011-01-14 02:38:19 +01:00
|
|
|
*/
|
|
|
|
int32_t TaskMonitorInitialize(void)
|
|
|
|
{
|
|
|
|
lock = xSemaphoreCreateRecursiveMutex();
|
|
|
|
memset(handles, 0, sizeof(xTaskHandle)*TASKINFO_RUNNING_NUMELEM);
|
2011-06-17 16:50:10 +02:00
|
|
|
lastMonitorTime = 0;
|
Final step: lot of small fixes, last commit in this commit series
This is the first cleanup pass through makefiles and pios.
Probably it is difficult to track changes due to the nature of them.
I would recommend to look at resulting files and compiled code instead.
NOTE: original branch was rebased and lot of conflicts were fixed on
the way. So do not expect that every commit in this series will be
buildable (unlike original branch). Only final result was tested.
The main goal was to remove as much duplication of code (and copy/paste
errors) as possible, moving common parts out of Makefiles. It still is
not perfect, and mostly no code changes made - Makefiles and #ifdefs only.
But please while testing make sure that all code works as before, and no
modules/options are missed by accident.
Brief list of changes:
- Moved common parts of Makefiles into the set of *.mk files.
- Changed method of passing common vars from top Makefile to lower ones.
- Some pios cleanup, mostly #ifdefs, and all pios_config.h files.
- Many obsolete files removed (for instance, AHRS files, op_config.h).
- Many obsolete or unused macros removed or fixed/renamed (ALL_DIGNOSTICS).
- Unified pios_config.h template. Please don't remove lines for board
configs, only comment/uncomment them. Adding new PIOS options, please
propagate them to all board files keeping the same order.
- Some formatting, spacing, indentation (no line endings change yet).
- Some cosmetic fixes (no more C:\X\Y\filename.c printings on Windows).
- Added some library.mk files to move libs into AR achives later.
- EntireFlash target now uses cross-platform python script to generate bin
files. So it works on all supported platforms: Linux, OSX, Windows.
- Top level packaging is completely rewritten. Now it is a part of top
Makefile. As such, all dependencies are checked and accounted, no
more 'make -j' problems should occur.
- Default GCS_BUILD_CONF is release now, may be changed if necessary
using 'make GCS_BUILD_CONF=debug gcs'.
- GCS build paths are separated into debug and release, so no more obj
file clashes. Packaging system supports only release builds.
- New target is introduced: 'clean_package'. Now 'make package' does not
clean build directory. Use clean_package instead for distributable builds.
- Targets like 'all', 'opfw_resource', etc now will print extra contex
in parallel builds too.
- If any of 'package', 'clean_package', 'opfw_resource' targets are given
on command line, GCS build will depend on the resource, so all fw_*.opfw
targets will be built and embedded into GCS. By default GCS does not
depend on resource, and will be built w/o firmware (unless the resource
files already exist and the Qt resource file is generated).
- fw_simposix (ELF executable) is now packaged for linux. Run'n'play!
- Make help is refined and is now up to date.
Still broken:
- UnitTests, should be fixed
- SimPosix: buildable, but should be reworked.
Next planned passes to do:
- toolchain bootstrapping and packaging (including windows - WIP)
- CMSIS/StdPeriph lib cleanup
- more PIOS cleanup
- move libs into AR archives to save build time
- sim targets refactir and cleanup
- move android-related directories under <top>/android
- unit test targets fix
- source code line ending changes (there are many different, were not changed)
- coding style
Merging this, please use --no-ff git option to make it the real commit point
Conflicts:
A lot of... :-)
2013-03-24 12:02:08 +01:00
|
|
|
#ifdef DIAG_TASKS
|
2011-06-13 06:04:35 +02:00
|
|
|
lastMonitorTime = portGET_RUN_TIME_COUNTER_VALUE();
|
2011-06-17 16:50:10 +02:00
|
|
|
#endif
|
2011-01-14 02:38:19 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-06-13 06:04:35 +02:00
|
|
|
* Register a task handle with the library
|
2011-01-14 02:38:19 +01:00
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-16 00:02:38 +01:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-27 20:43:41 +02:00
|
|
|
/**
|
|
|
|
* Query if a task is running
|
|
|
|
*/
|
|
|
|
bool TaskMonitorQueryRunning(TaskInfoRunningElem task)
|
|
|
|
{
|
|
|
|
if (task < TASKINFO_RUNNING_NUMELEM && handles[task] != 0)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-01-14 02:38:19 +01:00
|
|
|
/**
|
2011-06-13 06:04:35 +02:00
|
|
|
* Update the status of all tasks
|
2011-01-14 02:38:19 +01:00
|
|
|
*/
|
|
|
|
void TaskMonitorUpdateAll(void)
|
|
|
|
{
|
Final step: lot of small fixes, last commit in this commit series
This is the first cleanup pass through makefiles and pios.
Probably it is difficult to track changes due to the nature of them.
I would recommend to look at resulting files and compiled code instead.
NOTE: original branch was rebased and lot of conflicts were fixed on
the way. So do not expect that every commit in this series will be
buildable (unlike original branch). Only final result was tested.
The main goal was to remove as much duplication of code (and copy/paste
errors) as possible, moving common parts out of Makefiles. It still is
not perfect, and mostly no code changes made - Makefiles and #ifdefs only.
But please while testing make sure that all code works as before, and no
modules/options are missed by accident.
Brief list of changes:
- Moved common parts of Makefiles into the set of *.mk files.
- Changed method of passing common vars from top Makefile to lower ones.
- Some pios cleanup, mostly #ifdefs, and all pios_config.h files.
- Many obsolete files removed (for instance, AHRS files, op_config.h).
- Many obsolete or unused macros removed or fixed/renamed (ALL_DIGNOSTICS).
- Unified pios_config.h template. Please don't remove lines for board
configs, only comment/uncomment them. Adding new PIOS options, please
propagate them to all board files keeping the same order.
- Some formatting, spacing, indentation (no line endings change yet).
- Some cosmetic fixes (no more C:\X\Y\filename.c printings on Windows).
- Added some library.mk files to move libs into AR achives later.
- EntireFlash target now uses cross-platform python script to generate bin
files. So it works on all supported platforms: Linux, OSX, Windows.
- Top level packaging is completely rewritten. Now it is a part of top
Makefile. As such, all dependencies are checked and accounted, no
more 'make -j' problems should occur.
- Default GCS_BUILD_CONF is release now, may be changed if necessary
using 'make GCS_BUILD_CONF=debug gcs'.
- GCS build paths are separated into debug and release, so no more obj
file clashes. Packaging system supports only release builds.
- New target is introduced: 'clean_package'. Now 'make package' does not
clean build directory. Use clean_package instead for distributable builds.
- Targets like 'all', 'opfw_resource', etc now will print extra contex
in parallel builds too.
- If any of 'package', 'clean_package', 'opfw_resource' targets are given
on command line, GCS build will depend on the resource, so all fw_*.opfw
targets will be built and embedded into GCS. By default GCS does not
depend on resource, and will be built w/o firmware (unless the resource
files already exist and the Qt resource file is generated).
- fw_simposix (ELF executable) is now packaged for linux. Run'n'play!
- Make help is refined and is now up to date.
Still broken:
- UnitTests, should be fixed
- SimPosix: buildable, but should be reworked.
Next planned passes to do:
- toolchain bootstrapping and packaging (including windows - WIP)
- CMSIS/StdPeriph lib cleanup
- more PIOS cleanup
- move libs into AR archives to save build time
- sim targets refactir and cleanup
- move android-related directories under <top>/android
- unit test targets fix
- source code line ending changes (there are many different, were not changed)
- coding style
Merging this, please use --no-ff git option to make it the real commit point
Conflicts:
A lot of... :-)
2013-03-24 12:02:08 +01:00
|
|
|
#ifdef DIAG_TASKS
|
2011-01-14 02:38:19 +01:00
|
|
|
TaskInfoData data;
|
|
|
|
int n;
|
2012-01-16 00:02:38 +01:00
|
|
|
|
2011-01-14 02:38:19 +01:00
|
|
|
// Lock
|
|
|
|
xSemaphoreTakeRecursive(lock, portMAX_DELAY);
|
2012-01-16 00:02:38 +01:00
|
|
|
|
2011-06-13 06:04:35 +02:00
|
|
|
#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
|
|
|
|
|
2011-01-14 02:38:19 +01:00
|
|
|
// 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;
|
2012-03-12 02:49:54 +01:00
|
|
|
#endif
|
2011-06-13 06:04:35 +02:00
|
|
|
#if ( configGENERATE_RUN_TIME_STATS == 1 )
|
|
|
|
/* Generate run time stats */
|
|
|
|
data.RunningTime[n] = uxTaskGetRunTime(handles[n]) / deltaTime;
|
|
|
|
#endif
|
|
|
|
|
2011-01-14 02:38:19 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
data.Running[n] = TASKINFO_RUNNING_FALSE;
|
|
|
|
data.StackRemaining[n] = 0;
|
2011-06-13 06:04:35 +02:00
|
|
|
data.RunningTime[n] = 0;
|
2011-01-14 02:38:19 +01:00
|
|
|
}
|
|
|
|
}
|
2012-01-16 00:02:38 +01:00
|
|
|
|
2011-01-14 02:38:19 +01:00
|
|
|
// Update object
|
|
|
|
TaskInfoSet(&data);
|
2012-01-16 00:02:38 +01:00
|
|
|
|
2011-01-14 02:38:19 +01:00
|
|
|
// Done
|
|
|
|
xSemaphoreGiveRecursive(lock);
|
2011-06-17 16:50:10 +02:00
|
|
|
#endif
|
2011-01-14 02:38:19 +01:00
|
|
|
}
|