Ejemplo n.º 1
0
bool MPI_Base :: MakeAssignsFromMasks( unsigned *full_mask, 
									   unsigned *part_mask, 
									   unsigned *mask_value,
									   vec< vec<Lit> > &dummy_vec )
{
// for predict with minisat2.2. convert masks to vector of Literals
	unsigned variate_vars_count = 0;
	full_mask_var_count = 0;
	for ( unsigned i = 0; i < FULL_MASK_LEN; i++ ) {
		variate_vars_count  += BitCount( full_mask[i] ^ part_mask[i] );
		full_mask_var_count += BitCount( full_mask[i] );
	}
	
	// determine count of assumptions and lenght of every one
	int problems_count = 1 << variate_vars_count;
	dummy_vec.resize( problems_count );
	for( int i=0; i < dummy_vec.size(); ++i )
		dummy_vec[i].resize( full_mask_var_count );

	unsigned mask, range_mask_ind;
	int range_mask;
	unsigned index;
	int cur_var_ind;
	bool IsPositiveLiteral, IsAddingLiteral;

	for ( int lint = 0; lint < problems_count; lint++ ) {
		range_mask = 1;
		range_mask_ind = 1;
		index = 0;
		for ( unsigned i = 0; i < FULL_MASK_LEN; i++ ) {
			for ( unsigned j = 0; j < UINT_LEN; j++ ) {
				mask = ( 1 << j );
				cur_var_ind = i * UINT_LEN + j;
				IsAddingLiteral = false;
				if ( part_mask[i] & mask ) { // one common vector send by control process
					IsPositiveLiteral = ( mask_value[i] & mask ) ? true : false;
					IsAddingLiteral = true;
				}
				else if ( full_mask[i] & mask ) { // set of vectors
					IsPositiveLiteral = ( lint & range_mask ) ? true : false;
					range_mask = 1 << range_mask_ind;
					range_mask_ind++;
					IsAddingLiteral = true;
				}
				if ( !IsAddingLiteral ) continue;
				dummy_vec[lint][index++] = IsPositiveLiteral ? mkLit( cur_var_ind ) : ~mkLit( cur_var_ind );
			}
		}
	}
	return true;
}
Ejemplo n.º 2
0
bool SudokuSolver::FindMin(unsigned iMin, unsigned iMax, unsigned jMin, unsigned jMax, unsigned &outI, unsigned &outJ)
{
	bool found = false;
	unsigned count = 0;

	for (unsigned i = iMin; i < iMax; i++)
		for (unsigned j = jMin; j < jMax; j++)
			if (cells[i][j] == invalid &&	
				(!found || BitCount(Candidates(i, j)) < count)) {
				count = BitCount(Candidates(i, j));
				outI = i;
				outJ = j;
				found = true;
			}

	return found;
}
Ejemplo n.º 3
0
int push (Instruction ins, Emulator* emul) {
	
	int t;
	int i;
	long registers;
	long address;
	

	if (ins.encoding == 1 ) {
		if (push_T1 (ins, &registers)) {
			return 1;
		}
	}

	else if (ins.encoding == 2 ) {
		if (push_T2 (ins, &registers)) {
			return 1;
		}
	}
	
	else if (ins.encoding == 3 ) {
		if (push_T3 (ins, &registers, &t)) {
			return 1;
		}
	}
	
	else {
		WARNING_MSG ("Cet encodage n'est pas dans le dictionnaire");
		return 1;
	}
	
	address = emul->reg[13] - 4*BitCount(registers);
	for (i=0 ; i<=14; i++) {
		if (registers & (1u << i) ){
			address = emul->reg[i];
			address = address + 4;
		}
		
	}
	emul->reg[13] = emul->reg[13] - 4*BitCount(address) ;
	return 0;

}
Ejemplo n.º 4
0
// Count the number of 1 bits in this BitString
size_t BitString::Count( ) const
{
	WordArrayConstIter itr1 = mWords.begin();
	size_t count = 0;
	while( itr1 != mWords.end( )  )
	{
		// Count the number of 1's in each word
		count += BitCount( *itr1++ );
	}
	return count;
}
Ejemplo n.º 5
0
PolynomialMod2 PolynomialMod2::Times(const PolynomialMod2 &b) const
{
	PolynomialMod2 result((word)0, BitCount() + b.BitCount());

	for (int i=b.Degree(); i>=0; i--)
	{
		result <<= 1;
		if (b[i])
			XorWords(result.reg, reg, reg.size());
	}
	return result;
}
Ejemplo n.º 6
0
int pop_T1 (Instruction ins, long* registers) {

	//*registers = ins.ext->ue:'00.va.000':ins.reg->ue ;
	*registers = ins.reg.plages[0].value;
	if (ins.ext.plages[0].value) {
		*registers = *registers | (1u << 12);
	} 
	if (BitCount(*registers)<1){
		WARNING_MSG ("Accès non autorisé");
		return 1;
	}
	return 0;
}
Ejemplo n.º 7
0
int push_T1 (Instruction ins, long* registers) {

	*registers = ins.imm.plages[0].value;
	
	if (ins.ext.plages[0].value) {
		*registers = *registers | (1u << 16) ;
	} 	
	
	if (BitCount(*registers)<1){
		WARNING_MSG ("Accès non autorisé");
		return 1;
	}
	return 0;
}
Ejemplo n.º 8
0
BEGIN_NCBI_SCOPE

