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
39 * Contains the implementation of interface functions of the XWdtPs driver.
40 * See xwdtps.h for a description of the driver.
43 * MODIFICATION HISTORY:
45 * Ver Who Date Changes
46 * ----- ------ -------- ---------------------------------------------
47 * 1.00a ecm/jz 01/15/10 First release
48 * 1.02a sg 07/15/12 Removed code/APIs related to External Signal
49 * Length functionality for CR 658287
50 * Removed APIs XWdtPs_SetExternalSignalLength,
51 * XWdtPs_GetExternalSignalLength
52 * 3.00 kvn 02/13/15 Modified code for MISRA-C:2012 compliance.
55 ******************************************************************************/
57 /***************************** Include Files *********************************/
61 /************************** Constant Definitions *****************************/
64 /**************************** Type Definitions *******************************/
67 /***************** Macros (Inline Functions) Definitions *********************/
70 /************************** Function Prototypes ******************************/
73 /************************** Variable Definitions *****************************/
76 /****************************************************************************/
79 * Initialize a specific watchdog timer instance/driver. This function
80 * must be called before other functions of the driver are called.
82 * @param InstancePtr is a pointer to the XWdtPs instance.
83 * @param ConfigPtr is the config structure.
84 * @param EffectiveAddress is the base address for the device. It could be
85 * a virtual address if address translation is supported in the
86 * system, otherwise it is the physical address.
89 * - XST_SUCCESS if initialization was successful.
90 * - XST_DEVICE_IS_STARTED if the device has already been started.
94 ******************************************************************************/
95 s32 XWdtPs_CfgInitialize(XWdtPs *InstancePtr,
96 XWdtPs_Config *ConfigPtr, u32 EffectiveAddress)
99 Xil_AssertNonvoid(InstancePtr != NULL);
100 Xil_AssertNonvoid(ConfigPtr != NULL);
103 * If the device is started, disallow the initialize and return a
104 * status indicating it is started. This allows the user to stop the
105 * device and reinitialize, but prevents a user from inadvertently
108 if (InstancePtr->IsStarted == XIL_COMPONENT_IS_STARTED) {
109 Status = XST_DEVICE_IS_STARTED;
113 * Copy configuration into instance.
115 InstancePtr->Config.DeviceId = ConfigPtr->DeviceId;
118 * Save the base address pointer such that the registers of the block
119 * can be accessed and indicate it has not been started yet.
121 InstancePtr->Config.BaseAddress = EffectiveAddress;
122 InstancePtr->IsStarted = 0U;
125 * Indicate the instance is ready to use, successfully initialized.
127 InstancePtr->IsReady = XIL_COMPONENT_IS_READY;
129 Status = XST_SUCCESS;
134 /****************************************************************************/
137 * Start the watchdog timer of the device.
139 * @param InstancePtr is a pointer to the XWdtPs instance.
145 ******************************************************************************/
146 void XWdtPs_Start(XWdtPs *InstancePtr)
150 Xil_AssertVoid(InstancePtr != NULL);
151 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
154 * Read the contents of the ZMR register.
156 Register = XWdtPs_ReadReg(InstancePtr->Config.BaseAddress,
160 * Enable the Timer field in the register and Set the access key so the
163 Register |= XWDTPS_ZMR_WDEN_MASK;
164 Register |= XWDTPS_ZMR_ZKEY_VAL;
167 * Update the ZMR with the new value.
169 XWdtPs_WriteReg(InstancePtr->Config.BaseAddress, XWDTPS_ZMR_OFFSET,
173 * Indicate that the device is started.
175 InstancePtr->IsStarted = XIL_COMPONENT_IS_STARTED;
179 /****************************************************************************/
182 * Disable the watchdog timer.
184 * It is the caller's responsibility to disconnect the interrupt handler
185 * of the watchdog timer from the interrupt source, typically an interrupt
186 * controller, and disable the interrupt in the interrupt controller.
188 * @param InstancePtr is a pointer to the XWdtPs instance.
194 ******************************************************************************/
195 void XWdtPs_Stop(XWdtPs *InstancePtr)
199 Xil_AssertVoid(InstancePtr != NULL);
200 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
203 * Read the contents of the ZMR register.
205 Register = XWdtPs_ReadReg(InstancePtr->Config.BaseAddress,
209 * Disable the Timer field in the register and
210 * Set the access key for the write to be done the register.
212 Register &= (u32)(~XWDTPS_ZMR_WDEN_MASK);
213 Register |= XWDTPS_ZMR_ZKEY_VAL;
216 * Update the ZMR with the new value.
218 XWdtPs_WriteReg(InstancePtr->Config.BaseAddress, XWDTPS_ZMR_OFFSET,
221 InstancePtr->IsStarted = 0U;
225 /****************************************************************************/
228 * Enables the indicated signal/output.
229 * Performs a read/modify/write cycle to update the value correctly.
231 * @param InstancePtr is a pointer to the XWdtPs instance.
232 * @param Signal is the desired signal/output.
233 * Valid Signal Values are XWDTPS_RESET_SIGNAL and
235 * Only one of them can be specified at a time.
241 ******************************************************************************/
242 void XWdtPs_EnableOutput(XWdtPs *InstancePtr, u8 Signal)
246 Xil_AssertVoid(InstancePtr != NULL);
247 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
248 Xil_AssertVoid((Signal == XWDTPS_RESET_SIGNAL) ||
249 (Signal == XWDTPS_IRQ_SIGNAL));
252 * Read the contents of the ZMR register.
254 Register = XWdtPs_ReadReg(InstancePtr->Config.BaseAddress,
257 if (Signal == XWDTPS_RESET_SIGNAL) {
259 * Enable the field in the register.
261 Register |= XWDTPS_ZMR_RSTEN_MASK;
263 } else if (Signal == XWDTPS_IRQ_SIGNAL) {
265 * Enable the field in the register.
267 Register |= XWDTPS_ZMR_IRQEN_MASK;
270 /* Else was made for misra-c compliance */
275 * Set the access key so the write takes.
277 Register |= XWDTPS_ZMR_ZKEY_VAL;
280 * Update the ZMR with the new value.
282 XWdtPs_WriteReg(InstancePtr->Config.BaseAddress, XWDTPS_ZMR_OFFSET,
286 /****************************************************************************/
289 * Disables the indicated signal/output.
290 * Performs a read/modify/write cycle to update the value correctly.
292 * @param InstancePtr is a pointer to the XWdtPs instance.
293 * @param Signal is the desired signal/output.
294 * Valid Signal Values are XWDTPS_RESET_SIGNAL and
296 * Only one of them can be specified at a time.
302 ******************************************************************************/
303 void XWdtPs_DisableOutput(XWdtPs *InstancePtr, u8 Signal)
307 Xil_AssertVoid(InstancePtr != NULL);
308 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
309 Xil_AssertVoid((Signal == XWDTPS_RESET_SIGNAL) ||
310 (Signal == XWDTPS_IRQ_SIGNAL));
313 * Read the contents of the ZMR register.
315 Register = XWdtPs_ReadReg(InstancePtr->Config.BaseAddress,
318 if (Signal == XWDTPS_RESET_SIGNAL) {
320 * Disable the field in the register.
322 Register &= (u32)(~XWDTPS_ZMR_RSTEN_MASK);
324 } else if (Signal == XWDTPS_IRQ_SIGNAL) {
326 * Disable the field in the register.
328 Register &= (u32)(~XWDTPS_ZMR_IRQEN_MASK);
331 /* Else was made for misra-c compliance */
336 * Set the access key so the write takes place.
338 Register |= XWDTPS_ZMR_ZKEY_VAL;
341 * Update the ZMR with the new value.
343 XWdtPs_WriteReg(InstancePtr->Config.BaseAddress, XWDTPS_ZMR_OFFSET,
347 /****************************************************************************/
350 * Returns the current control setting for the indicated signal/output.
351 * The register referenced is the Counter Control Register (XWDTPS_CCR_OFFSET)
353 * @param InstancePtr is a pointer to the XWdtPs instance.
354 * @param Control is the desired signal/output.
355 * Valid Control Values are XWDTPS_CLK_PRESCALE and
356 * XWDTPS_COUNTER_RESET. Only one of them can be specified at a
359 * @return The contents of the requested control field in the Counter
360 * Control Register (XWDTPS_CCR_OFFSET).
361 * If the Control is XWDTPS_CLK_PRESCALE then use the
362 * defintions XWDTEPB_CCR_PSCALE_XXXX.
363 * If the Control is XWDTPS_COUNTER_RESET then the values are
364 * 0x0 to 0xFFF. This is the Counter Restart value in the CCR
369 ******************************************************************************/
370 u32 XWdtPs_GetControlValue(XWdtPs *InstancePtr, u8 Control)
373 u32 ReturnValue = 0U;
375 Xil_AssertNonvoid(InstancePtr != NULL);
376 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
377 Xil_AssertNonvoid((Control == XWDTPS_CLK_PRESCALE) ||
378 (Control == XWDTPS_COUNTER_RESET));
381 * Read the contents of the CCR register.
383 Register = XWdtPs_ReadReg(InstancePtr->Config.BaseAddress,
386 if (Control == XWDTPS_CLK_PRESCALE) {
388 * Mask off the field in the register.
390 ReturnValue = Register & XWDTPS_CCR_CLKSEL_MASK;
392 } else if (Control == XWDTPS_COUNTER_RESET) {
394 * Mask off the field in the register.
396 Register &= XWDTPS_CCR_CRV_MASK;
399 * Shift over to the right most positions.
401 ReturnValue = Register >> XWDTPS_CCR_CRV_SHIFT;
403 /* Else was made for misra-c compliance */
410 /****************************************************************************/
413 * Updates the current control setting for the indicated signal/output with
414 * the provided value.
416 * Performs a read/modify/write cycle to update the value correctly.
417 * The register referenced is the Counter Control Register (XWDTPS_CCR_OFFSET)
419 * @param InstancePtr is a pointer to the XWdtPs instance.
420 * @param Control is the desired signal/output.
421 * Valid Control Values are XWDTPS_CLK_PRESCALE and
422 * XWDTPS_COUNTER_RESET. Only one of them can be specified at a
424 * @param Value is the desired control value.
425 * If the Control is XWDTPS_CLK_PRESCALE then use the
426 * defintions XWDTEPB_CCR_PSCALE_XXXX.
427 * If the Control is XWDTPS_COUNTER_RESET then the valid values
428 * are 0x0 to 0xFFF, this sets the counter restart value of the CCR
435 ******************************************************************************/
436 void XWdtPs_SetControlValue(XWdtPs *InstancePtr, u8 Control, u32 Value)
439 u32 LocalValue = Value;
441 Xil_AssertVoid(InstancePtr != NULL);
442 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
443 Xil_AssertVoid((Control == XWDTPS_CLK_PRESCALE) ||
444 (Control == XWDTPS_COUNTER_RESET));
447 * Read the contents of the CCR register.
449 Register = XWdtPs_ReadReg(InstancePtr->Config.BaseAddress,
452 if (Control == XWDTPS_CLK_PRESCALE) {
454 * Zero the field in the register.
456 Register &= (u32)(~XWDTPS_CCR_CLKSEL_MASK);
458 } else if (Control == XWDTPS_COUNTER_RESET) {
460 * Zero the field in the register.
462 Register &= (u32)(~XWDTPS_CCR_CRV_MASK);
465 * Shift Value over to the proper positions.
467 LocalValue = LocalValue << XWDTPS_CCR_CRV_SHIFT;
469 /* This was made for misrac compliance. */
473 Register |= LocalValue;
476 * Set the access key so the write takes.
478 Register |= XWDTPS_CCR_CKEY_VAL;
481 * Update the CCR with the new value.
483 XWdtPs_WriteReg(InstancePtr->Config.BaseAddress, XWDTPS_CCR_OFFSET,