About casting , this works :
Code: Select all
cfg.callback= (void(*)(GPTDriver*))&Protocol::method;
BUT IT IS USELESS , inside the call back you have no reference to your class members, complier won't complain but you cannot use you class::method or your class variable , for me it was not obvious .
You need to pass the reference of your class as argument as chibios does for the driver reference.
Code: Select all
/** Uart callback assigned to class method*/
void protocol::method(UARTDriver *d){
classVariable = value; /** Not affecting classVariable*/
classMethod(); /** see the former */
}
So if you want to use some driver callback my conclusion is that you have to pass data , in this case chars on rx buffer , to the worker thread class with mailbox and so on.
Here some pseudo code , i haven't tried it yet:
Code: Select all
void txend(UARTDriver*, uint16_t c){
chMbPostI(mb, c ); /** and you need to share mailbox with worker thread class*/
}
class protocol : public BaseStaticThread<256> {
...
msg_t main(void){
while(1){
...
chMbFetch(mb,data,timeout);
.....
}
}
}
And what about changing your class internal state synchronously to a driver callback ?
you will need to know the reference of the worker thread or to the class itself , is it the cleanest way ?
Code: Select all
void rxend(GPTDriver* d , uint16_t c){
classRef->resumeI(msg); /** clean solution ? */
}
Design suggestions well accepted.