Paparazzi UAS  v5.15_devel-230-gc96ce27
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  */
28 #include "core/sys_mon.h"
30 #include "mcu_periph/sys_time.h"
31 
32 #include "mcu_periph/uart.h"
33 #include "pprzlink/messages.h"
35 
37 struct SysMon sys_mon;
38 
39 /* Local vars */
50 
51 void init_sysmon(void)
52 {
53  sys_mon.cpu_load = 0;
55  sys_mon.periodic_time_min = 0xFFFF;
58  sys_mon.periodic_cycle_min = 0xFFFF;
61  sys_mon.cpu_time = 0;
62 
63  n_periodic = 0;
64  n_event = 0;
67  sum_time_event = 0;
68  min_time_event = ~0;
69  sum_n_event = 0;
70  periodic_timer = 0;
71 }
72 
74 {
76  if (n_periodic > 0) {
82 
83  DOWNLINK_SEND_SYS_MON(DefaultChannel, DefaultDevice, &sys_mon.periodic_time,
88  }
89 
90  n_periodic = 0;
93  sum_n_event = 0;
94  sys_mon.periodic_time_min = 0xFFFF;
96  sys_mon.periodic_cycle_min = 0xFFFF;
98 }
99 
100 void periodic_sysmon(void)
101 {
103  uint32_t periodic_usec = SysTimeTimer(periodic_timer);
105  sum_time_periodic += periodic_usec;
106 
107  /* only periodic cycle : periodic_cycle = periodic_usec - sum_time_event; */
108  periodic_cycle = periodic_usec - n_event * min_time_event;
110 
111  /* remember min and max periodic times */
112  if (periodic_usec < sys_mon.periodic_time_min) {
113  sys_mon.periodic_time_min = periodic_usec;
114  }
115  if (periodic_usec > sys_mon.periodic_time_max) {
116  sys_mon.periodic_time_max = periodic_usec;
117  }
118 
119  /* remember min and max periodic cycle times */
122  }
125  }
126 
127  n_periodic++;
128  sum_n_event += n_event;
129  n_event = 0;
130  sum_time_event = 0;
131 }
132 
133 void event_sysmon(void)
134 {
136  if (n_event > 0) {
138  if (t < min_time_event) {
139  min_time_event = t;
140  }
141  sum_time_event += t;
142  }
144  n_event++;
145 }
146 
unsigned short uint16_t
Definition: types.h:16
static uint32_t sum_cycle_periodic
in usec
Definition: sys_mon.c:46
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
static uint16_t n_event
Definition: sys_mon.c:41
void periodic_report_sysmon(void)
Report system status.
Definition: sys_mon.c:73
uint16_t periodic_cycle_max
in usec
static uint16_t n_periodic
Definition: sys_mon.c:40
void init_sysmon(void)
Init system monitoring.
Definition: sys_mon.c:51
uint8_t cpu_load
void periodic_sysmon(void)
Analyse periodic calls Should be run at the highest frequency.
Definition: sys_mon.c:100
static float get_sys_time_float(void)
Get the time in seconds since startup.
Definition: sys_time.h:129
uint16_t periodic_time_max
in usec
static uint32_t periodic_cycle
Definition: sys_mon.c:43
static uint32_t sum_time_periodic
in usec
Definition: sys_mon.c:45
Architecture independent timing functions.
void event_sysmon(void)
Analyse event calls.
Definition: sys_mon.c:133
static uint32_t sum_n_event
Definition: sys_mon.c:49
unsigned long uint32_t
Definition: types.h:18
uint16_t periodic_time_min
in usec
struct SysMon sys_mon
Global system monitor data (averaged over 1 sec)
Definition: sys_mon.c:37
#define Max(x, y)
Definition: main_fbw.c:53
static uint32_t periodic_timer
Definition: sys_mon.c:42
#define SysTimeTimer(_t)
Definition: sys_time.h:219
static uint32_t sum_time_event
in usec
Definition: sys_mon.c:47
uint16_t periodic_cycle
in usec
static uint32_t event_timer
Definition: sys_mon.c:44
System monitoring common header return cpu load, average exec time, ...
float cpu_time
#define SysTimeTimerStart(_t)
Definition: sys_time.h:218
uint16_t periodic_time
in usec
uint16_t periodic_cycle_min
in usec
uint16_t event_number
static uint32_t min_time_event
in usec
Definition: sys_mon.c:48