T2A1: Important Thoughts

Write down the difference between Extended SCCharts and Core SCCharts.

Core SCCharts consist of a minimal set of SCCharts elements on which the semantic of SCCharts is defined.

Extended SCCharts are conservative extension of the Core SCCharts elements. These Extended features extend the syntax of SCCharts and enlarge the language for better usability.

Each Extended SSChart can be transformed step-by-step into a semantically equal Core SCChart. Some Transformations translating a single Extended features into Core use other Extended features, resulting dependencies between Extended Transformations.

What advantages has the Core SCCharts normalization?

Normalization simplifies the structure of Core SCChart by reducing the variety of allowed structure constructions to a minimal set of five structure pattern.

This facilitates transformation into other model types especially SCG because normalized SCCharts have the same structure as SCGs. This is due to the appropriate definition of the structure patterns.

Describe in own words what a basic block is.

BBs are distinct sets of SCG nodes that can be executed monolithically and continuously in cases of control flow.

There are no incoming or outgoing control flow edges in a BB or a tick edge.

Thus a BB can be executes without any control flow switches or jumps.

Which constraints influence the ordering of a schedule?

The main constraint is the initialize update read protocol for concurrent but not confluent access of variables.

As a result there are dependencies between nodes in SCGs which define their ordering constraints in a schedule.

There are simple "happen before" dependencies cause by sequential control flow.

Furthermore there are dependencies demanding absolute writes before relative write, relative writes before reads and consequently absolute writes before read.

A “write / write conflict", both absolute or relative, makes it impossible to find an schedule.

T2A2: Tickets

Created

Resolved

T2A3: Modeling with SCCharts

rail.sct
scchart rail {
  
input bool second;
  
input bool contact0 , contact1;
  
output int track;
  
initial state station_controller "station controller" {
    
region go:
    
initial state init
    
--> running immediate with / track = 60;
   
    
state running;    
    
region platform:
    
initial state waiting
    
--> slowdown immediate with contact0 / track = 20;
   
    
state slowdown
    
--> stop immediate with contact1 / track = 0;
   
    
state stop
    
--> waiting with 5 second / track = 60;
   
  
};
}

T2A4: SCCharts Transformations

Transforming into Core SCChart

  1. Count Delay (5 seconds guard in transition).
    • 5 seconds becomes _counter == 5.
      • Implicit counting becomes explicit check of a counter.
    • Counter control
      • State station control gets integer variable _counter.
      • State stop where counting should happen gets:
        • entry action with counter = 0 effect to initialize counter each time the state is entered.
        • during action which increments counter each time second holds.
  2. During action in stop added in step 1.
    • State stop gets boolean variable _term initialized to false.
    • State stop gets a region with a Main --> _Term states were the immediate transition sets _term to true. Main contains the behavior of stop which is empty.
    • State stop gets a region with the counter behavior increments _counter every tick where second is true or terminates if _term is true.
  3. Abort of state stop
    • Transition form stop to waiting becomes normal termination without trigger.
    • State station controller gets boolean variable _trig initialized to false.
    • State Main gets region with states _Run --> _Done with trigger _counter == 5 of the transformed termination and effect _trig = true
  4. Initialization_term = false in state stop added in step 2 and _trig = false in step 3
    • _term and _trig become uninitialized.
    • State stop gets entry action initializing _term with false.
    • State station controller gets entry action initializing _trig with false.
  5. Entry actions added in step 1 and 4.
    • The internal regions of stop are moved into a state Main in stop.
    • The initial state leads to Main via two concatenated immediate transitions connected by a connector. The transitions have their triggers and effects according to the two entry actions they are transformed from. So the entry behavior is executed before entering Main and thus as entry action of the state.
    • Main has an empty normal termination to the final state in stop.
    • The internal regions of station controller are moved into a state Main in station controller.
    • The initial state leads to Main via  immediate transitions with effects _trig = false
    • Main has an empty normal termination to the final state in station controller.
  6. Connector added in step 4.
    • The connector is turned into a simple state _c.

After these transformations there are no more Extended features resulting a Core SCChart.

rail_core.png

Normalization

rail_normalized.png

SCG

The SCG is not schedulable because there is a write/write conflict between the transitions setting variable track.

The initialization of track in region go is concurrent to the effects of the contact transitions and all three are absolute writes.

If contact0 is true , and maybe contact1 too, in the first tick there is a conflict between effects: track = 60, track = 20, track = 0 which is impossible to schedule in SC MoC.

rail_scg_dep.png

T2A5: Code Generation

The write/write conflict needs to be resolved.

This is done by moving the go region into the platform regions and initializing track to 60 before entering waiting state.

Additionally the transformation of Count Delay behavior produces an ASC-unscheldulable SCG (cycle between read/write of _trem and _counter) thus the counter needs to be flatten to a chain of states sleep_.

The resulting SCChart is:

rail_2.png

rail_2.scg.png

Generated C code:

Generated C code
 
/*****************************************************************************/
/*                 G E N E R A T E D       C    C O D E                      */
/*****************************************************************************/
/* KIELER - Kiel Integrated Environment for Layout Eclipse RichClient        */
/*                                                                           */
/* http://www.informatik.uni-kiel.de/rtsys/kieler/                           */
/* Copyright 2014 by                                                         */
/* + Christian-Albrechts-University of Kiel                                  */
/*   + Department of Computer Science                                        */
/*     + Real-Time and Embedded Systems Group                                */
/*                                                                           */
/* This code is provided under the terms of the Eclipse Public License (EPL).*/
/*****************************************************************************/



