]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MicroBlaze_Kintex7_EthernetLite/BSP/microblaze_0/libsrc/tmrctr_v3_0/src/xtmrctr_selftest.c
Update some more standard demos for use on 64-bit architectures.
[freertos] / FreeRTOS / Demo / MicroBlaze_Kintex7_EthernetLite / BSP / microblaze_0 / libsrc / tmrctr_v3_0 / src / xtmrctr_selftest.c
1 /******************************************************************************
2 *
3 * Copyright (C) 2002 - 2014 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 xtmrctr_selftest.c
36 *
37 * Contains diagnostic/self-test functions for the XTmrCtr component.
38 *
39 * <pre>
40 * MODIFICATION HISTORY:
41 *
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
47 *                     definitions.
48 * </pre>
49 *
50 ******************************************************************************/
51
52 /***************************** Include Files *********************************/
53
54 #include "xil_io.h"
55 #include "xtmrctr.h"
56 #include "xtmrctr_i.h"
57
58 /************************** Constant Definitions *****************************/
59
60
61 /**************************** Type Definitions *******************************/
62
63
64 /***************** Macros (Inline Functions) Definitions *********************/
65
66
67 /************************** Function Prototypes ******************************/
68
69
70 /************************** Variable Definitions *****************************/
71
72
73 /*****************************************************************************/
74 /**
75 *
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.
78 *
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).
84 *
85 * @return
86 *               - XST_SUCCESS if self-test was successful
87 *               - XST_FAILURE if the timer is not incrementing.
88 *
89 * @note
90 *
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.
94 *
95 ******************************************************************************/
96 int XTmrCtr_SelfTest(XTmrCtr * InstancePtr, u8 TmrCtrNumber)
97 {
98         u32 TimerCount1 = 0;
99         u32 TimerCount2 = 0;
100         u16 Count = 0;
101
102         Xil_AssertNonvoid(InstancePtr != NULL);
103         Xil_AssertNonvoid(TmrCtrNumber < XTC_DEVICE_TIMER_COUNT);
104         Xil_AssertNonvoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
105
106         /*
107          * Set the Capture register to 0
108          */
109         XTmrCtr_WriteReg(InstancePtr->BaseAddress, TmrCtrNumber,
110                           XTC_TLR_OFFSET, 0);
111
112         /*
113          * Reset the timer and the interrupt
114          */
115         XTmrCtr_WriteReg(InstancePtr->BaseAddress, TmrCtrNumber,
116                           XTC_TCSR_OFFSET,
117                           XTC_CSR_INT_OCCURED_MASK | XTC_CSR_LOAD_MASK);
118
119         /*
120          * Set the control/status register to enable timer
121          */
122         XTmrCtr_WriteReg(InstancePtr->BaseAddress, TmrCtrNumber,
123                           XTC_TCSR_OFFSET, XTC_CSR_ENABLE_TMR_MASK);
124
125         /*
126          * Read the timer
127          */
128         TimerCount1 = XTmrCtr_ReadReg(InstancePtr->BaseAddress,
129                                          TmrCtrNumber, XTC_TCR_OFFSET);
130         /*
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
133          */
134
135         do {
136                 TimerCount2 = XTmrCtr_ReadReg(InstancePtr->BaseAddress,
137                                                  TmrCtrNumber, XTC_TCR_OFFSET);
138                 Count++;
139         }
140         while ((TimerCount1 == TimerCount2) && (Count != 0));
141
142         /*
143          * Reset the timer and the interrupt
144          */
145         XTmrCtr_WriteReg(InstancePtr->BaseAddress, TmrCtrNumber,
146                           XTC_TCSR_OFFSET,
147                           XTC_CSR_INT_OCCURED_MASK | XTC_CSR_LOAD_MASK);
148
149         /*
150          * Set the control/status register to 0 to complete initialization
151          * this disables the timer completely and allows it to be used again
152          */
153
154         XTmrCtr_WriteReg(InstancePtr->BaseAddress, TmrCtrNumber,
155                           XTC_TCSR_OFFSET, 0);
156
157         if (TimerCount1 == TimerCount2) {
158                 return XST_FAILURE;
159         }
160         else {
161                 return XST_SUCCESS;
162         }
163 }