Pointer Function Error

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hi guys. 

   

PSoc Designer amazes me. I can not do ordinary operations(in C)..

   

When I run below code, it does not works.

   

FuncCb cbfunc = 0;
void main(void)
{
    
    if (0 == cbfunc) {
        f = foo;
        f();
}

   

 

   

But When I run below code, it is working

   

FuncCb cbfunc = 0;

   

FuncCb x = 0;
void main(void)
{
    
    if (x == cbfunc) {
        f = foo;
        f();
}

   

I think it is cast problem. But it is not problem in ANSI C. Does PSoC support all ANSI C rules?

   

Is there anyone with an idea?

0 Likes
4 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Can you please post the complete project example. We cannot see what runs and what not.

   

PSoC4 and 5 are running GCC which is ANSI C. PSoC3 might be a bit different.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

typedef void (*FuncCb)(void);

   

void callbackFunc(void)
{
    PRT0DR |= 0x01;
}

   

FuncCb pFunc = 0;  //it used to call related function
FuncCb emptyPointer; // test pointer. it used instead of 0 (NULL)address
void main(void)
{
    
    if (0 == pFunc ) {   // if you use emptyPointer instead of "0", it is working. But now it not working.
        pFunc  = callbackFunc;
        pFunc ();
    }
    
    while (1)
        ;
}

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Coderun,

   

what makes you expect me to

   
        
  • Create a new project in PSoC Designer 5.???
  •     
  • Guessing the Chip you used
  •     
  • Guessing the stack settings you made.
  •     
  • Pasting your code and then starting to compile
  •    
   

when you could deliver an archive which I could open right out-of-the box.

   

 

   

Bob

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Consider posting your project, makes life easier to troubleshoot.

   

 

   

“File”                                                           Designer

   

“Archive Project”

   

 

   

Regards, Dana. 

0 Likes