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: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Serial Driver Event Handling Example

Postby Giovanni » Thu Jan 11, 2018 7:27 pm

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

Postby king2 » Fri Jan 12, 2018 6:13 am

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: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Serial Driver Event Handling Example

Postby Giovanni » Fri Jan 12, 2018 8:43 am

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

Postby king2 » Sun Jan 14, 2018 11:13 am

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!


Return to “Development and Feedback”

Who is online

Users browsing this forum: No registered users and 19 guests