Jason Armistead

BitIO bean return value for GetVal doesn't match specification

Discussion created by Jason Armistead on Jun 20, 2011
Latest reply on Jun 22, 2011 by Processor Expert

I am using CodeWarrior 6.3.1 Patch, Build 10105 for ColdFire V1

 

Here is the auto-generated macro code for PutVal for my input SW2

 

/*
** ===================================================================
**     Method      :  SW2_GetVal (component BitIO)
**
**     Description :
**         This method returns an input value.
**           a) direction = Input  : reads the input value from the
**                                   pin and returns it
**           b) direction = Output : returns the last written value
**         Note: This bean is set to work in Input direction only.
**     Parameters  : None
**     Returns     :
**         ---             - Input value. Possible values:
**                           FALSE - logical "0" (Low level)
**                           TRUE - logical "1" (High level)

** ===================================================================
*/
#define SW2_GetVal() ( \
    (bool)((getReg8(PTGD) & 0x40))     /* Return port data */ \
  )

 

/* END SW2. *

 

The problem I am seeing is that it is NOT returning the values of TRUE  when the input is at a logical high level.

 

If I write code like the following, it doesn't work:

 

x= 0;

if (SW_GetVal() == TRUE)

{

 x = 1;

}

 

The value of x always remains zero.  Stepping with the debugger, I can see that this is because the macro for SW_GetVal() actually returns a value of 0x40 when the input is ON, which is not equal to the macro definition of TRUE which is 1.

 

So, I'm left to re-write my code as

 

x= 0;

if (SW_GetVal() != FALSE)

{

 x = 1;

}

 

Please fix the bug in the code generation for the BitIO bean's GetVal() function.  Either change the documentation, or change the way the code is generated.  They have to be consistent, otherwise by simply believing the "Returns" values as shown in the auto-generated function header, a programmer gets led down the wrong path.

 

Processor Expert's auto-generated code *MUST* be implemented better than this !!!

 

Slightly frustrated

J

 

Outcomes