This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

C672x Variable passing

Hello:

I have a strange problem in some functions.  When I compile and simulate, the program does what it is suppose to.  However, when I compile and emulate, it does not.

The issue arises in the passing wdata variable into the function memsw().  For example: In the function setpga() the variable pgaset is passed correctly to the memsw() function.  In the function setanalsw(), the answsetup variable passed to the memsw() function is passed in as 0 (it simulates showing a pass of the correct value but, when run and debugged the value passed shows up as 0 and I can verify that the on board peripheal is not set)

Code:

void memsw(unsigned int Address, unsigned short wdata)
{
    unsigned short* AddressP;  
    AddressP= setadd13_19(Address);
    if (Address>=0x90000000 && Address<0x90040000){delay(0x00000100);}
    *AddressP=wdata;

    delay(0x0064);  }

The code above works fine for the call from setpga() but does not work for setanalsw().

unsigned short setpga (unsigned short pga, unsigned short fs, unsigned short swoe)
{
    unsigned short pgaset;
    pgaset=pga;
    pgaset=pgaset | (fs *4);
    pgaset=pgaset | (swoe *8);
    memsw(pga_fs_disp,pgaset);
    return pgaset;
}

The code above works fine

void setanalsw(unsigned short ch1, unsigned short ch2, unsigned short gm)
{
    unsigned short answsetup,x;
    answsetup=ch1-1;
    x=(ch2-1) * 8;
    answsetup=answsetup | x;
    x=gm * 64;
    answsetup=answsetup | x;
    memsw(analogch, answsetup);
}

The code above simulates fine but while running the processor does not interpret correctly.

I have verified that a direct write ie:  memsw(anlogch,0x0048); will set the peripheal to the expected condition.

I am booting from EEPROM, and am going through the GENAIS step.

