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.

CC1110 and IAR compiler Non volatile object



Just want to check I am not going mad. Im trying to check the data returned from a call to IOCTL(IOCTL_OBJ_NVOBJ)

this contains a pointer to a pointer uint8_t **objPtr;

In the debugger objPtr appears to contain 0 but *objPtr looks like it has valid data.

So to try and confirm that I understand the double pointer I wrote the following code which doesn't work.1

1/ void SaveLinkTable(void)
2/ {
3/     smplStatus_t status;
4/     uint8_t *objPtr;
5/
6/     status = SMPL_Ioctl( IOCTL_OBJ_NVOBJ, IOCTL_ACT_GET, &LinkTable);
7/
8/     objPtr = *LinkTable.objPtr;
9/
10/    objPtr++;
11/    objPtr--;
12/    if( status == SMPL_SUCCESS)
13/    {
14/        if(objPtr != NULL)
15/        {
16/            writeFlash();
17/        }
18/    }
19/ }

Now line 6 works but status is invalid in the debugger at this point.

I CANNOT put a breakpoint on lines 8 or 10 or 11 or 12 because the debugger thinks they don't exist. The dissasembler doesn't show the C source.

When you run the code it jumps straight from line 6 to line14.

Can anyone shed some light on what is happening here.

PS lines 10 and 11 are only for debug puposes.

  • An update, I made two changes.

    mplStatus_t SaveLinkTable(void)
    {
        smplStatus_t status;
        volatile uint8_t *objPtr;

        status = SMPL_Ioctl( IOCTL_OBJ_NVOBJ, IOCTL_ACT_GET, &LinkTable);
     
        objPtr = *LinkTable.objPtr;
     
        objPtr++;
        objPtr--;
        if( status == SMPL_SUCCESS)
        {
            if(objPtr != NULL)
            {
                writeFlash();
            }
        }
        
        return status;
    }

    I don't know which of the two lines made it work but I can now put a break point on an line.

    Now it could be the optimisation settings which I havn't checked yet, but there is no excuse for optimising out one of the condtional statements.

    Can anyone can explain this and how to avoid it in future.

  • This is definitely related to optimization done by the compiler. It sees that it doesn't need to store the returned status from the IOCTL function (sufficient to have it stored in a register) nor the intermediate variable objPtr.

    By having your function return the status variable, the variable can no longer be removed from your code. And by declaring the other variable as volatile, the compiler knows that it's not allowed to remove any accesses to that variable.

    By turning optimization off completely in your project options, I believe you would be able to set breakpoints as expected in your original code.

  • Thanks for reply I thought it might be the optimizer, now checked and it was set high.

    Normally I can get away with it by making a variable volatile but the optimizer must be tto good for that.

    The thing that made me question it was that the debugger said the value was not available even though the if statement was still to be run so it should still be valid.

    Anyway it works now.

  • Since my last post I found a few bugs in my flash program and restore code which are now fixed.

    However I still cannot retore a saved link table (stored in sPersistInfo).

    I am almost certain that I restore the data that I saved but my application doesn't talk to its endpoints. I seems to be sending packets fine but my endpoint does not respond.

    Does anyone have any idea if I have missed anything here.

    My application is based on the linkto link listen demo and is peer to peer, except that I have an EP acting as a hub that concts to 8 endponts. The endpoints only ever listen and send a response if they recieve a packet. The hub polls each ep in turn with a single packet. so there should be no problem if the hub shuts down and restarts. Except that it doesn't work.

    The first time through you have to manually link all the endpoints. the link table is saved to flash and the application runs as expected. If I shut down the hub and restrart it the the previous link table is read from flash as expected  and restored as expected but the app doesn't pick up where it left off.

    I am sure I have missed something somewhere. The outline code of the hub is below.

    void main (void)
    {
    volatile     smplStatus_t status;
      BSP_Init();

      /* This call will fail because the join will fail since there is no Access Point
       * in this scenario. But we don't care -- just use the default link token later.
       * We supply a callback pointer to handle the message returned by the peer.
       */
        SMPL_Init(sRxCallback);

            if (BSP_BUTTON1() || BSP_BUTTON2())
            {
                DoRegistration();
            }
            else
            {
                status = RestoreLinkTable();
                if (status != SMPL_SUCCESS )
                {
                    DoRegistration();
                }
            }

        SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SETPWR, &LastPwrRequest);

        uart_intfc_init( );

      /* turn on LEDs. */
        LED_Off(2);
        LED_On(1);
     
      /* never coming back... */
      linkTo();

      /* but in case we do... */
      while (1) ;
    }

    static void DoRegistration(void)
    {
        uint8_t  listen = 1;

        while(listen)
        {
            while (SMPL_SUCCESS != SMPL_Link(& EndPoints [LinkCount].sLinkID1))
            {
                /* blink LEDs until we link successfully */
                toggleLED(1);
                SPIN_ABOUT_A_SECOND; /* manages FHSS implicitly */
                if (BSP_BUTTON1() || BSP_BUTTON2())
                {
                    listen = 0;
                    LinkCount--; /* need to dec here as we always inc */
                    break;
                }
            }
            LinkCount++; /* got one so move to next slot ready and inform user */
            if (LinkCount >= NUM_CONNECTIONS)
            {
                break;
            }
            toggleLED(2);
            SPIN_ABOUT_A_SECOND; /* manages FHSS implicitly */
            toggleLED(2);
        }
        SaveLinkTable();
        /* we're linked. turn off red LED. received messages will toggle the green LED. */
         LED_Off(2);
    }