Paparazzi UAS  v5.8.2_stable-0-g6260b7c
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
sys_mon.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010 Gautier Hattenberger
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  *
21  */
22 
23 #include "core/sys_mon.h"
24 #include "mcu_periph/sys_time.h"
25 
27 struct SysMon sys_mon;
28 
29 /* Local vars */
40 
41 void init_sysmon(void)
42 {
43  sys_mon.cpu_load = 0;
45  sys_mon.periodic_time_min = 0xFFFF;
48  sys_mon.periodic_cycle_min = 0xFFFF;
51 
52  n_periodic = 0;
53  n_event = 0;
56  sum_time_event = 0;
57  min_time_event = ~0;
58  sum_n_event = 0;
59  periodic_timer = 0;
60 }
61 
62 #include "mcu_periph/uart.h"
63 #include "messages.h"
65 
67 {
69  if (n_periodic > 0) {
74 
75  DOWNLINK_SEND_SYS_MON(DefaultChannel, DefaultDevice, &sys_mon.periodic_time,
79  &sys_mon.cpu_load);
80  }
81 
82  n_periodic = 0;
85  sum_n_event = 0;
86  sys_mon.periodic_time_min = 0xFFFF;
88  sys_mon.periodic_cycle_min = 0xFFFF;
90 }
91 
92 void periodic_sysmon(void)
93 {
95  uint32_t periodic_usec = SysTimeTimer(periodic_timer);
97  sum_time_periodic += periodic_usec;
98 
99  /* only periodic cycle : periodic_cycle = periodic_usec - sum_time_event; */
100  periodic_cycle = periodic_usec - n_event * min_time_event;
102 
103  /* remember min and max periodic times */
104  if (periodic_usec < sys_mon.periodic_time_min) {
105  sys_mon.periodic_time_min = periodic_usec;
106  }
107  if (periodic_usec > sys_mon.periodic_time_max) {
108  sys_mon.periodic_time_max = periodic_usec;
109  }
110 
111  /* remember min and max periodic cycle times */
114  }
117  }
118 
119  n_periodic++;
120  sum_n_event += n_event;
121  n_event = 0;
122  sum_time_event = 0;
123 }
124 
125 void event_sysmon(void)
126 {
128  if (n_event > 0) {
130  if (t < min_time_event) {
131  min_time_event = t;
132  }
133  sum_time_event += t;
134  }
136  n_event++;
137 }
138 
unsigned short uint16_t
Definition: types.h:16
static uint32_t sum_cycle_periodic
in usec
Definition: sys_mon.c:36
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
static uint16_t n_event
Definition: sys_mon.c:31
void periodic_report_sysmon(void)
Report system status.
Definition: sys_mon.c:66
uint16_t periodic_time_max
in usec
Definition: sys_mon.h:38
static uint16_t n_periodic
Definition: sys_mon.c:30
uint16_t periodic_time_min
in usec
Definition: sys_mon.h:37
void init_sysmon(void)
Init system monitoring.
Definition: sys_mon.c:41
void periodic_sysmon(void)
Analyse periodic calls Should be run at the highest frequency.
Definition: sys_mon.c:92
Definition: sys_mon.h:34
uint16_t periodic_cycle_max
in usec
Definition: sys_mon.h:41
static uint32_t periodic_cycle
Definition: sys_mon.c:33
#define Max(x, y)
static uint32_t sum_time_periodic
in usec
Definition: sys_mon.c:35
Architecture independent timing functions.
void event_sysmon(void)
Analyse event calls.
Definition: sys_mon.c:125
static uint32_t sum_n_event
Definition: sys_mon.c:39
unsigned long uint32_t
Definition: types.h:18
uint16_t periodic_cycle
in usec
Definition: sys_mon.h:39
struct SysMon sys_mon
Global system monitor data (averaged over 1 sec)
Definition: sys_mon.c:27
static uint32_t periodic_timer
Definition: sys_mon.c:32
#define SysTimeTimer(_t)
Definition: sys_time.h:214
uint16_t periodic_time
in usec
Definition: sys_mon.h:36
static uint32_t sum_time_event
in usec
Definition: sys_mon.c:37
uint16_t periodic_cycle_min
in usec
Definition: sys_mon.h:40
static uint32_t event_timer
Definition: sys_mon.c:34
System monitoring return cpu load, average exec time, ...
uint16_t event_number
Definition: sys_mon.h:42
#define SysTimeTimerStart(_t)
Definition: sys_time.h:213
uint8_t cpu_load
Definition: sys_mon.h:35
static uint32_t min_time_event
in usec
Definition: sys_mon.c:38