1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
$NetBSD: patch-ae,v 1.2 2003/01/05 03:31:25 dsainty Exp $
Without the first hunk of this patch, ROM transfers tend to not get very far
due to consistently lost characters.
The remainder corrects an assumption in the code that 0 is an invalid file
handle, and registers NetBSD-style tty device names.
--- SrcUnix/EmTransportSerialUnix.cpp.orig Sat Mar 30 01:11:19 2002
+++ SrcUnix/EmTransportSerialUnix.cpp Sun Nov 24 05:42:39 2002
@@ -220,7 +220,7 @@
// Programming Mini-Howto") says to turn off these for "raw" (as opposed to
// "canonical") mode.
- io.c_lflag &= ~(ICANON | ECHO | ISIG);
+ io.c_lflag &= ~(ICANON | ECHO | ISIG | IEXTEN);
// The UNIX Programming FAQ (<www://www.faqs.org/faqs/unix-faq/programmer/faq/>)
// recommends just setting all the c_iflags and c_oflags to zero.
@@ -541,6 +541,20 @@
#ifdef __QNXNTO__
results.push_back ("/dev/ser1");
results.push_back ("/dev/ser2");
+#elif __FreeBSD__
+ results.push_back ("/dev/pilot");
+ results.push_back ("/dev/cuaa0");
+ results.push_back ("/dev/cuaa1");
+ results.push_back ("/dev/cuaa2");
+ results.push_back ("/dev/cuaa3");
+#elif __NetBSD__
+ results.push_back ("/dev/pilot");
+ results.push_back ("/dev/tty00");
+ results.push_back ("/dev/tty01");
+ results.push_back ("/dev/tty02");
+ results.push_back ("/dev/tty03");
+ results.push_back ("/dev/ttyU0");
+ results.push_back ("/dev/ttyU1");
#else
results.push_back ("/dev/ttyS0");
results.push_back ("/dev/ttyS1");
@@ -596,9 +610,9 @@
EmHostTransportSerial::EmHostTransportSerial (void) :
fReadThread (NULL),
fWriteThread (NULL),
- fCommHandle (0),
- fCommSignalPipeA (0),
- fCommSignalPipeB (0),
+ fCommHandle (-1),
+ fCommSignalPipeA (-1),
+ fCommSignalPipeB (-1),
fTimeToQuit (false),
fDataMutex (),
fDataCondition (&fDataMutex),
@@ -626,9 +640,9 @@
{
EmAssert (fReadThread == NULL);
EmAssert (fWriteThread == NULL);
- EmAssert (fCommHandle == 0);
- EmAssert (fCommSignalPipeA == 0);
- EmAssert (fCommSignalPipeB == 0);
+ EmAssert (fCommHandle == -1);
+ EmAssert (fCommSignalPipeA == -1);
+ EmAssert (fCommSignalPipeB == -1);
}
@@ -662,9 +676,9 @@
fCommHandle = open(portName.c_str (), O_RDWR | O_NOCTTY | O_NDELAY);
- if (fCommHandle <= 0)
+ if (fCommHandle < 0)
{
- fCommHandle = 0;
+ fCommHandle = -1;
return errno;
}
@@ -694,7 +708,7 @@
ErrCode EmHostTransportSerial::CreateCommThreads (const EmTransportSerial::ConfigSerial& /*config*/)
{
- if (fCommHandle)
+ if (fCommHandle != -1)
{
PRINTF ("EmTransportSerial::HostOpen: Creating serial port handler threads...");
@@ -734,40 +748,41 @@
{
// If never created, nothing to destroy.
- if (!fCommSignalPipeA)
+ if (fCommSignalPipeA == -1)
return errNone;
// Signal the threads to quit.
- fDataMutex.lock ();
-
- fTimeToQuit = true;
-
- int dummy = 0;
- write (fCommSignalPipeB, &dummy, sizeof (dummy)); // Signals CommRead.
-
- fDataCondition.broadcast (); // Signals CommWrite.
- fDataMutex.unlock ();
+ if((fCommSignalPipeA != -1) && (fCommSignalPipeB != -1))
+ {
+ fDataMutex.lock();
- // Wait for the threads to quit.
+ fTimeToQuit = true;
- if (fReadThread)
- {
- fReadThread->join (NULL);
- fWriteThread->join (NULL);
- }
+ int dummy = 0;
+ write(fCommSignalPipeB, &dummy, sizeof (dummy)); // Signals CommRead.
- // Thread objects delete themselves, so set our references to NULL.
+ fDataCondition.broadcast(); // Signals CommWrite.
+ fDataMutex.unlock();
- fReadThread = NULL;
- fWriteThread = NULL;
+ // Wait for the threads to quit.
- // Close the signal pipe.
+ if (fReadThread)
+ {
+ fReadThread->join (NULL);
+ fWriteThread->join (NULL);
+ }
- close (fCommSignalPipeA);
- close (fCommSignalPipeB);
+ // Thread objects delete themselves, so set our references to NULL.
+ fReadThread = NULL;
+ fWriteThread = NULL;
+
+ // Close the signal pipe.
+ close (fCommSignalPipeA);
+ close (fCommSignalPipeB);
- fCommSignalPipeA = fCommSignalPipeB = 0;
+ fCommSignalPipeA = fCommSignalPipeB = -1;
+ }
return errNone;
}
@@ -787,9 +802,11 @@
ErrCode EmHostTransportSerial::CloseCommPort (void)
{
- (void) close (fCommHandle);
-
- fCommHandle = 0;
+ if(fCommHandle != -1)
+ {
+ int result = close(fCommHandle);
+ fCommHandle = -1;
+ }
return errNone;
}
|