//--------------------------------------------------------------------------- // Copyright (C) 1998 Dallas Semiconductor Corporation, All Rights Reserved. // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. // IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES // OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. // // Except as contained in this notice, the name of Dallas Semiconductor // shall not be used except as stated in the Dallas Semiconductor // Branding Policy. //--------------------------------------------------------------------------- // // TODO.C - COM functions required by MLANLLU.C, MLANTRNU, MLANNETU.C and // MLanFile.C for MLANU to communicate with the DS2480 based // Universal Serial Adapter 'U'. Fill in the platform specific code. // // Version: 1.00 // // //-------------------------------------------------------------------------- // Platform specific code for Linux. // // Copyright (C) 1998 Andrea Chambers and University of Newcastle upon Tyne, // All Rights Reserved. //-------------------------------------------------------------------------- // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. // IN NO EVENT SHALL THE UNIVERSITY OF NEWCASTLE UPON TYNE OR ANDREA CHAMBERS // BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH // THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. //--------------------------------------------------------------------------- // // LinuxLNK.C - COM functions required by MLANLLU.C, MLANTRNU.C, MLANNETU.C and // MLanFile.C for MLANU to communicate with the DS2480 based // Universal Serial Adapter 'U'. Platform specific code. // // Version: 1.00 // // #include #include #include #include #include #include #include #include // Exportable functions required for MLANLL.C, MLANTRNU.C, or MLANNETU.C void FlushCOM(void); int WriteCOM(int, unsigned char*); int ReadCOM(int, unsigned char*); void BreakCOM(void); void msDelay(int); // Exportable functions for Linux link int OpenLinuxCOM(void); void CloseLinuxCOM(void); // Exportable functions as in Win32 link to save changing TSTMLANU.C int OpenWin32COM(int COMPrt); void CloseWin32COM(void); // LinuxLNK global int fd; // Write an array of bytes to the comm port, verify it was sent out. // Assume the baud rate has been set. // Returns 1 for success and 0 for failure. int WriteCOM(int outlen, unsigned char *outbuf) { long count = outlen; int i = write(fd, outbuf, outlen); msDelay(1000*count/960); // tcdrain(fd); return (i == count); } // Read an array of bytes from the comm port. // Assume baud rate has been set. // Return the number of bytes read. int ReadCOM(int inlen, unsigned char *inbuf) { return read(fd, inbuf, inlen); } // Flush the rx and tx buffers void FlushCOM(void) { tcflush (fd, TCIOFLUSH); } void msDelay(int len) { struct timespec s; // Set aside memory space on the stack s.tv_sec = 0; s.tv_nsec = 1000000 * len; nanosleep(&s, NULL); } void BreakCOM(void) { int duration = 0; // see man termios break may be tcsendbreak(fd, duration); // too long } int OpenLinuxCOM(void) { struct termios t; // see man termios - declared as above int rc; fd = open("/dev/ttyS1", O_RDWR|O_NONBLOCK); if (fd<0) return fd; rc = tcgetattr (fd, &t); if (rc < 0) { int tmp; tmp = errno; close(fd); errno = tmp; return rc; } cfsetospeed(&t, B9600); cfsetispeed (&t, B9600); cfmakeraw(&t); // don't generate signals, translate or echo t.c_lflag |= CLOCAL; // ignore modem signals rc = tcsetattr (fd, TCSAFLUSH, &t); if (rc < 0) { int tmp; tmp = errno; close(fd); errno = tmp; return rc; } return fd; } void CloseLinuxCOM(void) { FlushCOM(); close(fd); } //attempt to open/close comm port using Win32 calls int OpenWin32COM(int COMPrt) { return OpenLinuxCOM(); } void CloseWin32COM(void) { CloseLinuxCOM(); } // End of LinuxLNK.C