| Timer Mode | Behaviour | Typical Use |
|---|---|---|
| One-shot | Starts, counts to period, fires callback once, stops | Software timeout; single delay |
| Continuous | Starts, counts to period, fires callback, auto-restarts | Periodic task trigger; heartbeat |
| Free-running | Counts continuously; application reads counter value | Elapsed time measurement; profiling |
| Output compare | Triggers output pin or callback at configurable count | PWM generation (alternative to PWM module) |
GPT Concepts and Timer Modes
GPT Timer Configuration
/* GPT configuration: 1ms periodic task trigger + 100ms timeout */
#include "Gpt.h"
const Gpt_ChannelConfigType Gpt_ChannelConfig[] = {
/* 1 ms periodic: triggers OsTask_1ms */
{
.GptChannelId = GPT_CH_1MS_TICK,
.GptChannelMode = GPT_MODE_CONTINUOUS,
.GptChannelTickFreq = 1000000u, /* 1 MHz tick (1 us resolution) */
.GptChannelTickValueMax = 0xFFFFFFFFu,
.GptNotification = Gpt_1ms_Notification,
.GptHwChannel = GPT_HW_STM0, /* Aurix STM timer */
},
/* 100 ms one-shot: NVM write timeout */
{
.GptChannelId = GPT_CH_NVM_TIMEOUT,
.GptChannelMode = GPT_MODE_ONESHOT,
.GptChannelTickFreq = 1000u, /* 1 kHz tick (1 ms resolution) */
.GptChannelTickValueMax = 0xFFFFu,
.GptNotification = Gpt_NvmTimeout_Notification,
.GptHwChannel = GPT_HW_STM1,
},
};
/* Usage: start 1ms periodic */
void Gpt_StartPeriodic(void)
{
Gpt_StartTimer(GPT_CH_1MS_TICK, 1000u); /* 1000 ticks @ 1MHz = 1ms */
Gpt_EnableNotification(GPT_CH_1MS_TICK);
}
/* Notification: fires every 1ms (in ISR context) */
void Gpt_1ms_Notification(void)
{
/* Increment AUTOSAR OS system counter or trigger task */
OsCounter_Increment(OS_COUNTER_SYSTEMTIMER);
}Watchdog Timer: MCAL Concepts
WdgM (Watchdog Manager) -- supervises software deadlines
|
Wdg_SetTriggerCondition(timeout_ms)
|
Wdg (MCAL) -- manages on-chip watchdog hardware register
|
Hardware: internal WDG (Aurix ENDINIT WDT) or external WDG IC
Wdg_SetTriggerCondition() must be called within timeout_ms window
If not called: WDG expires, MCU RESET
Modes:
- WDGIF_FAST_MODE: short timeout (typ. 10-100ms) -- normal operation
- WDGIF_SLOW_MODE: long timeout (typ. 1-10s) -- startup/sleep
- WDGIF_OFF_MODE: watchdog disabled -- dev/test only (ASIL-D: forbidden)
AUTOSAR WdgM periodically calls Wdg_SetTriggerCondition() from a supervised
task. If that task misses its deadline, no trigger -> reset.Watchdog Configuration
/* Watchdog configuration: Aurix TC387 internal ENDINIT WDT */
#include "Wdg.h"
const Wdg_SettingsType Wdg_FastModeSettings = {
.WdgSettingsMode = WDGIF_FAST_MODE,
/* Reload value sets timeout; formula: T = reload * (16384 / f_WDT) */
/* f_WDT = SPB/256 = 100MHz/256 = 390 kHz; 16384/390kHz = 42ms/count */
/* Target: 50ms timeout -> reload = ceil(50/42) = 2 */
.WdgReloadValue = 2u, /* ~50ms window */
};
const Wdg_SettingsType Wdg_SlowModeSettings = {
.WdgSettingsMode = WDGIF_SLOW_MODE,
.WdgReloadValue = 60u, /* ~2.5s window for startup */
};
/* Usage from WdgM integration (called by WdgM_MainFunction) */
void WdgM_PerformReset(void)
{
/* WdgM has detected a supervised entity violation -- force reset */
Wdg_SetTriggerCondition(0u); /* 0ms timeout = immediate reset */
}
/* Normal service: must be called within 50ms (fast mode) */
void WdgM_ServiceWatchdog(void)
{
Wdg_SetTriggerCondition(50u); /* refresh: next timeout in 50ms */
}Summary
The watchdog is the last safety net against software hangs and runaway code. The MCAL Wdg module is intentionally simple: it handles only the hardware register writes. WdgM (Watchdog Manager) above it implements the supervision logic: monitoring that each supervised entity (critical task or function) completes within its alive counter deadline. Never configure WDGIF_OFF_MODE in production code for safety-relevant systems - ISO 26262 ASIL-D requires the watchdog to be active. The GPT 1ms periodic timer is typically used to drive the AUTOSAR OS counter, which in turn activates tasks and alarm callbacks. Getting the GPT period value wrong by 10% means all timed functions (debounce, ramp rate, timeout) in the entire system are proportionally wrong.
🔬 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
- 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'.
- 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.
- 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.
- 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.