paparazzi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[paparazzi-commits] [5182] added calculation of cpu_load in booz.


From: Felix Ruess
Subject: [paparazzi-commits] [5182] added calculation of cpu_load in booz.
Date: Wed, 28 Jul 2010 01:07:52 +0000

Revision: 5182
          http://svn.sv.gnu.org/viewvc/?view=rev&root=paparazzi&revision=5182
Author:   flixr
Date:     2010-07-28 01:07:51 +0000 (Wed, 28 Jul 2010)
Log Message:
-----------
added calculation of cpu_load in booz. Define CALC_CPU_LOAD to use it

Modified Paths:
--------------
    paparazzi3/trunk/conf/airframes/booz2_flixr.xml
    paparazzi3/trunk/conf/messages.xml
    paparazzi3/trunk/sw/airborne/booz/booz2_main.c
    paparazzi3/trunk/sw/airborne/booz/booz2_telemetry.h

Modified: paparazzi3/trunk/conf/airframes/booz2_flixr.xml
===================================================================
--- paparazzi3/trunk/conf/airframes/booz2_flixr.xml     2010-07-28 01:07:45 UTC 
(rev 5181)
+++ paparazzi3/trunk/conf/airframes/booz2_flixr.xml     2010-07-28 01:07:51 UTC 
(rev 5182)
@@ -245,6 +245,8 @@
         ap.srcs += $(SRC_BOOZ_ARCH)/booz2_pwm_hw.c
         sim.srcs += $(SRC_BOOZ_SIM)/booz2_pwm_hw.c
 
+        ap.CFLAGS += -DCALC_CPU_LOAD
+
         ap.CFLAGS += -DUSEMODULES
         sim.CFLAGS += -DUSEMODULES
 

Modified: paparazzi3/trunk/conf/messages.xml
===================================================================
--- paparazzi3/trunk/conf/messages.xml  2010-07-28 01:07:45 UTC (rev 5181)
+++ paparazzi3/trunk/conf/messages.xml  2010-07-28 01:07:51 UTC (rev 5182)
@@ -1458,7 +1458,9 @@
       <field name="ap_h_mode"    type="uint8" 
values="KILL|RATE|ATTITUDE|HOVER|NAV"/>
       <field name="ap_v_mode"    type="uint8" 
values="KILL|RC_DIRECT|RC_CLIMB|CLIMB|HOVER|NAV"/>
       <field name="vsupply"      type="uint8" unit="decivolt"/>
-      <field name="cpu_time"     type="uint16" unit="s"></field>
+      <field name="cpu_time"     type="uint16" unit="s"/>
+      <field name="cpu_load_avg" type="uint8" unit="%"/>
+      <field name="cpu_load_max" type="uint8" unit="%"/>
   </message>
 
   <message name="BOOZ_SIM_RPMS" id="239">

Modified: paparazzi3/trunk/sw/airborne/booz/booz2_main.c
===================================================================
--- paparazzi3/trunk/sw/airborne/booz/booz2_main.c      2010-07-28 01:07:45 UTC 
(rev 5181)
+++ paparazzi3/trunk/sw/airborne/booz/booz2_main.c      2010-07-28 01:07:51 UTC 
(rev 5182)
@@ -68,6 +68,8 @@
 #endif
 
 uint32_t startup_counter = 0;
+uint8_t cpu_load_avg = 0;
+uint8_t cpu_load_max = 0;
 
 static inline void on_gyro_accel_event( void );
 static inline void on_baro_event( void );
@@ -75,16 +77,49 @@
 static inline void on_mag_event( void );
 
 #ifndef SITL
+#ifdef CALC_CPU_LOAD
+/* estimate of time needed in idle main_event taks (no pending events) in TOTC 
ticks */
+uint32_t main_event_idle_ticks = PERIODIC_TASK_PERIOD;
+
 int main( void ) {
+  uint32_t load_counter = 0;
+  uint8_t cpu_load = 0;
+  uint16_t cpu_load_avg_sum = 0;
+
   booz2_main_init();
 
   while(1) {
+    if (sys_time_periodic()) {
+      if (load_counter > 0)
+        cpu_load = 100*(PERIODIC_TASK_PERIOD - (load_counter + 
(load_counter-1)*main_event_idle_ticks)) / PERIODIC_TASK_PERIOD;
+      else
+        cpu_load = 100;
+      if (cpu_load > cpu_load_max)
+        cpu_load_max = cpu_load;
+      cpu_load_avg_sum += cpu_load;
+
+      booz2_main_periodic();
+
+      load_counter = 0;
+      RunOnceEvery(512, {cpu_load_avg = cpu_load_avg_sum/512; cpu_load_avg_sum 
= 0; cpu_load_max = 0;});
+    }
+    load_counter++;
+    booz2_main_event();
+  }
+  return 0;
+}
+#else // Do not calculate cpu load
+int main( void ) {
+  booz2_main_init();
+
+  while(1) {
     if (sys_time_periodic())
       booz2_main_periodic();
     booz2_main_event();
   }
   return 0;
 }
