~ubuntu-branches/ubuntu/lucid/skyeye/lucid-proposed

« back to all changes in this revision

Viewing changes to device/uart/skyeye_uart_stdio.c

  • Committer: Bazaar Package Importer
  • Author(s): Yu Guanghui
  • Date: 2007-08-07 13:25:49 UTC
  • mfrom: (1.1.2 upstream) (2.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20070807132549-96159k1obat1fxr0
Tags: 1.2.3-1
* New upstream release
* Added NO_BFD=1, don't require libbfd now. (Closes:Bug#423933) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#ifndef __MINGW32__
28
28
 
29
29
#ifdef __BEOS__
30
 
#include <BeBuild.h>
31
 
#if (B_BEOS_VERSION >= 0x510)
32
 
#include <sys/select.h>
33
 
#endif
 
30
        #include <BeBuild.h>
 
31
        #if (B_BEOS_VERSION >= 0x510)
 
32
                #include <sys/select.h>
 
33
        #else /* B_BEOS_VERSION < 0x510 */
 
34
                #define SELECT_UNSUPPORTED
 
35
        #endif /* B_BEOS_VERSION >= 0x510 */
34
36
#else /* !__BEOS__ */
35
 
#include <sys/select.h>
 
37
        #include <sys/select.h>
36
38
#endif /* __BEOS__ */
37
39
 
 
40
#ifdef SELECT_UNSUPPORTED
 
41
        #include <stdint.h>
 
42
        #include "portable/usleep.h"
 
43
#endif /* SELECT_UNSUPPORTED */
 
44
 
38
45
#include <unistd.h>
39
46
 
40
47
#include <termios.h>
77
84
int uart_stdio_read(struct uart_device *uart_dev, void *buf, size_t count, struct timeval *timeout)
78
85
{
79
86
        /*
80
 
         * 2007-02-02 by Anthony Lee : for BeOS R5.0.x.
81
 
         * BeOS R5.0.x don't support select, and terminal is non-blocking now.
 
87
         * 2007-03-03 by Anthony Lee : for the system that don't support select().
 
88
         * WHY: maybe useful for real-time improvement.
82
89
         */
83
 
#if !(defined(__BEOS__) && B_BEOS_VERSION < 0x510)
 
90
#ifndef SELECT_UNSUPPORTED
 
91
 
84
92
        fd_set rfds;
85
93
 
86
94
        FD_ZERO(&rfds);
87
95
        FD_SET(0, &rfds);
88
96
 
89
97
        if(select(1, &rfds, NULL, NULL, timeout) != 1 || !FD_ISSET(0, &rfds)) return 0;
90
 
#endif
91
 
 
92
98
        return read(0, buf, count);
 
99
 
 
100
#else /* SELECT_UNSUPPORTED */
 
101
 
 
102
        int retVal;
 
103
        int64_t time_left;
 
104
 
 
105
        if(timeout != NULL) time_left = (int64_t)timeout->tv_sec * (int64_t)1000000 + (int64_t)timeout->tv_usec;
 
106
        while(1)
 
107
        {
 
108
                /* for non-blocking input, instead of polling. */
 
109
                if((retVal = read(0, buf, count)) != 0) break;
 
110
                if(timeout == NULL) continue;
 
111
                if(time_left <= 0) break;
 
112
                usleep(1000);
 
113
                time_left -= (int64_t)1000;
 
114
        }
 
115
 
 
116
        return retVal;
 
117
 
 
118
#endif /* !SELECT_UNSUPPORTED */
93
119
}
94
120
 
95
121