int main(void) { remove_pcap(); static XHwIcap HwIcap; XHwIcap_Config *CfgPtr = XHwIcap_LookupConfig(HWICAP_DEVICEID); if (CfgPtr == NULL) { return XST_FAILURE; } int Status = XHwIcap_custom_CfgInitialize(&HwIcap, CfgPtr, CfgPtr->BaseAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Perform a self-test to ensure that the hardware was built correctly. */ Status = XHwIcap_SelfTest(&HwIcap); if (Status != XST_SUCCESS) { return XST_FAILURE; } test(&HwIcap); xil_printf("End ROM test.\n\r\n\r"); return 0; }
/** * * This function reads a frame from the device as an example using polled mode. * * @param DeviceId is the XPAR_<HWICAP_INSTANCE>_DEVICE_ID value from * xparameters.h * * @return XST_SUCCESS if successful, otherwise XST_FAILURE * * @note None * ****************************************************************************/ int HwIcapReadFramePolledExample(u16 DeviceId) { int Status; u32 Index; XHwIcap_Config *CfgPtr; u32 FrameData[XHI_NUM_WORDS_FRAME_INCL_NULL_FRAME]; /* * Initialize the HwIcap instance. */ CfgPtr = XHwIcap_LookupConfig(DeviceId); if (CfgPtr == NULL) { return XST_FAILURE; } Status = XHwIcap_CfgInitialize(&HwIcap, CfgPtr, CfgPtr->BaseAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Perform a self-test to ensure that the hardware was built correctly. */ Status = XHwIcap_SelfTest(&HwIcap); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Read the Frame */ Status = XHwIcap_DeviceReadFrame(&HwIcap, HWICAP_EXAMPLE_TOP, HWICAP_EXAMPLE_BLOCK, HWICAP_EXAMPLE_HCLK, HWICAP_EXAMPLE_MAJOR, HWICAP_EXAMPLE_MINOR, (u32 *) &FrameData[0]); if (Status != XST_SUCCESS) { printf("Failed to Read Frame: %d \r\n", Status); return XST_FAILURE; } /* * Print Frame contents */ for (Index = XHI_NUM_FRAME_WORDS; Index < (XHI_NUM_FRAME_WORDS << 1) ; Index++) { printf("Frame Word %d -> \t %x \r\n", (Index - XHI_NUM_FRAME_WORDS) , FrameData[Index]); } printf("\r\nHwIcapReadFramePolledExample Passed Successfully.\r\n\r\n"); return XST_SUCCESS; }
static void remove_head_inst(void) { struct xhwicap_instance *inst; XHwIcap_Config *cfg; /* Pull the head off of inst_list. */ inst = inst_list; inst_list = inst->next_inst; cfg = XHwIcap_LookupConfig(inst->index); iounmap((void *) cfg->BaseAddress); cfg->BaseAddress = inst->save_BaseAddress; }
static int __init probe(int index) { static const unsigned long remap_size = CONFIG_XILINX_HWICAP_0_HIGHADDR - CONFIG_XILINX_HWICAP_0_BASEADDR + 1; struct xhwicap_instance *inst; XHwIcap_Config *cfg; /* Find the config for our instance. */ cfg = XHwIcap_LookupConfig(index); if (!cfg) return -ENODEV; /* Allocate the inst and zero it out. */ inst = (struct xhwicap_instance *) kmalloc(sizeof (struct xhwicap_instance), GFP_KERNEL); if (!inst) { printk(KERN_ERR "%s #%d: Could not allocate instance.\n", miscdev.name, index); return -ENOMEM; } memset(inst, 0, sizeof (struct xhwicap_instance)); inst->index = index; /* Make it the head of inst_list. */ inst->next_inst = inst_list; inst_list = inst; /* Change the addresses to be virtual; save the old ones to restore. */ inst->save_BaseAddress = cfg->BaseAddress; cfg->BaseAddress = (u32) ioremap(inst->save_BaseAddress, remap_size); /* Tell the Xilinx code to bring this HWICAP interface up. */ /* REALLY FIXME - XC2V1000 is hard coded - bleugh! */ if (XHwIcap_Initialize(&inst->HwIcap, cfg->DeviceId, XHI_XC2V1000) != XST_SUCCESS) { printk(KERN_ERR "%s #%d: Could not initialize instance.\n", miscdev.name, inst->index); remove_head_inst(); return -ENODEV; } printk(KERN_INFO "%s #%d at 0x%08X mapped to 0x%08X\n", miscdev.name, inst->index, inst->save_BaseAddress, cfg->BaseAddress); return 0; }
/** * * The purpose of this function is to illustrate the usage of the HwIcap driver. * * @param HwIcapDeviceId is device ID of the XHwIcap Device, typically * XPAR_<HWICAP_instance>_DEVICE_ID value from xparameters.h * * @return XST_SUCCESS to indicate success, otherwise XST_FAILURE. * * @note None. * ****************************************************************************/ int HwIcapTestAppExample(u16 HwIcapDeviceId) { int Status; XHwIcap_Config *ConfigPtr; u32 ConfigRegData; /* * Initialize the HwIcap driver. */ ConfigPtr = XHwIcap_LookupConfig(HwIcapDeviceId); if (ConfigPtr == NULL) { return XST_FAILURE; } Status = XHwIcap_CfgInitialize(&HwIcap, ConfigPtr, ConfigPtr->BaseAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Perform a self-test to ensure that the hardware was built correctly. */ Status = XHwIcap_SelfTest(&HwIcap); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Read the ID Code register inside the FPGA. */ Status = XHwIcap_GetConfigReg(&HwIcap, XHI_IDCODE, &ConfigRegData); if (Status != XST_SUCCESS) { return XST_FAILURE; } return XST_SUCCESS; }
/// /// Initialize the ICAP /// void icap_init(void){ CYG_REPORT_FUNCTION(); XStatus Status; icap_config = XHwIcap_LookupConfig(HWICAP_DEVICEID); Status = XHwIcap_CfgInitialize(&HwIcap, &icap_config, icap_config->BaseAddress); if (Status != XST_SUCCESS) { switch (Status) { case XST_INVALID_PARAM: diag_printf("HWICAP: invalid parameter\n"); break; case XST_FAILURE: diag_printf("HWICAP: failure\n"); break; case XST_DEVICE_IS_STARTED: diag_printf("HWICAP: device already started\n"); break; case XST_DEVICE_NOT_FOUND: diag_printf("HWICAP: device not found\n"); break; default: diag_printf("HWICAP: failed with return value %d\n", Status); } CYG_FAIL("failed to initialize icap\naborting\n"); } // Run self test Status = XHwIcap_SelfTest(&HwIcap); if (Status != XST_SUCCESS) { CYG_FAIL("HWICAP: self-test failed\n"); } cyg_mutex_init(&icap_mutex); CYG_REPORT_RETURN(); }
/** * * This function does a minimal test on the HwIcap device and driver as a * design example. The purpose of this function is to illustrate how to use * the XHwIcap component using the interrupt mode. * * This function sends data and expects to receive the same data. * * * @param IntcInstancePtr is a pointer to the instance of the INTC component. * @param HwIcapInstancePtr is a pointer to the instance of HwIcap component. * @param HwIcapDeviceId is the Device ID of the HwIcap Device and is the * XPAR_<HWICAP_instance>_DEVICE_ID value from xparameters.h. * @param HwIcapIntrId is the interrupt Id and is typically * XPAR_<INTC_instance>_<HWICAP_instance>_IP2INTC_IRPT_INTR * value from xparameters.h . * * @return XST_SUCCESS if successful, otherwise XST_FAILURE. * * @note * * This function contains an infinite loop such that if interrupts are not * working it may never return. * ******************************************************************************/ int HwIcapIntrExample(XIntc *IntcInstancePtr, XHwIcap *HwIcapInstancePtr, u16 HwIcapDeviceId, u16 HwIcapIntrId) { int Status; u32 Count; u8 Test; XHwIcap_Config *ConfigPtr; /* * Initialize the HwIcap driver. */ ConfigPtr = XHwIcap_LookupConfig(HwIcapDeviceId); if (ConfigPtr == NULL) { return XST_FAILURE; } Status = XHwIcap_CfgInitialize(HwIcapInstancePtr, ConfigPtr, ConfigPtr->BaseAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Perform a self-test to ensure that the hardware was built correctly. */ Status = XHwIcap_SelfTest(HwIcapInstancePtr); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Connect the HwIcap device to the interrupt subsystem such that * interrupts can occur. This function is application specific. */ Status = HwIcapSetupInterruptSystem(IntcInstancePtr, HwIcapInstancePtr, HwIcapIntrId); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Setup the handler for the HwIcap that will be called from the * interrupt context when an HwIcap status occurs, specify a pointer * to the HwIcap driver instance as the callback reference so the * handler is able to access the instance data. */ XHwIcap_SetInterruptHandler(HwIcapInstancePtr, HwIcapInstancePtr, (XHwIcap_StatusHandler)HwIcapIntrHandler); /* * Initialize the write buffer with pattern to write. */ for (Count = 0; Count < TEST_WRITE_BUFFER_SIZE;) { WriteBuffer[Count++] = XHI_DUMMY_PACKET; WriteBuffer[Count++] = XHI_SYNC_PACKET; WriteBuffer[Count++] = XHwIcap_Type1Read(XHI_IDCODE) | 1; WriteBuffer[Count++] = XHI_NOOP_PACKET; WriteBuffer[Count++] = XHI_NOOP_PACKET; WriteBuffer[Count++] = XHI_DUMMY_PACKET; WriteBuffer[Count++] = XHI_SYNC_PACKET; WriteBuffer[Count++] = XHwIcap_Type1Read(XHI_COR) | 1; WriteBuffer[Count++] = XHI_NOOP_PACKET; WriteBuffer[Count++] = XHI_NOOP_PACKET; } /* * Enable the Write FIFO Half Full Interrupt. */ XHwIcap_IntrEnable(HwIcapInstancePtr, XHI_IPIXR_WRP_MASK); /* * Write the the data to the device. */ TransferInProgress = TRUE; Status = XHwIcap_DeviceWrite(HwIcapInstancePtr, (u32 *) &WriteBuffer[0], TEST_WRITE_BUFFER_SIZE); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Wait for the data to be written to the device. */ while (TransferInProgress); return XST_SUCCESS; }
/** * * This function reads the configuration registers inside the FPGA. * * @param DeviceId is the XPAR_<HWICAP_INSTANCE>_DEVICE_ID value from * xparameters.h. * * @return XST_SUCCESS if successful, otherwise XST_FAILURE. * * @note None. * ******************************************************************************/ int HwIcapReadConfigRegExample(u16 DeviceId) { int Status; XHwIcap_Config *CfgPtr; u32 ConfigRegData; /* * Initialize the HwIcap instance. */ CfgPtr = XHwIcap_LookupConfig(DeviceId); if (CfgPtr == NULL) { return XST_FAILURE; } Status = XHwIcap_CfgInitialize(&HwIcap, CfgPtr, CfgPtr->BaseAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Run the Self test. */ Status = XHwIcap_SelfTest(&HwIcap); if (Status != XST_SUCCESS) { return XST_FAILURE; } printf("Value of the Configuration Registers. \r\n\r\n"); if (XHwIcap_GetConfigReg(&HwIcap, XHI_CRC, (u32 *)&ConfigRegData) == XST_SUCCESS) { printf(" CRC -> \t %x \t\r\n", ConfigRegData); } if (XHwIcap_GetConfigReg(&HwIcap, XHI_FAR, (u32 *)&ConfigRegData) == XST_SUCCESS) { printf(" FAR -> \t %x \t\r\n", ConfigRegData); } if (XHwIcap_GetConfigReg(&HwIcap, XHI_FDRI, (u32 *)&ConfigRegData) == XST_SUCCESS) { printf(" FDRI -> \t %x \t\r\n", ConfigRegData); } if (XHwIcap_GetConfigReg(&HwIcap, XHI_FDRO, (u32 *)&ConfigRegData) == XST_SUCCESS) { printf(" FDRO -> \t %x \t\r\n", ConfigRegData); } if (XHwIcap_GetConfigReg(&HwIcap, XHI_CMD, (u32 *)&ConfigRegData) == XST_SUCCESS) { printf(" CMD -> \t %x \t\r\n", ConfigRegData); } if (XHwIcap_GetConfigReg(&HwIcap, XHI_CTL, (u32 *)&ConfigRegData) == XST_SUCCESS) { printf(" CTL -> \t %x \t\r\n", ConfigRegData); } if (XHwIcap_GetConfigReg(&HwIcap, XHI_MASK, (u32 *)&ConfigRegData) == XST_SUCCESS) { printf(" MASK -> \t %x \t\r\n", ConfigRegData); } if (XHwIcap_GetConfigReg(&HwIcap, XHI_STAT, (u32 *)&ConfigRegData) == XST_SUCCESS) { printf(" STAT -> \t %x \t\r\n", ConfigRegData); } if (XHwIcap_GetConfigReg(&HwIcap, XHI_LOUT, (u32 *)&ConfigRegData) == XST_SUCCESS) { printf(" LOUT -> \t %x \t\r\n", ConfigRegData); } if (XHwIcap_GetConfigReg(&HwIcap, XHI_COR, (u32 *)&ConfigRegData) == XST_SUCCESS) { printf(" COR -> \t %x \t\r\n", ConfigRegData); } if (XHwIcap_GetConfigReg(&HwIcap, XHI_MFWR, (u32 *)&ConfigRegData) == XST_SUCCESS) { printf(" MFWR -> \t %x \t\r\n", ConfigRegData); } if (XHwIcap_GetConfigReg(&HwIcap, XHI_CBC, (u32 *)&ConfigRegData) == XST_SUCCESS) { printf(" CBC -> \t %x \t\r\n", ConfigRegData); } if (XHwIcap_GetConfigReg(&HwIcap, XHI_AXSS, (u32 *)&ConfigRegData) == XST_SUCCESS) { printf(" AXSS -> \t %x \t\r\n", ConfigRegData); } if (XHwIcap_GetConfigReg(&HwIcap, XHI_IDCODE, (u32 *)&ConfigRegData) == XST_SUCCESS) { printf(" IDCODE -> \t %x \t\r\n", ConfigRegData); } if (XHwIcap_GetConfigReg(&HwIcap, XHI_COR_1, (u32 *)&ConfigRegData) == XST_SUCCESS) { printf(" COR_1 -> \t %x \t\r\n", ConfigRegData); } if (XHwIcap_GetConfigReg(&HwIcap, XHI_CSOB, (u32 *)&ConfigRegData) == XST_SUCCESS) { printf(" CSOB -> \t %x \t\r\n", ConfigRegData); } if (XHwIcap_GetConfigReg(&HwIcap, XHI_WBSTAR, (u32 *)&ConfigRegData) == XST_SUCCESS) { printf(" WBSTAR -> \t %x \t\r\n", ConfigRegData); } if (XHwIcap_GetConfigReg(&HwIcap, XHI_TIMER, (u32 *)&ConfigRegData) == XST_SUCCESS) { printf(" TIMER -> \t %x \t\r\n", ConfigRegData); } if (XHwIcap_GetConfigReg(&HwIcap, XHI_BOOTSTS, (u32 *)&ConfigRegData) == XST_SUCCESS) { printf(" BOOTSTS -> \t %x \t\r\n", ConfigRegData); } if (XHwIcap_GetConfigReg(&HwIcap, XHI_CTL_1, (u32 *)&ConfigRegData) == XST_SUCCESS) { printf(" CTL_1 -> \t %x \t\r\n", ConfigRegData); } printf("\r\n HwIcapReadConfigRegExample Passed Successfully.\r\n\r\n"); return XST_SUCCESS; }
/** * * This function does a test on the BRAM FF as an example. * * @param DeviceId is the XPAR_<HWICAP_INSTANCE>_DEVICE_ID value from * xparameters.h * * @return XST_SUCCESS if successful, otherwise XST_FAILURE * * @note None * ****************************************************************************/ int HwIcapBramFfExample(u16 DeviceId) { u32 SrMode=0; int Status; u32 Row; u32 Col; u32 Slice; u32 Loop; u32 Value; u8 Contents[1]; XHwIcap_Config *CfgPtr; /* * Initialize the HwIcap instance. */ CfgPtr = XHwIcap_LookupConfig(DeviceId); if (CfgPtr == NULL) { return XST_FAILURE; } Status = XHwIcap_CfgInitialize(&HwIcap, CfgPtr, CfgPtr->BaseAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Identify the FF to change: FFX in SLICE_X0Y0. */ Col = XHwIcap_SliceX2Col(HWICAP_EXAMPLE_TEST_COL); Row = XHwIcap_SliceY2Row(&HwIcap, HWICAP_EXAMPLE_TEST_ROW); Slice = XHwIcap_SliceXY2Slice(HWICAP_EXAMPLE_TEST_COL, HWICAP_EXAMPLE_TEST_ROW); printf("Setting the SRMODE -> SRHIGH. \r\n"); Status = XHwIcap_SetClbBits(&HwIcap, Row, Col, XHI_CLB_FF.SRMODE[Slice][XHI_CLB_XQ], XHI_CLB_FF.SRHIGH, 1); if (Status != XST_SUCCESS) { printf("Failed to Set SRMODE->SRHIGH: %d \r\n", Status); return XST_FAILURE; } printf("Setting the SRMODE -> SRLOW. \r\n"); Status = XHwIcap_SetClbBits(&HwIcap, Row, Col, XHI_CLB_FF.SRMODE[Slice][XHI_CLB_XQ], XHI_CLB_FF.SRLOW, 1); if (Status != XST_SUCCESS) { printf("Failed to Set SRMODE->SRLOW: %d \r\n", Status); return XST_FAILURE; } printf("Set SRINV to SR \r\n"); Status = XHwIcap_SetClbBits(&HwIcap, Row, Col, XHI_CLB_SRINV.RES[Slice], XHI_CLB_SRINV.SR, 1); if (Status != XST_SUCCESS) { printf("Failed to Set SRINV->SR: %d \r\n", Status); return XST_FAILURE; } /* * Set it back */ printf("Set SRINV to SR_B \r\n"); Status = XHwIcap_SetClbBits(&HwIcap, Row, Col, XHI_CLB_SRINV.RES[Slice], XHI_CLB_SRINV.SR_B, 1); if (Status != XST_SUCCESS) { printf("Failed to Set SRINV->SR_B: %d \r\n", Status); return XST_FAILURE; } /* * Capture the FF states. If the CAPTURE block is instantiated in * the design then the XHwIcap_CommandCapture() is not necessary. */ printf("Capture the FF state. \r\n"); Status = XHwIcap_CommandCapture(&HwIcap); if (Status != XST_SUCCESS) { printf("Failed to capture FF states: %d \r\n", Status); return XST_FAILURE; } /* * Read the FF Contents */ Status = XHwIcap_GetClbBits(&HwIcap, Row, Col, XHI_CLB_FF.CONTENTS[Slice][XHI_CLB_XQ], Contents, 1); if (Status != XST_SUCCESS) { printf("Failed to Get FF Contents: %d \r\n", Status); return XST_FAILURE; } /* * The readback value of the FF is inverted from its true value. */ Value = ~Contents[0] & 0x1; printf("FF Contents: %d \r\n", Value); printf("HwicapBramFFExample Passed Successfully ... \r\n\r\n"); return XST_SUCCESS; }