For DOS Protected Mode version of sensor core software
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.

1212 lines
32 KiB

3 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. #ifdef WATCHDOG_ENABLED
  16. #include "watchdog.h"
  17. #endif
  18. CBoard::CBoard( PISRPROC pIsrProc ) : CIsr( pIsrProc ){
  19. m_pOldIsrProc = NULL;
  20. mOld_TV = clock();
  21. m_wTimer = 0;
  22. mwBoardID=0;
  23. mwSoftwareID=0;
  24. g_bIsDMABoard = FALSE;
  25. //printf("Board's Constructor\n");
  26. #ifndef DEFAULT_DISC_C
  27. if ( g_bIsVortex ){
  28. nHID = 0;
  29. } else {
  30. nHID = 2;
  31. };
  32. #else
  33. nHID = 2;
  34. #endif
  35. g_bFlashDriveID = nHID;
  36. BSNS = NULL;
  37. BFCD = NULL;
  38. BSCD = NULL;
  39. bl_day = 0;
  40. bl_month = 0;
  41. bl_year = 0;
  42. fw_day = 0;
  43. fw_month = 0;
  44. fw_year = 0;
  45. #ifndef BOARD_DEFFERED_PROCESSING
  46. m_bReady = FALSE;
  47. memset( &m_BoardData, 0, sizeof(BOARDDATA) );
  48. #endif
  49. // unknown type of board
  50. m_nBoardType = BT_NONE;
  51. m_bBoardMCU = FALSE;
  52. m_bBoardBLO = FALSE;
  53. m_bOutputDirty = FALSE;
  54. m_Settings.M_LRFDisable = TRUE;
  55. m_Settings.S_LRFDisable = TRUE;
  56. #ifdef DEBUG_ENABLE_OLD_BOARD
  57. // used for A/D conversion
  58. s_pDataArray[0] = s_pDataArray[1] = 0;
  59. #endif
  60. // reset mask
  61. m_bOutputMask = 0;
  62. }
  63. CBoard::~CBoard(){
  64. if( BSNS != NULL ){
  65. free( BSNS );
  66. };
  67. if( BFCD != NULL ){
  68. free( BFCD );
  69. };
  70. if( BSCD != NULL ){
  71. free( BSCD );
  72. };
  73. UpdateLicensing();
  74. Destroy();
  75. }
  76. #ifdef DEBUG_ENABLE_OLD_BOARD
  77. BOOL CBoard::InitOldBoard(){
  78. g_bWorkEnable=TRUE;
  79. // try to initialize old board
  80. static short infoArray[11];// = { 0, 0x300, 5, 3, 12, 20, 0, 0, 0, 0, 0 };
  81. infoArray[0] = 0; // result
  82. infoArray[1] = 0x300; // base address
  83. infoArray[2] = 5; // interrupt level
  84. infoArray[3] = 3; // DMA level
  85. infoArray[4] = 12; // A/D resolution
  86. infoArray[5] = 20; // A/D scan interval
  87. infoArray[6] = 0; // reserved
  88. infoArray[7] = 0; // reserved
  89. infoArray[8] = 0; // reserved
  90. infoArray[9] = 0; // reserved
  91. infoArray[10] = 0; // reserved
  92. // initialize board
  93. SMM( 0, infoArray );
  94. if( infoArray[0] )
  95. return FALSE;
  96. infoArray[1] = 1; // Number of conversions
  97. infoArray[2] = FP_SEG(s_pDataArray);
  98. infoArray[3] = FP_OFF(s_pDataArray);
  99. infoArray[4] = 1; // Operation type
  100. infoArray[5] = 0; // Gain setting
  101. infoArray[6] = 0; // Low channel
  102. infoArray[7] = 1; // High channel
  103. infoArray[8] = 0; // reserved
  104. infoArray[9] = 0; // reserved
  105. infoArray[10] = 0; // reserved
  106. // Install ISR for Sapphire
  107. SMM(4, infoArray);
  108. if( infoArray[0] )
  109. return FALSE;
  110. // fix irq 7
  111. asm
  112. {
  113. mov AL, 0xDE
  114. out 0xF2, AL
  115. in AL, 0xF3
  116. and AL, 0xF3
  117. out 0xF3, AL
  118. }
  119. // set type of board
  120. m_nBoardType = BT_OLD;
  121. // install interrupt handler
  122. _disable();
  123. m_pOldIsrProc = _dos_getvect( OLD_INTERRUPT_BOARD );
  124. _dos_setvect( OLD_INTERRUPT_BOARD, m_pIsrProc );
  125. #ifndef BOARD_BIND_IRQ_TO_SAPHIR
  126. outportb(PICIMR, inportb(PICIMR) & OLD_INTERRUPT_MASK );
  127. inportb( OLD_BASE_ADDRESS ); // Reset interrupt trigger
  128. // outportb( OLD_BASE_ADDRESS, 0x01 );
  129. #endif
  130. _enable();
  131. #ifdef RELAY_ACTIVATE_BY_ZERO
  132. m_bOutputMask = 0x0;
  133. #else
  134. m_bOutputMask = 0x0;
  135. #endif
  136. // Enable two lasers
  137. outportb( OLD_BASE_ADDRESS, m_bOutputMask |= 0x07 );
  138. return TRUE;
  139. }
  140. #endif
  141. BYTE validateHexImage( char *FileName, BYTE MSB, BYTE LSB ){
  142. FILE *fileID = NULL;
  143. BYTE RetValue = 0;
  144. fileID = fopen( FileName, "r" );
  145. char Sig;
  146. BYTE InpB;
  147. BOOL inLine = FALSE;
  148. BYTE Stage = 0;
  149. BYTE RecLen = 0;
  150. BYTE CRec = 0;
  151. WORD OffSet = 0;
  152. WORD RecType = 0;
  153. BYTE RCheck = 0;
  154. WORD CCheck = 0;
  155. char InpC[3];
  156. char InpW[5];
  157. if( fileID ){
  158. RetValue = 1;
  159. while( !feof( fileID ) && RetValue == 1 ){
  160. if( !inLine ){
  161. fread( &Sig, 1, 1, fileID );
  162. if( Sig == ':' ) inLine = TRUE;
  163. CCheck = 0;
  164. Stage = 0;
  165. } else {
  166. switch( Stage ){
  167. case 0:{
  168. fread( &InpC, 2, 1, fileID );
  169. InpC[2]='\0';
  170. if( sscanf( InpC, "%x", &RecLen ) == 0 ) RetValue = 0;
  171. CCheck = RecLen;
  172. Stage = 1;
  173. break;
  174. };
  175. case 1:{
  176. fread( &InpW, 4, 1, fileID );
  177. InpW[4]='\0';
  178. if( sscanf( InpW, "%x", &OffSet )== 0 ) RetValue = 0;
  179. CCheck = ( CCheck + (OffSet >> 8 ) + (OffSet & 0xFF ) ) & 0xFF ;
  180. CRec = 0;
  181. Stage = 2;
  182. break;
  183. };
  184. case 2:{
  185. fread( &InpC, 2, 1, fileID );
  186. InpC[2]='\0';
  187. if( sscanf( InpC, "%x", &RecType ) == 0 ) RetValue = 0;
  188. CCheck = ( CCheck + RecType ) & 0xFF ;
  189. Stage = 3;
  190. break;
  191. };
  192. default:{
  193. fread( &InpC, 2, 1, fileID );
  194. InpC[2]='\0';
  195. if( sscanf( InpC, "%x", &InpB ) == 0 ) RetValue = 0;
  196. CCheck = ( CCheck + InpB ) & 0xFF ;
  197. if( CRec == RecLen ){
  198. inLine = FALSE;
  199. if( CCheck != 0 ) RetValue = 0;
  200. } else CRec++;
  201. };
  202. };
  203. };
  204. };
  205. fclose( fileID );
  206. };
  207. return RetValue;
  208. };
  209. FILE *FirmwarefileID = NULL;
  210. volatile BOOL FirmwareUpgradeDone = FALSE;
  211. void interrupt FirmwareUpdaterISR( ... ){
  212. BOOL LineIsSent;
  213. BYTE S_BUFFER[21];
  214. char Sig;
  215. BYTE InpB;
  216. BOOL inLine = FALSE;
  217. BYTE Stage = 0;
  218. BYTE RecLen = 0;
  219. BYTE CRec = 0;
  220. WORD OffSet = 0;
  221. WORD RecType = 0;
  222. BYTE RCheck = 0;
  223. WORD CCheck = 0;
  224. char InpC[3];
  225. char InpW[5];
  226. if( !feof( FirmwarefileID ) ){
  227. LineIsSent = FALSE;
  228. inLine = FALSE;
  229. while( !feof( FirmwarefileID ) && !LineIsSent ){
  230. if( !inLine ){
  231. fread( &Sig, 1, 1, FirmwarefileID );
  232. if( Sig == ':' ) inLine = TRUE;
  233. CCheck = 0;
  234. Stage = 0;
  235. } else {
  236. switch( Stage ){
  237. case 0:{
  238. fread( &InpC, 2, 1, FirmwarefileID );
  239. InpC[2]='\0';
  240. sscanf( InpC, "%x", &RecLen );
  241. CCheck = RecLen;
  242. S_BUFFER[0] = RecLen;
  243. //outportb(NEW_BASE_ADDRESS + 0x05, RecLen );
  244. Stage = 1;
  245. break;
  246. };
  247. case 1:{
  248. fread( &InpW, 4, 1, FirmwarefileID );
  249. InpW[4]='\0';
  250. sscanf( InpW, "%x", &OffSet );
  251. CCheck = ( CCheck + (OffSet >> 8 ) + (OffSet & 0xFF ) ) & 0xFF ;
  252. S_BUFFER[2] = (OffSet >> 8 ) & 0xFF;
  253. S_BUFFER[3] = OffSet & 0xFF;
  254. CRec = 0;
  255. Stage = 2;
  256. break;
  257. };
  258. case 2:{
  259. fread( &InpC, 2, 1, FirmwarefileID );
  260. InpC[2]='\0';
  261. sscanf( InpC, "%x", &RecType );
  262. CCheck = ( CCheck + RecType ) & 0xFF ;
  263. S_BUFFER[1] = RecType;
  264. Stage = 3;
  265. break;
  266. };
  267. default:{
  268. fread( &InpC, 2, 1, FirmwarefileID );
  269. InpC[2]='\0';
  270. sscanf( InpC, "%x", &InpB );
  271. CCheck = ( CCheck + InpB ) & 0xFF ;
  272. S_BUFFER[ 4 + CRec ] = InpB;
  273. if( CRec == RecLen ){ //Send To the board
  274. outp( PICICR, EOI );
  275. inLine = FALSE;
  276. outportb( NEW_RST_ADDRESS, S_BUFFER[ 0 ] );
  277. CRec = 1;
  278. while( CRec < ( RecLen + 5 ) ){
  279. outportb( NEW_DTA_ADDRESS, S_BUFFER[ CRec ] );
  280. CRec++;
  281. };
  282. LineIsSent = TRUE;
  283. //Confirm Record
  284. outportb( NEW_BASE_ADDRESS + 0x05, 0xFF );
  285. } else CRec++;
  286. };
  287. };
  288. };
  289. };
  290. };
  291. if( RecType == 0x01 ){
  292. FirmwareUpgradeDone = TRUE;
  293. };
  294. };
  295. BOOL StartDownloadHexImage( char *FileName, BYTE MSB, BYTE LSB ){
  296. FirmwarefileID = fopen( FileName, "r" );
  297. if( FirmwarefileID ){
  298. //Disable Watchdog
  299. unsigned char valb;
  300. outp(0x22, 0x13); // lock register
  301. outp(0x23, 0xc5); // unlock config
  302. outp(0x22, 0x37);
  303. valb = inp(0x23);
  304. outp(0x22, 0x37);
  305. outp( 0x23, valb & 0xBF);
  306. outp(0x22,0x13); //Lock reg
  307. outp(0x22,0x00); // Lock config
  308. // Instal IRQ Handler
  309. // m_pOldIsrProc = _dos_getvect( NEW_INTERRUPT_BOARD );
  310. outp( NEW_BL_ADDRESS, 0xAA ); // Start BootLoader Proc
  311. outp( NEW_BL_ADDRESS, 0x55 ); // Start BootLoader Proc
  312. outp( NEW_BL_ADDRESS, 0xAA ); // Start BootLoader Proc
  313. outp( NEW_BL_ADDRESS, 0x55 ); // Start BootLoader Proc
  314. delay( 5000 );
  315. int nono = 50;
  316. unsigned char TestBYTE = inportb( NEW_BL_ADDRESS );
  317. while ( nono && ( TestBYTE!= 0x5A || TestBYTE!= 0xA5 || TestBYTE == 0xAA ) ){
  318. nono--;
  319. TestBYTE = inportb( NEW_BL_ADDRESS );
  320. delay(100);
  321. };
  322. if( !( TestBYTE == 0xAA || TestBYTE == 0x55 ) ) return FALSE;
  323. _disable();
  324. _dos_setvect( NEW_INTERRUPT_BOARD, FirmwareUpdaterISR );
  325. outp( PICIMR, inportb(PICIMR) & NEW_INTERRUPT_MASK );
  326. _enable();
  327. FirmwareUpgradeDone = FALSE;
  328. FirmwareUpdaterISR();
  329. while( !FirmwareUpgradeDone ) delay( 1 );
  330. fclose( FirmwarefileID );
  331. FirmwarefileID = NULL;
  332. };
  333. return TRUE;
  334. };
  335. #ifdef LGS_MIR22ROR
  336. BOOL CBoard::InitNewBoard(){
  337. //#ifdef RELAY_ACTIVATE_BY_ZERO
  338. // m_bOutputMask = BE_NEW_DC0;
  339. //#else
  340. // m_bOutputMask = 0;
  341. //#endif
  342. // disable laser devices
  343. //outportb( NEW_BASE_ADDRESS + 2, m_bOutputMask &= ~(BE_NEW_DEVICE0 | BE_NEW_DEVICE1) );
  344. m_bOutputMask &= ~(BE_NEW_DEVICE0 | BE_NEW_DEVICE1);
  345. SetRelayBit( m_Settings.RelayDefaultMode );
  346. #ifdef BOARD_LAZY_INIT
  347. delay(2000); // Wait 2 seconds
  348. #endif
  349. // check if this is a new board
  350. unsigned char TestBYTE;
  351. int nono = 50;
  352. TestBYTE = inportb( NEW_ID_ADDRESS );
  353. #ifdef DEBUG_PRINTOUT_MSGS
  354. debugProcBegin("Checking Board Type");
  355. #endif
  356. while ( nono && TestBYTE!= 0x5A && TestBYTE!= 0xA5 && TestBYTE != 0xAA ){
  357. nono--;
  358. TestBYTE = inportb( NEW_ID_ADDRESS );
  359. delay(1);
  360. };
  361. #ifdef DEBUG_PRINTOUT_MSGS
  362. debugProcEnd();
  363. #endif
  364. if( TestBYTE == 0x5A ){
  365. m_bBoardMCU = TRUE;
  366. m_bBoardBLO = FALSE;
  367. g_bIsDMABoard = FALSE;
  368. #ifdef DEBUG_PRINTOUT_MSGS
  369. debug( "Board in IRQ mode" );
  370. #endif
  371. };
  372. if( TestBYTE == 0xA5 ){
  373. m_bBoardMCU = TRUE;
  374. m_bBoardBLO = FALSE;
  375. g_bIsDMABoard = TRUE;
  376. #ifdef DEBUG_PRINTOUT_MSGS
  377. debug("Board in DMA mode");
  378. #endif
  379. };
  380. if( TestBYTE == 0xAA ){
  381. m_bBoardBLO = TRUE;
  382. m_bBoardMCU = TRUE;
  383. g_bIsDMABoard = TRUE;
  384. #ifdef DEBUG_PRINTOUT_MSGS
  385. debug("Board in BootLoader mode");
  386. #endif
  387. };
  388. if( TestBYTE != 0xA5 && TestBYTE != 0x5A && TestBYTE != 0xAA ){
  389. m_bBoardBLO = FALSE;
  390. #ifdef DEBUG_PRINTOUT_MSGS
  391. debug("Oy Vey! Board is Old!");
  392. #endif
  393. #ifdef RESTART_PC_BY_WATCHDOG
  394. //No Board Init -> Restart WDT
  395. outportb( NEW_WDT_ADDRESS, 0xAA ); // Try To restart Board
  396. #ifdef WATCHDOG_ENABLED
  397. CWatchDog m_WatchDog;
  398. m_WatchDog.Create();
  399. m_WatchDog.Update( 255 );
  400. while(1);
  401. #endif
  402. #endif
  403. };
  404. BSNLB=0;
  405. BSNHB=0;
  406. // if not MCU board
  407. if( m_bBoardMCU ){
  408. if( g_bIsDMABoard ){
  409. outportb( NEW_RST_ADDRESS, 5 ); // Load 2 Bytes:
  410. delay(1);
  411. outportb( NEW_DTA_ADDRESS, m_bOutputMask ); // Status - LRF Off
  412. delay(1);
  413. outportb( NEW_DTA_ADDRESS, 3 ); // Stop DMA
  414. // nessesary to make delay
  415. #ifdef DEBUG_PRINTOUT_MSGS
  416. debug("Stoped DMA Transfers (if Any )");
  417. #endif
  418. if( g_bWorkEnable == FALSE ){
  419. delay(1);
  420. outportb( NEW_RST_ADDRESS, 0 ); // Load Full Data
  421. #ifdef DEBUG_PRINTOUT_MSGS
  422. debugProcBegin("Read BSN");
  423. #endif
  424. delay(1);
  425. BSNLB = inportb( NEW_DTA_ADDRESS ); // 1
  426. delay(1);
  427. BSNHB = inportb( NEW_DTA_ADDRESS ); // 2
  428. delay(1);
  429. fw_year = inportb( NEW_DTA_ADDRESS ); // 3
  430. delay(1);
  431. fw_month = inportb( NEW_DTA_ADDRESS ); // 4
  432. delay(1);
  433. fw_day = inportb( NEW_DTA_ADDRESS ); // 5
  434. delay(1);
  435. bl_year = inportb( NEW_DTA_ADDRESS ); // 6
  436. delay(1);
  437. bl_month = inportb( NEW_DTA_ADDRESS ); // 7
  438. delay(1);
  439. bl_day = inportb( NEW_DTA_ADDRESS ); // 8
  440. mwBoardID = (( BSNHB<<8) | BSNLB );
  441. if ( ~( mwBoardID ^ mwSoftwareID ) == 0 ){
  442. g_bWorkEnable = TRUE;
  443. #ifdef DEBUG_PRINTOUT_MSGS
  444. debugProcEnd();
  445. #endif
  446. } else {
  447. #ifdef DEBUG_PRINTOUT_MSGS
  448. debugProcEnd( 0 );
  449. #endif
  450. };
  451. };
  452. ffblk buffer[1];
  453. if ( findfirst("firmware", buffer,0)==0 ){
  454. #ifdef DEBUG_PRINTOUT_MSGS
  455. debugProcBegin("Upgrading Board Firmware");
  456. debugProcBegin("Checking Firmware Integrity");
  457. #endif
  458. if( validateHexImage( "firmware", BSNHB, BSNLB ) ){
  459. #ifdef DEBUG_PRINTOUT_MSGS
  460. debugProcEnd();
  461. debugProcBegin("Sending Firmware to Board");
  462. #endif
  463. if( StartDownloadHexImage( "firmware", BSNHB, BSNLB ) ){
  464. #ifdef DEBUG_PRINTOUT_MSGS
  465. debugProcEnd();
  466. #endif
  467. #ifndef LGS_PLS_1
  468. delay( 15000 );
  469. #else
  470. delay( 5000 );
  471. #endif
  472. } else {
  473. #ifdef DEBUG_PRINTOUT_MSGS
  474. debugProcEnd();
  475. #endif
  476. };
  477. } else {
  478. #ifdef DEBUG_PRINTOUT_MSGS
  479. debugProcEnd( 0 );
  480. #endif
  481. };
  482. unlink("firmware");
  483. #ifdef DEBUG_PRINTOUT_MSGS
  484. debugProcEnd();
  485. #endif
  486. return FALSE;
  487. } else {
  488. if( m_bBoardBLO ) return TRUE; // Don't do Init to the board if in BootLoader Mode
  489. };
  490. #ifdef DEBUG_PRINTOUT_MSGS
  491. debugProcBegin("Downloading Board Parameters");
  492. #endif
  493. delay(1);
  494. outportb( NEW_RST_ADDRESS, 0 ); // Full Upload
  495. delay(1);
  496. outportb( NEW_DTA_ADDRESS, mwSoftwareID & 0xFF ); // 1 Serial Number
  497. delay(1);
  498. outportb( NEW_DTA_ADDRESS, ( mwSoftwareID >> 8 ) & 0xFF ); // 2
  499. delay(1);
  500. outportb( NEW_DTA_ADDRESS, 0x00 );//m_Settings.nZeroShift & 0xFF ); // 3
  501. delay(1);
  502. outportb( NEW_DTA_ADDRESS, 0x00 );//( m_Settings.nZeroShift >> 8 ) & 0xFF ); // 4 Zero offset
  503. delay(1);
  504. outportb( NEW_DTA_ADDRESS, m_Settings.nTemperature ); // 5 Temp
  505. delay(1);
  506. outportb( NEW_DTA_ADDRESS, m_bOutputMask ); // 6 Work Status
  507. delay(1);
  508. outportb( NEW_DTA_ADDRESS, 3 ); // 7 Reset DMA
  509. #ifdef DEBUG_PRINTOUT_MSGS
  510. debugProcEnd();
  511. debugProcBegin("Wait Till Board INIT done");
  512. #endif
  513. delay(1);
  514. //Wait till speed/reset is done
  515. TestBYTE = inportb( NEW_ID_ADDRESS );
  516. nono = 15000;
  517. while ( nono && TestBYTE!= 0x5A && TestBYTE!= 0xA5 && TestBYTE != 0xAA ){
  518. nono--;
  519. TestBYTE = inportb( NEW_ID_ADDRESS );
  520. delay(1);
  521. };
  522. #ifdef DEBUG_PRINTOUT_MSGS
  523. debugProcEnd();
  524. debugProcBegin("Alloc DMA Buffer");
  525. #endif
  526. Assign_DMA_Buffer ( DMA_TRANSFER_CHUNK * DMA_TRANSFER_ZONES );
  527. #ifdef DEBUG_PRINTOUT_MSGS
  528. debugProcEnd();
  529. #endif
  530. m_nbWriteChunk = 0;
  531. m_nbReadChunk = 0;
  532. m_nwChunkInterator = 0;
  533. InitDMA( DMA_CHANNEL , DMA_BUFFER, DMA_TRANSFER_CHUNK );
  534. } else { // IRQ MCU Board
  535. // disable interrupts
  536. disable();
  537. delay(1);
  538. outportb( NEW_BASE_ADDRESS + 2, m_bOutputMask );
  539. // nessesary to make delay
  540. delay(100);
  541. BSNLB=inportb( NEW_BASE_ADDRESS + 6 );
  542. BSNHB=inportb( NEW_BASE_ADDRESS + 7 );
  543. mwBoardID = (( BSNHB<<8) | BSNLB );
  544. if ( ~( mwBoardID ^ mwSoftwareID ) == 0 ){
  545. g_bWorkEnable = TRUE;
  546. };
  547. outportb( NEW_BASE_ADDRESS + 6, ( unsigned char )( mwSoftwareID & 0xFF )); // Sending SoftwareID to the Board
  548. outportb( NEW_BASE_ADDRESS + 7, ( unsigned char )(( mwSoftwareID >> 8 ) & 0xFF));
  549. //outportb( NEW_BASE_ADDRESS + 3, 0 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nGearRatio >> 8 ); // motor ratio
  550. //outportb( NEW_BASE_ADDRESS + 3, 1 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nGearRatio & 0xFF );
  551. //outportb( NEW_BASE_ADDRESS + 3, 2 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nEncoderSteps >> 8 ); // encoder count
  552. //outportb( NEW_BASE_ADDRESS + 3, 3 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nEncoderSteps & 0xFF );
  553. outportb( NEW_BASE_ADDRESS + 3, 4 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nTemperature ); // temperature
  554. delay( 10 );
  555. outportb( NEW_BASE_ADDRESS + 3, 5 ); outportb( NEW_BASE_ADDRESS + 4, 0x00 );//m_Settings.nZeroShift >> 8 ); // zero offset
  556. delay( 10 );
  557. outportb( NEW_BASE_ADDRESS + 3, 6 ); outportb( NEW_BASE_ADDRESS + 4, 0x00 );//m_Settings.nZeroShift & 0xFF );
  558. //outportb( NEW_BASE_ADDRESS + 3, 7 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nMaxRange >> 8 );
  559. //outportb( NEW_BASE_ADDRESS + 3, 8 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nMaxRange & 0xFF ); // max range
  560. };
  561. } else { // No MCU Board
  562. g_bWorkEnable = TRUE; // Old Board = Work Always
  563. // write to CR0
  564. outportb(NEW_BASE_ADDRESS + 1, 0x04); // 1st word
  565. outportb(NEW_BASE_ADDRESS, 0x01);
  566. // write to CR1
  567. outportb(NEW_BASE_ADDRESS + 1, 0x04); // 2nd word
  568. outportb(NEW_BASE_ADDRESS, 0x00);
  569. // write to CR0
  570. outportb(NEW_BASE_ADDRESS + 1, 0x00); // 3th word
  571. outportb(NEW_BASE_ADDRESS, 0x8A); // 10001010
  572. // 10001--- autoscan two single-ended channels,
  573. // -----0-- ADC is active,
  574. // ------1- single conversation mode
  575. // -------0 internal reference
  576. // outportb(BASE_ADDRESS, 0x02); // One channel, internal reference
  577. // write to CR1
  578. outportb(NEW_BASE_ADDRESS + 1, 0x04); // 4th word
  579. #ifdef BOARD_A2D_FOUR_SAMPLES
  580. outportb(NEW_BASE_ADDRESS, 0x8A); //(10011010)
  581. // 1------- output in binary format
  582. // -0------ RD: read input, WR: write input
  583. // --00---- DATA_AV: active low level
  584. // ----10-- trigger level 8
  585. // ------1- FIFO reset
  586. // -------0 no reset
  587. #else
  588. outportb(NEW_BASE_ADDRESS, 0x92); // 10010010
  589. // 1------- output in binary format
  590. // -0------ RD: read input, WR: write input
  591. // --01---- DATA_AV: active low pulse
  592. // ----00-- trigger level 1
  593. // ------1- FIFO reset
  594. // -------0 no reset
  595. #endif
  596. }
  597. // set type of board
  598. m_nBoardType = BT_NEW;
  599. if( g_bIsDMABoard ){ // DMA Mode
  600. #ifdef DEBUG_PRINTOUT_MSGS
  601. debug("Board DMA Transfers Started");
  602. #endif
  603. m_bResetIssued = FALSE;
  604. // install handler
  605. _disable();
  606. m_pOldIsrProc = _dos_getvect( NEW_INTERRUPT_BOARD );
  607. _dos_setvect( NEW_INTERRUPT_BOARD, m_pIsrProc );
  608. //outportb( PICICR, PICROT | 0x04 ); // Prioritize IRQ5 as most VII
  609. outportb( PICIMR, inportb(PICIMR) & NEW_INTERRUPT_MASK );
  610. _enable();
  611. m_bDMA_CRASH = FALSE;
  612. m_bOutputMask |= (m_Settings.M_LRFDisable?0:BE_NEW_DEVICE0) | (m_Settings.S_LRFDisable?0:BE_NEW_DEVICE1); // Set LRF ON
  613. SetRelayBit( m_Settings.RelayDefaultMode );
  614. delay(1);
  615. outportb( NEW_RST_ADDRESS, 5 ); // Set 2 Bytes:
  616. delay(1);
  617. outportb( NEW_DTA_ADDRESS, m_bOutputMask ); // 1 Status
  618. delay(1);
  619. outportb( NEW_DTA_ADDRESS, 1 ); // 2 Start DMA
  620. delay(1);
  621. #ifdef DEBUG_PRINTOUT_MSGS
  622. debugProcEnd();
  623. #endif
  624. } else { // IRQ Mode
  625. #ifdef DEBUG_PRINTOUT_MSGS
  626. debug("Board IRQ Transfers Started");
  627. #endif
  628. // install handler
  629. m_pOldIsrProc = _dos_getvect( NEW_INTERRUPT_BOARD );
  630. _disable();
  631. _dos_setvect( NEW_INTERRUPT_BOARD, m_pIsrProc );
  632. outportb( PICIMR, inportb(PICIMR) & NEW_INTERRUPT_MASK );
  633. _enable();
  634. // enable devices
  635. delay( 10 );
  636. m_bOutputMask |= (m_Settings.M_LRFDisable?0:BE_NEW_DEVICE0) | (m_Settings.S_LRFDisable?0:BE_NEW_DEVICE1);
  637. SetRelayBit( m_Settings.RelayDefaultMode );
  638. outportb( NEW_BASE_ADDRESS + 2, m_bOutputMask );
  639. #ifdef DEBUG_PRINTOUT_MSGS
  640. debugProcEnd();
  641. #endif
  642. };
  643. m_nOldAngle = 0;
  644. return TRUE;
  645. }
  646. #else //ALL Other(ALL) Devices
  647. BOOL CBoard::InitNewBoard(){
  648. //printf("Sending to Board Temp Settings: %d\n", m_Settings.nTemperature );
  649. // control register 0
  650. // 0 - VREF (0=internal, 1=external)
  651. // 1 - MODE (0-continues conversations, 1-single conversation )
  652. // 2 - POWER_DOWN (0-active, 1-power down)
  653. // 3,4 - CHANAL SELECT
  654. // 5,6 - NUMBER OF DIFFERENTION CHANALS
  655. // 7 - AUTOSCAN ENABLE
  656. // 8,9 - TEST INPUT ENABLE
  657. // control register 1
  658. // 0 - RESET
  659. // 1 - FIFO_RESET
  660. // 2 - FIFO_LEVEL
  661. // 3 - FIFO_LEVEL
  662. // 4 - DATA_AVALIBLE TYPE (pulse = 1, static = 0)
  663. // 5 - DATA_AVALIBLE POLARITY (hi = 1,0 = low)
  664. // 6 - R/W, RD/WR SELECTION
  665. // 7 - BIN/2s DATA FORMAT (binary = 1, 2s = 0 )
  666. // 8 - OFFSET (0=normal, 1=offset calibration)
  667. // 9 - RBACK (0=normal, 1=debug mode)
  668. //#ifdef RELAY_ACTIVATE_BY_ZERO
  669. // m_bOutputMask = BE_NEW_DC0;
  670. //#else
  671. // m_bOutputMask = 0;
  672. //#endif
  673. // disable laser devices
  674. //outportb( NEW_BASE_ADDRESS + 2, m_bOutputMask &= ~(BE_NEW_DEVICE0 | BE_NEW_DEVICE1) );
  675. #ifdef BOARD_LAZY_INIT
  676. //delay(2000); // Wait 2 seconds
  677. #endif
  678. /*
  679. * Cecking Before All if Firmware must be upgraded
  680. */
  681. ffblk buffer[1];
  682. if( findfirst("firmware", buffer, 0 )==0 ){
  683. #ifdef DEBUG_PRINTOUT_MSGS
  684. debugProcBegin("Upgrading Board Firmware");
  685. debugProcBegin("Checking Firmware Integrity");
  686. #endif
  687. if( validateHexImage( "firmware", BSNHB, BSNLB ) ){
  688. #ifdef DEBUG_PRINTOUT_MSGS
  689. debugProcEnd();
  690. debugProcBegin("Sending Firmware to Board");
  691. #endif
  692. if( StartDownloadHexImage( "firmware", BSNHB, BSNLB ) ){
  693. #ifdef DEBUG_PRINTOUT_MSGS
  694. debugProcEnd();
  695. #endif
  696. #ifndef LGS_PLS_1
  697. delay( 15000 );
  698. #else
  699. delay( 5000 );
  700. #endif
  701. } else {
  702. #ifdef DEBUG_PRINTOUT_MSGS
  703. debugProcEnd();
  704. #endif
  705. };
  706. } else {
  707. #ifdef DEBUG_PRINTOUT_MSGS
  708. debugProcEnd( 0 );
  709. #endif
  710. };
  711. unlink("firmware");
  712. #ifdef DEBUG_PRINTOUT_MSGS
  713. debugProcEnd();
  714. #endif
  715. return FALSE;
  716. } else {
  717. if( m_bBoardBLO ) return TRUE; // Don't do Init to the board if in BootLoader Mode
  718. };
  719. /*
  720. * After BootLoader - Firmware checking do regular INIT
  721. */
  722. m_bOutputMask &= ~(BE_NEW_DEVICE0 | BE_NEW_DEVICE1);
  723. SetRelayBit( m_Settings.RelayDefaultMode );
  724. // check if this is a new board
  725. unsigned char TestBYTE;
  726. #ifdef BOARD_LAZY_INIT
  727. int nono = 150;
  728. #else
  729. int nono = 50;
  730. #endif
  731. TestBYTE = inportb( NEW_ID_ADDRESS );
  732. #ifdef DEBUG_PRINTOUT_MSGS
  733. debugProcBegin("Checking Board Type");
  734. #endif
  735. while ( nono && TestBYTE!= 0x5A && TestBYTE!= 0xA5 && TestBYTE != 0xAA ){
  736. nono--;
  737. TestBYTE = inportb( NEW_ID_ADDRESS ); //+5 ??
  738. #ifdef DEBUG_PRINTOUT_MSGS
  739. //putch(176);
  740. #endif
  741. delay(1);
  742. };
  743. #ifdef DEBUG_PRINTOUT_MSGS
  744. debugProcEnd();
  745. #endif
  746. // default Board Props
  747. m_bBoardMCU = TRUE;
  748. g_bIsDMABoard = TRUE;
  749. m_bBoardBLO = FALSE;
  750. #if !( defined(LGS_PLS_1) || defined( LGS_STEPPER ) || defined( LGS_MND ) )
  751. if( TestBYTE == 0x5A ){
  752. m_bBoardMCU = TRUE;
  753. m_bBoardBLO = FALSE;
  754. g_bIsDMABoard = FALSE;
  755. #ifdef DEBUG_PRINTOUT_MSGS
  756. debug( "Board in IRQ mode" );
  757. #endif
  758. };
  759. if( TestBYTE == 0xA5 ){
  760. m_bBoardMCU = TRUE;
  761. m_bBoardBLO = FALSE;
  762. g_bIsDMABoard = TRUE;
  763. #ifdef DEBUG_PRINTOUT_MSGS
  764. debug("Board in DMA mode");
  765. #endif
  766. };
  767. if( TestBYTE == 0xAA ){
  768. m_bBoardBLO = TRUE;
  769. m_bBoardMCU = TRUE;
  770. g_bIsDMABoard = TRUE;
  771. #ifdef DEBUG_PRINTOUT_MSGS
  772. debug("Board in BootLoader mode");
  773. #endif
  774. };
  775. if( TestBYTE != 0xA5 && TestBYTE != 0x5A && TestBYTE != 0xAA ){
  776. m_bBoardBLO = FALSE;
  777. #ifdef DEBUG_PRINTOUT_MSGS
  778. debug("Oy Vey! Board is Old!");
  779. #endif
  780. #ifdef RESTART_PC_BY_WATCHDOG
  781. //No Board Init -> Try Restart WDT
  782. outportb( NEW_WDT_ADDRESS, 0xAA ); // Try To restart Board
  783. #ifdef WATCHDOG_ENABLED
  784. CWatchDog m_WatchDog;
  785. m_WatchDog.Create();
  786. m_WatchDog.Update( 255 );
  787. while(1);
  788. #endif
  789. #else
  790. return FALSE;
  791. #endif
  792. };
  793. #else // Not Step Motor board
  794. if( TestBYTE == 0xAA ){
  795. m_bBoardBLO = TRUE;
  796. } else {
  797. m_bBoardBLO = FALSE;
  798. };
  799. m_bBoardMCU = TRUE;
  800. g_bIsDMABoard = TRUE;
  801. if( TestBYTE != 0xA5 && TestBYTE != 0x5A && TestBYTE != 0xAA ){
  802. m_bBoardBLO = FALSE;
  803. #ifdef DEBUG_PRINTOUT_MSGS
  804. debug("Oy Vey! Board is Old!");
  805. #endif
  806. #ifdef RESTART_PC_BY_WATCHDOG
  807. //No Bard Init -> Restart WDT
  808. outportb( NEW_WDT_ADDRESS, 0xAA ); // Try To restart Board
  809. #ifdef WATCHDOG_ENABLED
  810. CWatchDog m_WatchDog;
  811. m_WatchDog.Create();
  812. m_WatchDog.Update( 255 );
  813. while(1);
  814. #endif
  815. #else
  816. return FALSE;
  817. #endif
  818. };
  819. #endif // Not a Step Motor Board
  820. BSNLB=0;
  821. BSNHB=0;
  822. // if not MCU board
  823. if( m_bBoardMCU ){
  824. if( g_bIsDMABoard ){
  825. #if !( defined(LGS_PLS_1) || defined( LGS_STEPPER ) || defined( LGS_MND ) )
  826. outportb( NEW_RST_ADDRESS, 5 ); // Status + DMA Upload
  827. #else
  828. outportb( NEW_RST_ADDRESS, 7 ); // Status + DMA Upload
  829. #endif
  830. // delay(1);
  831. outportb( NEW_DTA_ADDRESS, m_bOutputMask );
  832. //delay(1);
  833. outportb( NEW_DTA_ADDRESS, 3 ); // Stop DMA
  834. // nessesary to make delay
  835. #ifdef DEBUG_PRINTOUT_MSGS
  836. debug("Stoped DMA Transfers (if Any )");
  837. #endif
  838. if( g_bWorkEnable == FALSE ){
  839. delay(10);
  840. int nono = 10;
  841. while ( nono && inportb( NEW_RST_ADDRESS )!= 0x5A ){
  842. nono--; // Full Upload
  843. delay(1);
  844. };
  845. #ifdef DEBUG_PRINTOUT_MSGS
  846. debugProcBegin("Read BSN");
  847. #endif
  848. delay(1);
  849. BSNLB = inportb( NEW_DTA_ADDRESS );
  850. delay(1);
  851. BSNHB = inportb( NEW_DTA_ADDRESS );
  852. delay(1);
  853. fw_year = inportb( NEW_DTA_ADDRESS );
  854. delay(1);
  855. fw_month = inportb( NEW_DTA_ADDRESS );
  856. delay(1);
  857. fw_day = inportb( NEW_DTA_ADDRESS );
  858. delay(1);
  859. bl_year = inportb( NEW_DTA_ADDRESS );
  860. delay(1);
  861. bl_month = inportb( NEW_DTA_ADDRESS );
  862. delay(1);
  863. bl_day = inportb( NEW_DTA_ADDRESS );
  864. mwBoardID = (( BSNHB<<8) | BSNLB );
  865. if ( ~( mwBoardID ^ mwSoftwareID ) == 0 ){
  866. g_bWorkEnable = TRUE;
  867. #ifdef DEBUG_PRINTOUT_MSGS
  868. debugProcEnd();
  869. #endif
  870. } else {
  871. #ifdef DEBUG_PRINTOUT_MSGS
  872. debugProcEnd( 0 );
  873. #endif
  874. };
  875. };
  876. #ifdef DEBUG_PRINTOUT_MSGS
  877. debugProcBegin("Downloading Board Parameters");
  878. #endif
  879. outportb( NEW_RST_ADDRESS, 0 ); // Full Upload
  880. outportb( NEW_DTA_ADDRESS, mwSoftwareID & 0xFF ); // Serial Number
  881. outportb( NEW_DTA_ADDRESS, ( mwSoftwareID >> 8 ) & 0xFF );
  882. #if defined( LGS_PLS_1 ) || defined( LGS_STEPPER ) || defined( LGS_MND )
  883. #ifdef LGS_PLS_200
  884. outportb( NEW_DTA_ADDRESS, ( m_Settings.nMotorSpeed * 535 * 3 ) & 0xFF );
  885. outportb( NEW_DTA_ADDRESS, ( ( m_Settings.nMotorSpeed * 535 * 3 ) >> 8 ) & 0xFF );
  886. #else
  887. outportb( NEW_DTA_ADDRESS, ( m_Settings.nMotorSpeed * 535 ) & 0xFF );
  888. outportb( NEW_DTA_ADDRESS, ( ( m_Settings.nMotorSpeed * 535 ) >> 8 ) & 0xFF );
  889. #endif
  890. #endif
  891. outportb( NEW_DTA_ADDRESS, 0x00 );//m_Settings.nZeroShift & 0xFF );
  892. outportb( NEW_DTA_ADDRESS, 0x00 );//m_Settings.nZeroShift >> 8 ); // Zero offset
  893. outportb( NEW_DTA_ADDRESS, m_Settings.nTemperature ); // Temp
  894. outportb( NEW_DTA_ADDRESS, m_bOutputMask ); // Work Status
  895. outportb( NEW_DTA_ADDRESS, 3 ); // Reset DMA
  896. #ifdef DEBUG_PRINTOUT_MSGS
  897. debugProcEnd();
  898. debugProcBegin("Alloc DMA Buffer");
  899. #endif
  900. Assign_DMA_Buffer ( DMA_TRANSFER_CHUNK * DMA_TRANSFER_ZONES );
  901. #ifdef DEBUG_PRINTOUT_MSGS
  902. debugProcEnd();
  903. #endif
  904. m_nbWriteChunk = 0;
  905. m_nbReadChunk = 0;
  906. m_nwChunkInterator = 0;
  907. InitDMA( DMA_CHANNEL , DMA_BUFFER, DMA_TRANSFER_CHUNK );
  908. } else {
  909. // disable interrupts
  910. disable();
  911. outportb( NEW_BASE_ADDRESS + 2, m_bOutputMask );
  912. // nessesary to make delay
  913. delay(100);
  914. BSNLB=inportb( NEW_BASE_ADDRESS + 6 );
  915. BSNHB=inportb( NEW_BASE_ADDRESS + 7 );
  916. mwBoardID = (( BSNHB<<8) | BSNLB );
  917. if ( ~( mwBoardID ^ mwSoftwareID ) == 0 ){
  918. g_bWorkEnable = TRUE;
  919. };
  920. outportb( NEW_BASE_ADDRESS + 6, ( unsigned char )( mwSoftwareID & 0xFF )); // Sending SoftwareID to the Board
  921. outportb( NEW_BASE_ADDRESS + 7, ( unsigned char )(( mwSoftwareID >> 8 ) & 0xFF));
  922. //outportb( NEW_BASE_ADDRESS + 3, 0 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nGearRatio >> 8 ); // motor ratio
  923. //outportb( NEW_BASE_ADDRESS + 3, 1 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nGearRatio & 0xFF );
  924. //outportb( NEW_BASE_ADDRESS + 3, 2 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nEncoderSteps >> 8 ); // encoder count
  925. //outportb( NEW_BASE_ADDRESS + 3, 3 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nEncoderSteps & 0xFF );
  926. outportb( NEW_BASE_ADDRESS + 3, 4 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nTemperature ); // temperature
  927. delay( 10 );
  928. outportb( NEW_BASE_ADDRESS + 3, 5 ); outportb( NEW_BASE_ADDRESS + 4, 0x00 );//m_Settings.nZeroShift >> 8 ); // zero offset
  929. delay( 10 );
  930. outportb( NEW_BASE_ADDRESS + 3, 6 ); outportb( NEW_BASE_ADDRESS + 4, 0x00 );//m_Settings.nZeroShift & 0xFF );
  931. // outportb( NEW_BASE_ADDRESS + 3, 7 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nMaxRange >> 8 );
  932. // outportb( NEW_BASE_ADDRESS + 3, 8 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nMaxRange & 0xFF ); // max range
  933. };
  934. } else {
  935. g_bWorkEnable = TRUE; // Old Board = Work Always
  936. // write to CR0
  937. outportb(NEW_BASE_ADDRESS + 1, 0x04); // 1st word
  938. outportb(NEW_BASE_ADDRESS, 0x01);
  939. // write to CR1
  940. outportb(NEW_BASE_ADDRESS + 1, 0x04); // 2nd word
  941. outportb(NEW_BASE_ADDRESS, 0x00);
  942. // write to CR0
  943. outportb(NEW_BASE_ADDRESS + 1, 0x00); // 3th word
  944. outportb(NEW_BASE_ADDRESS, 0x8A); // 10001010
  945. // 10001--- autoscan two single-ended channels,
  946. // -----0-- ADC is active,
  947. // ------1- single conversation mode
  948. // -------0 internal reference
  949. // outportb(BASE_ADDRESS, 0x02); // One channel, internal reference
  950. // write to CR1
  951. outportb(NEW_BASE_ADDRESS + 1, 0x04); // 4th word
  952. #ifdef BOARD_A2D_FOUR_SAMPLES
  953. outportb(NEW_BASE_ADDRESS, 0x8A); //(10011010)
  954. // 1------- output in binary format
  955. // -0------ RD: read input, WR: write input
  956. // --00---- DATA_AV: active low level
  957. // ----10-- trigger level 8
  958. // ------1- FIFO reset
  959. // -------0 no reset
  960. #else
  961. outportb(NEW_BASE_ADDRESS, 0x92); // 10010010
  962. // 1------- output in binary format
  963. // -0------ RD: read input, WR: write input
  964. // --01---- DATA_AV: active low pulse
  965. // ----00-- trigger level 1
  966. // ------1- FIFO reset
  967. // -------0 no reset
  968. #endif
  969. }
  970. // set type of board
  971. m_nBoardType = BT_NEW;
  972. if( g_bIsDMABoard ){
  973. #ifdef DEBUG_PRINTOUT_MSGS
  974. debug("Board DMA Transfers Started");
  975. #endif
  976. m_bResetIssued = FALSE;
  977. // install handler
  978. m_pOldIsrProc = _dos_getvect( NEW_INTERRUPT_BOARD );
  979. _disable();
  980. _dos_setvect( NEW_INTERRUPT_BOARD, m_pIsrProc );
  981. outportb( PICIMR, inportb(PICIMR) & NEW_INTERRUPT_MASK );
  982. _enable();
  983. //SignalToBoard( 0x301 ); // Init DMA
  984. m_bDMA_CRASH = FALSE;
  985. m_bOutputMask |= (m_Settings.M_LRFDisable?0:BE_NEW_DEVICE0) | (m_Settings.S_LRFDisable?0:BE_NEW_DEVICE1);
  986. SetRelayBit( m_Settings.RelayDefaultMode );
  987. #if !( defined(LGS_PLS_1) || defined( LGS_STEPPER ) || defined( LGS_MND ) )
  988. outportb( NEW_RST_ADDRESS, 5 ); // Status + DMA Upload
  989. #else
  990. outportb( NEW_RST_ADDRESS, 7 ); // Status + DMA Upload
  991. #endif
  992. outportb( NEW_DTA_ADDRESS, m_bOutputMask );
  993. outportb( NEW_DTA_ADDRESS, 1 ); // Init DMA
  994. #ifdef DEBUG_PRINTOUT_MSGS
  995. debugProcEnd();
  996. #endif
  997. } else {
  998. #ifdef DEBUG_PRINTOUT_MSGS
  999. debug("Board IRQ Transfers Started");
  1000. #endif
  1001. // install handler
  1002. m_pOldIsrProc = _dos_getvect( NEW_INTERRUPT_BOARD );
  1003. _disable();
  1004. _dos_setvect( NEW_INTERRUPT_BOARD, m_pIsrProc );
  1005. outportb( PICIMR, inportb(PICIMR) & NEW_INTERRUPT_MASK );
  1006. _enable();
  1007. // enable devices
  1008. delay( 10 );
  1009. m_bOutputMask |= (m_Settings.M_LRFDisable?0:BE_NEW_DEVICE0) | (m_Settings.S_LRFDisable?0:BE_NEW_DEVICE1);
  1010. SetRelayBit( m_Settings.RelayDefaultMode );
  1011. outportb( NEW_BASE_ADDRESS + 2, m_bOutputMask );
  1012. #ifdef DEBUG_PRINTOUT_MSGS
  1013. debugProcEnd();
  1014. #endif
  1015. };
  1016. m_nRealAngle = -1;
  1017. m_nErrorAngle = -1;
  1018. return TRUE;
  1019. }
  1020. #endif // LGS_MIRROR
  1021. BOOL CBoard::Create( BOARD_SETTINGS* pSettings ){
  1022. #ifndef DEFAULT_DISC_C
  1023. if ( g_bIsVortex ){
  1024. nHID = 0;
  1025. } else {
  1026. nHID = 2;
  1027. };
  1028. #else
  1029. nHID = 2;
  1030. #endif
  1031. if( pSettings != NULL ){
  1032. m_Settings = *pSettings;
  1033. };
  1034. Destroy();
  1035. if ( m_Settings.nHID < 255 ){
  1036. nHID = m_Settings.nHID;
  1037. g_bFlashDriveID = nHID;
  1038. };
  1039. #ifdef DEBUG_PRINTOUT_MSGS
  1040. debug( "SetUp Settings : Disk: %d",nHID );
  1041. debugProcBegin( "License Check ");
  1042. #endif
  1043. SetupLicense();
  1044. #ifdef DEBUG_PRINTOUT_MSGS
  1045. debugProcEnd();
  1046. #endif
  1047. SetRelayBit( m_Settings.RelayDefaultMode );
  1048. #ifndef BOARD_SIMULATION
  1049. if( InitNewBoard() )
  1050. return TRUE;
  1051. #ifdef DEBUG_ENABLE_OLD_BOARD
  1052. if( InitOldBoard() )
  1053. return TRUE;
  1054. #endif
  1055. return FALSE;
  1056. #else
  1057. return TRUE;
  1058. #endif // BOARD_SIMULATION
  1059. }
  1060. void CBoard::Destroy(){
  1061. #ifndef BOARD_SIMULATION
  1062. SetRelayBit( m_Settings.RelayDefaultMode );
  1063. if( m_pOldIsrProc )
  1064. {
  1065. if( m_nBoardType == BT_NEW )
  1066. {
  1067. if( g_bIsDMABoard ){
  1068. m_bResetIssued = TRUE;
  1069. int nono = 10;
  1070. while ( nono && m_bResetIssued ){
  1071. nono--;
  1072. delay(100);
  1073. };
  1074. };
  1075. _disable();
  1076. outportb( PICIMR, inportb(PICIMR) | !NEW_INTERRUPT_MASK );
  1077. _dos_setvect( NEW_INTERRUPT_BOARD, m_pOldIsrProc );
  1078. _enable();
  1079. }
  1080. #ifdef DEBUG_ENABLE_OLD_BOARD
  1081. else
  1082. if( m_nBoardType == BT_OLD )
  1083. {
  1084. #ifndef BOARD_BIND_IRQ_TO_SAPHIR
  1085. outportb( PICIMR, inportb(PICIMR) | !OLD_INTERRUPT_MASK );
  1086. m_bOutputMask &= ~0x07;
  1087. SetRelayBit( m_Settings.RelayDefaultMode );
  1088. outportb( OLD_BASE_ADDRESS, m_bOutputMask ); // Disable interrupt
  1089. #endif
  1090. _disable();
  1091. _dos_setvect( OLD_INTERRUPT_BOARD, m_pOldIsrProc );
  1092. _enable();
  1093. }
  1094. #endif
  1095. m_pOldIsrProc = NULL;
  1096. #ifndef BOARD_DEFFERED_PROCESSING
  1097. m_bReady = FALSE;
  1098. memset( &m_BoardData, 0, sizeof(BOARDDATA) );
  1099. #endif
  1100. }
  1101. // unknown type of board
  1102. m_nBoardType = BT_NONE;
  1103. // used for A/D conversion
  1104. #ifdef DEBUG_ENABLE_OLD_BOARD
  1105. s_pDataArray[0] = s_pDataArray[1] = 0;
  1106. #endif
  1107. #endif // BOARD_SIMULATION
  1108. }