Added support for v4.2 boards
[SCSI2SD.git] / software / SCSI2SD / v4 / SCSI2SD.cydsn / Generated_Source / PSoC5 / Debug_Timer_PM.c
1 /*******************************************************************************
2 * File Name: Debug_Timer_PM.c
3 * Version 2.50
4 *
5 *  Description:
6 *     This file provides the power management source code to API for the
7 *     Timer.
8 *
9 *   Note:
10 *     None
11 *
12 *******************************************************************************
13 * Copyright 2008-2012, Cypress Semiconductor Corporation.  All rights reserved.
14 * You may use this file only in accordance with the license, terms, conditions,
15 * disclaimers, and limitations in the end user license agreement accompanying
16 * the software package with which this file was provided.
17 ********************************************************************************/
18
19 #include "Debug_Timer.h"
20 static Debug_Timer_backupStruct Debug_Timer_backup;
21
22
23 /*******************************************************************************
24 * Function Name: Debug_Timer_SaveConfig
25 ********************************************************************************
26 *
27 * Summary:
28 *     Save the current user configuration
29 *
30 * Parameters:
31 *  void
32 *
33 * Return:
34 *  void
35 *
36 * Global variables:
37 *  Debug_Timer_backup:  Variables of this global structure are modified to
38 *  store the values of non retention configuration registers when Sleep() API is
39 *  called.
40 *
41 *******************************************************************************/
42 void Debug_Timer_SaveConfig(void) 
43 {
44     #if (!Debug_Timer_UsingFixedFunction)
45         /* Backup the UDB non-rentention registers for CY_UDB_V0 */
46         #if (CY_UDB_V0)
47             Debug_Timer_backup.TimerUdb = Debug_Timer_ReadCounter();
48             Debug_Timer_backup.TimerPeriod = Debug_Timer_ReadPeriod();
49             Debug_Timer_backup.InterruptMaskValue = Debug_Timer_STATUS_MASK;
50             #if (Debug_Timer_UsingHWCaptureCounter)
51                 Debug_Timer_backup.TimerCaptureCounter = Debug_Timer_ReadCaptureCount();
52             #endif /* Backup the UDB non-rentention register capture counter for CY_UDB_V0 */
53         #endif /* Backup the UDB non-rentention registers for CY_UDB_V0 */
54
55         #if (CY_UDB_V1)
56             Debug_Timer_backup.TimerUdb = Debug_Timer_ReadCounter();
57             Debug_Timer_backup.InterruptMaskValue = Debug_Timer_STATUS_MASK;
58             #if (Debug_Timer_UsingHWCaptureCounter)
59                 Debug_Timer_backup.TimerCaptureCounter = Debug_Timer_ReadCaptureCount();
60             #endif /* Back Up capture counter register  */
61         #endif /* Backup non retention registers, interrupt mask and capture counter for CY_UDB_V1 */
62
63         #if(!Debug_Timer_ControlRegRemoved)
64             Debug_Timer_backup.TimerControlRegister = Debug_Timer_ReadControlRegister();
65         #endif /* Backup the enable state of the Timer component */
66     #endif /* Backup non retention registers in UDB implementation. All fixed function registers are retention */
67 }
68
69
70 /*******************************************************************************
71 * Function Name: Debug_Timer_RestoreConfig
72 ********************************************************************************
73 *
74 * Summary:
75 *  Restores the current user configuration.
76 *
77 * Parameters:
78 *  void
79 *
80 * Return:
81 *  void
82 *
83 * Global variables:
84 *  Debug_Timer_backup:  Variables of this global structure are used to
85 *  restore the values of non retention registers on wakeup from sleep mode.
86 *
87 *******************************************************************************/
88 void Debug_Timer_RestoreConfig(void) 
89 {   
90     #if (!Debug_Timer_UsingFixedFunction)
91         /* Restore the UDB non-rentention registers for CY_UDB_V0 */
92         #if (CY_UDB_V0)
93             /* Interrupt State Backup for Critical Region*/
94             uint8 Debug_Timer_interruptState;
95
96             Debug_Timer_WriteCounter(Debug_Timer_backup.TimerUdb);
97             Debug_Timer_WritePeriod(Debug_Timer_backup.TimerPeriod);
98             /* CyEnterCriticalRegion and CyExitCriticalRegion are used to mark following region critical*/
99             /* Enter Critical Region*/
100             Debug_Timer_interruptState = CyEnterCriticalSection();
101             /* Use the interrupt output of the status register for IRQ output */
102             Debug_Timer_STATUS_AUX_CTRL |= Debug_Timer_STATUS_ACTL_INT_EN_MASK;
103             /* Exit Critical Region*/
104             CyExitCriticalSection(Debug_Timer_interruptState);
105             Debug_Timer_STATUS_MASK =Debug_Timer_backup.InterruptMaskValue;
106             #if (Debug_Timer_UsingHWCaptureCounter)
107                 Debug_Timer_SetCaptureCount(Debug_Timer_backup.TimerCaptureCounter);
108             #endif /* Restore the UDB non-rentention register capture counter for CY_UDB_V0 */
109         #endif /* Restore the UDB non-rentention registers for CY_UDB_V0 */
110
111         #if (CY_UDB_V1)
112             Debug_Timer_WriteCounter(Debug_Timer_backup.TimerUdb);
113             Debug_Timer_STATUS_MASK =Debug_Timer_backup.InterruptMaskValue;
114             #if (Debug_Timer_UsingHWCaptureCounter)
115                 Debug_Timer_SetCaptureCount(Debug_Timer_backup.TimerCaptureCounter);
116             #endif /* Restore Capture counter register*/
117         #endif /* Restore up non retention registers, interrupt mask and capture counter for CY_UDB_V1 */
118
119         #if(!Debug_Timer_ControlRegRemoved)
120             Debug_Timer_WriteControlRegister(Debug_Timer_backup.TimerControlRegister);
121         #endif /* Restore the enable state of the Timer component */
122     #endif /* Restore non retention registers in the UDB implementation only */
123 }
124
125
126 /*******************************************************************************
127 * Function Name: Debug_Timer_Sleep
128 ********************************************************************************
129 *
130 * Summary:
131 *     Stop and Save the user configuration
132 *
133 * Parameters:
134 *  void
135 *
136 * Return:
137 *  void
138 *
139 * Global variables:
140 *  Debug_Timer_backup.TimerEnableState:  Is modified depending on the
141 *  enable state of the block before entering sleep mode.
142 *
143 *******************************************************************************/
144 void Debug_Timer_Sleep(void) 
145 {
146     #if(!Debug_Timer_ControlRegRemoved)
147         /* Save Counter's enable state */
148         if(Debug_Timer_CTRL_ENABLE == (Debug_Timer_CONTROL & Debug_Timer_CTRL_ENABLE))
149         {
150             /* Timer is enabled */
151             Debug_Timer_backup.TimerEnableState = 1u;
152         }
153         else
154         {
155             /* Timer is disabled */
156             Debug_Timer_backup.TimerEnableState = 0u;
157         }
158     #endif /* Back up enable state from the Timer control register */
159     Debug_Timer_Stop();
160     Debug_Timer_SaveConfig();
161 }
162
163
164 /*******************************************************************************
165 * Function Name: Debug_Timer_Wakeup
166 ********************************************************************************
167 *
168 * Summary:
169 *  Restores and enables the user configuration
170 *
171 * Parameters:
172 *  void
173 *
174 * Return:
175 *  void
176 *
177 * Global variables:
178 *  Debug_Timer_backup.enableState:  Is used to restore the enable state of
179 *  block on wakeup from sleep mode.
180 *
181 *******************************************************************************/
182 void Debug_Timer_Wakeup(void) 
183 {
184     Debug_Timer_RestoreConfig();
185     #if(!Debug_Timer_ControlRegRemoved)
186         if(Debug_Timer_backup.TimerEnableState == 1u)
187         {     /* Enable Timer's operation */
188                 Debug_Timer_Enable();
189         } /* Do nothing if Timer was disabled before */
190     #endif /* Remove this code section if Control register is removed */
191 }
192
193
194 /* [] END OF FILE */