TLE986x Device Family SDK
scu.h
Go to the documentation of this file.
1 /*
2  ***********************************************************************************************************************
3  *
4  * Copyright (c) 2015, Infineon Technologies AG
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without modification,are permitted provided that the
8  * following conditions are met:
9  *
10  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following
11  * disclaimer.
12  *
13  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
14  * following disclaimer in the documentation and/or other materials provided with the distribution.
15  *
16  * Neither the name of the copyright holders nor the names of its contributors may be used to endorse or promote
17  * products derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
25  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  **********************************************************************************************************************/
39 /*******************************************************************************
40 ** Author(s) Identity **
41 ********************************************************************************
42 ** Initials Name **
43 ** ---------------------------------------------------------------------------**
44 ** DM Daniel Mysliwitz **
45 ** TA Thomas Albersinger **
46 ** BG Blandine Guillot **
47 ** JO Julia Ott **
48 *******************************************************************************/
49 
50 /*******************************************************************************
51 ** Revision Control History **
52 ********************************************************************************
53 ** V0.1.0: 2013-02-10, DM: Initial version **
54 ** V0.1.1: 2013-02-21, DM: VCOSEL added to function SCU_SetSysClk() **
55 ** V0.1.2: 2013-03-06, DM: NVM Protection added **
56 ** V0.1.3: 2013-03-26, DM: EXINT3 removed **
57 ** V0.1.4: 2013-04-05, DM: APCLK1/2 (MI_CLK, FILT_CLK) register access **
58 ** corrected **
59 ** V0.1.5: 2013-11-06, DM: Change global interrupt disable/enable in power **
60 ** saving functions **
61 ** V0.2.0: 2014-04-26, TA: In SCU_init(), use #defines from the header file **
62 ** generated by the Config Wizard **
63 ** V0.2.1: 2014-05-18, DM: Fixed SCU_ChangeNVMProtection function **
64 ** V0.2.2: 2014-06-17, DM: Fixed EnterSleepMode, switched LIN Trx. into **
65 ** sleep mode as well **
66 ** V0.2.3: 2014-06-18, TA: Include bootrom.h for NVM protection control **
67 ** Include lin.h because of sleep functions **
68 ** V0.2.4: 2014-06-23, TA: Conditional include of lin.h **
69 ** V0.2.5: 2014-09-09, DM: OSC_CON, XTAL power down handled **
70 ** V0.2.6: 2014-10-20, DM: OSC_CON, OSC_PLL async. set before StopMode entry**
71 ** V0.2.7: 2015-02-10, DM: Individual header file added **
72 ** OSC_CON register defined by Config Wizard **
73 ** V0.2.8: 2015-11-18, DM: In function SCU_EnterStopMode() one __WFE removed**
74 ** V0.2.9: 2015-11-26, DM: Init of DMASRCSELx added **
75 ** V0.3.0: 2016-08-04, DM: Password open check removed for EnterSleepMode, **
76 ** EnterStopMode, EnterSlowMode **
77 ** V0.3.1: 2017-05-26, DM: Global variable SystemFrequency added **
78 ** V0.3.2: 2017-10-11, DM: MISRA 2012 compliance, the following PC-Lint **
79 ** rules are globally deactivated: **
80 ** - Info 793: ANSI/ISO limit of 6 'significant **
81 ** characters in an external identifier **
82 ** - Info 835: A zero has been given as right **
83 ** argument to operator **
84 ** - Info 845: The left argument to operator '&' **
85 ** is certain to be 0 **
86 ** The following rules are locally deactivated: **
87 ** - Warning 438: Last value assigned to variable **
88 ** 'dummy' (defined at line ...) not used **
89 ** - Info 838: Previously assigned value to **
90 ** variable 'dummy' has not been used **
91 ** Replaced register accesses within functions by **
92 ** function calls **
93 ** Replaced __STATIC_INLINE by INLINE **
94 ** V0.3.3: 2018-03-12, DM: SCU_ChangeNVMProtection() returns a bool result **
95 ** V0.3.4: 2018-07-06, BG: SCU_WDT_Start(),SCU_WDT_Stop(),SCU_WDT_Service(),**
96 ** SCU_OpenPASSWD(), SCU_ClosePASSWD() rewritten **
97 ** V0.3.5: 2018-10-05, JO: Parameter for prescaler to SCU_function **
98 ** EnterSlowMode and defines for the slow down mode **
99 ** prescaler added **
100 ** SCU_ClkInit(), SCU_Init, SCU_EnterSleepMode, **
101 ** SCU_EnterStopMode, SCU_EnterSlowMode, **
102 ** SCU_ExitSlowMode and SCU_ChangeNVMProtection **
103 ** rewritten **
104 ** V0.3.6: 2018-11-28, JO: Doxygen update, moved revision history from **
105 ** scu.c to scu.h **
106 ** Replaced register accesses by function calls in **
107 ** SCU_ClkInit **
108 ** Added #ifndef UNIT_TESTING_LV2 condition in **
109 ** SCU_EnterSleepMode for testability **
110 ** Reworked SCU_EnterSlowMode and added a parameter **
111 ** for the divider **
112 ** Reworked SCU_ExitSlowMode **
113 ** V0.3.7: 2019-06-05, JO: Enable SysTick after entering Slow Mode in **
114 ** function SCU_EnterSlowMode **
115 ** V0.3.8: 2020-02-28, BG: Updated revision history format **
116 ** V0.3.9: 2020-04-20, BG: Updated stop mode entry sequence to match the UM **
117 ** V0.4.0: 2020-10-12, JO: EP-506: remove ARMCC v6 Compiler warnings **
118 ** - Added '__attribute__((noreturn))' to **
119 ** definition of SCU_EnterSleepMode(void) **
120 ** - Disable warning -Wself-assign incfile scu.c **
121 ** V0.5.0: 2020-10-21, DM: EP-529: update PLL init. flow **
122 ** V0.5.1: 2020-10-27, DM: EP-558: replace Field_Mod() in the power saving **
123 ** function between the Open_/Close_Passwd **
124 ** V0.5.2: 2020-11-04, JO: EP-545: Moved function PLL_setClkSrcToIntOscAsync**
125 ** into contition #if (PMU_STOP_MODE == 1) **
126 *******************************************************************************/
127 
128 #ifndef SCU_H
129 #define SCU_H
130 
131 /*******************************************************************************
132 ** Includes **
133 *******************************************************************************/
134 #include "tle986x.h"
135 #include "types.h"
136 #include "sfr_access.h"
137 #include "scu_defines.h"
138 
139 
140 /*******************************************************************************
141 ** Global Macro Definitions **
142 *******************************************************************************/
144 #define PASSWD_Open (0x98U)
145 
146 #define PASSWD_Close (0xA8U)
147 
149 #define NVM_DATA_WRITE (0U)
150 
151 #define NVM_CODE_WRITE (1U)
152 
153 #define NVM_DATA_READ (2U)
154 
155 #define NVM_CODE_READ (3U)
156 
158 #define PROTECTION_CLEAR (1U)
159 
160 #define PROTECTION_SET (0U)
161 
162 /* Slow Down mode prescaler */
163 #define SLOWDOWN_PRESCALER_1 (0U)
164 #define SLOWDOWN_PRESCALER_2 (1U)
165 #define SLOWDOWN_PRESCALER_3 (2U)
166 #define SLOWDOWN_PRESCALER_4 (3U)
167 #define SLOWDOWN_PRESCALER_8 (4U)
168 #define SLOWDOWN_PRESCALER_16 (5U)
169 #define SLOWDOWN_PRESCALER_24 (6U)
170 #define SLOWDOWN_PRESCALER_32 (7U)
171 #define SLOWDOWN_PRESCALER_48 (8U)
172 #define SLOWDOWN_PRESCALER_64 (9U)
173 #define SLOWDOWN_PRESCALER_96 (10U)
174 #define SLOWDOWN_PRESCALER_128 (11U)
175 #define SLOWDOWN_PRESCALER_192 (12U)
176 #define SLOWDOWN_PRESCALER_256 (13U)
177 #define SLOWDOWN_PRESCALER_384 (14U)
178 #define SLOWDOWN_PRESCALER_512 (15U)
179 
180 
181 /*******************************************************************************
182 ** Global Type Definitions **
183 *******************************************************************************/
187 typedef enum
188 {
189  Mod_ADC1 = 0x00,
190  Mod_SSC1 = 0x01,
191  Mod_CCU6 = 0x02,
192  Mod_Timer2 = 0x03,
193  Mod_GPT12 = 0x04,
194  Mod_SSC2 = 0x11,
195  Mod_Timer21 = 0x13,
196  Mod_Timer3 = 0x15
197 } TScu_Mod;
198 
199 /*******************************************************************************
200 ** Global Variable Declarations **
201 *******************************************************************************/
202 
203 /*******************************************************************************
204 ** Global Function Declarations **
205 *******************************************************************************/
210 void SCU_ClkInit(void);
211 
216 void SCU_Init(void);
217 
239 void SCU_EnterSleepMode(void);
240 
270 void SCU_EnterStopMode(void);
271 
293 void SCU_EnterSlowMode(uint8 divider_scaled);
294 
307 void SCU_ExitSlowMode(void);
308 
330 bool SCU_ChangeNVMProtection(uint32 mode, uint32 action);
331 
332 
333 /*******************************************************************************
334 ** Global Inline Function Declarations **
335 *******************************************************************************/
336 INLINE void SCU_WDT_Start(void);
337 INLINE void SCU_WDT_Stop(void);
338 INLINE void SCU_WDT_Service(void);
339 INLINE void SCU_Disable_Module(TScu_Mod Module);
340 INLINE void SCU_Enable_Module(TScu_Mod Module);
341 INLINE void SCU_OpenPASSWD(void);
342 INLINE void SCU_ClosePASSWD(void);
343 
344 /*******************************************************************************
345 ** Global Inline Function Definitions **
346 *******************************************************************************/
361 INLINE void SCU_WDT_Start(void)
362 {
363  SCU_OpenPASSWD();
365  SCU_ClosePASSWD();
366 }
367 
381 INLINE void SCU_WDT_Stop(void)
382 {
383  SCU_OpenPASSWD();
385  SCU_ClosePASSWD();
386 }
387 
401 INLINE void SCU_WDT_Service(void)
402 {
404 }
405 
421 {
422  if (((uint8)Module & (uint8)0x10) == (uint8)0x10)
423  {
424  /* reset the corresponding bit (given by the lower nibble in the parameter Module)
425  * in register PMCON2 */
426  SCU->PMCON2.reg |= (uint8) (1u << ((uint8)Module & (uint8)0x07));
427  }
428  else
429  {
430  /* reset the corresponding bit (given by the lower nibble in the parameter Module)
431  * in register PMCON1 */
432  SCU->PMCON1.reg |= (uint8) (1u << ((uint8)Module & (uint8)0x07));
433  }
434 }
435 
450 INLINE void SCU_Enable_Module(TScu_Mod Module)
451 {
452  if (((uint8)Module & (uint8)0x10) == (uint8)0x10)
453  {
454  /* set the corresponding bit (given by the lower nibble in the parameter Module)
455  * in register PMCON2 */
456  SCU->PMCON2.reg &= (uint8) ~ (1u << ((uint8)Module & (uint8)0x07));
457  }
458  else
459  {
460  /* set the corresponding bit (given by the lower nibble in the parameter Module)
461  * in register PMCON1 */
462  SCU->PMCON1.reg &= (uint8) ~ (1u << ((uint8)Module & (uint8)0x07));
463  }
464 }
465 
478 INLINE void SCU_OpenPASSWD(void)
479 {
480  Field_Wrt8all(&SCU->PASSWD.reg, PASSWD_Open);
481 }
482 
495 INLINE void SCU_ClosePASSWD(void)
496 {
497  Field_Wrt8all(&SCU->PASSWD.reg, PASSWD_Close);
498 }
499 
500 #endif
Mod_Timer2
Definition: scu.h:187
SCU_WDTCON_WDTEN_Pos
#define SCU_WDTCON_WDTEN_Pos
Definition: tle986x.h:9228
types.h
General type declarations.
SCU_Enable_Module
INLINE void SCU_Enable_Module(TScu_Mod Module)
Enables a given peripheral module in the Peripheral Management Control Registers.
Definition: scu.h:441
SCU_OpenPASSWD
INLINE void SCU_OpenPASSWD(void)
Opens the bit protection by writing PASSWD_Open to the Bit Protection Register.
Definition: scu.h:469
SCU_ChangeNVMProtection
bool SCU_ChangeNVMProtection(uint32 mode, uint32 action)
Sets the Write/Read Protection for the Code/Data Flash.
Mod_SSC2
Definition: scu.h:189
SCU_Disable_Module
INLINE void SCU_Disable_Module(TScu_Mod Module)
Disables a given peripheral module in the Peripheral Management Control Registers.
Definition: scu.h:411
sfr_access.h
SFR low level access library.
Field_Wrt8all
INLINE void Field_Wrt8all(volatile uint8 *reg, uint8 val)
This function writes an 8-bit register directly, no mask/position needed.
Definition: sfr_access.h:326
INLINE
#define INLINE
Definition: types.h:134
Field_Mod8
INLINE void Field_Mod8(volatile uint8 *reg, uint8 pos, uint8 msk, uint8 val)
This function writes a bit field in a 8-bit register.
Definition: sfr_access.h:346
SCU_WDT_Stop
INLINE void SCU_WDT_Stop(void)
Stops the Watchdog of SCU-DM in the Watchdog Timer Control Register The written bit is protected by t...
Definition: scu.h:372
PASSWD_Close
#define PASSWD_Close
PASSWD Phrases, PASSWD Closed.
Definition: scu.h:142
SCU_ExitSlowMode
void SCU_ExitSlowMode(void)
Gets the device out of Slow Mode.
SCU_Init
void SCU_Init(void)
Initializes the SCU module.
Mod_GPT12
Definition: scu.h:188
uint8
unsigned char uint8
8 bit unsigned value
Definition: types.h:139
SCU_WDT_Service
INLINE void SCU_WDT_Service(void)
Services the Watchdog of SCU-DM in the Watchdog Timer Control Register.
Definition: scu.h:392
SCU_WDTCON_WDTEN_Msk
#define SCU_WDTCON_WDTEN_Msk
Definition: tle986x.h:9229
SCU_WDTCON_WDTRS_Msk
#define SCU_WDTCON_WDTRS_Msk
Definition: tle986x.h:9231
uint32
unsigned int uint32
32 bit unsigned value
Definition: types.h:141
Mod_ADC1
Definition: scu.h:184
SCU_ClosePASSWD
INLINE void SCU_ClosePASSWD(void)
Closes the bit protection by writing PASSWD_Close to the Bit Protection Register.
Definition: scu.h:486
SCU_WDT_Start
INLINE void SCU_WDT_Start(void)
Starts the Watchdog of SCU-DM in the Watchdog Timer Control Register The written bit is protected by ...
Definition: scu.h:352
TScu_Mod
TScu_Mod
This enum lists the SCU Modules Configuration.
Definition: scu.h:182
tle986x.h
CMSIS register HeaderFile.
SCU_EnterSlowMode
void SCU_EnterSlowMode(uint8 divider_scaled)
Sets the device into Slow Down Mode.
SCU
#define SCU
Definition: tle986x.h:6004
SCU_WDTCON_WDTRS_Pos
#define SCU_WDTCON_WDTRS_Pos
Definition: tle986x.h:9230
Mod_SSC1
Definition: scu.h:185
Mod_Timer21
Definition: scu.h:190
SCU_EnterSleepMode
void SCU_EnterSleepMode(void)
Sets the device into Sleep Mode.
SCU_EnterStopMode
void SCU_EnterStopMode(void)
Sets the device into Stop Mode.
Mod_Timer3
Definition: scu.h:191
SCU_ClkInit
void SCU_ClkInit(void)
Initializes the system clocks.
PASSWD_Open
#define PASSWD_Open
PASSWD Phrases, PASSWD Opened.
Definition: scu.h:140
Mod_CCU6
Definition: scu.h:186