]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo_bsp/ps7_cortexa9_0/libsrc/scuwdt_v2_1/src/xscuwdt.c
Update Zynq, MPSoc Cortex-A53 and MPSoc Cortex-R5 demo projects to build with the...
[freertos] / FreeRTOS / Demo / CORTEX_A9_Zynq_ZC702 / RTOSDemo_bsp / ps7_cortexa9_0 / libsrc / scuwdt_v2_1 / src / xscuwdt.c
1 /******************************************************************************
2 *
3 * Copyright (C) 2010 - 2015 Xilinx, Inc.  All rights reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * Use of the Software is limited solely to applications:
16 * (a) running on a Xilinx device, or
17 * (b) that interact with a Xilinx device through a bus or interconnect.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * XILINX  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 *
27 * Except as contained in this notice, the name of the Xilinx shall not be used
28 * in advertising or otherwise to promote the sale, use or other dealings in
29 * this Software without prior written authorization from Xilinx.
30 *
31 ******************************************************************************/
32 /****************************************************************************/
33 /**
34 *
35 * @file xscuwdt.c
36 * @addtogroup scuwdt_v2_1
37 * @{
38 *
39 * Contains the implementation of interface functions of the XScuWdt driver.
40 * See xscuwdt.h for a description of the driver.
41 *
42 * <pre>
43 * MODIFICATION HISTORY:
44 *
45 * Ver   Who Date     Changes
46 * ----- --- -------- ---------------------------------------------
47 * 1.00a sdm 01/15/10 First release
48 * 2.1   sk  02/26/15 Modified the code for MISRA-C:2012 compliance.
49 * </pre>
50 *
51 ******************************************************************************/
52
53 /***************************** Include Files *********************************/
54
55 #include "xscuwdt.h"
56
57 /************************** Constant Definitions *****************************/
58
59 /**************************** Type Definitions *******************************/
60
61 /***************** Macros (Inline Functions) Definitions *********************/
62
63 /************************** Function Prototypes ******************************/
64
65 /************************** Variable Definitions *****************************/
66
67 /****************************************************************************/
68 /**
69 *
70 * Initialize a specific watchdog timer instance/driver. This function
71 * must be called before other functions of the driver are called.
72 *
73 * @param        InstancePtr is a pointer to the XScuWdt instance.
74 * @param        ConfigPtr is the config structure.
75 * @param        EffectiveAddress is the base address for the device. It could be
76 *               a virtual address if address translation is supported in the
77 *               system, otherwise it is the physical address.
78 *
79 * @return
80 *               - XST_SUCCESS if initialization was successful.
81 *               - XST_DEVICE_IS_STARTED if the device has already been started.
82 *
83 * @note         This function enables the watchdog mode.
84 *
85 ******************************************************************************/
86 s32 XScuWdt_CfgInitialize(XScuWdt *InstancePtr,
87                          XScuWdt_Config *ConfigPtr, u32 EffectiveAddress)
88 {
89         s32 CfgStatus;
90         Xil_AssertNonvoid(InstancePtr != NULL);
91         Xil_AssertNonvoid(ConfigPtr != NULL);
92         Xil_AssertNonvoid(EffectiveAddress != 0x00U);
93
94         /*
95          * If the device is started, disallow the initialize and return a
96          * status indicating it is started. This allows the user to stop the
97          * device and reinitialize, but prevents a user from inadvertently
98          * initializing.
99          */
100         if (InstancePtr->IsStarted == XIL_COMPONENT_IS_STARTED) {
101                 CfgStatus = (s32)XST_DEVICE_IS_STARTED;
102         }
103         else {
104                 /*
105                  * Copy configuration into instance.
106                  */
107                 InstancePtr->Config.DeviceId = ConfigPtr->DeviceId;
108
109                 /*
110                  * Save the base address pointer such that the registers of the block
111                  * can be accessed and indicate it has not been started yet.
112                  */
113                 InstancePtr->Config.BaseAddr = EffectiveAddress;
114                 InstancePtr->IsStarted = 0U;
115
116                 /*
117                  * Put the watchdog timer in Watchdog mode.
118                  */
119                 XScuWdt_SetWdMode(InstancePtr);
120
121                 /*
122                  * Indicate the instance is ready to use, successfully initialized.
123                  */
124                 InstancePtr->IsReady = XIL_COMPONENT_IS_READY;
125
126                 CfgStatus =(s32)XST_SUCCESS;
127         }
128         return CfgStatus;
129 }
130
131 /****************************************************************************/
132 /**
133 *
134 * Start the watchdog counter of the device.
135 *
136 * @param        InstancePtr is a pointer to the XScuWdt instance.
137 *
138 * @return       None.
139 *
140 * @note         User needs to select the appropriate mode (watchdog/timer)
141 *               before using this API.
142 *               See XScuWdt_SetWdMode/XScuWdt_SetTimerMode macros in
143 *               xscuwdt.h.
144 *
145 ******************************************************************************/
146 void XScuWdt_Start(XScuWdt *InstancePtr)
147 {
148         u32 Register;
149
150         Xil_AssertVoid(InstancePtr != NULL);
151         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
152
153         /*
154          * Read the contents of the Control register.
155          */
156         Register = XScuWdt_ReadReg(InstancePtr->Config.BaseAddr,
157                                   XSCUWDT_CONTROL_OFFSET);
158
159         /*
160          * Set the 'watchdog enable' bit in the register.
161          */
162         Register |= XSCUWDT_CONTROL_WD_ENABLE_MASK;
163
164         /*
165          * Update the Control register with the new value.
166          */
167         XScuWdt_WriteReg(InstancePtr->Config.BaseAddr,
168                         XSCUWDT_CONTROL_OFFSET, Register);
169
170         /*
171          * Indicate that the device is started.
172          */
173         InstancePtr->IsStarted = XIL_COMPONENT_IS_STARTED;
174 }
175
176 /****************************************************************************/
177 /**
178 *
179 * Stop the watchdog timer.
180 *
181 * @param        InstancePtr is a pointer to the XScuWdt instance.
182 *
183 * @return       None.
184 *
185 * @note         None.
186 *
187 ******************************************************************************/
188 void XScuWdt_Stop(XScuWdt *InstancePtr)
189 {
190         u32 Register;
191
192         Xil_AssertVoid(InstancePtr != NULL);
193         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
194
195         /*
196          * Read the contents of the Control register.
197          */
198         Register = XScuWdt_ReadReg(InstancePtr->Config.BaseAddr,
199                                   XSCUWDT_CONTROL_OFFSET);
200
201         /*
202          * Clear the 'watchdog enable' bit in the register.
203          */
204         Register &= (u32)(~XSCUWDT_CONTROL_WD_ENABLE_MASK);
205
206         /*
207          * Update the Control register with the new value.
208          */
209         XScuWdt_WriteReg(InstancePtr->Config.BaseAddr,
210                         XSCUWDT_CONTROL_OFFSET, Register);
211
212         /*
213          * Indicate that the device is stopped.
214          */
215         InstancePtr->IsStarted = 0U;
216 }
217 /** @} */