DCL_STATUS DclBMT_Initialize(void){

#if defined(DRV_BMT_HIGH_VCHG_ADAPTIVE_CHARGE_CURRENT_SUPPORT)
    bmt_high_vchg_para=bmt_get_customized_high_vchg_para();
#endif

	#if defined(__DRV_BMT_PRECHARGE_TO_FULL_DIRECTLY__)
	BMT_VbatInHISR_Init();
	#endif //#if defined(__DRV_BMT_PRECHARGE_TO_FULL_DIRECTLY__)

#ifdef __BACKUP_DOWNLOAD_RESTORE_WITHOUT_BATTERY__
	if (INT_GetSysStaByCmd(CHK_USB_META_WO_BAT, NULL)==KAL_TRUE)
	{

		DCL_HANDLE handle;
		handle = DclBMT_Open(DCL_BMT, FLAGS_NONE);
		DclBMT_Control(handle, BMT_CMD_WDT_INIT, NULL);
		DclBMT_Close(handle);

	}
#endif //#ifdef __BACKUP_DOWNLOAD_RESTORE_WITHOUT_BATTERY__


	return STATUS_OK;
}
/*************************************************************************
* 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;
}
Beispiel #3
0
void Drv_Init_Phase1(void)
{
#if defined(DRV_GPT_GPT3)
   DCL_HANDLE gpt_handle;
#endif //defined(DRV_GPT_GPT3)
#ifndef DRV_RTC_NOT_EXIST
   DCL_HANDLE rtc_handler;
#endif //#ifndef DRV_RTC_NOT_EXIST

	DCL_HANDLE uart_handle;
   UART_CTRL_INIT_T data_init;
   extern Seriport_HANDLER_T Uart_Drv_Handler;

#ifdef __USB_COM_PORT_ENABLE__
   DCL_HANDLE  usb_dcl_handle;
   DCL_BOOL dcl_data;
   kal_bool b_is_dl_mode;

   usb_dcl_handle = DclUSB_DRV_Open(DCL_USB, FLAGS_NONE);
   DclUSB_DRV_Control(usb_dcl_handle, USB_DRV_CMD_USBDL_UPDATE_USB_DL_MODE, NULL);
   DclUSB_DRV_Control(usb_dcl_handle, USB_DRV_CMD_USBDL_IS_USB_DL_MODE, (DCL_CTRL_DATA_T  *)&dcl_data);
   b_is_dl_mode = (kal_bool)dcl_data;
   if(b_is_dl_mode == KAL_TRUE)
   {
      UPLL_Enable(UPLL_OWNER_USB);
   }
   DclUSB_DRV_Close(usb_dcl_handle);
#endif //__USB_COM_PORT_ENABLE__

#if defined(__HW_US_TIMER_SUPPORT__ )
   USC_Start();
#endif

#ifdef __BACKUP_DOWNLOAD_RESTORE_WITHOUT_BATTERY__
	if (INT_GetSysStaByCmd(CHK_USB_META_WO_BAT, NULL)==KAL_TRUE)
	{

		DCL_HANDLE handle;
		DclPMU_Initialize();
		handle = DclPMU_Open(DCL_PMU, FLAGS_NONE);
		DclPMU_Control(handle, CHR_SET_CHARGE_WITHOUT_BATTERY, NULL);
		DclPMU_Close(handle);

	}
#endif //#ifdef __BACKUP_DOWNLOAD_RESTORE_WITHOUT_BATTERY__

   print_bootup_trace_enter(SST_INIT_DRV1_DRVHISR);
   drv_hisr_init();
   print_bootup_trace_exit(SST_INIT_DRV1_DRVHISR);

#if defined(__DSP_FCORE4__)
   print_bootup_trace_enter(SST_INIT_DRV1_MDCIHW);
   mdci_hw_init(1,0x0);
   print_bootup_trace_exit(SST_INIT_DRV1_MDCIHW);
#endif
#if defined(__SMART_PHONE_MODEM__)
   print_bootup_trace_enter(SST_INIT_DRV1_CCCI);

   ccif_init(1,0x0);
   ipc_msgsvc_init();
   FS_CCCI_Init();
   ccci_init(CCCI_FS_CHANNEL, FS_CCCI_Callback);
   ccci_init(CCCI_FS_ACK_CHANNEL, FS_CCCI_Callback);

   uart_handle =  DclSerialPort_Open(uart_port_tst_ccci, 0);
   DclSerialPort_RegisterCallback(uart_handle, &CCCI_Uart_Drv_Handler);

   uart_handle =  DclSerialPort_Open(uart_port_at_ccci, 0);
   DclSerialPort_RegisterCallback(uart_handle, &CCCI_Uart_Drv_Handler);


#if defined(__UPS_SUPPORT__)

   uart_handle =  DclSerialPort_Open(uart_port_ccmni1_ccci, 0);
   DclSerialPort_RegisterCallback(uart_handle, &CCCI_Uart_Drv_Handler);

   uart_handle =  DclSerialPort_Open(uart_port_ccmni2_ccci, 0);
   DclSerialPort_RegisterCallback(uart_handle, &CCCI_Uart_Drv_Handler);

   uart_handle =  DclSerialPort_Open(uart_port_ccmni3_ccci, 0);
   DclSerialPort_RegisterCallback(uart_handle, &CCCI_Uart_Drv_Handler);

#endif /* __UPS_SUPPORT__ */

   uart_handle =  DclSerialPort_Open(uart_port_gps_ccci, 0);
   DclSerialPort_RegisterCallback(uart_handle, &CCCI_Uart_Drv_Handler);

   print_bootup_trace_exit(SST_INIT_DRV1_CCCI);
