]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo_bsp/ps7_cortexa9_0/libsrc/scuwdt_v2_0/src/xscuwdt.c
FreeRTOS source updates:
[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 * @addtogroup scuwdt_v2_0
38 * @{
39 *
40 * Contains the implementation of interface functions of the XScuWdt driver.
41 * See xscuwdt.h for a description of the driver.
42 *
43 * <pre>
44 * MODIFICATION HISTORY:
45 *
46 * Ver   Who Date     Changes
47 * ----- --- -------- ---------------------------------------------
48 * 1.00a sdm 01/15/10 First release
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 int XScuWdt_CfgInitialize(XScuWdt *InstancePtr,
87                          XScuWdt_Config *ConfigPtr, u32 EffectiveAddress)
88 {
89         Xil_AssertNonvoid(InstancePtr != NULL);
90         Xil_AssertNonvoid(ConfigPtr != NULL);
91
92         /*
93          * If the device is started, disallow the initialize and return a
94          * status indicating it is started. This allows the user to stop the
95          * device and reinitialize, but prevents a user from inadvertently
96          * initializing.
97          */
98         if (InstancePtr->IsStarted == XIL_COMPONENT_IS_STARTED) {
99                 return XST_DEVICE_IS_STARTED;
100         }
101
102         /*
103          * Copy configuration into instance.
104          */
105         InstancePtr->Config.DeviceId = ConfigPtr->DeviceId;
106
107         /*
108          * Save the base address pointer such that the registers of the block
109          * can be accessed and indicate it has not been started yet.
110          */
111         InstancePtr->Config.BaseAddr = EffectiveAddress;
112         InstancePtr->IsStarted = 0;
113
114         /*
115          * Put the watchdog timer in Watchdog mode.
116          */
117         XScuWdt_SetWdMode(InstancePtr);
118
119         /*
120          * Indicate the instance is ready to use, successfully initialized.
121          */
122         InstancePtr->IsReady = XIL_COMPONENT_IS_READY;
123
124         return XST_SUCCESS;
125 }
126
127 /****************************************************************************/
128 /**
129 *
130 * Start the watchdog counter of the device.
131 *
132 * @param        InstancePtr is a pointer to the XScuWdt instance.
133 *
134 * @return       None.
135 *
136 * @note         User needs to select the appropriate mode (watchdog/timer)
137 *               before using this API.
138 *               See XScuWdt_SetWdMode/XScuWdt_SetTimerMode macros in
139 *               xscuwdt.h.
140 *
141 ******************************************************************************/
142 void XScuWdt_Start(XScuWdt *InstancePtr)
143 {
144         u32 Register;
145
146         Xil_AssertVoid(InstancePtr != NULL);
147         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
148
149         /*
150          * Read the contents of the Control register.
151          */
152         Register = XScuWdt_ReadReg(InstancePtr->Config.BaseAddr,
153                                   XSCUWDT_CONTROL_OFFSET);
154
155         /*
156          * Set the 'watchdog enable' bit in the register.
157          */
158         Register |= XSCUWDT_CONTROL_WD_ENABLE_MASK;
159
160         /*
161          * Update the Control register with the new value.
162          */
163         XScuWdt_WriteReg(InstancePtr->Config.BaseAddr,
164                         XSCUWDT_CONTROL_OFFSET, Register);
165
166         /*
167          * Indicate that the device is started.
168          */
169         InstancePtr->IsStarted = XIL_COMPONENT_IS_STARTED;
170 }
171
172 /****************************************************************************/
173 /**
174 *
175 * Stop the watchdog timer.
176 *
177 * @param        InstancePtr is a pointer to the XScuWdt instance.
178 *
179 * @return       None.
180 *
181 * @note         None.
182 *
183 ******************************************************************************/
184 void XScuWdt_Stop(XScuWdt *InstancePtr)
185 {
186         u32 Register;
187
188         Xil_AssertVoid(InstancePtr != NULL);
189         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
190
191         /*
192          * Read the contents of the Control register.
193          */
194         Register = XScuWdt_ReadReg(InstancePtr->Config.BaseAddr,
195                                   XSCUWDT_CONTROL_OFFSET);
196
197         /*
198          * Clear the 'watchdog enable' bit in the register.
199          */
200         Register &= ~XSCUWDT_CONTROL_WD_ENABLE_MASK;
201
202         /*
203          * Update the Control register with the new value.
204          */
205         XScuWdt_WriteReg(InstancePtr->Config.BaseAddr,
206                         XSCUWDT_CONTROL_OFFSET, Register);
207
208         /*
209          * Indicate that the device is stopped.
210          */
211         InstancePtr->IsStarted = 0;
212 }
213 /** @} */