iLLD_TC27xD  1.0
IfxScuWdt.c
Go to the documentation of this file.
1 /**
2  * \file IfxScuWdt.c
3  * \brief SCU basic functionality
4  *
5  * \version iLLD_1_0_0_11_0
6  * \copyright Copyright (c) 2013 Infineon Technologies AG. All rights reserved.
7  *
8  *
9  * IMPORTANT NOTICE
10  *
11  *
12  * Infineon Technologies AG (Infineon) is supplying this file for use
13  * exclusively with Infineon's microcontroller products. This file can be freely
14  * distributed within development tools that are supporting such microcontroller
15  * products.
16  *
17  * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
18  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
19  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
20  * INFINEON SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
21  * OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
22  *
23  *
24  */
25 
26 /******************************************************************************/
27 /*----------------------------------Includes----------------------------------*/
28 /******************************************************************************/
29 
30 #include "IfxScuWdt.h"
31 #include "Cpu/Std/IfxCpu.h"
32 
33 /******************************************************************************/
34 /*----------------------------------Macros------------------------------------*/
35 /******************************************************************************/
36 
37 /** \brief Reset password of watchdog module.
38  */
39 #define IFXSCUWDT_RESET_PASSWORD (0x3CU)
40 
41 /******************************************************************************/
42 /*-------------------------Function Implementations---------------------------*/
43 /******************************************************************************/
44 
46 {
47  Ifx_SCU_WDTCPU *watchdog = &MODULE_SCU.WDTCPU[IfxCpu_getCoreIndex()];
48 
49  /* Read Config_0 register */
50  Ifx_SCU_WDTCPU_CON0 wdt_con0;
51  wdt_con0.U = watchdog->CON0.U;
52 
53  if (wdt_con0.B.LCK)
54  {
55  /* see Table 1 (Password Access Bit Pattern Requirements) */
56  wdt_con0.B.ENDINIT = 1;
57  wdt_con0.B.LCK = 0;
58  wdt_con0.B.PW = password;
59 
60  /* Password ready. Store it to WDT_CON0 to unprotect the register */
61  watchdog->CON0.U = wdt_con0.U;
62  }
63 
64  /* Set new Password, ENDINT and LCK bit in Config_0 register */
65  wdt_con0.B.ENDINIT = 1;
66  wdt_con0.B.LCK = 1;
67  wdt_con0.B.PW = newPassword;
68  watchdog->CON0.U = wdt_con0.U;
69 
70  /* read back ENDINIT and wait until it has been set */
71  while (watchdog->CON0.B.ENDINIT == 0)
72  {}
73 }
74 
75 
77 {
78  /* Select CPU Watchdog based on Core Id */
79  uint32 coreId = IfxCpu_getCoreIndex();
80  Ifx_SCU_WDTCPU *wdt = &MODULE_SCU.WDTCPU[coreId];
81 
82  /* Read Config_0 register */
83  Ifx_SCU_WDTCPU_CON0 wdt_con0;
84  wdt_con0.U = wdt->CON0.U;
85 
86  if (wdt_con0.B.LCK)
87  {
88  /* see Table 1 (Password Access Bit Pattern Requirements) */
89  wdt_con0.B.ENDINIT = 1;
90  wdt_con0.B.LCK = 0;
91  wdt_con0.B.PW = password;
92 
93  /* Password ready. Store it to WDT_CON0 to unprotect the register */
94  wdt->CON0.U = wdt_con0.U;
95  }
96 
97  /* Set new Reload value, set ENDINT and LCK bit in Config_0 register */
98  wdt_con0.B.ENDINIT = 1;
99  wdt_con0.B.LCK = 1;
100  wdt_con0.B.REL = reload;
101  wdt->CON0.U = wdt_con0.U;
102 
103  /* read back ENDINIT and wait until it has been set */
104  while (wdt->CON0.B.ENDINIT == 0)
105  {}
106 }
107 
108 
110 {
111  Ifx_SCU_WDTS *watchdog = &MODULE_SCU.WDTS;
112 
113  /* Read Config_0 register */
114  Ifx_SCU_WDTS_CON0 wdt_con0;
115  wdt_con0.U = watchdog->CON0.U;
116 
117  if (wdt_con0.B.LCK)
118  {
119  /* see Table 1 (Password Access Bit Pattern Requirements) */
120  wdt_con0.B.ENDINIT = 1;
121  wdt_con0.B.LCK = 0;
122  wdt_con0.B.PW = password;
123 
124  /* Password ready. Store it to WDT_CON0 to unprotect the register */
125  watchdog->CON0.U = wdt_con0.U;
126  }
127 
128  /* Set new Password, ENDINT and LCK bit in Config_0 register */
129  wdt_con0.B.ENDINIT = 1;
130  wdt_con0.B.LCK = 1;
131  wdt_con0.B.PW = newPassword;
132  watchdog->CON0.U = wdt_con0.U;
133 
134  /* read back ENDINIT and wait until it has been set */
135  while (watchdog->CON0.B.ENDINIT == 0)
136  {}
137 }
138 
139 
141 {
142  /* Initialize pointer to Safety Watchdog */
143  Ifx_SCU_WDTS *wdt = &MODULE_SCU.WDTS;
144 
145  /* Read Config_0 register */
146  Ifx_SCU_WDTS_CON0 wdt_con0;
147  wdt_con0.U = wdt->CON0.U;
148 
149  if (wdt_con0.B.LCK)
150  {
151  /* see Table 1 (Password Access Bit Pattern Requirements) */
152  wdt_con0.B.ENDINIT = 1;
153  wdt_con0.B.LCK = 0;
154  wdt_con0.B.PW = password;
155 
156  /* Password ready. Store it to WDT_CON0 to unprotect the register */
157  wdt->CON0.U = wdt_con0.U;
158  }
159 
160  /* Set new Reload value, set ENDINT and LCK bit in Config_0 register */
161  wdt_con0.B.ENDINIT = 1;
162  wdt_con0.B.LCK = 1;
163  wdt_con0.B.REL = reload;
164  wdt->CON0.U = wdt_con0.U;
165 
166  /* read back ENDINIT and wait until it has been set */
167  while (wdt->CON0.B.ENDINIT == 0)
168  {}
169 }
170 
171 
173 {
174  IfxScuWdt_clearCpuEndinitInline(&MODULE_SCU.WDTCPU[IfxCpu_getCoreIndex()], password);
175 }
176 
177 
179 {
181 }
182 
183 
185 {
186  /* Select CPU Watchdog based on Core Id */
187  uint32 coreId = IfxCpu_getCoreIndex();
188  Ifx_SCU_WDTCPU *wdt = &MODULE_SCU.WDTCPU[coreId];
189 
190  IfxScuWdt_clearCpuEndinit(password);
191  wdt->CON1.B.DR = 1; //Set DR bit in Config_1 register
192  IfxScuWdt_setCpuEndinit(password);
193 }
194 
195 
197 {
199  SCU_WDTS_CON1.B.DR = 1; //Set DR bit in Config_1 register
200  IfxScuWdt_setSafetyEndinit(password);
201 }
202 
203 
205 {
206  /* Select CPU Watchdog based on Core Id */
207  uint32 coreId = IfxCpu_getCoreIndex();
208  Ifx_SCU_WDTCPU *wdt = &MODULE_SCU.WDTCPU[coreId];
209 
210  IfxScuWdt_clearCpuEndinit(password);
211  wdt->CON1.B.DR = 0; //Clear DR bit in Config_1 register
212  IfxScuWdt_setCpuEndinit(password);
213 }
214 
215 
217 {
219  SCU_WDTS_CON1.B.DR = 0; //Clear DR bit in Config_1 register
220  IfxScuWdt_setSafetyEndinit(password);
221 }
222 
223 
225 {
226  return IfxScuWdt_getCpuWatchdogPasswordInline(&MODULE_SCU.WDTCPU[IfxCpu_getCoreIndex()]);
227 }
228 
229 
231 {
233 }
234 
235 
237 {
239  config->reload = 0xFFFC;
241  config->disableWatchdog = FALSE;
242  config->enableSmuRestriction = FALSE;
244  config->enableTimerCheck = FALSE;
246  config->clrInternalResetFlag = FALSE;
247 }
248 
249 
250 void IfxScuWdt_initCpuWatchdog(Ifx_SCU_WDTCPU *wdt, const IfxScuWdt_Config *config)
251 {
252  Ifx_SCU_WDTCPU_CON0 wdt_con0;
253  Ifx_SCU_WDTCPU_CON1 wdt_con1;
254 
255  /* Read Config_0 register and clear wdt_con1 variable */
256  wdt_con0.U = wdt->CON0.U;
257  wdt_con1.U = 0;
258 
259  if (wdt_con0.B.LCK)
260  {
261  /* see Table 1 (Password Access Bit Pattern Requirements) */
262  wdt_con0.B.ENDINIT = 1;
263  wdt_con0.B.LCK = 0;
264  wdt_con0.B.PW ^= 0x003F;
265 
266  /* Password ready. Store it to WDT_CON0 to unprotect the register */
267  wdt->CON0.U = wdt_con0.U;
268  }
269 
270  /* Initialize CON0 register, with modify access, with user defined parameters
271  * Clear ENDINT bit to unprotect CON1 register for initialization
272  * see Table 3 (Modify Access Bit Pattern Requirements) */
273  wdt_con0.B.ENDINIT = 0;
274  wdt_con0.B.LCK = 1;
275  wdt_con0.B.PW = config->password; //user defined password
276  wdt_con0.B.REL = config->reload; //user defined reload value
277 
278  /* Modify access ready - write WDT_CON0 register */
279  wdt->CON0.U = wdt_con0.U;
280 
281  /* read back ENDINIT and wait until it has been cleared */
282  while (wdt->CON0.B.ENDINIT == 1)
283  {}
284 
285  /* Initialize CON1 register */
286  switch (config->inputFrequency)
287  {
289  wdt_con1.B.IR0 = 0;
290  wdt_con1.B.IR1 = 0;
291  break;
293  wdt_con1.B.IR0 = 1;
294  wdt_con1.B.IR1 = 0;
295  break;
297  wdt_con1.B.IR0 = 0;
298  wdt_con1.B.IR1 = 1;
299  break;
300  }
301 
302  wdt_con1.B.DR = config->disableWatchdog ? 1 : 0;
303  wdt_con1.B.UR = config->enableSmuRestriction ? 1 : 0;
304  wdt_con1.B.PAR = config->enableAutomaticPasswordChange ? 1 : 0;
305  wdt_con1.B.TCR = config->enableTimerCheck ? 1 : 0;
306  wdt_con1.B.TCTR = config->enableTimerCheckTolerance ? 1 : 0;
307 
308  /* Finally write CON1 with user defined configuration */
309  wdt->CON1.U = wdt_con1.U;
310 
311  /* Initialization finished - set CPU ENDINIT protection */
313 }
314 
315 
316 void IfxScuWdt_initSafetyWatchdog(Ifx_SCU_WDTS *wdt, const IfxScuWdt_Config *config)
317 {
318  Ifx_SCU_WDTS_CON0 wdt_con0;
319  Ifx_SCU_WDTS_CON1 wdt_con1;
320 
321  /* Read Config_0 register and clear wdt_con1 variable */
322  wdt_con0.U = wdt->CON0.U;
323  wdt_con1.U = 0;
324 
325  if (wdt_con0.B.LCK)
326  {
327  /* see Table 1 (Password Access Bit Pattern Requirements) */
328  wdt_con0.B.ENDINIT = 1;
329  wdt_con0.B.LCK = 0;
330  wdt_con0.B.PW ^= 0x003F;
331 
332  /* Password ready. Store it to WDT_CON0 to unprotect the register */
333  wdt->CON0.U = wdt_con0.U;
334  }
335 
336  /* Initialize CON0 register, with modify access, with user defined parameters
337  * Clear ENDINT bit to unprotect CON1 register for initialization
338  * see Table 3 (Modify Access Bit Pattern Requirements) */
339  wdt_con0.B.ENDINIT = 0;
340  wdt_con0.B.LCK = 1;
341  wdt_con0.B.PW = config->password; //user defined password
342  wdt_con0.B.REL = config->reload; //user defined reload value
343 
344  /* Modify access ready - write WDT_CON0 register */
345  wdt->CON0.U = wdt_con0.U;
346 
347  /* read back ENDINIT and wait until it has been cleared */
348  while (wdt->CON0.B.ENDINIT == 1)
349  {}
350 
351  /* Initialize CON1 register */
352  switch (config->inputFrequency)
353  {
355  wdt_con1.B.IR0 = 0;
356  wdt_con1.B.IR1 = 0;
357  break;
359  wdt_con1.B.IR0 = 1;
360  wdt_con1.B.IR1 = 0;
361  break;
363  wdt_con1.B.IR0 = 0;
364  wdt_con1.B.IR1 = 1;
365  break;
366  }
367 
368  wdt_con1.B.DR = config->disableWatchdog ? 1 : 0;
369  wdt_con1.B.UR = config->enableSmuRestriction ? 1 : 0;
370  wdt_con1.B.PAR = config->enableAutomaticPasswordChange ? 1 : 0;
371  wdt_con1.B.TCR = config->enableTimerCheck ? 1 : 0;
372  wdt_con1.B.TCTR = config->enableTimerCheckTolerance ? 1 : 0;
373  wdt_con1.B.CLRIRF = config->clrInternalResetFlag ? 0 : 1;
374 
375  /* Finally write CON1 with user defined configuration */
376  wdt->CON1.U = wdt_con1.U;
377 
378  /* Initialization finished - set Safety ENDINIT protection */
380 }
381 
382 
384 {
385  IfxScuWdt_setCpuEndinit(password);
386 }
387 
388 
390 {
391  IfxScuWdt_setSafetyEndinit(password);
392 }
393 
394 
396 {
397  IfxScuWdt_setCpuEndinitInline(&MODULE_SCU.WDTCPU[IfxCpu_getCoreIndex()], password);
398 }
399 
400 
402 {
404 }