Home Learning Paths ECU Lab Assessments Interview Preparation Arena Pricing Log In Sign Up

Key Safety Architecture Patterns

PatternPurposeImplementationASIL Relevance
Monitor-ActuatorMonitor (checker) verifies actuator output before it takes effectTwo independent software paths; monitor can override actuatorASIL-D: enables ASIL decomposition
Read-Modify-Write protectionPrevent simultaneous access to shared safety dataDisable interrupts or use atomic operations for safety-relevant globalsAll ASIL levels
Defensive APIFunctions validate inputs before use; fail safely on invalid inputAssert-style checks at function entry; return error code on invalidASIL-B and above
State machine with exhaustive elseNo undefined state transitionsEvery state/event combination has defined behaviour; final else → safe stateAll ASIL levels
Dead-code eliminationUnreachable code cannot hide bugsStatic analysis; compiler warnings; MC/DC testingASIL-C/D: MC/DC required

E2E Protection Implementation

Ce2e_protection.c
/* AUTOSAR E2E Library: protects safety-relevant data in communication */
/* Covers: data corruption, message loss, out-of-sequence, bus errors */
/* Applied at SW-C level (sender + receiver) — transparent to middleware */

#include "E2E_P04.h"  /* E2E Profile 4: 32-bit CRC + 16-bit counter + 16-bit data ID */

/* Sender (AEB Domain Controller → Brake ECU) */
typedef struct {
    uint8_t  header[12];     /* E2E Profile 4 header: CRC32 + counter + data_id */
    uint16_t aeb_request;    /* 0 = no request; 1 = request braking */
    uint16_t decel_target;   /* target deceleration (dm/s²) */
} AEB_BrakeRequest_Msg_t;

static E2E_P04SenderStateType g_e2e_sender_state;

void AEB_SendBrakeRequest(boolean request, uint16_t decel_mds2)
{
    AEB_BrakeRequest_Msg_t msg;
    msg.aeb_request  = request ? 1u : 0u;
    msg.decel_target = decel_mds2;

    /* E2E protect: adds CRC-32 + increments counter in header */
    uint8_t *data = (uint8_t *)&msg;
    E2E_P04Protect(&g_e2e_sender_config,   /* includes data_id, data_length */
                   &g_e2e_sender_state,    /* counter state */
                   data,                   /* message buffer */
                   sizeof(msg));           /* total message length */

    CAN_Send(CAN_MSG_AEB_BRAKE_REQ, data, sizeof(msg));
}

/* Receiver (Brake ECU) */
static E2E_P04ReceiverStateType g_e2e_recv_state;

boolean Brake_ReceiveAEBRequest(uint16_t *decel_out)
{
    uint8_t buf[sizeof(AEB_BrakeRequest_Msg_t)];
    if (!CAN_Receive(CAN_MSG_AEB_BRAKE_REQ, buf, sizeof(buf))) { return FALSE; }

    E2E_P04CheckStatusType status;
    E2E_P04Check(&g_e2e_recv_config, &g_e2e_recv_state, buf, sizeof(buf));
    status = g_e2e_recv_state.Status;

    if (status == E2E_P04STATUS_OK || status == E2E_P04STATUS_OKSOMELOST) {
        AEB_BrakeRequest_Msg_t *msg = (AEB_BrakeRequest_Msg_t *)buf;
        *decel_out = msg->decel_target;
        return msg->aeb_request != 0u;
    }
    /* E2E error: treat as no request (safe default) */
    *decel_out = 0u;
    Dem_ReportErrorStatus(DEM_EVENT_E2E_ERROR_AEB, DEM_EVENT_STATUS_FAILED);
    return FALSE;  /* safe state: no braking request */
}

Defensive Programming Patterns

Cdefensive_programming.c
/* ASIL-D defensive programming: validate all inputs; never assume valid state */
#include 
#include "Std_Types.h"

/* Pattern 1: Input validation at function boundary */
Std_ReturnType SafetyMonitor_SetThreshold(float threshold_nm)
{
    /* Validate: threshold must be in physically plausible range */
    if (threshold_nm < 0.1f || threshold_nm > 10.0f) {
        Dem_ReportErrorStatus(DEM_EVENT_INVALID_PARAM, DEM_EVENT_STATUS_FAILED);
        return E_NOT_OK;   /* do not apply invalid threshold */
    }
    g_threshold = threshold_nm;
    return E_OK;
}

/* Pattern 2: Exhaustive switch with default → safe state */
typedef enum { STATE_INIT=0, STATE_ACTIVE, STATE_FAULT, STATE_SAFE } SafetyState_t;

void SafetyFSM_Process(SafetyState_t state, SafetyEvent_t event)
{
    switch (state) {
        case STATE_INIT:
            if (event == EVT_STARTUP_OK) { FSM_Transition(STATE_ACTIVE); }
            else                          { FSM_Transition(STATE_SAFE);   }
            break;
        case STATE_ACTIVE:
            if (event == EVT_FAULT_DETECTED) { FSM_Transition(STATE_FAULT);  }
            else if (event == EVT_HEARTBEAT)  { /* stay active */ }
            else                              { FSM_Transition(STATE_SAFE);   }
            break;
        case STATE_FAULT:
            /* In fault: any event results in safe state transition */
            FSM_Transition(STATE_SAFE);
            break;
        case STATE_SAFE:
            /* Safe state: no transitions out; only reset can recover */
            Safety_ApplySafeState();
            break;
        default:
            /* Undefined state (memory corruption): safe state immediately */
            FSM_Transition(STATE_SAFE);  /* MISRA: default must be present */
            break;
    }
}

/* Pattern 3: Inverse check (double-check critical decisions) */
boolean AEB_ShouldActivate(float ttc, float radar_conf, float cam_conf)
{
    boolean primary_decision = (ttc < 1.5f && radar_conf > 0.95f && cam_conf > 0.95f);

    /* Inverse check: independently computed — if inverse logic disagrees, fault */
    boolean inverse_check    = !(ttc >= 1.5f || radar_conf <= 0.95f || cam_conf <= 0.95f);

    if (primary_decision != inverse_check) {
        /* Impossible: indicates data corruption or compiler fault */
        Dem_ReportErrorStatus(DEM_EVENT_INVERSE_CHECK_FAIL, DEM_EVENT_STATUS_FAILED);
        return FALSE;  /* conservative: do not activate */
    }
    return primary_decision;
}

Summary

Software architecture safety patterns translate abstract ASIL requirements into concrete code structures. The monitor-actuator pattern is the most powerful for ASIL decomposition: the monitor (higher ASIL) independently verifies the actuator's (lower ASIL) decision and can veto it. The inverse check pattern detects data corruption and compiler errors by computing the same decision through logically equivalent but syntactically different code — a discrepancy indicates either data corruption or a compiler optimisation that changed the program behaviour. These patterns are not optional decorations — they are the implementation of the safety mechanisms that drive the DC values in the hardware metrics calculation.

🔬 Deep Dive — Core Concepts Expanded

This section builds on the foundational concepts covered above with additional technical depth, edge cases, and configuration nuances that separate competent engineers from experts. When working on production ECU projects, the details covered here are the ones most commonly responsible for integration delays and late-phase defects.

Key principles to reinforce:

  • Configuration over coding: In AUTOSAR and automotive middleware environments, correctness is largely determined by ARXML configuration, not application code. A correctly implemented algorithm can produce wrong results due to a single misconfigured parameter.
  • Traceability as a first-class concern: Every configuration decision should be traceable to a requirement, safety goal, or architecture decision. Undocumented configuration choices are a common source of regression defects when ECUs are updated.
  • Cross-module dependencies: In tightly integrated automotive software stacks, changing one module's configuration often requires corresponding updates in dependent modules. Always perform a dependency impact analysis before submitting configuration changes.

🏭 How This Topic Appears in Production Projects

  • Project integration phase: The concepts covered in this lesson are most commonly encountered during ECU integration testing — when multiple software components from different teams are combined for the first time. Issues that were invisible in unit tests frequently surface at this stage.
  • Supplier/OEM interface: This is a topic that frequently appears in technical discussions between Tier-1 ECU suppliers and OEM system integrators. Engineers who can speak fluently about these details earn credibility and are often brought into critical design review meetings.
  • Automotive tool ecosystem: Vector CANoe/CANalyzer, dSPACE tools, and ETAS INCA are the standard tools used to validate and measure the correct behaviour of the systems described in this lesson. Familiarity with these tools alongside the conceptual knowledge dramatically accelerates debugging in real projects.

⚠️ Common Mistakes and How to Avoid Them

  1. Assuming default configuration is correct: Automotive software tools ship with default configurations that are designed to compile and link, not to meet project-specific requirements. Every configuration parameter needs to be consciously set. 'It compiled' is not the same as 'it is correctly configured'.
  2. Skipping documentation of configuration rationale: In a 3-year ECU project with team turnover, undocumented configuration choices become tribal knowledge that disappears when engineers leave. Document why a parameter is set to a specific value, not just what it is set to.
  3. Testing only the happy path: Automotive ECUs must behave correctly under fault conditions, voltage variations, and communication errors. Always test the error handling paths as rigorously as the nominal operation. Many production escapes originate in untested error branches.
  4. Version mismatches between teams: In a multi-team project, the BSW team, SWC team, and system integration team may use different versions of the same ARXML file. Version management of all ARXML files in a shared repository is mandatory, not optional.

📊 Industry Note

Engineers who master both the theoretical concepts and the practical toolchain skills covered in this course are among the most sought-after professionals in the automotive software industry. The combination of AUTOSAR standards knowledge, safety engineering understanding, and hands-on configuration experience commands premium salaries at OEMs and Tier-1 suppliers globally.

← PreviousSoftware Safety Requirements SpecificationNext →Coding Guidelines: MISRA & CERT