Page 2 of 2
Re: Serial Driver Event Handling Example
Posted: Thu Jan 11, 2018 7:27 pm
by Giovanni
It will raise all flags but only CHN_TRANSMISSION_END will wakeup your thread.
Giovanni
Re: Serial Driver Event Handling Example
Posted: Fri Jan 12, 2018 6:13 am
by king2
OK, I have a code in a function that sends a packet:
Code: Select all
chEvtWaitAny(EVENT_MASK(0));
eventflags_t pending = chEvtGetAndClearFlags(&cmdListener);
if (pending & CHN_TRANSMISSION_END) palClearPort(GPIOF, CONSOLE_DE);
In fact, after a time of working correctly (wakeup on CHN_TRANSMISSION_END only), it starts to wakeup thread (pass chEvtWaitAny() line) on other flags instead of CHN_TRANSMISSION_END. And from that time I see no CHN_TRANSMISSION_END set from chEvtGetAndClearFlags again.
Why?
How to handle CHN_TRANSMISSION_END correctly?
Re: Serial Driver Event Handling Example
Posted: Fri Jan 12, 2018 8:43 am
by Giovanni
Try placing a breakpoint where CHN_TRANSMISSION_END is broadcasted.
Giovanni
Re: Serial Driver Event Handling Example
Posted: Sun Jan 14, 2018 11:13 am
by king2
I got where mistake is: sdWrite() followed by chEvtWaitAny() and possibility for thread to be woken up not by my event only (and pass chEvtWaitAny for no good reason, i.e. with CHN_TRANSMISSION_END not set).
Sometimes it wakes up by unknown reason with flags = 0. It passes chEvtWaitAny(), and can start next sdWrite while actually it hasn't sent previous packet. From this time it gets previous event with CHN_TRANSMISSION_END immediately after sdWrite(), so DE line rises up and falling down very fast.
I gave up at this point and finished by patching interrupt routine, adding hardcoded line for falling DE line down, instead of playing games with events.
I can get fully asynchronous behaviour of DE line such way, and I can do something useful in my thread instead of just waiting for event.
Thank you for helping me!