#endif /* __SMART_PHONE_MODEM__ */

#if defined(DRV_EMIMPU)
   print_bootup_trace_enter(SST_INIT_DRV1_EMIMPU);
   emimpu_init();
   print_bootup_trace_exit(SST_INIT_DRV1_EMIMPU);
#endif /* DRV_EMIMPU */

   print_bootup_trace_enter(SST_INIT_DRV1_LPWR);
   lpwr_init();
   print_bootup_trace_exit(SST_INIT_DRV1_LPWR);

   print_bootup_trace_enter(SST_INIT_DRV1_DRVPDN);
   DRVPDN_ini();
   print_bootup_trace_exit(SST_INIT_DRV1_DRVPDN);

   print_bootup_trace_enter(SST_INIT_DRV1_PWM);
   DclPWM_Initialize();
   print_bootup_trace_exit(SST_INIT_DRV1_PWM);

   /*To get all customized data*/
   print_bootup_trace_enter(SST_INIT_DRV1_CUSTOM);

   DclSADC_Initialize();

   Drv_Customize_Init();
   custom_drv_init();

   print_bootup_trace_exit(SST_INIT_DRV1_CUSTOM);

   #if defined(DRV_GPT_GPT3)
   print_bootup_trace_enter(SST_INIT_DRV1_GPT3);
   /*turn on gpt3 to count powen on period*/
  DclFGPT_Initialize();
	gpt_handle=DclFGPT_Open(DCL_GPT_FreeRUN3,0);
	DclFGPT_Control(gpt_handle,FGPT_CMD_START,0);
	DclFGPT_Close(gpt_handle);

   print_bootup_trace_exit(SST_INIT_DRV1_GPT3);
   #endif

   #if !defined(__L1_STANDALONE__) && !defined(__MAUI_BASIC__) && !defined(__SMART_PHONE_MODEM__)
      print_bootup_trace_enter(SST_INIT_DRV1_VISUAL);
      Visual_Init();
      print_bootup_trace_exit(SST_INIT_DRV1_VISUAL);
   #endif /*!defined(__L1_STANDALONE__) && !defined(__MAUI_BASIC__) && !defined(__SMART_PHONE_MODEM__)*/

#if defined(DRV_TIMING_DEBUG) && defined(DRV_GPT_6218B_GPT3_TIMING_DEBUG)
   DRV_MISC_WriteReg(0x8010001c,1);
   DRV_MISC_WriteReg(0x80100024,0x04);
   //DRV_WriteReg(0x80100024,1); // (1/16K)
#endif

   #ifdef DRV_MISC_DMA_NO_MEMCPY
      DRV_MEMCPY = (MEMCPY_FUNC)0x48000150;
   #elif defined(DRV_MISC_DMA_MEMCPY)
      DRV_MEMCPY_PTR = (MEMCPY_FUNC)0x48000134;
   #endif

   print_bootup_trace_enter(SST_INIT_DRV1_GPTI);
   DclSGPT_Initialize();
   print_bootup_trace_exit(SST_INIT_DRV1_GPTI);

   print_bootup_trace_enter(SST_INIT_DRV1_WDT);
   WDT_init();
   print_bootup_trace_exit(SST_INIT_DRV1_WDT);

   print_bootup_trace_enter(SST_INIT_DRV1_DMA);
   DMA_Ini();
   print_bootup_trace_exit(SST_INIT_DRV1_DMA);

#ifndef DRV_RTC_NOT_EXIST
   // need to set XOSC earlier
   print_bootup_trace_enter(SST_INIT_DRV1_XOSC);
	rtc_handler = DclRTC_Open(DCL_RTC,FLAGS_NONE);
   DclRTC_Control(rtc_handler, RTC_CMD_SETXOSC, (DCL_CTRL_DATA_T *)NULL);
   print_bootup_trace_exit(SST_INIT_DRV1_XOSC);
#endif /*DRV_RTC_NOT_EXIST*/
   print_bootup_trace_enter(SST_INIT_DRV1_ADC);
   DclHADC_Initialize( );
   print_bootup_trace_exit(SST_INIT_DRV1_ADC);

#ifdef __CS_FAC_DET__
   print_bootup_trace_enter(SST_INIT_DRV1_CSFACDET);
   cs_fac_det = cs_fac_det_get_interface();
   cs_fac_det->drv_init();
   print_bootup_trace_exit(SST_INIT_DRV1_CSFACDET);
#endif // #ifdef __CS_FAC_DET__

