iLLD_TC27xC  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_0_1_0_10
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 {
48  config->reload = 0xFFFC;
50  config->disableWatchdog = FALSE;
51  config->enableSmuRestriction = FALSE;
53  config->enableTimerCheck = FALSE;
55  config->clrInternalResetFlag = FALSE;
56 }
57 
58 
59 void IfxScuWdt_initCpuWatchdog(Ifx_SCU_WDTCPU *wdt, IfxScuWdt_Config *config)
60 {
61  Ifx_SCU_WDTCPU_CON0 wdt_con0;
62  Ifx_SCU_WDTCPU_CON1 wdt_con1;
63 
64  /* Read Config_0 register and clear wdt_con1 variable */
65  wdt_con0.U = wdt->CON0.U;
66  wdt_con1.U = 0;
67 
68  if (wdt_con0.B.LCK)
69  {
70  /* see Table 1 (Password Access Bit Pattern Requirements) */
71  wdt_con0.B.ENDINIT = 1;
72  wdt_con0.B.LCK = 0;
73  wdt_con0.B.PW ^= 0x003F;
74 
75  /* Password ready. Store it to WDT_CON0 to unprotect the register */
76  wdt->CON0.U = wdt_con0.U;
77  }
78 
79  /* Initialize CON0 register, with modify access, with user defined parameters
80  * Clear ENDINT bit to unprotect CON1 register for initialization
81  * see Table 3 (Modify Access Bit Pattern Requirements) */
82  wdt_con0.B.ENDINIT = 0;
83  wdt_con0.B.LCK = 1;
84  wdt_con0.B.PW = config->password; //user defined password
85  wdt_con0.B.REL = config->reload; //user defined reload value
86 
87  /* Modify access ready - write WDT_CON0 register */
88  wdt->CON0.U = wdt_con0.U;
89 
90  /* read back ENDINIT and wait until it has been cleared */
91  while (wdt->CON0.B.ENDINIT == 1)
92  {}
93 
94  /* Initialize CON1 register */
95  switch (config->inputFrequency)
96  {
98  wdt_con1.B.IR0 = 0;
99  wdt_con1.B.IR1 = 0;
100  break;
102  wdt_con1.B.IR0 = 1;
103  wdt_con1.B.IR1 = 0;
104  break;
106  wdt_con1.B.IR0 = 0;
107  wdt_con1.B.IR1 = 1;
108  break;
109  }
110 
111  wdt_con1.B.DR = config->disableWatchdog ? 1 : 0;
112  wdt_con1.B.UR = config->enableSmuRestriction ? 1 : 0;
113  wdt_con1.B.PAR = config->enableAutomaticPasswordChange ? 1 : 0;
114  wdt_con1.B.TCR = config->enableTimerCheck ? 1 : 0;
115  wdt_con1.B.TCTR = config->enableTimerCheckTolerance ? 1 : 0;
116 
117  /* Finally write CON1 with user defined configuration */
118  wdt->CON1.U = wdt_con1.U;
119 
120  /* Initialization finished - set CPU ENDINIT protection */
122 }
123 
124 
125 void IfxScuWdt_initSafetyWatchdog(Ifx_SCU_WDTS *wdt, IfxScuWdt_Config *config)
126 {
127  Ifx_SCU_WDTS_CON0 wdt_con0;
128  Ifx_SCU_WDTS_CON1 wdt_con1;
129 
130  /* Read Config_0 register and clear wdt_con1 variable */
131  wdt_con0.U = wdt->CON0.U;
132  wdt_con1.U = 0;
133 
134  if (wdt_con0.B.LCK)
135  {
136  /* see Table 1 (Password Access Bit Pattern Requirements) */
137  wdt_con0.B.ENDINIT = 1;
138  wdt_con0.B.LCK = 0;
139  wdt_con0.B.PW ^= 0x003F;
140 
141  /* Password ready. Store it to WDT_CON0 to unprotect the register */
142  wdt->CON0.U = wdt_con0.U;
143  }
144 
145  /* Initialize CON0 register, with modify access, with user defined parameters
146  * Clear ENDINT bit to unprotect CON1 register for initialization
147  * see Table 3 (Modify Access Bit Pattern Requirements) */
148  wdt_con0.B.ENDINIT = 0;
149  wdt_con0.B.LCK = 1;
150  wdt_con0.B.PW = config->password; //user defined password
151  wdt_con0.B.REL = config->reload; //user defined reload value
152 
153  /* Modify access ready - write WDT_CON0 register */
154  wdt->CON0.U = wdt_con0.U;
155 
156  /* read back ENDINIT and wait until it has been cleared */
157  while (wdt->CON0.B.ENDINIT == 1)
158  {}
159 
160  /* Initialize CON1 register */
161  switch (config->inputFrequency)
162  {
164  wdt_con1.B.IR0 = 0;
165  wdt_con1.B.IR1 = 0;
166  break;
168  wdt_con1.B.IR0 = 1;
169  wdt_con1.B.IR1 = 0;
170  break;
172  wdt_con1.B.IR0 = 0;
173  wdt_con1.B.IR1 = 1;
174  break;
175  }
176 
177  wdt_con1.B.DR = config->disableWatchdog ? 1 : 0;
178  wdt_con1.B.UR = config->enableSmuRestriction ? 1 : 0;
179  wdt_con1.B.PAR = config->enableAutomaticPasswordChange ? 1 : 0;
180  wdt_con1.B.TCR = config->enableTimerCheck ? 1 : 0;
181  wdt_con1.B.TCTR = config->enableTimerCheckTolerance ? 1 : 0;
182  wdt_con1.B.CLRIRF = config->clrInternalResetFlag ? 0 : 1;
183 
184  /* Finally write CON1 with user defined configuration */
185  wdt->CON1.U = wdt_con1.U;
186 
187  /* Initialization finished - set Safety ENDINIT protection */
189 }
190 
191 
193 {
194  IfxScuWdt_clearCpuEndinitInline(&MODULE_SCU.WDTCPU[IfxCpu_getCoreId()], password);
195 }
196 
197 
199 {
200  IfxScuWdt_setCpuEndinitInline(&MODULE_SCU.WDTCPU[IfxCpu_getCoreId()], password);
201 }
202 
203 
205 {
206  IfxScuWdt_setCpuEndinit(password);
207 }
208 
209 
211 {
212  Ifx_SCU_WDTCPU *watchdog = &MODULE_SCU.WDTCPU[IfxCpu_getCoreId()];
213 
214  /* Read Config_0 register */
215  Ifx_SCU_WDTCPU_CON0 wdt_con0;
216  wdt_con0.U = watchdog->CON0.U;
217 
218  if (wdt_con0.B.LCK)
219  {
220  /* see Table 1 (Password Access Bit Pattern Requirements) */
221  wdt_con0.B.ENDINIT = 1;
222  wdt_con0.B.LCK = 0;
223  wdt_con0.B.PW = password;
224 
225  /* Password ready. Store it to WDT_CON0 to unprotect the register */
226  watchdog->CON0.U = wdt_con0.U;
227  }
228 
229  /* Set new Password, ENDINT and LCK bit in Config_0 register */
230  wdt_con0.B.ENDINIT = 1;
231  wdt_con0.B.LCK = 1;
232  wdt_con0.B.PW = newPassword;
233  watchdog->CON0.U = wdt_con0.U;
234 
235  /* read back ENDINIT and wait until it has been set */
236  while (watchdog->CON0.B.ENDINIT == 0)
237  {}
238 }
239 
240 
242 {
243  /* Select CPU Watchdog based on Core Id */
244  uint32 coreId = IfxCpu_getCoreId();
245  Ifx_SCU_WDTCPU *wdt = &MODULE_SCU.WDTCPU[coreId];
246 
247  IfxScuWdt_clearCpuEndinit(password);
248  wdt->CON1.B.DR = 0; //Clear DR bit in Config_1 register
249  IfxScuWdt_setCpuEndinit(password);
250 }
251 
252 
254 {
255  /* Select CPU Watchdog based on Core Id */
256  uint32 coreId = IfxCpu_getCoreId();
257  Ifx_SCU_WDTCPU *wdt = &MODULE_SCU.WDTCPU[coreId];
258 
259  IfxScuWdt_clearCpuEndinit(password);
260  wdt->CON1.B.DR = 1; //Set DR bit in Config_1 register
261  IfxScuWdt_setCpuEndinit(password);
262 }
263 
264 
266 {
267  /* Select CPU Watchdog based on Core Id */
268  uint32 coreId = IfxCpu_getCoreId();
269  Ifx_SCU_WDTCPU *wdt = &MODULE_SCU.WDTCPU[coreId];
270 
271  /* Read Config_0 register */
272  Ifx_SCU_WDTCPU_CON0 wdt_con0;
273  wdt_con0.U = wdt->CON0.U;
274 
275  if (wdt_con0.B.LCK)
276  {
277  /* see Table 1 (Password Access Bit Pattern Requirements) */
278  wdt_con0.B.ENDINIT = 1;
279  wdt_con0.B.LCK = 0;
280  wdt_con0.B.PW = password;
281 
282  /* Password ready. Store it to WDT_CON0 to unprotect the register */
283  wdt->CON0.U = wdt_con0.U;
284  }
285 
286  /* Set new Reload value, set ENDINT and LCK bit in Config_0 register */
287  wdt_con0.B.ENDINIT = 1;
288  wdt_con0.B.LCK = 1;
289  wdt_con0.B.REL = reload;
290  wdt->CON0.U = wdt_con0.U;
291 
292  /* read back ENDINIT and wait until it has been set */
293  while (wdt->CON0.B.ENDINIT == 0)
294  {}
295 }
296 
297 
299 {
300  return IfxScuWdt_getCpuWatchdogPasswordInline(&MODULE_SCU.WDTCPU[IfxCpu_getCoreId()]);
301 }
302 
303 
305 {
307 }
308 
309 
311 {
313 }
314 
315 
317 {
318  IfxScuWdt_setSafetyEndinit(password);
319 }
320 
321 
323 {
324  Ifx_SCU_WDTS *watchdog = &MODULE_SCU.WDTS;
325 
326  /* Read Config_0 register */
327  Ifx_SCU_WDTS_CON0 wdt_con0;
328  wdt_con0.U = watchdog->CON0.U;
329 
330  if (wdt_con0.B.LCK)
331  {
332  /* see Table 1 (Password Access Bit Pattern Requirements) */
333  wdt_con0.B.ENDINIT = 1;
334  wdt_con0.B.LCK = 0;
335  wdt_con0.B.PW = password;
336 
337  /* Password ready. Store it to WDT_CON0 to unprotect the register */
338  watchdog->CON0.U = wdt_con0.U;
339  }
340 
341  /* Set new Password, ENDINT and LCK bit in Config_0 register */
342  wdt_con0.B.ENDINIT = 1;
343  wdt_con0.B.LCK = 1;
344  wdt_con0.B.PW = newPassword;
345  watchdog->CON0.U = wdt_con0.U;
346 
347  /* read back ENDINIT and wait until it has been set */
348  while (watchdog->CON0.B.ENDINIT == 0)
349  {}
350 }
351 
352 
354 {
356  SCU_WDTS_CON1.B.DR = 0; //Clear DR bit in Config_1 register
357  IfxScuWdt_setSafetyEndinit(password);
358 }
359 
360 
362 {
364  SCU_WDTS_CON1.B.DR = 1; //Set DR bit in Config_1 register
365  IfxScuWdt_setSafetyEndinit(password);
366 }
367 
368 
370 {
371  /* Initialize pointer to Safety Watchdog */
372  Ifx_SCU_WDTS *wdt = &MODULE_SCU.WDTS;
373 
374  /* Read Config_0 register */
375  Ifx_SCU_WDTS_CON0 wdt_con0;
376  wdt_con0.U = wdt->CON0.U;
377 
378  if (wdt_con0.B.LCK)
379  {
380  /* see Table 1 (Password Access Bit Pattern Requirements) */
381  wdt_con0.B.ENDINIT = 1;
382  wdt_con0.B.LCK = 0;
383  wdt_con0.B.PW = password;
384 
385  /* Password ready. Store it to WDT_CON0 to unprotect the register */
386  wdt->CON0.U = wdt_con0.U;
387  }
388 
389  /* Set new Reload value, set ENDINT and LCK bit in Config_0 register */
390  wdt_con0.B.ENDINIT = 1;
391  wdt_con0.B.LCK = 1;
392  wdt_con0.B.REL = reload;
393  wdt->CON0.U = wdt_con0.U;
394 
395  /* read back ENDINIT and wait until it has been set */
396  while (wdt->CON0.B.ENDINIT == 0)
397  {}
398 }
399 
400 
402 {
404 }