DOCU-738 - Integration of Cyclic BSW Mainfunctions
DOCU-738 - Integration of Cyclic BSW Mainfunctions
DOCU-738 - Integration of Cyclic BSW Mainfunctions
Felix Zollner
V1.0.0 | Released
Background Knowledge MICROSAR – Integration of Cyclic BSW Mainfunctions
Document Information
History
Reference Documents
Caution
We have configured the programs in accordance with your specifications in the
questionnaire. Whereas the programs do support other configurations than the one
specified in your questionnaire, Vector´s release of the programs delivered to your
company is expressly restricted to the configuration you have specified in the
questionnaire.
Contents
5 Contact ................................................................................................................................. 36
Introduction
This article describes how to map BSW- and application functions to OS tasks.
It shows the influences and cross-dependencies of these mappings to your system and
gives hints and best practices for this topic.
BSW MainFunctions are mapped via the SchM parts of the Rte. Cyclic application
runnables are mapped via the application implementation of the Rte. Both can be mapped
to Os tasks, the settings of the task and the mappings are defining the runtime behavior of
the ECU.
Mapping function calls of a BSW module or software component (SWC) is realized via task
mapping of SWC runnables and BSW MainFunctions.
Several BSW modules need a cyclic execution of some of their functions, these are normally
called void <BSW Module>_MainFunction<UseCasePrefix>(void);
Within these BSW modules the cycle time of the MainFunction call can be configured.
Also, application SWCs of type Application, SensorActuator, IO Hardware Abstraction
and Complex Driver have triggered runnables who need to be mapped.
The triggering of your SWC runnables can be configured to several different options like
cyclic or On Data Reception at Software design.
All these parts of your software need to be mapped to tasks, to define the context on which
they are executed.
All runnable entities of a BSW module or SWC have to be mapped to the same Os
application. So as soon as a runnable entity of a SWC (or BSW module) is mapped to a
certain task, all the other runnables of the same SWC will have to be mapped to tasks with
the same application referencing them.
1.3.1 Exceptions on Application Distribution - Dem
Some BSW modules can be run in several applications at the same time, this is currently
developed for some modules.
The BSW module Dem for example often needs to be spread over all applications in an ECU
project, therefore there is one Dem_MasterMainFunction() which shall be mapped to
the application that initiates the module Dem, and there is the function
Dem_SatelliteMainFunction_<SatelliteId>(), which needs to be mapped to the
application where the Dem functionality is also needed.
> Cycle time – in which cycle time does the runnable entity need to be called
Figure 1-2 DaVinci Developer – Configuration of Runnable’s Cycle Time of the Cyclic Trigger
> Activation Offset – which offset from start of the triggering until first invocation of the
runnable entity shall be realized?
Figure 1-4 DaVinci Configurator Pro – Configuration of SWC Runnable’s Activation Offset of a Cyclic Trigger)
First all runnable entities that need to be mapped to a certain task can be selected at the same time.
Use the several display settings to get an overview over your task mapping system like the
Trigger view above or the runnable owner’s view below.
Note
The following implementation samples are very simple ones which already differ a bit in
the actual generated Rte code. For several other runnable settings and core /
application distributions of these runnables, the implementation will differ and get much
more complex.
Example
TASK(<YourTaskName>) /* Task started at System Startup */
{
EventMaskType ev;
for(;;)
{
(void)WaitEvent(<all Trigger conditions for this
task>);
(void)GetEvent(Bsw_Task, &ev);
(void)ClearEvent(ev & (<all Trigger conditions for
this task>));
if ((ev & <First Trigger condition>) !=
(EventMaskType)0)
{
/* call runnable entity triggered on first event */
<SWC>_RunnableEntity();
}
if ((ev & <Second Trigger Condition>) !=
(EventMaskType)0)
{
/* call BSW runnable entity which is triggered on
second event */
<BSW Module>_MainFunction<UseCase>();
/* call second runnable triggered on second event */
<BSW Module>_MainFunction<UseCase>();
}
}
}
.
This is the default strategy of the Rte to realize runnable entity triggers.
Example
TASK(<YourTaskName>) /* Task activated cyclically */
{
/* call schedulable entity */
<BSW Module>_MainFunction<UseCase>();
/* call runnable entity */
<SWC>_RunnableEntity();
/* Terminate Task */
(void)TerminateTask();
}
Basically, all runnable entities mapped to a BASIC task shall have the same trigger,
otherwise a schedule-table-like implementation is used.
Example
TASK(Default_BSW_Sync_Task)
{
if (Rte_ScheduleTable_Default_BSW_Sync_Task_Step == 0)
{
/* call first schedulable entity */
<BSW Module>_MainFunction<UseCase>();
/* call cyclic runnable entity */
<SWC>_RunnableEntity();
Rte_ScheduleTable_Default_BSW_Sync_Task_Step = 1;
}
else if (Rte_ScheduleTable_Default_BSW_Sync_Task_Step ==
1)
{
/* call second schedulable entity */
<BSW Module>_MainFunction<UseCase>();
/* call cyclic runnable entity */
<SWC>_RunnableEntity();
Rte_ScheduleTable_Default_BSW_Sync_Task_Step = 0;
}
(void)TerminateTask();
}.
Depending on the Trigger configuration of these runnable entities the task implementations
can become much more complex. There are several further settings that could have
influence on the generation of these cyclic triggers.
EXTENDED tasks can merge several cyclic triggers and also non-cyclic triggers, but for
each different trigger an Os Event is needed. Some Os implementations are limited to 32
Events per task which limits the amount of different trigger implementations per task.
EXTENDED task implementations can handle more complex triggers and are therefore the
default strategy. For some easy use cases BASIC tasks would be the better strategy, so
keep the default and change to BASIC if you see the need and the possibility for it.
This construct can be used if a runnable trigger is based on a cyclic ECU Event (e.g. Adc
conversion finished, Pwm signal was sent completely) which is reflected by an interrupt.
Since SWCs are not allowed to be executed in interrupt context, the event to trigger the
runnable can be set in the CAT2 interrupt context which then activates the task and its
runnable triggering.
2.3.1 CUSTOM Triggers on BASIC Tasks
BASIC tasks with customized triggers can only be realized if ALL triggers within this task are
configured customer-specific. The task which is implemented by the Rte then has to be
activated via ActivateTask(<TaskName>) by the application. Please refer to the
generated task Implementation when to activate the task.
2.3.2 CUSTOM Triggers on EXTENDED Tasks
EXTENDED tasks with customized triggers can merge custom- and automatically-created
trigger implementations within one task implementation. For each runnable entity trigger the
Rte is then generating one specific Event which has to be set via application code
SetEvent(<TaskName>, <EventName>).
Take care
If you configure this, most CPU load measurement methods will detect a CPU load of
100%.
2.5.3 Periodic/Cyclic
Runnables will be called cyclically depending on their cycle time configuration.
2.5.4 On Data Events
If a SWC receives/transmits data elements from a sender/receiver port the events
> reception of a data element (On Data Reception…)
> reception timeout of an external data element (Ón Data Reception Error…) and
> transmission confirmation of an external data element (On Data Send Completion…)
can trigger a runnable entity.
Note
To enable an ECU to react fast and smooth without bigger latencies, it is essential to
carefully design the task mapping of its functions.
The runnables mapped to lower priority tasks will be interrupted as soon as a higher priority
task is being activated (due to runnable triggers). Triggers for lower priority tasks will only
become active when the higher priority tasks are suspended.
The more important a runnable is, the higher the priority of the task should be on which it is
mapped. Otherwise, functional latencies could occur, and cycle times will be deviated. Two
basic rules shall help you here:
If you follow these rules the most important functionalities in your system will be executed
right on time (due to high task priorities), and they will not halt the complete system (due to
the short execution time).
Even if the higher priority tasks have active triggers, the runnables in the lower priority task
are executed first since the task is non-preemptive. When the Task Prio 1 was finished,
then triggers for Task Prio 2 and Task Prio 3 were active, here the priority 3 wins.
Note
> Tasks on other Cores can run in parallel
> Interrupts still can interrupt this task, even CAT2 interrupts, this would delay other
tasks even more than the 1ms calculated before.
The schedule calls within a non-preemptive task create a predetermined breaking point
in task execution where higher priority tasks can be activated and executed at once. This
enables easier runnable design and implementation.
These cases happen very often since some cyclic triggers are very popular (5ms, 10ms,
50ms), in case of 50ms also the 10ms and 5ms triggers become active at the same time.
3.1.4 Activation Offset
All alarms for cyclic triggers are started at the same time (please refer to chapter 4.1, at the
moment there are two different times). It often happens that cyclic triggers cumulate to one
point in time where all runnable triggers are to be executed at the same time, this could lead
to CPU load peaks on certain cycles (e.g. every 50ms) that will last over several ms. This
could in turn produce larger latencies for your system than expected, at least worst case
scenarios will happen more often than necessary.
To avoid this the Activation Offset can be configured for each cyclic runnable trigger. The
alarm that triggers the affecting runnable is then started with the configured delay, from this
time on the cyclic trigger always comes cyclically, but with the offset configured.
This construct can be used to avoid peak loads on your system.
To reach this you can also define exclusive areas in the SWC, which prevent other tasks
from interrupting the currently executed task, but this costs execution time and therefore
CPU load. It could also lead to latencies if the exclusive area is active for a long time.
3.2.2 BSW Exclusive Areas
The MICROSAR basic software implements several of its functions preemptively, but not all
of them. For example, a function Dem_SetEventStatus can be invoked concurrently, so
it can be interrupted by a function call to the same function whereas a Dem_MainFunction
is not preemptive and therefore not allowed to interrupt itself. To protect the RAM content of
the basic software, nearly each BSW module is defining exclusive areas, which are by
default mapped to an interrupt lock. These exclusive areas are described in the technical
references of their modules and can be configured in the Rte section of the DaVinci
Configurator Pro. To optimize your system regarding latencies and CPU load, you could
configure some of these exclusive areas to None, but you will have to follow the rules for
exactly this exclusive area in the technical reference of the module.
To conclude
Exclusive areas basically prevent the system from activating tasks / interrupts and as a
result prevent calling runnables on their configured triggers
> Keep the runtime within exclusive areas as short as possible
> Measure the maximum runtime of an exclusive area, add the maximum runtime of
all interrupts that could be triggered at the same time, then you get the maximum
possible delay of your highest priority task
DaVinci Configurator Pro knows which runnables need to be mapped. In the Add Task
Mapping wizard there is a checkbox Don’t show functions where mapping is optional,
have this option always checked and only map these server runnables where it is really
necessary.
Caution.
Please make sure that runnables configured with Mode Disabling Dependencies for a
certain mode must not be responsible for switching this mode. Otherwise this can
result in a deadlock of the mode state machine.
The following rules seem to contradict each other, but in some way, they can be
met altogether:
1. Use Activation Offsets
2. Avoid too much Os actions
3. Avoid too much rescheduling.
If we take another rule into account:
Short cycle time → higher priority → shorter execution time
Since the task defines the priority of the runnable which is mapped, we could assume that
runnable entities with the same cyclic trigger can be mapped to the same task. This merge
of one cyclic trigger on one task reduces the amount of needed Os alarms. If all these
runnables define the same activation offset, we could also distribute the CPU load of all the
5ms runnables to one certain offset time where no other runnable triggers are modelled.
If the 10ms runnables are also merged to another activation offset, they will never meet each
other, therefore the peak load is prevented and only 2 Os alarms are necessary.
For sure this will not be possible for all runnable entities. Properties like
> Safety inhibition level
> Core assignment
> Synchronization of functionalities to external time bases
> Required execution order of distributed functionalities
> Logical grouping of functionalities and their runnables to tasks would prevent you from
modelling this strategy, but at least for the BSW clusters and for functional units in your
applications this could be discussed.
On FlexRay systems it is essential that e.g. FrNm_MainFunction is called 4ms after cycle
start, whereas the FrTp_MainFunction has to be called 1ms after cycle start. Let’s
assume both MainFunctions are mapped to the same FrSynchtask with ActivationOffset
1ms and 4ms.
The generated function SchM_Init()is starting the corresponding two alarms at startup,
but at startup the ECU hardware is not synchronized to the FlexRay bus, so the alarms are
not synchronized either.
The alarms are stopped at (nearly) macro tick 0, then they are restarted with second
parameter offset and 3rd parameter cycle time. Usually FlexRay cycles are 5ms long.
4.6.2 Synchronizing via Schedule Table Synchronization
Schedule tables are completely synchronizable time bases where on every timer tick an
action (like activating a task or setting an event) can be configured. These actions can be
used to implement the cyclic triggers of your runnable entities. If configured right, one
schedule table could trigger all runnable entities. This time base can be re-synchronized at
any time at runtime via function call SynchScheduleTable().
Caution
Using Os schedule tables is not automated via the tooling. All runnable entity’s Cyclic
Trigger Implementations will have to be set to None and you will have to configure
the schedule table on your own to set the events on the right timings.
5 Contact
> News
> Products
> Demo software
> Support
> Training data
> Addresses