#ifdef  __DRV_EXT_ACCESSORY_DETECTION__
#ifdef   __USB_COM_PORT_ENABLE__
   usb_dcl_handle = DclUSB_DRV_Open(DCL_USB, FLAGS_NONE);
   DclUSB_DRV_Control(usb_dcl_handle, USB_DRV_CMD_USBDL_IS_USB_DL_MODE, (DCL_CTRL_DATA_T  *)&dcl_data);
   b_is_dl_mode = (kal_bool)dcl_data;
   DclUSB_DRV_Close(usb_dcl_handle);

   if(b_is_dl_mode == KAL_FALSE)
#endif
   {
        print_bootup_trace_enter(SST_INIT_DRV1_EXTACCDET);
   	aux_ext_acc_det = aux_custom_get_ext_accessory_det();
   	aux_ext_acc_det->drv_init();
        print_bootup_trace_exit(SST_INIT_DRV1_EXTACCDET);
   }
#endif // #ifdef  __DRV_EXT_ACCESSORY_DETECTION__

//#if (defined(__ACCDET_SUPPORT__) && !defined(__L1_STANDALONE__))
   print_bootup_trace_enter(SST_INIT_DRV1_ACCDET);
	DclAUX_Initialize();
   print_bootup_trace_exit(SST_INIT_DRV1_ACCDET);

//#endif //#if defined(__ACCDET_SUPPORT__)

#if defined(__RESOURCE_MANAGER__)
   print_bootup_trace_enter(SST_INIT_DRV1_RM);
   RMInit();
   print_bootup_trace_exit(SST_INIT_DRV1_RM);
#endif //__RESOURCE_MANAGER__

#ifndef DRV_LCD_NOT_EXIST
   print_bootup_trace_enter(SST_INIT_DRV1_LCD);
   lcd_system_init();
   print_bootup_trace_exit(SST_INIT_DRV1_LCD);
#endif /*DRV_LCD_NOT_EXIST*/
#ifndef DRV_RTC_NOT_EXIST
#ifdef DRV_RTC_HW_CALI
   print_bootup_trace_enter(SST_INIT_DRV1_RTCHW);
   DclRTC_Control(rtc_handler, RTC_CMD_HW_INIT, (DCL_CTRL_DATA_T *)NULL);
   print_bootup_trace_exit(SST_INIT_DRV1_RTCHW);
#endif
#endif /*DRV_RTC_NOT_EXIST*/
	DclPW_Initialize();

    DclPMU_Initialize();

    Drv_PW_Init();

	/* update the system boot mode */
/*lint -e552*/
	system_boot_mode = Drv_query_boot_mode();
/*lint +e552*/
      print_boot_mode();

#ifdef __DMA_UART_VIRTUAL_FIFO__
//        print_bootup_trace_enter(SST_INIT_DRV1_DMAVFIFO);
//	DMA_Vfifo_init();
 //       print_bootup_trace_exit(SST_INIT_DRV1_DMAVFIFO);
#if defined(__MD_STANDALONE__)
// This is to configure AP side VFIFO ALT register, to avoid un-init AP side DMA setting
// conflict MD side setting
// This is only used in MD DVT load, when both side are ready, we shouldn't overwrite AP side setting via back door
	// Hack DMA channel 13 (VFIFO channel) in AP side in order to avoid conflict
	*(volatile kal_uint32 *)(0xF0022000 + 0xD40) = 0x3F;
	// Hack DMA channel 14 (VFIFO channel) in AP side in order to avoid conflict
	*(volatile kal_uint32 *)(0xF0022000 + 0xE40) = 0x3F;
#endif // #if defined(__MD_STANDALONE__)

#endif

   print_bootup_trace_enter(SST_INIT_DRV1_UART1);

	 data_init.u4Flag = KAL_FALSE;
   uart_handle =  DclSerialPort_Open(uart_port1, 0);
   DclSerialPort_RegisterCallback(uart_handle, &Uart_Drv_Handler);

   // Initialization

   DclSerialPort_Control(uart_handle,SIO_CMD_INIT,(DCL_CTRL_DATA_T *)&data_init);
   print_bootup_trace_exit(SST_INIT_DRV1_UART1);

   // Register the callback function
   print_bootup_trace_enter(SST_INIT_DRV1_UART2);
   uart_handle =  DclSerialPort_Open(uart_port2, 0);
   DclSerialPort_RegisterCallback(uart_handle, &Uart_Drv_Handler);

   // Initialization
   DclSerialPort_Control(uart_handle,SIO_CMD_INIT,(DCL_CTRL_DATA_T *)&data_init);
   print_bootup_trace_exit(SST_INIT_DRV1_UART2);

   #ifdef __UART3_SUPPORT__
   print_bootup_trace_enter(SST_INIT_DRV1_UART3);
   // Register the callback function
   uart_handle =  DclSerialPort_Open(uart_port3, 0);
   DclSerialPort_RegisterCallback(uart_handle,&Uart_Drv_Handler);
   DclSerialPort_Control(uart_handle,SIO_CMD_INIT,(DCL_CTRL_DATA_T *)&data_init);
   print_bootup_trace_exit(SST_INIT_DRV1_UART3);
   #endif

}