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.

282 lines
7.8 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
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: board_.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of board_.cpp
  13. //----------------------------------------------------------------------------
  14. #include "board.h"
  15. CBoard::CBoard( PISRPROC pIsrProc ) : CIsr( pIsrProc )
  16. {
  17. m_pOldIsrProc = NULL;
  18. m_wTimer = 0;
  19. #ifndef BOARD_DEFFERED_PROCESSING
  20. m_bReady = FALSE;
  21. memset( &m_BoardData, 0, sizeof(BOARDDATA) );
  22. #endif
  23. // unknown type of board
  24. m_nBoardType = BT_NONE;
  25. m_bBoardMCU = FALSE;
  26. m_bOutputDirty = FALSE;
  27. #ifdef DEBUG_ENABLE_OLD_BOARD
  28. // used for A/D conversion
  29. s_pDataArray[0] = s_pDataArray[1] = 0;
  30. #endif
  31. // reset mask
  32. m_bOutputMask = 0;
  33. }
  34. CBoard::~CBoard()
  35. {
  36. Destroy();
  37. }
  38. #ifdef DEBUG_ENABLE_OLD_BOARD
  39. BOOL CBoard::InitOldBoard()
  40. {
  41. // try to initialize old board
  42. static short infoArray[11];// = { 0, 0x300, 5, 3, 12, 20, 0, 0, 0, 0, 0 };
  43. infoArray[0] = 0; // result
  44. infoArray[1] = 0x300; // base address
  45. infoArray[2] = 5; // interrupt level
  46. infoArray[3] = 3; // DMA level
  47. infoArray[4] = 12; // A/D resolution
  48. infoArray[5] = 20; // A/D scan interval
  49. infoArray[6] = 0; // reserved
  50. infoArray[7] = 0; // reserved
  51. infoArray[8] = 0; // reserved
  52. infoArray[9] = 0; // reserved
  53. infoArray[10] = 0; // reserved
  54. // initialize board
  55. SMM( 0, infoArray );
  56. if( infoArray[0] )
  57. return FALSE;
  58. infoArray[1] = 1; // Number of conversions
  59. infoArray[2] = FP_SEG(s_pDataArray);
  60. infoArray[3] = FP_OFF(s_pDataArray);
  61. infoArray[4] = 1; // Operation type
  62. infoArray[5] = 0; // Gain setting
  63. infoArray[6] = 0; // Low channel
  64. infoArray[7] = 1; // High channel
  65. infoArray[8] = 0; // reserved
  66. infoArray[9] = 0; // reserved
  67. infoArray[10] = 0; // reserved
  68. // Install ISR for Sapphire
  69. SMM(4, infoArray);
  70. if( infoArray[0] )
  71. return FALSE;
  72. // fix irq 7
  73. asm
  74. {
  75. mov AL, 0xDE
  76. out 0xF2, AL
  77. in AL, 0xF3
  78. and AL, 0xF3
  79. out 0xF3, AL
  80. }
  81. // set type of board
  82. m_nBoardType = BT_OLD;
  83. // install interrupt handler
  84. _disable();
  85. m_pOldIsrProc = _dos_getvect( OLD_INTERRUPT_BOARD );
  86. _dos_setvect( OLD_INTERRUPT_BOARD, m_pIsrProc );
  87. #ifndef BOARD_BIND_IRQ_TO_SAPHIR
  88. outportb(PICIMR, inportb(PICIMR) & OLD_INTERRUPT_MASK );
  89. inportb( OLD_BASE_ADDRESS ); // Reset interrupt trigger
  90. // outportb( OLD_BASE_ADDRESS, 0x01 );
  91. #endif
  92. _enable();
  93. #ifdef RELAY_ACTIVATE_BY_ZERO
  94. m_bOutputMask = 0x0;
  95. #else
  96. m_bOutputMask = 0x0;
  97. #endif
  98. // Enable two lasers
  99. outportb( OLD_BASE_ADDRESS, m_bOutputMask |= 0x07 );
  100. return TRUE;
  101. }
  102. #endif
  103. BOOL CBoard::InitNewBoard()
  104. {
  105. // control register 0
  106. // 0 - VREF (0=internal, 1=external)
  107. // 1 - MODE (0-continues conversations, 1-single conversation )
  108. // 2 - POWER_DOWN (0-active, 1-power down)
  109. // 3,4 - CHANAL SELECT
  110. // 5,6 - NUMBER OF DIFFERENTION CHANALS
  111. // 7 - AUTOSCAN ENABLE
  112. // 8,9 - TEST INPUT ENABLE
  113. // control register 1
  114. // 0 - RESET
  115. // 1 - FIFO_RESET
  116. // 2 - FIFO_LEVEL
  117. // 3 - FIFO_LEVEL
  118. // 4 - DATA_AVALIBLE TYPE (pulse = 1, static = 0)
  119. // 5 - DATA_AVALIBLE POLARITY (hi = 1,0 = low)
  120. // 6 - R/W, RD/WR SELECTION
  121. // 7 - BIN/2s DATA FORMAT (binary = 1, 2s = 0 )
  122. // 8 - OFFSET (0=normal, 1=offset calibration)
  123. // 9 - RBACK (0=normal, 1=debug mode)
  124. #ifdef RELAY_ACTIVATE_BY_ZERO
  125. m_bOutputMask = BE_NEW_DC0;
  126. #else
  127. m_bOutputMask = 0;
  128. #endif
  129. // disable laser devices
  130. outportb( NEW_BASE_ADDRESS + 2, m_bOutputMask &= ~(BE_NEW_DEVICE0 | BE_NEW_DEVICE1) );
  131. // nessesary to make delay
  132. delay(100);
  133. // check if this is a new board
  134. m_bBoardMCU = inportb( NEW_BASE_ADDRESS + 0x05 ) == 0x5A;
  135. // if not MCU board
  136. if( m_bBoardMCU )
  137. {
  138. outportb( NEW_BASE_ADDRESS + 3, 0 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nGearRatio >> 8 ); // motor ratio
  139. outportb( NEW_BASE_ADDRESS + 3, 1 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nGearRatio & 0xFF );
  140. outportb( NEW_BASE_ADDRESS + 3, 2 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nEncoderSteps >> 8 ); // encoder count
  141. outportb( NEW_BASE_ADDRESS + 3, 3 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nEncoderSteps & 0xFF );
  142. outportb( NEW_BASE_ADDRESS + 3, 4 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nTemperature ); // temperature
  143. outportb( NEW_BASE_ADDRESS + 3, 5 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nZeroShift >> 8 ); // zero offset
  144. outportb( NEW_BASE_ADDRESS + 3, 6 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nZeroShift & 0xFF );
  145. // outportb( NEW_BASE_ADDRESS + 3, 7 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nMaxRange >> 8 );
  146. // outportb( NEW_BASE_ADDRESS + 3, 8 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nMaxRange & 0xFF ); // max range
  147. }
  148. else
  149. {
  150. // write to CR0
  151. outportb(NEW_BASE_ADDRESS + 1, 0x04); // 1st word
  152. outportb(NEW_BASE_ADDRESS, 0x01);
  153. // write to CR1
  154. outportb(NEW_BASE_ADDRESS + 1, 0x04); // 2nd word
  155. outportb(NEW_BASE_ADDRESS, 0x00);
  156. // write to CR0
  157. outportb(NEW_BASE_ADDRESS + 1, 0x00); // 3th word
  158. outportb(NEW_BASE_ADDRESS, 0x8A); // 10001010
  159. // 10001--- autoscan two single-ended channels,
  160. // -----0-- ADC is active,
  161. // ------1- single conversation mode
  162. // -------0 internal reference
  163. // outportb(BASE_ADDRESS, 0x02); // One channel, internal reference
  164. // write to CR1
  165. outportb(NEW_BASE_ADDRESS + 1, 0x04); // 4th word
  166. #ifdef BOARD_A2D_FOUR_SAMPLES
  167. outportb(NEW_BASE_ADDRESS, 0x8A); //(10011010)
  168. // 1------- output in binary format
  169. // -0------ RD: read input, WR: write input
  170. // --00---- DATA_AV: active low level
  171. // ----10-- trigger level 8
  172. // ------1- FIFO reset
  173. // -------0 no reset
  174. #else
  175. outportb(NEW_BASE_ADDRESS, 0x92); // 10010010
  176. // 1------- output in binary format
  177. // -0------ RD: read input, WR: write input
  178. // --01---- DATA_AV: active low pulse
  179. // ----00-- trigger level 1
  180. // ------1- FIFO reset
  181. // -------0 no reset
  182. #endif
  183. }
  184. // set type of board
  185. m_nBoardType = BT_NEW;
  186. // install handler
  187. m_pOldIsrProc = _dos_getvect( NEW_INTERRUPT_BOARD );
  188. _disable();
  189. _dos_setvect( NEW_INTERRUPT_BOARD, m_pIsrProc );
  190. outportb( PICIMR, inportb(PICIMR) & NEW_INTERRUPT_MASK );
  191. _enable();
  192. // enable devices
  193. outportb( NEW_BASE_ADDRESS + 2, m_bOutputMask |= BE_NEW_DEVICE0 | BE_NEW_DEVICE1 );
  194. return TRUE;
  195. }
  196. BOOL CBoard::Create( BOARD_SETTINGS* pSettings )
  197. {
  198. Destroy();
  199. m_Settings = *pSettings;
  200. #ifdef DEBUG_ENABLE_OLD_BOARD
  201. if( InitOldBoard() )
  202. return TRUE;
  203. #endif
  204. if( InitNewBoard() )
  205. return TRUE;
  206. return FALSE;
  207. }
  208. void CBoard::Destroy()
  209. {
  210. if( m_pOldIsrProc )
  211. {
  212. if( m_nBoardType == BT_NEW )
  213. {
  214. outportb( PICIMR, inportb(PICIMR) | !NEW_INTERRUPT_MASK );
  215. _disable();
  216. _dos_setvect( NEW_INTERRUPT_BOARD, m_pOldIsrProc );
  217. _enable();
  218. }
  219. #ifdef DEBUG_ENABLE_OLD_BOARD
  220. else
  221. if( m_nBoardType == BT_OLD )
  222. {
  223. #ifndef BOARD_BIND_IRQ_TO_SAPHIR
  224. outportb( PICIMR, inportb(PICIMR) | !OLD_INTERRUPT_MASK );
  225. outportb( OLD_BASE_ADDRESS, m_bOutputMask &= ~0x07 ); // Disable interrupt
  226. #endif
  227. _disable();
  228. _dos_setvect( OLD_INTERRUPT_BOARD, m_pOldIsrProc );
  229. _enable();
  230. }
  231. #endif
  232. m_pOldIsrProc = NULL;
  233. #ifndef BOARD_DEFFERED_PROCESSING
  234. m_bReady = FALSE;
  235. memset( &m_BoardData, 0, sizeof(BOARDDATA) );
  236. #endif
  237. }
  238. // unknown type of board
  239. m_nBoardType = BT_NONE;
  240. // used for A/D conversion
  241. #ifdef DEBUG_ENABLE_OLD_BOARD
  242. s_pDataArray[0] = s_pDataArray[1] = 0;
  243. #endif
  244. }