This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Debug Skipping Function with IF ELSE

Summary: Device TI MSC1210

A user function called in main passes a pointer to an array and either a 1 or a 0. The function uses the 1/0 to decide which serial port to use. It then outputs data from the pointed array over serial N.

I have tried the function with both a case statement and an if-else.

MAIN is an opcode handler which recieves serial opcodes and calls function based on those. When the opcode is given to call the above mentioned function, the function is stepped over.

If I remove the case or if-else from the function and hardcode one serial port or the other, it calls just fine.

Any ideas?

I can post the code, but it'll have to wait till monday.

Parents
  • code snippet showing the general idea:

    void SerialXmit(BYTE * pArray, bit n)
    {
    if(n == 1)
    {
    //Use Serial Port 1
    // transmit pArray stuff
    }
    else if( n == 0)
    {
    //Use Serial Port 0
    // transmit pArray stuff
    }
    }

    void MAIN()
    {
    //Initialization Stuff
    BYTE DataArray [4];
    BYTE * pArrayStart;
    pArrayStart = DataArray[0];

    while(1)
    {
    switch(opcode)
    {
    case opcode4:
    SerialXmit(pArrayStart,1);
    break;
    // rest of cases...
    }
    }
    }

Reply
  • code snippet showing the general idea:

    void SerialXmit(BYTE * pArray, bit n)
    {
    if(n == 1)
    {
    //Use Serial Port 1
    // transmit pArray stuff
    }
    else if( n == 0)
    {
    //Use Serial Port 0
    // transmit pArray stuff
    }
    }

    void MAIN()
    {
    //Initialization Stuff
    BYTE DataArray [4];
    BYTE * pArrayStart;
    pArrayStart = DataArray[0];

    while(1)
    {
    switch(opcode)
    {
    case opcode4:
    SerialXmit(pArrayStart,1);
    break;
    // rest of cases...
    }
    }
    }

Children
  • Here's the listing I get for your SerialXmit function:

                 ; FUNCTION _SerialXmit (BEGIN)
                                               ; SOURCE LINE # 3
    ;---- Variable 'pArray' assigned to Register 'R1/R2/R3' ----
                                               ; SOURCE LINE # 4
                                               ; SOURCE LINE # 5
    0000 300004      R     JNB     n,?C0001
                                               ; SOURCE LINE # 6
                                               ; SOURCE LINE # 7
    0003 7441              MOV     A,#041H
                                               ; SOURCE LINE # 10
    0005 8005              SJMP    ?C0010
    0007         ?C0001:
                                               ; SOURCE LINE # 11
    0007 200005      R     JB      n,?C0004
                                               ; SOURCE LINE # 12
                                               ; SOURCE LINE # 13
    000A 7442              MOV     A,#042H
    000C         ?C0010:
    000C 120000      E     LCALL   ?C?CSTPTR
                                               ; SOURCE LINE # 16
                                               ; SOURCE LINE # 17
    000F         ?C0004:
    000F 22                RET
                 ; FUNCTION _SerialXmit (END)
    

    It looks fine to me.

    Actually, I had to modify your example to get it to compile:

       1          typedef unsigned char BYTE;
       2
       3          void SerialXmit(BYTE * pArray, bit n)
       4          {
       5   1      if(n == 1)
       6   1      {
       7   2      *pArray='A';
       8   2      //Use Serial Port 1
       9   2      // transmit pArray stuff
      10   2      }
      11   1      else if( n == 0)
      12   1      {
      13   2      *pArray='B';
      14   2      //Use Serial Port 0
      15   2      // transmit pArray stuff
      16   2      }
      17   1      }
    

    Jon

  • Well, I got back to work this morning and started poking around through the compiler outputs. Turns out it was indeed skipping the call.

    I changed the optimization settings, recompiled, and viola - function called properly.

    Thanks for the replies.

  • Can you please contact technical support about the code that was skipping the call so we can take a look at it and get this problem corrected?

    Jon