From 74817469654cf6793c4b682d07c94ac425e7255f Mon Sep 17 00:00:00 2001
From: Christian Dietrich <christian.dietrich@informatik.uni-erlangen.de>
Date: Wed, 14 Sep 2016 14:28:09 +0200
Subject: [PATCH] timing/bench: timing-2 measures RC control

---
 app/benchmark/timing/copter.cc     | 8 ++++++--
 generator/transform/GeneratePML.py | 8 ++++++++
 os/timing.h                        | 2 ++
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/app/benchmark/timing/copter.cc b/app/benchmark/timing/copter.cc
index 2fde270..d9d2803 100644
--- a/app/benchmark/timing/copter.cc
+++ b/app/benchmark/timing/copter.cc
@@ -108,7 +108,6 @@ TASK(MavlinkSendTask) {
 }
 
 TASK(CopterControlTask) {
-    timing_end(TIMING_POINT_NO_INTERRUPTS_IN_BLOCK | 2);
 
     calculation();
     SuspendAllInterrupts();
@@ -116,16 +115,21 @@ TASK(CopterControlTask) {
     ResumeAllInterrupts();
     calculation();
 
+    /* Saves 8000 states
     if (round < 5) {
         CancelAlarm(CopterControlWatchdogAlarm);
         SetRelAlarm(CopterControlWatchdogAlarm, 100, 100);
     }
     calculation();
+    */
+
+    timing_end(2);
+
     TerminateTask();
 }
 
 ISR2(MavlinkRecvHandler) {
-    timing_start(2 | TIMING_POINT_IS_HIGHEST_PRIO);
+    timing_start(2 | TIMING_POINT_START_INTERRUPT_FROM_IDLE);
     calculation_short();
     ActivateTask(CopterControlTask);
     calculation_short();
diff --git a/generator/transform/GeneratePML.py b/generator/transform/GeneratePML.py
index 0d35949..c38ec49 100644
--- a/generator/transform/GeneratePML.py
+++ b/generator/transform/GeneratePML.py
@@ -20,6 +20,9 @@ def is_TIMING_POINT_NO_INTERRUPTS_IN_BLOCK(flags):
 def is_TIMING_POINT_IS_HIGHEST_PRIO(flags):
     return (flags & 4) == 4
 
+def is_TIMING_POINT_START_FROM_IDLE(flags):
+    return (flags & 8) == 8
+
 
 
 class GeneratePML(Analysis, GraphObject):
@@ -104,6 +107,10 @@ class GeneratePML(Analysis, GraphObject):
                         pass # Ignore state
                     else:
                         start_states[id(state)] = state
+                elif is_TIMING_POINT_START_FROM_IDLE(start_abbs.get(state.current_abb,0)):
+                    # Only IRQ states from idle are allowed
+                    if len(priority_map(state)) == 0:
+                        start_states[id(state)] = state
                 else:
                     start_states[id(state)] = state
 
@@ -451,6 +458,7 @@ class GeneratePML(Analysis, GraphObject):
 
         # Add a list of nodes:
         G.add_nodes_from(all_states.keys())
+        logging.debug("  searching loops in %d-node graph (networkx)", len(all_states))
 
         for a in all_states.values():
             for b in a.get_outgoing_nodes(SavedStateTransition):
diff --git a/os/timing.h b/os/timing.h
index ef91aa2..9b8a5f9 100644
--- a/os/timing.h
+++ b/os/timing.h
@@ -25,6 +25,8 @@ extern "C" {
 #define TIMING_POINT_STOP_BEFORE 0x100
 
 #define TIMING_POINT_START_INTERRUPT_IN_BLOCK 0x100
+#define TIMING_POINT_START_INTERRUPT_FROM_IDLE 0x800
+
 
 
 
-- 
GitLab