/* ------------------------------------------------------- -------------- Low Level Dallas MicroLan interface software Copyright 1997 by Brian C. Lane All rights Reserved -----------------------------------------------------------------------*/ #include #include #include #include struct _roms { char *roms; /* Array of 8 bytes */ int max; /* Maximum number */ }; /* ----------------------------------------------------------------------- * Setup - Setup the tty for 115.2k operation returns 0 if successful and -1 if it failed * ----------------------------------------------------------------------- */ int Setup( unsigned char CmPt ) { unsigned int far *ptr = (unsigned int far *) 0x00400000; unsigned int SPA; /* Check to see if it is a valid com port number and address */ SPA = *(ptr+CmPt-1); /* Get the address */ if( CmPt < 1 || CmPt > 4 || !SPA ) return -1; outportb( SPA+3, 0x83 ); /* Set DLAB */ outportb( SPA , 0x01 ); /* Bit rate is 115200 */ outportb( SPA+1, 0x00 ); outportb( SPA+3, 0x03 ); /* 8 data, 1 stop, no parity */ outportb( SPA+1, 0x00 ); /* No Interrupts */ outportb( SPA+4, 0x03 ); /* RTS and DTR on */ return CmPt; } /* ----------------------------------------------------------------------- * Reset the One Wire device and look for a presence pulse from it returns: 0 - No Presence/device detected 1 - Presence Detected no alarm 2 - Alarm followed by pressence -3 - Short to Ground -4 - Serial device error This expects the device to already be opened and pass the fd of it * ----------------------------------------------------------------------- */ int TouchReset( unsigned char comport, int timeout ) { unsigned int SPA, F, X, Y, tmp, trst = 0; unsigned int far *ptr = (unsigned int far *) 0x00400000; unsigned long far *sysclk = (unsigned long far *) 0x0040006C; unsigned long M; /* Get the port address */ SPA = *(ptr+comport-1); if( !SPA ) return -4; outportb( SPA+3, 0x83 ); /* Set DLAB */ outportb( SPA , 0x01 ); /* Bit rate is 115200 */ outportb( SPA+1, 0x00 ); outportb( SPA+3, 0x03 ); /* 8 data, 1 stop, no parity */ outportb( SPA+1, 0x00 ); /* No Interrupts */ outportb( SPA+4, 0x03 ); /* RTS and DTR on */ /* Clear the buffers */ M = *sysclk + 1000; do { tmp = inportb(SPA+5) & 0x60; } while ( (tmp != 0x60 ) && (*sysclk <= M) ); /* Flush input */ M = *sysclk + 1000; while( ( inportb(SPA+5) & 0x01) && (*sysclk <= M) ) { X = inportb(SPA); } outportb( SPA+3, 0x83 ); /* Set DLAB */ outportb( SPA+1, 0x00 ); /* Bit rate is 0x0B = 10473 */ outportb( SPA , 0x0B ); /* 0x0C = 9600 baud */ outportb( SPA+3, 0x03 ); /* 8 data, 1 stop, no parity */ outportb( SPA , 0xF0 ); /* Send the reset pulse */ M = *sysclk + 50; /* Wait until character back or timeout */ do { Y = inportb(SPA+5); /* Read status register */ F = Y & 0x01; } while( !F && (*sysclk <= M) ); if( F ) X = inportb( SPA ); else return -3; outportb( SPA+3, 0x83 ); /* Set DLAB */ outportb( SPA , 0x01 ); /* Bit rate is 115200 */ outportb( SPA+3, 0x03 ); /* 8 data, 1 stop, no parity */ return 1; #ifdef MORE_CHECKS if( X != 0xF0 ) /* If more bits back than sent */ { trst = 1; if( ( Y & 0x18 ) != 0 ) { trst = 2; /* Clear the buffers */ M = *sysclk + 1000; do { tmp = inportb(SPA+5) & 0x60; } while ( (tmp != 0x60 ) && (*sysclk <= M) ); M = *sysclk + 50; /* wait until character back or timeout */ do { Y = inportb( SPA+5 ); F = Y & 0x01; } while( !F && (*sysclk <= M) ); if( F ) X = inportb( SPA ); else return 3; } } outportb( SPA+3, 0x83 ); /* Set DLAB */ outportb( SPA , 0x01 ); /* Bit rate is 115200 */ outportb( SPA+3, 0x03 ); /* 8 data, 1 stop, no parity */ return trst; #endif } /* ----------------------------------------------------------------------- * TouchBits - Read/Write a number of bits to the TouchMemory device Expects that the tty is set up for 115.2k operation returns the read byte if one received * ----------------------------------------------------------------------- */ int TouchBits( int comport, int timeout, int nbits, unsigned char outch) { unsigned char inch=0, sendbit, Mask=1; unsigned int SPA, tmp; unsigned far *ptr = (unsigned int far *) 0x00400000; unsigned long far *sysclk = (unsigned long far *) 0x0040006C; unsigned long M; int x; /* Get the serial port address */ SPA = *(ptr+comport-1); /* Clear the buffers */ M = *sysclk + 1000; do { tmp = inportb(SPA+5) & 0x60; } while ( (tmp != 0x60 ) && (*sysclk <= M) ); /* Flush input */ M = *sysclk + 1000; while( ( inportb(SPA+5) & 0x01) && (*sysclk <= M) ) { inportb(SPA); } /* get first bit ready to go out */ sendbit = (outch & 0x01) ? 0xFF : 0x00; /* loop to send and receive 8 bits */ for( x = 0; x < nbits; x++ ) { outportb( SPA, sendbit); /* Get next bit ready */ Mask <<= 1; sendbit = (outch & Mask) ? 0xFF : 0x00; /* shift input char over ready for next bit */ inch >>= 1; M = *sysclk + 50; for(;;) { /* return if out of time */ if( *sysclk > M ) return 0xFF; if( inportb(SPA+5) & 0x01 ) { inch |= ((inportb(SPA) & 0x01 ) ? 0x80 : 0x00); break; } } } return inch; } /* ----------------------------------------------------------------------- * TouchByte - Read/Write a byte to the TouchMemory device Expects that the tty is set up for 115.2k operation returns the read byte if one received * ----------------------------------------------------------------------- */ int TouchByte( int comport, int timeout, unsigned char outch ) { return TouchBits( comport, timeout, 8, outch ); }