⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dvm.c

📁 Xcale270Bsp包,wince平台
💻 C
📖 第 1 页 / 共 2 页
字号:
{
	int i =0;
	for(i=0; i<32; i++)
		*(PCMD + 4 * i) &= ~PCMD_MBC;
}

void ClearAllDCE(void)
{
	int i =0;
	for(i=0; i<32; i++)
		* (PCMD + 4 * i)  &= ~PCMD_DCE;
}

void SetMBCBit(int ReadPointer, int NumOfBytes)
{
	int i = 0;
/*	for (i=ReadPointer; i<ReadPointer + NumOfBytes; i++)
	{
		*(PCMD + 4 * i)  |= PCMD_MBC;
	}
*/
	 *PCMD0 |=  PCMD_MBC; 
	 *PCMD1 |=  PCMD_MBC;
//	 *PCMD2 |=  PCMD_MBC; 
}

void SetLCBit(int ReadPointer, int NumOfBytes)
{
	int i = 0;
/*	for (i=ReadPointer; i<ReadPointer + NumOfBytes; i++)
	{
		*(PCMD + 4 * i)  |= PCMD_LC;
	}
*/
	 *PCMD0 |=  PCMD_LC; 
	 *PCMD1 |=  PCMD_LC;
	 *PCMD2 |=  PCMD_LC; 


}

void SetCommandData(unsigned char *DataArray, int StartPoint, int size)
{
    int i = 0;
/*	for (i=StartPoint; i<StartPoint + size; i++)
	{
	   *(PCMD + i * 4) &= 0xFFFFFF00;
       *(PCMD + 4 * i)  |= DataArray[i-StartPoint];
	}
*/
	 *PCMD0 &= 0xFFFFFF00;
     *PCMD0 |= DataArray[0];

     *PCMD1 &= 0xFFFFFF00;
     *PCMD1 |= DataArray[1];

	 *PCMD2 &= 0xFFFFFF00;
     *PCMD2 |= DataArray[2];


}

BOOL VSetPCMDRange_LC(UINT iFrom, UINT iTo)
{
   	UINT i;

   	if (iTo < iFrom || iTo < 0 || iFrom < 0 || iTo > 31 || iFrom > 31)
   	{
	  	return FALSE;
   	}

   	for (i = iFrom ; i <= iTo ; i++)
   	{
		// set commands, this is not the last one
      	*(PCMD + 4 * i) &= ~PCMD_LC;
   	}

	// set last command
   	*(PCMD + 4 * iTo) |=  PCMD_LC;

   	return TRUE;
}

void VM_SingleByte_Command(DWORD data,int ReadPointer)
{
    int i = 0;
//	EdbgOutputDebugString("DM_SingleByte_VoltageSetting is entered\r\n");
	
	*PVCR = 0;
//	*PCFR = 0;

	*PCFR &= ~PCFR_FVC;  
	*PVCR &=~ PVCR_CommandDelay; //no delay is necessary
	*PVCR |= 0xFFFFFF80;    //clear slave address
	*PVCR |= 0x20;         //set slave address
	*PVCR &= ~(0x1f<<20);   //clear read pointer 0
	*PVCR |= (ReadPointer<<20);
	 ClearAllSQC();
	 ClearAllMBC();        //single byte command
	 ClearAllDCE();       //Clear DCE bit

	 //through ReadPointer to find the command register which needs to send byte
	 //fill the data with command register
	 for(i=0; i<32; i++)
	 {
		 if(i == ReadPointer)
		 {
			 *(PCMD + i * 4) = data;
			 break;
		 }
			 else
				*(PCMD + i * 4) &= 0xFFFFFF00;
	 }
    //Set last command to read pointer also so we only send one command  
	VSetPCMDRange_LC(0, ReadPointer);

	*PCFR |= 0x60;    //PCFR_PI2C_EN;  //enable Pwr I2C 

//	 EdbgOutputDebugString("before *PCFR is 0x%x\r\n", *PCFR);
//     EdbgOutputDebugString("before *PVCR is 0x%x\r\n", *PVCR);
//     EdbgOutputDebugString("before *PCMD is 0x%x\r\n", *PCMD);
	XSC1ChangeVoltage( );    //set VC on the PWRMODE on CP14

	while ( ( (*PVCR) & PVCR_VCSA) )
	{
//		EdbgOutputDebugString("Voltage sequence is going on\r\n");
	}
//    EdbgOutputDebugString("*PCFR is 0x%x\r\n", *PCFR);
//     EdbgOutputDebugString("*PVCR is 0x%x\r\n", *PVCR);
//     EdbgOutputDebugString("*PCMD is 0x%x\r\n", *PCMD);
}

