Paparazzi UAS  v5.0.5_stable-7-g4b8bbb7
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 
30 /* Global system monitor data (averaged over 1 sec) */
31 struct SysMon sys_mon;
32 
33 /* Local vars */
44 
45 void init_sysmon(void) {
46  sys_mon.cpu_load = 0;
49  sys_mon.periodic_cycle_min = 0xFFFF;
52 
53  n_periodic = 0;
54  n_event = 0;
57  sum_time_event = 0;
58  min_time_event = ~0;
59  sum_n_event = 0;
60  periodic_timer = 0;
61 }
62 
63 #include "mcu_periph/uart.h"
64 #include "messages.h"
65 #ifndef DOWNLINK_DEVICE
66 #define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
67 #endif
69 
72  if (n_periodic > 0) {
77 
79  }
80 
81  n_periodic = 0;
84  sum_n_event = 0;
85  sys_mon.periodic_cycle_min = 0xFFFF;
87 }
88 
89 void periodic_sysmon(void) {
91  uint32_t periodic_usec = SysTimeTimer(periodic_timer);
93  sum_time_periodic += periodic_usec;
94 
95  /* only periodic cycle : periodic_cycle = periodic_usec - sum_time_event; */
96  periodic_cycle = periodic_usec - n_event * min_time_event;
98 
99  /* remember min and max periodic cycle times */
104 
105  n_periodic++;
106  sum_n_event += n_event;
107  n_event = 0;
108  sum_time_event = 0;
109 }
110 
111 void event_sysmon(void) {
113  if (n_event > 0) {
115  if (t < min_time_event)
116  min_time_event = t;
117  sum_time_event += t;
118  }
120  n_event++;
121 }
122 
uint8_t cpu_load
Definition: sys_mon.h:35
unsigned short uint16_t
Definition: types.h:16
uint32_t sum_cycle_periodic
in usec
Definition: sys_mon.c:40
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
uint16_t n_event
Definition: sys_mon.c:35
void periodic_report_sysmon(void)
Report system status.
Definition: sys_mon.c:70
uint16_t event_number
Definition: sys_mon.h:40
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:89
uint32_t periodic_cycle
Definition: sys_mon.c:37
uint16_t periodic_cycle_max
in usec
Definition: sys_mon.h:39
uint16_t periodic_cycle
in usec
Definition: sys_mon.h:37
#define Max(x, y)
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:111
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:38
#define SysTimeTimer(_t)
Definition: sys_time_arch.h:65
struct SysMon sys_mon
Definition: sys_mon.c:31
uint32_t periodic_timer
Definition: sys_mon.c:36
uint32_t sum_time_event
in usec
Definition: sys_mon.c:41
#define SysTimeTimerStart(_t)
Definition: sys_time_arch.h:64
uint32_t event_timer
Definition: sys_mon.c:38
System monitoring return cpu load, average exec time, ...
uint16_t periodic_time
in usec
Definition: sys_mon.h:36
arch independent USB API
uint32_t min_time_event
in usec
Definition: sys_mon.c:42
Definition: sys_mon.h:34