/** * * Send an Ethernet frame. The size is the total frame size, including header. * This function blocks waiting for the frame to be transmitted. * * @param BaseAddress is the base address of the device * @param FramePtr is a pointer to frame * @param ByteCount is the size, in bytes, of the frame * * @return * * None. * * @note * * This function call is blocking in nature, i.e. it will wait until the * frame is transmitted. This function can hang and not exit if the * hardware is not configured properly. * * If the ping buffer is the destination of the data, the argument should be * DeviceAddress + XEL_TXBUFF_OFFSET. * If the pong buffer is the destination of the data, the argument should be * DeviceAddress + XEL_TXBUFF_OFFSET + XEL_BUFFER_OFFSET. * The function does not take the different buffers into consideration. ******************************************************************************/ void XEmacLite_SendFrame(u32 BaseAddress, u8 *FramePtr, unsigned ByteCount) { u32 Register; /* * Write data to the EMAC Lite */ XEmacLite_AlignedWrite(FramePtr, (u32 *) (BaseAddress), ByteCount); /* * The frame is in the buffer, now send it */ XIo_Out32(BaseAddress + XEL_TPLR_OFFSET, (ByteCount & (XEL_TPLR_LENGTH_MASK_HI | XEL_TPLR_LENGTH_MASK_LO))); Register = XIo_In32(BaseAddress + XEL_TSR_OFFSET); XIo_Out32(BaseAddress + XEL_TSR_OFFSET, (Register | XEL_TSR_XMIT_BUSY_MASK)); /* * Loop on the status waiting for the transmit to be complete. */ // while (!XEmacLite_mIsTxDone(BaseAddress)); }
/** * * Performs a SelfTest on the EmacLite device as follows: * - Writes to the mandatory TX buffer and reads back to verify. * - If configured, writes to the secondary TX buffer and reads back to verify. * - Writes to the mandatory RX buffer and reads back to verify. * - If configured, writes to the secondary RX buffer and reads back to verify. * * * @param InstancePtr is a pointer to the XEmacLite instance to be worked on. * * @return * * - XST_SUCCESS if the device Passed the Self Test. * - XST_FAILURE if any of the data read backs fail. * * @note * * None. * ******************************************************************************/ XStatus XEmacLite_SelfTest(XEmacLite *InstancePtr) { u32 BaseAddress; u8 i; u8 TestString[4] = {0xDE, 0xAD, 0xBE, 0xEF}; u8 ReturnString[4] = {0x0, 0x0, 0x0, 0x0}; /* * Verify that each of the inputs are valid. */ XASSERT_NONVOID(InstancePtr != NULL); /* * Determine the TX buffer address */ BaseAddress = InstancePtr->BaseAddress + XEL_TXBUFF_OFFSET; /* * Write the TestString to the TX buffer in EMAC Lite then * back from the EMAC Lite and verify */ XEmacLite_AlignedWrite(TestString, (u32 *) BaseAddress, sizeof(TestString)); XEmacLite_AlignedRead((u32 *) BaseAddress, ReturnString, sizeof(ReturnString)); for (i=0; i < 4; i++) { if (ReturnString[i] != TestString[i]) { return XST_FAILURE; } /* * Zero thge return string for the next test */ ReturnString[i] = 0; } /* * If the second buffer is configured, test it also */ if (InstancePtr->ConfigPtr->TxPingPong != 0) { BaseAddress += XEL_BUFFER_OFFSET; /* * Write the TestString to the optional TX buffer in EMAC Lite then * back from the EMAC Lite and verify */ XEmacLite_AlignedWrite(TestString, (u32 *) BaseAddress, sizeof(TestString)); XEmacLite_AlignedRead((u32 *) BaseAddress, ReturnString, sizeof(ReturnString)); for (i=0; i < 4; i++) { if (ReturnString[i] != TestString[i]) { return XST_FAILURE; } /* * Zero thge return string for the next test */ ReturnString[i] = 0; } } /* * Determine the RX buffer address */ BaseAddress = InstancePtr->BaseAddress + XEL_RXBUFF_OFFSET; /* * Write the TestString to the RX buffer in EMAC Lite then * back from the EMAC Lite and verify */ XEmacLite_AlignedWrite(TestString, (u32 *) (BaseAddress), sizeof(TestString)); XEmacLite_AlignedRead((u32 *) (BaseAddress), ReturnString, sizeof(ReturnString)); for (i=0; i < 4; i++) { if (ReturnString[i] != TestString[i]) { return XST_FAILURE; } /* * Zero thge return string for the next test */ ReturnString[i] = 0; } /* * If the second buffer is configured, test it also */ if (InstancePtr->ConfigPtr->RxPingPong != 0) { BaseAddress += XEL_BUFFER_OFFSET; /* * Write the TestString to the optional RX buffer in EMAC Lite then * back from the EMAC Lite and verify */ XEmacLite_AlignedWrite(TestString, (u32 *) BaseAddress, sizeof(TestString)); XEmacLite_AlignedRead((u32 *) BaseAddress, ReturnString, sizeof(ReturnString)); for (i=0; i < 4; i++) { if (ReturnString[i] != TestString[i]) { return XST_FAILURE; } /* * Zero thge return string for the next test */ ReturnString[i] = 0; } } return XST_SUCCESS; }
/** * * Performs a SelfTest on the EmacLite device as follows: * - Writes to the mandatory TX buffer and reads back to verify. * - If configured, writes to the secondary TX buffer and reads back to verify. * - Writes to the mandatory RX buffer and reads back to verify. * - If configured, writes to the secondary RX buffer and reads back to verify. * * * @param InstancePtr is a pointer to the XEmacLite instance . * * @return * - XST_SUCCESS if the device Passed the Self Test. * - XST_FAILURE if any of the data read backs fail. * * @note None. * ******************************************************************************/ int XEmacLite_SelfTest(XEmacLite * InstancePtr) { UINTPTR BaseAddress; u8 Index; u8 TestString[4] = { 0xDE, 0xAD, 0xBE, 0xEF }; u8 ReturnString[4] = { 0x0, 0x0, 0x0, 0x0 }; /* * Verify that each of the inputs are valid. */ Xil_AssertNonvoid(InstancePtr != NULL); /* * Determine the TX buffer address */ BaseAddress = InstancePtr->EmacLiteConfig.BaseAddress + XEL_TXBUFF_OFFSET; /* * Write the TestString to the TX buffer in EMAC Lite then * back from the EMAC Lite and verify */ XEmacLite_AlignedWrite(TestString, (UINTPTR *) BaseAddress, sizeof(TestString)); XEmacLite_AlignedRead((UINTPTR *) BaseAddress, ReturnString, sizeof(ReturnString)); for (Index = 0; Index < 4; Index++) { if (ReturnString[Index] != TestString[Index]) { return XST_FAILURE; } /* * Zero the return string for the next test */ ReturnString[Index] = 0; } /* * If the second buffer is configured, test it also */ if (InstancePtr->EmacLiteConfig.TxPingPong != 0) { BaseAddress += XEL_BUFFER_OFFSET; /* * Write the TestString to the optional TX buffer in EMAC Lite * then back from the EMAC Lite and verify */ XEmacLite_AlignedWrite(TestString, (UINTPTR *) BaseAddress, sizeof(TestString)); XEmacLite_AlignedRead((UINTPTR *) BaseAddress, ReturnString, sizeof(ReturnString)); for (Index = 0; Index < 4; Index++) { if (ReturnString[Index] != TestString[Index]) { return XST_FAILURE; } /* * Zero the return string for the next test */ ReturnString[Index] = 0; } } /* * Determine the RX buffer address */ BaseAddress = InstancePtr->EmacLiteConfig.BaseAddress + XEL_RXBUFF_OFFSET; /* * Write the TestString to the RX buffer in EMAC Lite then * back from the EMAC Lite and verify */ XEmacLite_AlignedWrite(TestString, (UINTPTR *) (BaseAddress), sizeof(TestString)); XEmacLite_AlignedRead((UINTPTR *) (BaseAddress), ReturnString, sizeof(ReturnString)); for (Index = 0; Index < 4; Index++) { if (ReturnString[Index] != TestString[Index]) { return XST_FAILURE; } /* * Zero the return string for the next test */ ReturnString[Index] = 0; } /* * If the second buffer is configured, test it also */ if (InstancePtr->EmacLiteConfig.RxPingPong != 0) { BaseAddress += XEL_BUFFER_OFFSET; /* * Write the TestString to the optional RX buffer in EMAC Lite * then back from the EMAC Lite and verify */ XEmacLite_AlignedWrite(TestString, (UINTPTR *) BaseAddress, sizeof(TestString)); XEmacLite_AlignedRead((UINTPTR *) BaseAddress, ReturnString, sizeof(ReturnString)); for (Index = 0; Index < 4; Index++) { if (ReturnString[Index] != TestString[Index]) { return XST_FAILURE; } /* * Zero the return string for the next test */ ReturnString[Index] = 0; } } return XST_SUCCESS; }