1 /******************************************************************************
3 * Copyright (C) 2002 - 2014 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 /*****************************************************************************/
35 * @file xtmrctr_selftest.c
37 * Contains diagnostic/self-test functions for the XTmrCtr component.
40 * MODIFICATION HISTORY:
42 * Ver Who Date Changes
43 * ----- ---- -------- -----------------------------------------------
44 * 1.00b jhl 02/06/02 First release
45 * 1.10b mta 03/21/07 Updated to new coding style
46 * 2.00a ktn 10/30/09 Updated to use HAL API's. _m is removed from all the macro
50 ******************************************************************************/
52 /***************************** Include Files *********************************/
56 #include "xtmrctr_i.h"
58 /************************** Constant Definitions *****************************/
61 /**************************** Type Definitions *******************************/
64 /***************** Macros (Inline Functions) Definitions *********************/
67 /************************** Function Prototypes ******************************/
70 /************************** Variable Definitions *****************************/
73 /*****************************************************************************/
76 * Runs a self-test on the driver/device. This test verifies that the specified
77 * timer counter of the device can be enabled and increments.
79 * @param InstancePtr is a pointer to the XTmrCtr instance.
80 * @param TmrCtrNumber is the timer counter of the device to operate on.
81 * Each device may contain multiple timer counters. The timer
82 * number is a zero based number with a range of
83 * 0 - (XTC_DEVICE_TIMER_COUNT - 1).
86 * - XST_SUCCESS if self-test was successful
87 * - XST_FAILURE if the timer is not incrementing.
91 * This is a destructive test using the provided timer. The current settings
92 * of the timer are returned to the initialized values and all settings at the
93 * time this function is called are overwritten.
95 ******************************************************************************/
96 int XTmrCtr_SelfTest(XTmrCtr * InstancePtr, u8 TmrCtrNumber)
102 Xil_AssertNonvoid(InstancePtr != NULL);
103 Xil_AssertNonvoid(TmrCtrNumber < XTC_DEVICE_TIMER_COUNT);
104 Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
107 * Set the Capture register to 0
109 XTmrCtr_WriteReg(InstancePtr->BaseAddress, TmrCtrNumber,
113 * Reset the timer and the interrupt
115 XTmrCtr_WriteReg(InstancePtr->BaseAddress, TmrCtrNumber,
117 XTC_CSR_INT_OCCURED_MASK | XTC_CSR_LOAD_MASK);
120 * Set the control/status register to enable timer
122 XTmrCtr_WriteReg(InstancePtr->BaseAddress, TmrCtrNumber,
123 XTC_TCSR_OFFSET, XTC_CSR_ENABLE_TMR_MASK);
128 TimerCount1 = XTmrCtr_ReadReg(InstancePtr->BaseAddress,
129 TmrCtrNumber, XTC_TCR_OFFSET);
131 * Make sure timer is incrementing if the Count rolls over to zero
132 * and the timer still has not incremented an error is returned
136 TimerCount2 = XTmrCtr_ReadReg(InstancePtr->BaseAddress,
137 TmrCtrNumber, XTC_TCR_OFFSET);
140 while ((TimerCount1 == TimerCount2) && (Count != 0));
143 * Reset the timer and the interrupt
145 XTmrCtr_WriteReg(InstancePtr->BaseAddress, TmrCtrNumber,
147 XTC_CSR_INT_OCCURED_MASK | XTC_CSR_LOAD_MASK);
150 * Set the control/status register to 0 to complete initialization
151 * this disables the timer completely and allows it to be used again
154 XTmrCtr_WriteReg(InstancePtr->BaseAddress, TmrCtrNumber,
157 if (TimerCount1 == TimerCount2) {