void VM_MulitByte_Command(unsigned char *dataArray, int ReadPointer, int NumOfBytes)
{
//	volatile XLLP_OST_T *v_pOSTReg = (volatile XLLP_OST_T *)OST_BASE_U_VIRTUAL;
	unsigned long start = 0, end = 0;

//    EdbgOutputDebugString("PM_MulitByte_Command is entered\r\n");
	//start = v_pOSTReg->oscr0;
	*PVCR = 0;
//	*PCFR = 0;

	*PCFR &= ~PCFR_FVC;  
	*PVCR &=0xFFFFF07F; //no delay is necessary
	*PVCR &= 0xFFFFFF80;    //clear slave address
	*PVCR |= 0x20;         //set slave address

	*PVCR &= 0xFE0FFFFF;   //clear read pointer 0
	*PVCR |= (ReadPointer<<20);
	//DCE and SQC are not necessary for single command 
	 ClearAllSQC();        //Sequence configuration is not necessary
	 ClearAllDCE();       //Clear DCE bit

	 ClearAllMBC( );     //Clear all MBC bit first
	 SetMBCBit(ReadPointer, NumOfBytes-1);
   
	 //indicate the last byte of this command is holded in this register
	 //*(PCMD + ReadPointer + (4 * (NumOfBytes-1)) ) &= ~PCMD_MBC;
      *PCMD2 &= ~PCMD_MBC; 
    //indicate this is the first command and last command also
	 SetLCBit(ReadPointer, NumOfBytes);

	//programming the command data bit 
	 SetCommandData(dataArray, ReadPointer, NumOfBytes-1);

	 //Enable Power I2C
      *PCFR |= 0x60;    //PCFR_PI2C_EN;  //enable Pwr I2C 
  //  EdbgOutputDebugString("before PCMD[0] is 0x%x\r\n", *PCMD0);
  //  EdbgOutputDebugString("before PCMD[1] is 0x%x\r\n", *PCMD1);
//	EdbgOutputDebugString("before PCMD[2] is 0x%x\r\n", *PCMD2);
//	EdbgOutputDebugString("*PCFR is 0x%x\r\n", *PCFR);
 //   EdbgOutputDebugString("*PVCR is 0x%x\r\n", *PVCR);
 
	//while(1);
	 //Execute voltage change sequence
	XSC1ChangeVoltage( );    //set VC on the PWRMODE on CP14
    //if(Freq_Mode == 1)
         while ( ( (*PVCR) & PVCR_VCSA) !=0 );
	
		

//	end = v_pOSTReg->oscr0;
//	voltagechange_latency = (end-start)/3.25;
//	EdbgOutputDebugString("start is %d\r\n",start);
//    EdbgOutputDebugString("end is %d\r\n",end);
//	EdbgOutputDebugString("voltage change latency is %f\r\n",voltagechange_latency);
}


void VM_SetVoltage(DWORD DACValue)
{
	unsigned char dataArray[3];
	dataArray[0] = 0;  //Command 0
	dataArray[1] = (DACValue & 0x000000FF);
	dataArray[2] = (DACValue & 0x0000FF00)>>8;
  //  EdbgOutputDebugString("dataArray[2] is %x\r\n",dataArray[2] );
//	lpWriteDebugStringFunc(TEXT("VM_SetVoltage...\r\n"));
	VM_MulitByte_Command(dataArray, 0, 3);
	//send command 0
	//PM_SingleByte_Command(DACValue,0);
	//send data LSB
//	PM_SingleByte_Command( (DACValue & 0x000000FF), 0);

	//send data MSB
//	PM_SingleByte_Command( ( (DACValue & 0x0000FF00)>>8), 0);
}

