Forum Discussion

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

Problem with IORD and IOWR instructions

Dear all,

I have a qsys system composed of two NIOS that can access a shared memory (data masters are connected to the memory),

when I use the instructions IORD and IOWR I don't obtain the right value

The shared memory is intialised with a hex file that contains tha value 6 at the adress 0

But when NIOS1 does: IORD (SHAREDMEM_BASE, 0x0) I obtain in the console a wrong value : 6c6c6cFc!!!

Also when the first NIOS writes a value at the @0 using IORD and then the NIOS 2 tries to read this value, I obtain a wrong value

I'm using NIOSII SBT 11.1

Please anyone can help me?? is there a functioning example using these two instructions?

18 Replies

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

    --- Quote Start ---

    Hi BadOmen,

    where enable the optimizations? I'm using the default setting of NIOS II SBT tool to compile both codes

    I want in a first step be sure of the functioning of IORD and IOWR and then use the mutex to access the shared memory

    any help will be appreciated,

    Thanks

    --- Quote End ---

    I typically work from the command line so I forget where it is but a debug profile would normally contain -O0 optimization (i.e. no optimization). For that updated code that polls for 9 to be read back from memory try making the 'j' variable volatile, regardless of whether optimizations are enabled or not that should prevent the loop from being removed.

    Also are you sure your both processors are actually running code? Each CPU should have it's own BSP (can't have them both sharing read/write, heap, and stack regions) so you should be able to run them independent of eachother to make sure they execute code properly up to a certain point. Once that's verified then you can download the code as a multi-download group (whatever it's called in the IDE). I normally find it easier to coordinate multiple processor downloads from the command line like this:

    nios2-download -i 0 -g <elf1.elf>

    nios2-download -i 1 -g -r <elf2.elf>

    nios2-terminal -i 0

    nios2-terminal -i 1

    The -i lets you pick which Nios II JTAG debug module/JTAG UART you are using. The -g tells nios2-download to start executing code and -r means reset the target. Normally I open one terminal window per command shell so that I can watch the output of all the processors at the same time.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    I typically work from the command line so I forget where it is but a debug profile would normally contain -O0 optimization (i.e. no optimization). For that updated code that polls for 9 to be read back from memory try making the 'j' variable volatile, regardless of whether optimizations are enabled or not that should prevent the loop from being removed.

    Also are you sure your both processors are actually running code? Each CPU should have it's own BSP (can't have them both sharing read/write, heap, and stack regions) so you should be able to run them independent of eachother to make sure they execute code properly up to a certain point. Once that's verified then you can download the code as a multi-download group (whatever it's called in the IDE). I normally find it easier to coordinate multiple processor downloads from the command line like this:

    nios2-download -i 0 -g <elf1.elf>

    nios2-download -i 1 -g -r <elf2.elf>

    nios2-terminal -i 0

    nios2-terminal -i 1

    The -i lets you pick which Nios II JTAG debug module/JTAG UART you are using. The -g tells nios2-download to start executing code and -r means reset the target. Normally I open one terminal window per command shell so that I can watch the output of all the processors at the same time.

    --- Quote End ---

    Yes I'm using same things: command lines

    I put j as volatile but I've always same problem, Nios2 read a false value from the shared memory
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi,

    is there any problem if each CPU has its own on-chip memory containing the code to execute

    or I should have one instruction memory shared between the two NIOS???
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Both methods are fine. I normally keep the memories seperate to simplify things but combine them is fine too.

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

    But I've always same problem,

    please tell me how to share a memory between two cpu in order to share data???
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Depending on what I'm doing I typically either use a shared memory and a mutex or FIFOs to share data back and forth. You just connect them to the data master of each processor and both should be able to issue reads/writes to the shared data.

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

    --- Quote Start ---

    Depending on what I'm doing I typically either use a shared memory and a mutex or FIFOs to share data back and forth. You just connect them to the data master of each processor and both should be able to issue reads/writes to the shared data.

    --- Quote End ---

    Pl

    what version of qsys and NIOSII SBT are you using??
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I use all sorts of different versions, typically whichever is the latest is what I use. I haven't been working on Nios II projects lately so the last version was probably 12.0