MATLAB Answers

What is the difference between "Initial Function" and "InitValue"?

8 views (last 30 days)
I can define the Initial value of the output of my model using the “Initialize Function”. I have noticed that it is possible to assign a different “InitValue” to corresponding AUTOSAR Port.
So I use both methods:
METHOD 1:
I modify the “Initial value” by going in the “Initialize Function” and setting the value of the constant to block to “uint8(69)”. I then follow the procedure described in:
Example image:
METHOD 2:
I modify the "InitValue" by going to the pane “Code > C/C++ Code > Configure AUTOSAR Dictionary …” then in “AUTOSAR > AtomicComponents > swcLUT > SenderPorts”, click on “Out1” and modify the field “InitValue”.
I have specified the value “69” in the “Initialize Function” and the value “96” for the “InitValue”.
Example images:
and the following:
Modified in AUTOSAR:
So,
There is no error while validating/building the model. As a result, I get a generated C file that uses the value “69” as initialization value in the runnable Init, and a generated arxml file that defines the “InitValue” of the port to “96” :
This seems a bit confusing, and I would like to know whether this is expected behaviour, and which is the method to use for initialization.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 4 Dec 2019
Regarding the main issue of your support request, let me give you some hints that will provide some explanation into the behaviour you were experiencing:
General advice for initialization specification
The general advice (you can check more here: https://www.mathworks.com/help/autosar/ug/autosar-software-components.html#bvg3rfo-1) for using those IRT subsystems is to model complex logic required by your SWC in response to a system event like startup, shutdown, or reset. Think of this as "what does my component need to do to initialize itself?" Usually this would mean writing internal states or reading some value from NVRAM, but I suppose you could want to share that result with a downstream component. In contrast, the InitVal setting on the ComSpec answers a different, systems-level question: "What does the receiver get if it happens to read invalid data?" This includes both data never sent or data intentionally invalidated by the sender.
Initialization behaviour details
I will give the details for when the InitVal comes into play vs the C-code initialization, so it is possible for you to decide if and how you would like to specify these:
ComSpec Initval comes into play for two cases:
  • The RTE gives this value to a receiver if no value has been written to that data element since ECU (or Partition) start
  • The RTE gives this value to a receiver if it receives an invalidated data element (assuming the receiver has "handleInvalid" set to "replace")
Note that if both the sender SWC and receiver SWC specify a different InitVal for the same data element, the receiver SWC wins. This makes sense, because the InitVal is only ever used on the receiver side. Last, if no InitVal is set by the sender or receiver, the RTE will assume an InitVal of 0.
In contrast, the C-code initialization has a very basic meaning: when the RTE schedules the runnable_init method, that runnable writes out a specific value (e.g. 69) to the data element in question; you decide what system events trigger this data write by mapping that runnable_init to different AUTOSAR events, like maybe a mode switch event or initialization event.
Things to consider are SWCs connected by an S-R port but running in different Partitions/ECUs. If the receiver Partition/ECU resets, but the sender Partition/ECU does not, the "data received" status will reset on the receiver's Partition/ECU, since a separate RTE runs on each Partition/ECU) until the next time the sender sends data on that port.

  0 Comments

Sign in to comment.

More Answers (0)

Sign in to answer this question.