Paparazzi UAS  v4.0.4_stable-3-gf39211a
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
sys_mon.c
Go to the documentation of this file.
1 /*
2  * $Id: $
3  *
4  * Copyright (C) 2010 Gautier Hattenberger
5  *
6  * This file is part of paparazzi.
7  *
8  * paparazzi is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2, or (at your option)
11  * any later version.
12  *
13  * paparazzi is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with paparazzi; see the file COPYING. If not, write to
20  * the Free Software Foundation, 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  *
23  */
24 
25 #include "core/sys_mon.h"
26 #include "mcu_periph/sys_time.h"
27 
28 #ifdef USE_USB_SERIAL
29 #include "mcu_periph/usb_serial.h"
30 #endif
31 
32 /* Global system monitor data (averaged over 1 sec) */
33 struct SysMon sys_mon;
34 
35 /* Local vars */
46 
47 void init_sysmon(void) {
48  sys_mon.cpu_load = 0;
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"
67 #ifndef DOWNLINK_DEVICE
68 #define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
69 #endif
71 
74  if (n_periodic > 0) {
79 
81  }
82 
83  n_periodic = 0;
86  sum_n_event = 0;
87  sys_mon.periodic_cycle_min = 0xFFFF;
89 }
90 
91 void periodic_sysmon(void) {
93  uint32_t periodic_usec = SysTimeTimer(periodic_timer);
95  sum_time_periodic += periodic_usec;
96 
97  /* only periodic cycle : periodic_cycle = periodic_usec - sum_time_event; */
98  periodic_cycle = periodic_usec - n_event * min_time_event;
100 
101  /* remember min and max periodic cycle times */
106 
107  n_periodic++;
108  sum_n_event += n_event;
109  n_event = 0;
110  sum_time_event = 0;
111 }
112 
113 void event_sysmon(void) {
115  if (n_event > 0) {
117  if (t < min_time_event)
118  min_time_event = t;
119  sum_time_event += t;
120  }
122  n_event++;
123 }
124 
uint8_t cpu_load
Definition: sys_mon.h:37
unsigned short uint16_t
Definition: types.h:16
uint32_t sum_cycle_periodic
in usec
Definition: sys_mon.c:42
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
uint16_t n_event
Definition: sys_mon.c:37
void periodic_report_sysmon(void)
Report system status.
Definition: sys_mon.c:72
uint16_t event_number
Definition: sys_mon.h:42
uint16_t n_periodic
Definition: sys_mon.c:36
void init_sysmon(void)
Init system monitoring.
Definition: sys_mon.c:47
void periodic_sysmon(void)
Analyse periodic calls Should be run at the highest frequency.
Definition: sys_mon.c:91
uint32_t periodic_cycle
Definition: sys_mon.c:39
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)
uint32_t sum_time_periodic
in usec
Definition: sys_mon.c:41
Architecture independent timing functions.
void event_sysmon(void)
Analyse event calls.
Definition: sys_mon.c:113
uint32_t sum_n_event
Definition: sys_mon.c:45
unsigned long uint32_t
Definition: types.h:18
uint16_t periodic_cycle_min
in usec
Definition: sys_mon.h:40
#define SysTimeTimer(_t)
Definition: sys_time_arch.h:71
struct SysMon sys_mon
Definition: sys_mon.c:33
uint32_t periodic_timer
Definition: sys_mon.c:38
uint32_t sum_time_event
in usec
Definition: sys_mon.c:43
#define SysTimeTimerStart(_t)
Definition: sys_time_arch.h:70
uint32_t event_timer
Definition: sys_mon.c:40
System monitoring return cpu load, average exec time, ...
uint16_t periodic_time
in usec
Definition: sys_mon.h:38
arch independent USB API
uint32_t min_time_event
in usec
Definition: sys_mon.c:44
Definition: sys_mon.h:36