- define my callback ( comm-lib.c )
typedef void (*com_callback)(const unsigned int iReceived);
const in parameter list is bit odd.
- declare internal callback ( comm-lib.c )
volatile static com_callback ReceivedData;
To be more precise, you not declare callback ^^ here, but define variable ReceivedData, which is a pointer to your callback routine.
- create function to assign call back ( comm-lib.c )
void uart_setcallback( void (*my_callback )(const unsigned int iReceived) );
You typedefed com_callback. You may retype this ^^ line simpler
void uart_setcallback( com_callback my_callback);
- declare my call back ( main.c )
com_callback com_binnen ( const unsigned int iReceived );
You declared ^^ here function com_binnen returning pointer to callback routine.
- and it implementation ( main.c )
com_callback com_binnen ( const unsigned int iReceived )
{
if ( iReceived == 2 )
{
}
}
- assign the callback ( main.c )
uart_setcallback ( *com_binnen );
When compiling i get a warning "Indirection to different types .................." but its compiling.
Can any one help me with what i'm doing wrong
Thanks
Peter
// define type com_callback, that will be a pointer to callback routine with following characteristics:
// return type - void
// arguments - unsigned int
typedef void (*com_callback)(unsigned int iReceived);
//Define callback function foo1
void foo1(unsigned int i)
{
}
//Define callback function foo2
void foo2(unsigned int i)
{
}
//Define pointer to callback routine, coult be static, volatile and combinations
com_callback Callback;
// routine to set Callback variable
void SetCallback(com_callback cb)
{
Callback = cb;
}
void test(void)
{
// set Callback directly
Callback = foo1;
// call Callback
Callback(123);
// set Callback using SetCallback
SetCallback(foo1);
SetCallback(foo2);
// call Callback
Callback(123);
}