Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
16 years ago

Cannot write on-chip memory with fread.

I use DE2-70 to develop my project. My uClinux is running in SDRAM, and I want to copy a file to on-chip memory, but there is only 0 in on-chip memory, the fread() function didn't work.

can anyone help me in removing this error,

Thanks a lot !

Code:

int main()

{

FILE *fp1;

unsigned int *mem_source = (unsigned int *)(na_onchip_mem_source|0x80000000);

fp1 = open_file("P.dat",READ);

long length;

fseek(fp1, 0L, SEEK_END);

length = ftell(fp1);

int counter = 0;

fseek(fp1,0L,SEEK_SET);

fread(mem_source,length,1,fp1);

int i;

for(i=0;i<(length+3)/4;i++)

printf("mem_source %d = %x\n",i,mem_source[i]);

return 0;

}

6 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    You cannot use onchip_mem directly. Please read to a buffer, (dump/check it) then copy the content to the onchip_mem.

    You should check return of every file functions, such as open/seek/read/close etc.

    - Hippo
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thanks.

    I want to use DMA to encrypt file between two onchip mems, and it will save some time if I can read data to onchip mem directly. Is there any other method can do that?

    Any of your help will be appreciated!
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    You cannot handle interrupt in user space. So you might have to do it in kernel space, like using a driver or syscall.

    Beside, you should add return value check in your program and test it again before doing anything else.

    - Hippo
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    You cannot use onchip_mem directly.

    --- Quote End ---

    This _should_ be possible in a Kernel driver ?!?!?!?

    -Michael
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    But I can use fwrite() to move data from on-chip mem to a file directly.

    Why fread() can't copy a file to on-chip mem?

    I tried kernel function like read(), failed too.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi

    I wonder if the fread did work eventually to write to on chip memory? if so, what was the solution?

    thanks