I have created a pair of files: user_common.c and user_common.h and added them to the workspace. user_common.h includes user_common.c . Inside user_common.c are several functions I use during an interrupt to read a sensor. all functions in user_common.c are stated in user_common.h with the return type and any parameters in () then followed by a semicolon. In each file where any function from user_common.c is used, user_common.h is included. When I make or build everything, the build succeeds but for each function i used that came from user_common.c, I receive the following error:
" file path : line number : Warning [2058] call of function without prototype ". I have no idea what it means, but the functions don’t work. Could this error be a side effect of the problem that is preventing the functions from working correctly? Any help would be appreciated.
Post the two files for us to check out.
My guess is you have something as follows…
#include "user_common.h"
main
{
foo();
}
void foo(void)
{
// Do something
}
Try adding a function prototype for foo() to your user_common.h file.
void foo(void);
From this article
A declaration or prototype is a way of telling the compiler the data types of the any return value and of any parameters, so it can perform error checking.
Essentially your compiler is complaining that you’re using a function that it doesn’t know about.
Something to also consider…
If you are using the functions in files other than user_common.c, you will probably have to use prepend the prototype with extern and include user_common.h in those files
extern foo(void);
This tells the compiler that the file will be using a function that is defined externally to the file being compiled.
I hope you meant that the other way around. Never, ever, do a #include “myfile.c” unless you want a big headache
Thank you all. I will take another look at the code and try your suggestions and see if they work. I’ll let you know what happens.
Adding the “void” in the parentheses prevented all but one of the warnings. Before the addition, every time a function from user_common.c was called, I would get the warning. Now i only get the warning when I call the initialization function.
I am going to post the code on the assumption that I can trust the users of this site to not steal my ideas unless they have already thought of it on their own. Please do not make this assumption incorrect.
The user_common.h is as follows:
#ifndef _user_common_h
#define _user_common_h
/***************************************************************/
extern unsigned char rc_dig_in03last;
extern long tmpcount;
extern int inturrupt;
/***************************************************************/
void init_HallEffect(void);
void updateSpeed(int pwmL, int pwmR);
void setLastPWM(void);
void handleHallEffect(void);
long getCountLeft(void);
long getCountRight(void);
/***************************************************************/
#endif
I tried using extern before each function but it had no effect.
Here is user_common.c:
#include “user_common.h”
#include “ifi_aliases.h”
#include “ifi_default.h”
int prevL, prevR, currL, currR; /*used when determining
which direction to count when changing the count in update speed,
init_hallEffect and setLastPWM */
unsigned char lastPWMLeft, lastPWMRight, lastPORTB; /used to find
change in sensors, and keep track of direction/
long countLeft, countRight; /used to keep track of increments
sensed by the hallEffect sensors/
unsigned char rc_dig_in03last;
long tmpcount;
int inturrupt = 0;
/***************************************************************/
void init_HallEffect(void)
{
/init wheel counts to 0 each/
countLeft = 0;
countRight= 0;
/first initialization of PORTB/
lastPORTB = PORTB;
/init for prev left and right pwm values/
prevL = 129;
prevR = 129;
digital_io_03 = 1;
digital_io_04 = 1;
INTCON2bits.RBPU = 0;
tmpcount = 5;
rc_dig_in03 = 0;
rc_dig_in03last = rc_dig_in03;
/inti inturrupt flag bit enabled/
INTCONbits.RBIE = 1;
}
/***************************************************************/
/***************************************************************/
/here comes the code to set lastPWMLeft/Right./
void updateSpeed(int pwmL, int pwmR)
{
currL = pwmL;
currR = pwmR;
}
/***************************************************************/
/***************************************************************/
void setLastPWM(void)
{
if (currL != 128)
{
lastPWMLeft = currL;
prevL = currL;
}
else
{
if (prevL > 128)
{
lastPWMLeft = 200;
}
else if (prevL < 128)
{
lastPWMLeft = 50;
}
}
if (currR != 128)
{
lastPWMRight = currR;
prevR = currR;
}
else
{
if (prevR > 128)
{
lastPWMRight = 200;
}
else if (prevR < 128)
{
lastPWMRight = 50;
}
}
}
/***************************************************************/
/***************************************************************/
/inturrupt code/
void handleHallEffect(void)
{/left sensor = rc_dig_in03, right = rc_dig_in04: left = bit 4,
right = bit 5/
unsigned char thisPortB, change;
thisPortB = PORTB & 0b00011000;
change = thisPortB ^ lastPORTB;
switch(change)
{
case 0: break;
case 48:
{
if (lastPWMLeft > 128)
{
countLeft ++;
}
else if (lastPWMLeft < 128)
{
countLeft --;
}
if (lastPWMRight > 128)
{
countRight ++;
}
else if (lastPWMRight < 128)
{
countRight --;
}
break;
}
case 16:
{
if (lastPWMLeft > 128)
{
countLeft ++;
}
else if (lastPWMLeft < 128)
{
countLeft --;
}
break;
}
case 32:
{
if (lastPWMRight > 128)
{
countRight ++;
}
else if (lastPWMRight < 128)
{
countRight --;
}
break;
}
}
}
/***************************************************************/
/***************************************************************/
long getCountLeft(void)
{
return countLeft;
}
/***************************************************************/
/***************************************************************/
long getCountRight(void)
{
return countRight;
}
/***************************************************************/
I apologize if it is difficult to read. Code does not paste well into these windows.
Here is where the functions are used:
In user_routines.c:
in User_Initialization:
{
…
init_HallEffect();
}
in Default_Routine
{
inside the #if and #else statements where the pwm values are set…
right at the end of each block: updateSpeed();
after that for testing purposes: I put a printf displaying the count values recieved from getCountLeft() and getCountRight();
}
in user_routines_fast.c
in InturruptHandlerLow()
{
inside the section that checks INTCONbits.RBIF and INTCONbits.RBIE…
setLastPWM();
handleHallEffect();
}
Even with the void in the parentheses, I still get the warning about init_HallEffect(); at the location where it is called.
Besides that, the display is always zero for both sensor counters. Does anyone see a problem that I missed? user_common.h and user_common.c are direct copy and paste. The locations of the calls are description mostly. If anyone has any questions, feel free to ask. I will try to answer them.
Thank you all.
P.S. I am sorry about the length of this post.
Try using a code block (replace the <'s in the text below with a )
<code]code goes here</code]
Is it safe to say that you’re including user_common.h in both user_routines.c and user_routines.h?
I put a printf displaying the count values recieved from getCountLeft() and getCountRight()
What if you put a print in those functions? Are you sure they’re getting called? Did you typecast your variables in your printf?
OK, quick probably stupid question once I get a response. How does one upload their program to the robot? Do we use the IFI Loader the same way as for loading the new firmware or whatever it was? I have code and it debugs ok so I would like to load to the robot. I haven’t used this program before (I’m using the Mplad IDE), and last year someone else did programming on the other team I was on. I did the programming previously for 3/4 years with basic so I understand the most part, just don’t know how to upload! :ahh:
-Mike
Yes, use the IFI loader with the hex file that was created when you compiled your code.
Thank you, I thought that was it but it seemed odd. Thanks alot. now we can complete our robot.
I included user_common.h in user_routines.c, but I didn’t know I needed to or should include it in user_routines.h . I did not put a printf in the get functions and I don’t know for sure if they are being called. I did not consciously typecast the printf. What must be done to the printf? I will try the added include and the extra printf. Please tell me more about the typecasting of printf. Also, thanks for telling me about the code block.
That’s because I mistyped…I meant to say user_routines_fast.c…you shouldn’t include user_common.h in user_routines.h…
Please tell me more about the typecasting of printf.
Eugene Brooks had a good explanation in this thread about casting variables and printf.
He gives an example of how to perform the casting right above that explaination
Ok. Thanks. If that is the case, then I did include user_common.h in user_routines.c and user_routines_fast.c . I also was not typecasting the variables in the printf statement. I will try that.
Thanks to all who contributed suggestions. The problem has been resolved.
Thanks again
PVC Pirates