1 /******************************************************************************
3 * Copyright (C) 2010 - 2015 Xilinx, Inc. All rights reserved.
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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.
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
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.
31 ******************************************************************************/
32 /****************************************************************************/
36 * @addtogroup scuwdt_v2_1
39 * Contains the implementation of interface functions of the XScuWdt driver.
40 * See xscuwdt.h for a description of the driver.
43 * MODIFICATION HISTORY:
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.
51 ******************************************************************************/
53 /***************************** Include Files *********************************/
57 /************************** Constant Definitions *****************************/
59 /**************************** Type Definitions *******************************/
61 /***************** Macros (Inline Functions) Definitions *********************/
63 /************************** Function Prototypes ******************************/
65 /************************** Variable Definitions *****************************/
67 /****************************************************************************/
70 * Initialize a specific watchdog timer instance/driver. This function
71 * must be called before other functions of the driver are called.
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.
80 * - XST_SUCCESS if initialization was successful.
81 * - XST_DEVICE_IS_STARTED if the device has already been started.
83 * @note This function enables the watchdog mode.
85 ******************************************************************************/
86 s32 XScuWdt_CfgInitialize(XScuWdt *InstancePtr,
87 XScuWdt_Config *ConfigPtr, u32 EffectiveAddress)
90 Xil_AssertNonvoid(InstancePtr != NULL);
91 Xil_AssertNonvoid(ConfigPtr != NULL);
92 Xil_AssertNonvoid(EffectiveAddress != 0x00U);
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
100 if (InstancePtr->IsStarted == XIL_COMPONENT_IS_STARTED) {
101 CfgStatus = (s32)XST_DEVICE_IS_STARTED;
105 * Copy configuration into instance.
107 InstancePtr->Config.DeviceId = ConfigPtr->DeviceId;
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.
113 InstancePtr->Config.BaseAddr = EffectiveAddress;
114 InstancePtr->IsStarted = 0U;
117 * Put the watchdog timer in Watchdog mode.
119 XScuWdt_SetWdMode(InstancePtr);
122 * Indicate the instance is ready to use, successfully initialized.
124 InstancePtr->IsReady = XIL_COMPONENT_IS_READY;
126 CfgStatus =(s32)XST_SUCCESS;
131 /****************************************************************************/
134 * Start the watchdog counter of the device.
136 * @param InstancePtr is a pointer to the XScuWdt instance.
140 * @note User needs to select the appropriate mode (watchdog/timer)
141 * before using this API.
142 * See XScuWdt_SetWdMode/XScuWdt_SetTimerMode macros in
145 ******************************************************************************/
146 void XScuWdt_Start(XScuWdt *InstancePtr)
150 Xil_AssertVoid(InstancePtr != NULL);
151 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
154 * Read the contents of the Control register.
156 Register = XScuWdt_ReadReg(InstancePtr->Config.BaseAddr,
157 XSCUWDT_CONTROL_OFFSET);
160 * Set the 'watchdog enable' bit in the register.
162 Register |= XSCUWDT_CONTROL_WD_ENABLE_MASK;
165 * Update the Control register with the new value.
167 XScuWdt_WriteReg(InstancePtr->Config.BaseAddr,
168 XSCUWDT_CONTROL_OFFSET, Register);
171 * Indicate that the device is started.
173 InstancePtr->IsStarted = XIL_COMPONENT_IS_STARTED;
176 /****************************************************************************/
179 * Stop the watchdog timer.
181 * @param InstancePtr is a pointer to the XScuWdt instance.
187 ******************************************************************************/
188 void XScuWdt_Stop(XScuWdt *InstancePtr)
192 Xil_AssertVoid(InstancePtr != NULL);
193 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
196 * Read the contents of the Control register.
198 Register = XScuWdt_ReadReg(InstancePtr->Config.BaseAddr,
199 XSCUWDT_CONTROL_OFFSET);
202 * Clear the 'watchdog enable' bit in the register.
204 Register &= (u32)(~XSCUWDT_CONTROL_WD_ENABLE_MASK);
207 * Update the Control register with the new value.
209 XScuWdt_WriteReg(InstancePtr->Config.BaseAddr,
210 XSCUWDT_CONTROL_OFFSET, Register);
213 * Indicate that the device is stopped.
215 InstancePtr->IsStarted = 0U;