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