2 ******************************************************************************
4 * @file instrumentation.c
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2014.
6 * @brief Instrumentation infrastructure
7 * UAVObject wrapper layer for PiOS instrumentation
8 * @see The GNU Public License (GPL) Version 3
10 *****************************************************************************/
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include <openpilot.h>
28 #include <instrumentation.h>
29 #include <pios_instrumentation.h>
31 static uint8_t publishedCountersInstances
= 0;
32 static void counterCallback(const pios_perf_counter_t
*counter
, const int8_t index
, void *context
);
33 static xSemaphoreHandle sem
;
34 void InstrumentationInit()
36 PerfCounterInitialize();
37 publishedCountersInstances
= 1;
38 vSemaphoreCreateBinary(sem
);
41 void InstrumentationPublishAllCounters()
43 if (xSemaphoreTake(sem
, 0) != pdTRUE
) {
46 PIOS_Instrumentation_ForEachCounter(&counterCallback
, NULL
);
50 void counterCallback(const pios_perf_counter_t
*counter
, const int8_t index
, __attribute__((unused
)) void *context
)
52 if (publishedCountersInstances
< index
+ 1) {
53 PerfCounterCreateInstance();
54 publishedCountersInstances
++;
57 data
.Id
= counter
->id
;
58 data
.Counter
.Max
= counter
->max
;
59 data
.Counter
.Min
= counter
->min
;
60 data
.Counter
.Value
= counter
->value
;
61 PerfCounterInstSet(index
, &data
);