//---------------------------------------------------------------------------- // Laser Guard Ltd. // Copyright ?2000-2002. All Rights Reserved. // Version 1.0 01/01/2000 // Last modification: 19/08/2002 // PROJECT: // SUBSYSTEM: // FILE: BOARD.CPP // AUTHOR: Sergey Chizhevskiy // OVERVIEW // ~~~~~~~~ // Source file of BOARD.CPP //---------------------------------------------------------------------------- #include "stdafx.h" #include "board.h" #include "screen.h" //#include "..\LgLib\version.h" BOOL HID_UI_Debug = FALSE; #ifdef DEBUG_ENABLE_OLD_BOARD extern "C" void SMM( short, short[] ); short CBoard::s_pDataArray[4] = {0,0,0,0}; #endif #ifdef INCLUDE_WINDOWS_DEFINITIONS static DWORD far* g_Timer = (DWORD far*)0x46CL; static DWORD old_Timer = 0; #define TIMER() *g_Timer #else #define TIMER() (GetTickCount() * 10 / 182) #endif #ifdef DMA_TRANSFERS unsigned char *DMA_BUFFER = NULL; #ifdef ALS_300_EDMA BOOL validateDMASettingsChecSumm( DMA_IO_BUFFER *Buffer ){ WORD Summ; Summ = 0; #ifdef DEBUG_PRINTOUT_MSGS debugProcBegin("Validating CheckSumm"); #endif for( BYTE index = 0; index < (sizeof(DMA_IO_BUFFER)-1); index++ ){ Summ += (( BYTE *) Buffer )[index]; Summ = Summ & 0xFF; }; #ifdef DEBUG_PRINTOUT_MSGS if( Buffer->CheckSumm == Summ ){ debugProcEnd(); return TRUE; } else { debugProcEnd(0); return FALSE; }; #else return ( Buffer->fields.CheckSumm == Summ ); #endif }; void updateDMASettingsChecSumm( DMA_IO_BUFFER *Buffer ){ WORD Summ; Summ = 0; for( BYTE index = 0; index < (sizeof(DMA_IO_BUFFER)-1); index++ ){ Summ += (( BYTE *) Buffer )[index]; Summ = Summ & 0xFF; }; Buffer->fields.CheckSumm = Summ; }; BOOL CBoard::LoadDMASettings( int DMA, DMA_IO_BUFFER *Buffer ){ long LinearAddress; unsigned int Page, OffSet; //Convert pointer to linear address LinearAddress = FP_SEG ( Buffer ); LinearAddress = ( LinearAddress << 4 ) + FP_OFF( Buffer ); Page = LinearAddress >> 16; //Calculate page OffSet = LinearAddress & 0xFFFF; //Calculate offset in the page #ifdef DEBUG_PRINTOUT_MSGS char temp[255]; sprintf(temp, "Programm DMA Channel %d transfer %d bytes from board", DMA, sizeof(DMA_IO_BUFFER) ); debugProcBegin(temp); #endif outportb (0x0A, 4 | DMA); //Mask DMA channel outportb (0x0C, 0); //Clear byte pointer outportb (0x0B, 0x44 | DMA ); //Set mode /* The mode consists of the following: 0x14 + x = binary 01 00 01 xx || || || || || || || ++- DMA channel || || |+--- Write operation (the DSP writes to memory) || || +---- Read operation (the DSP reads from memory) || |+------ Autoinit || +------- Increment - 1/Decrement - 0 |+--------- Single mode - 1 -+--- 00 - on Demand +---------- Block mode - 1 -+ */ outportb (DMA << 1, OffSet & 0xFF ); //Write the offset to the DMA controller outportb (DMA << 1, OffSet >> 8 ); if (DMA == 0) outportb ( 0x87, Page ); if (DMA == 1) outportb ( 0x83, Page ); if (DMA == 3) outportb ( 0x82, Page ); outportb (( DMA << 1 ) + 1, ( sizeof(DMA_IO_BUFFER) - 1 ) & 0xFF ); outportb (( DMA << 1 ) + 1, ( ( sizeof(DMA_IO_BUFFER) - 1 ) >> 8 ) & 0xFF ); outportb (0x0A, DMA); //Unmask DMA channel #ifdef DEBUG_PRINTOUT_MSGS debugProcEnd(); #endif BOOL TranzactionComplete = FALSE; unsigned char Retry = 3; DWORD Timeout; static DWORD far* g_Timer = (DWORD far*)0x46CL; BYTE TCMASK = ( 0x01 << DMA ); while( ( TranzactionComplete == 0 ) && Retry ){ #ifdef DEBUG_PRINTOUT_MSGS debugProcBegin("Signal To Board"); #endif SignalToBoard( DMA_LOAD_ADDRESS ); #ifdef DEBUG_PRINTOUT_MSGS debugProcEnd(); #endif Retry--; Timeout = 5; // Timeout 1/200 sec. #ifdef DEBUG_PRINTOUT_MSGS debugProcBegin("Wait till CF Flag Rise"); #endif Timeout = *g_Timer; while( !( TranzactionComplete = ( ( inportb( 0x08 ) & TCMASK ) == TCMASK ) ) && ( ( *g_Timer - Timeout ) < 18 ) );// { // Timeout --; // delay(1); //}; #ifdef DEBUG_PRINTOUT_MSGS if( TranzactionComplete ){ debugProcEnd(); } else { debugProcEnd( 0 ); }; #endif }; #ifdef DEBUG_PRINTOUT_MSGS debugProcBegin("Small Delay"); #endif delay(1); #ifdef DEBUG_PRINTOUT_MSGS debugProcEnd(); #endif //outportb (0x0A, 4 | DMA); //Mask DMA channel #ifdef DEBUG_PRINTOUT_MSGS debugProcEnd(); #endif if( TranzactionComplete ){ return validateDMASettingsChecSumm( Buffer ); }; return FALSE; }; BOOL CBoard::SaveDMASettings( int DMA, DMA_IO_BUFFER *Buffer ){ long LinearAddress; unsigned int Page, OffSet; #ifdef DEBUG_PRINTOUT_MSGS debugProcBegin("Alloc DMA Buffer"); debugProcBegin("Calc Checksum"); #endif updateDMASettingsChecSumm( Buffer ); #ifdef DEBUG_PRINTOUT_MSGS debugProcEnd(); #endif //Convert pointer to linear address LinearAddress = FP_SEG ( Buffer ); LinearAddress = ( LinearAddress << 4 ) + FP_OFF( Buffer ); Page = LinearAddress >> 16; //Calculate page OffSet = LinearAddress & 0xFFFF; //Calculate offset in the page #ifdef DEBUG_PRINTOUT_MSGS char temp[255]; sprintf(temp, "Programm DMA Channel %d transfer %d bytes to board", DMA, sizeof(DMA_IO_BUFFER) ); debugProcBegin(temp); #endif outportb (0x0A, 4 | DMA); //Mask DMA channel outportb (0x0C, 0); //Clear byte pointer outportb (0x0B, 0x08 | DMA); //Set mode /* The mode consists of the following: 0x14 + x = binary 00 00 10 xx || || || || || || || ++- DMA channel || || |+--- Write operation (the DSP writes to memory) || || +---- Read operation (the DSP reads from memory) || |+------ Autoinit || +------- Increment - 1/Decrement - 0 |+--------- Single mode - 1 -+--- 00 - on Demand +---------- Block mode - 1 -+ */ outportb (DMA << 1, OffSet & 0xFF ); //Write the offset to the DMA controller outportb (DMA << 1, OffSet >> 8 ); if (DMA == 0) outportb ( 0x87, Page ); if (DMA == 1) outportb ( 0x83, Page ); if (DMA == 3) outportb ( 0x82, Page ); outportb (( DMA << 1 ) + 1, ( sizeof(DMA_IO_BUFFER) - 1 ) & 0xFF ); outportb (( DMA << 1 ) + 1, ( ( sizeof(DMA_IO_BUFFER) - 1 ) >> 8 ) & 0xFF ); outportb (0x0A, DMA); //Unmask DMA channel #ifdef DEBUG_PRINTOUT_MSGS debugProcEnd(); #endif /***** Signal to the board to load Data *****/ BOOL TranzactionComplete = FALSE; unsigned char Retry = 3; DWORD Timeout; static DWORD far* g_Timer = (DWORD far*)0x46CL; BYTE TCMASK = (0x01 << DMA ); while( ( !TranzactionComplete ) && Retry ){ #ifdef DEBUG_PRINTOUT_MSGS debugProcBegin("Signal To Board"); #endif SignalToBoard( DMA_SAVE_ADDRESS ); #ifdef DEBUG_PRINTOUT_MSGS debugProcEnd(); #endif Retry--; Timeout = 5; // Timeout 1/200 sec #ifdef DEBUG_PRINTOUT_MSGS debugProcBegin("Wait till CF Flag Rise"); #endif Timeout = *g_Timer; while( !( TranzactionComplete = ( ( inportb( 0x08 ) & TCMASK ) == TCMASK ) ) && ( ( *g_Timer - Timeout ) < 18 ) );//{ // Timeout --; // delay(1); //}; #ifdef DEBUG_PRINTOUT_MSGS if( TranzactionComplete ){ debugProcEnd(); } else { debugProcEnd( 0 ); }; #endif }; #ifdef DEBUG_PRINTOUT_MSGS debugProcBegin("Small Delay"); #endif delay(1); #ifdef DEBUG_PRINTOUT_MSGS debugProcEnd(); #endif //outportb (0x0A, 4 | DMA); //Mask DMA channel #ifdef DEBUG_PRINTOUT_MSGS debugProcEnd(); #endif return TranzactionComplete; } #endif //ALS_300_EDMA void InitDMA( int DMA, unsigned char *Buffer , unsigned int Size ){ #ifndef BOARD_SIMULATION long LinearAddress; unsigned int Page, OffSet; //Convert pointer to linear address LinearAddress = FP_SEG ( Buffer ); LinearAddress = ( LinearAddress << 4 ) + FP_OFF( Buffer ); Page = LinearAddress >> 16; //Calculate page OffSet = LinearAddress & 0xFFFF; //Calculate offset in the page outportb (0x0A, 4 | DMA); //Mask DMA channel outportb (0x0C, 0); //Clear byte pointer outportb (0x0B, 0x14 | DMA); //Set mode /* The mode consists of the following: 0x14 + x = binary 00 01 01 xx || || || || || || || ++- DMA channel || || |+--- Write operation (the DSP writes to memory) || || +---- Read operation (the DSP reads from memory) || |+------ Autoinit || +------- Increment - 1/Decrement - 0 |+--------- Single mode - 1 -+--- 00 - on Demand +---------- Block mode - 1 -+ */ outportb (DMA << 1, OffSet & 0xFF ); //Write the offset to the DMA controller outportb (DMA << 1, OffSet >> 8 ); if (DMA == 0) outportb ( 0x87, Page ); if (DMA == 1) outportb ( 0x83, Page ); if (DMA == 3) outportb ( 0x82, Page ); outportb (( DMA << 1 ) + 1, ( Size - 1 ) & 0xFF ); outportb (( DMA << 1 ) + 1, ( ( Size - 1 ) >> 8 ) & 0xFF ); outportb (0x0A, DMA); //Unmask DMA channel #endif // BOARD_SIMULATION }; void Assign_DMA_Buffer ( unsigned int Size ){ #ifndef BOARD_SIMULATION unsigned char *TempBuf=NULL; //Temporary pointer long LinearAddress; unsigned int Page1, Page2; //Words if( DMA_BUFFER == NULL ){ do { TempBuf = ( unsigned char * ) malloc( Size ); if( DMA_BUFFER ) free( DMA_BUFFER ); LinearAddress = FP_SEG (TempBuf); LinearAddress = (LinearAddress << 4) + FP_OFF ( TempBuf ); Page1 = LinearAddress >> 16; Page2 = ( LinearAddress + Size ) >> 16; DMA_BUFFER = TempBuf; } while ( Page1 != Page2 ); }; memset ( DMA_BUFFER, 0, Size ); //printf( "Assigned Mem: %p\n", DMA_BUFFER ); #endif // BOARD_SIMULATION }; #endif unsigned int CBoard::getRandomSeedFromLicense(unsigned long LIC){ unsigned int RetVal=0; unsigned long cm; int i,j=0; for (i=0; i< 32; i++){ cm = 1ul << i; if ( i%2 == 1){ // Odd values = Random Seed if ( LIC & cm ){ RetVal |= 0x01 << j; }; j++; }; }; //printf("\n"); return RetVal; }; unsigned int CBoard::getSoftwareIDFromLicense(unsigned long LIC){ unsigned int RetVal=0; unsigned long cm; int i,j=0; for (i=0; i< 32; i++){ cm=1ul << i; if (i%2==0){ // Even values = Software ID if ( (LIC & cm ) > 0 ){ RetVal |= 0x01 << j; }; j++; }; }; return RetVal; }; unsigned int CBoard::getRandomSeedFromHiddenID(char *HID){ unsigned long LLIC=0; sscanf(HID,"%8lX",&LLIC); return getRandomSeedFromLicense( LLIC ); }; unsigned int CBoard::getSoftwareIDFromHiddenID(char *HID){ unsigned long LLIC=0; sscanf(HID,"%8lX",&LLIC); return getSoftwareIDFromLicense( LLIC ); }; char *CBoard::assembleHiddenID( unsigned int SWID, unsigned int RND ){ unsigned char tArr[8]; int i,k; WORD cm; if( BSNS == NULL ){ BSNS = (char *) malloc(9); // Board SN Placeholder }; k=0; tArr[k]=0; for ( i = 0; i<16; i++){ cm = 1 << i; if ( i%4 == 0 && i != 0 ){ k++; tArr[k]=0; }; if( ( SWID & cm ) > 0 ){ tArr[k] |= 0x01 << ((i%4)*2); } else { tArr[k] |= 0x00 << ((i%4)*2); }; if( ( RND & cm ) > 0 ){ tArr[k] |= 0x02 << ((i%4)*2); } else { tArr[k] |= 0x00 << ((i%4)*2); }; } for (i=0;i<4;i++){ sprintf( BSNS+(i*2),"%02X",tArr[3-i]); }; BSNS[8]='\0'; return BSNS; }; void CBoard::UpdateLicensing(){ #ifndef BOARD_SIMULATION ffblk buffer[1]; char *HID; char *DUMMY=" LIBERMANDA "; unsigned long a,b; unsigned long LicenseID,NRN; FILE *fileID; if ( findfirst("license", buffer,0)==0 ){ #ifdef DEBUG_PRINTOUT_LIC_MSGS printf("\nUpgrading the License\n"); #endif fileID=fopen("license","r"); if ( fileID ){ LicenseID=0; fscanf(fileID,"%8lX",&LicenseID); fclose(fileID); unlink("license"); #ifdef DEBUG_PRINTOUT_LIC_MSGS printf("License file read and deleted\nLicense ID: %lX \n\n",LicenseID ); #endif HID=GetHiddenParam( nHID ); if ( HID!=NULL ){ //proceed License if ( getRandomSeedFromLicense( LicenseID ) == getRandomSeedFromHiddenID( HID ) ){ // License generated for this software install HID = assembleHiddenID(getSoftwareIDFromLicense( LicenseID ),getRandomSeedFromHiddenID( HID )); #ifdef DEBUG_PRINTOUT_LIC_MSGS printf("Upgrated HID: %s\n", HID ); #endif SetHiddenParam( nHID, HID ); } else { #ifdef DEBUG_PRINTOUT_LIC_MSGS printf("Incorrect License Version %x %x\n", getRandomSeedFromLicense( LicenseID ), getRandomSeedFromHiddenID( HID )); #endif }; } else { // Must Set Random Number to HiddenID - License is Ignored; randomize(); #ifdef DEBUG_PRINTOUT_LIC_MSGS printf("No Hidden ID present\n Generating New one: %s\n",assembleHiddenID(rand(),rand())); #endif SetHiddenParam( nHID , HID ); }; sprintf(DUMMY,"%c:\license.txt", 65+nHID ); fileID=fopen( DUMMY,"w" ); if ( fileID!= NULL ){ fprintf(fileID,"%s\n",assembleHiddenID( mwBoardID, mwRandomSeed )); fclose(fileID); }; } else { #ifdef DEBUG_PRINTOUT_LIC_MSGS printf("License file cannot be opened\n\n"); #endif }; } else { #ifdef DEBUG_PRINTOUT_LIC_MSGS printf("No License where found\n\n"); #endif } #endif // BOARD_SIMULATION }; void CBoard::SetupLicense(){ #ifndef BOARD_SIMULATION char *HID; HID = GetHiddenParam( nHID ); if ( HID == NULL ){ // New Software Installation - Must Generate New Random Seed randomize(); HID=assembleHiddenID(rand(),rand()); #ifdef DEBUG_PRINTOUT_LIC_MSGS printf("NEW RHID: %s\n",HID); #endif SetHiddenParam( nHID , HID ); }; mwSoftwareID = getSoftwareIDFromHiddenID(HID); mwRandomSeed = getRandomSeedFromHiddenID(HID); #ifdef DEBUG_PRINTOUT_LIC_MSGS printf("Hidden ID: %s\nRandom seed: %X Software ID: %X\n",HID, mwRandomSeed, mwSoftwareID); #endif #endif // BOARD_SIMULATION }; char *CBoard::GetHiddenParam( unsigned char DiskID ){ #ifndef BOARD_SIMULATION unsigned char HAttr = 0x19; unsigned char bobo[512]; unsigned int ReservedSectors; unsigned int BytesPerSector; unsigned int SectorsPerFAT; unsigned int RootDirEntries; unsigned char FatCopies; char cname[12]; unsigned char cattr; unsigned int RootStart; int i=0,j=0; if ( absread( DiskID, 1, 0, bobo ) == 0 ) { /* Offset in Boot Sector Length in Bytes Mnemonic 03 8 OEM_Identifier 0B 2 BytesPerSector 0D 1 SectorsPerCluster 0E 2 ReservedSectors 10 1 NumberOfFATs 11 2 RootEntries 13 2 NumberOfSectors 15 1 MediaDescriptor 16 2 SectorsPerFAT 18 2 SectorsPerHead 1A 2 HeadsPerCylinder 1C 4 HiddenSectors 20 4 BigNumberOfSectors 24 4 BigSectorsPerFAT 28 2 ExtFlags 2A 2 FSVersion 2C 4 RootDirectoryStart 30 2 FSInfoSector 32 2 BackupBootSector 34 12d Reserved */ BytesPerSector = ( unsigned int )*(bobo+0x0B); ReservedSectors = ( unsigned int )*(bobo+0x0E); FatCopies = ( unsigned char ) *(bobo+0x10); RootDirEntries = ( unsigned int )*(bobo+0x11); SectorsPerFAT = ( unsigned int )*(bobo+0x16); RootStart = ReservedSectors + SectorsPerFAT * FatCopies; if( BytesPerSector == 0 ) BytesPerSector = 512; if( RootDirEntries == 0 ) RootDirEntries = 512; #ifdef DEBUG_PRINTOUT_LIC_MSGS printf( " *******************\n" ); printf( " * Disk Info: *\n" ); printf( " * Reserved: %06d*\n", ReservedSectors ); printf( " * Sec.P.FT: %06d*\n", SectorsPerFAT ); printf( " * Root Entry: %03d *\n", RootDirEntries ); printf( " * FAT Copies: %02d *\n", FatCopies ); printf( " *******************\n" ); #endif } else { #ifdef DEBUG_PRINTOUT_LIC_MSGS printf( "Disk Read Failure\n" ); #endif return NULL; }; for ( i = 0; i< ( RootDirEntries*32/BytesPerSector ); i++){ if ( absread( DiskID, 1, RootStart + i, bobo ) == 0 ) { for(j=0;j<16;j++){ if ( bobo[j*32] == 0 ) break; sprintf(cname,"%.11s",(char *)(bobo+j*32)); cattr=bobo[j*32+0x0b]; #ifdef DEBUG_PRINTOUT_LIC_MSGS printf("> %s %02x\n",cname,cattr); #endif if ( cattr==HAttr ) return cname; }; } else { #ifdef DEBUG_PRINTOUT_LIC_MSGS printf( "Disk Read Failure\n" ); #endif }; if ( j > 0 && j < 15 ) break; }; return NULL; #else return "5FDF5D77"; #endif // BOARD_SIMULATION }; void CBoard::SetHiddenParam( unsigned char DiskID, char *Param ){ #ifndef BOARD_SIMULATION unsigned char HAttr = 0x19; unsigned char bobo[512]; unsigned int ReservedSectors; unsigned int BytesPerSector; unsigned int SectorsPerFAT; unsigned int RootDirEntries; unsigned char FatCopies; char cname[12]; char path[18]; unsigned char cattr; unsigned int RootStart; char Token[12]; int i=0,j=0; if ( absread( DiskID, 1, 0, bobo ) == 0 ) { BytesPerSector = ( unsigned int )*(bobo+0x0B); ReservedSectors = ( unsigned int )*(bobo+0x0E); FatCopies = ( unsigned char ) *(bobo+0x10); RootDirEntries = ( unsigned int )*(bobo+0x11); SectorsPerFAT = ( unsigned int )*(bobo+0x16); RootStart = ReservedSectors + SectorsPerFAT * FatCopies; if( BytesPerSector == 0 ) BytesPerSector = 512; if( RootDirEntries == 0 ) RootDirEntries = 512; #ifdef DEBUG_PRINTOUT_LIC_MSGS printf( " *******************\n" ); printf( " * Disk Info: *\n" ); printf( " * Reserved: %06d*\n", ReservedSectors ); printf( " * Sec.P.FT: %06d*\n", SectorsPerFAT ); printf( " * Root Entry: %03d *\n", RootDirEntries ); printf( " * FAT Copies: %02d *\n", FatCopies ); printf( " *******************\n" ); #endif } else { #ifdef DEBUG_PRINTOUT_LIC_MSGS printf( "Disk Read Failure\n" ); #endif return; }; for ( i = 0; i< ( RootDirEntries*32/BytesPerSector ); i++){ if ( absread( DiskID, 1, RootStart + i, bobo ) == 0 ) { for(j=0;j<16;j++){ if ( bobo[j*32] == 0 ) break; sprintf(cname,"%.11s",(char *)(bobo+j*32)); cattr=bobo[j*32+0x0b]; #ifdef DEBUG_PRINTOUT_LIC_MSGS printf("> %s %02x\n",cname,cattr); #endif if ( cattr==HAttr ) { sprintf((char *)(bobo+j*32),"%.11s",Param); bobo[j*32+0x0b] = HAttr; #ifdef DEBUG_PRINTOUT_LIC_MSGS printf("Upgrading ... \n"); #endif int RetVal = abswrite( DiskID, 1, RootStart + i, bobo ); #ifdef DEBUG_PRINTOUT_LIC_MSGS if( RetVal == 0 ){ printf( "Ok\n" ); } else { printf( "Disk Write Failure\n" ); }; #endif return; }; }; } else { #ifdef DEBUG_PRINTOUT_LIC_MSGS printf( "Disk Read Failure\n" ); #endif }; if ( j > 0 && j < 15 ) break; }; if ( strlen(Param)>8 ){ sprintf(path,"%c:\\%.8s.%.3s",(char )(DiskID+65),Param,(char *)(Param+8)); } else { sprintf(path,"%c:\\%s",(char )(DiskID+65),Param); }; #ifdef DEBUG_PRINTOUT_LIC_MSGS printf("Create New Hidden ID\n"); #endif mkdir(path); switch(strlen(Param)){ case 1: sprintf(Token, "%s ",Param); break; case 2: sprintf(Token, "%s ",Param); break; case 3: sprintf(Token, "%s ",Param); break; case 4: sprintf(Token, "%s ",Param); break; case 5: sprintf(Token, "%s ",Param); break; case 6: sprintf(Token, "%s ",Param); break; case 7: sprintf(Token, "%s ",Param); break; case 8: sprintf(Token, "%s ",Param); break; case 9: sprintf(Token, "%s ",Param); break; case 10: sprintf(Token,"%s ",Param); break; case 11: sprintf(Token,"%s",Param); break; default: sprintf(Token,"Error Copy String: %s",Param); }; for ( i = 0; i< ( RootDirEntries*32/512 ); i++){ if ( absread( DiskID, 1, RootStart + i, bobo ) == 0 ) { for(j=0;j<16;j++){ if ( bobo[j*32] == 0 ) break; sprintf(cname,"%.11s",(char *)(bobo+j*32)); cattr=bobo[j*32+0x0b]; #ifdef DEBUG_PRINTOUT_LIC_MSGS printf(" >%s< %02x >%s< == >%s<\n",cname,cattr,Param,Token); #endif if ( strcmp( cname, Token )==0 ) { bobo[j*32+0x0b] = HAttr; #ifdef DEBUG_PRINTOUT_LIC_MSGS printf("Hidding the Marker\n"); #endif int RetVal = abswrite( DiskID, 1, RootStart + i, bobo ); #ifdef DEBUG_PRINTOUT_LIC_MSGS if( RetVal == 0 ){ printf( "Ok\n" ); } else { printf( "Disk Write Failure\n" ); }; #endif return; }; }; } else { #ifdef DEBUG_PRINTOUT_LIC_MSGS printf( "Disk Read Failure\n" ); #endif }; if ( j > 0 && j < 15 ) break; }; #endif // BOARD_SIMULATION }; void CBoard::ClearHiddenParam( unsigned char DiskID ){ #ifndef BOARD_SIMULATION unsigned char HAttr = 0x19; unsigned char UAttr = 0x10; unsigned char bobo[512]; unsigned int ReservedSectors; unsigned int BytesPerSector; unsigned int SectorsPerFAT; unsigned int RootDirEntries; unsigned char FatCopies; char cname[12]; char path[18]; unsigned char cattr; unsigned int RootStart; char Token[12]; int i=0,j=0; if ( absread( DiskID, 1, 0, bobo ) == 0 ) { BytesPerSector = ( unsigned int )*(bobo+0x0B); ReservedSectors = ( unsigned int )*(bobo+0x0E); FatCopies = ( unsigned char ) *(bobo+0x10); RootDirEntries = ( unsigned int )*(bobo+0x11); SectorsPerFAT = ( unsigned int )*(bobo+0x16); if( BytesPerSector == 0 ) BytesPerSector = 512; if( RootDirEntries == 0 ) RootDirEntries = 512; RootStart = ReservedSectors + SectorsPerFAT * FatCopies; #ifdef DEBUG_PRINTOUT_LIC_MSGS printf( " *******************\n" ); printf( " * Disk Info: *\n" ); printf( " * Reserved: %06d*\n", ReservedSectors ); printf( " * Sec.P.FT: %06d*\n", SectorsPerFAT ); printf( " * Root Entry: %03d *\n", RootDirEntries ); printf( " * FAT Copies: %02d *\n", FatCopies ); printf( " *******************\n" ); #endif } else { #ifdef DEBUG_PRINTOUT_LIC_MSGS printf( "Disk Read Failure\n" ); #endif return; }; for ( i = 0; i< ( RootDirEntries*32/BytesPerSector ); i++){ if ( absread( DiskID, 1, RootStart + i, bobo ) == 0 ) { for(j=0;j<16;j++){ if ( bobo[j*32] == 0 ) break; sprintf(cname,"%.11s",(char *)(bobo+j*32)); cattr=bobo[j*32+0x0b]; #ifdef DEBUG_PRINTOUT_LIC_MSGS printf("> %s %02x\n",cname,cattr); #endif if ( cattr==HAttr ) { bobo[j*32+0x0b] = UAttr; int RetVal = abswrite( DiskID, 1, RootStart + i, bobo ); #ifdef DEBUG_PRINTOUT_LIC_MSGS if( RetVal == 0 ){ printf( "Ok\n" ); } else { printf( "Disk Write Failure\n" ); }; #endif return; }; }; } else { #ifdef DEBUG_PRINTOUT_LIC_MSGS printf( "Disk Read Failure\n" ); #endif }; if ( j > 0 && j < 15 ) break; }; #endif // BOARD_SIMULATION }; char *CBoard::GetBSN( void ){ // Get Board Serial Number return assembleHiddenID( mwBoardID, mwRandomSeed ); }; char *CBoard::GetBSW( void ){ if( BSCD == NULL ){ BSCD = ( char * ) malloc( 16 ); }; if( BSCD != NULL ){ #ifdef BOARD_SIMULATION sprintf( BSCD, "SIMULA" ); #else if( fw_year > 0 && fw_year < 100 ){ sprintf( BSCD ,"%02d%02d%02d", fw_year, fw_month, fw_day ); BSCD[6]='\0'; } else { sprintf( BSCD ,"UNKNOWN" ); BSCD[7]='\0'; }; #endif }; return BSCD; }; char *CBoard::GetBFW( void ){ if( BFCD == NULL ){ BFCD = ( char * ) malloc( 16 ); }; if( BFCD != NULL ){ #ifdef BOARD_SIMULATION sprintf( BFCD, "SIMULA" ); #else if( bl_year > 0 && bl_year < 100 ){ sprintf( BFCD ,"%02d%02d%02d", bl_year, bl_month, bl_day ); BFCD[6]='\0'; } else { sprintf( BFCD ,"UNKNOWN" ); BFCD[7]='\0'; }; #endif }; return BFCD; }; void CBoard::ShutDown( void ){ #ifndef BOARD_SIMULATION switch( m_nBoardType ){ case BT_NEW:{ // disable interrupts // disable(); // disable laser devices // outportb( NEW_BASE_ADDRESS + 2, m_bOutputMask &= ~(BE_NEW_DEVICE0 | BE_NEW_DEVICE1) ); //SetStatus( m_bOutputMask &= ~(BE_NEW_DEVICE0 | BE_NEW_DEVICE1) ); m_bOutputMask &= ~(BE_NEW_DEVICE0 | BE_NEW_DEVICE1); SetRelayBit( m_Settings.RelayDefaultMode ); // if MCU board if( m_bBoardMCU ){ if( g_bIsDMABoard ){ // DMA Mode Board StopDMA(); if( !g_bWorkEnable ){ outportb( NEW_RST_ADDRESS, 0 );// Full Upload //delay(1); BSNLB = inportb( NEW_DTA_ADDRESS ); //delay(1); BSNHB = inportb( NEW_DTA_ADDRESS ); //unsigned char Temp = inportb( NEW_DTA_ADDRESS ); //Temp = inportb( NEW_DTA_ADDRESS ); // Read Future Planes //Temp = inportb( NEW_DTA_ADDRESS ); //Temp = inportb( NEW_DTA_ADDRESS ); //Temp = inportb( NEW_DTA_ADDRESS ); mwBoardID = (( BSNHB<<8) | BSNLB ); //printf(" Board ser num: %04X\n", mwBoardID ); if ( ~( mwBoardID ^ mwSoftwareID ) == 0 ){ g_bWorkEnable = TRUE; }; outportb( NEW_RST_ADDRESS, 0 ); // Full Upload outportb( NEW_DTA_ADDRESS, mwSoftwareID & 0xFF ); // Serial Number outportb( NEW_DTA_ADDRESS, ( mwSoftwareID >> 8 ) & 0xFF ); } else { outportb( NEW_RST_ADDRESS, 2 ); // Partial Upload }; #if defined( LGS_PLS_1 ) || defined( LGS_STEPPER ) || defined( LGS_MND ) || defined( LGS_FOD ) #ifdef LGS_PLS_200 outportb( NEW_DTA_ADDRESS, ( m_Settings.nMotorSpeed * 535 * 3 ) & 0xFF ); outportb( NEW_DTA_ADDRESS, ( ( m_Settings.nMotorSpeed * 535 * 3 ) >> 8 ) & 0xFF ); #else outportb( NEW_DTA_ADDRESS, ( m_Settings.nMotorSpeed * 535 ) & 0xFF ); outportb( NEW_DTA_ADDRESS, ( ( m_Settings.nMotorSpeed * 535 ) >> 8 ) & 0xFF ); #endif #endif #ifdef LGS_MND outportb( NEW_DTA_ADDRESS, m_Settings.nZeroShift & 0xFF ); outportb( NEW_DTA_ADDRESS, m_Settings.nZeroShift >> 8 ); // Zero offset #else outportb( NEW_DTA_ADDRESS, 0x00 ); outportb( NEW_DTA_ADDRESS, 0x00 ); // Zero offset #endif outportb( NEW_DTA_ADDRESS, m_Settings.nTemperature ); // Temp outportb( NEW_DTA_ADDRESS, m_bOutputMask ); // Work Status outportb( NEW_DTA_ADDRESS, 3 ); // Reset DMA //delay(1); // To ensure stop of DMA conveyor } else { // IRQ Mode of Board // disable interrupts disable(); // disable laser devices outportb( NEW_BASE_ADDRESS + 2, m_bOutputMask ); enable(); delay(100); if( !g_bWorkEnable ){ BSNLB=inportb( NEW_BASE_ADDRESS + 6 ); BSNHB=inportb( NEW_BASE_ADDRESS + 7 ); mwBoardID = (( BSNHB<<8) | BSNLB ); if ( ~( mwBoardID ^ mwSoftwareID ) == 0 ){ g_bWorkEnable = TRUE; }; outportb( NEW_BASE_ADDRESS + 6, mwSoftwareID & 0xFF ); outportb( NEW_BASE_ADDRESS + 7, ( mwSoftwareID >> 8 ) & 0xFF ); }; //outportb( NEW_BASE_ADDRESS + 3, 0 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nGearRatio >> 8 ); // motor ratio //outportb( NEW_BASE_ADDRESS + 3, 1 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nGearRatio & 0xFF ); //outportb( NEW_BASE_ADDRESS + 3, 2 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nEncoderSteps >> 8 ); // encoder count //outportb( NEW_BASE_ADDRESS + 3, 3 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nEncoderSteps & 0xFF ); outportb( NEW_BASE_ADDRESS + 3, 4 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nTemperature ); // temperature delay( 10 ); outportb( NEW_BASE_ADDRESS + 3, 5 ); outportb( NEW_BASE_ADDRESS + 4, 0x00 );//m_Settings.nZeroShift >> 8 ); // zero offset delay( 10 ); outportb( NEW_BASE_ADDRESS + 3, 6 ); outportb( NEW_BASE_ADDRESS + 4, 0x00 );//m_Settings.nZeroShift & 0xFF ); //outportb( NEW_BASE_ADDRESS + 3, 7 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nMaxRange >> 8 ); //outportb( NEW_BASE_ADDRESS + 3, 8 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nMaxRange & 0xFF ); // max range m_BoardData.Clear(); }; } else { // initialize A/D outportb( NEW_BASE_ADDRESS + 1, 0x04 ); // 1st word outportb( NEW_BASE_ADDRESS, 0x01 ); outportb( NEW_BASE_ADDRESS + 1, 0x04 ); // 2nd word outportb( NEW_BASE_ADDRESS, 0x00 ); outportb( NEW_BASE_ADDRESS + 1, 0x00 ); // 3th word outportb( NEW_BASE_ADDRESS, 0x8A ); // Two channels, internal reference outportb( NEW_BASE_ADDRESS + 1, 0x04 ); // 4th word #ifdef BOARD_A2D_FOUR_SAMPLES outportb( NEW_BASE_ADDRESS, 0x8A ); #else outportb( NEW_BASE_ADDRESS, 0x92 ); #endif }; m_nRealAngle = -1; m_nErrorAngle = -1; break; };// case BT_NEW };// end of SWITCH board type #ifdef DEBUG_BOARD_PRINT_NO_IRQ printf("Board ShutDown\n"); #endif #endif // BOARD_SIBULATION }; void CBoard::Reset(){ switch( m_nBoardType ){ case BT_NEW:{ // disable interrupts // disable(); // disable laser devices // outportb( NEW_BASE_ADDRESS + 2, m_bOutputMask &= ~(BE_NEW_DEVICE0 | BE_NEW_DEVICE1) ); //SetStatus( m_bOutputMask &= ~(BE_NEW_DEVICE0 | BE_NEW_DEVICE1) ); m_bOutputMask &= ~(BE_NEW_DEVICE0 | BE_NEW_DEVICE1); SetRelayBit( m_Settings.RelayDefaultMode ); // if MCU board if( m_bBoardMCU ){ if( g_bIsDMABoard ){ // DMA Mode Board StopDMA(); if( !g_bWorkEnable ){ outportb( NEW_RST_ADDRESS, 0 );// Full Upload // delay(1); BSNLB = inportb( NEW_DTA_ADDRESS ); //delay(1); BSNHB = inportb( NEW_DTA_ADDRESS ); //unsigned char Temp = inportb( NEW_DTA_ADDRESS ); //Temp = inportb( NEW_DTA_ADDRESS ); // Read Future Planes //Temp = inportb( NEW_DTA_ADDRESS ); //Temp = inportb( NEW_DTA_ADDRESS ); //Temp = inportb( NEW_DTA_ADDRESS ); mwBoardID = (( BSNHB<<8) | BSNLB ); //printf(" Board ser num: %04X\n", mwBoardID ); if ( ~( mwBoardID ^ mwSoftwareID ) == 0 ){ g_bWorkEnable = TRUE; }; outportb( NEW_RST_ADDRESS, 0 ); // Full Upload outportb( NEW_DTA_ADDRESS, mwSoftwareID & 0xFF ); // Serial Number outportb( NEW_DTA_ADDRESS, ( mwSoftwareID >> 8 ) & 0xFF ); } else { outportb( NEW_RST_ADDRESS, 2 ); // Partial Upload }; #if defined( LGS_PLS_1 ) || defined( LGS_STEPPER ) || defined( LGS_MND ) || defined( LGS_FOD ) #ifdef LGS_PLS_200 outportb( NEW_DTA_ADDRESS, ( m_Settings.nMotorSpeed * 535 * 3 ) & 0xFF ); outportb( NEW_DTA_ADDRESS, ( ( m_Settings.nMotorSpeed * 535 * 3 ) >> 8 ) & 0xFF ); #else outportb( NEW_DTA_ADDRESS, ( m_Settings.nMotorSpeed * 535 ) & 0xFF ); outportb( NEW_DTA_ADDRESS, ( ( m_Settings.nMotorSpeed * 535 ) >> 8 ) & 0xFF ); #endif #endif #ifdef LGS_MND outportb( NEW_DTA_ADDRESS, m_Settings.nZeroShift & 0xFF ); outportb( NEW_DTA_ADDRESS, m_Settings.nZeroShift >> 8 ); // Zero offset #else outportb( NEW_DTA_ADDRESS, 0x00 ); outportb( NEW_DTA_ADDRESS, 0x00 ); // Zero offset #endif outportb( NEW_DTA_ADDRESS, m_Settings.nTemperature ); // Temp outportb( NEW_DTA_ADDRESS, m_bOutputMask ); // Work Status outportb( NEW_DTA_ADDRESS, 3 ); // Reset DMA //delay(1); // To ensure stop of DMA conveyor } else { // IRQ Mode of Board // disable interrupts disable(); // disable laser devices outportb( NEW_BASE_ADDRESS + 2, m_bOutputMask ); enable(); delay(100); if( !g_bWorkEnable ){ BSNLB=inportb( NEW_BASE_ADDRESS + 6 ); BSNHB=inportb( NEW_BASE_ADDRESS + 7 ); mwBoardID = (( BSNHB<<8) | BSNLB ); if ( ~( mwBoardID ^ mwSoftwareID ) == 0 ){ g_bWorkEnable = TRUE; }; outportb( NEW_BASE_ADDRESS + 6, mwSoftwareID & 0xFF ); outportb( NEW_BASE_ADDRESS + 7, ( mwSoftwareID >> 8 ) & 0xFF ); }; //outportb( NEW_BASE_ADDRESS + 3, 0 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nGearRatio >> 8 ); // motor ratio //outportb( NEW_BASE_ADDRESS + 3, 1 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nGearRatio & 0xFF ); //outportb( NEW_BASE_ADDRESS + 3, 2 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nEncoderSteps >> 8 ); // encoder count //outportb( NEW_BASE_ADDRESS + 3, 3 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nEncoderSteps & 0xFF ); outportb( NEW_BASE_ADDRESS + 3, 4 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nTemperature ); // temperature delay( 10 ); outportb( NEW_BASE_ADDRESS + 3, 5 ); outportb( NEW_BASE_ADDRESS + 4, 0x00 );//m_Settings.nZeroShift >> 8 ); // zero offset delay( 10 ); outportb( NEW_BASE_ADDRESS + 3, 6 ); outportb( NEW_BASE_ADDRESS + 4, 0x00 );//m_Settings.nZeroShift & 0xFF ); //outportb( NEW_BASE_ADDRESS + 3, 7 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nMaxRange >> 8 ); //outportb( NEW_BASE_ADDRESS + 3, 8 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nMaxRange & 0xFF ); // max range }; } else { // initialize A/D outportb( NEW_BASE_ADDRESS + 1, 0x04 ); // 1st word outportb( NEW_BASE_ADDRESS, 0x01 ); outportb( NEW_BASE_ADDRESS + 1, 0x04 ); // 2nd word outportb( NEW_BASE_ADDRESS, 0x00 ); outportb( NEW_BASE_ADDRESS + 1, 0x00 ); // 3th word outportb( NEW_BASE_ADDRESS, 0x8A ); // Two channels, internal reference outportb( NEW_BASE_ADDRESS + 1, 0x04 ); // 4th word #ifdef BOARD_A2D_FOUR_SAMPLES outportb( NEW_BASE_ADDRESS, 0x8A ); #else outportb( NEW_BASE_ADDRESS, 0x92 ); #endif }; if( g_bIsDMABoard ){ m_nbWriteChunk = 0; m_nbReadChunk = 0; m_nwChunkInterator = 0; m_bDMA_CRASH = FALSE; memset ( DMA_BUFFER, 0, DMA_TRANSFER_CHUNK ); InitDMA( DMA_CHANNEL , DMA_BUFFER, DMA_TRANSFER_CHUNK ); m_bOutputMask |= (BE_NEW_DEVICE0 | BE_NEW_DEVICE1); SetRelayBit( m_Settings.RelayDefaultMode ); #if defined( LGS_PLS_1 ) || defined( LGS_STEPPER ) || defined( LGS_MND ) || defined( LGS_FOD ) outportb( NEW_RST_ADDRESS, 7 ); // Status + DMA Upload #else outportb( NEW_RST_ADDRESS, 5 ); // Status + DMA Upload #endif outportb( NEW_DTA_ADDRESS, m_bOutputMask ); // Work Status outportb( NEW_DTA_ADDRESS, 1 ); // Init DMA // enable interrupts enable(); } else { delay( 10 ); // enable laser devices m_bOutputMask |= (BE_NEW_DEVICE0 | BE_NEW_DEVICE1); SetRelayBit( m_Settings.RelayDefaultMode ); outportb( NEW_BASE_ADDRESS + 2, m_bOutputMask ); m_BoardData.Clear(); }; m_nRealAngle = -1; m_nErrorAngle = -1; break; }; // case BT_NEW }; // end of SWITCH board type #ifdef DEBUG_BOARD_PRINT_NO_IRQ printf("Board Reset\n"); #endif } void CBoard::StopDMA(){ m_bOutputMask &= ~(BE_NEW_DEVICE0 | BE_NEW_DEVICE1); SetRelayBit( m_Settings.RelayDefaultMode ); m_bResetIssued = TRUE; //outportb( NEW_RST_ADDRESS, 5 ); // Status + DMA Upload //delay(1); //outportb( NEW_DTA_ADDRESS, m_bOutputMask ); // work status //delay(1); //outportb( NEW_DTA_ADDRESS, 3 ); // Stop DMA //delay(10); int nono = 10; while ( nono && m_bResetIssued ){ nono--; delay(100); }; }; void CBoard::AsyncReset(){ #ifndef BOARD_SIMULATION switch( m_nBoardType ){ case BT_NEW:{ // disable interrupts // disable(); // disable laser devices // outportb( NEW_BASE_ADDRESS + 2, m_bOutputMask &= ~(BE_NEW_DEVICE0 | BE_NEW_DEVICE1) ); //SetStatus( m_bOutputMask &= ~(BE_NEW_DEVICE0 | BE_NEW_DEVICE1) ); m_bOutputMask &= ~(BE_NEW_DEVICE0 | BE_NEW_DEVICE1); SetRelayBit( m_Settings.RelayDefaultMode ); // if MCU board if( m_bBoardMCU ){ if( g_bIsDMABoard ){ // DMA Mode Board #if defined( LGS_PLS_1 ) || defined( LGS_STEPPER ) || defined( LGS_MND ) || defined( LGS_FOD ) outportb( NEW_RST_ADDRESS, 7 ); // Status + DMA Upload #else outportb( NEW_RST_ADDRESS, 5 ); // Status + DMA Upload #endif //delay(1); outportb( NEW_DTA_ADDRESS, m_bOutputMask ); // work status // delay(1); outportb( NEW_DTA_ADDRESS, 3 ); // Stop DMA //delay(10); if(!g_bWorkEnable){ outportb( NEW_RST_ADDRESS, 0 ); // Full Upload outportb( NEW_DTA_ADDRESS, mwSoftwareID & 0xFF ); // Serial Number outportb( NEW_DTA_ADDRESS, ( mwSoftwareID >> 8 ) & 0xFF ); } else { outportb( NEW_RST_ADDRESS, 2 ); //Params + Status + DMA Upload - SerNum }; #if defined( LGS_PLS_1 ) || defined( LGS_STEPPER ) || defined( LGS_MND ) || defined( LGS_FOD ) #ifdef LGS_PLS_200 outportb( NEW_DTA_ADDRESS, ( m_Settings.nMotorSpeed * 535 * 3 ) & 0xFF ); outportb( NEW_DTA_ADDRESS, ( ( m_Settings.nMotorSpeed * 535 * 3 ) >> 8 ) & 0xFF ); #else outportb( NEW_DTA_ADDRESS, ( m_Settings.nMotorSpeed * 535 ) & 0xFF ); outportb( NEW_DTA_ADDRESS, ( ( m_Settings.nMotorSpeed * 535 ) >> 8 ) & 0xFF ); #endif #endif #ifdef LGS_MND outportb( NEW_DTA_ADDRESS, m_Settings.nZeroShift & 0xFF ); outportb( NEW_DTA_ADDRESS, m_Settings.nZeroShift >> 8 ); // Zero offset #else outportb( NEW_DTA_ADDRESS, 0x00 ); outportb( NEW_DTA_ADDRESS, 0x00 ); // Zero offset #endif outportb( NEW_DTA_ADDRESS, m_Settings.nTemperature ); // Temp outportb( NEW_DTA_ADDRESS, m_bOutputMask ); // Work Status outportb( NEW_DTA_ADDRESS, 3 ); // Reset DMA delay(10); // To ensure stop of DMA conveyor } else { // IRQ Mode of Board // disable interrupts disable(); // disable laser devices outportb( NEW_BASE_ADDRESS + 2, m_bOutputMask ); enable(); delay(100); if( !g_bWorkEnable ){ BSNLB=inportb( NEW_BASE_ADDRESS + 6 ); BSNHB=inportb( NEW_BASE_ADDRESS + 7 ); mwBoardID = (( BSNHB<<8) | BSNLB ); if ( ~( mwBoardID ^ mwSoftwareID ) == 0 ){ g_bWorkEnable = TRUE; }; outportb( NEW_BASE_ADDRESS + 6, mwSoftwareID & 0xFF ); outportb( NEW_BASE_ADDRESS + 7, ( mwSoftwareID >> 8 ) & 0xFF ); }; //outportb( NEW_BASE_ADDRESS + 3, 0 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nGearRatio >> 8 ); // motor ratio //outportb( NEW_BASE_ADDRESS + 3, 1 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nGearRatio & 0xFF ); //outportb( NEW_BASE_ADDRESS + 3, 2 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nEncoderSteps >> 8 ); // encoder count //outportb( NEW_BASE_ADDRESS + 3, 3 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nEncoderSteps & 0xFF ); outportb( NEW_BASE_ADDRESS + 3, 4 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nTemperature ); // temperature delay(10); outportb( NEW_BASE_ADDRESS + 3, 5 ); outportb( NEW_BASE_ADDRESS + 4, 0x00 );//m_Settings.nZeroShift >> 8 ); // zero offset delay(10); outportb( NEW_BASE_ADDRESS + 3, 6 ); outportb( NEW_BASE_ADDRESS + 4, 0x00 );//m_Settings.nZeroShift & 0xFF ); //outportb( NEW_BASE_ADDRESS + 3, 7 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nMaxRange >> 8 ); //outportb( NEW_BASE_ADDRESS + 3, 8 ); outportb( NEW_BASE_ADDRESS + 4, m_Settings.nMaxRange & 0xFF ); // max range }; } else { // initialize A/D outportb( NEW_BASE_ADDRESS + 1, 0x04 ); // 1st word outportb( NEW_BASE_ADDRESS, 0x01 ); outportb( NEW_BASE_ADDRESS + 1, 0x04 ); // 2nd word outportb( NEW_BASE_ADDRESS, 0x00 ); outportb( NEW_BASE_ADDRESS + 1, 0x00 ); // 3th word outportb( NEW_BASE_ADDRESS, 0x8A ); // Two channels, internal reference outportb( NEW_BASE_ADDRESS + 1, 0x04 ); // 4th word #ifdef BOARD_A2D_FOUR_SAMPLES outportb( NEW_BASE_ADDRESS, 0x8A ); #else outportb( NEW_BASE_ADDRESS, 0x92 ); #endif }; if( g_bIsDMABoard ){ m_nbWriteChunk = 0; m_nbReadChunk = 0; m_nwChunkInterator = 0; m_bDMA_CRASH = FALSE; memset ( DMA_BUFFER, 0, DMA_TRANSFER_CHUNK ); InitDMA( DMA_CHANNEL , DMA_BUFFER, DMA_TRANSFER_CHUNK ); m_bOutputMask |= (BE_NEW_DEVICE0 | BE_NEW_DEVICE1); SetRelayBit( m_Settings.RelayDefaultMode ); #if defined( LGS_PLS_1 ) || defined( LGS_STEPPER ) || defined( LGS_MND ) || defined( LGS_FOD ) outportb( NEW_RST_ADDRESS, 7 ); // Status + DMA Upload #else outportb( NEW_RST_ADDRESS, 5 ); // Status + DMA Upload #endif // delay(10); outportb( NEW_DTA_ADDRESS, m_bOutputMask ); // Work Status outportb( NEW_DTA_ADDRESS, 1 ); // Init DMA // enable interrupts enable(); } else { // enable interrupts delay( 10 ); m_bOutputMask |= (BE_NEW_DEVICE0 | BE_NEW_DEVICE1); SetRelayBit( m_Settings.RelayDefaultMode ); // enable laser devices outportb( NEW_BASE_ADDRESS + 2, m_bOutputMask ); m_BoardData.Clear(); }; m_nRealAngle = -1; m_nErrorAngle = -1; break; }; // case BT_NEW }; // end of SWITCH board type // if( g_UI_Debug ){ #ifdef DEBUG_BOARD_PRINT_NO_IRQ printf("Board Async Reset\n"); #endif // }; #endif // BOARD_SIMULATION } void CBoard::OnFWBL(){ } void CBoard::OnISR(){ m_nbWriteChunk ++; if( m_nbWriteChunk == DMA_TRANSFER_ZONES ) m_nbWriteChunk = 0; if( m_nbWriteChunk == m_nbReadChunk ){ m_bDMA_CRASH = TRUE; } else { InitDMA( DMA_CHANNEL , DMA_BUFFER + DMA_TRANSFER_CHUNK * m_nbWriteChunk , DMA_TRANSFER_CHUNK ); }; #if defined( LGS_PLS_1 ) || defined( LGS_STEPPER ) || defined( LGS_MND ) || defined( LGS_FOD ) outportb( NEW_RST_ADDRESS, 7 ); // Status + DMA Upload outportb( NEW_RST_ADDRESS, 7 ); // Status + DMA Upload #else outportb( NEW_RST_ADDRESS, 5 ); // Status + DMA Upload #endif outportb( NEW_DTA_ADDRESS, m_bOutputMask ); if( m_bDMA_CRASH || m_bResetIssued ){ outportb( NEW_DTA_ADDRESS, 3 ); // Stop DMA if( m_bResetIssued ) m_bResetIssued = FALSE; } else { outportb( NEW_DTA_ADDRESS, 2 ); // Continue DMA }; outp( PICICR, EOI ); } #ifdef DEBUG_BOARD_PRINT_NO_IRQ WORD CBoard::ReadNewBoard() { BYTE bData[2]; bData[0] = inportb(NEW_BASE_ADDRESS); bData[1] = inportb(NEW_BASE_ADDRESS+1); WORD& wData = (WORD&) bData[0]; return wData; } #endif /* void CBoard::SetTestBit( BOOL bOn ) { switch( m_nBoardType ) { case BT_NEW: // update mask m_bOutputMask = bOn ? (m_bOutputMask | BE_NEW_OUTPUT0) : (m_bOutputMask & ~BE_NEW_OUTPUT0); m_bOutputDirty = TRUE; break; #ifdef DEBUG_ENABLE_OLD_BOARD case BT_OLD: // update mask m_bOutputMask = bOn ? (m_bOutputMask | 0x10) : (m_bOutputMask & ~0x10); outportb( OLD_BASE_ADDRESS, m_bOutputMask ); break; #endif } } void CBoard::SetTestBit2( BOOL bOn ) { switch( m_nBoardType ) { case BT_NEW: // update mask m_bOutputMask = bOn ? (m_bOutputMask | BE_NEW_OUTPUT1) : (m_bOutputMask & ~BE_NEW_OUTPUT1); m_bOutputDirty = TRUE; break; } } */ void CBoard::SetRelayBit( BOOL bOn ) { switch( m_nBoardType ) { case BT_NEW: // update mask #ifdef RELAY_ACTIVATE_BY_ZERO m_bOutputMask = bOn ? (m_bOutputMask & ~(BE_NEW_DC0|BE_NEW_DC1)) : (m_bOutputMask | (BE_NEW_DC0|BE_NEW_DC1)); #else m_bOutputMask = bOn ? (m_bOutputMask | BE_NEW_DC0) : (m_bOutputMask & ~BE_NEW_DC0); #endif m_bOutputDirty = TRUE; break; #ifdef DEBUG_ENABLE_OLD_BOARD case BT_OLD: // update mask m_bOutputMask = bOn ? (m_bOutputMask | 0x08) : (m_bOutputMask & ~0x08); outportb( OLD_BASE_ADDRESS, m_bOutputMask ); break; #endif } } BYTE CBoard::GetData( PBOOL pZero, PBOOL pSun, PWORD pRange, PBOOL pPower ){ enum { BF_NONE = 0x00, BF_ZERO = 0x10, BF_SUN1 = 0x20, BF_SUN2 = 0x40, BF_POWER = 0x80, BF_MASK = 0xF0 }; // special structure for data converting typedef union DATA { WORD wValue[1]; BYTE bValue[2]; } DATA, *PDATA; PDATA data; BYTE bFlags; WORD wRange[2]; if ( m_bDMA_CRASH ){ #ifdef DEBUG_BOARD_PRINT_NO_IRQ printf( "DMA Overlaps [%d]=[%d] - BR\n", m_nbReadChunk , m_nbWriteChunk ); #endif //this->Reset(); return 2; }; if( m_nbWriteChunk != m_nbReadChunk ){ data = ( PDATA ) ( DMA_BUFFER + DMA_TRANSFER_CHUNK * m_nbReadChunk ); m_wTimer++; // store flags bFlags = data[ m_nwChunkInterator ].bValue[1] & BF_MASK; wRange[0] = 0x07FF - (( data[m_nwChunkInterator].wValue[0] & 0x0FFF ) >> 1); wRange[1] = wRange[0]; *pZero = ( bFlags & BF_ZERO ) > 0; // read zero *pPower = bFlags & BF_POWER; // read power bit pSun[0] = bFlags & BF_SUN1; // read sun from device 1 pSun[1] = pSun[0]; // prepare values ( convert from 4095..0 to 0..2047 ) pRange[0] = wRange[0]; m_nwChunkInterator++; if ( m_nwChunkInterator >= ( DMA_TRANSFER_CHUNK / DMA_ANGLE_SHOT ) ){ m_nwChunkInterator = 0; m_nbReadChunk++; if ( m_nbReadChunk == DMA_TRANSFER_ZONES ) m_nbReadChunk = 0; }; return 1; }; return 0; }; DWORD CBoard::GetTimer( void ){ #ifdef NO_WDT2_INIT if( g_bIsDMABoard ){ DWORD TT; mOld_TV = clock(); TT =( DWORD )( mOld_TV & 0xFFFFFFFFL ); return TT; } else { return m_wTimer; }; #else if( g_bIsVortex ) { return get_sys_clock(); } else { if( g_bIsDMABoard ){ DWORD TT; mOld_TV = clock(); TT =( DWORD )( mOld_TV & 0xFFFFFFFFL ); return TT; } else { return m_wTimer; }; }; #endif }