Watchdog Manager
Tags: programming, softwaredevelopment, softwareengineering, software
Published: 2023-12-28 17:59:14

Hello Readers,
My name is Santosha S Chikkur, and I work at Luxoft India as a Junior Software Developer. Luxoft has given me several opportunities to work on various projects, which has inspired me to learn the essential processes involved in developing AUTOSAR Modulеs and Add-Ons in Watchdog Manager


**Introduction**

Watchdog manager (WDGM) is present at the service layer of the AUTOSAR stack as seen. ask of the watchdog manager is to supervise software execution and if it finds an error or flaw in the execution of software, WDGM takes action on it. SWCs use services provided by WDGM, using a client-server interface. SWC are client and WDGM is the server.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n633z2nk5x37qrjsvxm5.png)

**Functionality of WDGM:**
Functionality of WDGM is
- To supervise the SW and to supervise software, the watchdog manager uses supervised entities.
- WDGM can change the mode of the WDG driver (Slow, Fast, or OFF).
- WDGM updates the trigger condition if SW tracking is good. - If the overall monitor status is not good, reset the ECU or do not set the trigger condition, so that the WDG controller does not trigger the WDG and the WDG generates a restart.


**Supervision and Supervised Entity:**
**What is a supervised entity ?**
Supervised entities (SEs) are nothing but runnable within Software Component (SWC), BSW, or CDD.

**What WDGM supervises ?**

WDGM monitors monitored units in SWCs and verifies that: 
1. Monitored units (software) are periodically started according to configuration, e.g. if a runnable has a frequency of 10ms so in 50ms runnable should have executed 5 times so the watchdog manager monitors if SEs are getting executed a number of times per configuration. 
2. The flow of SEs or sequence of execution of SEs is according to a model (e.g. code is getting executed in the correct sequence).
3. SEs are getting executed within expected time? (e.g. 
if executable A should stop executing after 5ms, the WDG controller checks.)

**What is Checkpoint ?**

How did WDGM get to know that the supervised entity has been executed?

Supervised entities use checkpoint and when a checkpoint (i.e. particular area or line in code may be the start of runnable, end of runnable, or in between some code line of runnable ) is reached while execution, supervised entities notify to watchdog manager that this checkpoint is reached (i.e. it is executed).

Supervised entities use the port provided by WDGM to notify checkpoint reached, using the client server mechanism Function Provided by WDGM is 

Std_ReturnType WdgM_CheckpointReached ( 
 WdgM_SupervisedEntityIdType SEID,
 WdgM_CheckpointIdType CheckpointID
 )

There can be multiple checkpoint in one runnable or a single check point in one runnable that depends on the design and can be configurable.

Watchdog manager keeps track of check points reached indication and calculates the status of supervision based on supervision function. The status of supervision is calculated in the supervision cycle.

**What is the supervision cycle?** 

Frequency at which watchdog manager supervises supervised entities. e.g. if the supervision cycle is configured as 50ms then every 50ms watchdog manager supervises the supervised entities and checks the status of supervised entities as per configuration.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yqdrpx05n1htvw72e5tq.png)


In a system, there are multiple runnable and among them 2 are selected as supervised entities. Supervision cycle of WDGM is configured to 50ms. The cyclicity of SE1 is 5 ms and the cyclicity of SE2 is 10 ms. 
Every 5ms SE1 and every 10ms SE2 indicates that a checkpoint has been reached in the WDGM ie. indicates to WDG, that a particular line(or area) in code is reached.
 
Every 100ms WDGM will calculate the status of SEs based on checkpoints reported by SEs and the supervision function decides if the status of SE is correct or incorrect.

WDGM calculates the local monitoring status based on the monitoring status of each SE in the system. Based on local supervision status WDGM calculates Global supervision status and decides whether SW execution is OK or not. 

**WDG Triggering:**
WDGM is no longer responsible for launching the WDG driver, as of the AUTOSAR version , the WDGM program flag is set to true or false. i.e. sets triggering condition to TRUE or FALSE based on Global supervision status. WDGM uses the function WdgIf_SetTriggerConditionto() to update a flag.

WDG driver reads the flag i.e. triggering condition and based on the triggering condition (if TRUE) triggers the watchdog to avoid reset. 

**Supervision Functions and working**

In the above section, you have learnt that WDGM supervises supervised entities by using supervision functions. 
WDGM performs this task in each monitoring cycle, and monitored entities report their status to WDGM using the CheckpointReached (WdgM_CheckpointReached) function. WDGM calculates the status of supervision based on supervision functions and these supervision functions are:


**Conclusion:** 
In the complex field of automotive software, Watchdog Manager (WDGM) emerges as the silent hero to ensure the smooth running of software tasks. Keeping a close eye on it, keeping track of checkpoints, and organizing the items to be inspected will contribute to a safer and more reliable driving experience. As an important part of AUTOSAR, WDGM's collaboration with Watchdog (WDG) reflects the industry's commitment to improving vehicle safety and reliability. In every journey, WDGM ensures a quiet driving experience and embodies the future of innovation in the automotive industry. Nice roads ahead!

This will be continued in the next article, including examples. Please let me know in the comments below if you have any questions. Thanks for reading.