Showing results for 
Show  only  | Search instead for 
Did you mean: 
Registered: ‎02-25-2009

How to use xilinx_hwicap.c to perform read back?

I do not have problem with write through icap. The device is configurated with the partial bitstream correctly.


However, I have trouble in using this driver to perfrom read back.


Here is what I do (as a user-appliation):


  //open ICAP

  ICAP = fopen("/dev/icap0", "r+");

  fread(word, sizeof(*word), inFileSize/4, inFile);

  fwrite(word,  sizeof(*word), inFileSize/4, ICAP);

  fread(frame,  sizeof(*word), 82 + 200, ICAP); // 200 is not important, I just want to read out more than needed

  fwrite(frame,  sizeof(*word), 82 + 200, outFile);


inFile is the configuration command sequence (the same as in : xhwicap_device_read_frame.c)

ffff ffff aa99 5566 2000 0000 2000 0000  // Dummy   Sync  Nope  Nope

3000 8001 0000 0007 2000 0000 2000 0000 // CMD  CRC_Reset  Nope Nope

3000 8001 0000 0004 2000 0000 2000 0000 // CMD  Read_Config Nope  Nope

2000 0000 3000 2001 0040 c095 2800 6053 //  Nope FAR  FRDO

2000 0000 2000 0000                                    //  Nope Nope


However, no configuration is read out and written in outFile. I only get "0000"s. (I do not have problem in using the function "XHwIcap_DeviceReadFrameV4" as a stand-alone EDK project.)


Anybody has some experience in using Xilinx icap dirver in kernel 2.6? What mistakes have I made above?



Tags (4)
0 Kudos
3 Replies
Xilinx Employee
Xilinx Employee
Registered: ‎09-10-2008



We don't regularly test this driver in out automation as we do others and I don't have any experience using it. 


We don't have a lot of users for this driver to my knowledge. 


Sorry I'm not much help,


0 Kudos
Registered: ‎02-25-2009

One problem I found is: after the icap read, the status register is not back to 0x7ffc. This seems to mean read fails.


I would like to just read 0x53 words out of ICAP, however, no matter what value I put as the 3rd parameter of fread ICAP, by default the icap driver read function get a count of 1000 (pre-defined buffer size?). This is not of frame boundry and contradicts with the command previously written to ICAP - to read one frame. This might be the reason why status register is still 0 after read.


Then I tried to force count to 83 in icap driver code (83 = 1 dummy word + 1 dummy frame of 41 words + 1 desired frame of 41 words). This time, the status register is back to 0x7ffc after reading icap. And it works! Thought the data read out is not 83 words as using Xilinx hwicap v1_01_a driver, but 81, 40 dummy words is ahead of a frame data of 41 words.


So the questions is: why the desired count is not passed?


Here is my user application:

int* frame = (int*) malloc( 83 * sizeof(int));
ICAP = fopen("/dev/icap0", "r+b"); // The deivce is opened OK.

fread(frame, sizeof(int), 83, ICAP);


The device read operation is defined as:
static ssize_t hwicap_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)


Why 83 is not passed into hwica_read, but 0x1000 is used?

Message Edited by wenweizha on 09-22-2009 06:28 PM
0 Kudos
Registered: ‎02-25-2009

I get a reply from a Linux forum that:

"fread should return the actual value it did read, unregarded what you passed in count."


So the driver read function should take care of how many words to request from icap. This can not be an arbitrary value. The value 0x1000 simple cause icap in a abnormal status and the device won't function correctly any more.


Here are my suggestion:

Words read from icap should not start at offset 0 of bram; rather, it should start at 20 (like the EDK driver hwicap v1_01_a). Then the "read back command sequence" is still kept in the top of bram and how many frames are actually requested can be retrieved from bram. Driver read function then use this value when perform copy_to_user. 

0 Kudos