Forum Discussion

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

IOWR, IOWR_32DIRECT, alt_flash_read... need help to get the bits

I have got a quite simple problem I think, but I am messing around about half a day now with that and don't figure it out. So I would like to ask for your advice.

I want to copy data from my EPCS Flash to a SDRAM.

I can do it with this rather ugly method:


int i;
char read_data;
for(i=0; i<size; i++){
//in
ret_code = alt_read_flash(my_epcs, i<<2,     &(read_data), 1);
ret_code = alt_read_flash(my_epcs, (i<<2)+1, &(read_data), 1);
ret_code = alt_read_flash(my_epcs, (i<<2)+2, &(read_data), 1);
ret_code = alt_read_flash(my_epcs, (i<<2)+3, &(read_data), 1);
//out
IOWR_8DIRECT((SDRAM_2_MASK0_BASE+3), ((i-1)*32/8), read_data);
IOWR_8DIRECT((SDRAM_2_MASK0_BASE+2), ((i-1)*32/8), read_data);
IOWR_8DIRECT((SDRAM_2_MASK0_BASE+1), ((i-1)*32/8), read_data);
IOWR_8DIRECT((SDRAM_2_MASK0_BASE)  , ((i-1)*32/8), read_data);
}

Can someone give me a working example how to do this with 32bit directly? Everytime I try it with IOWR it get messed up. My C-knowledge isn't so well, so I think I mess up with the pointers and adresses some kind of.

Thanks in advance, I really need this urgently.

5 Replies

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

    You can use alt_read_flash right into SDRAM in one call. I do this currently on startup to copy the application in EPCS to SDRAM - with one call and a tricky jump to the entry point.

    
    ret_code = alt_read_flash(my_epcs, epcsAddr,  sdramAddr, dataSize);
    
    Bill
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thanks for your reply BillA. I already tried that, but did not matched the addresses right I think.

    Does alt_read_flash read Bytes or Bits? So dataSize*8=Bit or dataSize=Bit?

    
    ret_code = alt_read_flash(my_epcs, epcsAddr,  sdramAddr, dataSize);
    

    I have got a EPCS64 Serial Device and my SDRAM Master Width is 32Bit wide. How would you count?

    
    epcsAddr++, sdramAddr++, dataSize = 32
    ret_code = alt_read_flash(my_epcs, epcsAddr,  sdramAddr, dataSize);
    or
    epcsAddr+=4, sdramAddr++, dataSize = 32
    ret_code = alt_read_flash(my_epcs, epcsAddr,  sdramAddr, dataSize);
    or
    epcsAddr+=32, sdramAddr++, dataSize = 32
    ret_code = alt_read_flash(my_epcs, epcsAddr,  sdramAddr, dataSize);
    or
    epcsAddr+=4, sdramAddr++, dataSize = 4
    ret_code = alt_read_flash(my_epcs, epcsAddr,  sdramAddr, dataSize);
    

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

    Everything is in bytes. datasize is a number of bytes, and the addresses point to bytes in memory (i.e. you need to increase them by 4 to jump to the next 32-bit word, as long as they are ints or char*).

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

    --- Quote Start ---

    Thanks for your reply BillA. I already tried that, but did not matched the addresses right I think.

    Does alt_read_flash read Bytes or Bits? So dataSize*8=Bit or dataSize=Bit?

    --- Quote End ---

    Bytes. I don't know if there is optimization to write 32-bits at a time to SDRAM but the call is bytes (like C's fread) and the EPCS contents are placed byte for byte in order.

    --- Quote Start ---

    I have got a EPCS64 Serial Device and my SDRAM Master Width is 32Bit wide. How would you count?

    --- Quote End ---

    Use the following to read 32 bytes at a time. But there's no reason to do this - one call will suffice - dataSize is the bytes to copy. Look at alt_read_flash as if it were memcpy:

    
    while(dataSize>32)
      {
      ret_code = alt_read_flash(my_epcs, epcsAddr,  sdramAddr, 32);
      epcsAddr+=32, sdramAddr+=32;
      dataSize-=32;
      }
    if(dataSize>0)
      ret_code = alt_read_flash(my_epcs, epcsAddr,  sdramAddr, dataSize);
    
    Bill
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thanks for your help, tried it out today and just works fine.

    Yours, Peter.