Watchdog Driver in AUTOSAR

After reading  this article you will learn :

  1. Use of watchdog driver.
  2. Fast Mode, Slow Mode and OFF mode of watchdog.
  3. Triggering of Watchdog (Internal/External)
  4. Important configuration parameters for Watchdog.



1. Introduction to Watchdog Driver :


Watchdog driver present in MCAL layer of AUTOSAR. Main use of watchdog driver is to trigger HW watchdog.

Watchdog driver is used to initialize HW watchdog, trigger the watchdog and to change the mode of watchdog(Slow/Fast/OFF).

If internal watchdog (internal to MCU) is not used and external watchdog is used (external to MCU),then driver for external watchdog present in onboard abstraction layer (ECU Abstraction) and this driver needs other MCAL driver (e.g. SPI) to communicate  with external watchdog.


Fig.1 AUTOSAR Watchdog Stack




Fig 1. Shows location of watchdog driver in AUTOSAR stack, it shows internal as well as external watchdog driver. If you are not aware about what is watchdog then please read blog about watchdog.If you are aware about watchdog concept, then in next chapter we will see how watchdog functionality is used in AUTOSAR.




2. AUTOSAR Watchdog Concepts :


Watchdog has its counter, when system starts and wdg is initialized (Wdg_Init () functin provided by AUTOSAR watchdog driver to initialise HW watchdog driver) this counter starts counting from 0.When count reaches to particular count (watchdog timeout period), watchdog will generate reset. To avoid reset, SW need to trigger watchdog before watchdog count reaches to certain value.

e.g Watchdog timeout period is configured as 100ms. 

Clock to watchdog is 1Khz.

1 tick of clock = 1ms

watchdog counter will starts with 0 and when it reaches to 100 i.e. 100ms is over and SW did not trigger the watchdog and watchdog will generate reset.


2.1 What is Slow Mode, Fast Mode and OFF Mode :

  • Slow mode means timeout of watchdog is high e.g 1000ms (Generally used at system startup) 
  • Fast mode means timeout of watchdog is low e.g. 100ms (Generally used at run time)
  • OFF mode means watchdog functionality is OFF. (if WdgDisableAllowed is configured to true)
While configuration of Watchdog driver you can decide what should be the init mode(slow/fast).Later at run time watchdog manager changes the mode(slow/fast) as per configuration. Wdg_SetMode() is the function provided by watchdog driver.

2.2 How to trigger Watchdog at right time? 

To trigger watchdog at correct time, in AUTOSAR it is mentioned that use GPT timer service. e.g. if you want to trigger watchdog at 60ms, then configure GPT timer for 60ms and use GPT interrupt (ISR) mechanism to trigger the watchdog at particular time.

Note : Start GPT timer immediately after WDG is triggered.

e.g. if watchdog timeout period is 100ms and you want to trigger watchdog every 75ms then configure GPT timer for 75 ms. Now once WDG driver is initialized and trigger is provided to internal/external watchdog (i.e. WDG counter starts from counting 0), immediately after this start  GPT timer.

Trigger to external watchdog can be done by Spi/Dio.

Triggering Condition :

As mentioned in above section, trigger watchdog by using GPT services (ISR), but while triggering watchdog , triggering condition should be considered. Triggering condition is updated by Watchdog Manager. If triggering condition is set (i.e trigger counter>0)  then trigger HW watchdog else do not trigger the watchdog (this will leads watchdog counter overflow and generate watchdog reset).  i.e. watchdog manager sets triggering condition and based on that watchdog driver decides to trigger watchdog or not. 

Wdg_SetTriggerCondition(timeout) function provided by watchdog driver to set triggering condition/ trigger counter counter as provided by watchdog manager (it could be 0 or > 0).


Fig.2 Triggering Watchdog

Consider above image provided by Autosar WDG SWS (4.2.2), 

  1. Here it is shown sequence for watchdog triggering. Watchdog manager sets triggering condition based on supervision performed by watchdog manager.
  2. Once interrupt occurred (i.e. GPT interrupt), based on trigger condition WDG driver either triggers watchdog HW or do not trigger HW watchdog.
  3. External watchdog triggering is performed by SPI/DIO driver.




3. Important Configuration Parameters :


While configuration of Watchdog Driver please note below parameters

  1. Watchdog Clock reference :Clock to watchdog
  2. Initial/Default Watchdog Mode : Slow or Fast Mode or OFF
  3. Slow mode timeout : WDG timeout in case slow mode
  4. Fast Mode timeout :WDG timeout in case fast mode
  5. Initial timeout : Default/initial WDG timeout
  6. Disabling of WDG allowed : WdgDisableAllowed
  7. For external WDG provide reference to external module (a DioChannelGroup container in case the hardware watchdog is connected via DIO pins - an SpiSequenceConfiguration container in case the watchdog hardware is accessed via SPI)
  8. If Watchdog is external (e.g. SBC) then configure SPI/DIO (as per need) and configure SBC WDG setting as per SBC watchdog data sheet.


Post a Comment