[En-Nut-Discussion] Any way to get an interupt (NutEventWait) when a UART RX buffer has something in it?
Ole Reinhardt
ole.reinhardt at embedded-it.de
Mon Nov 11 09:14:31 CET 2013
Hi Steve,
> I've got a UART (ARM7) that may get unexpected asynchronous input. I have
> multiple threads running and if the UART gets something, I like to switch
> that thread and service the UART (read the buffer).
>
> Is there a something like an internal interrupt that I can use or some how
> use NutEventWait?
>
> Right now I'm polling and checking the buffer. It works but I don't like
> it and I'm afraid it's slow and I might be missing something.
I'm not sure if I completely understood your use-case.
Do you want to keep your thread running while waiting on some data to
arrive? (Non-blocking read)
Or do you just want to read data, that arrived?
The second case is quite simple. Just do a read() on your UART file
descriptor. It will return as soon as the wanted amount of data arrived.
You could even read the characters one at at time, so you would not have
to wait until the buffer got filled.
The first case offers you several solutions:
Non blocking read:
------------------
You could set a read-timeout:
_ioctl(_fileno(dev), UART_SETREADTIMEOUT, &t);
In this case, the read will timeout latest after t milliseconds. So your
read() function will never block longer than this timeout. If no data
was received until the timeout, read() will return 0
Monitor file descriptors using select():
----------------------------------------
I'm currently doing some final grinding on the devnut_select_or branch,
where I'm currently working on a select() implementation. Currently
USARTs and TCP sockets are supported.
If you do not know, what select does, have a look to:
http://www.gnu.org/software/libc/manual/html_node/Waiting-for-I_002fO.html
or it's man-page:
http://man7.org/linux/man-pages/man2/select.2.html
Best regards,
Ole Reinhardt
--
kernel concepts GmbH Tel: +49-271-771091-14
Sieghuetter Hauptweg 48 Mob: +49-177-7420433
D-57072 Siegen
http://www.embedded-it.de
http://www.kernelconcepts.de
More information about the En-Nut-Discussion
mailing list