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 * Contains the implementation of interface functions of the XWdtPs driver.
38 * See xwdtps.h for a description of the driver.
41 * MODIFICATION HISTORY:
43 * Ver Who Date Changes
44 * ----- ------ -------- ---------------------------------------------
45 * 1.00a ecm/jz 01/15/10 First release
46 * 1.02a sg 07/15/12 Removed code/APIs related to External Signal
47 * Length functionality for CR 658287
48 * Removed APIs XWdtPs_SetExternalSignalLength,
49 * XWdtPs_GetExternalSignalLength
50 * 3.00 kvn 02/13/15 Modified code for MISRA-C:2012 compliance.
53 ******************************************************************************/
55 /***************************** Include Files *********************************/
59 /************************** Constant Definitions *****************************/
62 /**************************** Type Definitions *******************************/
65 /***************** Macros (Inline Functions) Definitions *********************/
68 /************************** Function Prototypes ******************************/
71 /************************** Variable Definitions *****************************/
74 /****************************************************************************/
77 * Initialize a specific watchdog timer instance/driver. This function
78 * must be called before other functions of the driver are called.
80 * @param InstancePtr is a pointer to the XWdtPs instance.
81 * @param ConfigPtr is the config structure.
82 * @param EffectiveAddress is the base address for the device. It could be
83 * a virtual address if address translation is supported in the
84 * system, otherwise it is the physical address.
87 * - XST_SUCCESS if initialization was successful.
88 * - XST_DEVICE_IS_STARTED if the device has already been started.
92 ******************************************************************************/
93 s32 XWdtPs_CfgInitialize(XWdtPs *InstancePtr,
94 XWdtPs_Config *ConfigPtr, u32 EffectiveAddress)
97 Xil_AssertNonvoid(InstancePtr != NULL);
98 Xil_AssertNonvoid(ConfigPtr != NULL);
101 * If the device is started, disallow the initialize and return a
102 * status indicating it is started. This allows the user to stop the
103 * device and reinitialize, but prevents a user from inadvertently
106 if (InstancePtr->IsStarted == XIL_COMPONENT_IS_STARTED) {
107 Status = XST_DEVICE_IS_STARTED;
111 * Copy configuration into instance.
113 InstancePtr->Config.DeviceId = ConfigPtr->DeviceId;
116 * Save the base address pointer such that the registers of the block
117 * can be accessed and indicate it has not been started yet.
119 InstancePtr->Config.BaseAddress = EffectiveAddress;
120 InstancePtr->IsStarted = 0U;
123 * Indicate the instance is ready to use, successfully initialized.
125 InstancePtr->IsReady = XIL_COMPONENT_IS_READY;
127 Status = XST_SUCCESS;
132 /****************************************************************************/
135 * Start the watchdog timer of the device.
137 * @param InstancePtr is a pointer to the XWdtPs instance.
143 ******************************************************************************/
144 void XWdtPs_Start(XWdtPs *InstancePtr)
148 Xil_AssertVoid(InstancePtr != NULL);
149 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
152 * Read the contents of the ZMR register.
154 Register = XWdtPs_ReadReg(InstancePtr->Config.BaseAddress,
158 * Enable the Timer field in the register and Set the access key so the
161 Register |= XWDTPS_ZMR_WDEN_MASK;
162 Register |= XWDTPS_ZMR_ZKEY_VAL;
165 * Update the ZMR with the new value.
167 XWdtPs_WriteReg(InstancePtr->Config.BaseAddress, XWDTPS_ZMR_OFFSET,
171 * Indicate that the device is started.
173 InstancePtr->IsStarted = XIL_COMPONENT_IS_STARTED;
177 /****************************************************************************/
180 * Disable the watchdog timer.
182 * It is the caller's responsibility to disconnect the interrupt handler
183 * of the watchdog timer from the interrupt source, typically an interrupt
184 * controller, and disable the interrupt in the interrupt controller.
186 * @param InstancePtr is a pointer to the XWdtPs instance.
192 ******************************************************************************/
193 void XWdtPs_Stop(XWdtPs *InstancePtr)
197 Xil_AssertVoid(InstancePtr != NULL);
198 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
201 * Read the contents of the ZMR register.
203 Register = XWdtPs_ReadReg(InstancePtr->Config.BaseAddress,
207 * Disable the Timer field in the register and
208 * Set the access key for the write to be done the register.
210 Register &= (u32)(~XWDTPS_ZMR_WDEN_MASK);
211 Register |= XWDTPS_ZMR_ZKEY_VAL;
214 * Update the ZMR with the new value.
216 XWdtPs_WriteReg(InstancePtr->Config.BaseAddress, XWDTPS_ZMR_OFFSET,
219 InstancePtr->IsStarted = 0U;
223 /****************************************************************************/
226 * Enables the indicated signal/output.
227 * Performs a read/modify/write cycle to update the value correctly.
229 * @param InstancePtr is a pointer to the XWdtPs instance.
230 * @param Signal is the desired signal/output.
231 * Valid Signal Values are XWDTPS_RESET_SIGNAL and
233 * Only one of them can be specified at a time.
239 ******************************************************************************/
240 void XWdtPs_EnableOutput(XWdtPs *InstancePtr, u8 Signal)
244 Xil_AssertVoid(InstancePtr != NULL);
245 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
246 Xil_AssertVoid((Signal == XWDTPS_RESET_SIGNAL) ||
247 (Signal == XWDTPS_IRQ_SIGNAL));
250 * Read the contents of the ZMR register.
252 Register = XWdtPs_ReadReg(InstancePtr->Config.BaseAddress,
255 if (Signal == XWDTPS_RESET_SIGNAL) {
257 * Enable the field in the register.
259 Register |= XWDTPS_ZMR_RSTEN_MASK;
261 } else if (Signal == XWDTPS_IRQ_SIGNAL) {
263 * Enable the field in the register.
265 Register |= XWDTPS_ZMR_IRQEN_MASK;
268 /* Else was made for misra-c compliance */
273 * Set the access key so the write takes.
275 Register |= XWDTPS_ZMR_ZKEY_VAL;
278 * Update the ZMR with the new value.
280 XWdtPs_WriteReg(InstancePtr->Config.BaseAddress, XWDTPS_ZMR_OFFSET,
284 /****************************************************************************/
287 * Disables the indicated signal/output.
288 * Performs a read/modify/write cycle to update the value correctly.
290 * @param InstancePtr is a pointer to the XWdtPs instance.
291 * @param Signal is the desired signal/output.
292 * Valid Signal Values are XWDTPS_RESET_SIGNAL and
294 * Only one of them can be specified at a time.
300 ******************************************************************************/
301 void XWdtPs_DisableOutput(XWdtPs *InstancePtr, u8 Signal)
305 Xil_AssertVoid(InstancePtr != NULL);
306 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
307 Xil_AssertVoid((Signal == XWDTPS_RESET_SIGNAL) ||
308 (Signal == XWDTPS_IRQ_SIGNAL));
311 * Read the contents of the ZMR register.
313 Register = XWdtPs_ReadReg(InstancePtr->Config.BaseAddress,
316 if (Signal == XWDTPS_RESET_SIGNAL) {
318 * Disable the field in the register.
320 Register &= (u32)(~XWDTPS_ZMR_RSTEN_MASK);
322 } else if (Signal == XWDTPS_IRQ_SIGNAL) {
324 * Disable the field in the register.
326 Register &= (u32)(~XWDTPS_ZMR_IRQEN_MASK);
329 /* Else was made for misra-c compliance */
334 * Set the access key so the write takes place.
336 Register |= XWDTPS_ZMR_ZKEY_VAL;
339 * Update the ZMR with the new value.
341 XWdtPs_WriteReg(InstancePtr->Config.BaseAddress, XWDTPS_ZMR_OFFSET,
345 /****************************************************************************/
348 * Returns the current control setting for the indicated signal/output.
349 * The register referenced is the Counter Control Register (XWDTPS_CCR_OFFSET)
351 * @param InstancePtr is a pointer to the XWdtPs instance.
352 * @param Control is the desired signal/output.
353 * Valid Control Values are XWDTPS_CLK_PRESCALE and
354 * XWDTPS_COUNTER_RESET. Only one of them can be specified at a
357 * @return The contents of the requested control field in the Counter
358 * Control Register (XWDTPS_CCR_OFFSET).
359 * If the Control is XWDTPS_CLK_PRESCALE then use the
360 * defintions XWDTEPB_CCR_PSCALE_XXXX.
361 * If the Control is XWDTPS_COUNTER_RESET then the values are
362 * 0x0 to 0xFFF. This is the Counter Restart value in the CCR
367 ******************************************************************************/
368 u32 XWdtPs_GetControlValue(XWdtPs *InstancePtr, u8 Control)
371 u32 ReturnValue = 0U;
373 Xil_AssertNonvoid(InstancePtr != NULL);
374 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
375 Xil_AssertNonvoid((Control == XWDTPS_CLK_PRESCALE) ||
376 (Control == XWDTPS_COUNTER_RESET));
379 * Read the contents of the CCR register.
381 Register = XWdtPs_ReadReg(InstancePtr->Config.BaseAddress,
384 if (Control == XWDTPS_CLK_PRESCALE) {
386 * Mask off the field in the register.
388 ReturnValue = Register & XWDTPS_CCR_CLKSEL_MASK;
390 } else if (Control == XWDTPS_COUNTER_RESET) {
392 * Mask off the field in the register.
394 Register &= XWDTPS_CCR_CRV_MASK;
397 * Shift over to the right most positions.
399 ReturnValue = Register >> XWDTPS_CCR_CRV_SHIFT;
401 /* Else was made for misra-c compliance */
408 /****************************************************************************/
411 * Updates the current control setting for the indicated signal/output with
412 * the provided value.
414 * Performs a read/modify/write cycle to update the value correctly.
415 * The register referenced is the Counter Control Register (XWDTPS_CCR_OFFSET)
417 * @param InstancePtr is a pointer to the XWdtPs instance.
418 * @param Control is the desired signal/output.
419 * Valid Control Values are XWDTPS_CLK_PRESCALE and
420 * XWDTPS_COUNTER_RESET. Only one of them can be specified at a
422 * @param Value is the desired control value.
423 * If the Control is XWDTPS_CLK_PRESCALE then use the
424 * defintions XWDTEPB_CCR_PSCALE_XXXX.
425 * If the Control is XWDTPS_COUNTER_RESET then the valid values
426 * are 0x0 to 0xFFF, this sets the counter restart value of the CCR
433 ******************************************************************************/
434 void XWdtPs_SetControlValue(XWdtPs *InstancePtr, u8 Control, u32 Value)
437 u32 LocalValue = Value;
439 Xil_AssertVoid(InstancePtr != NULL);
440 Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
441 Xil_AssertVoid((Control == XWDTPS_CLK_PRESCALE) ||
442 (Control == XWDTPS_COUNTER_RESET));
445 * Read the contents of the CCR register.
447 Register = XWdtPs_ReadReg(InstancePtr->Config.BaseAddress,
450 if (Control == XWDTPS_CLK_PRESCALE) {
452 * Zero the field in the register.
454 Register &= (u32)(~XWDTPS_CCR_CLKSEL_MASK);
456 } else if (Control == XWDTPS_COUNTER_RESET) {
458 * Zero the field in the register.
460 Register &= (u32)(~XWDTPS_CCR_CRV_MASK);
463 * Shift Value over to the proper positions.
465 LocalValue = LocalValue << XWDTPS_CCR_CRV_SHIFT;
467 /* This was made for misrac compliance. */
471 Register |= LocalValue;
474 * Set the access key so the write takes.
476 Register |= XWDTPS_CCR_CKEY_VAL;
479 * Update the CCR with the new value.
481 XWdtPs_WriteReg(InstancePtr->Config.BaseAddress, XWDTPS_CCR_OFFSET,