5 //---------------------------------------------------------------------------
6 // Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
8 // Permission is hereby granted, free of charge, to any person obtaining a
9 // copy of this software and associated documentation files (the "Software"),
10 // to deal in the Software without restriction, including without limitation
11 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 // and/or sell copies of the Software, and to permit persons to whom the
13 // Software is furnished to do so, subject to the following conditions:
15 // The above copyright notice and this permission notice shall be included
16 // in all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 // IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
22 // OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 // OTHER DEALINGS IN THE SOFTWARE.
26 // Except as contained in this notice, the name of Dallas Semiconductor
27 // shall not be used except as stated in the Dallas Semiconductor
29 //---------------------------------------------------------------------------
31 // TODO.C - COM functions required by MLANLL.C, MLANTRNU, MLANNETU.C and
32 // MLanFile.C for MLANU to communicate with the DS2480 based
33 // Universal Serial Adapter 'U'. Fill in the platform specific code.
37 // History: 1.00 -> 1.01 Added function msDelay.
39 // 1.01 -> 1.02 Changed to generic OpenCOM/CloseCOM for easier
40 // use with other platforms.
43 //--------------------------------------------------------------------------
44 // Copyright (C) 1998 Andrea Chambers and University of Newcastle upon Tyne,
45 // All Rights Reserved.
46 //--------------------------------------------------------------------------
48 // Permission is hereby granted, free of charge, to any person obtaining a
49 // copy of this software and associated documentation files (the "Software"),
50 // to deal in the Software without restriction, including without limitation
51 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
52 // and/or sell copies of the Software, and to permit persons to whom the
53 // Software is furnished to do so, subject to the following conditions:
55 // The above copyright notice and this permission notice shall be included
56 // in all copies or substantial portions of the Software.
58 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
59 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
60 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
61 // IN NO EVENT SHALL THE UNIVERSITY OF NEWCASTLE UPON TYNE OR ANDREA CHAMBERS
62 // BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
63 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
64 // THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
65 //---------------------------------------------------------------------------
67 // LinuxLNK.C - COM functions required by MLANLLU.C, MLANTRNU.C, MLANNETU.C
68 // and MLanFile.C for MLANU to communicate with the DS2480 based
69 // Universal Serial Adapter 'U'. Platform specific code.
72 // History: 1.00 -> 1.03 modifications by David Smiczek
73 // Changed to use generic OpenCOM/CloseCOM
74 // Pass port name to OpenCOM instead of hard coded
75 // Changed msDelay to handle long delays
76 // Reformatted to look like 'TODO.C'
77 // Added #include "ds2480.h" to use constants.
78 // Added function SetBaudCOM()
79 // Added function msGettick()
80 // Removed delay from WriteCOM(), used tcdrain()
81 // Added wait for byte available with timeout using
82 // select() in ReadCOM()
84 // 1.03 -> 2.00 Support for multiple ports. Include "ownet.h". Use
85 // 'uchar'. Reorder functions. Provide correct
86 // return values to OpenCOM. Replace 'makeraw' call.
87 // Should now be POSIX.
95 //---------------------------------------------------------------------------
96 // Attempt to open a com port.
97 // Set the starting baud rate to 9600.
99 // 'portnum' - number 0 to MAX_PORTNUM-1. This number provided will
100 // be used to indicate the port number desired when calling
101 // all other functions in this library.
103 // 'port_zstr' - zero terminate port name. For this platform
107 // Returns: TRUE(1) - success, COM port opened
108 // FALSE(0) - failure, could not open specified port
110 int OpenCOM(int portnum, char *port_zstr)
112 unsigned long baud=9600;
114 //printf ("OpenCOM(%d,\"%s\")\n", portnum, port_zstr);
122 return TRUE; // changed (2.00), used to return fd;
125 //---------------------------------------------------------------------------
126 // Closes the connection to the port.
128 // 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
129 // OpenCOM to indicate the port number.
131 void CloseCOM(int portnum)
133 //printf ("CloseCOM(%d)\n", portnum);
140 //--------------------------------------------------------------------------
141 // Write an array of bytes to the COM port, verify that it was
142 // sent out. Assume that baud rate has been set.
144 // 'portnum' - number 0 to MAX_PORTNUM-1. This number provided will
145 // be used to indicate the port number desired when calling
146 // all other functions in this library.
147 // Returns 1 for success and 0 for failure
149 int WriteCOM(int portnum, int outlen, uchar *outbuf)
154 printf ("WriteCOM(%d, %d,...): ", portnum, outlen, outbuf);
160 for (i=0; i<outlen; i++) {
162 printf ("%02x ", outbuf[i]);
164 Serial1PutChar(outbuf[i]);
172 //--------------------------------------------------------------------------
173 // Read an array of bytes to the COM port, verify that it was
174 // sent out. Assume that baud rate has been set.
176 // 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
177 // OpenCOM to indicate the port number.
178 // 'outlen' - number of bytes to write to COM port
179 // 'outbuf' - pointer ot an array of bytes to write
181 // Returns: TRUE(1) - success
182 // FALSE(0) - failure
184 int ReadCOM(int portnum, int inlen, uchar *inbuf)
189 printf ("ReadCOM(%d,%d,...): ", portnum, inlen);
195 for (i=0; i<inlen; i++) {
196 inbuf[i]=Serial1GetChar();
198 printf ("%02x ", inbuf[i]&0xff);
205 // success, so return desired length
210 //---------------------------------------------------------------------------
212 // flush the rx and tx buffers
214 // 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
215 // OpenCOM to indicate the port number.
217 void FlushCOM(int portnum)
219 //printf ("FlushCOM(%d): ", portnum);
228 //--------------------------------------------------------------------------
230 // Send a break on the com port for at least 2 ms
232 // 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
233 // OpenCOM to indicate the port number.
236 void BreakCOM(int portnum)
238 //printf ("BreakCOM(%d)\n", portnum);
246 //--------------------------------------------------------------------------
247 // Set the baud rate on the com port.
249 // 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
250 // OpenCOM to indicate the port number.
251 // 'new_baud' - new baud rate defined as
253 // PARMSET_19200 0x02
254 // PARMSET_57600 0x04
255 // PARMSET_115200 0x06
258 void SetBaudCOM(int portnum, int new_baud)
262 portnum; // hush the compiler
265 case PARMSET_9600: baud=9600; break;
266 case PARMSET_19200: baud=19200; break;
267 case PARMSET_57600: baud=57600; break;
268 case PARMSET_115200: baud=115200; break;
275 //--------------------------------------------------------------------------
276 // Get the current millisecond tick count. Does not have to represent
277 // an actual time, it just needs to be an incrementing timer.
285 //--------------------------------------------------------------------------
287 // Delay for at least 'len' ms
289 void msDelay(int len)
291 ClockMilliSecondsDelay(len);