You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
2.2 KiB
86 lines
2.2 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 01/01/2000
|
|
// Last modification: 08/10/2003
|
|
// PROJECT:
|
|
// SUBSYSTEM:
|
|
// FILE: procinit.cpp
|
|
// AUTHOR: Sergey Chizhevskiy
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file of procinit.cpp
|
|
//----------------------------------------------------------------------------
|
|
#include "Comm485.h"
|
|
|
|
CComm485::CComm485( PISRPROC pIsrProc ) : CIsr( pIsrProc )
|
|
{
|
|
m_pBaseAddress = 0;
|
|
m_nBase = 0;
|
|
m_pOldIsrProc = NULL;
|
|
#ifdef COMM_RS485_PREVENT_ECHO
|
|
m_bWrite = FALSE;
|
|
#endif
|
|
m_nBaudRate = 0;
|
|
m_nBitCount = 0;
|
|
m_eParity = NOPARITY;
|
|
|
|
#ifdef DEBUG_SHOW_COMMUNICATION
|
|
m_bShowCommunication = FALSE;
|
|
m_nShowCommunicationWrite = 0;
|
|
m_nShowCommunicationRead = 0;
|
|
m_bShowCommunicationWritten = FALSE;
|
|
#endif
|
|
}
|
|
|
|
BOOL CComm485::Create( PORTS nPort, LONG nBaudRate, INT nBitCount, PARITY eParity )
|
|
{
|
|
Destroy();
|
|
|
|
if( !m_InputStream.Create() )
|
|
return FALSE;
|
|
|
|
if( !m_OutputStream.Create() )
|
|
return FALSE;
|
|
|
|
m_nBase = nPort;
|
|
|
|
m_pBaseAddress = *((short far*)MK_FP(0x0040, 2 * m_nBase ));
|
|
if(!m_pBaseAddress)
|
|
return FALSE;
|
|
|
|
if( !SetParameters( nBaudRate, nBitCount, eParity ) )
|
|
return FALSE;
|
|
|
|
// Use FIFO
|
|
outportb(m_pBaseAddress + FCR_REGISTER,
|
|
FCR_ITL14 | FCR_RESETTF | FCR_RESETRF | FCR_FIFO_ENABLE );
|
|
|
|
#ifndef COMM_WITHOUT_INTERRUPTS
|
|
// First thing is to store the old interrupt
|
|
m_pOldIsrProc = _dos_getvect( c_acPort[m_nBase] );
|
|
|
|
_dos_setvect( c_acPort[m_nBase], m_pIsrProc );
|
|
|
|
// Set OUT2 bit to enable interrupts
|
|
outportb(m_pBaseAddress + MCR_REGISTER, MCR_IE);
|
|
|
|
// Enable the interrupts we want
|
|
outportb(m_pBaseAddress + IER_REGISTER,
|
|
IER_EDSSI | IER_ELSI | IER_ERBFI );
|
|
|
|
// Last thing to do is unmask the int in the ICU
|
|
outportb(IMR_REGISTER, c_acMask[m_nBase] & inp(IMR_REGISTER));
|
|
#else
|
|
// Disable all interrupts
|
|
outportb(m_pBaseAddress + IER_REGISTER, 0 );
|
|
#endif
|
|
|
|
// clear RTS
|
|
BYTE MCR_Status = inportb( m_pBaseAddress + MCR_REGISTER );
|
|
if( MCR_Status & MCR_RTSC )
|
|
outportb( m_pBaseAddress + MCR_REGISTER, MCR_Status & ~MCR_RTSC );
|
|
|
|
return TRUE;
|
|
}
|
|
|