0

I am having problem understanding difference between below two code cases. Case 1 is working as per expectation and Case 2 is not.

Problem Statement: I need to write some set of DWORDS on my device file and trigger a DMA. DMA capacity is 128*4 bytes (128 DWORDS). So I want to trigger DMA(using ioctl) after writing 128 bytes to device file descriptor to have full utilisation of capacity. I can do this for individual Dwords as well.

Basic difference in two cases: In first case intention is to write 128 DWORDS to the file at once and in second case write DWORDS individually and trigger DMA after 128 DWORDS are written.

Is the data written to the file same in both cases? Second is not working so something wrong there. please help. By not working I mean the expected result of DMA commands are not happening so in second case data in file descriptor is is not same as first case just before the dma command.

Case 1 (WORKING)

int input_dwords[128] = {0xAABBCCDD, 0XBBCCDDAA, ....} //128 DWORDS (actually this data is in
                                                     //text file just putting in array for  
                                                     //illustration)
int cmd_buf = (int*)malloc(sizeof(int) * 128); //space for 128 DWORDS
int* cur = cmd_buf;  
for(int i = 0; i< 128; i++)
{
*cur = input_dword[i] 
cur++;
}
//Write to file in one shot
write(fd, cmd_buf, sizeof(int)*128);

//trigger DMA (ioctl)
 trigger_dma(fd);

Case 2 (NOT WORKING)

int input_dwords[128] = {0xAABBCCDD, 0xBBCCDDAA, ....}
int* cur = (int*)input_dwords;

for(int i = 0 ; i< 128 i++)
{
 //writing to file one DWORD at a time.
write(fd, cur, sizeof(int));
cur++;
}
    //trigger DMA (ioctl)
 trigger_dma(fd);
bdubey
  • 307
  • 4
  • 13
  • did you try to flush `fd` at the end of the loop in case 2? – Aif Nov 08 '14 at 11:43
  • 1
    Please, be clear about "not working". – rslemos Nov 08 '14 at 11:44
  • EDITED By not working I mean the expected result of DMA commands are not happening so in second case data in file descriptor is is not same as first case just before the dma command – bdubey Nov 08 '14 at 11:47
  • Is the for loop supposed to only write 127 ints? Maybe not fully using the buffer is an issue? If you mean to do 128 then the loop should be `for(int i = 0 ; i < 128 ; i++)` – hcs Nov 08 '14 at 11:48
  • @Aif Can you be clear what needs to be done and what effect it will have? – bdubey Nov 08 '14 at 11:49
  • @hcs corrected! No that is not the issue. This is not the exact code so some mistake while typing. Basically just before dma trigger data written in file descriptor must be different for the second case to fail. I am having trouble understanding why? Never worked with file descriptor before. – bdubey Nov 08 '14 at 11:53
  • `write (fd, input_dwords, sizeof input_dwords);` writes hem in one sweep. – wildplasser Nov 08 '14 at 13:14
  • I know. Actually I dont have an array of input_dwords. I have a file with dwords which I have to read line by line and get the dwords. Array is just for illustration purpose. I want case 2 to be working after required changes – bdubey Nov 08 '14 at 13:22
  • On which operating system, and on which file system??? – Basile Starynkevitch Nov 08 '14 at 13:28
  • but *why* do you want to make 128 systemcalls, if the same thing can be acomplished in one? (a 512 byte buffer is not big) – wildplasser Nov 08 '14 at 13:42
  • If the problem is really on the difference between using 128*write (1DWORD) and 1*write(128DWORD) I would look at the driver implementation of the write function. It might not keep fpos pointer. – Claudio Nov 09 '14 at 07:11

0 Answers0