function argument disappear

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

function argument disappear

3,205 Views
marcodz8
Contributor I
Hello, I'm trying to understand why a function created by Processor Expert stopped working.
 
#define byte unsigned char
 
byte ADC1_GetChanValue16(byte Channel,word *Value)
{
  if (Channel >= 6)                    /* Is channel number greater than or equal to 6 */
    return ERR_RANGE;                  /* If yes then error */
  if (!OutFlg)                         /* Is output flag set? */
    return ERR_NOTAVAIL;               /* If no then error */
  *Value = (word)((ADC1_OutV[Channel] << 6) / 200); /* Save measured values to the output buffer */
  return ERR_OK;                       /* OK */
}
****** LIST FILE *******
 
Function: ADC1_GetChanValue16
Source  : D:\CodeWarrior\SunTrack\Code\ADC1.C
Options : -BfaGapLimitBits0 -D_HCS12 -D__NO_FLOAT__ -Env"GENPATH=D:\CodeWarrior\SunTrack;D:\CodeWarrior\SunTrack\bin;D:\CodeWarrior\SunTrack\prm;D:\CodeWarrior\SunTrack\cmd;D:\CodeWarrior\SunTrack\Sources;C:\Programmi\Metrowerks\CodeWarrior CW12_V3.1\lib\HC12c\lib;C:\Programmi\Metrowerks\CodeWarrior CW12_V3.1\lib\HC12c\src;D:\CodeWarrior\SunTrack\Code;D:\CodeWarrior\SunTrack\doc;C:\Programmi\Metrowerks\CodeWarrior CW12_V3.1\lib\hc12c\include;C:\Programmi\Metrowerks\CodeWarrior CW12_V3.1\bin\Plugins\support\ProcessorExpert\PESL\HCS12;C:\Programmi\Metrowerks\CodeWarrior CW12_V3.1\bin\Plugins\support\ProcessorExpert;D:\CodeWarrior\SunTrack\src\common;D:\CodeWarrior\SunTrack\src\drivers\uart;D:\CodeWarrior\SunTrack\src\drivers\clock;C:\Programmi\Metrowerks\CodeWarrior CW12_V3.1\lib\HC12c\include" -Env"LIBPATH=C:\Programmi\Metrowerks\CodeWarrior CW12_V3.1\lib\HC12c\include" -EnvOBJPATH=D:\CodeWarrior\SunTrack\bin -EnvTEXTPATH=D:\CodeWarrior\SunTrack\bin -Lasm=%n.lst -Mb -ObjN=D:\CodeWarrior\SunTrack\SunTrack_Data\Lauterbach\ObjectCode\ADC1.C.o -WmsgSd1106 -WmsgSd1420 -WmsgSd4402 -WmsgSd5703
  0000 3b           PSHD 
  0001 3b           PSHD 
  287:    if (Channel >= 6)                    /* Is channel number greater than or equal to 6 */
  0002 e687         LDAB  7,SP
  0004 c106         CMPB  #6
  0006 2504         BCS   *+6 ;abs = 000c
  288:      return ERR_RANGE;                  /* If yes then error */
  0008 c602         LDAB  #2
  000a 202c         BRA   *+46 ;abs = 0038
  289:    if (!OutFlg)                         /* Is output flag set? */
  000c b60000       LDAA  OutFlg
  000f 2604         BNE   *+6 ;abs = 0015
  290:      return ERR_NOTAVAIL;               /* If no then error */
  0011 c609         LDAB  #9
  0013 2023         BRA   *+37 ;abs = 0038
  291:    *Value = (word)((ADC1_OutV[Channel] << 6) / 200); /* Save measured values to the output buffer */
  0015 87           CLRA 
  0016 59           ASLD 
  0017 59           ASLD 
  0018 b745         TFR   D,X
  001a ede20000     LDY   ADC1_OutV:2,X
  001e eee20000     LDX   ADC1_OutV,X
  0022 c606         LDAB  #6
  0024 160000       JSR   _LSHL
  0027 6e80         STX   0,SP
  0029 1ae8c8       LEAX  200,Y
  002c 34           PSHX 
  002d 35           PSHY 
  002e ee84         LDX   4,SP
  0030 160000       JSR   _LDIVU
  0033 ee82         LDX   2,SP
  0035 6c00         STD   0,X
  292:    return ERR_OK;                       /* OK */
  0037 c7           CLRB 
  293:  }
  0038 1b84         LEAS  4,SP
  003a 0a           RTC  
************************************
 
I use the function like this
 
unsigned int val = 0;
ADC1_GetChanValue16(4, &val);
 
Debuggin inside the function I get Channel always 0... and in val the corresponding of the calculation of ADC1_OutV[0]
Thinking coulb be a contant problem, I've used a local variable for passing the number 4, but it is the same.
 
