Ejemplo n.º 1
0
void ADC_Init(void)
{
#if (!defined(DRV_ADC_NOT_EXIST)) && (!defined(DRV_ADC_MODEM_SIDE))

#if !defined(__DRV_SUPPORT_LPWR__)
   ADCSM_handler = L1SM_GetHandle();
#endif //#if !defined(__DRV_SUPPORT_LPWR__)
#if defined(DRV_ADC_TDMA_TIME)
   adc_tdma_time_setup(0,6000);
   #ifndef DRV_ADC_NO_TEST_DACMON
   DRV_ADC_WriteReg(AUXADC_CON,(AUXADC_CON_AUTOCLR0|AUXADC_CON_AUTOCLR1|AUXADC_CON_PUWAIT_EN|AUXADC_CON_TESTDACMON|0x0018));
   #endif // #ifndef DRV_ADC_NO_TEST_DACMON
   #if defined(DRV_ADC_SW_RESET)
   DRV_ADC_WriteReg(AUXADC_CON,(AUXADC_CON_AUTOCLR0|AUXADC_CON_AUTOCLR1|AUXADC_CON_PUWAIT_EN));
   #endif // #if defined(DRV_ADC_SW_RESET)

   #ifdef DRV_ADC_NO_PUWAIT_EN
   DRV_ADC_ClearBits(AUXADC_CON,AUXADC_CON_PUWAIT_EN);
   #endif

#if defined(DRV_ADC_DELAY_FOR_ADCCAP )
	/* AuxADC sampling period control */
	//DRV_ADC_SetBits(AUX_CON2,0x0064);	//delay 25us
	DRV_ADC_SetData(AUXADC_SPL_NUM,AUXADC_SPL_NUM_MASK,0x64<<AUXADC_SPL_NUM_SHIFT);
#endif
   
   #if defined(DRV_ADC_BIAS_CURRENT_ENLARGE)
   {
   	ECO_VERSION MT6276ipVersion = INT_ecoVersion();
	if(ECO_E2 == MT6276ipVersion)
	{
		DRV_ADC_WriteReg((MIX_ABB_base + 0x0B00),0x0022);	//AUX_CON0
	}	
   }
   #endif
	
#ifndef DRV_ADC_NO_ADC_DEF_CONFIG

#if defined(DRV_AUX_AC_CON_DEF_F)
   /*AUX_AC_CON*/
   DRV_ADC_WriteReg(0x80500700,0x00f);
#endif   
#if defined(DRV_AUX_AC_CON_DEF_0)
   /*AUX_AC_CON*/
   DRV_ADC_WriteReg(0x80500700,0x0);
#endif   

#if defined(DRV_AUX_AC_CON_DEF_X)
   /*AUX_AC_CON*/
   if(DRV_ADC_Reg(0x80500004)==0x8c01)
   {      
      DRV_ADC_WriteReg(0x80500700,0xf);
   } 
   else if(DRV_ADC_Reg(0x80500004)==0x8d00)
   {
      DRV_ADC_WriteReg(0x80500700,0x0);
   }
   else if(DRV_ADC_Reg(0x80500004)==0x8d01)
   {
      DRV_ADC_WriteReg(0x80500700,0x0);
   }
         
#endif   /*DRV_AUX_AC_CON_DEF_X*/

#endif // #ifndef DRV_ADC_NO_ADC_DEF_CONFIG

#endif   /*DRV_ADC_TDMA_TIME*/

#endif // #if (!defined(DRV_ADC_NOT_EXIST)) && (!defined(DRV_ADC_MODEM_SIDE))
}
DCL_STATUS DclHADC_Control(DCL_HANDLE handle, DCL_CTRL_CMD cmd, DCL_CTRL_DATA_T *data)
{
	switch (cmd)
	{
		case ADC_CMD_IMM_MEASURE:
		{
			ADC_CTRL_IMM_MEASURE_T  *prIMMMeasure;
			prIMMMeasure = &(data->rADCImmMeasure);
	
			if (!dcl_hadc_power_state){
				ASSERT(0);
				return STATUS_FAIL;
			}

			prIMMMeasure->u2ADCValue = ADC_IMM_Data(prIMMMeasure->u2Channel);
			return STATUS_OK;
		}
		case ADC_CMD_SYNC_MEASURE:
		{
			ADC_CTRL_SYNC_MEASURE_T  *prSYNCMeasure;
			prSYNCMeasure = &(data->rADCSyncMeasure);

			if (!dcl_hadc_power_state){
				ASSERT(0);
				return STATUS_FAIL;
			}

			prSYNCMeasure->u2ADCValue = ADC_SYNC_Data(prSYNCMeasure->u2Channel);
			return STATUS_OK;
		}
		case ADC_CMD_TDMA_SYNC_SETUP:
		{
                        #if defined(DRV_ADC_FULL_FUNC)
			ADC_CTRL_TDMA_SYNC_SETUP_T  *prTDMASyncSetup;
			prTDMASyncSetup = &(data->rADCTDMASyncSetup);
			adc_tdma_time_setup(prTDMASyncSetup->u2Event0, prTDMASyncSetup->u2Event1);
			return STATUS_OK;
			#else // #if defined(DRV_ADC_FULL_FUNC)
			
			// Not supported
			return STATUS_INVALID_CMD;
			#endif
		}
		case ADC_CMD_POWER:
		{
			ADC_CTRL_POWER_T  *prPower;
			prPower = &(data->rADCPower);
			if (prPower->fgEnable == DCL_TRUE){
				// Enable ADC power
				adc_pwrdown_disable();
				dcl_hadc_power_state = KAL_TRUE;
			}else{
				// Disable ADC power
				dcl_hadc_power_state = KAL_FALSE;
				adc_pwrdown_enable();
			}
			return STATUS_OK;
		}
		case ADC_CMD_GET_DATA_2_META:
		{
			ADC_CTRL_GET_DATA_2_META_T  *prGetData2Meta;
			prGetData2Meta = &(data->rADCGetData2Meta);
			
			prGetData2Meta->u4ADCData = ADC_GetData2Meta(prGetData2Meta->u1Channel, prGetData2Meta->u2MeaCount);
			return STATUS_OK;
		}
		case ADC_CMD_GET_DATA:
		{
			ADC_CTRL_GET_DATA_T  *prGetData;
			prGetData = &(data->rADCGetData);
			
			prGetData->u4ADCData = ADC_GetData(prGetData->u1Channel);
			return STATUS_OK;
		}
		case ADC_CMD_GET_META_DATA:
		{
			ADC_CTRL_GET_META_DATA_T  *prGetMetaData;
			prGetMetaData = &(data->rADCGetMetaData);
			
			prGetMetaData->u4ADCData = ADC_GetMeaData(prGetMetaData->u1Channel, prGetMetaData->u2MeaCount);
			return STATUS_OK;
		}
		case ADC_CMD_GET_MAX_PHYSICAL_CH:
		{
			ADC_CTRL_GET_MAX_PHYSICAL_CH_T  *prGetMaxPhyCh;
			prGetMaxPhyCh = &(data->rADCGetMaxPhyCh);
			
			prGetMaxPhyCh->u4Adc_max_ch = ADC_MAX_CHANNEL;
			return STATUS_OK;
		}
		case ADC_CMD_GET_IMM_DATA_ON_BOOTING:
		{
			ADC_CTRL_GET_IMM_DATA_ON_BOOTING_T  *prGetImmDataOnBooting;
			prGetImmDataOnBooting = &(data->rGetImmDataOnBooting);
	
			ADC_IMM_Data_on_Booting((kal_uint32)prGetImmDataOnBooting->u4Channel, (kal_uint32)prGetImmDataOnBooting->u4MeaCount, (kal_uint16 *)prGetImmDataOnBooting->u2ADCData);
			return STATUS_OK;
		}        
		default:
			return STATUS_INVALID_CMD;
	}
	//return STATUS_FAIL;
}