Using a class in multiple SW-Cs
One may not include contracts of multiple SW-Cs in a single source:
this is a Product Restrictions caused by AUTOSAR.
Because Rhapsody generates a source file for a class, this is a problem: the class may not use RTE APIs defined in multiple contracts.
In our Blinky example, we want to re-use the class LED in multiple SW-Cs.
This class contains an RTE API Rte_Call_Digital_LED_Write() which is defined in the contracts Rte_SwcA.h, Rte_SwcB.h and Rte_SwcC.h
In Rhapsody we have created a Class Diagram LED Inheritance where classes LED_SwcA and LED_SwcB use a static inheritance relation from the class LED:
There are a few details you should be aware of:
- the operations on and off are implemented in the class LED only
Via the Implementation tab of the Features of LED you can modify them.
- when inspecting LED_SwcA or LED_SwcB the operations are shown as inherited operations
- the statechart is implemented in LED. In LED_SwcA or LED_SwcB the statechart is shown as readonly
- the implementation of operations in a class which is re-used in multiple SW-Cs must deal with possible differences in RTE API calls.
In our Blinky example, SwcA is multiple instantiated, so RTE calls require a self pointer. SwcB is not multiple instantiated,
so needs conceptually the same API but without this self pointer argument. In Blinky the operations on() and off() in LED.c show an example
- the implementation of operations in a class which is re-used in multiple SW-Cs may require to
use the exact same references from a class to its SW-C
- the code generation of class LED must be disabled. For this, we use the property CG::Class::UseAsExternal
- the proper contract must be included in the generated source code of the descendent classes. For this, we use the property C_CG::Class::ImpIncludes