当前位置: 动力学知识库 > 问答 > 编程问答 >

c - How to copy a required chunk of data from a text file to device node (file opened using open) for dma

问题描述:

I have this file called input.txt opened using file pointer. Now I want to read this file and write this data into device node file using write() system call(Any better way). Right now I am scanning integer values one by one and writing to device node. Any way so that I can do this in block say some fixed number of bytes. input.txt contain 32 bit integers seperated by newline. Below is the code I have right now.

FILE *fp = fopen("input.txt", "r");

int fd = open("/dev/devnode", O_WRONLY);

int current = 0;

while(!feof(fp))

{

fscanf(fp,"%x\n", &current)

write(fd,&current,sizeof(int));

trigger_dma_to_device();

}

Is there any better way to do this? Please help.

EDIT:

To put my requirement clearly I write to device node and then have to trigger DMA but DMA capacity is 1024 bytes so rather than writing one integer (32 bytes) I want to read 32 integers (1024 bytes) from input.txt and write it to device node before triggering dma. Any way this can be done without allocating extra memory. I'm OK with loop to start with.

分享给朋友:
您可能感兴趣的文章:
随机阅读: