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.

Code Composer Optimizer

Hello:

We encountert a problem with the optimization in Code Composer 4.1.3, 5.2.1, 6.2.5, 6.4.6, LTS 15.12.0. Is it known and how we get arround it?

struct CCanQueue
{
 unsigned short *  Pending_In; 
 unsigned short *  Pending_Out;
} ;
unsigned short Spi_Out_Queue_Ctr;

void error_example ( struct CCanQueue * pQueue , short unsigned *CanBuf ) 
{
   short unsigned       nummsg ;
  short unsigned     NumWords ;
  short unsigned * pQExpected ;
  long            nWords2Send ;

 nWords2Send = (long) pQueue->Pending_In - (long) pQueue->Pending_Out ;
 /*=============================================================================================
  When this code is compiled with the optimizer, the code below "if ( nWords2Send < 0 )" is ignored.
  When the nWords2Send parameter is defined as "long  volatile" the compiler does not ignore it!
  but we don't know it until we we have a failure!
 ==============================================================================================*/
 if ( nWords2Send < 0 )
  {
   nWords2Send += 160 ; // Cyclic buffer roll
  }
 /*=============================================================================================
  End of optimizer ignored code
 ==============================================================================================*/
 nWords2Send = _IQsat (  (long) (58 - Spi_Out_Queue_Ctr ) , (long)nWords2Send , 0  ) ;
 nummsg = (short unsigned)_IQ16mpy(  nWords2Send ,13108 ) ; // 13108 is _IQ16(0.2) + epsilon

 NumWords = nummsg * 5 ;

 pQExpected = pQueue->Pending_Out + NumWords ;

 if ( pQExpected >= (CanBuf + 160) )
  {
   pQExpected -= 160 ;
  }
  
 pQueue->Pending_Out = pQExpected ;

}

Regards Arye