/*************************************************************************
* FUNCTION
*  DclBMT_Control
*
* DESCRIPTION
*  This function is to send command to control the BMT module.
*
* PARAMETERS
*  handle: The handle value returned from DclBMT_Open
*  cmd: A control command for BMT module
*           1. BMT_CMD_CALLSTATE: to nodify talk/idle state to BMT task
*           2. BMT_CMD_SET_EXT_CHARGER: to control the external charger
*           3. BMT_CMD_IS_BAT_ON: to check is battery exist or not
*       	4. BMT_CMD_SENDMES2UEM: to send message from BMT to UEM
*           5. BMT_CMD_SET_CHR_STATUS: to set charger status
*           6. BMT_CMD_VBATINHISR: to save the Battery voltage in HISR
*
*  data: The data of the control command
*           1. BMT_CMD_CALLSTATE: pointer to a BMT_CTRL_CALLSTATE_T structure
*           2. BMT_CMD_SET_EXT_CHARGER: pointer to a BMT_CTRL_SET_EXT_CHARGER_T structure
*           3. BMT_CMD_IS_BAT_ON: pointer to a BMT_CTRL_IS_BAT_ON_T structure
*           4. BMT_CMD_SENDMES2UEM: pointer to a BMT_CTRL_SENDMES2UEM_T structure
*           5. BMT_CMD_SET_CHR_STATUS: pointer to a BMT_CTRL_SET_CHR_STATUS_T structure
*           6. BMT_CMD_VBATINHISR: A null pointer   
*
* RETURNS
*  STATUS_OK: command is executed successfully.
*  STATUS_FAIL: command is failed.
*  STATUS_INVALID_CMD: It's a invalid command.
*
*************************************************************************/
DCL_STATUS DclBMT_Control(DCL_HANDLE handle, DCL_CTRL_CMD cmd, DCL_CTRL_DATA_T *data)
{
    DCL_STATUS return_status = STATUS_INVALID_CMD;

	// Check magic number
	if ((handle & DCL_BMT_DEV_MAGIC_NUM) != DCL_BMT_DEV_MAGIC_NUM){
		ASSERT(0);
		return STATUS_INVALID_DCL_HANDLE;
	}

	// Error check
	if (dcl_bmt_handle_count == 0){
		ASSERT(0);
		return STATUS_NOT_OPENED;
	}

	switch (cmd)
	{
#ifdef __BACKUP_DOWNLOAD_RESTORE_WITHOUT_BATTERY__
	case BMT_CMD_WDT_INIT:
	{

		if (bmt_without_battery_handle == 0x7F)
		{
			bmt_without_battery_handle=DclSGPT_Open(DCL_GPT_CB,0);
		}


		{   	  
			SGPT_CTRL_START_T start;	  
			start.u2Tick=1000;	  // 10 secs
			start.pfCallback=bmt_without_battery_callback;	  
			start.vPara=NULL;	  
			DclSGPT_Control(bmt_without_battery_handle,SGPT_CMD_START,(DCL_CTRL_DATA_T*)&start);		
		}


		

	}
	break;
#endif //#ifdef __BACKUP_DOWNLOAD_RESTORE_WITHOUT_BATTERY__	
	
        case BMT_CMD_CALLSTATE:
        {
			BMT_CTRL_CALLSTATE_T *prCallState;
			prCallState = &(data->rCallState);
			BMT_CallState(prCallState->call_state);            
            return_status = STATUS_OK;
        }
        break;
        
        case BMT_CMD_CHARGE:
        {
			BMT_CTRL_CHARGE_T *prChargeControl;
			prChargeControl = &(data->rChargeControl);

			if(INT_GetSysStaByCmd(CHK_USB_META_WO_BAT, NULL)==KAL_TRUE && prChargeControl->bEnable==DCL_TRUE)
			{
				return_status = STATUS_OK;
				break;
			}
			
			BMT_Charge((kal_bool)prChargeControl->bEnable);            
            return_status = STATUS_OK;
        }
        break;
        
        case BMT_CMD_GET_CUSTOMIZED_PARA:
        {
            BMT_CTRL_GET_CUSTOMIZED_PARA_T *prGetCustomizedPara;
            prGetCustomizedPara = &(data->rGetCustomizedPara);
            return_status = bmt_get_customized_para(prGetCustomizedPara);            
        }
        break;

        case BMT_CMD_SET_EXT_CHARGER:
        {
            return_status = STATUS_UNSUPPORTED;
        }
        break;
                
		case BMT_CMD_INITIALIZE:
		{
			bmt_initialize();
			return_status = STATUS_OK;
		}
		break;        
                
        case BMT_CMD_IS_BAT_ON:
        {
			BMT_CTRL_IS_BAT_ON_T *prIsBatOn;
			prIsBatOn = &(data->rIsBatOn);
			prIsBatOn->fgBatIsOn = (DCL_BOOLEAN)bmt_is_bat_on();
            return_status = STATUS_OK;
        }        
        break;
        
		case BMT_CMD_SENDMES2UEM:
		{
			BMT_CTRL_SENDMES2UEM_T  *prSendMes2Uem;
			prSendMes2Uem = &(data->rSendMes2Uem);
			BMT_sendMes2UEM((BMT_CHR_STAT)prSendMes2Uem->ChargerMsg);
			return_status = STATUS_OK;
		}
		break;
		
		case BMT_CMD_SET_CHR_STATUS:
		{
			BMT_CTRL_SET_CHR_STATUS_T  *prSetChrStatus;
			prSetChrStatus = &(data->rSetChrStatus);
			bmt_set_chr_status((Charger_Status)prSetChrStatus->ChargerStat);
			
			return_status = STATUS_OK;
		}
		break;  
		      
		case BMT_CMD_VBATINHISR:
		{
#if defined( __DRV_BMT_PRECHARGE_TO_FULL_DIRECTLY__)
			BMT_VbatInHISR();
			return_status = STATUS_OK;
#else
			return_status = STATUS_UNSUPPORTED;
#endif
		}
		break;
		default:
			return_status = STATUS_INVALID_CMD;
		break;
	}
    return return_status;
//	return STATUS_FAIL;
}
Exemplo n.º 2
0
// first_time_det: Means whether it is first time to perform battery detection
// If first time, then need to send the battery status to UEM
void bmt_batt_exist_detection(kal_bool first_time_det)
{
   kal_bool batt_exist_state;
   static kal_bool batt_exist_flag = KAL_TRUE;  // Assume batt is mounted at init state

   CHR_DET_TYPE_ENUM chr_type;

   chr_type = bmt_get_chr_type();
   
#ifdef __CS_FAC_DET__
   {
      cs_fac_boot_mode_enum fac_boot_mode;
      fac_boot_mode = cs_fac_det->factory_det_get_boot_mode();
      switch (fac_boot_mode)
      {
      case CS_FAC_BOOT_IDLE:
         ; // We boot into IDLE on purpose, skip battery check
         return;
         break;
      case CS_FAC_BOOT_CHARGING:
         ;
         break;
      case CS_FAC_BOOT_USB_CHARGING:
         ;
         break;
      default:
         break;
      }
   }
#endif // #ifdef __CS_FAC_DET__
   
   batt_exist_state = bmt_is_bat_on();
   drv_trace1(TRACE_GROUP_10, BMT_MSG_BATT_ON_DET, batt_exist_state);
   if ( (batt_exist_flag != batt_exist_state) || (first_time_det) )
   {
      if (batt_exist_state == KAL_FALSE)
      {
			// A temp workaround
			// It seems UEM expect to receive charger in message first in charger boot mode,
			// then be able to process other messages from BMT
			if (first_time_det)
			{
				if ((PW_AC_CHR == chr_type) || (PW_AC_NON_STD_CHR == chr_type))
				{
					// Send charger in to UEM
					bmt_sendMes2UEM(BMT_USB_NO_CHARGING_IN);
				}
			}
         // Batt removal
         bmt_sendMes2UEM(BMT_BATT_OUT);
      }
      else
      {
         // Batt attached
         bmt_sendMes2UEM(BMT_BATT_IN);
         
         // When program run to here, it means we are CHARGER or USB boot mode
         // Manually trigger cable plug-in HISR to perform charging procedure
         //pmic_adpt_sw_trigger_chr_usb_intr
         if ( (!first_time_det) && (batt_exist_flag != batt_exist_state) )
         {
         	bmt_sendMes2BMT(MOD_EINT_HISR/*MOD_BMT*/,MSG_ID_BMT_CHARGER_IND);
         }
         
      }
      batt_exist_flag = batt_exist_state;
   }
}