BitIO bean return value for GetVal doesn't match specification

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

BitIO bean return value for GetVal doesn't match specification

1,661 Views
armistej
Contributor III

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

 

Labels (1)
Tags (1)
0 Kudos
3 Replies

998 Views
jimtrudeau
Senior Contributor I

I don't know enough to technically answer this in detail, but let me make sure it does get a follow up.

0 Kudos

998 Views
armistej
Contributor III

Thanks Jim !

 

I am an old hand at writing embedded code, but a newbie when it comes to using Processor Expert.  I expect that the quality of the auto-generated code has to equal my own standard of what constitutes "good code", otherwise using a tool like Processor Expert becomes an exercise in frustration and futility.

 

I also noticed a typo for the AsynchroSerial bean

 

#ifndef __BWUserType_UART_TWRSER_TComData
#define __BWUserType_UART_TWRSER_TComData
  typedef word UART_TWRSER_TComData ;  /* User type for communication. Size of this type depends on the communication data witdh. */
#endif

Notice the mis-spelling of "width" as "witdh".

 

J

0 Kudos

998 Views
ProcessorExpert
Senior Contributor III

Hello,

 

the problem is, that ANSI C defines true  logical value as "any non-zero value" so it cannot be tested "something == TRUE".

When you need to check some boolean value, use if (something)... or if (!something) ...

 

Generally, when Processor Expert  returns "true", it does not refer to the "TRUE" constant, but to 'true' value in the sense of ANSI C language. It's a little bit tricky because the (something== TRUE) compiles, but doesn't work as expected.

Please see the Processor Expert user manual where there is a section 'Typical Usage of Component in User Code'  with subsection 'TRUE and FALSE Values of bool Type' describing the details.

 

Thank you for finding the typo in the AsynchroSerial , we will fix that.

 

best regards
Petr Hradsky
Processor Expert Support and Servicepacks Team

 

 

0 Kudos