Invalid variable name list or ????
pmrobert
Posts: 675
I am a novice with Prop GCC and SimpleIDE. While doing some experimentation with passing values between cogs I found that use of "pw" as a variable name is not reported as an error but does prevent my very simple program from running as expected. I can declare a 'pw" and all is fine until I assign it a value. If I change it's name to "pw1" the code works as expected, toggling P1 at period = 1000 usec and pulsewidth 500 usec. I have included the simplest possible code that demonstrates the observed behavior. What have I overlooked? The specifics are Win7-64 dev machine, latest SimpleIDE (0.9.45), C3 board type, compiled as LMM Main RAM, C compiler type, optimization changes made no difference.
#include "simpletools.h" // Include simpletools library // For LMM cog 160 bytes declared as int // Add enough for stack & calcs (50 bytes declared as int unsigned int stack[(160 + (50 * 4)) / 4]; // Declare volatile variables that will not be optimized // to one variable for both cogs to share. volatile unsigned int pin; volatile unsigned int per; volatile unsigned int pw1; volatile unsigned int pw; // Function prototype void inj_drive(void *par); // Cog 0 starts here int main() { pin = 1; //pw = 500; // This does not work pw1 = 500; // This works per = 1000; // Pass function pointer, optional parameter value, // stack array address, and the stack's size to cogstart. volatile int cog = cogstart(&inj_drive, NULL, stack, sizeof(stack)); while(1); } // Cog 1 starts executing code in this function in // parallel. Hooraaay! void inj_drive(void *par) { pwm_start(per); pwm_set(pin,0,pw1); // This works //pwm_set(pin,0,pw); //This does not. while(1); }
Comments
EDIT: The simpletools.h file does contain function prototypes for some of the pwm functions, but it doesn't have a prototype for the pw function. If it did have a prototype the compiler would have caught the error. The pw function in pwm.c should probably have been made static so that it wouldn't conflict with user variables.
-Mike
Silent conflicts are normally avoided by using unique names and using function prototypes, or making variables and functions static that don't need to be accessed from another file. The pmw library object should have either included a function prototype for pw in simpletools.h or made the pw function static. I would suggest contacting Parallax and letting them know about the problem.