Old fashion design for PC-104
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

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 08/10/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: procinit.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of procinit.cpp
  13. //----------------------------------------------------------------------------
  14. #include "Comm485.h"
  15. CComm485::CComm485( PISRPROC pIsrProc ) : CIsr( pIsrProc )
  16. {
  17. m_pBaseAddress = 0;
  18. m_nBase = 0;
  19. m_pOldIsrProc = NULL;
  20. #ifdef COMM_RS485_PREVENT_ECHO
  21. m_bWrite = FALSE;
  22. #endif
  23. m_nBaudRate = 0;
  24. m_nBitCount = 0;
  25. m_eParity = NOPARITY;
  26. #ifdef DEBUG_SHOW_COMMUNICATION
  27. m_bShowCommunication = FALSE;
  28. m_nShowCommunicationWrite = 0;
  29. m_nShowCommunicationRead = 0;
  30. m_bShowCommunicationWritten = FALSE;
  31. #endif
  32. }
  33. BOOL CComm485::Create( PORTS nPort, LONG nBaudRate, INT nBitCount, PARITY eParity )
  34. {
  35. Destroy();
  36. if( !m_InputStream.Create() )
  37. return FALSE;
  38. if( !m_OutputStream.Create() )
  39. return FALSE;
  40. m_nBase = nPort;
  41. m_pBaseAddress = *((short far*)MK_FP(0x0040, 2 * m_nBase ));
  42. if(!m_pBaseAddress)
  43. return FALSE;
  44. if( !SetParameters( nBaudRate, nBitCount, eParity ) )
  45. return FALSE;
  46. // Use FIFO
  47. outportb(m_pBaseAddress + FCR_REGISTER,
  48. FCR_ITL14 | FCR_RESETTF | FCR_RESETRF | FCR_FIFO_ENABLE );
  49. #ifndef COMM_WITHOUT_INTERRUPTS
  50. // First thing is to store the old interrupt
  51. m_pOldIsrProc = _dos_getvect( c_acPort[m_nBase] );
  52. _dos_setvect( c_acPort[m_nBase], m_pIsrProc );
  53. // Set OUT2 bit to enable interrupts
  54. outportb(m_pBaseAddress + MCR_REGISTER, MCR_IE);
  55. // Enable the interrupts we want
  56. outportb(m_pBaseAddress + IER_REGISTER,
  57. IER_EDSSI | IER_ELSI | IER_ERBFI );
  58. // Last thing to do is unmask the int in the ICU
  59. outportb(IMR_REGISTER, c_acMask[m_nBase] & inp(IMR_REGISTER));
  60. #else
  61. // Disable all interrupts
  62. outportb(m_pBaseAddress + IER_REGISTER, 0 );
  63. #endif
  64. // clear RTS
  65. BYTE MCR_Status = inportb( m_pBaseAddress + MCR_REGISTER );
  66. if( MCR_Status & MCR_RTSC )
  67. outportb( m_pBaseAddress + MCR_REGISTER, MCR_Status & ~MCR_RTSC );
  68. return TRUE;
  69. }