]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo_bsp/ps7_cortexa9_0/libsrc/scuwdt_v2_1/src/xscuwdt.c
Completely re-generate the Zynq 7000 demo using the 2016.1 SDK tools.
[freertos] / FreeRTOS / Demo / CORTEX_A9_Zynq_ZC702 / RTOSDemo_bsp / ps7_cortexa9_0 / libsrc / scuwdt_v2_1 / 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 - 2015 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_1
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 * 2.1   sk  02/26/15 Modified the code for MISRA-C:2012 compliance.
50 * </pre>
51 *
52 ******************************************************************************/
53
54 /***************************** Include Files *********************************/
55
56 #include "xscuwdt.h"
57
58 /************************** Constant Definitions *****************************/
59
60 /**************************** Type Definitions *******************************/
61
62 /***************** Macros (Inline Functions) Definitions *********************/
63
64 /************************** Function Prototypes ******************************/
65
66 /************************** Variable Definitions *****************************/
67
68 /****************************************************************************/
69 /**
70 *
71 * Initialize a specific watchdog timer instance/driver. This function
72 * must be called before other functions of the driver are called.
73 *
74 * @param        InstancePtr is a pointer to the XScuWdt instance.
75 * @param        ConfigPtr is the config structure.
76 * @param        EffectiveAddress is the base address for the device. It could be
77 *               a virtual address if address translation is supported in the
78 *               system, otherwise it is the physical address.
79 *
80 * @return
81 *               - XST_SUCCESS if initialization was successful.
82 *               - XST_DEVICE_IS_STARTED if the device has already been started.
83 *
84 * @note         This function enables the watchdog mode.
85 *
86 ******************************************************************************/
87 s32 XScuWdt_CfgInitialize(XScuWdt *InstancePtr,
88                          XScuWdt_Config *ConfigPtr, u32 EffectiveAddress)
89 {
90         s32 CfgStatus;
91         Xil_AssertNonvoid(InstancePtr != NULL);
92         Xil_AssertNonvoid(ConfigPtr != NULL);
93         Xil_AssertNonvoid(EffectiveAddress != 0x00U);
94
95         /*
96          * If the device is started, disallow the initialize and return a
97          * status indicating it is started. This allows the user to stop the
98          * device and reinitialize, but prevents a user from inadvertently
99          * initializing.
100          */
101         if (InstancePtr->IsStarted == XIL_COMPONENT_IS_STARTED) {
102                 CfgStatus = (s32)XST_DEVICE_IS_STARTED;
103         }
104         else {
105                 /*
106                  * Copy configuration into instance.
107                  */
108                 InstancePtr->Config.DeviceId = ConfigPtr->DeviceId;
109
110                 /*
111                  * Save the base address pointer such that the registers of the block
112                  * can be accessed and indicate it has not been started yet.
113                  */
114                 InstancePtr->Config.BaseAddr = EffectiveAddress;
115                 InstancePtr->IsStarted = 0U;
116
117                 /*
118                  * Put the watchdog timer in Watchdog mode.
119                  */
120                 XScuWdt_SetWdMode(InstancePtr);
121
122                 /*
123                  * Indicate the instance is ready to use, successfully initialized.
124                  */
125                 InstancePtr->IsReady = XIL_COMPONENT_IS_READY;
126
127                 CfgStatus =(s32)XST_SUCCESS;
128         }
129         return CfgStatus;
130 }
131
132 /****************************************************************************/
133 /**
134 *
135 * Start the watchdog counter of the device.
136 *
137 * @param        InstancePtr is a pointer to the XScuWdt instance.
138 *
139 * @return       None.
140 *
141 * @note         User needs to select the appropriate mode (watchdog/timer)
142 *               before using this API.
143 *               See XScuWdt_SetWdMode/XScuWdt_SetTimerMode macros in
144 *               xscuwdt.h.
145 *
146 ******************************************************************************/
147 void XScuWdt_Start(XScuWdt *InstancePtr)
148 {
149         u32 Register;
150
151         Xil_AssertVoid(InstancePtr != NULL);
152         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
153
154         /*
155          * Read the contents of the Control register.
156          */
157         Register = XScuWdt_ReadReg(InstancePtr->Config.BaseAddr,
158                                   XSCUWDT_CONTROL_OFFSET);
159
160         /*
161          * Set the 'watchdog enable' bit in the register.
162          */
163         Register |= XSCUWDT_CONTROL_WD_ENABLE_MASK;
164
165         /*
166          * Update the Control register with the new value.
167          */
168         XScuWdt_WriteReg(InstancePtr->Config.BaseAddr,
169                         XSCUWDT_CONTROL_OFFSET, Register);
170
171         /*
172          * Indicate that the device is started.
173          */
174         InstancePtr->IsStarted = XIL_COMPONENT_IS_STARTED;
175 }
176
177 /****************************************************************************/
178 /**
179 *
180 * Stop the watchdog timer.
181 *
182 * @param        InstancePtr is a pointer to the XScuWdt instance.
183 *
184 * @return       None.
185 *
186 * @note         None.
187 *
188 ******************************************************************************/
189 void XScuWdt_Stop(XScuWdt *InstancePtr)
190 {
191         u32 Register;
192
193         Xil_AssertVoid(InstancePtr != NULL);
194         Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
195
196         /*
197          * Read the contents of the Control register.
198          */
199         Register = XScuWdt_ReadReg(InstancePtr->Config.BaseAddr,
200                                   XSCUWDT_CONTROL_OFFSET);
201
202         /*
203          * Clear the 'watchdog enable' bit in the register.
204          */
205         Register &= (u32)(~XSCUWDT_CONTROL_WD_ENABLE_MASK);
206
207         /*
208          * Update the Control register with the new value.
209          */
210         XScuWdt_WriteReg(InstancePtr->Config.BaseAddr,
211                         XSCUWDT_CONTROL_OFFSET, Register);
212
213         /*
214          * Indicate that the device is stopped.
215          */
216         InstancePtr->IsStarted = 0U;
217 }
218 /** @} */