Page 1 of 2
serial write completion and documentation mismatch
Posted: Fri Jan 28, 2011 1:24 am
by ianmga
While trying to do serial I/O over RS-485 I have to wait for serial write completion.
1) What's the best way to do this?
2) I am experimenting with different ways, say, waiting until the queue is empty, but I am finding that things that show up in the documentation (2.0.10) are not in the headers (2.1.7) like sdGetAndClearFlags or chOQIsEmpty. Are these TODO?
Thanks.
Ian
ps. Amazing piece of software you got here if I may say.
Re: serial write completion and documentation mismatch
Posted: Fri Jan 28, 2011 1:48 am
by liamstask
I believe the docs are only posted for the last stable release (2.0.x), and are not built for the last development release (2.1.x) so that would explain the mismatch...certainly many things have changed between those 2 versions. I think for the development release docs, you'd need to build them yourself with Doxygen (there are docs on how to do this), or just browse the source.
Although, I think that it would be helpful to indicate more clearly on the docs which release they correspond to. For example, both on the docs front page (
http://chibios.org/dokuwiki/doku.php?id ... :documents) and the front page for each of the individual docs (
http://chibios.sourceforge.net/docs/ker ... index.html, for example) it would be nice to indicate versions.
Re: serial write completion and documentation mismatch
Posted: Fri Jan 28, 2011 2:29 am
by ianmga
That's true. However, the documentation online is for 2.1.7 and has the same functions.
Related to this, sdGetStatusChangeEventSource() points to vmt->sevent that doesn't exists. Should it be vmt->event? And sdPutWouldBlock calls chOQIsFull which doesn't exist either.
ian
Re: serial write completion and documentation mismatch
Posted: Fri Jan 28, 2011 2:58 am
by ianmga
This did the trick. It's still inefficient at the end while waiting for the transmission complete flag (TC) but at least it's just whatever it's on the 16 byte output buffer and not the entire write buffer.
Code: Select all
EventListener el1;
USART_TypeDef *u = SD2.usart;
chEvtRegisterMask( chIOGetEventSource( &SD2 ), &el1, IO_OUTPUT_EMPTY );
// . . .
// write . . .
// wait the transmission complete
chEvtWaitAny( IO_OUTPUT_EMPTY );
while ( (u->SR & USART_SR_TC) == 0 )
;
Re: serial write completion and documentation mismatch
Posted: Fri Jan 28, 2011 9:26 am
by Giovanni
Hi Ian,
About the RS485, you may also consider the solution proposed in this thread by Joaquin:
viewtopic.php?f=2&t=34This solution does not involve any busy waiting.
Another option is to use the unbuffered UART driver, it has a callback on transmission end and is more suited for networking-like application. In 2.3.0 a specific event for "transmission end" will be added to the serial driver too.
The missing sdGetAndClearFlags() is a documentation error, in the latest unstable version the handling of the I/O flags has been moved from the serial driver into the BaseAsynchronousChannel super class, the function name now is chIOGetAndClearFlags() (note it is a macro). Thanks for finding the error, I will fix it before next release.
chOQIsEmpty() has been renamed to chOQIsEmptyI() in one of the latest releases, it is now an I-class API because it should be invoked from within a lock zone.
Giovanni
Re: serial write completion and documentation mismatch
Posted: Fri Jan 28, 2011 9:31 am
by Giovanni
I agree, it is confusing, I'll verify if Doxygen allows that.
Giovanni
Re: serial write completion and documentation mismatch
Posted: Fri Jan 28, 2011 9:02 pm
by ianmga
Interesting. I'll look at that topic. My intention is to move to the unbuffered driver eventually and use a linked timer to detect end of transmission (as in one of ST's application notes). I started down that route and got burned so fell back to the serial drivers which are more intuitive.
ian
Re: serial write completion and documentation mismatch
Posted: Fri Jan 28, 2011 10:18 pm
by Giovanni
You wouldn't need any timer, the UART driver has a callback for the transmission end.
Anyway, you are correct, the unbuffered driver is harder to use because its API was designed with finite state machines in mind, it is purely asynchronous. If you prefer a sequential synchronous approach then the buffered serial driver is the easiest way.
Giovanni
Re: serial write completion and documentation mismatch
Posted: Fri Jan 28, 2011 10:31 pm
by ianmga
Got it working. Great.
Re: serial write completion and documentation mismatch
Posted: Fri Jan 28, 2011 10:35 pm
by ianmga
Giovanni wrote:You wouldn't need any timer, the UART driver has a callback for the transmission end.
Anyway, you are correct, the unbuffered driver is harder to use because its API was designed with finite state machines in mind, it is purely asynchronous. If you prefer a sequential synchronous approach then the buffered serial driver is the easiest way.
Giovanni
I am sorry, I meant for the read. For the transmit end the callback takes care of it. For the read there's the problem of what happens when you're getting a packet that's not supposed to fill the buffer, so the read will get stuck. ST suggests a way of timing out using the hardware timers.
Ian