Kurt Liebezite

Code optimizer prohibits bit-banging?!

Discussion created by Kurt Liebezite on Apr 21, 2010
Latest reply on Apr 23, 2010 by Kurt Liebezite

Hi, I'm having a problem where it appears that the CodeWarriror (4.6 btw) optimizer seems to be optimizing away my attempts to bit bang a sensor clock... here's what I've got.


In IO_Map.h we have this declaration for Port P:


/*** PTP - Port P I/O Register; 0x00000258 ***/
typedef union {
  byte Byte;
  struct {
    byte PTP0        :1;                                       /* Port P Bit 0 */
    byte PTP1        :1;                                       /* Port P Bit 1 */
    byte PTP2        :1;                                       /* Port P Bit 2 */
    byte PTP3        :1;                                       /* Port P Bit 3 */
    byte PTP4        :1;                                       /* Port P Bit 4 */
    byte PTP5        :1;                                       /* Port P Bit 5 */
    byte PTP6        :1;                                       /* Port P Bit 6 */
    byte PTP7        :1;                                       /* Port P Bit 7 */
  } Bits;
extern volatile PTPSTR _PTP @(REG_BASE + 0x00000258);
#define PTP                             _PTP.Byte

Then in my code I'm trying to do the following:


void ClearSensor(void) {
unsigned int i;

    // first, clock out NPIXELS pixels with SI low
    PTM &= ~0x10;     // set data input low
    PTP &= ~0x20;     // set clock low
    for (i= 0; i < NPIXELS; i++) {
        PTP |= 0x20;    // this statement executes
        PTP &= ~0x20;    // this statement does not execute
    }   // end for i

}    // end ClearSensor()


When I follow this code through the debugger the second statement in the for loop appears to never be executed.  I don't see wiggling on the Port P number 5 pin, either.  I was expecting the declaration of volatile on the PTP memory location would force the optimizer to always write to PTP regardless of other code nearby, but apparently I'm mistaken.  Any ideas?  I tried putting my bit  set/reset statements in separate functions that are called in place of the in-line statements, but I still have the same problem.