It will raise all flags but only CHN_TRANSMISSION_END will wakeup your thread.
Giovanni
Serial Driver Event Handling Example
- Giovanni
- Site Admin
- Posts: 14457
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: Serial Driver Event Handling Example
OK, I have a code in a function that sends a packet:
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?
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?
- Giovanni
- Site Admin
- Posts: 14457
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: Serial Driver Event Handling Example
Try placing a breakpoint where CHN_TRANSMISSION_END is broadcasted.
Giovanni
Giovanni
Re: Serial Driver Event Handling Example
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!
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!
Return to “Development and Feedback”
Who is online
Users browsing this forum: No registered users and 47 guests