void ComboChange(int LMult, int NMult, int run_mode_flag, int fastbus_mode_flag, DWORD DACValue)
{
	volatile XLLP_CLKMGR_T   *v_pClkReg = (volatile XLLP_CLKMGR_T *)CLK_BASE_U_VIRTUAL;
	int i= 0; 
	int newCLKCFGValue = 0;
    unsigned long  CLKCFGValue = 0;
	int turbo_mode;
    int ReadPointer = 0;
	int NumOfBytes = 3;
	unsigned char dataArray[3];
	dataArray[0] = 0;  //Command 0
	dataArray[1] = (DACValue & 0x000000FF);
	dataArray[2] = (DACValue & 0x0000FF00)>>8;


    CLKCFGValue = XSC1ReadCLKCFG();
    turbo_mode = (CLKCFGValue & 0x1);
	//disable all interrupts
//	INTERRUPTS_OFF();

	//set up the new frequency mulitipliers, N and L

	v_pClkReg->cccr = (NMult<<7) | LMult;

	//set up the new CLKCFG value, for an new frequency 

	 newCLKCFGValue =(0x2 | (fastbus_mode_flag<<3) | run_mode_flag);

    //votlage change configureation
   // EdbgOutputDebugString("PM_MulitByte_Command is entered\r\n");
//	start = v_pOSTReg->oscr0;
	*PVCR = 0;
//	*PCFR = 0;

	*PCFR &= ~PCFR_FVC;  
	*PVCR &=0xFFFFF07F; //no delay is necessary
	*PVCR &= 0xFFFFFF80;    //clear slave address
	*PVCR |= 0x20;         //set slave address

	*PVCR &= 0xFE0FFFFF;   //clear read pointer 0
	*PVCR |= (ReadPointer<<20);
	//DCE and SQC are not necessary for single command 
	 ClearAllSQC();        //Sequence configuration is not necessary
	 ClearAllDCE();       //Clear DCE bit

	 ClearAllMBC( );     //Clear all MBC bit first
	 SetMBCBit(ReadPointer, NumOfBytes-1);
   
	 //indicate the last byte of this command is holded in this register
	 //*(PCMD + ReadPointer + (4 * (NumOfBytes-1)) ) &= ~PCMD_MBC;
      *PCMD2 &= ~PCMD_MBC; 
    //indicate this is the first command and last command also
	 SetLCBit(ReadPointer, NumOfBytes);

	//programming the command data bit 
	 SetCommandData(dataArray, ReadPointer, NumOfBytes-1);


	*PCFR |= (0x60 | 0x1<<10);    //PCFR_PI2C_EN;  //enable Pwr I2C 

    XSC1FreqChange(newCLKCFGValue);
//	lpWriteDebugStringFunc(TEXT("ComboChange Exit...\r\n"));
}



void StartDVMTimer(int count)
{
	volatile XLLP_OST_T		*v_pOSTReg = (volatile XLLP_OST_T *)OST_BASE_U_VIRTUAL;
	volatile XLLP_INTC_T	*v_pICReg = (volatile XLLP_INTC_T *)INTC_BASE_U_VIRTUAL;


	if((v_pOSTReg != NULL)&&(v_pICReg != NULL))
	{
		v_pOSTReg->osmr3 = v_pOSTReg->oscr0 + (OSCR0_TICKS_1MS * count);
		TIMER_M3_INT_EN(v_pOSTReg->oier);
		INTC_M3_INT_EN(v_pICReg->icmr);
		TIMER_M3_INT_CLR(v_pOSTReg->ossr);	
	}

    lpWriteDebugStringFunc(TEXT("StartDVMTimer Exit...\r\n"));
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -