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

CAN MCAL Architecture

CAN Driver Stack
  CanNm / CanTp / CanSM (higher layers)
        |
  CanIf (CAN Interface) -- PDU routing, Tx confirmation, Rx indication
        |
  Can (MCAL) -- mailbox management, bit timing, controller mode
        |
  CanTrcv (MCAL) -- transceiver mode (Normal/Standby/Sleep/Wakeup)
        |
  Hardware: CAN controller (on-chip) + CAN transceiver IC (TJA1044, TJA1042...)

  Can module responsibilities:
  - Configure CAN controller (bit timing, mailboxes, filters)
  - Transmit: Can_Write() -> loads mailbox -> hardware sends frame
  - Receive: CAN Rx ISR fires -> Can calls CanIf_RxIndication()
  - Mode control: Can_SetControllerMode(STARTED/STOPPED/SLEEP)
  - Error handling: Can_MainFunction_BusOff() polls bus-off state

  CanTrcv module responsibilities:
  - Set TJA1044 mode pin: NormalMode/StandbyMode/SleepMode
  - SBC (System Basis Chip) may combine CAN Tx with power management

CAN Bit Timing Configuration

Ccan_bit_timing.c
/* CAN bit timing: fCAN = 80 MHz, target = 500 kbit/s */
/* Bit time = 1/500000 = 2000 ns */
/* Time quantum (tq): fCAN / prescaler = 80 MHz / 4 = 20 MHz -> tq = 50 ns */
/* Total TQs per bit: 2000 ns / 50 ns = 40 TQ */
/* Segment split: SYNC(1) + PROP+SEG1(31) + SEG2(8) = 40 TQ */
/* Sample point: (1+31)/40 = 80% -- automotive standard */

const Can_ControllerConfigType CanControllerConfig[] = {
    {
        .CanControllerId    = CAN_CONTROLLER_0,
        .CanControllerBaudRate = 500u,    /* kbit/s */
        /* Classical CAN bit timing */
        .CanBitTimingConfig = {
            .CanCpuClockRef  = 80000u,    /* kHz - peripheral clock */
            .CanPropSeg      = 15u,       /* propagation segment TQ */
            .CanSeg1         = 16u,       /* phase segment 1 TQ */
            .CanSeg2         = 8u,        /* phase segment 2 TQ */
            .CanSyncJumpWidth= 4u,        /* SJW TQ (resync tolerance) */
            .CanPrescaler    = 4u,        /* CAN clock / 4 = 20 MHz tq clock */
        },
        /* CAN FD data phase: 2 Mbit/s */
        .CanFdBitTimingConfig = {
            .CanFdPropSeg    = 3u,
            .CanFdSeg1       = 4u,
            .CanFdSeg2       = 2u,
            .CanFdSJW        = 1u,
            .CanFdPrescaler  = 4u,        /* 80 MHz / 4 = 20 MHz -> 2 Mbit/s */
        },
        .CanControllerActivation = TRUE,
    },
};

/* Mode control */
void CanController_Start(void)
{
    Can_Init(&CanConfig);
    Can_SetControllerMode(CAN_CONTROLLER_0, CAN_CS_STARTED);
    CanTrcv_SetOpMode(CANTRCV_CHANNEL_0, CANTRCV_TRCVMODE_NORMAL);
}

CanTrcv: Transceiver Mode Management

ModeTJA1044 Pin StateECU Bus StateMCAL Call
NormalEN=H, STB=LFull CAN operationCanTrcv_SetOpMode(NORMAL)
StandbyEN=L, STB=HBus monitoring; no TxCanTrcv_SetOpMode(STANDBY)
SleepEN=L, STB=LLowest power; wake on bus activityCanTrcv_SetOpMode(SLEEP)
WakeupTransition from SleepDetected by CanTrcv ISRCanTrcv_CheckWakeup() called

Summary

CAN bit timing configuration is the most mathematically demanding MCAL task. The formula is fixed: bit_time = (1 + PROP + SEG1 + SEG2) * tq, where tq = 1 / (fCAN / prescaler). Getting the sample point wrong (below 75% or above 87.5% for automotive CAN) causes bit errors on long harnesses where signal propagation delay is significant. CAN FD adds a second bit timing register set for the data phase - the data phase prescaler must produce the same tq as the arbitration phase, and the TDC (Transmitter Delay Compensation) must be configured for FD speeds above 1 Mbit/s or transmissions will be corrupted by the Tx-to-Rx signal path delay in the CAN transceiver IC.

🔬 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.

← PreviousHands-On: MCU Port ConfigurationNext →SPI Handler/Driver: SPI for External ICs