[En-Nut-Discussion] Problem: read uart port
urbi
Urban.Battaglia at ch.TRUMPF.com
Fri Mar 20 17:35:27 CET 2009
Adam Dybkowski wrote:
>
> Ole Reinhardt wrote:
>
>> Just write the code like this:
>>
>> int got
>> int offset = 0;
>> static char inbuf[58];
>>
>> do {
>> got = _read(_fileno(uart), inbuf + offset, 58 - offset);
>> if (got >= 0) offset += got;
>> } while ((got >= 0) && (offset < 58));
>
> This will make a 100% busy loop that eats a lot of CPU power. Is that
> possible in Nut/OS to use select function to sleep between reads? Or
> maybe _read function works in blocking mode and select is not necessary?
>
> --
> Adam Dybkowski
>
> Hi,
>
> You can check only the buffer bevor reading it:
>
> if (_filelength(_fileno(uart)) >= 58){
> got = _read(_fileno(uart), inbuf, MAX_INBUFF);
> }
>
> In this way you can polling the uart without blocking the ethernut.
>
> Urban
>
--
View this message in context: http://www.nabble.com/Problem%3A-read-uart-port-tp22607576p22623521.html
Sent from the MicroControllers - Ethernut mailing list archive at Nabble.com.
More information about the En-Nut-Discussion
mailing list