//-------------------------------------------------------------------------
Uint1 CSeqMaskerUtil::BitCount( Uint4 mask, Uint1 bit_value )
{
    if( !bit_value ) return BitCount( ~mask, 1 );
    else 
    {
        Uint1 result = 0;

        for( Uint1 i = 0; i < 8*sizeof( mask ); ++i )
            if( (1<<i)&mask ) ++result;

        return result;
    }
}
Ejemplo n.º 9
0
// Make full_mask and part_mask for sending from order that is set by var choose array
//---------------------------------------------------------
bool MPI_Base :: GetMainMasksFromVarChoose( std::vector<int> &var_choose_order )
{
	if ( verbosity > 0 ) {
		std::cout << std::endl << "GetMainMasksFromVarChoose() start with var_choose_order " << std::endl;
		for ( unsigned i = 0; i < var_choose_order.size(); i++ )
			std::cout << var_choose_order[i] << " ";
		std::cout << std::endl;
		std::cout << "part_mask_var_count " << part_mask_var_count << std::endl;
		std::cout << std::endl;
	}

	// init masks every launch
	for ( unsigned i = 0; i < FULL_MASK_LEN; ++i )
		part_mask[i] = full_mask[i] = 0;
	
	unsigned cur_uint_ind, var_index;
	for ( unsigned i = 0; i < var_choose_order.size(); ++i ) {
		var_index = var_choose_order[i] - 1;
		cur_uint_ind = var_index / UINT_LEN;
		full_mask[cur_uint_ind] += 1 << ( var_index % UINT_LEN );
	}

	// get first full_mask_var_count vars from  array var_choose_order
	for ( unsigned i = 0; i < part_mask_var_count; ++i ) {
		var_index = var_choose_order[i] - 1;
		cur_uint_ind = var_index / UINT_LEN;
		part_mask[cur_uint_ind] += 1 << ( var_index % UINT_LEN );
	}
	
	if ( verbosity > 1 ) {
		std::cout << "made part_mask" << std::endl;
		for( unsigned i = 0; i < FULL_MASK_LEN; ++i )
			std::cout << part_mask[i] << " ";
		std::cout << std::endl;
		unsigned bit_count = 0;
		for ( unsigned j=0; j < FULL_MASK_LEN; ++j )
			bit_count += BitCount( part_mask[j] );
		std::cout << "part_mask bit_count " << bit_count << std::endl;
	}
	
	if ( verbosity > 1 )
		std::cout << "GetMainMasksFromVarChoose() end" << std::endl;
	
	return true;
}
Ejemplo n.º 10
0
int pop (Instruction ins, Emulator* emul) {
	

	int t;
	int i;
	long registers;
	vaddr32 adress;


	if (ins.encoding == 1 ) {
		if (pop_T1 (ins, &registers)) {
			return 1;
		}
	}

	else if (ins.encoding == 2 ) {
		if (pop_T2 (ins, &registers)) {
			return 1;
		}
	}
	
	else if (ins.encoding == 3 ) {
		if (pop_T3 (ins, &registers, &t)) {
			return 1;
		}
	}
	
	else {
		WARNING_MSG ("Cet encodage n'est pas dans le dictionnaire");
		return 1;
	}

	adress = emul->reg[13];
	for (i = 0 ; i<=14 ; i++) {
		if (registers & (1u << i )) {
			emul->reg[i] = adress; //MemA(adress, 4);
			adress = adress +4;
		}
	}
	if (registers & (1u << 15 ) ) {
		BranchWritePC(adress, emul);//MemA(adress, 4));
	}
	emul->reg[13] = emul->reg[13] + 4*BitCount(registers);
	return 0;
}
Ejemplo n.º 11
0
int pop_T2 (Instruction ins, long* registers){

	//*registers = ins.ext->value:[0].s.ext->value:[1].s.reg->ue ;
	*registers = ins.reg.plages[0].value;
	if (ins.ext.plages[1].value) {
		*registers = *registers | (1u << 5);
	} 
	if (ins.ext.plages[0].value) {
		*registers = *registers | (1u << 6);
	} 
	if (BitCount (*registers)<2 || (ins.ext.plages[0].value == 1 && ins.ext.plages[1].value == 1 ) ) {
		WARNING_MSG ("Accès non autorisé");
		return 1;
	}

	if (*registers & (1u << 15) /* && InITBlock() && !LastInITBlock ()*/) {
		WARNING_MSG ("Accès non autorisé");
		return 1;
	}
	return 0;
}
Ejemplo n.º 12
0
int push_T2 (Instruction ins, long* registers){

	*registers = ins.imm.plages[0].value;
	if (ins.ext.plages[0].value) {
		*registers = *registers | (1u << 14) ;
	} 	
	if (ins.ext.plages[1].value) {
		*registers = *registers | (1u << 15) ;
	} 	

	if (BitCount (*registers)<2 || (ins.ext.plages[1].value && ins.ext.plages[0].value) ) {
		WARNING_MSG ("Accès non autorisé");
		return 1;
	}
	if (*registers & (1u << 15)) {
		WARNING_MSG ("Accès non autorisé");
		return 1;
	}
		 
	return 0;
}
Ejemplo n.º 13
0
int CBoard::EvaluateBoard (int ahead, int alpha, int beta)
    {
    // Game is over?
    if (C.WP == 0) return -2001 + ahead;
    if (C.BP == 0) return 2001 - ahead;
    //
    int eval, square;

    // Number of pieces present. Scaled higher for less material
    if ((nWhite+nBlack) > 12 ) eval = (nWhite-nBlack) * 100;
        else eval = (nWhite-nBlack) * (160 - (nWhite + nBlack) * 5 );
    eval+=nPSq;

    // Probe the W/L/D bitbase
    if ( InDatabase() )
    {        
        int Result = QueryDatabase( *this );
        if (Result == 2) eval+=400;
        if (Result == 1) eval-=400;
        if (Result == 0) return 0;
    }
    else {if (nWhite == 1 && nBlack >= 3 && nBlack < 8) eval = eval + (eval>>1); // surely winning advantage
          if (nBlack == 1 && nWhite >= 3 && nWhite < 8) eval = eval + (eval>>1);
         }

    // Too far from the alpha beta window? Forget about the rest of the eval, it probably won't get value back within the window
    if (eval+LAZY_EVAL_MARGIN < alpha) return eval;
    if (eval-LAZY_EVAL_MARGIN > beta) return eval;

    // Keeping checkers off edges
    eval -= 2 * (BitCount(C.WP & ~C.K & MASK_EDGES) - BitCount(C.BP & ~C.K & MASK_EDGES) );
    // Mobility
    eval += 2 * ( C.GetWhiteMoves( ) - C.GetBlackMoves( ) );

    // The losing side can make it tough to win the game by moving a King back and forth on the double corner squares.
    if (eval > 18)
        {if ((C.BP & C.K & MASK_2CORNER1)) {eval-=8; if ((MASK_2CORNER1 & ~C.BP &~C.WP)) eval-=10;}
         if ((C.BP & C.K & MASK_2CORNER2)) {eval-=8; if ((MASK_2CORNER2 & ~C.BP &~C.WP)) eval-=10;}
        }
    if (eval < -18)
        {if ((C.WP & C.K & MASK_2CORNER1)) {eval+=8; if ((MASK_2CORNER1 & ~C.BP &~C.WP)) eval+=10;}
         if ((C.WP & C.K & MASK_2CORNER2)) {eval+=8; if ((MASK_2CORNER2 & ~C.BP &~C.WP)) eval+=10;}
        }

    int nWK = BitCount( C.WP & C.K );
    int nBK = BitCount( C.BP & C.K );
    int WPP = C.WP & ~C.K;
    int BPP = C.BP & ~C.K;
    // Advancing checkers in endgame
    if ( (nWK*2) >= nWhite || (nBK*2) >= nBlack || (nBK+nWK)>=4) {
        int Mul;
        if ( nWK == nBK && (nWhite+nBlack) < (nWK+nBK+2) ) Mul = 8; else Mul = 2;
        eval -=  Mul * ( BitCount( (WPP & MASK_TOP) ) - BitCount( (WPP & MASK_BOTTOM) )
                      -BitCount( (BPP & MASK_BOTTOM) ) + BitCount( (BPP & MASK_TOP) ) );
        }

    static int BackRowGuardW[8] = { 0, 4, 5, 13, 4, 20, 18, 25 };
    static int BackRowGuardB[8] = { 0, 4, 5, 20, 4, 18, 13, 25 };
    int nBackB = 0, nBackW = 0;
    if ( (nWK*2) < nWhite )
        {
         nBackB = (( BPP ) >> 1) & 7;
         eval -= BackRowGuardB[ nBackB ];
        }
Ejemplo n.º 14
0
UINT CCISDL::Execute(	SettingConfgInfo *pCurSettingConfgInfo,
						CFlash			*pflash,
						CRootTable		*pRootTable,
						UINT 			*eCISADDR,
						UINT			*Original_EraseCnt,
						UINT			Terminate){

	UINT	Status=Success_State, BitErrorCnt=0, ErrorBitLimt;
	eMMC_CIS_INFO	eCISSetData, eCISBackData; //eCISPairMap; Cody_20150216
	BYTE	ECC, EraseStatus=0, ValueTmp=0, RetryCnt;
	WORD	*pWORD, CheckSum=0;
	SPARETYPE Spare;
	ULONG	Address;
	UINT    i,j,CISBlockNum;
	FILE	*ISPBinFile;
	ULONG	ISPRealByte, ISPTotalByte, EachTxSize;
	ULONG	ISPIdx, PageAddr, BufOffset;
	BYTE	*TxDataBuf, *RxDataBuf;
	BYTE	*RTDataBuf;
	BYTE	BackUpRTNum = 0, Num;						// RT Numbers
	ULONG	RTPageIdxOfs, EachRTSize = 14*1024;			// RT Size in One Page is 14K
	UINT 	OldCISVersionExit = pflash->isOldVersionCISExit();
	if(pflash->getPlaneNum() == 1)
		CISBlockNum = 2; // if 1 Plane, write 2 CIS Block
	else
		CISBlockNum = 4; // if 2 Plane, Write 4 CIS Block



	BYTE	SpareBuf[6]={0,0,0,0,0,0};

	// ----- ISP_Step 1/7: Prepare ISP Data -----Must Get This Here for CIS Data


	if(pflash->getPageSEC() == 32)
		EachTxSize = 12*1024;	// 16K_Flash, Each Page Write 12K
	else
		EachTxSize = 6*1024;	//   8K_Flash, Each Page Write 6K

	if(sizeof(eMMC_CIS_INFO)%EachTxSize) // Protection
	{
		Status=Illegal_CIS_Define;
		return Status;
	}

	if(pCurSettingConfgInfo->FWFileName.length() == 0)
	{
		Status=Open_FW_File_Error;
		return Status;
	}

	ISPBinFile = fopen((char *)pCurSettingConfgInfo->FWFileName.c_str(),"r");					// no attr. template

	if(ISPBinFile==NULL)
	{
		Status=Open_FW_File_Error;
		return Status;
	}


	ISPRealByte = FileSize(ISPBinFile); //	Get Real ISP Size
	if((ISPRealByte%EachTxSize) != 0) // If Not Multiple of 6K, Modify It As 6K*N
	{
		ISPTotalByte = ((ISPRealByte/EachTxSize)+1) * EachTxSize;

	}
	else
		ISPTotalByte = ISPRealByte;

	TxDataBuf=(BYTE *)malloc(sizeof(BYTE)*ISPTotalByte);
	RxDataBuf=(BYTE *)malloc(sizeof(BYTE)*ISPTotalByte);
	memset(TxDataBuf, 0, sizeof(BYTE)*ISPTotalByte);
	fread(&TxDataBuf,sizeof(char),ISPRealByte,ISPBinFile);
	RTDataBuf=(BYTE *)malloc(sizeof(BYTE)*EachRTSize*10);	// 1 Set of RT is 2*14K, Backup 5 Set of RT
	memset(RTDataBuf, 0xFF, sizeof(BYTE)*EachRTSize*10);
	RTPageIdxOfs = (sizeof(eMMC_CIS_INFO)/EachTxSize) + (ISPTotalByte/EachTxSize); // Normally is 15


// ----- CIS_Step 1/4: Prepare CIS Data -----
// Set eCIS Basic Data
// Sherlock_20140819, Modify For eMMC_CFG_A2Scan

// Get ExtCSD Data From File, Sherlock_20140620
//eMMC_Get_CID_From_File(pThreadInfo, &eCISSetData);


	for(i=0; i<CISBlockNum; i++){ // Sherlock_20140815, Set CIS Block As MLC, 60-bits For Current Read
		Status = pflash->writeCellMapFlashType(eCISADDR[i],1);
		Status = pflash->writeEccMapBitLength(eCISADDR[i],1);
	}
	for(i=0; i<CISBlockNum; i++){ // Sherlock_20140815, Set CIS Block As MLC, 60-bits into PairMaps For FW Read
		Status = pRootTable->setCellMap(eCISADDR[i],1);
		Status = pRootTable->setEccMap(eCISADDR[i],1);
	}
	// Set eCIS BitMap Data
	pmCisTool->setBlockMaptoBitMap(pflash,pRootTable,pRootTable->getUFDBlockMap(),&eCISSetData);

	// calc the checksum
	pWORD = (WORD *) &eCISSetData;
	for(i=1; i < (int)offsetof(eMMC_CIS_INFO, Bit_Map[0])/2; i++)
	{
		CheckSum+=pWORD[i];
	}
	CheckSum=0x10000-CheckSum; //get CheckSum inverse
	eCISSetData.CheckSum = (USHORT)CheckSum;

	// ----- Prepare Other Data For Writing -----
	ErrorBitLimt = (pCurSettingConfgInfo->LunTypeBitMap2 & BitErrorRate);
	ECC = pflash->getFlashModel(3) & 0x0F;
	Spare.SPARE0=0x43; //'C'
	Spare.SPARE1=0x53; //'S'
	Spare.SPARE2=0x00; //Initial Value
	Spare.SPARE3=0x00; //Initial Value
	Spare.SPARE4=0x99;
	Spare.SPARE5=0x99;

	// ----- Get CIS Data into CIS_SetData From Read CIS (Only_DL_FW Mode) -----
	if((pCurSettingConfgInfo->TestProcedureMask & Proc_DisableCISDL)   ||
	   (((pRootTable[0].getRootTableVersion() & 0xFFFF0000) != 0x52540000)  &&
	   (OldCISVersionExit == Success_State))) //Not Change CIS, Only DL FW, Use OLD CIS Data, Sherlock_20131015  ,Special Function of Keep old CIS data For RE-MP ,Cody_20150217
	{

		for(ISPIdx=0; ISPIdx<(sizeof(eMMC_CIS_INFO)/EachTxSize); ISPIdx++)
		{
			BufOffset = ISPIdx * EachTxSize;
			PageAddr = (ULONG)eCISSetData.TurboPage[ISPIdx];
			for(RetryCnt=0; RetryCnt<3; RetryCnt++)
			{
				Status=pflash->readBlockData((BYTE)(EachTxSize/512),
											ECC,
											Spare,
											eCISADDR[0]+PageAddr,
											EachTxSize,
											(BYTE *)&eCISSetData+BufOffset);
				if(Status)
					break;
			}
			;
			if(!Status)
			{
				Status=EEPROM_UpLoad_Error;
				goto Endof_eCIS_Download;
			}

//			OutputDataBuffer(sizeof(eMMC_CIS_INFO),(LPBYTE)&eCISSetData);

			// calc the checksum
			CheckSum=0;
			pWORD = (WORD *) &eCISSetData;
			for(i=1; i < (int)offsetof(eMMC_CIS_INFO, Bit_Map[0])/2; i++)
			{
				CheckSum+=pWORD[i];
			}
			CheckSum=0x10000-CheckSum; //get CheckSum inverse
			if(eCISSetData.CheckSum != (USHORT)CheckSum)
			{
				Status = CIS_CheckSum_Error;
				goto Endof_eCIS_Download;
			}
		}

		for(i=0; i<4; i++) // Sherlock_20131106, For Only_DL_FW Case, We Get CIS Address From CIS Set Data
			eCISADDR[i] = eCISSetData.CIS_RowAddr[i];

 // Sherlock_20131106, Get EraseCount For Only_DL_FW Mode
		for(i=0; i<4; i++)
		{
			if(eCISADDR[i] == 0xFFFFFFFF)	continue;	// Protection

			pflash->ReadSpareData(0, 0, eCISADDR[i], 6, SpareBuf);
			// For eCIS. EncryptionCMD is 0
			// ---------- New Get Spare ---------- Sherlock_20140415
			USHORT Shift1 = SpareBuf[1]&0x3F;	// Clear Bit7 and Bit6
			if( ((SpareBuf[0] == 0x43) && (SpareBuf[1] == 0x53)) || // 'CS'
				((Shift1<<8 | SpareBuf[0]) == (0x54<<7 | 0x52)) ||	// 'RT'
				((Shift1<<8 | SpareBuf[0]) == (0x48<<7 | 0x43)) ||	// 'CH'
				((Shift1<<8 | SpareBuf[0]) == (0x4B<<7 | 0x4D)) ||	// 'MK'
				((Shift1<<8 | SpareBuf[0]) == (0x54<<7 | 0x44)) ||	// 'DT'
				((Shift1<<8 | SpareBuf[0]) == (0x55<<7 | 0x44)) ||	// 'DU'
				((SpareBuf[0] == 0x4D) && (SpareBuf[1] == 0x50)) )	// 'MP' This Means "Erased By MPTool"
				Original_EraseCnt[i] = ((UINT)SpareBuf[3]<<8) | SpareBuf[2];	// Real Erase Count
			else
				Original_EraseCnt[i] = 0;
		}

	}

// Sherlock_20140814, Read RT from First CIS Block
	if(pCurSettingConfgInfo->TestProcedureMask & Proc_DisableCISDL)
	{
		for(Num=0; Num<10; Num++)
		{
			BufOffset = Num * EachRTSize;
			PageAddr = (ULONG)eCISSetData.TurboPage[RTPageIdxOfs+Num];
			Status=pflash->readBlockData((BYTE)(EachRTSize/512),
										ECC+BIT7, // Encryption ON
										Spare,
										eCISADDR[0]+PageAddr,
										EachRTSize,
										(BYTE *)RTDataBuf+BufOffset);

			if((Num%2) == 0)	// Check While Even Index, One Set Of RT is 28K
			{
				j = BufOffset+(EachRTSize/2);	// First RT(7K) Position
				if( (RTDataBuf[j-1]!=0x52) ||(RTDataBuf[j-2]!=0x54) ) // Check 1st RT for 'R' & 'T'
				{
					break;
				}
			}
		}
		BackUpRTNum = Num;
	}




	// ----- Dump eCIS Important Data -----

	// ---------- Whole Write CIS Block Cycle ----------
	for(i=0; i<CISBlockNum; i++)
	{
		Address = eCISADDR[i];
// Sherlock_20131106, Set New EraseCount
		Spare.SPARE3 = (BYTE)(((Original_EraseCnt[i]+1) & 0x0000FF00) >> 8);	// HI
		Spare.SPARE2 = (BYTE)((Original_EraseCnt[i]+1) & 0x000000FF);		// LO


		if(Address == 0xFFFFFFFF)	continue;	// Protection

		// ----- Erase Block -----
		for(RetryCnt=0; RetryCnt<3; RetryCnt++)
		{
			Status=pflash->EraseBlock(Address, &EraseStatus);
			if(Status)
				break;
		}

		if(!Status)
		{
			Status = Block_Erase_Error;
			goto Endof_eCIS_Download;
		}

		// ----- CIS_Step 2/4: Write eCIS Cycle-----
		for(ISPIdx=0; ISPIdx<(sizeof(eMMC_CIS_INFO)/EachTxSize); ISPIdx++)
		{
			BufOffset = ISPIdx * EachTxSize;
			PageAddr = (ULONG)eCISSetData.TurboPage[ISPIdx];
			for(RetryCnt=0; RetryCnt<3; RetryCnt++)
			{
				Status=pflash->writeBlockData((BYTE)(EachTxSize/512),
												ECC,
												Spare,
												Address+PageAddr,
												EachTxSize,
												(BYTE *)&eCISSetData+BufOffset);
				if(Status)
					break;
			}

			usleep(20000); // 20121114, For Multi-Device MP

			if(!Status)
			{
				Status=EEPROM_DownLoad_Error;
				goto Endof_eCIS_Download;
			}

		}

		// ----- CIS_Step 3/4: Read eCIS Cycle-----
		memset(&eCISBackData, 0, sizeof(eMMC_CIS_INFO));
		for(ISPIdx=0; ISPIdx<(sizeof(eMMC_CIS_INFO)/EachTxSize); ISPIdx++)
		{
			BufOffset = ISPIdx * EachTxSize;
			PageAddr = (ULONG)eCISSetData.TurboPage[ISPIdx];
			for(RetryCnt=0; RetryCnt<3; RetryCnt++)
			{
				Status=pflash->readBlockData((BYTE)(EachTxSize/512),
											 	ECC,
												Spare,
												Address+PageAddr,
												EachTxSize,
												(BYTE *)&eCISBackData+BufOffset);
				if(Status)
					break;
			}

			usleep(20000); // 20121114, For Multi-Device MP

			if(!Status)
			{
				Status=EEPROM_UpLoad_Error;
				goto Endof_eCIS_Download;
			}

		}


		if(Terminate==true) //terminate the thread and go back to start state
			goto Terminate_eCIS_DownLoad_Handle;

		// ----- CIS_Step 4/4: Compare eCIS Info -----
		for(j=0; j<sizeof(eMMC_CIS_INFO); j++)
		{
			if((j%1024)==0)
				BitErrorCnt=0;

			ValueTmp=((BYTE *)&eCISSetData)[j]^((BYTE *)&eCISBackData)[j];

			if(ValueTmp)
				BitErrorCnt+=BitCount(ValueTmp);

			if(BitErrorCnt > ErrorBitLimt)
			{
				Status=EEPROM_Compare_Error;
				goto Endof_eCIS_Download;
			}
		}

		// ----- ISP_Step 2/7: Write ISP 1 -----
		for(ISPIdx=0; ISPIdx<(ISPTotalByte/EachTxSize); ISPIdx++)
		{
			BufOffset = ISPIdx * EachTxSize;
			PageAddr = (ULONG)eCISSetData.TurboPage[ISPIdx + (sizeof(eMMC_CIS_INFO)/EachTxSize)]; // Skip eCIS Pages
			for(RetryCnt=0; RetryCnt<3; RetryCnt++)
			{
				Status=pflash->writeBlockData((BYTE)(EachTxSize/512),
												ECC,
												Spare,
												Address+PageAddr,
												EachTxSize,
												TxDataBuf+BufOffset);
				if(Status)
					break;
			}
			usleep(20000); // 20121114, For Multi-Device MP

			if(!Status)
			{
				Status=FW_DownLoad_Error;
				goto Endof_eCIS_Download;
			}

		}

 // Sherlock_20140814, Write RT into Each CIS Block
		if(pCurSettingConfgInfo->TestProcedureMask & Proc_DisableCISDL)
		{
			for(Num=0; Num<BackUpRTNum; Num++)
			{
				BufOffset = Num * EachRTSize;
				PageAddr = (ULONG)eCISSetData.TurboPage[RTPageIdxOfs+Num];
				Status=pflash->writeBlockData((BYTE)(EachRTSize/512),
												ECC+BIT7, // Encryption ON
												Spare,
												Address+PageAddr,
												EachRTSize,
														(BYTE *)RTDataBuf+BufOffset);
				if(!Status) // Write Fail
					break;
			}
		}


		// ----- ISP_Step 3/7: Read ISP 1 -----
		for(ISPIdx=0; ISPIdx<(ISPTotalByte/EachTxSize); ISPIdx++)
		{
			BufOffset = ISPIdx * EachTxSize;
			PageAddr = (ULONG)eCISSetData.TurboPage[ISPIdx + (sizeof(eMMC_CIS_INFO)/EachTxSize)]; // Skip eCIS Pages
			for(RetryCnt=0; RetryCnt<3; RetryCnt++)
			{
				Status=pflash->readBlockData((BYTE)(EachTxSize/512),
												ECC,
												Spare,
												Address+PageAddr,
												EachTxSize,
												RxDataBuf+BufOffset);
				if(Status)
					break;
			}
			if(!Status)
			{
				Status=FW_UpLoad_Error;
				goto Endof_eCIS_Download;
			}

		}

		// ----- ISP_Step 4/7: Compare ISP 1 -----
		for(BufOffset=0; BufOffset<ISPTotalByte; BufOffset++)
		{
			if((BufOffset%1024)==0)
				BitErrorCnt=0;

			ValueTmp=TxDataBuf[BufOffset]^RxDataBuf[BufOffset];

			if(ValueTmp)
				BitErrorCnt+=BitCount(ValueTmp);

			if(BitErrorCnt > ErrorBitLimt)
			{

				Status=FW_Compare_Error;
				goto Endof_eCIS_Download;
			}
		}
	}

Endof_eCIS_Download:
	fclose(ISPBinFile);
	free(TxDataBuf);
	free(RxDataBuf);
	free(RTDataBuf);
	return Status;

Terminate_eCIS_DownLoad_Handle:
	fclose(ISPBinFile);
	free(TxDataBuf);
	free(RxDataBuf);
	free(RTDataBuf);
	Status=ReStart_State;
	return Status;
}
Ejemplo n.º 15
0
BOOL CDrawing::DrawRaster(CDC* pDC, OgdcDatasetRaster* pDatasetR)
{
    OGDCASSERT(!OGDCIS0(m_dCoordRatio) && !m_rcClient.IsRectEmpty());

    OgdcRect2D rcDraw = pDatasetR->GetBounds();
    if(!rcDraw.IntersectRect(m_rcViewBounds, rcDraw))
    {
        return FALSE;
    }

    BYTE *lp = new BYTE[sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)*256];
    if(lp == NULL)
    {
        return FALSE;
    }

    int i = 0;
    BITMAPINFO *pBitMapInfo = (BITMAPINFO*)lp;
    PixelFormat ePixelFormat = pDatasetR->GetPixelFormat();
    pBitMapInfo->bmiHeader.biBitCount = BitCount(ePixelFormat);

    if(pDatasetR->GetBandCount() <= 1)
    {
        if(pDatasetR->GetType() == OgdcDataset::Image && ePixelFormat <= IPF_BYTE)
        {
            OgdcColorset colorset = pDatasetR->m_info.m_colorset;
            if(colorset.GetSize() == 0)
            {
                if(ePixelFormat == IPF_MONO)
                {
                    pBitMapInfo->bmiColors[0].rgbBlue = 0;
                    pBitMapInfo->bmiColors[0].rgbGreen = 0;
                    pBitMapInfo->bmiColors[0].rgbRed =  0;
                    pBitMapInfo->bmiColors[0].rgbReserved = 0;

                    pBitMapInfo->bmiColors[1].rgbBlue = 255;
                    pBitMapInfo->bmiColors[1].rgbGreen = 255;
                    pBitMapInfo->bmiColors[1].rgbRed =  255;
                    pBitMapInfo->bmiColors[1].rgbReserved = 0;
                }
                else if(ePixelFormat == IPF_FBIT)
                {
                    for(i = 0; i < 16; i++)
                    {
                        pBitMapInfo->bmiColors[i].rgbBlue = (16*i);
                        pBitMapInfo->bmiColors[i].rgbGreen = (16*i);
                        pBitMapInfo->bmiColors[i].rgbRed =  (16*i);
                        pBitMapInfo->bmiColors[i].rgbReserved = 0;
                    }
                }
                else
                {
                    for(i = 0; i < 256; i++)
                    {
                        pBitMapInfo->bmiColors[i].rgbBlue = i;
                        pBitMapInfo->bmiColors[i].rgbGreen = i;
                        pBitMapInfo->bmiColors[i].rgbRed =  i;
                        pBitMapInfo->bmiColors[i].rgbReserved = 0;
                    }
                }
            }
            else
            {
                for(i=0; i<256 && i<colorset.GetSize(); i++)
                {
                    //! 因为读进来的r和b是反的,所以要再反一次。
                    OgdcColor color = colorset.GetAt(i);
                    pBitMapInfo->bmiColors[i].rgbRed = GetBValue(color);
                    pBitMapInfo->bmiColors[i].rgbGreen = GetGValue(color);
                    pBitMapInfo->bmiColors[i].rgbBlue =  GetRValue(color);
                    pBitMapInfo->bmiColors[i].rgbReserved = 0;
                }
            }
        }
        else if(pDatasetR->GetType() == OgdcDataset::Grid)
        {
            pBitMapInfo->bmiHeader.biBitCount = 24;
            if(pDatasetR->m_colorTable.m_Colorset.GetSize() <= 0)
            {
                pDatasetR->m_colorTable.CreateDefault();
            }
        }
    }
    else
    {
        OgdcArray<OgdcInt> aryBand;
        aryBand.Add(0);
        aryBand.Add(1);
        aryBand.Add(pDatasetR->GetBandCount() > 2 ? 2:1);

        ImgColorSpace nColorSpace = ICS_RGB;
        pDatasetR->SetBandCombineMode(aryBand, nColorSpace);
        pBitMapInfo->bmiHeader.biBitCount = 24;
    }


    pBitMapInfo->bmiHeader.biPlanes = 1;
    pBitMapInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    pBitMapInfo->bmiHeader.biCompression = BI_RGB;
    pBitMapInfo->bmiHeader.biSizeImage = 0L;
    pBitMapInfo->bmiHeader.biXPelsPerMeter = 0L;
    pBitMapInfo->bmiHeader.biYPelsPerMeter = 0L;
    pBitMapInfo->bmiHeader.biClrUsed = 0L;
    pBitMapInfo->bmiHeader.biClrImportant = 0L;

    CRect rcBlock;
    CRgn *pClipRgn = NULL;
    OgdcElemRegion *pDTRasterClipRegion = pDatasetR->m_pClipRgn;
    if(pDTRasterClipRegion != NULL && !pDTRasterClipRegion->m_rcBounds.IsEmpty())
    {
        OgdcPoint2D *pPoint2Ds = pDTRasterClipRegion->m_points.GetData();
        CPoint *pClipPoints = NULL;
        if(GeoToDevice(pPoint2Ds, pDTRasterClipRegion->m_points.GetSize(), pClipPoints))
        {
            int nSubCount = pDTRasterClipRegion->m_polyCounts.GetSize();
            int *lpPolyCount = pDTRasterClipRegion->m_polyCounts.GetData();

            pClipRgn = new CRgn;
            if(pClipRgn != NULL)
            {
                pClipRgn->CreatePolyPolygonRgn(pClipPoints, lpPolyCount, nSubCount, ALTERNATE);
                pDC->SelectClipRgn(pClipRgn, RGN_AND);
            }
            delete[] pClipPoints;
            pClipPoints = NULL;
        }
    }

    OgdcSize szBMP(OGDCROUND(rcDraw.Width()/m_dCoordRatio), OGDCROUND(rcDraw.Height()/m_dCoordRatio));
    OgdcRasterBlock* pImgBlock = pDatasetR->GetViewBlock(rcDraw, szBMP.cx, szBMP.cy);
    if(pImgBlock != NULL)
    {
        DrawRasterBlock(pDC, pImgBlock, pDatasetR, pBitMapInfo);

        delete pImgBlock;
        pImgBlock = NULL;
    }
    pDatasetR->ReleaseAllBlocks();

    if(lp != NULL)
    {
        delete[] lp;
        lp = NULL;
    }

    if(pClipRgn != NULL)
    {
        pDC->SelectClipRgn(NULL, RGN_COPY);
        delete pClipRgn;
        pClipRgn = NULL;
    }
    return TRUE;
}