iLLD_TC27xD  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_1_0_0_11_0
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_Wdt Wdt Basic Functionality
28  * \ingroup IfxLld_Scu_Std
29  * \defgroup IfxLld_Scu_Std_Wdt_Wdt_Configuration Watchdog Configuration functions
30  * \ingroup IfxLld_Scu_Std_Wdt
31  * \defgroup IfxLld_Scu_Std_Wdt_Wdt_Endinit Watchdog Endinit functions
32  * \ingroup IfxLld_Scu_Std_Wdt
33  * \defgroup IfxLld_Scu_Std_Wdt_Wdt_Operative Watchdog Operative functions
34  * \ingroup IfxLld_Scu_Std_Wdt
35  * \defgroup IfxLld_Scu_Std_Wdt_Wdt_Endinit_Usage How to use Endinit APIs?
36  * \ingroup IfxLld_Scu_Std_Wdt
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_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, const 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, const IfxScuWdt_Config *config);
113 
114 /** \} */
115 
116 /** \addtogroup IfxLld_Scu_Std_Wdt_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 Clear ENDINIT bit provided by Safety WDT Hardware module.
138  *
139  * This API will disable ENDINIT functionality provided by Safety 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 before modifying any ENDINIT protected register. User must
142  * always set the ENDINIT bit using other API IfxScuWdt_setCpuEndinit. The sequence clear and set
143  * ENDINIT shall not be interrupted by another interrupt/call.
144  * User need to have the password stored locally in the caller function, (use IfxScuWdt_getSafetyWatchdogPassword).
145  * \param password Existing (Application specific) password for the Watchdog module.
146  * \return None
147  */
149 
150 /** \brief SCUWDT Inline API to Set ENDINIT bit provided by CPU WDT Hardware module.
151  *
152  * This API will enable ENDINIT functionality provided by CPU WDT Hardware module.
153  * This API is only meant to be used with startup routines where function call is not possible.
154  * User need to use this API call after modifying any ENDINIT protected register.
155  * User need to have the password stored locally in the caller function, (use IfxScuWdt_getCpuWatchdogPassword).
156  * \param watchdog pointer to the watchdog register map of CPU WDT hardware instance
157  * \param password Existing (Application specific) password for the Watchdog module.
158  * \return None
159  */
160 IFX_INLINE void IfxScuWdt_setCpuEndinitInline(Ifx_SCU_WDTCPU *watchdog, uint16 password);
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 Clear ENDINIT bit provided by Safety WDT Hardware module.
190  *
191  * This API will disable ENDINIT functionality provided by Safety WDT Hardware module.
192  * User need to use this API call before modifying any ENDINIT protected register. User must
193  * always set the ENDINIT bit using other API IfxScuWdt_setCpuEndinit. The sequence clear and set
194  * ENDINIT shall not be interrupted by another interrupt/call.
195  * User need to have the password stored locally in the caller function, (use IfxScuWdt_getSafetyWatchdogPassword).
196  * \param password Existing (Application specific) password for the Watchdog module.
197  * \return None
198  */
200 
201 /** \brief SCUWDT API to set ENDINIT bit provided by CPU WDT Hardware module.
202  *
203  * This API will enable ENDINIT functionality provided by CPU WDT Hardware module.
204  * User need to use this API call after modifying any ENDINIT protected register.
205  * User need to have the password stored locally in the caller function, (use IfxScuWdt_getCpuWatchdogPassword)
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_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 API to fetch current endinit of Safety/System Watchdog module.
242  * \return Endinit status for the Safety Watchdog module.
243  */
245 
246 /** \brief SCUWDT Inline API to fetch current password of Safety Watchdog module.
247  *
248  * This API will fetch current Watchdog password for Safety WDT Hardware module. password is needed to be passed
249  * with most of the WDT APIs. Normally this API can be used to store the password locally in the caller function
250  * or store the password globally in a global variable at the application memory.
251  * This API is only meant to be used with startup routines where function call is not possible.
252  * \return password Existing (Application specific) password for the Watchdog module.
253  */
255 
256 /******************************************************************************/
257 /*-------------------------Global Function Prototypes-------------------------*/
258 /******************************************************************************/
259 
260 /** \brief SCUWDT API to change CPU Watchdog password.
261  *
262  * This API will change password to new one for the corresponding to CPU WDT Hardware module.
263  * User need to have the old password stored locally in the caller function, (use IfxScuWdt_getCpuWatchdogPassword).
264  * \param password Existing (Application specific) password for the Watchdog module.
265  * \param newPassword Application specific new password to be changed for the Watchdog module.
266  * \return None
267  */
268 IFX_EXTERN void IfxScuWdt_changeCpuWatchdogPassword(uint16 password, uint16 newPassword);
269 
270 /** \brief SCUWDT API to change CPU Watchdog timer reload value.
271  *
272  * This API will change Watchdog timer reload value to new one for CPU WDT Hardware module.
273  * The Watchdog timers will be reloaded with this value after every serice of Watchdog.
274  * User need to have the password stored locally in the caller function, (use IfxScuWdt_getCpuWatchdogPassword).
275  * \param password Existing (Application specific) password for the Watchdog module.
276  * \param reload Reload value for the timer.
277  * \return None
278  */
280 
281 /** \brief SCUWDT API to change Safety Watchdog password.
282  *
283  * This API will change password to new one for the corresponding to Safety WDT Hardware module.
284  * User need to have the old password stored locally in the caller function, (use IfxScuWdt_getSafetyWatchdogPassword).
285  * \param password Existing (Application specific) password for the Watchdog module.
286  * \param newPassword Application specific new password to be changed for the Watchdog module.
287  * \return None
288  */
290 
291 /** \brief SCUWDT API to change Safety Watchdog timer reload value.
292  *
293  * This API will change Watchdog timer reload value to new one for Safety WDT Hardware module.
294  * The Watchdog timers will be reloaded with this value after every serice of Watchdog.
295  * User need to have the password stored locally in the caller function, (use IfxScuWdt_getSafetyWatchdogPassword).
296  * \param password Existing (Application specific) password for the Watchdog module.
297  * \param reload Reload value for the timer.
298  * \return None
299  */
301 
302 /** \brief SCUWDT API to disable CPU Watchdog functionality.
303  *
304  * This API will disable Watchdog functionality of CPU WDT Hardware module. The Watchdog timers will stop counting
305  * after this API call.
306  * User need to have the password stored locally in the caller function, (use IfxScuWdt_getCpuWatchdogPassword).
307  * \param password Existing (Application specific) password for the Watchdog module.
308  * \return None
309  */
311 
312 /** \brief SCUWDT API to disable Safety Watchdog functionality.
313  *
314  * This API will disable Watchdog functionality of Safety WDT Hardware module. The Watchdog timers will stop counting
315  * after this API call.
316  * User need to have the password stored locally in the caller function, (use IfxScuWdt_getSafetyWatchdogPassword).
317  * \param password Existing (Application specific) password for the Watchdog module.
318  * \return None
319  */
321 
322 /** \brief SCUWDT API to enable CPU Watchdog functionality.
323  *
324  * This API will enable Watchdog functionality of CPU WDT Hardware module. The Watchdog timers need to be serviced
325  * periodically after this API call.
326  * User need to have the password stored locally in the caller function, (use IfxScuWdt_getCpuWatchdogPassword).
327  * \param password Existing (Application specific) password for the Watchdog module.
328  * \return None
329  */
331 
332 /** \brief SCUWDT API to enable Safety Watchdog functionality.
333  *
334  * This API will enable Watchdog functionality of Safety WDT Hardware module. The Watchdog timers need to be serviced
335  * periodically after this API call.
336  * User need to have the password stored locally in the caller function, (use IfxScuWdt_getSafetyWatchdogPassword).
337  * \param password Existing (Application specific) password for the Watchdog module.
338  * \return None
339  */
341 
342 /** \brief SCUWDT API to fetch current password of CPU Watchdog module.
343  *
344  * This API will fetch current Watchdog password for CPU WDT Hardware module. password is needed to be passed
345  * with most of the WDT APIs. Normally this API can be used to store the password locally in the caller function
346  * or store the password globally in a global variable at the application memory.
347  * \return password Existing (Application specific) password for the Watchdog module.
348  */
350 
351 /** \brief SCUWDT API to fetch current password of Safety Watchdog module.
352  *
353  * This API will fetch current Watchdog password for Safety WDT Hardware module. password is needed to be passed
354  * with most of the WDT APIs. Normally this API can be used to store the password locally in the caller function
355  * or store the password globally in a global variable at the application memory.
356  * \return password Existing (Application specific) password for the Watchdog module.
357  */
359 
360 /** \brief SCUWDT API to service CPU Watchdog functionality.
361  *
362  * This API will service Watchdog functionality corresponding to CPU WDT Hardware module.
363  * User need to use this API call periodically. This API results in reloading of the Watchdog Timer.
364  * User need to have the password stored locally in the caller function, (use IfxScuWdt_getCpuWatchdogPassword).
365  * \param password Existing (Application specific) password for the Watchdog module.
366  * \return None
367  */
369 
370 /** \brief SCUWDT API to service Safety Watchdog functionality.
371  *
372  * This API will service Watchdog functionality corresponding to Safety WDT Hardware module.
373  * User need to use this API call periodically. This API results in reloading of the Watchdog Timer.
374  * User need to have the password stored locally in the caller function, (use IfxScuWdt_getSafetyWatchdogPassword).
375  * \param password Existing (Application specific) password for the Watchdog module.
376  * \return None
377  */
379 
380 /** \} */
381 
382 /******************************************************************************/
383 /*---------------------Inline Function Implementations------------------------*/
384 /******************************************************************************/
385 
386 IFX_INLINE void IfxScuWdt_clearCpuEndinitInline(Ifx_SCU_WDTCPU *watchdog, uint16 password)
387 {
388  /* Read Config_0 register */
389  Ifx_SCU_WDTCPU_CON0 wdt_con0;
390  wdt_con0.U = watchdog->CON0.U;
391 
392  if (wdt_con0.B.LCK)
393  {
394  /* see Table 1 (Pass.word Access Bit Pattern Requirements) */
395  wdt_con0.B.ENDINIT = 1;
396  wdt_con0.B.LCK = 0;
397  wdt_con0.B.PW = password;
398 
399  /* Password ready. Store it to WDT_CON0 to unprotect the register */
400  watchdog->CON0.U = wdt_con0.U;
401  }
402 
403  /* Clear ENDINT and set LCK bit in Config_0 register */
404  wdt_con0.B.ENDINIT = 0;
405  wdt_con0.B.LCK = 1;
406  watchdog->CON0.U = wdt_con0.U;
407 
408  /* read back ENDINIT and wait until it has been cleared */
409  while (watchdog->CON0.B.ENDINIT == 1)
410  {}
411 }
412 
413 
415 {
416  Ifx_SCU_WDTS *watchdog = &MODULE_SCU.WDTS;
417  /* Read Config_0 register */
418  Ifx_SCU_WDTS_CON0 wdt_con0;
419  wdt_con0.U = watchdog->CON0.U;
420 
421  if (wdt_con0.B.LCK)
422  {
423  /* see Table 1 (Password Access Bit Pattern Requirements) */
424  wdt_con0.B.ENDINIT = 1;
425  wdt_con0.B.LCK = 0;
426  wdt_con0.B.PW = password;
427 
428  /* Password ready. Store it to WDT_CON0 to unprotect the register */
429  watchdog->CON0.U = wdt_con0.U;
430  }
431 
432  /* Clear ENDINT and set LCK bit in Config_0 register */
433  wdt_con0.B.ENDINIT = 0;
434  wdt_con0.B.LCK = 1;
435  watchdog->CON0.U = wdt_con0.U;
436 
437  /* read back ENDINIT and wait until it has been cleared */
438  while (watchdog->CON0.B.ENDINIT == 1)
439  {}
440 }
441 
442 
444 {
445  uint16 password;
446 
447  /* Read Password from CON0 register
448  * !!! NOTE: !!! when read bottom six bit of password are inverted so we have
449  * to toggle them before returning password */
450  password = watchdog->CON0.B.PW;
451  password ^= 0x003F;
452 
453  return password;
454 }
455 
456 
458 {
459  return (boolean)MODULE_SCU.WDTS.CON0.B.ENDINIT;
460 }
461 
462 
464 {
465  uint16 password;
466  Ifx_SCU_WDTS *watchdog = &MODULE_SCU.WDTS;
467 
468  /* Read Password from Safety WDT CON0 register
469  * !!! NOTE: !!! when read bottom six bit of password are inverted so we have
470  * to toggle them before returning password */
471  password = watchdog->CON0.B.PW;
472  password ^= 0x003F;
473 
474  return password;
475 }
476 
477 
478 IFX_INLINE void IfxScuWdt_setCpuEndinitInline(Ifx_SCU_WDTCPU *watchdog, uint16 password)
479 {
480  /* Read Config_0 register */
481  Ifx_SCU_WDTCPU_CON0 wdt_con0;
482  wdt_con0.U = watchdog->CON0.U;
483 
484  if (wdt_con0.B.LCK)
485  {
486  /* see Table 1 (Password Access Bit Pattern Requirements) */
487  wdt_con0.B.ENDINIT = 1;
488  wdt_con0.B.LCK = 0;
489  wdt_con0.B.PW = password;
490 
491  /* Password ready. Store it to WDT_CON0 to unprotect the register */
492  watchdog->CON0.U = wdt_con0.U;
493  }
494 
495  /* Set ENDINT and set LCK bit in Config_0 register */
496  wdt_con0.B.ENDINIT = 1;
497  wdt_con0.B.LCK = 1;
498  watchdog->CON0.U = wdt_con0.U;
499 
500  /* read back ENDINIT and wait until it has been set */
501  while (watchdog->CON0.B.ENDINIT == 0)
502  {}
503 
504  // FIXME: old version: removed this line after check: watchdog->CON0.U; /* read is required */
505 }
506 
507 
509 {
510  Ifx_SCU_WDTS *watchdog = &MODULE_SCU.WDTS;
511 
512  /* Read Config_0 register */
513  Ifx_SCU_WDTS_CON0 wdt_con0;
514  wdt_con0.U = watchdog->CON0.U;
515 
516  if (wdt_con0.B.LCK)
517  {
518  /* see Table 1 (Password Access Bit Pattern Requirements) */
519  wdt_con0.B.ENDINIT = 1;
520  wdt_con0.B.LCK = 0;
521  wdt_con0.B.PW = password;
522 
523  /* Password ready. Store it to WDT_CON0 to unprotect the register */
524  watchdog->CON0.U = wdt_con0.U;
525  }
526 
527  /* Set ENDINT and set LCK bit in Config_0 register */
528  wdt_con0.B.ENDINIT = 1;
529  wdt_con0.B.LCK = 1;
530  watchdog->CON0.U = wdt_con0.U;
531 
532  /* read back ENDINIT and wait until it has been set */
533  while (watchdog->CON0.B.ENDINIT == 0)
534  {}
535 }
536 
537 
538 #endif /* IFXSCUWDT_H */