AUTOSAR, fault memory and MISRA C: interview questions
12 AUTOSAR, fault memory and MISRA C questions embedded interviewers ask, each with a model answer. What is the difference between sender-receiver and…
What is the difference between sender-receiver and client-server ports in AUTOSAR?
A software component never calls basic software or another component directly. It declares ports, and the RTE connects them.
- A sender-receiver port carries data. One side writes a value such as the vehicle speed and the other reads it. The sender does not know who reads it, or when. In code it is
Rte_Write_...andRte_Read_.... - A client-server port carries a call. The client invokes an operation with arguments, the server runs it and returns a result. Reading a DID's data and setting a diagnostic event's status are both operations. In code it is
Rte_Call_....
Choosing between them is choosing between state and action. A value that is always valid and updated periodically is sender-receiver. "Do this now and tell me whether it worked" is client-server.
The RTE generator turns each access into code that depends on where the other end lives. A sender-receiver read may become a direct read of a global, a copy protected against interruption, or a signal fetched from Com when the sender is on another ECU. The component's source is the same in every case, which is the portability AUTOSAR promises, and it is why generated RTE code is the first place to look when data arrives stale.
What is a PDU, and what does the PduR do with one?
A PDU (protocol data unit) is what one layer hands to its peer: the payload it was given by the layer above, the SDU, plus its own header. AUTOSAR names PDUs by layer:
| Name | Layer | On CAN it is |
|---|---|---|
| L-PDU | data link | a CAN frame's identifier and data |
| N-PDU | network (transport) | one ISO-TP frame's content |
| I-PDU | interaction | a whole message: a set of signals, or a complete diagnostic request |
The PduR (PDU router) moves I-PDUs between the modules above it and the modules below it by a generated routing table. For a diagnostic request the entry says "this I-PDU from CanTp goes to Dcm", and for the response "this I-PDU from Dcm goes to CanTp". A normal signal message goes between CanIf and Com in the same way.
It can also gateway: an I-PDU received on one bus is sent on another without any upper layer seeing it.
The PduR holds no protocol knowledge of its own. That is why the same stack serves CAN, LIN, FlexRay and Ethernet: only the modules under the router change.
In an interview, name the full path for a diagnostic request: Can, CanIf, CanTp, PduR, Dcm, and the same in reverse for the response.
How do OS tasks, runnables and the main functions of the basic software modules relate?
Only the OS task is a unit of scheduling. The Classic Platform's OS is OSEK-style: a fixed set of tasks with static priorities, activated by alarms or schedule tables. Everything else runs inside a task.
A runnable is a function of a software component, triggered by a period (every 10 ms), by the arrival of data or by a call. During integration each runnable is mapped onto a task, and the RTE generator writes the task bodies that call the runnables in the configured order.
A main function is the same idea for basic software. Each module has an <Module>_Init and one or more <Module>_MainFunction, called cyclically at a configured period. That is where the module does its deferred work: the Dcm checks its P2 and S3 timers and calls back the handlers that returned pending, CanTp runs its N_ timers, NvM carries out queued writes.
Two consequences in practice:
- Timing is a configuration result. If the Dcm's main function is called every 20 ms where 10 ms was configured, every timer in it runs at half speed. "A main function is called at the wrong rate" is a real class of bug.
- Nothing may block. A callback that waits inside a main function stalls every module that shares that task, so long work returns pending and continues on the next call.
What protects an NvM block against corruption?
Each NvM block can have a RAM copy, a non-volatile copy and a ROM default, and three mechanisms protect it:
- A CRC per block, stored with the data and checked when the block is read. A write that was cut off by a power loss, or a cell that has worn out, shows up as a CRC mismatch and is not handed to the application as valid data.
- Redundancy. A redundant block has two copies, each with its own CRC. Reading takes the first valid copy and repairs the other. A power cut during a write damages at most one of them.
- Defaults. When no copy is valid, the block is loaded from its ROM default (or an init callback), and the error status says so. The ECU starts with known values and can report the loss.
Further options exist for particular blocks: write verification (read back and compare), write protection for data that is written once, and a static block id to detect a block read from the wrong place.
Under NvM, the memory stack adds its own protection. Flash EEPROM emulation writes a new copy before it invalidates the old one, so there is always one complete version.
None of this helps data that was never written. NvM_WriteBlock returning E_OK means the request was accepted, and NvM_WriteAll runs at shutdown, so an ECU that loses power abruptly keeps the previous values.
What does a three-byte UDS DTC consist of, and what is the failure type byte?
9A 01 16
| |
| +-- failure type byte
+-------- base code, two bytes
The two-byte base code is the workshop code from SAE J2012. Its top two bits choose the letter, the next two the first digit, and the remaining twelve bits are three hex digits:
| Top bits | Letter | System |
|---|---|---|
00 | P | powertrain |
01 | C | chassis |
10 | B | body |
11 | U | network |
9A 01 is 10 01 1010 0000 0001, which reads B, 1, A, 0, 1: B1A01.
The failure type byte says how the circuit or signal failed. It comes from a standard list:
| Value | Failure type |
|---|---|
11 | short to ground |
12 | short to battery |
13 | open circuit |
16 | voltage below threshold |
17 | voltage above threshold |
87 | missing message |
So the tester shows B1A01-16. One base code with several failure types lets a single circuit report several faults, each with its own status byte and its own records.
A fourth byte, the status byte, follows each DTC in a ReadDTCInformation response. It is the DTC's state, not part of its identity.
What is an operation cycle, and which status bits change when one starts?
An operation cycle is the period in which a fault's bookkeeping is counted. Most often it is an ignition cycle. Other kinds are a power cycle, a warm-up cycle and an OBD driving cycle. Each DTC is assigned to one.
When a cycle starts:
- bit 6, testNotCompletedThisOperationCycle, is set: the monitor has not run yet in this cycle;
- bit 1, testFailedThisOperationCycle, is cleared.
Nothing else changes at that moment. confirmedDTC and testFailedSinceLastClear stay, since their job is to remember across cycles.
When a cycle ends with the test completed and no failure in it, bit 2, pendingDTC, is cleared. That is the one-cycle memory of "pending".
The cycle is also the unit of every counter:
- The trip counter counts cycles with a failure, towards confirmation.
- The warning indicator clears after a number of fault-free cycles.
- The ageing counter counts cycles in which the test completed and did not fail.
A cycle in which the monitor never ran counts for nothing. That is why bit 6 exists: a fault-free cycle and a cycle without a result must be told apart, or a fault would age out while its monitor was disabled.
What are enable conditions and storage conditions for a diagnostic monitor?
Enable conditions decide whether a monitor's result is taken at all. While one is not fulfilled, the monitor's reports are ignored and its debounce counter does not move. They switch a monitor off when its result would be wrong for a known reason:
- no "sensor voltage low" check while the starter pulls the battery down;
- no "message missing" check for an ECU that is not fitted to this variant, or before the bus has started;
- no plausibility check of two sensors while one of them already has a fault of its own.
Storage conditions act one step later. The test runs and its result updates the status, but the fault is not written to the event memory while the condition is not fulfilled. The usual example is not storing new entries while the supply voltage is too low to write non-volatile memory safely.
Both are different from ControlDTCSetting, which is a tester's request to stop DTC status updates for a while, as before reprogramming.
Forgetting an enable condition is the classic source of DTCs that appear on every cold start with nothing wrong. When a requirement says "set the DTC if the voltage is below 9 V", the first review question is under which conditions the monitor is active.
How does a confirmed DTC heal and age out?
In two stages, and they are easy to mix up.
Healing is the test passing again:
testFailedclears as soon as the monitor reports passed.- After a number of fault-free operation cycles, the warning indicator request (bit 7) clears. Three is the number for the OBD lamp.
- The entry stays in the memory with
confirmedDTCset. A tester reads status08or28: stored, not present now.
Ageing removes it:
- An ageing counter counts operation cycles in which the test completed and did not fail. For OBD these are warm-up cycles.
- A failure at any time resets the counter.
- At the threshold, commonly 40, the DTC is aged:
confirmedDTCclears, and its snapshot and extended data are freed.
So the lamp goes out long before the entry is erased, and for a while a workshop can still read a fault the driver no longer sees.
Whether an aged DTC leaves a trace is the manufacturer's choice. testFailedSinceLastClear is not cleared by ageing, so it can still say "this did happen at some point".
Ageing exists because the event memory is small and history goes stale: an under-voltage event from the day the battery was changed should not be on the screen two years later.
What is the MISRA essential type model, and which conversions does it forbid?
C's own rules promote small integers to int and convert between signed and unsigned silently. The essential type model ignores those promotions and gives every expression one of a few essential types: Boolean, character, signed, unsigned, enum and floating. The rules of group 10 then restrict how they may be mixed.
What it forbids, in practice:
- Assigning to a narrower or a different essential type (Rule 10.3): a
uint16_texpression into auint8_t, a signed value into an unsigned object, an integer into abool. - Mixing essential types in one operation (10.4):
u8 + s8, or an unsigned variable compared with a signed constant. This is why constants need aUsuffix. - Operands of an inappropriate type (10.1): a shift or a bitwise operation on a signed value, arithmetic on a Boolean.
- Widening the result of an expression after the fact (10.6 to 10.8): in
u32 = u16a * u16bthe multiplication is done in the narrower type, so one operand must be cast first.
An explicit cast is how you state that a conversion is intended, and it is also where a reviewer looks.
A related rule is 14.4: a controlling expression is essentially Boolean. if (flags & 0x01U) is a finding, and if ((flags & 0x01U) != 0U) is not.
The point is that the value a line computes is the one a reader expects, on a 16-bit and a 32-bit target alike.
What is the difference between a MISRA directive and a rule?
A rule is a statement about the source code that can be checked from the code alone. Rule 15.6 says the body of an if or a loop is a compound statement, and a tool can check it.
A directive needs information beyond the code, such as design documents, requirements or the compiler's manual. Directive 4.1 says run-time failures shall be minimised. A tool can help with a directive, but it cannot settle it. Compliance is shown by review and by documents.
That difference decides how each is enforced. A project's guideline enforcement plan lists, for every guideline, which tool check covers it, or which review step where no tool can.
Do not confuse this with two other classifications:
- The category, which every guideline has: mandatory (never deviated from), required (only with an approved deviation), advisory.
- Decidability, which only rules have. For a decidable rule a tool can always answer yes or no. For an undecidable one, such as reading an uninitialised object, the answer may depend on run-time values, so a tool reports possible violations and can miss real ones. A clean report is not proof.
Rules also have a scope of analysis: one translation unit, or the whole system. A system rule cannot be checked file by file.
Why does MISRA ask for a single point of exit, and how do you write error handling under it?
Rule 15.5 says a function should have a single point of exit at the end. Its reasons are that everything that must happen before returning (releasing a resource, restoring a state, writing an output parameter) is then in one place and cannot be skipped by an early return, and that the function is easier to analyse and to cover in testing.
The rule is advisory. Many projects formally disapply it, because the single-exit form can bury the main path in nesting. Many car makers' guidelines make it binding, so you should be able to write both.
The idiom that keeps single-exit code flat is "continue only while still OK": one result variable, set along the way and returned once.
Std_ReturnType handle(const uint8_t *req, uint16_t len)
{
Std_ReturnType result = E_OK;
if (len < 3U) {
result = E_NOT_OK;
}
if (result == E_OK) {
result = check_session();
}
if (result == E_OK) {
result = read_data(req);
}
return result;
}
Each step runs only if all the earlier ones succeeded. The checks stay in order, at one level of nesting, and cleanup can sit before the single return.
What does not comply: goto to a cleanup label is restricted by its own rules (15.1 advises against goto at all), so the result-variable form is the usual answer.
What goes into a MISRA deviation record, and who approves it?
A deviation is a documented, reviewed and approved decision not to follow a guideline in a stated set of circumstances. MISRA Compliance:2020 sets what the record contains:
| Field | For a memory-mapped register |
|---|---|
| The guideline | Rule 11.4 |
| The scope | the register access macros in the MCAL headers only |
| The reason, from the permitted set | access to hardware |
| The justification | the addresses are fixed by the device; the vendor's header is the only definition |
| The risk and how it is controlled | addresses come from the vendor's device header; a wrong one is caught by integration tests on the target |
| Approval | who, when, and with what authority |
Approval comes from whoever the project's process names, and it is not the author of the code: typically the technical lead or the software quality role, and for safety-relevant code someone with responsibility for safety. Where the customer's guideline says so, the customer approves too.
Three properties separate a deviation from an excuse:
- It is specific. "Rule 11.4 is disabled" is not a deviation. A deviation permit generalises a common case once, and each use refers to it.
- The reason is technical. "The code works" and "there is no time" are not reasons. A false positive is a tool problem and is recorded as one, not as a deviation.
- It is traceable in the code. A comment or pragma at the site suppresses the finding and names the record.
Only required guidelines need this. Mandatory ones cannot be deviated from, and advisory ones may be set aside with a lighter, documented decision.