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