Page 1 of 3

Serial Driver flush buffer

Posted: Wed Mar 15, 2017 1:11 pm
by vrollei
Hi!

Does it possible to flush serial driver buffer?

Thanks in advance!

Re: Serial Driver flush buffer

Posted: Wed Mar 15, 2017 7:08 pm
by Giovanni
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

Re: Serial Driver flush buffer

Posted: Thu Mar 16, 2017 8:46 am
by vrollei
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();

Re: Serial Driver flush buffer

Posted: Thu Mar 16, 2017 7:38 pm
by Giovanni
Hi,

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

Giovanni

Re: Serial Driver flush buffer

Posted: Thu Mar 16, 2017 7:54 pm
by vrollei
Thanks!

Re: Serial Driver flush buffer

Posted: Mon Mar 20, 2017 7:18 pm
by vrollei
Hi, Giovanni!

Is this right way to wait transmission complete:


[font=Courier New]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);[/font]

Re: Serial Driver flush buffer

Posted: Mon Mar 20, 2017 8:21 pm
by Giovanni
Hi,

It looks OK.

Giovanni

Re: Serial Driver flush buffer

Posted: Mon Mar 20, 2017 11:26 pm
by steved
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.

Re: Serial Driver flush buffer

Posted: Tue Mar 21, 2017 8:36 am
by vrollei
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....

Re: Serial Driver flush buffer

Posted: Tue Mar 21, 2017 1:37 pm
by Giovanni
Hi,

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

Giovanni