Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures 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 
26 #ifdef USE_USB_SERIAL
27 #include "mcu_periph/usb_serial.h"
28 #endif
29 
31 struct SysMon sys_mon;
32 
33 /* Local vars */
44 
45 void init_sysmon(void) {
46  sys_mon.cpu_load = 0;
48  sys_mon.periodic_time_min = 0xFFFF;
51  sys_mon.periodic_cycle_min = 0xFFFF;
54 
55  n_periodic = 0;
56  n_event = 0;
59  sum_time_event = 0;
60  min_time_event = ~0;
61  sum_n_event = 0;
62  periodic_timer = 0;
63 }
64 
65 #include "mcu_periph/uart.h"
66 #include "messages.h"
68 
71  if (n_periodic > 0) {
76 
77  DOWNLINK_SEND_SYS_MON(DefaultChannel, DefaultDevice, &sys_mon.periodic_time,
81  &sys_mon.cpu_load);
82  }
83 
84  n_periodic = 0;
87  sum_n_event = 0;
88  sys_mon.periodic_time_min = 0xFFFF;
90  sys_mon.periodic_cycle_min = 0xFFFF;
92 }
93 
94 void periodic_sysmon(void) {
96  uint32_t periodic_usec = SysTimeTimer(periodic_timer);
98  sum_time_periodic += periodic_usec;
99 
100  /* only periodic cycle : periodic_cycle = periodic_usec - sum_time_event; */
101  periodic_cycle = periodic_usec - n_event * min_time_event;
103 
104  /* remember min and max periodic times */
105  if (periodic_usec < sys_mon.periodic_time_min)
106  sys_mon.periodic_time_min = periodic_usec;
107  if (periodic_usec > sys_mon.periodic_time_max)
108  sys_mon.periodic_time_max = periodic_usec;
109 
110  /* remember min and max periodic cycle times */
115 
116  n_periodic++;
117  sum_n_event += n_event;
118  n_event = 0;
119  sum_time_event = 0;
120 }
121 
122 void event_sysmon(void) {
124  if (n_event > 0) {
126  if (t < min_time_event)
127  min_time_event = t;
128  sum_time_event += t;
129  }
131  n_event++;
132 }
133 
uint8_t cpu_load
Definition: sys_mon.h:35
unsigned short uint16_t
Definition: types.h:16
static uint32_t sum_cycle_periodic
in usec
Definition: sys_mon.c:40
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
uint16_t periodic_time_max
in usec
Definition: sys_mon.h:38
static uint16_t n_event
Definition: sys_mon.c:35
void periodic_report_sysmon(void)
Report system status.
Definition: sys_mon.c:69
uint16_t event_number
Definition: sys_mon.h:42
static uint16_t n_periodic
Definition: sys_mon.c:34
void init_sysmon(void)
Init system monitoring.
Definition: sys_mon.c:45
void periodic_sysmon(void)
Analyse periodic calls Should be run at the highest frequency.
Definition: sys_mon.c:94
uint16_t periodic_time_min
in usec
Definition: sys_mon.h:37
static uint32_t periodic_cycle
Definition: sys_mon.c:37
uint16_t periodic_cycle_max
in usec
Definition: sys_mon.h:41
uint16_t periodic_cycle
in usec
Definition: sys_mon.h:39
#define Max(x, y)
static uint32_t sum_time_periodic
in usec
Definition: sys_mon.c:39
Architecture independent timing functions.
void event_sysmon(void)
Analyse event calls.
Definition: sys_mon.c:122
static uint32_t sum_n_event
Definition: sys_mon.c:43
unsigned long uint32_t
Definition: types.h:18
uint16_t periodic_cycle_min
in usec
Definition: sys_mon.h:40
struct SysMon sys_mon
Global system monitor data (averaged over 1 sec)
Definition: sys_mon.c:31
static uint32_t periodic_timer
Definition: sys_mon.c:36
#define SysTimeTimer(_t)
Definition: sys_time.h:199
static uint32_t sum_time_event
in usec
Definition: sys_mon.c:41
static uint32_t event_timer
Definition: sys_mon.c:38
System monitoring return cpu load, average exec time, ...
#define SysTimeTimerStart(_t)
Definition: sys_time.h:198
uint16_t periodic_time
in usec
Definition: sys_mon.h:36
arch independent USB API
static uint32_t min_time_event
in usec
Definition: sys_mon.c:42
Definition: sys_mon.h:34