Serial Driver Event Handling Example

This forum is dedicated to feedback, discussions about ongoing or future developments, ideas and suggestions regarding the ChibiOS projects are welcome. This forum is NOT for support.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Serial Driver Event Handling Example

Post by Giovanni »

It will raise all flags but only CHN_TRANSMISSION_END will wakeup your thread.

Giovanni
king2
Posts: 98
Joined: Mon May 28, 2012 1:57 pm
Been thanked: 2 times

Re: Serial Driver Event Handling Example

Post 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?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Serial Driver Event Handling Example

Post by Giovanni »

Try placing a breakpoint where CHN_TRANSMISSION_END is broadcasted.

Giovanni
king2
Posts: 98
Joined: Mon May 28, 2012 1:57 pm
Been thanked: 2 times

Re: Serial Driver Event Handling Example

Post 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!
Post Reply