Any clue what may be happening here.


  • Can you narrow it down further by stepping through the code?  Is the expected address being passed to memsw?  Try stepping through the code in both simulator and emulator to see at which point things are different.  Once you get to that point perhaps we can help you figure out why.

  • Here is the information that I recorded initially which caused me to document this:

    void setanalsw(unsigned short ch1, unsigned short ch2, unsigned short gm)
    {
        unsigned short answsetup,x;
        answsetup=ch1-1;
        x=(ch2-1) * 8;
        answsetup=answsetup | x;
        x=gm * 64;
        answsetup=answsetup | x;
       memsw(analogch, answsetup);         
    }

    For the code above in the simulator and the emulator, right before running the memsw(), the parameter for analgch=0x900C0020 and answsetup=0x0048 (based on the parameters of ch1=1, ch2=2 and gm=1 this is correct being passed into this function).  I single step into the function:

    At this point the Simulator reads Address=0x900C0020 and wdata=72 or 0x0048 and continues to be 72 after each step executed in the memsw() function.

    At this point the Emulator reads Address=0x900C0020 and wdata=0 and continues to be 0 after each single step executed in the memsw() function.

    void memsw(unsigned int Address, unsigned short wdata)
    {
        unsigned short* AddressP;  
        AddressP= setadd13_19(Address);
        if (Address>=0x90000000 && Address<0x90040000){delay(0x00000100);}
        *AddressP=wdata;

        delay(0x0064);  }

    The other functions which call on memsw() or if I call memsw() directly from the main, the variable being passed into wdata gets properly translated.

     

    The disassembly of the memsw() step in the setanalsw():

    10007BAC 02BCA22A            MVK.S2        0x7944,B5
    10007BB0 0288006B            MVKH.S2       0x10000000,B5
    10007BB4 01DD7028 ||         MVK.S1        0xffffbae0,A3
    10007BB8 00140363            B.S2          B5
    10007BBC 01880068 ||         MVKH.S1       0x10000000,A3
    10007BC0 020C0265            LDW.D1T1      *+A3[0],A4
    10007BC4 023CA286 ||         LDHU.D2T2     *+SP[5],B4
    10007BC8 01BDEA2A            MVK.S2        0x7bd4,B3
    10007BCC 0188006A            MVKH.S2       0x10000000,B3
    10007BD0 00002000            NOP           2

    The disassembly of the memsw() step in the pgaset()

    10007AE4 02BCA22A            MVK.S2        0x7944,B5
    10007AE8 0288006B            MVKH.S2       0x10000000,B5
    10007AEC 01DD7228 ||         MVK.S1        0xffffbae4,A3
    10007AF0 00140363            B.S2          B5
    10007AF4 01880068 ||         MVKH.S1       0x10000000,A3
    10007AF8 020C0265            LDW.D1T1      *+A3[0],A4
    10007AFC 023CA286 ||         LDHU.D2T2     *+SP[5],B4
    10007B00 01BD862A            MVK.S2        0x7b0c,B3
    10007B04 0188006A            MVKH.S2       0x10000000,B3
    10007B08 00002000            NOP           2

    Here is the disassembly of the first section of the memsw() function

    10007944          memsw:
    10007944 01BC94F6            STW.D2T2      B3,*SP--[4]
    10007948 00002000            NOP           2
    1000794C 023C82D6            STH.D2T2      B4,*+SP[4]
    10007950 023C22F4            STW.D2T1      A4,*+SP[1]
    10007954 00002000            NOP           2
    10007958 01BAE228            MVK.S1        0x75c4,A3
    1000795C 01880068            MVKH.S1       0x10000000,A3
    10007960 000C1362            B.S2X         A3
    10007964 01BCB82A            MVK.S2        0x7970,B3
    10007968 0188006A            MVKH.S2       0x10000000,B3
    1000796C 00004000            NOP           3
    10007970          C$RL0:

    Going one step further it seems B4 is the register which I can see the value of the pass variable for wdata.  In the pgaset() routine after exexcuting the 2 NOPs comes the first line in memsw() and the value in B4 is still present. in both the simulator and emulator

    In the setanalsw() routine after the 2 NOPs comes the first line in memsw() value in B4 is 0x048 in the simulator and 0 in the emulator..

    Let me know if there is anything else needed.

    Thank you for investigating this, Happy 4th.

     

  • dan kantorski said:

    The disassembly of the memsw() step in the setanalsw():

    10007BAC 02BCA22A            MVK.S2        0x7944,B5
    10007BB0 0288006B            MVKH.S2       0x10000000,B5
    10007BB4 01DD7028 ||         MVK.S1        0xffffbae0,A3
    10007BB8 00140363            B.S2          B5
    10007BBC 01880068 ||         MVKH.S1       0x10000000,A3
    10007BC0 020C0265            LDW.D1T1      *+A3[0],A4
    10007BC4 023CA286 ||         LDHU.D2T2     *+SP[5],B4
    10007BC8 01BDEA2A            MVK.S2        0x7bd4,B3
    10007BCC 0188006A            MVKH.S2       0x10000000,B3
    10007BD0 00002000            NOP           2

    The disassembly of the memsw() step in the pgaset()

    10007AE4 02BCA22A            MVK.S2        0x7944,B5
    10007AE8 0288006B            MVKH.S2       0x10000000,B5
    10007AEC 01DD7228 ||         MVK.S1        0xffffbae4,A3
    10007AF0 00140363            B.S2          B5
    10007AF4 01880068 ||         MVKH.S1       0x10000000,A3
    10007AF8 020C0265            LDW.D1T1      *+A3[0],A4
    10007AFC 023CA286 ||         LDHU.D2T2     *+SP[5],B4
    10007B00 01BD862A            MVK.S2        0x7b0c,B3
    10007B04 0188006A            MVKH.S2       0x10000000,B3
    10007B08 00002000            NOP           2

    Here is the disassembly of the first section of the memsw() function

    10007944          memsw:
    10007944 01BC94F6            STW.D2T2      B3,*SP--[4]
    10007948 00002000            NOP           2
    1000794C 023C82D6            STH.D2T2      B4,*+SP[4]
    10007950 023C22F4            STW.D2T1      A4,*+SP[1]
    10007954 00002000            NOP           2
    10007958 01BAE228            MVK.S1        0x75c4,A3
    1000795C 01880068            MVKH.S1       0x10000000,A3
    10007960 000C1362            B.S2X         A3
    10007964 01BCB82A            MVK.S2        0x7970,B3
    10007968 0188006A            MVKH.S2       0x10000000,B3
    1000796C 00004000            NOP           3
    10007970          C$RL0:

    Going one step further it seems B4 is the register which I can see the value of the pass variable for wdata.  In the pgaset() routine after exexcuting the 2 NOPs comes the first line in memsw() and the value in B4 is still present. in both the simulator and emulator

    In the setanalsw() routine after the 2 NOPs comes the first line in memsw() value in B4 is 0x048 in the simulator and 0 in the emulator..

    I highlighted a couple lines in red.  Those are the instructions where B4 is being loaded with data.  As you can see, that data is coming off the stack.  By the way, that data won't "land" in the B4 register until 5 cycles later due to pipelining.  That said, it seems to me that you need to go back a little further to find the root cause.  Specifically, do you see the proper data on the stack?  (There is not actually a SP register, the SP is an alias of B15.)  You should be able to look at the location pointed to by B15 + 2*5.  For example, if B15 = 0x01000000 then you should look at the contents of address 0x0100000A.  It would seem to me that somehow the value on the stack is wrong/corrupt/etc.

    You may also want to check the value of B15 itself.  It should always be double-word aligned (last 3 bits equal to 0) according to C compiler conventions.  If that's not the case something such as an assembly instruction has messed up the stack pointer and so things are "off".

    Brad

  • Disregard, I was going to post something, but something has changed.  I will reedit later.