Declaring a similar function thad does only the calculation in the same CODE and DATA SEG of the calling it works!!!
byte MyGetChanValue16(byte Channel,word *Value)
{
   *Value = (word)((ADC1_OutV[Channel] << 6) / 200); /* Save measured values to the output buffer */
  return ERR_OK;                       /* OK */
}
 
Personally I can't see the offset for the instruction LDY and LDX, but I'm not an Assembler developer.
  001a ede20000     LDY   ADC1_OutV:2,X
  001e eee20000     LDX   ADC1_OutV,X
I'm working with CW 3.1 fo HCS12 under WinXP SP2, but I've tried the CW 4.6 but the problem is still the same.
 
If can help, there is another strange thing it happen, to get the return value of same functions I have to declare the returning type. ie.
 
if((byte)ADC1_GetChanValue16(4, &val) != ERR_OK)  { //code// }
 
otherwise I don't get the correct return
 
 
Labels (1)
Tags (1)
0 Kudos
10 Replies

700 Views
marcodz8
Contributor I
Lundin, thanks for trying!
I'm just starting using Processor Expert because we are using some different microprocessor, and the annoying thing is to learn every time a new processor datasheet etc etc.
PE is a good idea but should create stable and portable code following all the standards... otherwise is better don't use it.
 
I will wait the response of ProcessorExpert, may be I don't know how to use PE correctly (I hope so).
0 Kudos

700 Views
marcodz8
Contributor I
Lundin: Thanks, I agree with your comment, do you think the change you proposed will make the firmware work?
 
The #define has been created automatically by PE
 
ProcessorExpert: The source code attached
 
I will wait some suggestion or solution from you.
 
Thanks for the help.
 
Message Edited by t.dowe on 2009-10-22 09:21 AM
0 Kudos

700 Views
CompilerGuru
NXP Employee
NXP Employee
I strongly recommend not to use any implicit parameter declaration - ever. The whole concept is just part of ANSI-C (89) because of compatibility with old code.
Try to compile with  -Wpd, that will cause any implicit parameter declaration to be an error. Then see which header file defines the function, and include the header file.

The code also shows many other warnings I would look into too.

Daniel
0 Kudos

700 Views
Lundin
Senior Contributor IV
I have no idea, I'm surprised that it even compiles. If PE generated that code, I would have tossed it out the window immediately, but then I'm personally no big fan of code-generating tools. I prefer to write the bugs myself :smileyhappy:
0 Kudos

700 Views
CompilerGuru
NXP Employee
NXP Employee
According to the zip file attached, it was not PE generated code but code using PE functions without actually including the corresponding header. So you can still try out PE :smileyhappy:.

Daniel
0 Kudos

700 Views
ProcessorExpert
Senior Contributor III
We have analyzed your project and we assume that your problems are not influenced by code generated by Processor Expert.

Generaly if you are using your own module, this module must contain the includes of header files for all beans that you want to use in your code. This is standard C approach of using functions from other modules.

For example if you want to use the bean named  ADC0 and ADC1 then your module must contain:

#include "ADC0.h"
#include "ADC1.h"

If your Motors.c will contain the mentioned includes the warning disappears.

Regarding PE generated code stability and portability, the code gnerated by all beans is thoroughly tested for each release including testing the correctly functionality of generated code on hardware.

best regards
Vojtech Filip
Processor Expert Support Team
UNIS

www.processorexpert.com
0 Kudos

700 Views
marcodz8
Contributor I
Yes, the compiler gives me an "implicit parameter-declarations" WARNING but I don't understand why. It gives me this warning for other function that I made
The declaration is
 
byte ADC1_GetChanValue16(byte Channel,word *Value);
 
where word is a
 
#define unsigned int word
 
I'm secure that I give to the function all the declared parameters...
 
I've just started working with CodeWarrior for HCS12, I've been using IAR for a lot of project.
However I've used CodeWarrior for ColdFire without this kind if issues.
 
Please help me to solve this problem.
 
0 Kudos

700 Views
Lundin
Senior Contributor IV
The compiler is correct. It gives you that warning because it can't find the type word, since the type was never properly declared.

You have re-defined the ISO C keyword "unsigned" to instead be a macro for text replacement, replacing the text "unsigned" with the text "int word".

Correct syntax is

typedef unsigned int word;
0 Kudos

700 Views
ProcessorExpert
Senior Contributor III
http://www.processorexpert.com/" rel="nofollow" target="_blank
Could you pleas provide your project for us team to analyse it?

best regards
Vojtech Filip
Processor Expert Support Team
UNIS

www.processorexpert.com
0 Kudos

700 Views
CompilerGuru
NXP Employee
NXP Employee
Do you include all the needed headers, are there any implicit parameter declarations?
Both the input and return value problem are typical for implicit parameter declarations, if the function does use byte's as the PE one.
Daniel
0 Kudos