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.

Errors while porting from GCC to Code Composer Studio compiler

Hi I am working on a RTOS. The RTOS code is available for IAR and GCC compiler. However I need it to work i with CCS. I have changed mny things including the syntax of interrupt declare. However there are some assembly codes which are causing errors and I am unable to resolve them despite me looking for solution desperately. I am using CCS 6.0 and I have successfully compiled the mentioned code in RHGCC GNU 4.9.1. Now I want to compile it in TI compiler v 4.3.3.

The errors I am receiving are all the same kind. and in the same file and are concerned only to two functions. So wherever these functions are used, i get the error.

The file I am getting errors is "tiros.c" and the error is "#18 expected a ")""

Where ever these following lines are used, i get the error

OS_CRITICAL_BEGIN();

OS_CRITICAL_END();

when I right click and "Open Declaration", I get following lines in "tiros.h"

/** Begin a critical section.
 *  
 *  This should always be matched with an
 *   OS_CRITICAL_END() in the same function. Critical sections should be
 *  enabled in the function using  OS_CRITICAL_ENABLE() */
#define OS_CRITICAL_BEGIN()      OS_PORT_CRITICAL_BEGIN()

/** End a critical section.
 * This should be matched to a corresponding \ref OS_BEGIN_CRITICAL() call. */
#define OS_CRITICAL_END()        OS_PORT_CRITICAL_END()

when I right click OS_PORT_CRITICAL_BEGIN() and OS_PORT_CRITICAL_END() then click "Open Declaration" , I get following lines in "tr_port.h".

/* Begin a critical section 
 * 
 * The current interrupt state is saved in osint_int_status and then
 * interrupts are disabled 
 *  According to MSP430 documentation Pg 3-39, 3-40, the instuction
 * following EINT is always executed even if an ISR is pending.
 * Similarly, if any code sequence should be protected from
 * interruption, the DINT should be executed at least one instruction
 * before the uninterruptible sequence, or be followed by a nop. 
 * The osint_int_status &= GIE, saves only the interrupt
 * state. Similarly, only the interrupt state is restored later.
 * In this case, we don't add a NOP in OS_PORT_CRITICAL_BEGIN since
 * dint is followed by a non critical instruction.
*/
#define OS_PORT_CRITICAL_BEGIN()  \
    asm volatile("mov   r2, %0  \n\t"  \
                 "dint          \n\t" :  "=r" (osint_int_status)  : ); \
         osint_int_status &= GIE; 



/* End a critical section
 *
 * The saved interrupt state is restored */
#define OS_PORT_CRITICAL_END()  \
    asm volatile("bis  %0, r2   \n\t" \
                 "nop           \n\t" : : "r" (osint_int_status) );

because I dont know any assembly language, I am clueless however it seems all perfect to me since the same code compiles with GNU 4.9.1.

Can anyone please identify whats wrong here and provide solution?

Also tiros.h indirectly includes tr_port.h via tr_types.h.

  • The TI compiler does not support GCC-style asm statements.

    Thanks and regards,

    -George

  • Thanks George


    So should I convert it to C/C++ and then it should compile? or should i convert to asm format which is used by CCS. Can you please point me to some resource where I can learn this.

    Regards

  • The TI MSP430 compiler provides C intrinsics for many device instructions like this that might be accessed by inline assembly in GCC. In this case, I believe the intrinsics that you need for these macros are __get_interrupt_state(), __disable_interrupts(), and __set_interrupt_state(). They are documented in the compiler user's guide.
  • There are some intrinsics related to interrupts.  Read about them in the section titled MSP430 Intrinsics in the MSP430 compiler manual.  I lack the expertise to advise you on exactly which intrinsics to use in this situation.  If you need more help, consider starting a new thread in the MSP430 device forum.  Or, if you prefer, I can move this thread into that forum.

    Thanks and regards,

    -George

  • Thanks petec. It helped.

    Now my code look likes the following. Actually I also got some help from the RTOS files for IAR.

    #define OS_PORT_CRITICAL_BEGIN() \
    
       osint_int_status = _get_interrupt_state(); \
    
       _disable_interrupt()
    
    /* End a critical section
    
    *
    
    * The saved interrupt state is restored */
    
    #define OS_PORT_CRITICAL_END()  \
    
       _set_interrupt_state(osint_int_status);
    
    /* Enable interrupts
    
    * This allows the user to explicitly enable interrupts */
    
    #define OS_PORT_INT_ENABLE()      _enable_interrupt()
    
    /* Disable interrupts
    
    * This allows the user to explicitly disable interrupts */
    
    #define OS_PORT_INT_DISABLE()     _disable_interrupt()

    However if you see the actual code in my first post, in the definition of OS_PORT_CRITICAL_BEGIN() there is

    osint_int_status &= GIE;

    can you suggest what this is the purpose of this line? do I still need to place this line in the new code?

  • Mohammad Hassan Shahid said:
    can you suggest what this is the purpose of this line? do I still need to place this line in the new code?

    That code is specific to the OS implementation.  We lack the expertise to help you with that.

    Thanks and regards,

    -George