コード例 #1
0
ファイル: bmt_utility.c プロジェクト: WayWingsDev/testmywatch
/*
* FUNCTION
*	   bmt_get_adc_channel_voltage
*
* DESCRIPTION                                                           
*   	This function is used to obtain the Battery voltage of specific channel
*
* CALLS  
*
* PARAMETERS
*	   ch: specific channel
*	   voltage: pointer for read the voltage
*	
* RETURNS
*	   KAL_FALSE: invalid channel
*	   KAL_TRUE:  finish the measurement
*
* GLOBALS AFFECTED
*     None
*/
kal_bool bmt_get_adc_channel_voltage(DCL_ADC_CHANNEL_TYPE_ENUM ch, kal_uint32 *voltage)
{
	DCL_HANDLE adc_handle;
   	ADC_CTRL_GET_PHYSICAL_CHANNEL_T adc_get_channel;
	ADC_CTRL_GET_DATA_T adc_data;
	ADC_CTRL_TRANSFORM_INTO_VOLT_T adcTransV;

	if(ch > DCL_VCHARGER_ADC_CHANNEL)
		return KAL_FALSE;  
   
   	adc_handle = DclSADC_Open(DCL_ADC, FLAGS_NONE);
   	if(adc_handle == DCL_HANDLE_INVALID)
   	{
    	ASSERT(0);   
   	}
	
   	adc_get_channel.u2AdcName = ch;
   	DclSADC_Control(adc_handle, ADC_CMD_GET_CHANNEL, (DCL_CTRL_DATA_T *)&adc_get_channel);     

	adc_data.u1Channel = adc_get_channel.u1AdcPhyCh;
	DclHADC_Control(adc_handle, ADC_CMD_GET_DATA,(DCL_CTRL_DATA_T *)&adc_data);

	adcTransV.u1AdcPhyCh = adc_get_channel.u1AdcPhyCh;
	adcTransV.d8AdcValue = adc_data.u4ADCData;
	DclSADC_Control(adc_handle, ADC_CMD_TRANSFORM_INTO_VOLT, (DCL_CTRL_DATA_T *)&adcTransV);
	
	*voltage = adcTransV.u4Volt;
	
    DclSADC_Close(adc_handle);
	return KAL_TRUE;
}
コード例 #2
0
//called by drv_init_phase1
void Dcl_Chr_Det_reg_charger_usb_eint(void)
{

#if !defined (__CHARGER_USB_DETECT_WIHT_ONE_EINT__)
#if defined(PMIC_FIXED_CHR_EINT)
   gCHRDET_EINT_NO = PMIC_CHR_EINT_PIN;
#else
   gCHRDET_EINT_NO = custom_eint_get_channel(chrdet_eint_chann);
#endif

   #if defined(__USB_ENABLE__)
   gUSB_EINT_NO = custom_eint_get_channel(usb_eint_chann);
   #endif
#endif

#ifdef __CHARGER_USB_DETECT_WIHT_ONE_EINT__
#if defined(PMIC_FIXED_CHR_EINT)
   chr_usb_detect.chr_usb_eint = PMIC_CHR_EINT_PIN;
#else
   chr_usb_detect.chr_usb_eint = custom_eint_get_channel(chr_usb_eint_chann);
#endif
#if defined(PMIC_CHR_USB_DETECT_THROUGH_ADC)
{
   DCL_HANDLE adc_handle;
   ADC_CTRL_GET_PHYSICAL_CHANNEL_T adc_ch;

   adc_handle = DclSADC_Open(DCL_ADC, FLAGS_NONE);
   adc_ch.u2AdcName = DCL_CHR_USB_ADC_CHANNEL;
   DclSADC_Control(adc_handle, ADC_CMD_GET_CHANNEL, (DCL_CTRL_DATA_T *)&adc_ch);
   chr_usb_detect.chr_usb_adc = adc_ch.u1AdcPhyCh;
   chr_usb_detect.chr_usb_volt = bmt_get_chr_usb_detect_volt();
}
#endif   
#endif
}
コード例 #3
0
ファイル: bmt_utility.c プロジェクト: WayWingsDev/testmywatch
static void bmt_charging_timer_set_by_ADC_sche(DCL_UINT32 *timer_period, DCL_UINT8 *timer_count)
{
	  DCL_STATUS adc_status;
	  ADC_CTRL_MODIFY_PARAM_T adc_para; 
	
	  adc_para.u4Period =  *timer_period;
	  adc_para.u1EvaluateCount = *timer_count;	

	  adc_status = DclSADC_Control(bmt_adc_handle, ADC_CMD_MODIFY_PARAM, (DCL_CTRL_DATA_T *)&adc_para);
	  if(adc_status != STATUS_OK)
	  {
			ASSERT(0);
	  }   	
	 
	  adc_status = DclSADC_Control(bmt_adc_handle, ADC_CMD_START_MEASURE, NULL);
	  if(adc_status != STATUS_OK)
	  {
			ASSERT(0);  		
	  }	      

}
コード例 #4
0
ファイル: bmt_utility.c プロジェクト: WayWingsDev/testmywatch
kal_int32 bmt_change_Voltage_To_ISense(DCL_UINT32 TransformVolt)
{
	DCL_HANDLE dcl_adc_handle;
	ADC_CTRL_TRANSFORM_INTO_CURR_T rTransformCurr;

	dcl_adc_handle = DclSADC_Open(DCL_ADC, FLAGS_NONE);
	rTransformCurr.u4Volt = TransformVolt;
	DclSADC_Control(dcl_adc_handle, ADC_CMD_TRANSFORM_INTO_CURR, (DCL_CTRL_DATA_T *)&rTransformCurr);
	DclSADC_Close(dcl_adc_handle);

	return 	(kal_int32)rTransformCurr.u4Curr;
}
コード例 #5
0
ファイル: bmt_utility.c プロジェクト: WayWingsDev/testmywatch
kal_int32 bmt_change_VBatTmp_To_BatTmp(kal_int32 VbatTmp)
{
	DCL_HANDLE dcl_adc_handle;
	ADC_CTRL_TRANSFORM_INTO_TEMP_T adc_get_vbattmp;
		
	adc_get_vbattmp.u4Volt = VbatTmp;
	dcl_adc_handle = DclSADC_Open(DCL_ADC, FLAGS_NONE);
	DclSADC_Control(dcl_adc_handle, ADC_CMD_TRANSFORM_INTO_TEMP, (DCL_CTRL_DATA_T *)&adc_get_vbattmp);	   
	DclSADC_Close(dcl_adc_handle);

	return (kal_int32)adc_get_vbattmp.u4Temp;
}
コード例 #6
0
ファイル: bmtutil.c プロジェクト: WayWingsDev/testmywatch
/*
* FUNCTION
*	   bmt_timer_config
*
* DESCRIPTION                                                           
*   	This function is to configure the measure timer
*
* CALLS  
*
* PARAMETERS
*	   time: on/off time interval. (1 tick = 4.615ms)
*	
* RETURNS
*	   None
*
* GLOBALS AFFECTED
*     None
*/
void bmt_timer_config(kal_uint32 time) /*time unit is second*/
{
   kal_uint32  adc_bmt_tick;
   DCL_STATUS adc_status;
  
   ADC_CTRL_MODIFY_PARAM_T adc_para;   	
   
#if defined(__DRV_BMT_ULTRA_LOW_COST_CHARGER__)
#if defined(DRV_BMT_HW_PRECC_WORKAROUND)
   if(bmt_frequently_check_on_state() || bmt_frequently_check_off_state())
#else
   if(bmt_frequently_check_on_state())
#endif // End of #if defined(DRV_BMT_HW_PRECC_WORKAROUND)
   {
      time = 45; // 200ms/4.615 ~= 45 frames
   }
#endif //#if defined(__DRV_BMT_ULTRA_LOW_COST_CHARGER__)
	adc_bmt_tick = (kal_uint32)(time/BMT_EVALUATE_VALUE);
	adc_bmt_tick++;
	
 	adc_para.u4Period = adc_bmt_tick;
	adc_para.u1EvaluateCount = BMT_EVALUATE_VALUE;

	adc_status = DclSADC_Control(bmt_adc_handle, ADC_CMD_MODIFY_PARAM, (DCL_CTRL_DATA_T *)&adc_para);
	if(adc_status != STATUS_OK)
	{
		ASSERT(0);
	}
	
	adc_status = DclSADC_Control(bmt_adc_handle, ADC_CMD_START_MEASURE, NULL);
	if(adc_status != STATUS_OK)
	{
		ASSERT(0);  		
	}				   

}
コード例 #7
0
ファイル: bmtutil.c プロジェクト: WayWingsDev/testmywatch
/*
* FUNCTION
*	   bmt_charge_end
*
* DESCRIPTION                                                           
*   	This function is to stop charging when charger is plugged out 
*     or serious error in charging stage.
*
* CALLS  
*
* PARAMETERS
*	   None
*	
* RETURNS
*	   None
*
* GLOBALS AFFECTED
*     None
*/
void bmt_charge_end(void)
{
#if defined(__EVB__) && defined(__MTK_INTERNAL__)
/* under construction !*/
#elif defined(__DRV_BMT_NO_CHARGING__)
   return;
#else//#if defined(__EVB__)
    DCL_STATUS adc_status;
//#ifdef __DRV_BMT_SW_POLLING_CHARGER_OV__
//	kal_cancel_timer(bmt_sw_polling_timerId);
//#endif //#ifdef __DRV_BMT_SW_POLLING_CHARGER_OV__

#if defined(__DRV_BMT_ULTRA_LOW_COST_CHARGER__)
	bmt_chr_force_enable(KAL_FALSE);
#endif
	BMT.pmictrl_state = PMIC_CHARGEOFF;
   	BMT.VBAT_UEM= VBAT_UEM_CHR_OUT_FIRST;
	BMT_Charge(KAL_FALSE);
		adc_status = DclSADC_Control(bmt_adc_handle, ADC_CMD_STOP_MEASURE, NULL);
		if(adc_status != STATUS_OK)
		{
			ASSERT(0);
		}

	bmt_stop_stoptimer();
	stack_stop_timer(&ChargeTimeout_timer);
#ifdef __BMT_CHARGE_GUARD_TIME__
	bmt_stop_guardtimer();
#endif
#if defined(__DRV_BMT_ESTIMATIVE_TIMER_ON_TOPOFF__)
	bmt_stop_estimativetimer();
#endif //#if defined(__DRV_BMT_ESTIMATIVE_TIMER_ON_TOPOFF__)
	drv_trace1(TRACE_GROUP_10, BMT_SAFETY_TIMER_STOP_TRC, BMT_TOTAL_CHARGE_TIME);
   SaftyTimer_Flag = BMT_SAFETY_TIMER_OFF; 
//   #ifdef MTK_SLEEP_ENABLE
//   L1SM_SleepEnable(bmt_sm_handle);
//   #endif

	bmt_enable_sleepmode(KAL_TRUE);
   
   #if defined(PMIC_CHARGE_WDT)  // Defined in pmic_features.h
   bmt_charge_enable_wdt(KAL_FALSE);
   #endif // #if defined(PMIC_CHARGE_WDT)
   
   drv_trace0(TRACE_GROUP_10, BMT_CHARGING_END_TRC);
 //  DclSADC_Close(adc_handle);
#endif//#if defined(__EVB__)
}
コード例 #8
0
ファイル: bmt_utility.c プロジェクト: WayWingsDev/testmywatch
/*
* FUNCTION
*		bmt_ChrStop
*
* DESCRIPTION																			  
*		This function is called if charge is complete and run after 30 min
*
* CALLS  
*
* PARAMETERS
*		None
*	
* RETURNS
*		None
*
*/
static void bmt_ChrStop(void)  /*30 min*/
{
	DCL_STATUS adc_status;
	drv_trace0(TRACE_STATE, BMT_MEASURE_STOP_TRC);
	bmt_CtrlCharge((kal_uint8)KAL_FALSE);	//Stop Charge!!
	BMT.highfull = 1;
	
	adc_status = DclSADC_Control(bmt_adc_handle, ADC_CMD_STOP_MEASURE, NULL);
	if(adc_status != STATUS_OK)
	{
		ASSERT(0);
	}
	
	bmt_timer_config(bmt_charging_para.BATFULL_TOFF*CHARGING_TIME_UNIT);

}
コード例 #9
0
ファイル: bmtutil.c プロジェクト: WayWingsDev/testmywatch
/*
* FUNCTION
*	   bmt_measure_complete_vbatemp
*
* DESCRIPTION                                                           
*   	This function is the callback function when visense is measured done.
*
* CALLS  
*
* PARAMETERS
*	   handle: logical channel id.
*	
* RETURNS
*	   None
*
* GLOBALS AFFECTED
*     None
*/
void bmt_measure_complete(DCL_INT32 handle, DCL_INT32 *volt_array_result, DCL_DOUBLE *adc_array_result)
{
   	#ifdef BMT_DEBUG
      //dbg_printWithTime("bmt_measure_complete_vbat\r\n");	
	#endif
	DCL_STATUS adc_status;
	kal_uint32 i;
		
	adc_status = DclSADC_Control(handle, ADC_CMD_STOP_MEASURE, NULL);
	if(adc_status != STATUS_OK)
	{
		ASSERT(0);
	}   

	for(i=0;i<BMT_ADC_MAX_CHANNEL_TOTAL;i++)
	{
		BMT_VOL_RESULT[i] = *(volt_array_result+i);
		BMT_ADC_RESULT[i] = *(adc_array_result+i);
	}

	bmt_measure_done();
}
コード例 #10
0
ファイル: bmtutil.c プロジェクト: WayWingsDev/testmywatch
/*
* FUNCTION
*	   BMT_Current_Voltage
*
* DESCRIPTION                                                           
*   	This function is used to obtain the Battery voltage of specific channel
*
* CALLS  
*
* PARAMETERS
*	   ch: specific channel
*	   voltage: pointer for read the voltage
*	
* RETURNS
*	   KAL_FALSE: invalid channel
*	   KAL_TRUE:  finish the measurement
*
* GLOBALS AFFECTED
*     None
*/
kal_bool BMT_Current_Voltage(DCL_ADC_CHANNEL_TYPE_ENUM ch, kal_uint32 *voltage, double *adc_value)
{
	kal_uint8 adc_channel;
   	DCL_HANDLE adc_handle;
   	ADC_CTRL_GET_PHYSICAL_CHANNEL_T adc_ch;

	if(ch > DCL_VCHARGER_ADC_CHANNEL)
		return KAL_FALSE;  
   
   	adc_handle = DclSADC_Open(DCL_ADC, FLAGS_NONE);
   	if(adc_handle == DCL_HANDLE_INVALID)
   	{
    	ASSERT(0);   
   	}
   	adc_ch.u2AdcName = ch;
   	DclSADC_Control(adc_handle, ADC_CMD_GET_CHANNEL, (DCL_CTRL_DATA_T *)&adc_ch);     

	adc_channel = adc_ch.u1AdcPhyCh;
	*voltage = adc_measureVoltage(adc_channel, adc_value);
    DclSADC_Close(adc_handle);
	return KAL_TRUE;
}
コード例 #11
0
ファイル: bmt_utility.c プロジェクト: WayWingsDev/testmywatch
static void bmt_internal_adc_init()
{
   ADC_CTRL_GET_PHYSICAL_CHANNEL_T adc_ch;
   ADC_CTRL_CREATE_OBJECT_T adc_create;   
   DCL_STATUS adc_status;
   ADC_CTRL_REGISTER_MEASURE_CB_T registerMeasCB;
   DCL_MULTI_CHANNEL_PARA_T adc_multi_channel_para;

   bmt_adc_handle = DclSADC_Open(DCL_ADC, FLAGS_NONE);
   if(bmt_adc_handle == DCL_HANDLE_INVALID)
   {
      ASSERT(0);   
   }

   adc_ch.u2AdcName = DCL_VBAT_ADC_CHANNEL;
   DclSADC_Control(bmt_adc_handle, ADC_CMD_GET_CHANNEL, (DCL_CTRL_DATA_T *)&adc_ch);       
   bmt_multi_channel[BMT_ADC_VBAT] = adc_ch.u1AdcPhyCh;


   adc_ch.u2AdcName = DCL_VISENSE_ADC_CHANNEL;
   DclSADC_Control(bmt_adc_handle, ADC_CMD_GET_CHANNEL, (DCL_CTRL_DATA_T *)&adc_ch);    
   bmt_multi_channel[BMT_ADC_VISENSE] = adc_ch.u1AdcPhyCh;	


   adc_ch.u2AdcName = DCL_VBATTMP_ADC_CHANNEL;
   DclSADC_Control(bmt_adc_handle, ADC_CMD_GET_CHANNEL, (DCL_CTRL_DATA_T *)&adc_ch);      
   bmt_multi_channel[BMT_ADC_VBATTMP] = adc_ch.u1AdcPhyCh;	   


   adc_ch.u2AdcName = DCL_VCHARGER_ADC_CHANNEL;
   DclSADC_Control(bmt_adc_handle, ADC_CMD_GET_CHANNEL, (DCL_CTRL_DATA_T *)&adc_ch);      
   bmt_multi_channel[BMT_ADC_VCHARGER] = adc_ch.u1AdcPhyCh;	

   adc_create.u4Period = 10; // Measurement period (Uint is in Tick)
   adc_create.u1OwnerId = MOD_BMT; // Indicate the module to for ADC driver to notify the result
   //adc_create.u1AdcChannel = ADC_VBAT_channel; // To be measured physical ADC channel
   adc_create.u1EvaluateCount = 10; // Measurement count
   adc_create.fgSendPrimitive = KAL_FALSE; // Whether to send message to owner module or NOT
   adc_status = DclSADC_Control(bmt_adc_handle, ADC_CMD_CREATE_OBJECT, (DCL_CTRL_DATA_T *)&adc_create);
   if(adc_status != STATUS_OK)
   {
		ASSERT(0);   
   }
 
   registerMeasCB.pfMeasure_cb = adc_sche_measure;	
   adc_status = DclSADC_Control(bmt_adc_handle, ADC_CMD_REGISTER_MEASURE_CB, (DCL_CTRL_DATA_T *)&registerMeasCB);	
   if(adc_status != STATUS_OK)
   {
	   ASSERT(0);
   }	   

   adc_multi_channel_para.bEnable = KAL_TRUE;
   adc_multi_channel_para.u4ADC_ch_number = bmt_multi_channel;
   adc_multi_channel_para.u4Adc_max_ch_number = BMT_ADC_MAX_CHANNEL_TOTAL;
   adc_multi_channel_para.complete_multi_cb = bmt_measure_complete;
   adc_status = DclSADC_Control(bmt_adc_handle, ADC_CMD_SET_MULTI_CHANNEL_READ, (DCL_CTRL_DATA_T *)&adc_multi_channel_para);
   if(adc_status != STATUS_OK)
   {
	  ASSERT(0);  		
   }
}
コード例 #12
0
ファイル: bmtutil.c プロジェクト: WayWingsDev/testmywatch
/*
* FUNCTION
*	   bmt_charge_start
*
* DESCRIPTION                                                           
*   	This function is to start charging algorithm.
*
* CALLS  
*
* PARAMETERS
*	   None
*	
* RETURNS
*	   None
*
* GLOBALS AFFECTED
*     None
*/
void bmt_charge_start(void)
{
#if defined(__EVB__) && defined(__MTK_INTERNAL__)
/* under construction !*/
#elif defined(__DRV_BMT_NO_CHARGING__)
   return;
#else //#if defined(__EVB__)
  
#if defined(__DRV_BMT_PRECHARGE_TO_FULL_DIRECTLY__)
	double adc;
#endif //#if defined(__DRV_BMT_PRECHARGE_TO_FULL_DIRECTLY__)
    DCL_STATUS adc_status;
	ADC_CTRL_MODIFY_PARAM_T adc_para;   
#if defined(MT6236) || defined(MT6252)
   
  	PMU_CTRL_CHR_SET_CHR_CURRENT set_chr_current;
#endif

//#ifdef __DRV_BMT_SW_POLLING_CHARGER_OV__
//	kal_set_timer(bmt_sw_polling_timerId, (kal_timer_func_ptr)bmt_sw_polling_ov, NULL,43 ,	0);
//#endif //#ifdef __DRV_BMT_SW_POLLING_CHARGER_OV__


   BMT_Charge(KAL_FALSE);
   BMT.pmictrl_state = PMIC_CHARGEOFF;
#if defined(__DRV_BMT_PRECHARGE_TO_FULL_DIRECTLY__)
	if(g_battery_pre_voltage == 0)
	  BMT_Current_Voltage(DCL_VBAT_ADC_CHANNEL, &g_battery_pre_voltage,&adc);
	BMT.bat_state = CHR_PRE_FULL_CHECK;
#else //defined(__DRV_BMT_PRECHARGE_TO_FULL_DIRECTLY__)
   BMT.bat_state = CHR_PRE;
#endif //defined(__DRV_BMT_PRECHARGE_TO_FULL_DIRECTLY__)
   BMT.VBAT_UEM= VBAT_UEM_CHR_IN_FISRT;
   low_charger_count = 0;
   low_current_count = 0;
   low_temper_count = 0;
   over_temper_count = 0;
#if defined(DRV_BMT_HW_PRECC_WORKAROUND)
    SW_Workaround_Flag = KAL_TRUE;
    HW_Plug_Status = bmt_chr_uninit; 
    Manual_Disable_Charge_Flag = KAL_FALSE;
#endif
#if defined(DRV_BMT_HIGH_VCHG_ADAPTIVE_CHARGE_CURRENT_SUPPORT)
   First_Time_Charge_Enable = KAL_TRUE;
   bmt_high_vchg_current = 0xFFFFFFF;
   Pre_VCharge_AVG = 0;
   Cur_VCharge_MAX = 0;
#endif

   
	bmt_enable_sleepmode(KAL_FALSE);

 //  #ifdef MTK_SLEEP_ENABLE
 //  L1SM_SleepDisable(bmt_sm_handle);
 //  #endif
		

      adc_para.u4Period = 1;
	  adc_para.u1EvaluateCount = 1;
	  adc_status = DclSADC_Control(bmt_adc_handle, ADC_CMD_MODIFY_PARAM, (DCL_CTRL_DATA_T *)&adc_para);
	  if(adc_status != STATUS_OK)
	  {
			ASSERT(0);
	  }   	
	 
	  adc_status = DclSADC_Control(bmt_adc_handle, ADC_CMD_START_MEASURE, NULL);
	  if(adc_status != STATUS_OK)
	  {
			ASSERT(0);  		
	  }	      
	
#ifdef __BMT_CHARGE_GUARD_TIME__
	bmt_set_guardtimer(KAL_TICKS_1_MIN*BMT_CHARGE_GUARD_TIME_PERIOD);
	drv_trace2(TRACE_GROUP_10, BMT_SAFETY_AND_GUARD_TIMER_START_TRC, BMT_TOTAL_CHARGE_TIME, BMT_CHARGE_GUARD_TIME_PERIOD);
#else // __BMT_CHARGE_GUARD_TIME__

#if defined(DRV_BMT_HIGH_VCHG_ADAPTIVE_CHARGE_CURRENT_SUPPORT)
    bmt_safety_timer_config = KAL_FALSE;
#else
	stack_start_timer(&ChargeTimeout_timer, 0, KAL_TICKS_1_MIN*BMT_TOTAL_CHARGE_TIME);
	drv_trace1(TRACE_GROUP_10, BMT_SAFETY_TIMER_START_TRC, BMT_TOTAL_CHARGE_TIME);
	SaftyTimer_Flag = BMT_SAFETY_TIMER_ON; 
#endif //#if defined(DRV_BMT_HIGH_VCHG_ADAPTIVE_CHARGE_CURRENT_SUPPORT)

#endif // __BMT_CHARGE_GUARD_TIME__
	
   

#if defined(MT6236)  || defined(MT6252)
    
    set_chr_current.current = PMU_CHARGE_CURRENT_200_00_MA; // Pre-CC 200mA
    DclPMU_Control(bmt_PmuHandler, CHR_SET_CHR_CURRENT, (DCL_CTRL_DATA_T *)&set_chr_current);
                  
#else   
   bmt_set_chr_current();
#endif
   
   #if defined(PMIC_CHARGE_WDT)  // Defined in pmic_features.h
   bmt_charge_enable_wdt(KAL_TRUE);
   #endif // #if defined(PMIC_CHARGE_WDT)
   
   drv_trace0(TRACE_GROUP_10, BMT_CHARGING_START_TRC);
#endif//#if defined(__EVB__)
}
コード例 #13
0
ファイル: bmtutil.c プロジェクト: WayWingsDev/testmywatch
/*if add more measure parameters, just need modify bmt_adc_init*/
void bmt_adc_init(void)
{
   ADC_CTRL_GET_PHYSICAL_CHANNEL_T adc_ch;
   ADC_CTRL_CREATE_OBJECT_T adc_create;   
   DCL_STATUS adc_status;
   ADC_CTRL_REGISTER_MEASURE_CB_T registerMeasCB;
   DCL_MULTI_CHANNEL_PARA_T adc_multi_channel_para;
	
   #ifdef MTK_SLEEP_ENABLE
   bmt_sm_handle = L1SM_GetHandle();
   #endif
   bmt_stop_timer_init();
#ifdef __BMT_CHARGE_GUARD_TIME__
   bmt_guardtimer_init();
#endif
#if defined(__DRV_BMT_ESTIMATIVE_TIMER_ON_TOPOFF__)
		bmt_estimativetimer_init();
#endif //#if defined(__DRV_BMT_ESTIMATIVE_TIMER_ON_TOPOFF__)

   BMT.VBAT_UEM = VBAT_UEM_CHR_OUT;
   /*to get customized ADC channel*/

  
   bmt_adc_handle = DclSADC_Open(DCL_ADC, FLAGS_NONE);
   if(bmt_adc_handle == DCL_HANDLE_INVALID)
   {
      ASSERT(0);   
   }

   adc_ch.u2AdcName = DCL_VBAT_ADC_CHANNEL;
   DclSADC_Control(bmt_adc_handle, ADC_CMD_GET_CHANNEL, (DCL_CTRL_DATA_T *)&adc_ch);       
   bmt_multi_channel[BMT_ADC_VBAT] = adc_ch.u1AdcPhyCh;


   adc_ch.u2AdcName = DCL_VISENSE_ADC_CHANNEL;
   DclSADC_Control(bmt_adc_handle, ADC_CMD_GET_CHANNEL, (DCL_CTRL_DATA_T *)&adc_ch);    
   bmt_multi_channel[BMT_ADC_VISENSE] = adc_ch.u1AdcPhyCh;	


   adc_ch.u2AdcName = DCL_VBATTMP_ADC_CHANNEL;
   DclSADC_Control(bmt_adc_handle, ADC_CMD_GET_CHANNEL, (DCL_CTRL_DATA_T *)&adc_ch);      
   bmt_multi_channel[BMT_ADC_VBATTMP] = adc_ch.u1AdcPhyCh;	   


   adc_ch.u2AdcName = DCL_VCHARGER_ADC_CHANNEL;
   DclSADC_Control(bmt_adc_handle, ADC_CMD_GET_CHANNEL, (DCL_CTRL_DATA_T *)&adc_ch);      
   bmt_multi_channel[BMT_ADC_VCHARGER] = adc_ch.u1AdcPhyCh;	

   adc_create.u4Period = 10; // Measurement period (Uint is in Tick)
   adc_create.u1OwnerId = MOD_BMT; // Indicate the module to for ADC driver to notify the result
   //adc_create.u1AdcChannel = ADC_VBAT_channel; // To be measured physical ADC channel
   adc_create.u1EvaluateCount = BMT_EVALUATE_VALUE; // Measurement count
   adc_create.fgSendPrimitive = KAL_FALSE; // Whether to send message to owner module or NOT
   adc_status = DclSADC_Control(bmt_adc_handle, ADC_CMD_CREATE_OBJECT, (DCL_CTRL_DATA_T *)&adc_create);
   if(adc_status != STATUS_OK)
   {
		ASSERT(0);   
   }
 
   registerMeasCB.pfMeasure_cb = adc_sche_measure;	
   adc_status = DclSADC_Control(bmt_adc_handle, ADC_CMD_REGISTER_MEASURE_CB, (DCL_CTRL_DATA_T *)&registerMeasCB);	
   if(adc_status != STATUS_OK)
   {
	   ASSERT(0);
   }	   

   adc_multi_channel_para.bEnable = KAL_TRUE;
   adc_multi_channel_para.u4ADC_ch_number = bmt_multi_channel;
   adc_multi_channel_para.u4Adc_max_ch_number = BMT_ADC_MAX_CHANNEL_TOTAL;
   adc_multi_channel_para.complete_multi_cb = bmt_measure_complete;
   adc_status = DclSADC_Control(bmt_adc_handle, ADC_CMD_SET_MULTI_CHANNEL_READ, (DCL_CTRL_DATA_T *)&adc_multi_channel_para);
   if(adc_status != STATUS_OK)
   {
	  ASSERT(0);  		
   }

   
   #if defined(__DRV_BMT_PRECHARGE_TO_FULL_DIRECTLY__)
	   BMT_VbatInHISR_Init();
   #endif //#if defined(__DRV_BMT_PRECHARGE_TO_FULL_DIRECTLY__)
}
コード例 #14
0
ファイル: bmtutil.c プロジェクト: WayWingsDev/testmywatch
/*
* FUNCTION
*		BMT_ObtainBMTPHYSTAT
*
* DESCRIPTION																			  
*		This function is used to obtain the ADC measure result.
*	  Average the received Phy. data
*
* CALLS  
*
* PARAMETERS
*		Data: None
*	
* RETURNS
*		None
*
* GLOBALS AFFECTED
*	  None
*/
kal_bool BMT_ObtainBMTPHYSTAT(BATPHYStruct *BATPHYS)
{
#ifndef __BMT_NO_ISENSE_RESISTOR__    
	DCL_HANDLE dcl_adc_handle;
	ADC_CTRL_TRANSFORM_INTO_CURR_T rTransformCurr;
#endif    

#if defined(__DRV_BMT_ISENSE_OFFSET_COMPENSATION__)
	static kal_int32 ISense_Offset;
#endif

    drv_trace0(TRACE_GROUP_10, BMT_OBTAIN_PHY_STAT_TRC);
	BATPHYS->VBAT = BMT_VOL_RESULT[BMT_ADC_VBAT];
	drv_trace1(TRACE_GROUP_10, BMT_VBAT_TRC, BATPHYS->VBAT);
			
#ifndef __BMT_NO_ISENSE_RESISTOR__
	dcl_adc_handle = DclSADC_Open(DCL_ADC, FLAGS_NONE);

#if defined(__DRV_BMT_ISENSE_OFFSET_COMPENSATION__)
	if(BMT.pmictrl_state == PMIC_CHARGEOFF)
	{	
		ISense_Offset = BMT_VOL_RESULT[BMT_ADC_VISENSE] - BMT_VOL_RESULT[BMT_ADC_VBAT];
	}
	BATPHYS->ISense_Offset = ISense_Offset;
	
	rTransformCurr.u4Volt = BMT_VOL_RESULT[BMT_ADC_VISENSE] - BMT_VOL_RESULT[BMT_ADC_VBAT]-BATPHYS->ISense_Offset;
#else
	rTransformCurr.u4Volt = BMT_VOL_RESULT[BMT_ADC_VISENSE] - BMT_VOL_RESULT[BMT_ADC_VBAT];
#endif
	DclSADC_Control(dcl_adc_handle, ADC_CMD_TRANSFORM_INTO_CURR, (DCL_CTRL_DATA_T *)&rTransformCurr);
	BATPHYS->ICHARGE = rTransformCurr.u4Curr;
	DclSADC_Close(dcl_adc_handle);

#if defined(__DRV_BMT_ISENSE_OFFSET_COMPENSATION__)
	drv_trace1(TRACE_GROUP_10, BMT_VSENSE_TRC, BMT_VOL_RESULT[BMT_ADC_VISENSE]);
	drv_trace1(TRACE_GROUP_10, BMT_ICHARGE_TRC, BATPHYS->ICHARGE);
	drv_trace1(TRACE_GROUP_10, BMT_VSENSE_VBAT_OFFSET_TRC, BATPHYS->ISense_Offset);
#else
	BATPHYS->ICHARGE -= bmt_charging_para->CurrOffset[BMT.call_state];
	drv_trace1(TRACE_GROUP_10, BMT_ICHARGE_TRC, BATPHYS->ICHARGE);
	if((BMT.pmictrl_state == PMIC_CHARGEOFF) && ((BATPHYS->ICHARGE + bmt_charging_para->CurrOffset[BMT.call_state]) > bmt_charging_para->ICHARGE_ON_LOW))
	{
		drv_trace1(TRACE_GROUP_10, BMT_ADC_CALIBRATION_FAIL_TRC, BATPHYS->ICHARGE + bmt_charging_para->CurrOffset[BMT.call_state]);
	}
#endif
#endif // #ifndef __BMT_NO_ISENSE_RESISTOR__
	
	if(bmt_charging_para->bmt_check_temp)
	{
		BATPHYS->BATTMP = BMT_VOL_RESULT[BMT_ADC_VBATTMP];
		drv_trace1(TRACE_GROUP_10, BMT_BATTMP_TRC, BATPHYS->BATTMP);
	}
	if(bmt_charging_para->bmt_check_charger)
	{
		BATPHYS->VCHARGER = BMT_VOL_RESULT[BMT_ADC_VCHARGER];
		drv_trace1(TRACE_GROUP_10, BMT_VCHARGER_TRC, BATPHYS->VCHARGER);
	}
			
	if ((BMT.pmictrl_state == PMIC_CHARGEOFF)  ||
		(BMT.pmictrl_state == PMIC_CHARGEON ) &&
		( (BMT.bat_state == CHR_TOPOFF) || (BMT.bat_state == CHR_BATFULL) ))
	{
		VBAT_OFF = BATPHYS->VBAT;
		ADCBAT_OFF = BMT_ADC_RESULT[BMT_ADC_VBAT];
	}
	return KAL_TRUE;
}
void FT_MISC_Operation(ilm_struct *ptrMsg)
{
    kal_wchar         wpath[128];
    FT_MISC_REQ       *p_req = (FT_MISC_REQ *)ptrMsg->local_para_ptr;
    FT_MISC_CNF       misc_cnf;
    memset(&misc_cnf, 0x0, sizeof(misc_cnf));
    peer_buff_struct  *peer_buff_ret = NULL;  // default value
    kal_char    *pdu_ptr = NULL;
    kal_uint16    pdu_length = 0;
    misc_cnf.type = p_req->type;
    misc_cnf.status = FT_CNF_FAIL;  // default value
    ft_gl_misc_token =  p_req->header.token;

    switch(p_req->type)
    {
        case FT_MISC_OP_GET_IMEI_LOC:
        {
            misc_cnf.result.m_u1IMEILoc = nvram_get_imei_type();
            misc_cnf.status = FT_CNF_OK;
            break;
        }
        case FT_MISC_OP_GET_IMEI_VALUE:
        {
            // check the record index (because tools before 0912 causes assertion)
            kal_uint16 rec_num = nvram_get_imei_record_num();
            if(p_req->cmd.m_u1RecordIndex < 1 || p_req->cmd.m_u1RecordIndex > rec_num)
            {
                // set the record index to 1 (the behavior will be confrom to that of target load before 0909)
                p_req->cmd.m_u1RecordIndex = 1;
            }
            if(KAL_TRUE == nvram_get_imei_value(NVRAM_EF_IMEI_IMEISV_SIZE,
                        misc_cnf.result.m_rIMEIData.buf, p_req->cmd.m_u1RecordIndex))
            {
                misc_cnf.result.m_rIMEIData.buf_len = NVRAM_EF_IMEI_IMEISV_SIZE;
                misc_cnf.status = FT_CNF_OK;
            }
            else
                misc_cnf.status = FT_CNF_FAIL;
            break;

        }
#if defined(__MTK_INTERNAL__)
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif  //#if defined(__MTK_INTERNAL__)
        case FT_MISC_OP_GET_IMEI_REC_NUM:
        {
            misc_cnf.result.m_u2IMEIRecords = nvram_get_imei_record_num();
            misc_cnf.status = FT_CNF_OK;
            break;
        }
        case FT_MISC_OP_VERIFY_TEMP_SML_FILE:
        {
            //kal_char  *pdu_ptr;
            //kal_uint16    pdu_length;
            kal_wchar *w_filepath;
            // get the file path from peer_buffer
            if(ptrMsg->peer_buff_ptr != NULL)
            {
                pdu_ptr = get_peer_buff_pdu( ptrMsg->peer_buff_ptr, &pdu_length );

                // cast to kal_wchar
                w_filepath = (kal_wchar *)pdu_ptr;

                misc_cnf.status = FT_CNF_OK;

                // ask nvram task to check the SML file
                if(NVRAM_IO_ERRNO_OK == nvram_validate_file(NVRAM_EF_SML_LID, w_filepath))
                    misc_cnf.result.m_u1VerifyResult = FT_SML_VALID;
                else
                    misc_cnf.result.m_u1VerifyResult = FT_SML_INVALID;

            }
            else  // peer buffer is null
            {
                misc_cnf.status = FT_CNF_FAIL;
                misc_cnf.result.m_u1VerifyResult = FT_SML_NO_FILENAME;
            }

            break;
        }
        case FT_MISC_OP_GET_CAL_INFO:
        {
            ft_misc_op_collect_cal_info(&misc_cnf);
            return;
        }
        case FT_MISC_OP_QUERY_NVRAM_FOLDER:
        {
            kal_uint16  length;
            kal_char* buf;
            kal_uint8 folder_total_amount = nvram_get_folder_total_amount();
            kal_int16 total_length = 0;
            kal_int8 i;
            misc_cnf.status = FT_CNF_OK;

            // allocate peer buffer
            if(NULL == peer_buff_ret)
            {//FT_MISC_MAX_FRAME_SIZE
                peer_buff_ret = construct_peer_buff(FT_MISC_MAX_FRAME_SIZE, 0, 0, TD_CTRL);
                if(NULL == peer_buff_ret)  return;

                peer_buff_ret->pdu_len = 0 ;
            }
            pdu_ptr = get_peer_buff_pdu( peer_buff_ret, &pdu_length );
            for(i = 0;i<folder_total_amount;i++)
            {
                buf = nvram_get_work_path(i);
                kal_wsprintf(wpath, "%s", buf);
                if(nvram_check_hidden_file(wpath, true))
                {
                    continue;
                }
                length = (strlen(buf)+1);
                kal_mem_cpy(pdu_ptr+pdu_length+total_length, (buf), length );
                *(pdu_ptr+pdu_length+total_length+length-1) = '?';
                total_length += length;
            }
            // update pdu_len
            peer_buff_ret->pdu_len += (total_length);


            break;
        }
        case FT_MISC_OP_VERIFY_NVRAM_ATTR_SETTING_COMPLETE:
        {
            kal_uint16 stop_index = custom_meta_check_must_backup_lid_array(p_req->cmd.m_bcheckImeiFlag);
            if(stop_index == custom_meta_get_check_lid_num()) // check successfully!
            {
                misc_cnf.status = FT_CNF_OK;
                misc_cnf.result.m_rNvramVerifyResult.m_stop_enum_value = custom_meta_get_enum_by_index(stop_index-1); // pass the imei_enum
                misc_cnf.result.m_rNvramVerifyResult.m_total_lid_num = custom_meta_get_check_lid_num();
                misc_cnf.result.m_rNvramVerifyResult.m_stop_index = stop_index;
            }
            else
            {
                misc_cnf.status = FT_CNF_FAIL;
                misc_cnf.result.m_rNvramVerifyResult.m_stop_enum_value = custom_meta_get_enum_by_index(stop_index);
                misc_cnf.result.m_rNvramVerifyResult.m_total_lid_num = custom_meta_get_check_lid_num();
                misc_cnf.result.m_rNvramVerifyResult.m_stop_index = stop_index;
            }
            break;
        }
        case FT_MISC_OP_ENABLE_PATH_LIMITION:
        case FT_MISC_OP_DISABLE_PATH_LIMITION:
        {
            ft_gl_path_check_flag = (p_req->type == FT_MISC_OP_ENABLE_PATH_LIMITION)?true:false;
            misc_cnf.status = FT_CNF_OK;
            break;
        }
        case FT_MISC_OP_GET_NVRAM_FOLDER_AMOUNT:
        {
            kal_uint8 i;
            misc_cnf.result.m_u1NVRAMFolderAmount = nvram_get_folder_total_amount();
            for(i = 0;i<nvram_get_folder_total_amount();i++)
            {
                kal_wsprintf(wpath, "%s", nvram_get_work_path(i));
                if(nvram_check_hidden_file(wpath, true))
                {
                    misc_cnf.result.m_u1NVRAMFolderAmount--;
                }
            }
            misc_cnf.status = FT_CNF_OK;

        }
        break;
#ifndef SIM_NOT_PRESENT
        case FT_MISC_OP_CHECK_SIM1_INSERTED:
        {
            // Send reset request to MOD_SIM
            ilm_struct  ilm_ptr;
            sim_reset_req_struct* ptr_loc_para;
            FT_ALLOC_OTHER_MSG(&ilm_ptr, sizeof(sim_reset_req_struct));
            ptr_loc_para = (sim_reset_req_struct*) (ilm_ptr.local_para_ptr);
            ptr_loc_para->src_id = 0xff;
            // set sim cmd type to global variable
            ft_gl_sim_cmd_type = FT_MISC_OP_CHECK_SIM1_INSERTED;
            FT_SEND_MSG(MOD_FT, MOD_SIM, PS_SIM_SAP, MSG_ID_SIM_RESET_REQ, &ilm_ptr);
            // wait for SIM task CNF message
            return;
        }
#ifdef __GEMINI__
        case FT_MISC_OP_CHECK_SIM2_INSERTED:
        {
            // Send reset request to MOD_SIM_2
            ilm_struct  ilm_ptr;
            sim_reset_req_struct* ptr_loc_para;
            FT_ALLOC_OTHER_MSG(&ilm_ptr, sizeof(sim_reset_req_struct));
            ptr_loc_para = (sim_reset_req_struct*) (ilm_ptr.local_para_ptr);
            ptr_loc_para->src_id = 0xff;
            // set sim cmd type to global variable
            ft_gl_sim_cmd_type =FT_MISC_OP_CHECK_SIM2_INSERTED;
            FT_SEND_MSG(MOD_FT, MOD_SIM_2, PS_SIM_SAP, MSG_ID_SIM_RESET_REQ, &ilm_ptr);
            // wait for SIM task CNF message
            return;
        }
#endif // __GEMINI__
#ifdef GEMINI_PLUS
        case FT_MISC_OP_CHECK_GEMINI_PLUS_SIM_INSERTED:
        {
            // Send reset request to MOD_SIM_N
            ilm_struct  ilm_ptr;
            sim_reset_req_struct* ptr_loc_para;
            // if index out of range, break and then send error status CNF
            if(p_req->cmd.m_u1SimIndex >= GEMINI_PLUS)
            {
                break;
            }
            FT_ALLOC_OTHER_MSG(&ilm_ptr, sizeof(sim_reset_req_struct));
            ptr_loc_para = (sim_reset_req_struct*) (ilm_ptr.local_para_ptr);
            ptr_loc_para->src_id = 0xff;
            // set sim cmd type to global variable
            ft_gl_sim_cmd_type = FT_MISC_OP_CHECK_GEMINI_PLUS_SIM_INSERTED;
            FT_SEND_MSG(MOD_FT, (module_type)(MOD_SIM + p_req->cmd.m_u1SimIndex), PS_SIM_SAP, MSG_ID_SIM_RESET_REQ, &ilm_ptr);
            // wait for SIM task CNF message
            return;
        }
#endif // GEMINI_PLUS
#endif // SIM_NOT_PRESENT
        case FT_MISC_OP_SET_MUIC_CHARGER_MODE:
        {
#ifdef __DRV_EXT_CHARGER_DETECTION__
            MU_BQ25040_Charger_Mode(p_req->cmd.m_u1ChargerMode);
            misc_cnf.status = FT_CNF_OK;
#else
            misc_cnf.status = FT_CNF_FAIL;

#endif
            break;
        }
#if !defined(NVRAM_NOT_PRESENT)
        case FT_MISC_OP_CALDATA_INTEGRITY_START_REC:
        {
            if(g_b_ft_nvram_rec)
            {
                misc_cnf.status = FT_CNF_FAIL;
                break;
            }


            i4_ft_cur_misc_op =  p_req->type;
            ft_misc_cal_data_read_from_nvram();
            return;
        }
        case FT_MISC_OP_CALDATA_INTEGRITY_STOP_REC:
        {
            if(!g_b_ft_nvram_rec)
            {
                misc_cnf.status = FT_CNF_FAIL;
                break;
            }
            g_b_ft_nvram_rec = false; // stop record
            i4_ft_cur_misc_op =  p_req->type;
            ft_misc_cal_data_write_to_nvram();
            return;
        }
        case FT_MISC_OP_CALDATA_INTEGRITY_ADD_ONE:
        case FT_MISC_OP_CALDATA_INTEGRITY_DEL_ONE:
        case FT_MISC_OP_CALDATA_INTEGRITY_CHECK_ONE:

            ft_misc_cal_data_proc_one.u2LidEnumVal = p_req->cmd.m_rCalDataOne.u2LidEnum;
            ft_misc_cal_data_proc_one.u2LidRec = p_req->cmd.m_rCalDataOne.u2RID;
            ft_misc_cal_data_proc_one.u2CheckVal = 0;
            // note: don't break, keep going
        case FT_MISC_OP_CALDATA_INTEGRITY_DEL_ALL:
        case FT_MISC_OP_CALDATA_INTEGRITY_CHECK_ALL:
        {
            if(g_b_ft_nvram_rec)
            {
                misc_cnf.status = FT_CNF_FAIL;
                break;
            }
            i4_ft_cur_misc_op =  p_req->type;

            ft_misc_cal_data_read_from_nvram();
            return;
        }
#endif // #if !defined(NVRAM_NOT_PRESENT)
        case FT_MISC_OP_GET_ADC_FROM_EFUSE:
        {
            kal_bool b_ret_code;
            kal_uint8 i;
            kal_uint8 adc_max_channel;
            DCL_HANDLE adc_handle;
            ADC_CTRL_READ_CALIBRATION_DATA_T prReadCalibrationData;
            adc_handle = DclSADC_Open(DCL_ADC, FLAGS_NONE);
            adc_max_channel = FT_GetAdcMaxChannel();
            b_ret_code = (STATUS_OK == DclSADC_Control(adc_handle, ADC_CMD_READ_CALIBRATION_DATA, (DCL_CTRL_DATA_T*)&prReadCalibrationData)) ?
                KAL_TRUE : KAL_FALSE;
            misc_cnf.status = FT_CNF_OK;
            misc_cnf.result.m_rGetAdcFromEfuse.bADCStoredInEfuse = b_ret_code;
            misc_cnf.result.m_rGetAdcFromEfuse.u2ADCChnNum = b_ret_code ? adc_max_channel : 0;

            // if channel number > 0, construct peer buffer
            if(misc_cnf.result.m_rGetAdcFromEfuse.u2ADCChnNum > 0) // i.e. FT_GetAdcMaxChannel()
            {
                if( NULL != (peer_buff_ret=construct_peer_buff(adc_max_channel*8, 0, 0, TD_CTRL)) )
                {
                    pdu_ptr = get_peer_buff_pdu( peer_buff_ret, &pdu_length );
                    peer_buff_ret->pdu_len = adc_max_channel *8;

                    for(i =0; i< adc_max_channel; i++) // append slope first
                    {
                        kal_mem_cpy(pdu_ptr+(i*4), &(prReadCalibrationData.i4ADCSlope[i]), sizeof(kal_int32));
                    }
                    for(i =0; i<adc_max_channel; i++) // append offset second
                    {
                        kal_mem_cpy(pdu_ptr+((adc_max_channel+i)*4), &(prReadCalibrationData.i4ADCOffset[i]), sizeof(kal_int32));
                    }
                }
            }
            break;
        }
        case FT_MISC_OP_GET_CALFLAG_ENUM:
        {
                 misc_cnf.result.m_u2CalFlagEnum = custom_ft_get_calflag_enum();
                 misc_cnf.status = FT_CNF_OK;
        }
        break;
        case FT_MISC_OP_GET_ADC_MAX_CHANNEL:
        {
            // HAL modification
            misc_cnf.status = FT_CNF_OK;
            misc_cnf.result.m_u1ADCMaxChannel = FT_GetAdcMaxChannel();
            break;
        }
        case FT_MISC_OP_GET_TADC_INDEX:
        {
            // HAL modification
            //misc_cnf.result.m_u1TADCChannelIndex = custom_adc_get_channel(rftmp_adc_channel);
            DCL_HANDLE adc_handle;
            ADC_CTRL_GET_PHYSICAL_CHANNEL_T adc_ch;
            misc_cnf.status = FT_CNF_OK;
            adc_handle = DclSADC_Open(DCL_ADC, FLAGS_NONE);
            adc_ch.u2AdcName = DCL_RFTMP_ADC_CHANNEL;
            if(DclSADC_Control( adc_handle, ADC_CMD_GET_CHANNEL, (DCL_CTRL_DATA_T *)& adc_ch) != STATUS_OK)
            {
                misc_cnf.status = FT_CNF_FAIL;
            }
            misc_cnf.result.m_u1TADCChannelIndex = adc_ch.u1AdcPhyCh;
            if(DclSADC_Close(adc_handle) != STATUS_OK)
            {
                misc_cnf.status = FT_CNF_FAIL;
            }
            break;
        }
        case FT_MISC_OP_GET_RF_CAL_ENV_ENUM:
            misc_cnf.result.m_u2Enum = custom_ft_get_rf_cal_env_enum();
            misc_cnf.status = FT_CNF_OK;
        break;
        case FT_MISC_OP_GET_RF_CAL_LOSS_SETTING_ENUM:
            misc_cnf.result.m_u2Enum = custom_ft_get_rf_loss_setting_enum();
            misc_cnf.status = FT_CNF_OK;
        break;
        case FT_MISC_OP_GET_RF_TEST_POWER_RESULT_ENUM:
            misc_cnf.result.m_u2Enum = custom_ft_get_rf_test_power_result_enum();
            misc_cnf.status = FT_CNF_OK;
        break;
        case FT_MISC_OP_GET_RID:
        {
            if(KAL_TRUE == SST_Get_ChipRID((kal_char*)misc_cnf.result.m_rRIDData.buf, (p_req->cmd.m_RIDLength*8)))
            {
                misc_cnf.result.m_rRIDData.buf_len = p_req->cmd.m_RIDLength; // return RID length in bytes
            }
            else
            {
                misc_cnf.result.m_rRIDData.buf_len = 0; // return length = 0 for error check
            }
            misc_cnf.status = FT_CNF_OK;
            break;
        }
        case FT_MISC_OP_GET_BARCODE_VALUE:
        {
            if(p_req->cmd.m_u1RecordIndex < 1 || p_req->cmd.m_u1RecordIndex > NVRAM_EF_BARCODE_NUM_TOTAL)
            {
                p_req->cmd.m_u1RecordIndex = 1;
            }
            if( NULL != (peer_buff_ret=construct_peer_buff(NVRAM_EF_BARCODE_NUM_SIZE, 0, 0, TD_CTRL)))
            {
                peer_buff_ret->pdu_len = NVRAM_EF_BARCODE_NUM_SIZE;
                pdu_ptr = get_peer_buff_pdu( peer_buff_ret, &pdu_length );    	                           
                if(KAL_TRUE == nvram_external_read_data(NVRAM_EF_BARCODE_NUM_LID, p_req->cmd.m_u1RecordIndex, (kal_uint8*)pdu_ptr, NVRAM_EF_BARCODE_NUM_SIZE))
                {
                    misc_cnf.status = FT_CNF_OK;
                }
            }
            break;
        }
        default:
            return;
    }
    // send confirm to PC side
    FT_MISC_SendCnf(&misc_cnf, peer_buff_ret);
}