Ejemplo n.º 1
0
/**
*
* Receive a frame. Wait for a frame to arrive.
*
* @param BaseAddress is the base address of the device
* @param FramePtr is a pointer to a buffer where the frame will
*        be stored.
*
* @return
*
* The type/length field of the frame received.  When the type/length field
* contains the type , XEL_MAX_FRAME_SIZE bytes will be copied out of the
* buffer and it is up to the higher layers to sort out the frame.
*
* @note
*
* This function call is blocking in nature, i.e. it will wait until a
* frame arrives.
*
* If the ping buffer is the source of the data, the argument should be
* DeviceAddress + XEL_RXBUFF_OFFSET.
* If the pong buffer is the source of the data, the argument should be
* DeviceAddress + XEL_RXBUFF_OFFSET + XEL_BUFFER_OFFSET.
* The function does not take the different buffers into consideration.
******************************************************************************/
u16 XEmacLite_RecvFrame(u32 BaseAddress, u8 *FramePtr)
{
    u16 LengthType;
    u16 Length;
    u32 Register;

    /*
     * Wait for a frame to arrive - this is a blocking call
     */

    while (XEmacLite_mIsRxEmpty(BaseAddress));

    /*
     * Get the length of the frame that arrived
     */
    LengthType = XIo_In32(BaseAddress + XEL_RPLR_OFFSET);
    LengthType &= (XEL_RPLR_LENGTH_MASK_HI | XEL_RPLR_LENGTH_MASK_LO);

    /* check if length is valid */

    if (LengthType > XEL_MAX_FRAME_SIZE)
    {
        /* Field contain type, use max frame size and let user parse it */
        Length = XEL_MAX_FRAME_SIZE;
    }
    else
    {
        /* Use the length in the frame, plus the header and trailer */
        Length = LengthType + XEL_HEADER_SIZE + XEL_FCS_SIZE;
    }

    /*
     * Read each byte from the EMAC Lite
     */
    XEmacLite_AlignedRead((u32 *) (BaseAddress + XEL_RXBUFF_OFFSET),
                          FramePtr, Length);

    /*
     * Acknowledge the frame
     */

    Register = XIo_In32(BaseAddress + XEL_RSR_OFFSET);
    Register &= ~XEL_RSR_RECV_DONE_MASK;
    XIo_Out32(BaseAddress + XEL_RSR_OFFSET, Register);

    return LengthType;
}
Ejemplo n.º 2
0
/**
*
* 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;
}