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.

291 lines
8.0 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
4 years ago
​
​
4 years ago
​
​
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. BSNLB=0;
  136. BSNHB=0;
  137. // if not MCU board
  138. if( m_bBoardMCU )
  139. {
  140. BSNLB=inportb( NEW_BASE_ADDRESS + 6 );
  141. BSNHB=inportb( NEW_BASE_ADDRESS + 7 );
  142. outportb( NEW_BASE_ADDRESS + 6, 0xFF );
  143. outportb( NEW_BASE_ADDRESS + 7, 0x11 );
  144. outportb( NEW_BASE_ADDRESS + 3, 0 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nGearRatio >> 8 ); // motor ratio
  145. outportb( NEW_BASE_ADDRESS + 3, 1 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nGearRatio & 0xFF );
  146. outportb( NEW_BASE_ADDRESS + 3, 2 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nEncoderSteps >> 8 ); // encoder count
  147. outportb( NEW_BASE_ADDRESS + 3, 3 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nEncoderSteps & 0xFF );
  148. outportb( NEW_BASE_ADDRESS + 3, 4 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nTemperature ); // temperature
  149. outportb( NEW_BASE_ADDRESS + 3, 5 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nZeroShift >> 8 ); // zero offset
  150. outportb( NEW_BASE_ADDRESS + 3, 6 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nZeroShift & 0xFF );
  151. // outportb( NEW_BASE_ADDRESS + 3, 7 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nMaxRange >> 8 );
  152. // outportb( NEW_BASE_ADDRESS + 3, 8 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nMaxRange & 0xFF ); // max range
  153. }
  154. else
  155. {
  156. // write to CR0
  157. outportb(NEW_BASE_ADDRESS + 1, 0x04); // 1st word
  158. outportb(NEW_BASE_ADDRESS, 0x01);
  159. // write to CR1
  160. outportb(NEW_BASE_ADDRESS + 1, 0x04); // 2nd word
  161. outportb(NEW_BASE_ADDRESS, 0x00);
  162. // write to CR0
  163. outportb(NEW_BASE_ADDRESS + 1, 0x00); // 3th word
  164. outportb(NEW_BASE_ADDRESS, 0x8A); // 10001010
  165. // 10001--- autoscan two single-ended channels,
  166. // -----0-- ADC is active,
  167. // ------1- single conversation mode
  168. // -------0 internal reference
  169. // outportb(BASE_ADDRESS, 0x02); // One channel, internal reference
  170. // write to CR1
  171. outportb(NEW_BASE_ADDRESS + 1, 0x04); // 4th word
  172. #ifdef BOARD_A2D_FOUR_SAMPLES
  173. outportb(NEW_BASE_ADDRESS, 0x8A); //(10011010)
  174. // 1------- output in binary format
  175. // -0------ RD: read input, WR: write input
  176. // --00---- DATA_AV: active low level
  177. // ----10-- trigger level 8
  178. // ------1- FIFO reset
  179. // -------0 no reset
  180. #else
  181. outportb(NEW_BASE_ADDRESS, 0x92); // 10010010
  182. // 1------- output in binary format
  183. // -0------ RD: read input, WR: write input
  184. // --01---- DATA_AV: active low pulse
  185. // ----00-- trigger level 1
  186. // ------1- FIFO reset
  187. // -------0 no reset
  188. #endif
  189. }
  190. // set type of board
  191. m_nBoardType = BT_NEW;
  192. // install handler
  193. m_pOldIsrProc = _dos_getvect( NEW_INTERRUPT_BOARD );
  194. _disable();
  195. _dos_setvect( NEW_INTERRUPT_BOARD, m_pIsrProc );
  196. outportb( PICIMR, inportb(PICIMR) & NEW_INTERRUPT_MASK );
  197. _enable();
  198. // enable devices
  199. outportb( NEW_BASE_ADDRESS + 2, m_bOutputMask |= BE_NEW_DEVICE0 | BE_NEW_DEVICE1 );
  200. return TRUE;
  201. }
  202. BOOL CBoard::Create( BOARD_SETTINGS* pSettings )
  203. {
  204. Destroy();
  205. m_Settings = *pSettings;
  206. #ifdef DEBUG_ENABLE_OLD_BOARD
  207. if( InitOldBoard() )
  208. return TRUE;
  209. #endif
  210. if( InitNewBoard() )
  211. return TRUE;
  212. return FALSE;
  213. }
  214. void CBoard::Destroy()
  215. {
  216. if( m_pOldIsrProc )
  217. {
  218. if( m_nBoardType == BT_NEW )
  219. {
  220. outportb( PICIMR, inportb(PICIMR) | !NEW_INTERRUPT_MASK );
  221. _disable();
  222. _dos_setvect( NEW_INTERRUPT_BOARD, m_pOldIsrProc );
  223. _enable();
  224. }
  225. #ifdef DEBUG_ENABLE_OLD_BOARD
  226. else
  227. if( m_nBoardType == BT_OLD )
  228. {
  229. #ifndef BOARD_BIND_IRQ_TO_SAPHIR
  230. outportb( PICIMR, inportb(PICIMR) | !OLD_INTERRUPT_MASK );
  231. outportb( OLD_BASE_ADDRESS, m_bOutputMask &= ~0x07 ); // Disable interrupt
  232. #endif
  233. _disable();
  234. _dos_setvect( OLD_INTERRUPT_BOARD, m_pOldIsrProc );
  235. _enable();
  236. }
  237. #endif
  238. m_pOldIsrProc = NULL;
  239. #ifndef BOARD_DEFFERED_PROCESSING
  240. m_bReady = FALSE;
  241. memset( &m_BoardData, 0, sizeof(BOARDDATA) );
  242. #endif
  243. }
  244. // unknown type of board
  245. m_nBoardType = BT_NONE;
  246. // used for A/D conversion
  247. #ifdef DEBUG_ENABLE_OLD_BOARD
  248. s_pDataArray[0] = s_pDataArray[1] = 0;
  249. #endif
  250. }