1 /******************************************************************************
3 * Copyright (C) 2004 - 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 xemaclite_selftest.c
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.
42 * MODIFICATION HISTORY:
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.
50 ******************************************************************************/
52 /***************************** Include Files *********************************/
55 #include "xemaclite.h"
56 #include "xemaclite_i.h"
58 /************************** Constant Definitions *****************************/
60 /**************************** Type Definitions *******************************/
62 /***************** Macros (Inline Functions) Definitions *********************/
64 /************************** Function Prototypes ******************************/
66 /************************** Variable Definitions *****************************/
68 /*****************************************************************************/
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.
78 * @param InstancePtr is a pointer to the XEmacLite instance .
81 * - XST_SUCCESS if the device Passed the Self Test.
82 * - XST_FAILURE if any of the data read backs fail.
86 ******************************************************************************/
87 int XEmacLite_SelfTest(XEmacLite * InstancePtr)
91 u8 TestString[4] = { 0xDE, 0xAD, 0xBE, 0xEF };
92 u8 ReturnString[4] = { 0x0, 0x0, 0x0, 0x0 };
95 * Verify that each of the inputs are valid.
97 Xil_AssertNonvoid(InstancePtr != NULL);
100 * Determine the TX buffer address
102 BaseAddress = InstancePtr->EmacLiteConfig.BaseAddress +
106 * Write the TestString to the TX buffer in EMAC Lite then
107 * back from the EMAC Lite and verify
109 XEmacLite_AlignedWrite(TestString, (u32 *) BaseAddress,
111 XEmacLite_AlignedRead((u32 *) BaseAddress, ReturnString,
112 sizeof(ReturnString));
114 for (Index = 0; Index < 4; Index++) {
116 if (ReturnString[Index] != TestString[Index]) {
121 * Zero the return string for the next test
123 ReturnString[Index] = 0;
127 * If the second buffer is configured, test it also
129 if (InstancePtr->EmacLiteConfig.TxPingPong != 0) {
130 BaseAddress += XEL_BUFFER_OFFSET;
132 * Write the TestString to the optional TX buffer in EMAC Lite
133 * then back from the EMAC Lite and verify
135 XEmacLite_AlignedWrite(TestString, (u32 *) BaseAddress,
137 XEmacLite_AlignedRead((u32 *) BaseAddress, ReturnString,
138 sizeof(ReturnString));
140 for (Index = 0; Index < 4; Index++) {
142 if (ReturnString[Index] != TestString[Index]) {
147 * Zero the return string for the next test
149 ReturnString[Index] = 0;
154 * Determine the RX buffer address
156 BaseAddress = InstancePtr->EmacLiteConfig.BaseAddress +
160 * Write the TestString to the RX buffer in EMAC Lite then
161 * back from the EMAC Lite and verify
163 XEmacLite_AlignedWrite(TestString, (u32 *) (BaseAddress),
165 XEmacLite_AlignedRead((u32 *) (BaseAddress), ReturnString,
166 sizeof(ReturnString));
168 for (Index = 0; Index < 4; Index++) {
170 if (ReturnString[Index] != TestString[Index]) {
175 * Zero the return string for the next test
177 ReturnString[Index] = 0;
181 * If the second buffer is configured, test it also
183 if (InstancePtr->EmacLiteConfig.RxPingPong != 0) {
184 BaseAddress += XEL_BUFFER_OFFSET;
186 * Write the TestString to the optional RX buffer in EMAC Lite
187 * then back from the EMAC Lite and verify
189 XEmacLite_AlignedWrite(TestString, (u32 *) BaseAddress,
191 XEmacLite_AlignedRead((u32 *) BaseAddress, ReturnString,
192 sizeof(ReturnString));
194 for (Index = 0; Index < 4; Index++) {
196 if (ReturnString[Index] != TestString[Index]) {
201 * Zero the return string for the next test
203 ReturnString[Index] = 0;