Hi Ousseama,
I wrote the attached file awhile ago. It should work if I remember
correctly. After you compile it, execute it and it will tell you what the
arguments are.
Mark
On Mon, Nov 23, 2009 at 8:51 PM, Oussama Sekkat <[email protected]> wrote:
> Hi All,
>
> Does anyone happens to have C code already written that takes an input file
> and writes the content of that file into a shared BRAM in BORPH?
>
> Oussama.
>
>
>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
== INPUT ==
arg 1 is the tvg process number
arg 2 is starting bram address to write
arg 3 is ending bram address to write
arg 4 is bram name
arg 5 is data file of values to be written
== OUTPUT (stdout) ==
column 1 is the bram address
column 2 is the value
*/
int main(int argc,char **argv)
{
if(argv[1] == NULL)
{
printf("Usage: arite_bram <process number> <start addr> <end addr> <bram name> <data file>\n");
}
else
{
FILE *bram_file,*data_file;
char bram[200];
char file[100];
char tmp[100];
memset(file,0,100);
memcpy(file,argv[5],strlen(argv[5]));
int i;
int buffer;
sprintf(bram,"/proc/%s/hw/ioreg/%s",argv[1],argv[4]);
sprintf(tmp,"%s",file);
bram_file=fopen(bram,"wb");
data_file=fopen(file,"r");
if(bram_file == NULL)
{
printf("Error: couldn't open file '%s'\n",bram);
return 1;
}
for(i=atoi(argv[2]);i<=atoi(argv[3]);i++)
{
fscanf(data_file,"%s\n",tmp);
buffer=atof(tmp)*32767;
printf("%d %d\n",i,buffer);
fwrite(&buffer,sizeof(int),1,bram_file);
}
fclose(bram_file);
fclose(data_file);
}
return 0;
}