Forum Discussion

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

UDP Read and Writing in SDRAM

Dear Friend's

i am sucessfully able to read data through UDP but when i simultenauselly trying to write this received data in SDRAM it generate a message during run time and held operation.

as i add the code for writing in SDRAM

"IOWR_8DIRECT(SDRAM_BASE+myaddr,0,Data);"

the message on console is "smsc91c111 Auto-negotiation:" and then there is no respond

kaushal

6 Replies

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

    Hi Kaushal,

    Are you sure that 'myaddr' correctly points to your UDP data buffer? If something went wrong and you are writing to a code or program data section it would result somehow in this abnormal behavior.

    Other possibility: I don't know how smsc91 driver works, but maybe you need to suspend it whenever you write to your udp buffer; from what you say I supposer that both rd and wr operation can be concurrent and operate on the same memory area. So I think you need to use a mutex or something like it.

    Regards

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

    And are you sure you aren't overwriting something else, such as the software itself?

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

    #define MaxPkt 7

    unsigned int Data[1][1024];

    unsigned int RecvPkt = 0;

    .....recvfrom(...Data[1],sizeof(Data[1]),.......);

    and running a do...while loop in which after every sucessfully read i jut increment "myaddr"

    something like

    myaddr = 0;

    do

    {

    ret = recvfrom(......Data[1],sizeof(Data[1]),....);

    "IOWR_8DIRECT(SDRAM_BASE+myaddr,0,Data);

    myaddr++;

    RecvPkt++;

    }while(RcvPkt != MaxPkt);

    1. the only doubt is that i am receiving my udp data in Data which is a two dimentionl array,and also using same variable in writing to sdram...

    "IOWR_8DIRECT(SDRAM_BASE+myaddr,0,Data);
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    1. the only doubt is that i am receiving my udp data in Data which is a two dimentionl array...

    --- Quote End ---

    Actually Data is monodimensional, since the first dimension is 1.

    Then the reference to Data[1] in recvfrom() is illegal and you are possibly writing to other data memory;

    the correct reference would be Data[0].

    Moreover your use of myaddr as a pointer is not the best choice, unless you use sdram ONLY for udp data and all your code and program data resides in another memory section. You should rather define an array for storing data and then writing there, instead of direct addressing physical memory.

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

    How do i ensure that the area where i am writing my data won't effect the code area...

    What is the SDRAM structure ..i mean code area , data area, etc...i though the entire SDRAM is available for storing data and code will go to flash.

    i am using nios-ii (Quartus 9.1)

    can i use variable like "DATA[100][1024]" ....if it so then where this two dimension array create...is it go to flash or cpu cache?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Usually both code and data are stored in sdram, unless you map them in other places changing syslib properties or directly through linker options.

    Sure, code and initialized data are stored in flash eprom but they are copied upon boot into sdram (or sram or internal memory, wherever you have mapped each section).

    As I already posted in another similar thread, a safe and much simpler way to use sdram is: define a sdram buffer as a variable array, i.e. char bigbuffer[BUFSIZE] and then write to bigbuffer[myaddr] instead of using direct iowr. The linker automatically takes care of avoiding sdram corruption (provided you check myaddr<BUFSIZE in your code...)

    Cris