+#endif /* CALC_CPU_LOAD */
 #endif /* SITL */
 
 #ifdef BOOZ_START_DELAY
@@ -196,6 +231,10 @@
 }
 
 STATIC_INLINE void booz2_main_event( void ) {
+#ifdef CALC_CPU_LOAD
+  /* start estimation of ticks needed if no events are processed */
+  SysTimeChronoStart();
+#endif
 
   DatalinkEvent();
 
@@ -219,6 +258,12 @@
   modules_event_task();
 #endif
 
+#ifdef CALC_CPU_LOAD
+  /* remember lowest value -> no events processed */
+  SysTimeChronoStop();
+  if (sys_time_chrono < main_event_idle_ticks)
+    main_event_idle_ticks = sys_time_chrono;
+#endif
 }
 
 static inline void on_gyro_accel_event( void ) {

Modified: paparazzi3/trunk/sw/airborne/booz/booz2_telemetry.h
===================================================================
--- paparazzi3/trunk/sw/airborne/booz/booz2_telemetry.h 2010-07-28 01:07:45 UTC 
(rev 5181)
+++ paparazzi3/trunk/sw/airborne/booz/booz2_telemetry.h 2010-07-28 01:07:51 UTC 
(rev 5182)
@@ -56,41 +56,45 @@
 extern uint8_t telemetry_mode_Main_DefaultChannel;
 
 #ifdef USE_GPS
-#define PERIODIC_SEND_BOOZ_STATUS(_chan) {                             \
-    uint32_t booz_imu_nb_err = 0;                                      \
-    uint8_t _twi_blmc_nb_err = 0;                                      \
-    DOWNLINK_SEND_BOOZ_STATUS(_chan,                                   \
-                             &booz_imu_nb_err,                         \
-                             &_twi_blmc_nb_err,                        \
-                             &radio_control.status,                    \
-                             &booz_gps_state.fix,                      \
-                             &booz2_autopilot_mode,                    \
-                             &booz2_autopilot_in_flight,               \
-                             &booz2_autopilot_motors_on,               \
-                             &booz2_guidance_h_mode,                   \
-                             &booz2_guidance_v_mode,                   \
-                             &booz2_battery_voltage,                   \
-                             &cpu_time_sec                             \
-                             );                                        \
+#define PERIODIC_SEND_BOOZ_STATUS(_chan) {                  \
+    uint32_t booz_imu_nb_err = 0;                           \
+    uint8_t _twi_blmc_nb_err = 0;                           \
+    DOWNLINK_SEND_BOOZ_STATUS(_chan,                        \
+                              &booz_imu_nb_err,             \
+                              &_twi_blmc_nb_err,            \
+                              &radio_control.status,        \
+                              &booz_gps_state.fix,          \
+                              &booz2_autopilot_mode,        \
+                              &booz2_autopilot_in_flight,   \
+                              &booz2_autopilot_motors_on,   \
+                              &booz2_guidance_h_mode,       \
+                              &booz2_guidance_v_mode,       \
+                              &booz2_battery_voltage,       \
+                              &cpu_time_sec,                \
+                              &cpu_load_avg,                \
+                              &cpu_load_max                 \
+                              );                            \
   }
 #else /* !USE_GPS */
-#define PERIODIC_SEND_BOOZ_STATUS(_chan) {                             \
-    uint32_t booz_imu_nb_err = 0;                                      \
-    uint8_t twi_blmc_nb_err = 0;                                       \
-    uint8_t  fix = BOOZ2_GPS_FIX_NONE;                                 \
-    DOWNLINK_SEND_BOOZ_STATUS(_chan,                                   \
-                             &booz_imu_nb_err,                         \
-                             &twi_blmc_nb_err,                         \
-                             &radio_control.status,                    \
-                             &fix,                                     \
-                             &booz2_autopilot_mode,                    \
-                             &booz2_autopilot_in_flight,               \
-                             &booz2_autopilot_motors_on,               \
-                             &booz2_guidance_h_mode,                   \
-                             &booz2_guidance_v_mode,                   \
-                             &booz2_battery_voltage,                   \
-                             &cpu_time_sec                             \
-                             );                                        \
+#define PERIODIC_SEND_BOOZ_STATUS(_chan) {                  \
+    uint32_t booz_imu_nb_err = 0;                           \
+    uint8_t twi_blmc_nb_err = 0;                            \
+    uint8_t  fix = BOOZ2_GPS_FIX_NONE;                      \
+    DOWNLINK_SEND_BOOZ_STATUS(_chan,                        \
+                              &booz_imu_nb_err,             \
+                              &twi_blmc_nb_err,             \
+                              &radio_control.status,        \
+                              &fix,                         \
+                              &booz2_autopilot_mode,        \
+                              &booz2_autopilot_in_flight,   \
+                              &booz2_autopilot_motors_on,   \
+                              &booz2_guidance_h_mode,       \
+                              &booz2_guidance_v_mode,       \
+                              &booz2_battery_voltage,       \
+                              &cpu_time_sec,                \
+                              &cpu_load_avg,                \
+                              &cpu_load_max                 \
+                              );                            \
   }
 #endif /* USE_GPS */
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]