int second ;;
 
int contact0 ;;
 
int contact1 ;;
 
int track ;;
 
int _GO ;;
 
int guard20_e1 ;;
 
int guard0 ;;
 
int guard1 ;;
 
int guard2 ;;
 
int guard3 ;;
 
int guard4 ;;
 
int guard5 ;
  int PRE_guard5 ;;
 
int guard6 ;;
 
int guard7 ;
  int PRE_guard7 ;;
 
int guard8 ;;
 
int guard9 ;
  int PRE_guard9 ;;
 
int guard10 ;;
 
int guard11 ;
  int PRE_guard11 ;;
 
int guard12 ;;
 
int guard13 ;
  int PRE_guard13 ;;
 
int guard14 ;;
 
int guard15 ;;
 
int guard16 ;
  int PRE_guard16 ;;
 
int guard17 ;;
 
int guard18 ;
  int PRE_guard18 ;;
 
int guard19 ;;
 
int guard20 ;;
 
int guard21 ;





   int reset(){
      _GO = 1;
    }


   int tick(){
      guard0 = _GO;
      Tick: {
                 if (guard1) {
                            track = 60;
                           }
                 guard14 = (PRE_guard13)
                 ;
                 guard15 = (
                 guard14 &&
                 second
                         )
                 ;
                 if (guard15) {
                            track = 60;
                           }
                 guard2 = (
                 guard1 ||
                 guard15
                         )
                 ;
                 guard19 = (PRE_guard18)
                 ;
                 guard3 = (
                 (
                 guard2 &&
                 contact0
                         ) ||
                 (
                 guard19 &&
                 contact0
                         )
                         )
                 ;
                 if (guard3) {
                            track = 20;
                           }
                 guard17 = (PRE_guard16)
                 ;
                 guard4 = (
                 (
                 guard3 &&
                 contact1
                         ) ||
                 (
                 guard17 &&
                 contact1
                         )
                         )
                 ;
                 if (guard4) {
                            track = 0;
                           }
                 guard6 = (PRE_guard5)
                 ;
                 guard5 = (
                 guard4 ||
                 (
                 guard6 &&
                 (!(second))
                         )
                         )
                 ;
                 guard8 = (PRE_guard7)
                 ;
                 guard7 = (
                 (
                 guard6 &&
                 second
                         ) ||
                 (
                 guard8 &&
                 (!(second))
                         )
                         )
                 ;
                 guard10 = (PRE_guard9)
                 ;
                 guard9 = (
                 (
                 guard8 &&
                 second
                         ) ||
                 (
                 guard10 &&
                 (!(second))
                         )
                         )
                 ;
                 guard12 = (PRE_guard11)
                 ;
                 guard11 = (
                 (
                 guard10 &&
                 second
                         ) ||
                 (
                 guard12 &&
                 (!(second))
                         )
                         )
                 ;
                 guard13 = (
                 (
                 guard12 &&
                 second
                         ) ||
                 (
                 guard14 &&
                 (!(second))
                         )
                         )
                 ;
                 guard16 = (
                 (
                 guard3 &&
                 (!(contact1))
                         ) ||
                 (
                 guard17 &&
                 (!(contact1))
                         )
                         )
                 ;
                 guard18 = (
                 (
                 guard2 &&
                 (!(contact0))
                         ) ||
                 (
                 guard19 &&
                 (!(contact0))
                         )
                         )
                 ;
                 guard20 = 0;
                 guard20_e1 = (!((
                 guard18 ||
                 (
                 guard16 ||
                 (
                 guard5 ||
                 (
                 guard7 ||
                 (
                 guard9 ||
                 (
                 guard11 ||
                 guard13
                         )
                         )
                         )
                         )
                         )
                         )
                 ))
                 ;
                 guard21 = (
                 (
                 guard20_e1 ||
                 guard20
                         ) &&
                 guard20
                         )
                 ;
                  }
      _GO = 0
    }

T2A6: Hostcode

SCT
scchart rail {
 input bool second;
  initial state station_controller "station controller" {
    initial state init
   --> waiting immediate with / 'settrack(railway, KH_ST_1, FWD, 60)';  
   state waiting {
      entry / 'getcontact(railway, KH_ST_1, 0, 1)';//consume last contact event triggered by trains tail
   }
   --> slowdown immediate with 'getcontact(railway, KH_ST_1, 0, 1) != NONE' / 'settrack(railway, KH_ST_1, FWD, 20)';
   
   state slowdown {
      entry / 'getcontact(railway, KH_ST_1, 1, 1)';//consume last contact event triggered by trains tail
   }
   --> stop immediate with 'getcontact(railway, KH_ST_1, 1, 1) != NONE' / 'settrack(railway, KH_ST_1, BRAKE, 0)';
   
   state stop
   --> sleep_1 with second;
   
   state sleep_1
   --> sleep_2 with second;
   
   state sleep_2
   --> sleep_3 with second;
   
   state sleep_3
   --> sleep_4 with second;
   
   state sleep_4
   --> waiting with second / 'settrack(railway, KH_ST_1, FWD, 60)';
   
 };
}

Hostcode does not work properly.

Tags: