iLLD_TC27xC  1.0
IfxScuWdt.h
Go to the documentation of this file.
1 /**
2  * \file IfxScuWdt.h
3  * \brief SCU basic functionality
4  * \ingroup IfxLld_Scu
5  *
6  * \version iLLD_0_1_0_10
7  * \copyright Copyright (c) 2013 Infineon Technologies AG. All rights reserved.
8  *
9  *
10  * IMPORTANT NOTICE
11  *
12  *
13  * Infineon Technologies AG (Infineon) is supplying this file for use
14  * exclusively with Infineon's microcontroller products. This file can be freely
15  * distributed within development tools that are supporting such microcontroller
16  * products.
17  *
18  * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
19  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
20  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
21  * INFINEON SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
22  * OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
23  *
24  *
25  * This file contains the APIs for SCU Watchdog and Endinit related functions.
26  *
27  * \defgroup IfxLld_Scu_Std Standard Driver
28  * \ingroup IfxLld_Scu
29  * \defgroup IfxLld_Scu_Std_Wdt_Configuration Watchdog Configuration functions
30  * \ingroup IfxLld_Scu_Std
31  * \defgroup IfxLld_Scu_Std_Wdt_Endinit Watchdog Endinit functions
32  * \ingroup IfxLld_Scu_Std
33  * \defgroup IfxLld_Scu_Std_Wdt_Operative Watchdog Operative functions
34  * \ingroup IfxLld_Scu_Std
35  * \defgroup IfxLld_Scu_Std_Wdt_Endinit_Usage How to use Endinit APIs?
36  * \ingroup IfxLld_Scu_Std
37  */
38 
39 #ifndef IFXSCUWDT_H
40 #define IFXSCUWDT_H 1
41 
42 /******************************************************************************/
43 /*----------------------------------Includes----------------------------------*/
44 /******************************************************************************/
45 
46 #include "_Impl/IfxScu_cfg.h"
47 #include "Cpu/Std/Ifx_Types.h"
48 #include "IfxScu_reg.h"
49 #include "IfxScuWdt.asm.h"
50 
51 /******************************************************************************/
52 /*-----------------------------Data Structures--------------------------------*/
53 /******************************************************************************/
54 
55 /** \brief Configuration structure for Scu Watchdog.
56  * IfxScuWdt_Config is a type describing configuration structure of CPU and
57  * Safety WDT registers defined in IfxScuWdt.h file.
58  */
59 typedef struct
60 {
61  uint16 password; /**< \brief password for access to WDTxCON0 reg */
62  uint16 reload; /**< \brief WDT reload value */
63  IfxScu_WDTCON1_IR inputFrequency; /**< \brief input frequency of the WDT */
64  boolean disableWatchdog; /**< \brief Disable Request Control Bit */
65  boolean enableSmuRestriction; /**< \brief Unlock Restriction Request Control Bit */
66  boolean enableAutomaticPasswordChange; /**< \brief Password Auto-sequence Request Bit */
67  boolean enableTimerCheck; /**< \brief Counter Check Request Bit */
68  boolean enableTimerCheckTolerance; /**< \brief Timer Check Tolerance Request */
69  boolean clrInternalResetFlag; /**< \brief Clear Internal Reset Flag */
71 
72 /** \addtogroup IfxLld_Scu_Std_Wdt_Configuration
73  * \{ */
74 
75 /******************************************************************************/
76 /*-------------------------Global Function Prototypes-------------------------*/
77 /******************************************************************************/
78 
79 /** \brief SCUWDT API to initialize WDT configuration structure - Constructor
80  * This API initialize the ScuWdt configuration structure to default values, these default
81  * values are for software specific, not necessarily hardware reset values.
82  * User must use this API call before IfxScuWdt_Init API call
83  * \param config ScuWdt configuration structure to be initialized
84  * \return None
85  */
87 
88 /** \brief SCUWDT API to initialize an instance of WDT Driver which corresponds to CPU WDT Hardware module.
89  *
90  * This API initialize the ScuWdt software driver and corresponding CPU WDT hardware module.
91  * User can configure project specific Watchdog password, Watchdog timer period and other settings
92  * with this interface.
93  * API corresponds to one instance of the hardware module.
94  * User must use this API call for each instance of the WDT hardware module used.
95  * \param wdt reference to register map of CPU WDT hardware instance
96  * \param config ScuWdt configuration structure
97  * \return None
98  */
99 IFX_EXTERN void IfxScuWdt_initCpuWatchdog(Ifx_SCU_WDTCPU *wdt, IfxScuWdt_Config *config);
100 
101 /** \brief SCUWDT API to initialize an instance of WDT Driver which corresponds to Safety WDT Hardware module.
102  *
103  * This API initialize the ScuWdt software driver and corresponding safety WDT hardware module.
104  * User can configure project specific Watchdog password, Watchdog timer period and other settings
105  * with this interface.
106  * API corresponds to one instance of the hardware module.
107  * User must use this API call for each instance of the WDT hardware module used.
108  * \param wdt reference to register map of Safety WDT hardware instance
109  * \param config ScuWdt configuration structure
110  * \return None
111  */
112 IFX_EXTERN void IfxScuWdt_initSafetyWatchdog(Ifx_SCU_WDTS *wdt, IfxScuWdt_Config *config);
113 
114 /** \} */
115 
116 /** \addtogroup IfxLld_Scu_Std_Wdt_Endinit
117  * \{ */
118 
119 /******************************************************************************/
120 /*-------------------------Inline Function Prototypes-------------------------*/
121 /******************************************************************************/
122 
123 /** \brief SCUWDT Inline API to Clear ENDINIT bit provided by CPU WDT Hardware module.
124  *
125  * This Inline API will disable ENDINIT functionality provided by CPU WDT Hardware module.
126  * This API is only meant to be used with startup routines where function call is not possible.
127  * User need to use this API call before modifying any ENDINIT protected register. User must
128  * always set the ENDINIT bit using other API IfxScuWdt_setCpuEndinit. The sequence clear and set
129  * ENDINIT shall not be interrupted by another interrupt/call.
130  * User need to have the password stored locally in the caller function, (use IfxScuWdt_getCpuWatchdogPassword).
131  * \param watchdog pointer to the watchdog register map of CPU WDT hardware instance
132  * \param password Existing (Application specific) password for the Watchdog module.
133  * \return None
134  */
135 IFX_INLINE void IfxScuWdt_clearCpuEndinitInline(Ifx_SCU_WDTCPU *watchdog, uint16 password);
136 
137 /** \brief SCUWDT Inline API to Set ENDINIT bit provided by CPU WDT Hardware module.
138  *
139  * This API will enable ENDINIT functionality provided by CPU WDT Hardware module.
140  * This API is only meant to be used with startup routines where function call is not possible.
141  * User need to use this API call after modifying any ENDINIT protected register.
142  * User need to have the password stored locally in the caller function, (use IfxScuWdt_getCpuWatchdogPassword).
143  * \param watchdog pointer to the watchdog register map of CPU WDT hardware instance
144  * \param password Existing (Application specific) password for the Watchdog module.
145  * \return None
146  */
147 IFX_INLINE void IfxScuWdt_setCpuEndinitInline(Ifx_SCU_WDTCPU *watchdog, uint16 password);
148 
149 /** \brief SCUWDT Inline API to Clear ENDINIT bit provided by Safety WDT Hardware module.
150  *
151  * This API will disable ENDINIT functionality provided by Safety WDT Hardware module.
152  * This API is only meant to be used with startup routines where function call is not possible.
153  * User need to use this API call before modifying any ENDINIT protected register. User must
154  * always set the ENDINIT bit using other API IfxScuWdt_setCpuEndinit. The sequence clear and set
155  * ENDINIT shall not be interrupted by another interrupt/call.
156  * User need to have the password stored locally in the caller function, (use IfxScuWdt_getSafetyWatchdogPassword).
157  * \param password Existing (Application specific) password for the Watchdog module.
158  * \return None
159  */
161 
162 /** \brief SCUWDT Inline API to Set ENDINIT bit provided by Safety WDT Hardware module.
163  *
164  * This API will enable ENDINIT functionality provided by Safety WDT Hardware module.
165  * This API is only meant to be used with startup routines where function call is not possible.
166  * User need to use this API call after modifying any ENDINIT protected register.
167  * User need to have the password stored locally in the caller function, (use IfxScuWdt_getSafetyWatchdogPassword).
168  * \param password Existing (Application specific) password for the Watchdog module.
169  * \return None
170  */
172 
173 /******************************************************************************/
174 /*-------------------------Global Function Prototypes-------------------------*/
175 /******************************************************************************/
176 
177 /** \brief SCUWDT API to Clear ENDINIT bit provided by CPU WDT Hardware module.
178  *
179  * This API will disable ENDINIT functionality provided by CPU WDT Hardware module.
180  * User need to use this API call before modifying any ENDINIT protected register. User must
181  * always set the ENDINIT bit using other API IfxScuWdt_setCpuEndinit. The sequence clear and set
182  * ENDINIT shall not be interrupted by another interrupt/call.
183  * User need to have the password stored locally in the caller function, (use IfxScuWdt_getCpuWatchdogPassword)
184  * \param password Existing (Application specific) password for the Watchdog module.
185  * \return None
186  */
188 
189 /** \brief SCUWDT API to set ENDINIT bit provided by CPU WDT Hardware module.
190  *
191  * This API will enable ENDINIT functionality provided by CPU WDT Hardware module.
192  * User need to use this API call after modifying any ENDINIT protected register.
193  * User need to have the password stored locally in the caller function, (use IfxScuWdt_getCpuWatchdogPassword)
194  * \param password Existing (Application specific) password for the Watchdog module.
195  * \return None
196  */
198 
199 /** \brief SCUWDT API to Clear ENDINIT bit provided by Safety WDT Hardware module.
200  *
201  * This API will disable ENDINIT functionality provided by Safety WDT Hardware module.
202  * User need to use this API call before modifying any ENDINIT protected register. User must
203  * always set the ENDINIT bit using other API IfxScuWdt_setCpuEndinit. The sequence clear and set
204  * ENDINIT shall not be interrupted by another interrupt/call.
205  * User need to have the password stored locally in the caller function, (use IfxScuWdt_getSafetyWatchdogPassword).
206  * \param password Existing (Application specific) password for the Watchdog module.
207  * \return None
208  */
210 
211 /** \brief SCUWDT API to Set ENDINIT bit provided by Safety WDT Hardware module.
212  *
213  * This API will enable ENDINIT functionality provided by Safety WDT Hardware module.
214  * User need to use this API call after modifying any ENDINIT protected register.
215  * User need to have the password stored locally in the caller function, (use IfxScuWdt_getSafetyWatchdogPassword).
216  * \param password Existing (Application specific) password for the Watchdog module.
217  * \return None
218  */
220 
221 /** \} */
222 
223 /** \addtogroup IfxLld_Scu_Std_Wdt_Operative
224  * \{ */
225 
226 /******************************************************************************/
227 /*-------------------------Inline Function Prototypes-------------------------*/
228 /******************************************************************************/
229 
230 /** \brief SCUWDT Inline API to fetch current password of CPU Watchdog module.
231  *
232  * This API will fetch current Watchdog password for CPU WDT Hardware module. password is needed to be passed
233  * with most of the WDT APIs. Normally this API can be used to store the password locally in the caller function
234  * or store the password globally in a global variable at the application memory.
235  * This API is only meant to be used with startup routines where function call is not possible.
236  * \param watchdog pointer to the watchdog register map of CPU WDT hardware instance
237  * \return password Existing (Application specific) password for the Watchdog module.
238  */
240 
241 /** \brief SCUWDT Inline API to fetch current password of Safety Watchdog module.
242  *
243  * This API will fetch current Watchdog password for Safety WDT Hardware module. password is needed to be passed
244  * with most of the WDT APIs. Normally this API can be used to store the password locally in the caller function
245  * or store the password globally in a global variable at the application memory.
246  * This API is only meant to be used with startup routines where function call is not possible.
247  * \return password Existing (Application specific) password for the Watchdog module.
248  */
250 
251 /******************************************************************************/
252 /*-------------------------Global Function Prototypes-------------------------*/
253 /******************************************************************************/
254 
255 /** \brief SCUWDT API to service CPU Watchdog functionality.
256  *
257  * This API will service Watchdog functionality corresponding to CPU WDT Hardware module.
258  * User need to use this API call periodically. This API results in reloading of the Watchdog Timer.
259  * User need to have the password stored locally in the caller function, (use IfxScuWdt_getCpuWatchdogPassword).
260  * \param password Existing (Application specific) password for the Watchdog module.
261  * \return None
262  */
264 
265 /** \brief SCUWDT API to change CPU Watchdog password.
266  *
267  * This API will change password to new one for the corresponding to CPU WDT Hardware module.
268  * User need to have the old password stored locally in the caller function, (use IfxScuWdt_getCpuWatchdogPassword).
269  * \param password Existing (Application specific) password for the Watchdog module.
270  * \param newPassword Application specific new password to be changed for the Watchdog module.
271  * \return None
272  */
273 IFX_EXTERN void IfxScuWdt_changeCpuWatchdogPassword(uint16 password, uint16 newPassword);
274 
275 /** \brief SCUWDT API to enable CPU Watchdog functionality.
276  *
277  * This API will enable Watchdog functionality of CPU WDT Hardware module. The Watchdog timers need to be serviced
278  * periodically after this API call.
279  * User need to have the password stored locally in the caller function, (use IfxScuWdt_getCpuWatchdogPassword).
280  * \param password Existing (Application specific) password for the Watchdog module.
281  * \return None
282  */
284 
285 /** \brief SCUWDT API to disable CPU Watchdog functionality.
286  *
287  * This API will disable Watchdog functionality of CPU WDT Hardware module. The Watchdog timers will stop counting
288  * after this API call.
289  * User need to have the password stored locally in the caller function, (use IfxScuWdt_getCpuWatchdogPassword).
290  * \param password Existing (Application specific) password for the Watchdog module.
291  * \return None
292  */
294 
295 /** \brief SCUWDT API to change CPU Watchdog timer reload value.
296  *
297  * This API will change Watchdog timer reload value to new one for CPU WDT Hardware module.
298  * The Watchdog timers will be reloaded with this value after every serice of Watchdog.
299  * User need to have the password stored locally in the caller function, (use IfxScuWdt_getCpuWatchdogPassword).
300  * \param password Existing (Application specific) password for the Watchdog module.
301  * \param reload Reload value for the timer.
302  * \return None
303  */
305 
306 /** \brief SCUWDT API to fetch current password of CPU Watchdog module.
307  *
308  * This API will fetch current Watchdog password for CPU WDT Hardware module. password is needed to be passed
309  * with most of the WDT APIs. Normally this API can be used to store the password locally in the caller function
310  * or store the password globally in a global variable at the application memory.
311  * \return password Existing (Application specific) password for the Watchdog module.
312  */
314 
315 /** \brief SCUWDT API to service Safety Watchdog functionality.
316  *
317  * This API will service Watchdog functionality corresponding to Safety WDT Hardware module.
318  * User need to use this API call periodically. This API results in reloading of the Watchdog Timer.
319  * User need to have the password stored locally in the caller function, (use IfxScuWdt_getSafetyWatchdogPassword).
320  * \param password Existing (Application specific) password for the Watchdog module.
321  * \return None
322  */
324 
325 /** \brief SCUWDT API to change Safety Watchdog password.
326  *
327  * This API will change password to new one for the corresponding to Safety WDT Hardware module.
328  * User need to have the old password stored locally in the caller function, (use IfxScuWdt_getSafetyWatchdogPassword).
329  * \param password Existing (Application specific) password for the Watchdog module.
330  * \param newPassword Application specific new password to be changed for the Watchdog module.
331  * \return None
332  */
334 
335 /** \brief SCUWDT API to enable Safety Watchdog functionality.
336  *
337  * This API will enable Watchdog functionality of Safety WDT Hardware module. The Watchdog timers need to be serviced
338  * periodically after this API call.
339  * User need to have the password stored locally in the caller function, (use IfxScuWdt_getSafetyWatchdogPassword).
340  * \param password Existing (Application specific) password for the Watchdog module.
341  * \return None
342  */
344 
345 /** \brief SCUWDT API to disable Safety Watchdog functionality.
346  *
347  * This API will disable Watchdog functionality of Safety WDT Hardware module. The Watchdog timers will stop counting
348  * after this API call.
349  * User need to have the password stored locally in the caller function, (use IfxScuWdt_getSafetyWatchdogPassword).
350  * \param password Existing (Application specific) password for the Watchdog module.
351  * \return None
352  */
354 
355 /** \brief SCUWDT API to change Safety Watchdog timer reload value.
356  *
357  * This API will change Watchdog timer reload value to new one for Safety WDT Hardware module.
358  * The Watchdog timers will be reloaded with this value after every serice of Watchdog.
359  * User need to have the password stored locally in the caller function, (use IfxScuWdt_getSafetyWatchdogPassword).
360  * \param password Existing (Application specific) password for the Watchdog module.
361  * \param reload Reload value for the timer.
362  * \return None
363  */
365 
366 /** \brief SCUWDT API to fetch current password of Safety Watchdog module.
367  *
368  * This API will fetch current Watchdog password for Safety WDT Hardware module. password is needed to be passed
369  * with most of the WDT APIs. Normally this API can be used to store the password locally in the caller function
370  * or store the password globally in a global variable at the application memory.
371  * \return password Existing (Application specific) password for the Watchdog module.
372  */
374 
375 /** \} */
376 
377 /******************************************************************************/
378 /*---------------------Inline Function Implementations------------------------*/
379 /******************************************************************************/
380 
381 IFX_INLINE void IfxScuWdt_clearCpuEndinitInline(Ifx_SCU_WDTCPU *watchdog, uint16 password)
382 {
383  /* Read Config_0 register */
384  Ifx_SCU_WDTCPU_CON0 wdt_con0;
385  wdt_con0.U = watchdog->CON0.U;
386 
387  if (wdt_con0.B.LCK)
388  {
389  /* see Table 1 (Pass.word Access Bit Pattern Requirements) */
390  wdt_con0.B.ENDINIT = 1;
391  wdt_con0.B.LCK = 0;
392  wdt_con0.B.PW = password;
393 
394  /* Password ready. Store it to WDT_CON0 to unprotect the register */
395  watchdog->CON0.U = wdt_con0.U;
396  }
397 
398  /* Clear ENDINT and set LCK bit in Config_0 register */
399  wdt_con0.B.ENDINIT = 0;
400  wdt_con0.B.LCK = 1;
401  watchdog->CON0.U = wdt_con0.U;
402 
403  /* read back ENDINIT and wait until it has been cleared */
404  while (watchdog->CON0.B.ENDINIT == 1)
405  {}
406 }
407 
408 
409 IFX_INLINE void IfxScuWdt_setCpuEndinitInline(Ifx_SCU_WDTCPU *watchdog, uint16 password)
410 {
411  /* Read Config_0 register */
412  Ifx_SCU_WDTCPU_CON0 wdt_con0;
413  wdt_con0.U = watchdog->CON0.U;
414 
415  if (wdt_con0.B.LCK)
416  {
417  /* see Table 1 (Password Access Bit Pattern Requirements) */
418  wdt_con0.B.ENDINIT = 1;
419  wdt_con0.B.LCK = 0;
420  wdt_con0.B.PW = password;
421 
422  /* Password ready. Store it to WDT_CON0 to unprotect the register */
423  watchdog->CON0.U = wdt_con0.U;
424  }
425 
426  /* Set ENDINT and set LCK bit in Config_0 register */
427  wdt_con0.B.ENDINIT = 1;
428  wdt_con0.B.LCK = 1;
429  watchdog->CON0.U = wdt_con0.U;
430 
431  /* read back ENDINIT and wait until it has been set */
432  while (watchdog->CON0.B.ENDINIT == 0)
433  {}
434 
435  // FIXME: old version: removed this line after check: watchdog->CON0.U; /* read is required */
436 }
437 
438 
440 {
441  Ifx_SCU_WDTS *watchdog = &MODULE_SCU.WDTS;
442  /* Read Config_0 register */
443  Ifx_SCU_WDTS_CON0 wdt_con0;
444  wdt_con0.U = watchdog->CON0.U;
445 
446  if (wdt_con0.B.LCK)
447  {
448  /* see Table 1 (Password Access Bit Pattern Requirements) */
449  wdt_con0.B.ENDINIT = 1;
450  wdt_con0.B.LCK = 0;
451  wdt_con0.B.PW = password;
452 
453  /* Password ready. Store it to WDT_CON0 to unprotect the register */
454  watchdog->CON0.U = wdt_con0.U;
455  }
456 
457  /* Clear ENDINT and set LCK bit in Config_0 register */
458  wdt_con0.B.ENDINIT = 0;
459  wdt_con0.B.LCK = 1;
460  watchdog->CON0.U = wdt_con0.U;
461 
462  /* read back ENDINIT and wait until it has been cleared */
463  while (watchdog->CON0.B.ENDINIT == 1)
464  {}
465 }
466 
467 
469 {
470  Ifx_SCU_WDTS *watchdog = &MODULE_SCU.WDTS;
471 
472  /* Read Config_0 register */
473  Ifx_SCU_WDTS_CON0 wdt_con0;
474  wdt_con0.U = watchdog->CON0.U;
475 
476  if (wdt_con0.B.LCK)
477  {
478  /* see Table 1 (Password Access Bit Pattern Requirements) */
479  wdt_con0.B.ENDINIT = 1;
480  wdt_con0.B.LCK = 0;
481  wdt_con0.B.PW = password;
482 
483  /* Password ready. Store it to WDT_CON0 to unprotect the register */
484  watchdog->CON0.U = wdt_con0.U;
485  }
486 
487  /* Set ENDINT and set LCK bit in Config_0 register */
488  wdt_con0.B.ENDINIT = 1;
489  wdt_con0.B.LCK = 1;
490  watchdog->CON0.U = wdt_con0.U;
491 
492  /* read back ENDINIT and wait until it has been set */
493  while (watchdog->CON0.B.ENDINIT == 0)
494  {}
495 }
496 
497 
499 {
500  uint16 password;
501 
502  /* Read Password from CON0 register
503  * !!! NOTE: !!! when read bottom six bit of password are inverted so we have
504  * to toggle them before returning password */
505  password = watchdog->CON0.B.PW;
506  password ^= 0x003F;
507 
508  return password;
509 }
510 
511 
513 {
514  uint16 password;
515  Ifx_SCU_WDTS *watchdog = &MODULE_SCU.WDTS;
516 
517  /* Read Password from Safety WDT CON0 register
518  * !!! NOTE: !!! when read bottom six bit of password are inverted so we have
519  * to toggle them before returning password */
520  password = watchdog->CON0.B.PW;
521  password ^= 0x003F;
522 
523  return password;
524 }
525 
526 
527 #endif /* IFXSCUWDT_H */