📄 xpacket_fifo_v1_00_b.c
字号:
/******************************************************************************** Author: Xilinx, Inc.*** This program is free software; you can redistribute it and/or modify it* under the terms of the GNU General Public License as published by the* Free Software Foundation; either version 2 of the License, or (at your* option) any later version.*** XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" AS A* COURTESY TO YOU. BY PROVIDING THIS DESIGN, CODE, OR INFORMATION AS* ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION OR STANDARD,* XILINX IS MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION IS FREE* FROM ANY CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE FOR OBTAINING* ANY THIRD PARTY RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION.* XILINX EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO* THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY* WARRANTIES OR REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM* CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND* FITNESS FOR A PARTICULAR PURPOSE.*** Xilinx hardware products are not intended for use in life support* appliances, devices, or systems. Use in such applications is* expressly prohibited.*** (c) Copyright 2002-2004 Xilinx Inc.* All rights reserved.*** You should have received a copy of the GNU General Public License along* with this program; if not, write to the Free Software Foundation, Inc.,* 675 Mass Ave, Cambridge, MA 02139, USA.*******************************************************************************//*****************************************************************************//*** @file xpacket_fifo_v1_00_b.c** Contains functions for the XPacketFifoV100b component. See xpacket_fifo_v1_00_b.h* for more information about the component.** <pre>* MODIFICATION HISTORY:** Ver Who Date Changes* ----- ---- -------- -----------------------------------------------* 1.00b rpm 03/26/02 First release* </pre>******************************************************************************//***************************** Include Files *********************************/#include "xbasic_types.h"#include "xio.h"#include "xstatus.h"#include "xpacket_fifo_v1_00_b.h"/************************** Constant Definitions *****************************//* width of a FIFO word */#define XPF_FIFO_WIDTH_BYTE_COUNT 4UL/**************************** Type Definitions *******************************//***************** Macros (Inline Functions) Definitions *********************//************************* Variable Definitions ******************************//************************** Function Prototypes ******************************//*****************************************************************************//*** This function initializes a packet FIFO. Initialization resets the* FIFO such that it's empty and ready to use.** @param InstancePtr contains a pointer to the FIFO to operate on.* @param RegBaseAddress contains the base address of the registers for* the packet FIFO.* @param DataBaseAddress contains the base address of the data for* the packet FIFO.** @return** Always returns XST_SUCCESS.** @note** None.*******************************************************************************/XStatusXPacketFifoV100b_Initialize(XPacketFifoV100b * InstancePtr, u32 RegBaseAddress, u32 DataBaseAddress){ /* assert to verify input argument are valid */ XASSERT_NONVOID(InstancePtr != NULL); /* initialize the component variables to the specified state */ InstancePtr->RegBaseAddress = RegBaseAddress; InstancePtr->DataBaseAddress = DataBaseAddress; InstancePtr->IsReady = XCOMPONENT_IS_READY; /* reset the FIFO such that it's empty and ready to use and indicate the * initialization was successful, note that the is ready variable must be * set prior to calling the reset function to prevent an assert */ XPF_V100B_RESET(InstancePtr); return XST_SUCCESS;}/*****************************************************************************//*** This function performs a self-test on the specified packet FIFO. The self* test resets the FIFO and reads a register to determine if it is the correct* reset value. This test is destructive in that any data in the FIFO will* be lost.** @param InstancePtr is a pointer to the packet FIFO to be operated on.** @param FifoType specifies the type of FIFO, read or write, for the self test.* The FIFO type is specified by the values XPF_READ_FIFO_TYPE or* XPF_WRITE_FIFO_TYPE.** @return** XST_SUCCESS is returned if the selftest is successful, or* XST_PFIFO_BAD_REG_VALUE indicating that the value readback from the* occupancy/vacancy count register after a reset does not match the* specified reset value.** @note** None.*******************************************************************************/XStatusXPacketFifoV100b_SelfTest(XPacketFifoV100b * InstancePtr, u32 FifoType){ u32 Register; /* assert to verify valid input arguments */ XASSERT_NONVOID(InstancePtr != NULL); XASSERT_NONVOID((FifoType == XPF_READ_FIFO_TYPE) || (FifoType == XPF_WRITE_FIFO_TYPE)); XASSERT_NONVOID(InstancePtr->IsReady == XCOMPONENT_IS_READY); /* reset the fifo and then check to make sure the occupancy/vacancy * register contents are correct for a reset condition */ XPF_V100B_RESET(InstancePtr); Register = XIo_In32(InstancePtr->RegBaseAddress + XPF_COUNT_STATUS_REG_OFFSET); /* check the value of the register to ensure that it's correct for the * specified FIFO type since both FIFO types reset to empty, but a bit * in the register changes definition based upon FIFO type */ if (FifoType == XPF_READ_FIFO_TYPE) { /* check the regiser value for a read FIFO which should be empty */ if (Register != XPF_EMPTY_FULL_MASK) { return XST_PFIFO_BAD_REG_VALUE; } } else { /* check the register value for a write FIFO which should not be full * on reset */ if ((Register & XPF_EMPTY_FULL_MASK) != 0) { return XST_PFIFO_BAD_REG_VALUE; } } /* the test was successful */ return XST_SUCCESS;}/*****************************************************************************//*** Read data from a FIFO and puts it into a specified buffer. The packet FIFO is* currently 32 bits wide such that an input buffer which is a series of bytes* is filled from the FIFO a word at a time. If the requested byte count is not* a multiple of 32 bit words, it is necessary for this function to format the* remaining 32 bit word from the FIFO into a series of bytes in the buffer.* There may be up to 3 extra bytes which must be extracted from the last word* of the FIFO and put into the buffer.** @param InstancePtr contains a pointer to the FIFO to operate on.* @param BufferPtr points to the memory buffer to write the data into. This* buffer must be 32 bit aligned or an alignment exception could be* generated. Since this buffer is a byte buffer, the data is assumed to* be endian independent.* @param ByteCount contains the number of bytes to read from the FIFO. This* number of bytes must be present in the FIFO or an error will be* returned.** @return** XST_SUCCESS indicates the operation was successful. If the number of* bytes specified by the byte count is not present in the FIFO* XST_PFIFO_LACK_OF_DATA is returned.** If the function was successful, the specified buffer is modified to contain* the bytes which were removed from the FIFO.** @note** Note that the exact number of bytes which are present in the FIFO is* not known by this function. It can only check for a number of 32 bit
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -