]> git.sur5r.net Git - freertos/blob
b8891b8146a6e82163c8311325b8db58758d78a9
[freertos] /
1 /******************************************************************************
2 *
3 * Copyright (C) 2004 - 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 xemaclite_selftest.c
36 *
37 * Function(s) in this file are the required functions for the EMAC Lite
38 * driver sefftest for the hardware.
39 * See xemaclite.h for a detailed description of the driver.
40 *
41 * <pre>
42 * MODIFICATION HISTORY:
43 *
44 * Ver   Who  Date     Changes
45 * ----- ---- -------- --------------------------------------------------------
46 * 1.01a ecm  01/31/04 First release
47 * 1.11a mta  03/21/07 Updated to new coding style
48 * 3.00a ktn  10/22/09 Updated driver to use the HAL Processor APIs/macros.
49 * </pre>
50 ******************************************************************************/
51
52 /***************************** Include Files *********************************/
53
54 #include "xil_io.h"
55 #include "xemaclite.h"
56 #include "xemaclite_i.h"
57
58 /************************** Constant Definitions *****************************/
59
60 /**************************** Type Definitions *******************************/
61
62 /***************** Macros (Inline Functions) Definitions *********************/
63
64 /************************** Function Prototypes ******************************/
65
66 /************************** Variable Definitions *****************************/
67
68 /*****************************************************************************/
69 /**
70 *
71 * Performs a SelfTest on the EmacLite device as follows:
72 *   - Writes to the mandatory TX buffer and reads back to verify.
73 *   - If configured, writes to the secondary TX buffer and reads back to verify.
74 *   - Writes to the mandatory RX buffer and reads back to verify.
75 *   - If configured, writes to the secondary RX buffer and reads back to verify.
76 *
77 *
78 * @param        InstancePtr is a pointer to the XEmacLite instance .
79 *
80 * @return
81 *               - XST_SUCCESS if the device Passed the Self Test.
82 *               - XST_FAILURE if any of the data read backs fail.
83 *
84 * @note         None.
85 *
86 ******************************************************************************/
87 int XEmacLite_SelfTest(XEmacLite * InstancePtr)
88 {
89         u32 BaseAddress;
90         u8 Index;
91         u8 TestString[4] = { 0xDE, 0xAD, 0xBE, 0xEF };
92         u8 ReturnString[4] = { 0x0, 0x0, 0x0, 0x0 };
93
94         /*
95          * Verify that each of the inputs are valid.
96          */
97         Xil_AssertNonvoid(InstancePtr != NULL);
98
99         /*
100          * Determine the TX buffer address
101          */
102         BaseAddress = InstancePtr->EmacLiteConfig.BaseAddress +
103                         XEL_TXBUFF_OFFSET;
104
105         /*
106          * Write the TestString to the TX buffer in EMAC Lite then
107          * back from the EMAC Lite and verify
108          */
109         XEmacLite_AlignedWrite(TestString, (u32 *) BaseAddress,
110                                sizeof(TestString));
111         XEmacLite_AlignedRead((u32 *) BaseAddress, ReturnString,
112                               sizeof(ReturnString));
113
114         for (Index = 0; Index < 4; Index++) {
115
116                 if (ReturnString[Index] != TestString[Index]) {
117                         return XST_FAILURE;
118                 }
119
120                 /*
121                  * Zero the return string for the next test
122                  */
123                 ReturnString[Index] = 0;
124         }
125
126         /*
127          * If the second buffer is configured, test it also
128          */
129         if (InstancePtr->EmacLiteConfig.TxPingPong != 0) {
130                 BaseAddress += XEL_BUFFER_OFFSET;
131                 /*
132                  * Write the TestString to the optional TX buffer in EMAC Lite
133                  * then back from the EMAC Lite and verify
134                  */
135                 XEmacLite_AlignedWrite(TestString, (u32 *) BaseAddress,
136                                        sizeof(TestString));
137                 XEmacLite_AlignedRead((u32 *) BaseAddress, ReturnString,
138                                       sizeof(ReturnString));
139
140                 for (Index = 0; Index < 4; Index++) {
141
142                         if (ReturnString[Index] != TestString[Index]) {
143                                 return XST_FAILURE;
144                         }
145
146                         /*
147                          * Zero the return string for the next test
148                          */
149                         ReturnString[Index] = 0;
150                 }
151         }
152
153         /*
154          * Determine the RX buffer address
155          */
156         BaseAddress = InstancePtr->EmacLiteConfig.BaseAddress +
157                                 XEL_RXBUFF_OFFSET;
158
159         /*
160          * Write the TestString to the RX buffer in EMAC Lite then
161          * back from the EMAC Lite and verify
162          */
163         XEmacLite_AlignedWrite(TestString, (u32 *) (BaseAddress),
164                                sizeof(TestString));
165         XEmacLite_AlignedRead((u32 *) (BaseAddress), ReturnString,
166                               sizeof(ReturnString));
167
168         for (Index = 0; Index < 4; Index++) {
169
170                 if (ReturnString[Index] != TestString[Index]) {
171                         return XST_FAILURE;
172                 }
173
174                 /*
175                  * Zero the return string for the next test
176                  */
177                 ReturnString[Index] = 0;
178         }
179
180         /*
181          * If the second buffer is configured, test it also
182          */
183         if (InstancePtr->EmacLiteConfig.RxPingPong != 0) {
184                 BaseAddress += XEL_BUFFER_OFFSET;
185                 /*
186                  * Write the TestString to the optional RX buffer in EMAC Lite
187                  * then back from the EMAC Lite and verify
188                  */
189                 XEmacLite_AlignedWrite(TestString, (u32 *) BaseAddress,
190                                        sizeof(TestString));
191                 XEmacLite_AlignedRead((u32 *) BaseAddress, ReturnString,
192                                       sizeof(ReturnString));
193
194                 for (Index = 0; Index < 4; Index++) {
195
196                         if (ReturnString[Index] != TestString[Index]) {
197                                 return XST_FAILURE;
198                         }
199
200                         /*
201                          * Zero the return string for the next test
202                          */
203                         ReturnString[Index] = 0;
204                 }
205         }
206
207         return XST_SUCCESS;
208 }