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.

1379 lines
43 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: 19/08/2002
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: BOARD.CPP
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of BOARD.CPP
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "board.h"
  16. #include "screen.h"
  17. //#include "..\LgLib\version.h"
  18. BOOL HID_UI_Debug = FALSE;
  19. #ifdef DEBUG_ENABLE_OLD_BOARD
  20. extern "C" void SMM( short, short[] );
  21. short CBoard::s_pDataArray[4] = {0,0,0,0};
  22. #endif
  23. #ifdef INCLUDE_WINDOWS_DEFINITIONS
  24. static DWORD far* g_Timer = (DWORD far*)0x46CL;
  25. static DWORD old_Timer = 0;
  26. #define TIMER() *g_Timer
  27. #else
  28. #define TIMER() (GetTickCount() * 10 / 182)
  29. #endif
  30. #ifdef DMA_TRANSFERS
  31. unsigned char *DMA_BUFFER = NULL;
  32. #ifdef ALS_300_EDMA
  33. BOOL validateDMASettingsChecSumm( DMA_IO_BUFFER *Buffer ){
  34. WORD Summ;
  35. Summ = 0;
  36. #ifdef DEBUG_PRINTOUT_MSGS
  37. debugProcBegin("Validating CheckSumm");
  38. #endif
  39. for( BYTE index = 0; index < (sizeof(DMA_IO_BUFFER)-1); index++ ){
  40. Summ += (( BYTE *) Buffer )[index];
  41. Summ = Summ & 0xFF;
  42. };
  43. #ifdef DEBUG_PRINTOUT_MSGS
  44. if( Buffer->CheckSumm == Summ ){
  45. debugProcEnd();
  46. return TRUE;
  47. } else {
  48. debugProcEnd(0);
  49. return FALSE;
  50. };
  51. #else
  52. return ( Buffer->fields.CheckSumm == Summ );
  53. #endif
  54. };
  55. void updateDMASettingsChecSumm( DMA_IO_BUFFER *Buffer ){
  56. WORD Summ;
  57. Summ = 0;
  58. for( BYTE index = 0; index < (sizeof(DMA_IO_BUFFER)-1); index++ ){
  59. Summ += (( BYTE *) Buffer )[index];
  60. Summ = Summ & 0xFF;
  61. };
  62. Buffer->fields.CheckSumm = Summ;
  63. };
  64. BOOL CBoard::LoadDMASettings( int DMA, DMA_IO_BUFFER *Buffer ){
  65. long LinearAddress;
  66. unsigned int Page, OffSet;
  67. //Convert pointer to linear address
  68. LinearAddress = FP_SEG ( Buffer );
  69. LinearAddress = ( LinearAddress << 4 ) + FP_OFF( Buffer );
  70. Page = LinearAddress >> 16; //Calculate page
  71. OffSet = LinearAddress & 0xFFFF; //Calculate offset in the page
  72. #ifdef DEBUG_PRINTOUT_MSGS
  73. char temp[255];
  74. sprintf(temp, "Programm DMA Channel %d transfer %d bytes from board", DMA, sizeof(DMA_IO_BUFFER) );
  75. debugProcBegin(temp);
  76. #endif
  77. outportb (0x0A, 4 | DMA); //Mask DMA channel
  78. outportb (0x0C, 0); //Clear byte pointer
  79. outportb (0x0B, 0x44 | DMA ); //Set mode
  80. /*
  81. The mode consists of the following:
  82. 0x14 + x = binary 01 00 01 xx
  83. || || || ||
  84. || || || ++- DMA channel
  85. || || |+--- Write operation (the DSP writes to memory)
  86. || || +---- Read operation (the DSP reads from memory)
  87. || |+------ Autoinit
  88. || +------- Increment - 1/Decrement - 0
  89. |+--------- Single mode - 1 -+--- 00 - on Demand
  90. +---------- Block mode - 1 -+
  91. */
  92. outportb (DMA << 1, OffSet & 0xFF ); //Write the offset to the DMA controller
  93. outportb (DMA << 1, OffSet >> 8 );
  94. if (DMA == 0) outportb ( 0x87, Page );
  95. if (DMA == 1) outportb ( 0x83, Page );
  96. if (DMA == 3) outportb ( 0x82, Page );
  97. outportb (( DMA << 1 ) + 1, ( sizeof(DMA_IO_BUFFER) - 1 ) & 0xFF );
  98. outportb (( DMA << 1 ) + 1, ( ( sizeof(DMA_IO_BUFFER) - 1 ) >> 8 ) & 0xFF );
  99. outportb (0x0A, DMA); //Unmask DMA channel
  100. #ifdef DEBUG_PRINTOUT_MSGS
  101. debugProcEnd();
  102. #endif
  103. BOOL TranzactionComplete = FALSE;
  104. unsigned char Retry = 3;
  105. DWORD Timeout;
  106. static DWORD far* g_Timer = (DWORD far*)0x46CL;
  107. BYTE TCMASK = ( 0x01 << DMA );
  108. while( ( TranzactionComplete == 0 ) && Retry ){
  109. #ifdef DEBUG_PRINTOUT_MSGS
  110. debugProcBegin("Signal To Board");
  111. #endif
  112. SignalToBoard( DMA_LOAD_ADDRESS );
  113. #ifdef DEBUG_PRINTOUT_MSGS
  114. debugProcEnd();
  115. #endif
  116. Retry--;
  117. Timeout = 5; // Timeout 1/200 sec.
  118. #ifdef DEBUG_PRINTOUT_MSGS
  119. debugProcBegin("Wait till CF Flag Rise");
  120. #endif
  121. Timeout = *g_Timer;
  122. while( !( TranzactionComplete = ( ( inportb( 0x08 ) & TCMASK ) == TCMASK ) ) && ( ( *g_Timer - Timeout ) < 18 ) );// {
  123. // Timeout --;
  124. // delay(1);
  125. //};
  126. #ifdef DEBUG_PRINTOUT_MSGS
  127. if( TranzactionComplete ){
  128. debugProcEnd();
  129. } else {
  130. debugProcEnd( 0 );
  131. };
  132. #endif
  133. };
  134. #ifdef DEBUG_PRINTOUT_MSGS
  135. debugProcBegin("Small Delay");
  136. #endif
  137. delay(1);
  138. #ifdef DEBUG_PRINTOUT_MSGS
  139. debugProcEnd();
  140. #endif
  141. //outportb (0x0A, 4 | DMA); //Mask DMA channel
  142. #ifdef DEBUG_PRINTOUT_MSGS
  143. debugProcEnd();
  144. #endif
  145. if( TranzactionComplete ){
  146. return validateDMASettingsChecSumm( Buffer );
  147. };
  148. return FALSE;
  149. };
  150. BOOL CBoard::SaveDMASettings( int DMA, DMA_IO_BUFFER *Buffer ){
  151. long LinearAddress;
  152. unsigned int Page, OffSet;
  153. #ifdef DEBUG_PRINTOUT_MSGS
  154. debugProcBegin("Alloc DMA Buffer");
  155. debugProcBegin("Calc Checksum");
  156. #endif
  157. updateDMASettingsChecSumm( Buffer );
  158. #ifdef DEBUG_PRINTOUT_MSGS
  159. debugProcEnd();
  160. #endif
  161. //Convert pointer to linear address
  162. LinearAddress = FP_SEG ( Buffer );
  163. LinearAddress = ( LinearAddress << 4 ) + FP_OFF( Buffer );
  164. Page = LinearAddress >> 16; //Calculate page
  165. OffSet = LinearAddress & 0xFFFF; //Calculate offset in the page
  166. #ifdef DEBUG_PRINTOUT_MSGS
  167. char temp[255];
  168. sprintf(temp, "Programm DMA Channel %d transfer %d bytes to board", DMA, sizeof(DMA_IO_BUFFER) );
  169. debugProcBegin(temp);
  170. #endif
  171. outportb (0x0A, 4 | DMA); //Mask DMA channel
  172. outportb (0x0C, 0); //Clear byte pointer
  173. outportb (0x0B, 0x08 | DMA); //Set mode
  174. /*
  175. The mode consists of the following:
  176. 0x14 + x = binary 00 00 10 xx
  177. || || || ||
  178. || || || ++- DMA channel
  179. || || |+--- Write operation (the DSP writes to memory)
  180. || || +---- Read operation (the DSP reads from memory)
  181. || |+------ Autoinit
  182. || +------- Increment - 1/Decrement - 0
  183. |+--------- Single mode - 1 -+--- 00 - on Demand
  184. +---------- Block mode - 1 -+
  185. */
  186. outportb (DMA << 1, OffSet & 0xFF ); //Write the offset to the DMA controller
  187. outportb (DMA << 1, OffSet >> 8 );
  188. if (DMA == 0) outportb ( 0x87, Page );
  189. if (DMA == 1) outportb ( 0x83, Page );
  190. if (DMA == 3) outportb ( 0x82, Page );
  191. outportb (( DMA << 1 ) + 1, ( sizeof(DMA_IO_BUFFER) - 1 ) & 0xFF );
  192. outportb (( DMA << 1 ) + 1, ( ( sizeof(DMA_IO_BUFFER) - 1 ) >> 8 ) & 0xFF );
  193. outportb (0x0A, DMA); //Unmask DMA channel
  194. #ifdef DEBUG_PRINTOUT_MSGS
  195. debugProcEnd();
  196. #endif
  197. /***** Signal to the board to load Data *****/
  198. BOOL TranzactionComplete = FALSE;
  199. unsigned char Retry = 3;
  200. DWORD Timeout;
  201. static DWORD far* g_Timer = (DWORD far*)0x46CL;
  202. BYTE TCMASK = (0x01 << DMA );
  203. while( ( !TranzactionComplete ) && Retry ){
  204. #ifdef DEBUG_PRINTOUT_MSGS
  205. debugProcBegin("Signal To Board");
  206. #endif
  207. SignalToBoard( DMA_SAVE_ADDRESS );
  208. #ifdef DEBUG_PRINTOUT_MSGS
  209. debugProcEnd();
  210. #endif
  211. Retry--;
  212. Timeout = 5; // Timeout 1/200 sec
  213. #ifdef DEBUG_PRINTOUT_MSGS
  214. debugProcBegin("Wait till CF Flag Rise");
  215. #endif
  216. Timeout = *g_Timer;
  217. while( !( TranzactionComplete = ( ( inportb( 0x08 ) & TCMASK ) == TCMASK ) ) && ( ( *g_Timer - Timeout ) < 18 ) );//{
  218. // Timeout --;
  219. // delay(1);
  220. //};
  221. #ifdef DEBUG_PRINTOUT_MSGS
  222. if( TranzactionComplete ){
  223. debugProcEnd();
  224. } else {
  225. debugProcEnd( 0 );
  226. };
  227. #endif
  228. };
  229. #ifdef DEBUG_PRINTOUT_MSGS
  230. debugProcBegin("Small Delay");
  231. #endif
  232. delay(1);
  233. #ifdef DEBUG_PRINTOUT_MSGS
  234. debugProcEnd();
  235. #endif
  236. //outportb (0x0A, 4 | DMA); //Mask DMA channel
  237. #ifdef DEBUG_PRINTOUT_MSGS
  238. debugProcEnd();
  239. #endif
  240. return TranzactionComplete;
  241. }
  242. #endif //ALS_300_EDMA
  243. void InitDMA( int DMA, unsigned char *Buffer , unsigned int Size ){
  244. #ifndef BOARD_SIMULATION
  245. long LinearAddress;
  246. unsigned int Page, OffSet;
  247. //Convert pointer to linear address
  248. LinearAddress = FP_SEG ( Buffer );
  249. LinearAddress = ( LinearAddress << 4 ) + FP_OFF( Buffer );
  250. Page = LinearAddress >> 16; //Calculate page
  251. OffSet = LinearAddress & 0xFFFF; //Calculate offset in the page
  252. outportb (0x0A, 4 | DMA); //Mask DMA channel
  253. outportb (0x0C, 0); //Clear byte pointer
  254. outportb (0x0B, 0x14 | DMA); //Set mode
  255. /*
  256. The mode consists of the following:
  257. 0x14 + x = binary 00 01 01 xx
  258. || || || ||
  259. || || || ++- DMA channel
  260. || || |+--- Write operation (the DSP writes to memory)
  261. || || +---- Read operation (the DSP reads from memory)
  262. || |+------ Autoinit
  263. || +------- Increment - 1/Decrement - 0
  264. |+--------- Single mode - 1 -+--- 00 - on Demand
  265. +---------- Block mode - 1 -+
  266. */
  267. outportb (DMA << 1, OffSet & 0xFF ); //Write the offset to the DMA controller
  268. outportb (DMA << 1, OffSet >> 8 );
  269. if (DMA == 0) outportb ( 0x87, Page );
  270. if (DMA == 1) outportb ( 0x83, Page );
  271. if (DMA == 3) outportb ( 0x82, Page );
  272. outportb (( DMA << 1 ) + 1, ( Size - 1 ) & 0xFF );
  273. outportb (( DMA << 1 ) + 1, ( ( Size - 1 ) >> 8 ) & 0xFF );
  274. outportb (0x0A, DMA); //Unmask DMA channel
  275. #endif // BOARD_SIMULATION
  276. };
  277. void Assign_DMA_Buffer ( unsigned int Size ){
  278. #ifndef BOARD_SIMULATION
  279. unsigned char *TempBuf=NULL; //Temporary pointer
  280. long LinearAddress;
  281. unsigned int Page1, Page2; //Words
  282. if( DMA_BUFFER == NULL ){
  283. do {
  284. TempBuf = ( unsigned char * ) malloc( Size );
  285. if( DMA_BUFFER ) free( DMA_BUFFER );
  286. LinearAddress = FP_SEG (TempBuf);
  287. LinearAddress = (LinearAddress << 4) + FP_OFF ( TempBuf );
  288. Page1 = LinearAddress >> 16;
  289. Page2 = ( LinearAddress + Size ) >> 16;
  290. DMA_BUFFER = TempBuf;
  291. } while ( Page1 != Page2 );
  292. };
  293. memset ( DMA_BUFFER, 0, Size );
  294. //printf( "Assigned Mem: %p\n", DMA_BUFFER );
  295. #endif // BOARD_SIMULATION
  296. };
  297. #endif
  298. unsigned int CBoard::getRandomSeedFromLicense(unsigned long LIC){
  299. unsigned int RetVal=0;
  300. unsigned long cm;
  301. int i,j=0;
  302. for (i=0; i< 32; i++){
  303. cm = 1ul << i;
  304. if ( i%2 == 1){ // Odd values = Random Seed
  305. if ( LIC & cm ){
  306. RetVal |= 0x01 << j;
  307. };
  308. j++;
  309. };
  310. };
  311. //printf("\n");
  312. return RetVal;
  313. };
  314. unsigned int CBoard::getSoftwareIDFromLicense(unsigned long LIC){
  315. unsigned int RetVal=0;
  316. unsigned long cm;
  317. int i,j=0;
  318. for (i=0; i< 32; i++){
  319. cm=1ul << i;
  320. if (i%2==0){ // Even values = Software ID
  321. if ( (LIC & cm ) > 0 ){
  322. RetVal |= 0x01 << j;
  323. };
  324. j++;
  325. };
  326. };
  327. return RetVal;
  328. };
  329. unsigned int CBoard::getRandomSeedFromHiddenID(char *HID){
  330. unsigned long LLIC=0;
  331. sscanf(HID,"%8lX",&LLIC);
  332. return getRandomSeedFromLicense( LLIC );
  333. };
  334. unsigned int CBoard::getSoftwareIDFromHiddenID(char *HID){
  335. unsigned long LLIC=0;
  336. sscanf(HID,"%8lX",&LLIC);
  337. return getSoftwareIDFromLicense( LLIC );
  338. };
  339. char *CBoard::assembleHiddenID( unsigned int SWID, unsigned int RND ){
  340. unsigned char tArr[8];
  341. int i,k;
  342. WORD cm;
  343. if( BSNS == NULL ){
  344. BSNS = (char *) malloc(9); // Board SN Placeholder
  345. };
  346. k=0;
  347. tArr[k]=0;
  348. for ( i = 0; i<16; i++){
  349. cm = 1 << i;
  350. if ( i%4 == 0 && i != 0 ){
  351. k++;
  352. tArr[k]=0;
  353. };
  354. if( ( SWID & cm ) > 0 ){
  355. tArr[k] |= 0x01 << ((i%4)*2);
  356. } else {
  357. tArr[k] |= 0x00 << ((i%4)*2);
  358. };
  359. if( ( RND & cm ) > 0 ){
  360. tArr[k] |= 0x02 << ((i%4)*2);
  361. } else {
  362. tArr[k] |= 0x00 << ((i%4)*2);
  363. };
  364. }
  365. for (i=0;i<4;i++){
  366. sprintf( BSNS+(i*2),"%02X",tArr[3-i]);
  367. };
  368. BSNS[8]='\0';
  369. return BSNS;
  370. };
  371. void CBoard::UpdateLicensing(){
  372. #ifndef BOARD_SIMULATION
  373. ffblk buffer[1];
  374. char *HID;
  375. char *DUMMY=" LIBERMANDA ";
  376. unsigned long a,b;
  377. unsigned long LicenseID,NRN;
  378. FILE *fileID;
  379. if ( findfirst("license", buffer,0)==0 ){
  380. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  381. printf("\nUpgrading the License\n");
  382. #endif
  383. fileID=fopen("license","r");
  384. if ( fileID ){
  385. LicenseID=0;
  386. fscanf(fileID,"%8lX",&LicenseID);
  387. fclose(fileID);
  388. unlink("license");
  389. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  390. printf("License file read and deleted\nLicense ID: %lX \n\n",LicenseID );
  391. #endif
  392. HID=GetHiddenParam( nHID );
  393. if ( HID!=NULL ){ //proceed License
  394. if ( getRandomSeedFromLicense( LicenseID ) == getRandomSeedFromHiddenID( HID ) ){ // License generated for this software install
  395. HID = assembleHiddenID(getSoftwareIDFromLicense( LicenseID ),getRandomSeedFromHiddenID( HID ));
  396. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  397. printf("Upgrated HID: %s\n", HID );
  398. #endif
  399. SetHiddenParam( nHID, HID );
  400. } else {
  401. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  402. printf("Incorrect License Version %x %x\n", getRandomSeedFromLicense( LicenseID ), getRandomSeedFromHiddenID( HID ));
  403. #endif
  404. };
  405. } else { // Must Set Random Number to HiddenID - License is Ignored;
  406. randomize();
  407. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  408. printf("No Hidden ID present\n Generating New one: %s\n",assembleHiddenID(rand(),rand()));
  409. #endif
  410. SetHiddenParam( nHID , HID );
  411. };
  412. sprintf(DUMMY,"%c:\license.txt", 65+nHID );
  413. fileID=fopen( DUMMY,"w" );
  414. if ( fileID!= NULL ){
  415. fprintf(fileID,"%s\n",assembleHiddenID( mwBoardID, mwRandomSeed ));
  416. fclose(fileID);
  417. };
  418. } else {
  419. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  420. printf("License file cannot be opened\n\n");
  421. #endif
  422. };
  423. } else {
  424. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  425. printf("No License where found\n\n");
  426. #endif
  427. }
  428. #endif // BOARD_SIMULATION
  429. };
  430. void CBoard::SetupLicense(){
  431. #ifndef BOARD_SIMULATION
  432. char *HID;
  433. HID = GetHiddenParam( nHID );
  434. if ( HID == NULL ){ // New Software Installation - Must Generate New Random Seed
  435. randomize();
  436. HID=assembleHiddenID(rand(),rand());
  437. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  438. printf("NEW RHID: %s\n",HID);
  439. #endif
  440. SetHiddenParam( nHID , HID );
  441. };
  442. mwSoftwareID = getSoftwareIDFromHiddenID(HID);
  443. mwRandomSeed = getRandomSeedFromHiddenID(HID);
  444. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  445. printf("Hidden ID: %s\nRandom seed: %X Software ID: %X\n",HID, mwRandomSeed, mwSoftwareID);
  446. #endif
  447. #endif // BOARD_SIMULATION
  448. };
  449. char *CBoard::GetHiddenParam( unsigned char DiskID ){
  450. #ifndef BOARD_SIMULATION
  451. unsigned char HAttr = 0x19;
  452. unsigned char bobo[512];
  453. unsigned int ReservedSectors;
  454. unsigned int BytesPerSector;
  455. unsigned int SectorsPerFAT;
  456. unsigned int RootDirEntries;
  457. unsigned char FatCopies;
  458. char cname[12];
  459. unsigned char cattr;
  460. unsigned int RootStart;
  461. int i=0,j=0;
  462. if ( absread( DiskID, 1, 0, bobo ) == 0 ) {
  463. /*
  464. Offset in Boot Sector Length in Bytes Mnemonic
  465. 03 8 OEM_Identifier
  466. 0B 2 BytesPerSector
  467. 0D 1 SectorsPerCluster
  468. 0E 2 ReservedSectors
  469. 10 1 NumberOfFATs
  470. 11 2 RootEntries
  471. 13 2 NumberOfSectors
  472. 15 1 MediaDescriptor
  473. 16 2 SectorsPerFAT
  474. 18 2 SectorsPerHead
  475. 1A 2 HeadsPerCylinder
  476. 1C 4 HiddenSectors
  477. 20 4 BigNumberOfSectors
  478. 24 4 BigSectorsPerFAT
  479. 28 2 ExtFlags
  480. 2A 2 FSVersion
  481. 2C 4 RootDirectoryStart
  482. 30 2 FSInfoSector
  483. 32 2 BackupBootSector
  484. 34 12d Reserved
  485. */
  486. BytesPerSector = ( unsigned int )*(bobo+0x0B);
  487. ReservedSectors = ( unsigned int )*(bobo+0x0E);
  488. FatCopies = ( unsigned char ) *(bobo+0x10);
  489. RootDirEntries = ( unsigned int )*(bobo+0x11);
  490. SectorsPerFAT = ( unsigned int )*(bobo+0x16);
  491. RootStart = ReservedSectors + SectorsPerFAT * FatCopies;
  492. if( BytesPerSector == 0 ) BytesPerSector = 512;
  493. if( RootDirEntries == 0 ) RootDirEntries = 512;
  494. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  495. printf( " *******************\n" );
  496. printf( " * Disk Info: *\n" );
  497. printf( " * Reserved: %06d*\n", ReservedSectors );
  498. printf( " * Sec.P.FT: %06d*\n", SectorsPerFAT );
  499. printf( " * Root Entry: %03d *\n", RootDirEntries );
  500. printf( " * FAT Copies: %02d *\n", FatCopies );
  501. printf( " *******************\n" );
  502. #endif
  503. } else {
  504. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  505. printf( "Disk Read Failure\n" );
  506. #endif
  507. return NULL;
  508. };
  509. for ( i = 0; i< ( RootDirEntries*32/BytesPerSector ); i++){
  510. if ( absread( DiskID, 1, RootStart + i, bobo ) == 0 ) {
  511. for(j=0;j<16;j++){
  512. if ( bobo[j*32] == 0 ) break;
  513. sprintf(cname,"%.11s",(char *)(bobo+j*32));
  514. cattr=bobo[j*32+0x0b];
  515. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  516. printf("> %s %02x\n",cname,cattr);
  517. #endif
  518. if ( cattr==HAttr ) return cname;
  519. };
  520. } else {
  521. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  522. printf( "Disk Read Failure\n" );
  523. #endif
  524. };
  525. if ( j > 0 && j < 15 ) break;
  526. };
  527. return NULL;
  528. #else
  529. return "5FDF5D77";
  530. #endif // BOARD_SIMULATION
  531. };
  532. void CBoard::SetHiddenParam( unsigned char DiskID, char *Param ){
  533. #ifndef BOARD_SIMULATION
  534. unsigned char HAttr = 0x19;
  535. unsigned char bobo[512];
  536. unsigned int ReservedSectors;
  537. unsigned int BytesPerSector;
  538. unsigned int SectorsPerFAT;
  539. unsigned int RootDirEntries;
  540. unsigned char FatCopies;
  541. char cname[12];
  542. char path[18];
  543. unsigned char cattr;
  544. unsigned int RootStart;
  545. char Token[12];
  546. int i=0,j=0;
  547. if ( absread( DiskID, 1, 0, bobo ) == 0 ) {
  548. BytesPerSector = ( unsigned int )*(bobo+0x0B);
  549. ReservedSectors = ( unsigned int )*(bobo+0x0E);
  550. FatCopies = ( unsigned char ) *(bobo+0x10);
  551. RootDirEntries = ( unsigned int )*(bobo+0x11);
  552. SectorsPerFAT = ( unsigned int )*(bobo+0x16);
  553. RootStart = ReservedSectors + SectorsPerFAT * FatCopies;
  554. if( BytesPerSector == 0 ) BytesPerSector = 512;
  555. if( RootDirEntries == 0 ) RootDirEntries = 512;
  556. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  557. printf( " *******************\n" );
  558. printf( " * Disk Info: *\n" );
  559. printf( " * Reserved: %06d*\n", ReservedSectors );
  560. printf( " * Sec.P.FT: %06d*\n", SectorsPerFAT );
  561. printf( " * Root Entry: %03d *\n", RootDirEntries );
  562. printf( " * FAT Copies: %02d *\n", FatCopies );
  563. printf( " *******************\n" );
  564. #endif
  565. } else {
  566. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  567. printf( "Disk Read Failure\n" );
  568. #endif
  569. return;
  570. };
  571. for ( i = 0; i< ( RootDirEntries*32/BytesPerSector ); i++){
  572. if ( absread( DiskID, 1, RootStart + i, bobo ) == 0 ) {
  573. for(j=0;j<16;j++){
  574. if ( bobo[j*32] == 0 ) break;
  575. sprintf(cname,"%.11s",(char *)(bobo+j*32));
  576. cattr=bobo[j*32+0x0b];
  577. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  578. printf("> %s %02x\n",cname,cattr);
  579. #endif
  580. if ( cattr==HAttr ) {
  581. sprintf((char *)(bobo+j*32),"%.11s",Param);
  582. bobo[j*32+0x0b] = HAttr;
  583. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  584. printf("Upgrading ... \n");
  585. #endif
  586. int RetVal = abswrite( DiskID, 1, RootStart + i, bobo );
  587. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  588. if( RetVal == 0 ){
  589. printf( "Ok\n" );
  590. } else {
  591. printf( "Disk Write Failure\n" );
  592. };
  593. #endif
  594. return;
  595. };
  596. };
  597. } else {
  598. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  599. printf( "Disk Read Failure\n" );
  600. #endif
  601. };
  602. if ( j > 0 && j < 15 ) break;
  603. };
  604. if ( strlen(Param)>8 ){
  605. sprintf(path,"%c:\\%.8s.%.3s",(char )(DiskID+65),Param,(char *)(Param+8));
  606. } else {
  607. sprintf(path,"%c:\\%s",(char )(DiskID+65),Param);
  608. };
  609. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  610. printf("Create New Hidden ID\n");
  611. #endif
  612. mkdir(path);
  613. switch(strlen(Param)){
  614. case 1: sprintf(Token, "%s ",Param); break;
  615. case 2: sprintf(Token, "%s ",Param); break;
  616. case 3: sprintf(Token, "%s ",Param); break;
  617. case 4: sprintf(Token, "%s ",Param); break;
  618. case 5: sprintf(Token, "%s ",Param); break;
  619. case 6: sprintf(Token, "%s ",Param); break;
  620. case 7: sprintf(Token, "%s ",Param); break;
  621. case 8: sprintf(Token, "%s ",Param); break;
  622. case 9: sprintf(Token, "%s ",Param); break;
  623. case 10: sprintf(Token,"%s ",Param); break;
  624. case 11: sprintf(Token,"%s",Param); break;
  625. default: sprintf(Token,"Error Copy String: %s",Param);
  626. };
  627. for ( i = 0; i< ( RootDirEntries*32/512 ); i++){
  628. if ( absread( DiskID, 1, RootStart + i, bobo ) == 0 ) {
  629. for(j=0;j<16;j++){
  630. if ( bobo[j*32] == 0 ) break;
  631. sprintf(cname,"%.11s",(char *)(bobo+j*32));
  632. cattr=bobo[j*32+0x0b];
  633. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  634. printf(" >%s< %02x >%s< == >%s<\n",cname,cattr,Param,Token);
  635. #endif
  636. if ( strcmp( cname, Token )==0 ) {
  637. bobo[j*32+0x0b] = HAttr;
  638. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  639. printf("Hidding the Marker\n");
  640. #endif
  641. int RetVal = abswrite( DiskID, 1, RootStart + i, bobo );
  642. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  643. if( RetVal == 0 ){
  644. printf( "Ok\n" );
  645. } else {
  646. printf( "Disk Write Failure\n" );
  647. };
  648. #endif
  649. return;
  650. };
  651. };
  652. } else {
  653. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  654. printf( "Disk Read Failure\n" );
  655. #endif
  656. };
  657. if ( j > 0 && j < 15 ) break;
  658. };
  659. #endif // BOARD_SIMULATION
  660. };
  661. void CBoard::ClearHiddenParam( unsigned char DiskID ){
  662. #ifndef BOARD_SIMULATION
  663. unsigned char HAttr = 0x19;
  664. unsigned char UAttr = 0x10;
  665. unsigned char bobo[512];
  666. unsigned int ReservedSectors;
  667. unsigned int BytesPerSector;
  668. unsigned int SectorsPerFAT;
  669. unsigned int RootDirEntries;
  670. unsigned char FatCopies;
  671. char cname[12];
  672. char path[18];
  673. unsigned char cattr;
  674. unsigned int RootStart;
  675. char Token[12];
  676. int i=0,j=0;
  677. if ( absread( DiskID, 1, 0, bobo ) == 0 ) {
  678. BytesPerSector = ( unsigned int )*(bobo+0x0B);
  679. ReservedSectors = ( unsigned int )*(bobo+0x0E);
  680. FatCopies = ( unsigned char ) *(bobo+0x10);
  681. RootDirEntries = ( unsigned int )*(bobo+0x11);
  682. SectorsPerFAT = ( unsigned int )*(bobo+0x16);
  683. if( BytesPerSector == 0 ) BytesPerSector = 512;
  684. if( RootDirEntries == 0 ) RootDirEntries = 512;
  685. RootStart = ReservedSectors + SectorsPerFAT * FatCopies;
  686. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  687. printf( " *******************\n" );
  688. printf( " * Disk Info: *\n" );
  689. printf( " * Reserved: %06d*\n", ReservedSectors );
  690. printf( " * Sec.P.FT: %06d*\n", SectorsPerFAT );
  691. printf( " * Root Entry: %03d *\n", RootDirEntries );
  692. printf( " * FAT Copies: %02d *\n", FatCopies );
  693. printf( " *******************\n" );
  694. #endif
  695. } else {
  696. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  697. printf( "Disk Read Failure\n" );
  698. #endif
  699. return;
  700. };
  701. for ( i = 0; i< ( RootDirEntries*32/BytesPerSector ); i++){
  702. if ( absread( DiskID, 1, RootStart + i, bobo ) == 0 ) {
  703. for(j=0;j<16;j++){
  704. if ( bobo[j*32] == 0 ) break;
  705. sprintf(cname,"%.11s",(char *)(bobo+j*32));
  706. cattr=bobo[j*32+0x0b];
  707. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  708. printf("> %s %02x\n",cname,cattr);
  709. #endif
  710. if ( cattr==HAttr ) {
  711. bobo[j*32+0x0b] = UAttr;
  712. int RetVal = abswrite( DiskID, 1, RootStart + i, bobo );
  713. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  714. if( RetVal == 0 ){
  715. printf( "Ok\n" );
  716. } else {
  717. printf( "Disk Write Failure\n" );
  718. };
  719. #endif
  720. return;
  721. };
  722. };
  723. } else {
  724. #ifdef DEBUG_PRINTOUT_LIC_MSGS
  725. printf( "Disk Read Failure\n" );
  726. #endif
  727. };
  728. if ( j > 0 && j < 15 ) break;
  729. };
  730. #endif // BOARD_SIMULATION
  731. };
  732. char *CBoard::GetBSN( void ){ // Get Board Serial Number
  733. return assembleHiddenID( mwBoardID, mwRandomSeed );
  734. };
  735. char *CBoard::GetBSW( void ){
  736. if( BSCD == NULL ){
  737. BSCD = ( char * ) malloc( 16 );
  738. };
  739. if( BSCD != NULL ){
  740. #ifdef BOARD_SIMULATION
  741. sprintf( BSCD, "SIMULA" );
  742. #else
  743. if( fw_year > 0 && fw_year < 100 ){
  744. sprintf( BSCD ,"%02d%02d%02d", fw_year, fw_month, fw_day );
  745. BSCD[6]='\0';
  746. } else {
  747. sprintf( BSCD ,"UNKNOWN" );
  748. BSCD[7]='\0';
  749. };
  750. #endif
  751. };
  752. return BSCD;
  753. };
  754. char *CBoard::GetBFW( void ){
  755. if( BFCD == NULL ){
  756. BFCD = ( char * ) malloc( 16 );
  757. };
  758. if( BFCD != NULL ){
  759. #ifdef BOARD_SIMULATION
  760. sprintf( BFCD, "SIMULA" );
  761. #else
  762. if( bl_year > 0 && bl_year < 100 ){
  763. sprintf( BFCD ,"%02d%02d%02d", bl_year, bl_month, bl_day );
  764. BFCD[6]='\0';
  765. } else {
  766. sprintf( BFCD ,"UNKNOWN" );
  767. BFCD[7]='\0';
  768. };
  769. #endif
  770. };
  771. return BFCD;
  772. };
  773. void CBoard::ShutDown( void ){
  774. #ifndef BOARD_SIMULATION
  775. switch( m_nBoardType ){
  776. case BT_NEW:{
  777. // disable interrupts
  778. // disable();
  779. // disable laser devices
  780. // outportb( NEW_BASE_ADDRESS + 2, m_bOutputMask &= ~(BE_NEW_DEVICE0 | BE_NEW_DEVICE1) );
  781. //SetStatus( m_bOutputMask &= ~(BE_NEW_DEVICE0 | BE_NEW_DEVICE1) );
  782. m_bOutputMask &= ~(BE_NEW_DEVICE0 | BE_NEW_DEVICE1);
  783. SetRelayBit( m_Settings.RelayDefaultMode );
  784. // if MCU board
  785. if( m_bBoardMCU ){
  786. if( g_bIsDMABoard ){ // DMA Mode Board
  787. StopDMA();
  788. if( !g_bWorkEnable ){
  789. outportb( NEW_RST_ADDRESS, 0 );// Full Upload
  790. //delay(1);
  791. BSNLB = inportb( NEW_DTA_ADDRESS );
  792. //delay(1);
  793. BSNHB = inportb( NEW_DTA_ADDRESS );
  794. //unsigned char Temp = inportb( NEW_DTA_ADDRESS );
  795. //Temp = inportb( NEW_DTA_ADDRESS ); // Read Future Planes
  796. //Temp = inportb( NEW_DTA_ADDRESS );
  797. //Temp = inportb( NEW_DTA_ADDRESS );
  798. //Temp = inportb( NEW_DTA_ADDRESS );
  799. mwBoardID = (( BSNHB<<8) | BSNLB );
  800. //printf(" Board ser num: %04X\n", mwBoardID );
  801. if ( ~( mwBoardID ^ mwSoftwareID ) == 0 ){
  802. g_bWorkEnable = TRUE;
  803. };
  804. outportb( NEW_RST_ADDRESS, 0 ); // Full Upload
  805. outportb( NEW_DTA_ADDRESS, mwSoftwareID & 0xFF ); // Serial Number
  806. outportb( NEW_DTA_ADDRESS, ( mwSoftwareID >> 8 ) & 0xFF );
  807. } else {
  808. outportb( NEW_RST_ADDRESS, 2 ); // Partial Upload
  809. };
  810. #if defined( LGS_PLS_1 ) || defined( LGS_STEPPER ) || defined( LGS_MND ) || defined( LGS_FOD )
  811. #ifdef LGS_PLS_200
  812. outportb( NEW_DTA_ADDRESS, ( m_Settings.nMotorSpeed * 535 * 3 ) & 0xFF );
  813. outportb( NEW_DTA_ADDRESS, ( ( m_Settings.nMotorSpeed * 535 * 3 ) >> 8 ) & 0xFF );
  814. #else
  815. outportb( NEW_DTA_ADDRESS, ( m_Settings.nMotorSpeed * 535 ) & 0xFF );
  816. outportb( NEW_DTA_ADDRESS, ( ( m_Settings.nMotorSpeed * 535 ) >> 8 ) & 0xFF );
  817. #endif
  818. #endif
  819. #ifdef LGS_MND
  820. outportb( NEW_DTA_ADDRESS, m_Settings.nZeroShift & 0xFF );
  821. outportb( NEW_DTA_ADDRESS, m_Settings.nZeroShift >> 8 ); // Zero offset
  822. #else
  823. outportb( NEW_DTA_ADDRESS, 0x00 );
  824. outportb( NEW_DTA_ADDRESS, 0x00 ); // Zero offset
  825. #endif
  826. outportb( NEW_DTA_ADDRESS, m_Settings.nTemperature ); // Temp
  827. outportb( NEW_DTA_ADDRESS, m_bOutputMask ); // Work Status
  828. outportb( NEW_DTA_ADDRESS, 3 ); // Reset DMA
  829. //delay(1); // To ensure stop of DMA conveyor
  830. } else { // IRQ Mode of Board
  831. // disable interrupts
  832. disable();
  833. // disable laser devices
  834. outportb( NEW_BASE_ADDRESS + 2, m_bOutputMask );
  835. enable();
  836. delay(100);
  837. if( !g_bWorkEnable ){
  838. BSNLB=inportb( NEW_BASE_ADDRESS + 6 );
  839. BSNHB=inportb( NEW_BASE_ADDRESS + 7 );
  840. mwBoardID = (( BSNHB<<8) | BSNLB );
  841. if ( ~( mwBoardID ^ mwSoftwareID ) == 0 ){
  842. g_bWorkEnable = TRUE;
  843. };
  844. outportb( NEW_BASE_ADDRESS + 6, mwSoftwareID & 0xFF );
  845. outportb( NEW_BASE_ADDRESS + 7, ( mwSoftwareID >> 8 ) & 0xFF );
  846. };
  847. //outportb( NEW_BASE_ADDRESS + 3, 0 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nGearRatio >> 8 ); // motor ratio
  848. //outportb( NEW_BASE_ADDRESS + 3, 1 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nGearRatio & 0xFF );
  849. //outportb( NEW_BASE_ADDRESS + 3, 2 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nEncoderSteps >> 8 ); // encoder count
  850. //outportb( NEW_BASE_ADDRESS + 3, 3 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nEncoderSteps & 0xFF );
  851. outportb( NEW_BASE_ADDRESS + 3, 4 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nTemperature ); // temperature
  852. delay( 10 );
  853. outportb( NEW_BASE_ADDRESS + 3, 5 ); outportb( NEW_BASE_ADDRESS + 4, 0x00 );//m_Settings.nZeroShift >> 8 ); // zero offset
  854. delay( 10 );
  855. outportb( NEW_BASE_ADDRESS + 3, 6 ); outportb( NEW_BASE_ADDRESS + 4, 0x00 );//m_Settings.nZeroShift & 0xFF );
  856. //outportb( NEW_BASE_ADDRESS + 3, 7 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nMaxRange >> 8 );
  857. //outportb( NEW_BASE_ADDRESS + 3, 8 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nMaxRange & 0xFF ); // max range
  858. m_BoardData.Clear();
  859. };
  860. } else {
  861. // initialize A/D
  862. outportb( NEW_BASE_ADDRESS + 1, 0x04 ); // 1st word
  863. outportb( NEW_BASE_ADDRESS, 0x01 );
  864. outportb( NEW_BASE_ADDRESS + 1, 0x04 ); // 2nd word
  865. outportb( NEW_BASE_ADDRESS, 0x00 );
  866. outportb( NEW_BASE_ADDRESS + 1, 0x00 ); // 3th word
  867. outportb( NEW_BASE_ADDRESS, 0x8A ); // Two channels, internal reference
  868. outportb( NEW_BASE_ADDRESS + 1, 0x04 ); // 4th word
  869. #ifdef BOARD_A2D_FOUR_SAMPLES
  870. outportb( NEW_BASE_ADDRESS, 0x8A );
  871. #else
  872. outportb( NEW_BASE_ADDRESS, 0x92 );
  873. #endif
  874. };
  875. m_nRealAngle = -1;
  876. m_nErrorAngle = -1;
  877. break;
  878. };// case BT_NEW
  879. };// end of SWITCH board type
  880. #ifdef DEBUG_BOARD_PRINT_NO_IRQ
  881. printf("Board ShutDown\n");
  882. #endif
  883. #endif // BOARD_SIBULATION
  884. };
  885. void CBoard::Reset(){
  886. switch( m_nBoardType ){
  887. case BT_NEW:{
  888. // disable interrupts
  889. // disable();
  890. // disable laser devices
  891. // outportb( NEW_BASE_ADDRESS + 2, m_bOutputMask &= ~(BE_NEW_DEVICE0 | BE_NEW_DEVICE1) );
  892. //SetStatus( m_bOutputMask &= ~(BE_NEW_DEVICE0 | BE_NEW_DEVICE1) );
  893. m_bOutputMask &= ~(BE_NEW_DEVICE0 | BE_NEW_DEVICE1);
  894. SetRelayBit( m_Settings.RelayDefaultMode );
  895. // if MCU board
  896. if( m_bBoardMCU ){
  897. if( g_bIsDMABoard ){ // DMA Mode Board
  898. StopDMA();
  899. if( !g_bWorkEnable ){
  900. outportb( NEW_RST_ADDRESS, 0 );// Full Upload
  901. // delay(1);
  902. BSNLB = inportb( NEW_DTA_ADDRESS );
  903. //delay(1);
  904. BSNHB = inportb( NEW_DTA_ADDRESS );
  905. //unsigned char Temp = inportb( NEW_DTA_ADDRESS );
  906. //Temp = inportb( NEW_DTA_ADDRESS ); // Read Future Planes
  907. //Temp = inportb( NEW_DTA_ADDRESS );
  908. //Temp = inportb( NEW_DTA_ADDRESS );
  909. //Temp = inportb( NEW_DTA_ADDRESS );
  910. mwBoardID = (( BSNHB<<8) | BSNLB );
  911. //printf(" Board ser num: %04X\n", mwBoardID );
  912. if ( ~( mwBoardID ^ mwSoftwareID ) == 0 ){
  913. g_bWorkEnable = TRUE;
  914. };
  915. outportb( NEW_RST_ADDRESS, 0 ); // Full Upload
  916. outportb( NEW_DTA_ADDRESS, mwSoftwareID & 0xFF ); // Serial Number
  917. outportb( NEW_DTA_ADDRESS, ( mwSoftwareID >> 8 ) & 0xFF );
  918. } else {
  919. outportb( NEW_RST_ADDRESS, 2 ); // Partial Upload
  920. };
  921. #if defined( LGS_PLS_1 ) || defined( LGS_STEPPER ) || defined( LGS_MND ) || defined( LGS_FOD )
  922. #ifdef LGS_PLS_200
  923. outportb( NEW_DTA_ADDRESS, ( m_Settings.nMotorSpeed * 535 * 3 ) & 0xFF );
  924. outportb( NEW_DTA_ADDRESS, ( ( m_Settings.nMotorSpeed * 535 * 3 ) >> 8 ) & 0xFF );
  925. #else
  926. outportb( NEW_DTA_ADDRESS, ( m_Settings.nMotorSpeed * 535 ) & 0xFF );
  927. outportb( NEW_DTA_ADDRESS, ( ( m_Settings.nMotorSpeed * 535 ) >> 8 ) & 0xFF );
  928. #endif
  929. #endif
  930. #ifdef LGS_MND
  931. outportb( NEW_DTA_ADDRESS, m_Settings.nZeroShift & 0xFF );
  932. outportb( NEW_DTA_ADDRESS, m_Settings.nZeroShift >> 8 ); // Zero offset
  933. #else
  934. outportb( NEW_DTA_ADDRESS, 0x00 );
  935. outportb( NEW_DTA_ADDRESS, 0x00 ); // Zero offset
  936. #endif
  937. outportb( NEW_DTA_ADDRESS, m_Settings.nTemperature ); // Temp
  938. outportb( NEW_DTA_ADDRESS, m_bOutputMask ); // Work Status
  939. outportb( NEW_DTA_ADDRESS, 3 ); // Reset DMA
  940. //delay(1); // To ensure stop of DMA conveyor
  941. } else { // IRQ Mode of Board
  942. // disable interrupts
  943. disable();
  944. // disable laser devices
  945. outportb( NEW_BASE_ADDRESS + 2, m_bOutputMask );
  946. enable();
  947. delay(100);
  948. if( !g_bWorkEnable ){
  949. BSNLB=inportb( NEW_BASE_ADDRESS + 6 );
  950. BSNHB=inportb( NEW_BASE_ADDRESS + 7 );
  951. mwBoardID = (( BSNHB<<8) | BSNLB );
  952. if ( ~( mwBoardID ^ mwSoftwareID ) == 0 ){
  953. g_bWorkEnable = TRUE;
  954. };
  955. outportb( NEW_BASE_ADDRESS + 6, mwSoftwareID & 0xFF );
  956. outportb( NEW_BASE_ADDRESS + 7, ( mwSoftwareID >> 8 ) & 0xFF );
  957. };
  958. //outportb( NEW_BASE_ADDRESS + 3, 0 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nGearRatio >> 8 ); // motor ratio
  959. //outportb( NEW_BASE_ADDRESS + 3, 1 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nGearRatio & 0xFF );
  960. //outportb( NEW_BASE_ADDRESS + 3, 2 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nEncoderSteps >> 8 ); // encoder count
  961. //outportb( NEW_BASE_ADDRESS + 3, 3 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nEncoderSteps & 0xFF );
  962. outportb( NEW_BASE_ADDRESS + 3, 4 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nTemperature ); // temperature
  963. delay( 10 );
  964. outportb( NEW_BASE_ADDRESS + 3, 5 ); outportb( NEW_BASE_ADDRESS + 4, 0x00 );//m_Settings.nZeroShift >> 8 ); // zero offset
  965. delay( 10 );
  966. outportb( NEW_BASE_ADDRESS + 3, 6 ); outportb( NEW_BASE_ADDRESS + 4, 0x00 );//m_Settings.nZeroShift & 0xFF );
  967. //outportb( NEW_BASE_ADDRESS + 3, 7 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nMaxRange >> 8 );
  968. //outportb( NEW_BASE_ADDRESS + 3, 8 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nMaxRange & 0xFF ); // max range
  969. };
  970. } else {
  971. // initialize A/D
  972. outportb( NEW_BASE_ADDRESS + 1, 0x04 ); // 1st word
  973. outportb( NEW_BASE_ADDRESS, 0x01 );
  974. outportb( NEW_BASE_ADDRESS + 1, 0x04 ); // 2nd word
  975. outportb( NEW_BASE_ADDRESS, 0x00 );
  976. outportb( NEW_BASE_ADDRESS + 1, 0x00 ); // 3th word
  977. outportb( NEW_BASE_ADDRESS, 0x8A ); // Two channels, internal reference
  978. outportb( NEW_BASE_ADDRESS + 1, 0x04 ); // 4th word
  979. #ifdef BOARD_A2D_FOUR_SAMPLES
  980. outportb( NEW_BASE_ADDRESS, 0x8A );
  981. #else
  982. outportb( NEW_BASE_ADDRESS, 0x92 );
  983. #endif
  984. };
  985. if( g_bIsDMABoard ){
  986. m_nbWriteChunk = 0;
  987. m_nbReadChunk = 0;
  988. m_nwChunkInterator = 0;
  989. m_bDMA_CRASH = FALSE;
  990. memset ( DMA_BUFFER, 0, DMA_TRANSFER_CHUNK );
  991. InitDMA( DMA_CHANNEL , DMA_BUFFER, DMA_TRANSFER_CHUNK );
  992. m_bOutputMask |= (BE_NEW_DEVICE0 | BE_NEW_DEVICE1);
  993. SetRelayBit( m_Settings.RelayDefaultMode );
  994. #if defined( LGS_PLS_1 ) || defined( LGS_STEPPER ) || defined( LGS_MND ) || defined( LGS_FOD )
  995. outportb( NEW_RST_ADDRESS, 7 ); // Status + DMA Upload
  996. #else
  997. outportb( NEW_RST_ADDRESS, 5 ); // Status + DMA Upload
  998. #endif
  999. outportb( NEW_DTA_ADDRESS, m_bOutputMask ); // Work Status
  1000. outportb( NEW_DTA_ADDRESS, 1 ); // Init DMA
  1001. // enable interrupts
  1002. enable();
  1003. } else {
  1004. delay( 10 );
  1005. // enable laser devices
  1006. m_bOutputMask |= (BE_NEW_DEVICE0 | BE_NEW_DEVICE1);
  1007. SetRelayBit( m_Settings.RelayDefaultMode );
  1008. outportb( NEW_BASE_ADDRESS + 2, m_bOutputMask );
  1009. m_BoardData.Clear();
  1010. };
  1011. m_nRealAngle = -1;
  1012. m_nErrorAngle = -1;
  1013. break;
  1014. }; // case BT_NEW
  1015. }; // end of SWITCH board type
  1016. #ifdef DEBUG_BOARD_PRINT_NO_IRQ
  1017. printf("Board Reset\n");
  1018. #endif
  1019. }
  1020. void CBoard::StopDMA(){
  1021. m_bOutputMask &= ~(BE_NEW_DEVICE0 | BE_NEW_DEVICE1);
  1022. SetRelayBit( m_Settings.RelayDefaultMode );
  1023. m_bResetIssued = TRUE;
  1024. //outportb( NEW_RST_ADDRESS, 5 ); // Status + DMA Upload
  1025. //delay(1);
  1026. //outportb( NEW_DTA_ADDRESS, m_bOutputMask ); // work status
  1027. //delay(1);
  1028. //outportb( NEW_DTA_ADDRESS, 3 ); // Stop DMA
  1029. //delay(10);
  1030. int nono = 10;
  1031. while ( nono && m_bResetIssued ){
  1032. nono--;
  1033. delay(100);
  1034. };
  1035. };
  1036. void CBoard::AsyncReset(){
  1037. #ifndef BOARD_SIMULATION
  1038. switch( m_nBoardType ){
  1039. case BT_NEW:{
  1040. // disable interrupts
  1041. // disable();
  1042. // disable laser devices
  1043. // outportb( NEW_BASE_ADDRESS + 2, m_bOutputMask &= ~(BE_NEW_DEVICE0 | BE_NEW_DEVICE1) );
  1044. //SetStatus( m_bOutputMask &= ~(BE_NEW_DEVICE0 | BE_NEW_DEVICE1) );
  1045. m_bOutputMask &= ~(BE_NEW_DEVICE0 | BE_NEW_DEVICE1);
  1046. SetRelayBit( m_Settings.RelayDefaultMode );
  1047. // if MCU board
  1048. if( m_bBoardMCU ){
  1049. if( g_bIsDMABoard ){ // DMA Mode Board
  1050. #if defined( LGS_PLS_1 ) || defined( LGS_STEPPER ) || defined( LGS_MND ) || defined( LGS_FOD )
  1051. outportb( NEW_RST_ADDRESS, 7 ); // Status + DMA Upload
  1052. #else
  1053. outportb( NEW_RST_ADDRESS, 5 ); // Status + DMA Upload
  1054. #endif
  1055. //delay(1);
  1056. outportb( NEW_DTA_ADDRESS, m_bOutputMask ); // work status
  1057. // delay(1);
  1058. outportb( NEW_DTA_ADDRESS, 3 ); // Stop DMA
  1059. //delay(10);
  1060. if(!g_bWorkEnable){
  1061. outportb( NEW_RST_ADDRESS, 0 ); // Full Upload
  1062. outportb( NEW_DTA_ADDRESS, mwSoftwareID & 0xFF ); // Serial Number
  1063. outportb( NEW_DTA_ADDRESS, ( mwSoftwareID >> 8 ) & 0xFF );
  1064. } else {
  1065. outportb( NEW_RST_ADDRESS, 2 ); //Params + Status + DMA Upload - SerNum
  1066. };
  1067. #if defined( LGS_PLS_1 ) || defined( LGS_STEPPER ) || defined( LGS_MND ) || defined( LGS_FOD )
  1068. #ifdef LGS_PLS_200
  1069. outportb( NEW_DTA_ADDRESS, ( m_Settings.nMotorSpeed * 535 * 3 ) & 0xFF );
  1070. outportb( NEW_DTA_ADDRESS, ( ( m_Settings.nMotorSpeed * 535 * 3 ) >> 8 ) & 0xFF );
  1071. #else
  1072. outportb( NEW_DTA_ADDRESS, ( m_Settings.nMotorSpeed * 535 ) & 0xFF );
  1073. outportb( NEW_DTA_ADDRESS, ( ( m_Settings.nMotorSpeed * 535 ) >> 8 ) & 0xFF );
  1074. #endif
  1075. #endif
  1076. #ifdef LGS_MND
  1077. outportb( NEW_DTA_ADDRESS, m_Settings.nZeroShift & 0xFF );
  1078. outportb( NEW_DTA_ADDRESS, m_Settings.nZeroShift >> 8 ); // Zero offset
  1079. #else
  1080. outportb( NEW_DTA_ADDRESS, 0x00 );
  1081. outportb( NEW_DTA_ADDRESS, 0x00 ); // Zero offset
  1082. #endif
  1083. outportb( NEW_DTA_ADDRESS, m_Settings.nTemperature ); // Temp
  1084. outportb( NEW_DTA_ADDRESS, m_bOutputMask ); // Work Status
  1085. outportb( NEW_DTA_ADDRESS, 3 ); // Reset DMA
  1086. delay(10); // To ensure stop of DMA conveyor
  1087. } else { // IRQ Mode of Board
  1088. // disable interrupts
  1089. disable();
  1090. // disable laser devices
  1091. outportb( NEW_BASE_ADDRESS + 2, m_bOutputMask );
  1092. enable();
  1093. delay(100);
  1094. if( !g_bWorkEnable ){
  1095. BSNLB=inportb( NEW_BASE_ADDRESS + 6 );
  1096. BSNHB=inportb( NEW_BASE_ADDRESS + 7 );
  1097. mwBoardID = (( BSNHB<<8) | BSNLB );
  1098. if ( ~( mwBoardID ^ mwSoftwareID ) == 0 ){
  1099. g_bWorkEnable = TRUE;
  1100. };
  1101. outportb( NEW_BASE_ADDRESS + 6, mwSoftwareID & 0xFF );
  1102. outportb( NEW_BASE_ADDRESS + 7, ( mwSoftwareID >> 8 ) & 0xFF );
  1103. };
  1104. //outportb( NEW_BASE_ADDRESS + 3, 0 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nGearRatio >> 8 ); // motor ratio
  1105. //outportb( NEW_BASE_ADDRESS + 3, 1 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nGearRatio & 0xFF );
  1106. //outportb( NEW_BASE_ADDRESS + 3, 2 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nEncoderSteps >> 8 ); // encoder count
  1107. //outportb( NEW_BASE_ADDRESS + 3, 3 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nEncoderSteps & 0xFF );
  1108. outportb( NEW_BASE_ADDRESS + 3, 4 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nTemperature ); // temperature
  1109. delay(10);
  1110. outportb( NEW_BASE_ADDRESS + 3, 5 ); outportb( NEW_BASE_ADDRESS + 4, 0x00 );//m_Settings.nZeroShift >> 8 ); // zero offset
  1111. delay(10);
  1112. outportb( NEW_BASE_ADDRESS + 3, 6 ); outportb( NEW_BASE_ADDRESS + 4, 0x00 );//m_Settings.nZeroShift & 0xFF );
  1113. //outportb( NEW_BASE_ADDRESS + 3, 7 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nMaxRange >> 8 );
  1114. //outportb( NEW_BASE_ADDRESS + 3, 8 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nMaxRange & 0xFF ); // max range
  1115. };
  1116. } else {
  1117. // initialize A/D
  1118. outportb( NEW_BASE_ADDRESS + 1, 0x04 ); // 1st word
  1119. outportb( NEW_BASE_ADDRESS, 0x01 );
  1120. outportb( NEW_BASE_ADDRESS + 1, 0x04 ); // 2nd word
  1121. outportb( NEW_BASE_ADDRESS, 0x00 );
  1122. outportb( NEW_BASE_ADDRESS + 1, 0x00 ); // 3th word
  1123. outportb( NEW_BASE_ADDRESS, 0x8A ); // Two channels, internal reference
  1124. outportb( NEW_BASE_ADDRESS + 1, 0x04 ); // 4th word
  1125. #ifdef BOARD_A2D_FOUR_SAMPLES
  1126. outportb( NEW_BASE_ADDRESS, 0x8A );
  1127. #else
  1128. outportb( NEW_BASE_ADDRESS, 0x92 );
  1129. #endif
  1130. };
  1131. if( g_bIsDMABoard ){
  1132. m_nbWriteChunk = 0;
  1133. m_nbReadChunk = 0;
  1134. m_nwChunkInterator = 0;
  1135. m_bDMA_CRASH = FALSE;
  1136. memset ( DMA_BUFFER, 0, DMA_TRANSFER_CHUNK );
  1137. InitDMA( DMA_CHANNEL , DMA_BUFFER, DMA_TRANSFER_CHUNK );
  1138. m_bOutputMask |= (BE_NEW_DEVICE0 | BE_NEW_DEVICE1);
  1139. SetRelayBit( m_Settings.RelayDefaultMode );
  1140. #if defined( LGS_PLS_1 ) || defined( LGS_STEPPER ) || defined( LGS_MND ) || defined( LGS_FOD )
  1141. outportb( NEW_RST_ADDRESS, 7 ); // Status + DMA Upload
  1142. #else
  1143. outportb( NEW_RST_ADDRESS, 5 ); // Status + DMA Upload
  1144. #endif
  1145. // delay(10);
  1146. outportb( NEW_DTA_ADDRESS, m_bOutputMask ); // Work Status
  1147. outportb( NEW_DTA_ADDRESS, 1 ); // Init DMA
  1148. // enable interrupts
  1149. enable();
  1150. } else {
  1151. // enable interrupts
  1152. delay( 10 );
  1153. m_bOutputMask |= (BE_NEW_DEVICE0 | BE_NEW_DEVICE1);
  1154. SetRelayBit( m_Settings.RelayDefaultMode );
  1155. // enable laser devices
  1156. outportb( NEW_BASE_ADDRESS + 2, m_bOutputMask );
  1157. m_BoardData.Clear();
  1158. };
  1159. m_nRealAngle = -1;
  1160. m_nErrorAngle = -1;
  1161. break;
  1162. }; // case BT_NEW
  1163. }; // end of SWITCH board type
  1164. // if( g_UI_Debug ){
  1165. #ifdef DEBUG_BOARD_PRINT_NO_IRQ
  1166. printf("Board Async Reset\n");
  1167. #endif
  1168. // };
  1169. #endif // BOARD_SIMULATION
  1170. }
  1171. void CBoard::OnFWBL(){
  1172. }
  1173. void CBoard::OnISR(){
  1174. m_nbWriteChunk ++;
  1175. if( m_nbWriteChunk == DMA_TRANSFER_ZONES ) m_nbWriteChunk = 0;
  1176. if( m_nbWriteChunk == m_nbReadChunk ){
  1177. m_bDMA_CRASH = TRUE;
  1178. } else {
  1179. InitDMA( DMA_CHANNEL , DMA_BUFFER + DMA_TRANSFER_CHUNK * m_nbWriteChunk , DMA_TRANSFER_CHUNK );
  1180. };
  1181. #if defined( LGS_PLS_1 ) || defined( LGS_STEPPER ) || defined( LGS_MND ) || defined( LGS_FOD )
  1182. outportb( NEW_RST_ADDRESS, 7 ); // Status + DMA Upload
  1183. outportb( NEW_RST_ADDRESS, 7 ); // Status + DMA Upload
  1184. #else
  1185. outportb( NEW_RST_ADDRESS, 5 ); // Status + DMA Upload
  1186. #endif
  1187. outportb( NEW_DTA_ADDRESS, m_bOutputMask );
  1188. if( m_bDMA_CRASH || m_bResetIssued ){
  1189. outportb( NEW_DTA_ADDRESS, 3 ); // Stop DMA
  1190. if( m_bResetIssued ) m_bResetIssued = FALSE;
  1191. } else {
  1192. outportb( NEW_DTA_ADDRESS, 2 ); // Continue DMA
  1193. };
  1194. outp( PICICR, EOI );
  1195. }
  1196. #ifdef DEBUG_BOARD_PRINT_NO_IRQ
  1197. WORD CBoard::ReadNewBoard()
  1198. {
  1199. BYTE bData[2];
  1200. bData[0] = inportb(NEW_BASE_ADDRESS);
  1201. bData[1] = inportb(NEW_BASE_ADDRESS+1);
  1202. WORD& wData = (WORD&) bData[0];
  1203. return wData;
  1204. }
  1205. #endif
  1206. /*
  1207. void CBoard::SetTestBit( BOOL bOn )
  1208. {
  1209. switch( m_nBoardType )
  1210. {
  1211. case BT_NEW:
  1212. // update mask
  1213. m_bOutputMask = bOn ? (m_bOutputMask | BE_NEW_OUTPUT0) : (m_bOutputMask & ~BE_NEW_OUTPUT0);
  1214. m_bOutputDirty = TRUE;
  1215. break;
  1216. #ifdef DEBUG_ENABLE_OLD_BOARD
  1217. case BT_OLD:
  1218. // update mask
  1219. m_bOutputMask = bOn ? (m_bOutputMask | 0x10) : (m_bOutputMask & ~0x10);
  1220. outportb( OLD_BASE_ADDRESS, m_bOutputMask );
  1221. break;
  1222. #endif
  1223. }
  1224. }
  1225. void CBoard::SetTestBit2( BOOL bOn )
  1226. {
  1227. switch( m_nBoardType )
  1228. {
  1229. case BT_NEW:
  1230. // update mask
  1231. m_bOutputMask = bOn ? (m_bOutputMask | BE_NEW_OUTPUT1) : (m_bOutputMask & ~BE_NEW_OUTPUT1);
  1232. m_bOutputDirty = TRUE;
  1233. break;
  1234. }
  1235. } */
  1236. void CBoard::SetRelayBit( BOOL bOn )
  1237. {
  1238. switch( m_nBoardType )
  1239. {
  1240. case BT_NEW:
  1241. // update mask
  1242. #ifdef RELAY_ACTIVATE_BY_ZERO
  1243. m_bOutputMask = bOn ? (m_bOutputMask & ~(BE_NEW_DC0|BE_NEW_DC1)) : (m_bOutputMask | (BE_NEW_DC0|BE_NEW_DC1));
  1244. #else
  1245. m_bOutputMask = bOn ? (m_bOutputMask | BE_NEW_DC0) : (m_bOutputMask & ~BE_NEW_DC0);
  1246. #endif
  1247. m_bOutputDirty = TRUE;
  1248. break;
  1249. #ifdef DEBUG_ENABLE_OLD_BOARD
  1250. case BT_OLD:
  1251. // update mask
  1252. m_bOutputMask = bOn ? (m_bOutputMask | 0x08) : (m_bOutputMask & ~0x08);
  1253. outportb( OLD_BASE_ADDRESS, m_bOutputMask );
  1254. break;
  1255. #endif
  1256. }
  1257. }
  1258. BYTE CBoard::GetData( PBOOL pZero, PBOOL pSun, PWORD pRange, PBOOL pPower ){
  1259. enum { BF_NONE = 0x00, BF_ZERO = 0x10, BF_SUN1 = 0x20, BF_SUN2 = 0x40, BF_POWER = 0x80, BF_MASK = 0xF0 };
  1260. // special structure for data converting
  1261. typedef union DATA {
  1262. WORD wValue[1];
  1263. BYTE bValue[2];
  1264. } DATA, *PDATA;
  1265. PDATA data;
  1266. BYTE bFlags;
  1267. WORD wRange[2];
  1268. if ( m_bDMA_CRASH ){
  1269. #ifdef DEBUG_BOARD_PRINT_NO_IRQ
  1270. printf( "DMA Overlaps [%d]=[%d] - BR\n", m_nbReadChunk , m_nbWriteChunk );
  1271. #endif
  1272. //this->Reset();
  1273. return 2;
  1274. };
  1275. if( m_nbWriteChunk != m_nbReadChunk ){
  1276. data = ( PDATA ) ( DMA_BUFFER + DMA_TRANSFER_CHUNK * m_nbReadChunk );
  1277. m_wTimer++;
  1278. // store flags
  1279. bFlags = data[ m_nwChunkInterator ].bValue[1] & BF_MASK;
  1280. wRange[0] = 0x07FF - (( data[m_nwChunkInterator].wValue[0] & 0x0FFF ) >> 1);
  1281. wRange[1] = wRange[0];
  1282. *pZero = ( bFlags & BF_ZERO ) > 0; // read zero
  1283. *pPower = bFlags & BF_POWER; // read power bit
  1284. pSun[0] = bFlags & BF_SUN1; // read sun from device 1
  1285. pSun[1] = pSun[0];
  1286. // prepare values ( convert from 4095..0 to 0..2047 )
  1287. pRange[0] = wRange[0];
  1288. m_nwChunkInterator++;
  1289. if ( m_nwChunkInterator >= ( DMA_TRANSFER_CHUNK / DMA_ANGLE_SHOT ) ){
  1290. m_nwChunkInterator = 0;
  1291. m_nbReadChunk++;
  1292. if ( m_nbReadChunk == DMA_TRANSFER_ZONES ) m_nbReadChunk = 0;
  1293. };
  1294. return 1;
  1295. };
  1296. return 0;
  1297. };
  1298. DWORD CBoard::GetTimer( void ){
  1299. #ifdef NO_WDT2_INIT
  1300. if( g_bIsDMABoard ){
  1301. DWORD TT;
  1302. mOld_TV = clock();
  1303. TT =( DWORD )( mOld_TV & 0xFFFFFFFFL );
  1304. return TT;
  1305. } else {
  1306. return m_wTimer;
  1307. };
  1308. #else
  1309. if( g_bIsVortex ) {
  1310. return get_sys_clock();
  1311. } else {
  1312. if( g_bIsDMABoard ){
  1313. DWORD TT;
  1314. mOld_TV = clock();
  1315. TT =( DWORD )( mOld_TV & 0xFFFFFFFFL );
  1316. return TT;
  1317. } else {
  1318. return m_wTimer;
  1319. };
  1320. };
  1321. #endif
  1322. }