AUTOSAR_SWS_WatchdogDriver
Specification of Watchdog Driver
Introduction and functional overview
This document specifies the functionality, API and the configuration of the AUTOSAR Basic Software module watchdog driver (Wdg).
This module provides services for initialization, changing the operation mode and setting the trigger condition (timeout).
The functional requirements and the functional scope are the same for both internal and external watchdog drivers. Hence the API is semantically identical.
An internal watchdog driver belongs to the Microcontroller Abstraction Layer (MCAL), whereas an external watchdog driver belongs to the Onboard Device Abstraction Layer. Therefore, an external watchdog driver needs other drivers (in MCAL) in order to access the microcontroller hardware.
Acronyms and Abbreviations
The glossary below includes acronyms and abbreviations relevant to the Watchdog Driver module that are not included in the [1, AUTOSAR glossary].
Input documents & related standards and norms
[1] Glossary
- AUTOSAR_TR_Glossary
[2] General Specification of Basic Software Modules
- AUTOSAR_SWS_BSWGeneral
[3] Layered Software Architecture
- AUTOSAR_EXP_LayeredSoftwareArchitecture
[4] Requirements on Watchdog Driver
- AUTOSAR_SRS_WatchdogDriver
[5] General Requirements on Basic Software Modules
- AUTOSAR_SRS_BSWGeneral
[6] General Requirements on SPAL
- AUTOSAR_SRS_SPALGeneral
Related specification
AUTOSAR provides a General Specification on Basic Software modules [2, SWS BSW General], which is also valid for Watchdog Driver.
Thus, the specification SWS BSW General shall be considered as additional and required specification for Watchdog Driver.
Dependencies to other modules
A Wdg module for an internal (on-chip) watchdog accesses the microcontroller hardware directly and is located in the Microcontroller Abstraction layer.
A Wdg module for an external watchdog uses other modules (e.g. SPI) to access the external watchdog device. Such a Wdg module is located in the Onboard Device Abstraction Layer (see [3]).
[SWS_Wdg_00055]
[ ]
- The Wdg module for an external watchdog driver shall have source code that is independent of the microcontroller platform.
File structure
Code file structure
[SWS_Wdg_00079]
[SRS_BSW_00346]
[SRS_BSW_00314]
[SRS_SPAL_12263]
- The code file structure shall not be defined within this specification completely. At this point it shall be pointed out that the code-file structure shall include the following files (as far as required; for name expansion see SWS_ Wdg_00169):
- Wdg_Lcfg.c - for link time configurable parameters
- Wdg_PBcfg.c - for post build time configurable parameters
- In case an internal watchdog servicing is implemented as interrupt routine, code-file structure shall include Wdg_Irq.c for holding the interrupt frames.
- These files shall contain all link time and post-build time configurable parameters.
Note:
These names are required by SRS_BSW_00314 and SRS_BSW_00346.
[SWS_Wdg_00169]
[SRS_BSW_00347]
- If more than one watchdog driver instance exists on an ECU (namely an external and an internal one) the implementer shall provide unique code file names by expanding the names according to SRS_BSW_00347.
Header file structure
[SWS_Wdg_00170]
[SRS_BSW_00347]
- If more than one watchdog driver instance exists on an ECU (namely an external and an internal one) the implementer shall provide unique header file names by expanding the names according to SRS_BSW_00347.
Note:
In case of multiple watchdog driver instances, the Event Id symbols for production errors defined in this specification (see SWS_Wdg_00010 and ECUC_Wdg_00148) might be expanded in the configuration of the DEM in order to make them unique.
Version check
For details refer to the chapter 5.1.8 "Version Check" in SWS_BSWGeneral.
System clock
If the hardware of the internal watchdog depends on the system clock, changes to the system clock (e.g. PLL on PLL off) may also affect the clock settings of the watchdog hardware.
Onboard communication handlers
A Wdg module for an external watchdog device depends on the API and capabilities of the used onboard communication handlers or drivers (e.g. SPI handler).
Requirements Tracing
The following tables reference the requirements specified in [4] and links to the fulfillment of these. Please note that if column "Satisfied by" is empty for a specific requirement this means that this requirement is not fulfilled by this document.
General design rules
[SWS_Wdg_00086]
[SRS_BSW_00167]
[SRS_BSW_00004]
- The Wdg module shall statically check the configuration parameters (at the latest during compile time) for correctness.
[SWS_Wdg_00031]
[SRS_BSW_00336]
[SRS_SPAL_12163]
- The Wdg module shall not implement an interface for deinitialization/shutdown. If the watchdog supports a de-initialization/shutdown and the environment allows the usage of this feature, the de-initialization/shutdown shall be achieved by calling the Wdg_SetMode routine with OFF mode parameter.
Rationale:
Some watchdogs do not support the de-initialization/shutdown functionality and in some environments this feature must not be used (e.g. in safety critical systems).
[SWS_Wdg_00040]
[SRS_BSW_00426]
[SRS_BSW_00429]
- If interrupts have to be disabled in order to ensure data consistency or correct functionality of this module (e.g. while switching the watchdog mode or during the watchdog trigger routine), this shall be done by using the corresponding BSW Scheduler functionality if possible (this means definition of an exclusive area). The internal watchdog driver (because it belongs to MCAL) may also directly disable interrupts - see SRS_BSW_00429.
[SWS_Wdg_00168]
[ ]
- Depending on a static configuration (see ECUC_Wdg_00147), the code of the Wdg module is executed either from ROM or from RAM.
Motivation:
For certain use cases, e.g. for flash programming in bootloader mode, the watchdog module has to be part of an executable which runs in RAM.
Hint:
This is more a requirement for the build environment than for the watchdog module itself. However, since it might also influence the implementation of the code, it is stated here and a corresponding configuration parameter is given.
External watchdog driver
[SWS_Wdg_00076]
[SRS_SPAL_12092]
- To access the external watchdog hardware, the corresponding Wdg module instance shall use the functionality and API of the corresponding handler or driver, e.g. the SPI handler or DIO driver.
Note:
The routine servicing an external watchdog may be implemented by usage of an own internal hardware timer to be independent from other peripherals or by using a GPT driver callback.
Hint:
An external watchdog driver is part of the Onboard Device Abstraction Layer (see [3]), which excludes direct hardware access.
This architectural discrepancy will be resolved in an upcoming release.
[SWS_Wdg_00077]
[SRS_Wdg_12165]
- A Wdg module for an external watchdog shall satisfy the same functional requirements and offer the same functional scope as a Wdg module for an internal watchdog. Hence their respective APIs are semantically identical.
[SWS_Wdg_00078]
[SRS_Wdg_12166]
- The Wdg module shall add all parameters required for accessing the external watchdog hardware, e.g. the used SPI channel or DIO port, to the module's published parameters and to the module's configuration parameters.
Internal watchdog driver
[SWS_Wdg_00161]
[ ]
- To access the internal watchdog hardware, the corresponding Wdg module instance shall access the hardware for watchdog servicing directly.
Hint:
An internal watchdog driver is part of the Microcontroller Abstraction Layer (see [3]), which allows direct hardware access.
Note:
The routine servicing an internal watchdog may be implemented by usage of an internal hardware timer to be independent from other peripherals or by using a GPT driver callback."
If the watchdog servicing routine is implemented as an interrupt routine (i.e. as a cat1 or cat2 interrupt routine and not via the GPT), it shall be described in the Basic Software Module Description and the implementation shall follow the requirements for interrupt handling as given by [5] and [6] (SRS_BSW_00427, SRS_BSW_00325, SRS_ BSW_00439, SRS_BSW_00314, SRS_BSW_00429, SRS_SPAL_12129).
Triggering concept to support windowed watchdogs
In former versions of this specification, the watchdog servicing routine was called from an upper layer of the software which made it difficult to guarantee timing constraints namely for windowed watchdog conditions. This concept has been changed leading to the requirements explained in this chapter.
The basic idea of this concept is to decouple the timing for servicing the watchdog hardware from the logical control.
The time base for triggering the watchdog may be provided by means of hardware. This ensures minimum timing jitter. Servicing of the watchdog hardware directly from a timer ISR ensures minimum latencies."
These two conditions - minimum jitter and latencies - ensure that the time window of a windowed watchdog can be met.
The Wdg Driver expects, that the logical control of the watchdog (whether the watchdog shall be triggered or not) shall be the responsibility of the environment, e.g. the Wdg Manager, so that the basic concepts of the Wdg Manager (alive supervision) shall remain unchanged.
[SWS_Wdg_00144]
[SRS_Wdg_12019]
- The Wdg Manager (or other entities) shall control the watchdog driver via a so called trigger condition: as long as the trigger condition is valid the Wdg Driver services the watchdog hardware, if the trigger condition becomes invalid the Wdg Driver stops triggering and the watchdog expires.
- The semantics of the trigger condition can be interpreted as a "permission to service the watchdog for the next n milliseconds". Within this time frame the trigger condition has to be updated by the controlling entity else the watchdog will expire.
- Handover of the watchdog control logic is simply done by shared usage of the trigger condition (e.g. during startup / shutdown).
[SWS_Wdg_00134]
[SRS_Wdg_12019]
- If the trigger counter is greater than zero, the watchdog servicing routine shall decrement the trigger counter and trigger the hardware watchdog.
[SWS_Wdg_00135]
[SRS_Wdg_12019]
- If the trigger counter has reached zero, the watchdog servicing routine shall do nothing (i.e. the watchdog is not triggered and will therefore expire).
[SWS_Wdg_00093]
[SRS_Wdg_12019]
- If the watchdog hardware requires an activation code which can be configured or changed, the Wdg Driver shall handle the activation code internally. In this case, the Wdg Driver shall pass the correct activation code to the watchdog hardware and the watchdog hardware in turn shall update the Wdg module's internal variable where the next expected access code is stored.
[SWS_Wdg_00094]
[SRS_Wdg_12019]
- If the watchdog hardware requires an activation code which can be configured or changed, the trigger cycle of the Wdg Driver shall be defined with a value so that updating the activation code by the watchdog hardware can be guaranteed (see Figure 2).
[SWS_Wdg_00095]
[SRS_Wdg_12019]
- If the watchdog hardware requires an activation code which can be configured or changed and the initial activation code can be configured, the activation code shall be provided in the Wdg Driver's configuration set. If the activation code is fixed for a particular hardware the above requirement can be ignored.
[SWS_Wdg_00035]
[SRS_BSW_00337]
- When development error detection is enabled for the Wdg Driver module: the watchdog servicing routine shall check whether the Wdg module's state is WDG_IDLE (meaning the watchdog driver and hardware are initialized and the watchdog is currently not being triggered or switched). If this is not the case, the function shall not trigger the watchdog hardware but raise the development error WDG_E_DRIVER_ STATE.
[SWS_Wdg_00052]
[SRS_BSW_00337]
- When development error detection is enabled for the Wdg Driver module: the watchdog servicing routine shall set the Wdg module's state to WDG_ BUSY during its execution (indicating, that the module is busy) and shall reset the module's state to WDG_IDLE (indicating, that the module is initialized and not busy) as last operation before it returns.
Note:
This specification prescribes the symbols WDG_IDLE and WDG_BUSY only, if they are externally visible, e.g. for debugging (see SRS_BSW_00335). Choosing the data type for the status variable is up to the implementation.
Hint for the integration:
The Wdg module's environment shall make sure that the Wdg Driver module has been initialized before watchdog servicing routine is called.
Error Classification
Section 7.x "Error Handling" of the document "General Specification of Basic Software Modules" describes the error handling of the Basic Software in detail. Above all, it constitutes a classification scheme consisting of five error types which may occur in BSW modules.
Based on this foundation, the following section specifies particular errors arranged in the respective subsections below.
Development Errors
Extended Production Errors
[SWS_Wdg_00178]
[ ]
[SWS_Wdg_00180]
[SRS_BSW_00327]
[SRS_BSW_00331]
[SRS_BSW_00466]
[SRS_BSW_00385]
- The extended production error WDG_E_MODE_FAILED shall be reported with FAILED when setting of the watchdog mode failed.
[SWS_Wdg_00181]
[SRS_BSW_00327]
[SRS_BSW_00331]
[SRS_BSW_00466]
[SRS_BSW_00385]
- The extended production error WDG_E_MODE_FAILED shall be reported with PASSED when setting of the watchdog mode not failed.
[SWS_Wdg_00179]
[ ]
[SWS_Wdg_00182]
[SRS_BSW_00327]
[SRS_BSW_00331]
[SRS_BSW_00466]
[SRS_BSW_00385]
- The extended production error WDG_E_DISABLE_REJECTED shall be reported with FAILED when disabling of the watchdog mode failed.
[SWS_Wdg_00183]
[SRS_BSW_00327]
[SRS_BSW_00331]
[SRS_BSW_00466]
[SRS_BSW_00385]
- The extended production error WDG_E_DISABLE_REJECTED shall be reported with PASSED when disabling of the watchdog mode not failed.
API specification
[SWS_Wdg_00172]
[SRS_BSW_00347]
- If more than one watchdog driver instance exits on an ECU (namely an external and an internal one) the API names and instance specific type names specified in this chapter shall be made unique by expansion according to SRS_ BSW_00347.
Imported types
In this chapter all types included from the following modules are listed:
[SWS_Wdg_00105]
[ ]
Type definitions
Wdg_ConfigType
Function definitions
Wdg_Init
[SWS_Wdg_00001]
[SRS_BSW_00400]
[SRS_BSW_00101]
[SRS_Wdg_12105]
- The Wdg_Init function shall initialize the Wdg module and the watchdog hardware, i.e. it shall set the default watchdog mode and timeout period as provided in the configuration set.
Note:
Via post-build configuration, the user can choose the configuration set to be used with the Wdg_Init function from a limited number of statically configured sets (see also SRS_BSW_00314).
[SWS_Wdg_00100]
[SRS_SPAL_12057]
[SRS_SPAL_12125]
[SRS_SPAL_12461]
[SRS_Wdg_12105]
- The Wdg_Init function shall initialize all global variables of the Wdg module and set the default watchdog mode and initial timeout period
[SWS_Wdg_00101]
[SRS_SPAL_12057]
[SRS_SPAL_12125]
[SRS_SPAL_12461]
[SRS_Wdg_12105]
- The Wdg_Init function shall initialize those controller registers that are needed for controlling the watchdog hardware and that do not influence/depend on other (hardware) modules.
- Registers that can influence or depend on other modules are initialized by a common system module.
[SWS_Wdg_00025]
[SRS_BSW_00323]
[SRS_SPAL_12163]
[SRS_Wdg_12106]
- If disabling the watchdog is not allowed (because pre-compile configuration parameter WdgDisableAllowed == OFF) and if the default mode given in the provided configuration set disables the watchdog, the Wdg_Init function shall not execute the initialization but raise the extended production error WDG_E_DISABLE_ REJECTED.
[SWS_Wdg_00173]
[ ]
- If switching the Wdg module and the watchdog hardware into the default mode is not possible, e.g. because of inconsistent mode settings or because some timing constraints have not been met, the Wdg_Init function shall raise the extended production error WDG_E_MODE_FAILED.
[SWS_Wdg_00090]
[SRS_BSW_00323]
[SRS_SPAL_12448]
- When development error detection is enabled for the Wdg module: The Wdg_Init function shall check that the (hardware specific) contents of the given configuration set is within the allowed boundaries. If this error is detected, the function Wdg_Init shall not execute the initialization but raise the extended error WDG_ E_PARAM_CONFIG.
[SWS_Wdg_00019]
[SRS_BSW_00406]
[SRS_BSW_00335]
- When development error detection is enabled for the Wdg module: The Wdg_Init function shall set the Wdg module's internal state from WDG_ UNINIT (the default state indicating a non-initialized module) to WDG_IDLE if the initialization was successful.
Note:
This specification prescribes the symbols WDG_IDLE and WDG_UNINIT only, if they are externally visible, e.g. for debugging (see SRS_BSW_00335). Choosing the data type for the status variable is up to the implementation.
Wdg_SetMode
[SWS_Wdg_00107]
[ ]
[SWS_Wdg_00160]
[SRS_Wdg_12015]
[SRS_Wdg_12018]
- The function Wdg_SetMode shall switch the watchdog driver from the current watchdog mode into the mode given by the argument Mode. This means: By choosing one of a limited number of statically configured settings (e.g. toggle or window watchdog, different timeout periods) the Wdg module and the watchdog hardware are switched to one of the following three different modes:
- WDGIF_OFF_MODE
- WDGIF_SLOW_MODE
- WDGIF_FAST_MODE
[SWS_Wdg_00051]
[SRS_Wdg_12015]
- The configuration set provided to the Wdg module's initialization routine shall contain the hardware/driver specific parameters to be used in the different watchdog modes.
[SWS_Wdg_00145]
[ ]
- The Wdg_SetMode function shall reset the watchdog timeout counter based on the new watchdog mode i.e. the timeout frame remaining shall be recalculated based on a changed trigger period.
[SWS_Wdg_00103]
[ ]
- The Wdg_SetMode function shall return E_OK if the mode switch has been executed completely and successfully, i.e. all parameters of the Wdg module and the watchdog hardware have been set to the new values
[SWS_Wdg_00016]
[SRS_SPAL_12064]
- If switching the Wdg module and the watchdog hardware into the requested mode is not possible, e.g. because of inconsistent mode settings or because some timing constraints have not been met, the Wdg_SetMode function shall return the value E_NOT_OK and raise the extended production error WDG_E_MODE_ FAILED.
[SWS_Wdg_00026]
[SRS_BSW_00323]
[SRS_SPAL_12163]
[SRS_Wdg_12106]
- If disabling the watchdog is not allowed (e.g. in safety relevant systems, seeECUC_Wdg_00115) the Wdg_SetMode function shall check whether the settings for the requested mode would disable the watchdog. In this case, the function shall not execute the mode switch but raise the extended production error WDG_ E_DISABLE_REJECTED and return with the value E_NOT_OK.
[SWS_Wdg_00091]
[SRS_BSW_00323]
[SRS_SPAL_12448]
- When development error detection is enabled for the Wdg module: The Wdg_SetMode function shall check that the parameter Mode is within the allowed range. If this is not the case, the function shall not execute the mode switch but raise development error WDG_E_PARAM_MODE.
[SWS_Wdg_00092]
[SRS_BSW_00323]
[SRS_SPAL_12448]
- When development error detection is enabled for the Wdg module: The Wdg_SetMode function shall check that the (hardware specific) settings for the requested mode are within the allowed boundaries. If this is not the case, the function shall not execute the mode switch but raise the development error WDG_E_ PARAM_MODE.
[SWS_Wdg_00017]
[SRS_BSW_00335]
[SRS_SPAL_12064]
[SRS_SPAL_12448]
- When development error detection is enabled for the Wdg module: The Wdg_SetMode function shall check that the Wdg module's state is WDG_IDLE (meaning the Wdg module and the watchdog hardware are initialized and the watchdog is currently not being triggered or switched). If this is not the case, the function shall not execute the mode switch but raise the development error WDG_E_DRIVER_ STATE.
[SWS_Wdg_00018]
[SRS_BSW_00335]
- When development error detection is enabled for the Wdg module: The function Wdg_SetMode shall set the Wdg module's state to WDG_BUSY during its execution (indicating, that the module is busy) and shall reset the Wdg module's state to WDG_IDLE as last operation before it returns to the caller.
Note:
This specification prescribes the symbols WDG_IDLE and WDG_BUSY only, if they are externally visible, e.g. for debugging (see SRS_BSW_00335). Choosing the data type for the status variable is up to the implementation.
Wdg_SetTriggerCondition
[SWS_Wdg_00136]
[ ]
- The function Wdg_SetTriggerCondition shall reset the watchdog timeout counter according to the timeout value passed.
[SWS_Wdg_00138]
[ ]
- The timeout value passed shall be interpreted as 'milliseconds'. The conversion from milliseconds to the corresponding counter value shall be done internally by the Wdg module.
[SWS_Wdg_00139]
[ ]
- The current watchdog mode shall be taken into account when calculating the counter value from the timeout parameter.
[SWS_Wdg_00140]
[ ]
- This function shall also allow to set "0" as the time frame for triggering which will result in an (almost) immediate stop of the watchdog triggering and an (almost) instantaneous watchdog reset of the ECU. In case the counter value stored inside watchdog has the value "0", the service Wdg_SetTriggerCondition shall do nothing, which means it shall ignore the counter passed by the parameter to Wdg_ SetTriggerCondition.
[SWS_Wdg_00146]
[ ]
- When development error detection is enabled for the module: The function Wdg_SetTriggerCondition shall check that the timeout parameter given is less or equal to the maximum timeout value (WdgMaxTimeout). If this is not the case the function shall not reload the timeout counter but raise the development error WDG_ E_PARAM_TIMEOUT and return to the caller.
Wdg_GetVersionInfo
[SWS_Wdg_00174]
[ ]
- If development error detection is enabled for the Wdg Driver module, the function Wdg_GetVersionInfo shall raise WDG_E_PARAM_POINTER, if the argument is a NULL pointer and return without any action.
Expected interfaces
This chapter lists all functions that the Wdg module requires from other modules.
Mandatory interfaces
This module does not require any mandatory interfaces.
Optional interfaces
This chapter lists all interfaces which are required to fulfill an optional functionality of the module.
In addition to the functions listed above, further functions might be used to access the external watchdog over Dio or Spi.
Sequence diagrams
Watchdog initialization, setting trigger condition and mode.
The diagram shows the sequence to initialize the Wdg module, to set the trigger condition and to change the watchdog mode. Note that this is only an example. Especially, another "client" module than the Watchdog Manager (WdgM) could set the trigger condition.
The diagram shows the sequence to trigger the watchdog hardware when the WDG servicing routine is implemented as an interrupt routine. Note that this is only an example and the triggering routine is implementation specific. For an external watchdog, the watchdog hardware cannot be accessed directly, but only via drivers of the MCAL layer, like SPI or DIO.
Configuration specification
In general, this chapter defines configuration parameters and their clustering into containers. In order to support the specification Chapter 10.1 describes fundamentals. It also specifies a template (table) you shall use for the parameter specification. We intend to leave Chapter 10.1 in the specification to guarantee comprehension.
Chapter 10.2 specifies the structure (containers) and the parameters of the module Wdg.
Chapter 10.3 specifies published information of the module Wdg.
How to read this chapter
For details refer to the chapter 10.1 "Introduction to configuration specification" in SWS_BSWGeneral.
Containers and configuration parameters
The following chapters summarize all configuration parameters. The detailed meanings of the parameters describe Chapter 7 and Chapter 8.
Wdg
The three modes are provided as containers for the reason that they might be referred by other modules and hence no parameters are needed. However those containers might be extended by the vendor (resp. hardware) specific configuration parameters, but these could not be standardized.
WdgSettingsFast
For details refer to the chapter 10.3 "Published Information" in SWS_BSWGeneral.
WdgPublishedInformation
WdgTriggerMode is only published for information purposes; this parameter is not used to configure the Watchdog Driver or the modules using the Watchdog Driver.
评论
发表评论