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 wdtps_v3_0
40 * The Xilinx watchdog timer driver supports the Xilinx watchdog timer hardware.
42 * The Xilinx watchdog timer (WDT) driver supports the following features:
43 * - Both Interrupt driven and Polled mode
44 * - enabling and disabling the watchdog timer
45 * - restarting the watchdog.
46 * - initializing the most significant digit of the counter restart value.
47 * - multiple individually enabling/disabling outputs
49 * It is the responsibility of the application to provide an interrupt handler
50 * for the watchdog timer and connect it to the interrupt system if interrupt
51 * driven mode is desired.
53 * If interrupt is enabled, the watchdog timer device generates an interrupt
54 * when the counter reaches zero.
56 * If the hardware interrupt signal is not connected/enabled, polled mode is the
57 * only option (using IsWdtExpired) for the watchdog.
59 * The outputs from the WDT are individually enabled/disabled using
60 * _EnableOutput()/_DisableOutput(). The clock divisor ratio and initial restart
61 * value of the count is configurable using _SetControlValues().
63 * The reset condition of the hardware has the maximum initial count in the
64 * Counter Reset Value (CRV) and the WDT is disabled with the reset enable
65 * enabled and the reset length set to 32 clocks. i.e.
67 * register ZMR = 0x1C2
68 * register CCR = 0x3FC
71 * This driver is intended to be RTOS and processor independent. It works with
72 * physical addresses only. Any needs for dynamic memory management, threads
73 * or thread mutual exclusion, virtual memory, or cache control must be
74 * satisfied by the layer above this driver.
77 * MODIFICATION HISTORY:
79 * Ver Who Date Changes
80 * ----- ------ -------- -----------------------------------------------
81 * 1.00a ecm/jz 01/15/10 First release
82 * 1.01a asa 02/15/12 Added tcl file to generate xparameters
83 * 1.02a sg 07/15/12 Removed code/APIs related to External Signal
84 * Length functionality for CR 658287
85 * Removed APIs XWdtPs_SetExternalSignalLength,
86 * XWdtPs_GetExternalSignalLength
87 * Modified the Self Test to use the Reset Length mask
89 * 3.0 pkp 12/09/14 Added support for Zynq Ultrascale Mp.Also
90 * modified code for MISRA-C:2012 compliance.
93 ******************************************************************************/
94 #ifndef XWDTPS_H /* prevent circular inclusions */
95 #define XWDTPS_H /* by using protection macros */
97 /***************************** Include Files *********************************/
98 #include "xil_types.h"
99 #include "xil_assert.h"
101 #include "xwdtps_hw.h"
107 /************************** Constant Definitions *****************************/
110 * Choices for output selections for the device, used in
111 * XWdtPs_EnableOutput()/XWdtPs_DisableOutput() functions
113 #define XWDTPS_RESET_SIGNAL 0x01U /**< Reset signal request */
114 #define XWDTPS_IRQ_SIGNAL 0x02U /**< IRQ signal request */
117 * Control value setting flags, used in
118 * XWdtPs_SetControlValues()/XWdtPs_GetControlValues() functions
120 #define XWDTPS_CLK_PRESCALE 0x01U /**< Clock Prescale request */
121 #define XWDTPS_COUNTER_RESET 0x02U /**< Counter Reset request */
123 /**************************** Type Definitions *******************************/
126 * This typedef contains configuration information for the device.
129 u16 DeviceId; /**< Unique ID of device */
130 u32 BaseAddress; /**< Base address of the device */
135 * The XWdtPs driver instance data. The user is required to allocate a
136 * variable of this type for every watchdog/timer device in the system.
137 * A pointer to a variable of this type is then passed to the driver API
141 XWdtPs_Config Config; /**< Hardware Configuration */
142 u32 IsReady; /**< Device is initialized and ready */
143 u32 IsStarted; /**< Device watchdog timer is running */
146 /***************** Macros (Inline Functions) Definitions *********************/
147 /****************************************************************************/
150 * Check if the watchdog timer has expired. This function is used for polled
151 * mode and it is also used to check if the last reset was caused by the
154 * @param InstancePtr is a pointer to the XWdtPs instance.
157 * - TRUE if the watchdog has expired.
158 * - FALSE if the watchdog has not expired.
160 * @note C-style signature:
161 * int XWdtPs_IsWdtExpired(XWdtPs *InstancePtr)
163 ******************************************************************************/
164 #define XWdtPs_IsWdtExpired(InstancePtr) \
165 ((XWdtPs_ReadReg((InstancePtr)->Config.BaseAddress, XWDTPS_SR_OFFSET) & \
166 XWDTPS_SR_WDZ_MASK) == XWDTPS_SR_WDZ_MASK)
169 /****************************************************************************/
172 * Restart the watchdog timer. An application needs to call this function
173 * periodically to keep the timer from asserting the enabled output.
175 * @param InstancePtr is a pointer to the XWdtPs instance.
179 * @note C-style signature:
180 * void XWdtPs_RestartWdt(XWdtPs *InstancePtr)
182 ******************************************************************************/
183 #define XWdtPs_RestartWdt(InstancePtr) \
184 XWdtPs_WriteReg((InstancePtr)->Config.BaseAddress, \
185 XWDTPS_RESTART_OFFSET, XWDTPS_RESTART_KEY_VAL)
187 /************************** Function Prototypes ******************************/
190 * Lookup configuration in xwdtps_sinit.c.
192 XWdtPs_Config *XWdtPs_LookupConfig(u16 DeviceId);
195 * Interface functions in xwdtps.c
197 s32 XWdtPs_CfgInitialize(XWdtPs *InstancePtr,
198 XWdtPs_Config *ConfigPtr, u32 EffectiveAddress);
200 void XWdtPs_Start(XWdtPs *InstancePtr);
202 void XWdtPs_Stop(XWdtPs *InstancePtr);
204 void XWdtPs_EnableOutput(XWdtPs *InstancePtr, u8 Signal);
206 void XWdtPs_DisableOutput(XWdtPs *InstancePtr, u8 Signal);
208 u32 XWdtPs_GetControlValue(XWdtPs *InstancePtr, u8 Control);
210 void XWdtPs_SetControlValue(XWdtPs *InstancePtr, u8 Control, u32 Value);
213 * Self-test function in xwdttb_selftest.c.
215 s32 XWdtPs_SelfTest(XWdtPs *InstancePtr);
222 #endif /* end of protection macro */