]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_R5_UltraScale_MPSoC/RTOSDemo_R5_bsp/psu_cortexr5_0/libsrc/wdtps_v3_0/src/xwdtps.h
Update Zynq, MPSoc Cortex-A53 and MPSoc Cortex-R5 demo projects to build with the...
[freertos] / FreeRTOS / Demo / CORTEX_R5_UltraScale_MPSoC / RTOSDemo_R5_bsp / psu_cortexr5_0 / libsrc / wdtps_v3_0 / src / xwdtps.h
1 /******************************************************************************
2 *
3 * Copyright (C) 2010 - 2015 Xilinx, Inc.  All rights reserved.
4 *
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:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
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.
18 *
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
25 * SOFTWARE.
26 *
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.
30 *
31 ******************************************************************************/
32 /****************************************************************************/
33 /**
34 *
35 * @file xwdtps.h
36 * @addtogroup wdtps_v3_0
37 * @{
38 * @details
39 *
40 * The Xilinx watchdog timer driver supports the Xilinx watchdog timer hardware.
41 *
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
48 *
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.
52 *
53 * If interrupt is enabled, the watchdog timer device generates an interrupt
54 * when the counter reaches zero.
55 *
56 * If the hardware interrupt signal is not connected/enabled, polled mode is the
57 * only option (using IsWdtExpired) for the watchdog.
58 *
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().
62 *
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.
66 * <pre>
67 *     register ZMR = 0x1C2
68 *     register CCR = 0x3FC
69 * </pre>
70 *
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.
75 *
76 * <pre>
77 * MODIFICATION HISTORY:
78 *
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
88 *                                               for CR 658287
89 * 3.0   pkp        12/09/14 Added support for Zynq Ultrascale Mp.Also
90 *                       modified code for MISRA-C:2012 compliance.
91 *       ms     03/17/17 Added readme.txt file in examples folder for doxygen
92 *                       generation.
93 * </pre>
94 *
95 ******************************************************************************/
96 #ifndef XWDTPS_H                /* prevent circular inclusions */
97 #define XWDTPS_H                /* by using protection macros */
98
99 /***************************** Include Files *********************************/
100 #include "xil_types.h"
101 #include "xil_assert.h"
102 #include "xstatus.h"
103 #include "xwdtps_hw.h"
104
105 #ifdef __cplusplus
106 extern "C" {
107 #endif
108
109 /************************** Constant Definitions *****************************/
110
111 /*
112  * Choices for output selections for the device, used in
113  * XWdtPs_EnableOutput()/XWdtPs_DisableOutput() functions
114  */
115 #define XWDTPS_RESET_SIGNAL     0x01U   /**< Reset signal request */
116 #define XWDTPS_IRQ_SIGNAL       0x02U   /**< IRQ signal request */
117
118 /*
119  * Control value setting flags, used in
120  * XWdtPs_SetControlValues()/XWdtPs_GetControlValues() functions
121  */
122 #define XWDTPS_CLK_PRESCALE             0x01U   /**< Clock Prescale request */
123 #define XWDTPS_COUNTER_RESET    0x02U   /**< Counter Reset request */
124
125 /**************************** Type Definitions *******************************/
126
127 /**
128  * This typedef contains configuration information for the device.
129  */
130 typedef struct {
131         u16 DeviceId;           /**< Unique ID of device */
132         u32 BaseAddress;        /**< Base address of the device */
133 } XWdtPs_Config;
134
135
136 /**
137  * The XWdtPs driver instance data. The user is required to allocate a
138  * variable of this type for every watchdog/timer device in the system.
139  * A pointer to a variable of this type is then passed to the driver API
140  * functions.
141  */
142 typedef struct {
143         XWdtPs_Config Config;   /**< Hardware Configuration */
144         u32 IsReady;            /**< Device is initialized and ready */
145         u32 IsStarted;          /**< Device watchdog timer is running */
146 } XWdtPs;
147
148 /***************** Macros (Inline Functions) Definitions *********************/
149 /****************************************************************************/
150 /**
151 *
152 * Check if the watchdog timer has expired. This function is used for polled
153 * mode and it is also used to check if the last reset was caused by the
154 * watchdog timer.
155 *
156 * @param        InstancePtr is a pointer to the XWdtPs instance.
157 *
158 * @return
159 *               - TRUE if the watchdog has expired.
160 *               - FALSE if the watchdog has not expired.
161 *
162 * @note         C-style signature:
163 *               int XWdtPs_IsWdtExpired(XWdtPs *InstancePtr)
164 *
165 ******************************************************************************/
166 #define XWdtPs_IsWdtExpired(InstancePtr)                                  \
167 ((XWdtPs_ReadReg((InstancePtr)->Config.BaseAddress, XWDTPS_SR_OFFSET) & \
168    XWDTPS_SR_WDZ_MASK) == XWDTPS_SR_WDZ_MASK)
169
170
171 /****************************************************************************/
172 /**
173 *
174 * Restart the watchdog timer. An application needs to call this function
175 * periodically to keep the timer from asserting the enabled output.
176 *
177 * @param        InstancePtr is a pointer to the XWdtPs instance.
178 *
179 * @return       None.
180 *
181 * @note         C-style signature:
182 *               void XWdtPs_RestartWdt(XWdtPs *InstancePtr)
183 *
184 ******************************************************************************/
185 #define XWdtPs_RestartWdt(InstancePtr)                                  \
186         XWdtPs_WriteReg((InstancePtr)->Config.BaseAddress,              \
187                 XWDTPS_RESTART_OFFSET, XWDTPS_RESTART_KEY_VAL)
188
189 /************************** Function Prototypes ******************************/
190
191 /*
192  * Lookup configuration in xwdtps_sinit.c.
193  */
194 XWdtPs_Config *XWdtPs_LookupConfig(u16 DeviceId);
195
196 /*
197  * Interface functions in xwdtps.c
198  */
199 s32 XWdtPs_CfgInitialize(XWdtPs *InstancePtr,
200                         XWdtPs_Config *ConfigPtr, u32 EffectiveAddress);
201
202 void XWdtPs_Start(XWdtPs *InstancePtr);
203
204 void XWdtPs_Stop(XWdtPs *InstancePtr);
205
206 void XWdtPs_EnableOutput(XWdtPs *InstancePtr, u8 Signal);
207
208 void XWdtPs_DisableOutput(XWdtPs *InstancePtr, u8 Signal);
209
210 u32 XWdtPs_GetControlValue(XWdtPs *InstancePtr, u8 Control);
211
212 void XWdtPs_SetControlValue(XWdtPs *InstancePtr, u8 Control, u32 Value);
213
214 /*
215  * Self-test function in xwdttb_selftest.c.
216  */
217 s32 XWdtPs_SelfTest(XWdtPs *InstancePtr);
218
219
220 #ifdef __cplusplus
221 }
222 #endif
223
224 #endif /* end of protection macro */
225 /** @} */