Serial Driver flush buffer

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
vrollei
Posts: 163
Joined: Sun Nov 13, 2016 8:44 am
Been thanked: 26 times

Serial Driver flush buffer

Postby vrollei » Wed Mar 15, 2017 1:11 pm

Hi!

Does it possible to flush serial driver buffer?

Thanks in advance!
Vitaly

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 flush buffer

Postby Giovanni » Wed Mar 15, 2017 7:08 pm

Hi,

If you want to erase all the buffered content there are two ways:

1) Read and discard all content using TIME_IMMEDIATE, you get MSG_TIMEOUT when the queue is empty.
2) Reset the queue directly using iqResetI().

osalSysLock();
isResetI();
osalOsRescheduleS();
osalSysUnlock();

You may use "ch" function instead of "osal" functions, it is the same.

Giovanni

vrollei
Posts: 163
Joined: Sun Nov 13, 2016 8:44 am
Been thanked: 26 times

Re: Serial Driver flush buffer

Postby vrollei » Thu Mar 16, 2017 8:46 am

Hi,

I mean output buffer, is there any method to force driver process all output buffer to implement this scenario:

sdStart();
chprintf("log message");
// force driver to process log message before stop it
sdStop();
Vitaly

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 flush buffer

Postby Giovanni » Thu Mar 16, 2017 7:38 pm

Hi,

There is a specific event flag for transmission complete, you need to wait for that.

Giovanni

vrollei
Posts: 163
Joined: Sun Nov 13, 2016 8:44 am
Been thanked: 26 times

Re: Serial Driver flush buffer

Postby vrollei » Thu Mar 16, 2017 7:54 pm

Thanks!
Vitaly

vrollei
Posts: 163
Joined: Sun Nov 13, 2016 8:44 am
Been thanked: 26 times

Re: Serial Driver flush buffer

Postby vrollei » Mon Mar 20, 2017 7:18 pm

Hi, Giovanni!

Is this right way to wait transmission complete:


event_listener_t serial_listener;

chEvtRegisterMaskWithFlags(&(SD2.event), &serial_listener, EVENT_MASK(0), CHN_TRANSMISSION_END);

sdStart(&STDOUT_SD, &SD2Config);

<write to STDOUT_SD>

while (true) {
chEvtWaitAny(EVENT_MASK(0));
if (chEvtGetAndClearFlags(&serial_listener) & CHN_TRANSMISSION_END) {
break;
}
}

sdStop(&STDOUT_SD);
Vitaly

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 flush buffer

Postby Giovanni » Mon Mar 20, 2017 8:21 pm

Hi,

It looks OK.

Giovanni

steved
Posts: 823
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 135 times

Re: Serial Driver flush buffer

Postby steved » Mon Mar 20, 2017 11:26 pm

At risk of stating the obvious, dependent on your application you may need to check that there is a transmission in progress before waiting for it to complete. Or just add a timeout into the event wait.

vrollei
Posts: 163
Joined: Sun Nov 13, 2016 8:44 am
Been thanked: 26 times

Re: Serial Driver flush buffer

Postby vrollei » Tue Mar 21, 2017 8:36 am

Hi,

is there no queue for events? In this case you are right, there is a chance to wait forever.
Can not figure out how to check that transmission is in progress....
Vitaly

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 flush buffer

Postby Giovanni » Tue Mar 21, 2017 1:37 pm

Hi,

Events are bit masks, there is no queuing. You need to make sure there are no events pending before starting transmission.

Giovanni


Return to “ChibiOS/HAL”

Who is online

Users browsing this forum: No registered users and 8 guests