/************************************************************************* * FUNCTION * stack_config * * DESCRIPTION * This function implements to get system date time * * PARAMETERS * * RETURNS * * GLOBALS AFFECTED * *************************************************************************/ void RTFAPI RTFSYSGetDateTime(RTFDOSDateTime * TimeDate) { RTC_CTRL_GET_TIME_T rtc_time; // Always zero rtc_time, in case of unsupported RTC platforms. kal_mem_set(&rtc_time, 0, sizeof(RTC_CTRL_GET_TIME_T)); /* * Get a RTC handle in the first time. * This handle will not be closed in the future. */ if (DCL_HANDLE_INVALID == rtc_handler) rtc_handler = DclRTC_Open(DCL_RTC, FLAGS_NONE); DclRTC_Control(rtc_handler, RTC_CMD_GET_TIME, (DCL_CTRL_DATA_T*)&rtc_time); TimeDate->Day = rtc_time.u1Day; TimeDate->Hour = rtc_time.u1Hour; TimeDate->Minute = rtc_time.u1Min; TimeDate->Month = rtc_time.u1Mon; TimeDate->Second2 = rtc_time.u1Sec >> 1; // Second only contain 5 bits TimeDate->Year1980 = rtc_time.u1Year + 20; // Adapt to windows is 1980 base while RTC is 2000 base }
/** * This api calls the DCL interface to check and clear the PDN1 bit 7 set by flashtool * and scrambles theh powerkey1 */ static kal_bool FT_ClearPowerKey(void) { /// Driver RTC FT Power Off request RTC_CTRL_FT_POWEROFF_T ft_cmd_data; DCL_HANDLE rtc_handle = DclRTC_Open(DCL_RTC, FLAGS_NONE); DclRTC_Control(rtc_handle, RTC_CMD_FT_POWEROFF, (DCL_CTRL_DATA_T *) &ft_cmd_data); DclRTC_Close(rtc_handle); return (kal_bool)ft_cmd_data.fgMetaReset; }
kal_bool F32K_Query_Is_XOSC32(void) { DCL_HANDLE rtc_handler; RTC_CTRL_READ_XOSC_REG_T rtc_xosc32_config; rtc_handler = DclRTC_Open(DCL_RTC, FLAGS_NONE); DclRTC_Control(rtc_handler, RTC_CMD_RELOAD, (DCL_CTRL_DATA_T *)NULL); DclRTC_Control(rtc_handler, RTC_CMD_WRITE_TRIGGER_WAIT, NULL); DclRTC_Control(rtc_handler, RTC_CMD_READ_XOSC_REG, (DCL_CTRL_DATA_T *)&rtc_xosc32_config); DclRTC_Close(rtc_handler); if ((rtc_xosc32_config.XOSCValue & 0x20) == 0x0) return KAL_TRUE; else return KAL_FALSE; }
void ft_util_query_rtc(FT_UTILITY_COMMAND_CNF *cnf) { // HAL modification //RTC_GetTime(&cnf->result.rtc); DCL_HANDLE rtc_handle; RTC_CTRL_GET_TIME_T rtc_cmd_data3; // New Declaration cnf->status = FT_CNF_OK; rtc_handle = DclRTC_Open(DCL_RTC, FLAGS_NONE); if(DclRTC_Control(rtc_handle, RTC_CMD_GET_TIME, (DCL_CTRL_DATA_T *)&rtc_cmd_data3) != STATUS_OK) { cnf->status = FT_CNF_FAIL; } cnf->result.rtc.rtc_year = rtc_cmd_data3.u1Year; cnf->result.rtc.rtc_wday = rtc_cmd_data3.u1WDay; cnf->result.rtc.rtc_mon = rtc_cmd_data3.u1Mon; cnf->result.rtc.rtc_day = rtc_cmd_data3.u1Day; cnf->result.rtc.rtc_hour = rtc_cmd_data3.u1Hour; cnf->result.rtc.rtc_min = rtc_cmd_data3.u1Min; cnf->result.rtc.rtc_sec = rtc_cmd_data3.u1Sec; DclRTC_Close(rtc_handle); }
/***************************************************************************** * FUNCTION * mtk_gps_sys_time_read * DESCRIPTION * * PARAMETERS * utctime [OUT] * RETURNS * success(0) *****************************************************************************/ mtk_int32 mtk_gps_sys_time_read (mtk_time* utctime) { if ((utctime) && (first_time_modification_flag == 0)) { RTC_CTRL_GET_TIME_T tSysTime; /* handler for RTC Module */ DCL_HANDLE rtc_handler; // It could be a global variable or a local variable memset(&tSysTime, 0, sizeof(tSysTime)); /* Open a RTC handler to perform further operations */ rtc_handler = DclRTC_Open(DCL_RTC, FLAGS_NONE); //RTC_GetTime(&tSysTime); DclRTC_Control(rtc_handler, RTC_CMD_GET_TIME, (DCL_CTRL_DATA_T *)&tSysTime); utctime->year = tSysTime.u1Year + 100; utctime->month = tSysTime.u1Mon - 1; utctime->mday = tSysTime.u1Day; utctime->hour = tSysTime.u1Hour; utctime->min = tSysTime.u1Min; utctime->sec = tSysTime.u1Sec; utctime->msec = 0; // TODO: system time tick?? do not use timers if (1 == time_modification_flag) { time_modification_flag = 0; mtk_gps_time_change_notify(rtctime_diff); return MTK_GPS_ERROR_TIME_CHANGED; } return MTK_GPS_SUCCESS; } first_time_modification_flag = 0; return MTK_GPS_ERROR; }
/* * FUNCTION * Drv_Init_Phase2 * * DESCRIPTION * This function is the NFB phase2 (Secondary ROM) initial function for * all device drivers. * This function is called once to initialize the device driver. * * CALLS * * PARAMETERS * None * * RETURNS * None * * GLOBALS AFFECTED * external_global * * NOTE XXX * All sub functions reference by this function should be placed on * Secondary ROM for NFB projects. */ void Drv_Init_Phase2(void) { DCL_HANDLE uart_handle; #ifdef __USB_COM_PORT_ENABLE__ DCL_CTRL_DATA_T data; #endif /*__USB_COM_PORT_ENABLE__*/ #ifndef DRV_RTC_NOT_EXIST DCL_HANDLE rtc_handler; #endif /*DRV_RTC_NOT_EXIST*/ #if defined(IC_BURNIN_TEST) || defined(DRV_MISC_GPT1_AS_OS_TICK) /*AB: Enable GPT1 for OS tick in the burn-in test load*/ extern void GPT_init(kal_uint8 timerNum, void (*GPT_Callback)(void)); extern void GPT_ResetTimer(kal_uint8 timerNum,kal_uint16 countValue,kal_bool autoReload); extern void GPT_Start(kal_uint8 timerNum); GPT_init(1, INT_Timer_Interrupt); GPT_ResetTimer(1, 4, KAL_TRUE); GPT_Start(1); #endif //IC_BURNIN_TEST //#ifdef __SWDBG_SUPPORT__ // UART_Register(uart_port_swdbg, UART_TYPE, (UartDriver_strcut *)&swdbgdrv); //#endif /* __SWDBG_SUPPORT__ */ #ifdef __USB_COM_PORT_ENABLE__ print_bootup_trace_enter(SST_INIT_DRV2_USB2UART); uart_handle = DclSerialPort_Open(uart_port_usb, 0); DclSerialPort_RegisterCallback(uart_handle, &USB2Uart_Drv_Handler); #if defined(__USB_MULTIPLE_COMPORT_SUPPORT__) uart_handle = DclSerialPort_Open(uart_port_usb2, 0); DclSerialPort_RegisterCallback(uart_handle, &USB2Uart_Drv_Handler); #if defined (__USB_MODEM_CARD_SUPPORT__) uart_handle = DclSerialPort_Open(uart_port_usb3, 0); DclSerialPort_RegisterCallback(uart_handle, &USB2Uart_Drv_Handler); #endif #endif DclSerialPort_Control(uart_handle,SIO_CMD_INIT,&data);// Initialization print_bootup_trace_exit(SST_INIT_DRV2_USB2UART); #endif /*__USB_COM_PORT_ENABLE__*/ //#if defined(__IRDA_SUPPORT__) && !defined(__MEUT__) && !defined(__MEIT__) /*TY adds this 2004/10/27*/ /* Register UART API */ // UART_Register(uart_port_irda, IRDA_TYPE, &ircomm_uart_api); //#endif #if defined(__BTMTK__) && (defined(__BT_SPP_PROFILE__) || defined(__BT_HFG_PROFILE__)) { kal_uint16 i; for(i = (kal_uint16)start_of_virtual_port; i < (kal_uint16)end_of_virtual_port + 1; i++) { uart_handle = DclSerialPort_Open((DCL_DEV)i, 0); DclSerialPort_RegisterCallback(uart_handle, &SPPA_Uart_Drv_Handler); } } #elif defined __CMUX_SUPPORT__ { kal_uint16 i; for(i = (kal_uint16)start_of_virtual_port; i < (kal_uint16)end_of_virtual_port + 1; i++) { uart_handle = DclSerialPort_Open((DCL_DEV)i, 0); DclSerialPort_RegisterCallback(uart_handle, &CmuxUart_Drv_Handler); } } #endif #ifndef DRV_KBD_NOT_EXIST print_bootup_trace_enter(SST_INIT_DRV2_KBD); DclSKBD_Initialize(); print_bootup_trace_exit(SST_INIT_DRV2_KBD); #endif /*DRV_KBD_NOT_EXIST*/ #ifndef DRV_RTC_NOT_EXIST print_bootup_trace_enter(SST_INIT_DRV2_RTCSW); rtc_handler = DclRTC_Open(DCL_RTC,FLAGS_NONE); DclRTC_Control(rtc_handler, RTC_CMD_INIT_TC_AL_INTR, (DCL_CTRL_DATA_T *)NULL); print_bootup_trace_exit(SST_INIT_DRV2_RTCSW); #endif /*DRV_RTC_NOT_EXIST*/ #ifdef __SIM_DRV_MULTI_DRV_ARCH__ print_bootup_trace_enter(SST_INIT_DRV2_SIM); DclSIM_Initialize(); print_bootup_trace_exit(SST_INIT_DRV2_SIM); #endif #if (defined( DRV_MULTIPLE_SIM) && (!defined(DRV_2_SIM_CONTROLLER))) print_bootup_trace_enter(SST_INIT_DRV2_SIMMT6302); sim_MT6302_init(); print_bootup_trace_exit(SST_INIT_DRV2_SIMMT6302); #endif #if (defined(__MSDC_MS__) || defined(__MSDC_SD_MMC__) || defined (__MSDC_MSPRO__)) print_bootup_trace_enter(SST_INIT_DRV2_MSDC); #if !defined(DCL_MSDC_INTERFACE) MSDC_Initialize(); #else DclSD_Initialize(); #endif//!defined(DCL_MSDC_INTERFACE) print_bootup_trace_exit(SST_INIT_DRV2_MSDC); #if defined(__MSDC2_SD_MMC__) || defined(__MSDC2_SD_SDIO__) print_bootup_trace_enter(SST_INIT_DRV2_MSDC2); #if !defined(DCL_MSDC_INTERFACE) MSDC_Initialize2(); #endif//!defined(DCL_MSDC_INTERFACE) print_bootup_trace_exit(SST_INIT_DRV2_MSDC2); #endif//defined(__MSDC2_SD_MMC__) || defined(__MSDC2_SD_SDIO__) #endif//(defined(__MSDC_MS__) || defined(__MSDC_SD_MMC__) || defined (__MSDC_MSPRO__)) #ifdef IC_MODULE_TEST IC_ModuleTest_Start(); #endif /*IC_MODULE_TEST*/ print_bootup_trace_enter(SST_INIT_DRV2_EINTSWDBNC); EINT_SW_Debounce_Init(); print_bootup_trace_exit(SST_INIT_DRV2_EINTSWDBNC); #ifdef MT6218B/*only 6218B has this */ GCU_Disable_ReverseBit(); #endif #ifdef __SWDBG_SUPPORT__ /* initialize SWDBG */ print_bootup_trace_enter(SST_INIT_DRV2_SWDBG); swdbg_init(); print_bootup_trace_exit(SST_INIT_DRV2_SWDBG); #endif /* __SWDBG_SUPPORT__ */ /* Cipher/Hash engine initialize */ print_bootup_trace_enter(SST_INIT_DRV2_CHE); che_hw_init(); print_bootup_trace_exit(SST_INIT_DRV2_CHE); /* ISP/Camera initialize */ #if defined(ISP_SUPPORT) print_bootup_trace(SST_INIT_DRV2_CIS_ENTER); #if defined(__MM_DCM_SUPPORT__) DCM_Load(DYNAMIC_CODE_COMPRESS_CAMCAL, NULL, NULL); #endif CalInit(); #if defined(__MM_DCM_SUPPORT__) DCM_Unload(DYNAMIC_CODE_COMPRESS_CAMCAL); #endif print_bootup_trace(SST_INIT_DRV2_CIS_EXIT); #endif #ifdef __WIFI_SUPPORT__ print_bootup_trace_enter(SST_INIT_DRV2_WN); wndrv_HWinit(); print_bootup_trace_exit(SST_INIT_DRV2_WN); #endif //#if (defined(_USE_SCCB_V2_DRIVER_)) #if defined(DRV_I2C_25_SERIES) print_bootup_trace_enter(SST_INIT_DRV2_I2C); DclSI2C_Initialize(); print_bootup_trace_exit(SST_INIT_DRV2_I2C); #endif // PXS is init at phase2 because it is external devices // Currently, do NOT think it should be put in phase1 #if defined(__PXS_ENABLE__) && !defined(IC_MODULE_TEST) && !defined(IC_BURNIN_TEST) DclPXS_Initialize(); #endif // #if defined(__PXS_ENABLE__) && !defined(IC_MODULE_TEST) && !defined(IC_BURNIN_TEST) #if defined(__L1_STANDALONE__)&&defined(__CLKG_DEFINE__)&&!defined(IC_BURNIN_TEST) mm_disable_power(MMPWRMGR_LCD); #endif #ifdef CAS_SMD_SUPPORT print_bootup_trace_enter(SST_INIT_DRV2_ICC); DalIccInit(); print_bootup_trace_exit(SST_INIT_DRV2_ICC); #endif #if 0 // Init BTIF_HWInit_VFIFO(); in bluetooth module #if defined(__BTMODULE_MT6236__) /* under construction !*/ /* under construction !*/ /* under construction !*/ #elif defined(__BTMODULE_MT6256__) || defined(__BTMODULE_MT6276__) /* under construction !*/ #endif /* under construction !*/ #endif // 0 #if defined(__HW_PFC_SUPPORT__) print_bootup_trace_enter(SST_INIT_DRV2_PFC); DclPFC_Initialize(); print_bootup_trace_exit(SST_INIT_DRV2_PFC); #endif //#if defined(__HW_PFC_SUPPORT__) #ifdef DRV_HIF_SUPPORT hif_init(); #endif #ifdef DRV_SPI_SUPPORT spi_init(); #endif #if defined(TOUCH_PANEL_SUPPORT) DclSTS_Initialize();//always call --- remove the init function from touch_panel_main() #endif #if defined(MOTION_SENSOR_SUPPORT) print_bootup_trace_enter(SST_INIT_DRV2_MSENS); motion_sensor_init(); print_bootup_trace_exit(SST_INIT_DRV2_MSENS); #endif brt_drv_init(); }
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 }
kal_uint8 PW_PowerDetect(void) { #if !defined(DRV_RTC_NOT_EXIST) && !defined(DRV_RTC_OFF) kal_uint8 RTC_Firston; RTC_CTRL_IS_FIRST_ON_T IsFirstOn; kal_uint16 REG_COMM2; kal_uint8 return_value = 0; kal_bool factors[PWR_FACTOR_MAX] = {KAL_FALSE}; DCL_HANDLE rtc_handler; PW_CTRL_POWER_ON_REASON PWRon; RTC_CTRL_CONFIG_PDN_BIT_T rtc_cmd_data18; kal_bool PowerKeyStatus; kal_bool WdtRstFlag; rtc_handler = DclRTC_Open(DCL_RTC, FLAGS_NONE); rtc_cmd_data18.PDNIndex = DCL_RTC_PDN2; DclRTC_Control(rtc_handler, RTC_CMD_READ_PDN_BITS, (DCL_CTRL_DATA_T *)&rtc_cmd_data18); // New API with CMD & DATA REG_COMM2 = rtc_cmd_data18.PDNValue; DclRTC_Control(rtc_handler, RTC_CMD_IS_FIRST_ON, (DCL_CTRL_DATA_T *)&IsFirstOn); // If RTC first on, reset PDN bits to normal reset RTC_Firston = (kal_uint8)IsFirstOn.fgFirstOn; DclRTC_Close(rtc_handler); if (RTC_Firston) { REG_COMM2 = DRV_COMM_REG2_NORMAL_RESET; // REG_COMM2 will be refered in later check } // collect all factors // check RTC expired //if (PW_Is_RTC_Expired()) if (DclPW_Is_RTC_Expired()) { factors[PWR_FACTOR_RTC_EXPIRE] = KAL_TRUE; } PowerKeyStatus = BL_PowerKey_Press(); // check power key pressed if (PowerKeyStatus) { factors[PWR_FACTOR_POWER_KEY] = KAL_TRUE; } if (USBDL_Cable_IN()) { factors[PWR_FACTOR_CHARGER_IN] = KAL_TRUE; } WdtRstFlag = (PW_DRV_ReadReg16(WDT_STATUS) & WDT_STATUS_BITMASK)?(KAL_TRUE):(KAL_FALSE); if (WdtRstFlag) { factors[PWR_FACTOR_WDT_RESET] = KAL_TRUE; } // check flags if (REG_COMM2 & DRV_COMM_REG2_NORMAL_RESET) { factors[PWR_FACTOR_NORMAL_RESET_FLG] = KAL_TRUE; } if (REG_COMM2 & DRV_COMM_REG2_CHRPWRON) { factors[PWR_FACTOR_CHRPWRON_FLG] = KAL_TRUE; } if (REG_COMM2 & DRV_COMM_REG2_USBMS_PWRON) { factors[PWR_FACTOR_USBMS_PWRON_FLG] = KAL_TRUE; } if (REG_COMM2 & DRV_COMM_REG2_RTCPWRON) { factors[PWR_FACTOR_RTCPWRON_FLG] = KAL_TRUE; } if (REG_COMM2 & DRV_COMM_REG2_SWITCH2IDLE_PWRON) { factors[PWR_FACTOR_SWITCH2IDLE_FLG] = KAL_TRUE; } // check power on type // priority: PWRKEYPWRON > ABNRESET > CHRPWRON > USBPWRON_WDT > USBPWRON > RTCPWRON #if defined(DRV_MISC_PWIC_FORCE_RETURN_PWRKEY_POWERON) { kal_uint32 tmp_i; for (tmp_i=0; tmp_i<PWR_FACTOR_MAX;tmp_i++){ factors[tmp_i] = KAL_FALSE; } factors[PWR_FACTOR_SWITCH2IDLE_FLG] = KAL_TRUE; } #endif // #if defined(DRV_MISC_PWIC_FORCE_RETURN_PWRKEY_POWERON) if(factors[PWR_FACTOR_PRECHRPWRON_FLG]) { //BMT.PWRon = (kal_uint8)CHRPWRON;//PRECHRPWRON PWRon=CHRPWRON; } else if (factors[PWR_FACTOR_SWITCH2IDLE_FLG]) { //BMT.PWRon = (kal_uint8)PWRKEYPWRON; PWRon=PWRKEYPWRON; } else if (factors[PWR_FACTOR_SWITCH2CHR_FLG]) { //BMT.PWRon = (kal_uint8)CHRPWRON; PWRon=CHRPWRON; } else if (factors[PWR_FACTOR_SWITCH2USB_FLG]) { //BMT.PWRon = (kal_uint8)USBPWRON; PWRon=USBPWRON; } else if ((factors[PWR_FACTOR_POWER_KEY]&& !factors[PWR_FACTOR_CHARGER_IN]&& !factors[PWR_FACTOR_USB_IN])|| (factors[PWR_FACTOR_POWER_KEY]&& factors[PWR_FACTOR_CHARGER_IN]&& factors[PWR_FACTOR_WDT_RESET]&& factors[PWR_FACTOR_CHRPWRON_FLG])|| (factors[PWR_FACTOR_POWER_KEY]&& factors[PWR_FACTOR_USB_IN]&& factors[PWR_FACTOR_WDT_RESET]&& factors[PWR_FACTOR_USBMS_PWRON_FLG])|| (factors[PWR_FACTOR_POWER_KEY]&& factors[PWR_FACTOR_CHARGER_IN]&& !factors[PWR_FACTOR_WDT_RESET])|| (factors[PWR_FACTOR_POWER_KEY]&& factors[PWR_FACTOR_USB_IN]&& !factors[PWR_FACTOR_WDT_RESET])) { //BMT.PWRon = (kal_uint8)PWRKEYPWRON; PWRon=PWRKEYPWRON; } else if (factors[PWR_FACTOR_WDT_RESET]&&!factors[PWR_FACTOR_CHRPWRON_FLG]&&!factors[PWR_FACTOR_USBMS_PWRON_FLG] &&!factors[PWR_FACTOR_RTCPWRON_FLG]&& !factors[PWR_FACTOR_NORMAL_RESET_FLG]) { //BMT.PWRon = (kal_uint8)ABNRESET; PWRon=ABNRESET; } #ifdef __MA_L1__ /* under construction !*/ /* under construction !*/ /* under construction !*/ /* under construction !*/ /* under construction !*/ #endif // #ifdef __MA_L1__ else if ((factors[PWR_FACTOR_CHARGER_IN]&&!factors[PWR_FACTOR_POWER_KEY])|| (factors[PWR_FACTOR_CHARGER_IN]&&factors[PWR_FACTOR_POWER_KEY]&&!factors[PWR_FACTOR_RTCPWRON_FLG])) { //BMT.PWRon = (kal_uint8)CHRPWRON; PWRon=CHRPWRON; } #ifdef __USB_ENABLE__ else if ((factors[PWR_FACTOR_USB_IN]&&!factors[PWR_FACTOR_POWER_KEY]&&factors[PWR_FACTOR_WDT_RESET]&& !factors[PWR_FACTOR_NORMAL_RESET_FLG]&&factors[PWR_FACTOR_USBMS_PWRON_FLG])) { #if defined(DRV_BMT_NONE_USB_POWER_ON) //BMT.PWRon = (kal_uint8)CHRPWRON; PWRon=CHRPWRON; #else //#if defined(DRV_BMT_NONE_USB_POWER_ON) //BMT.PWRon = (kal_uint8)USBPWRON_WDT; PWRon=USBPWRON_WDT; #endif //#if defined(DRV_BMT_NONE_USB_POWER_ON) } else if ((factors[PWR_FACTOR_USB_IN]&&!factors[PWR_FACTOR_POWER_KEY])|| (factors[PWR_FACTOR_USB_IN]&&factors[PWR_FACTOR_POWER_KEY]&&!factors[PWR_FACTOR_USBMS_PWRON_FLG]) ) { #if defined(DRV_BMT_NONE_USB_POWER_ON) //BMT.PWRon = (kal_uint8)CHRPWRON; PWRon=CHRPWRON; #else //#if defined(DRV_BMT_NONE_USB_POWER_ON) //BMT.PWRon = (kal_uint8)USBPWRON; PWRon=USBPWRON; #endif //#if defined(DRV_BMT_NONE_USB_POWER_ON) } #endif // #ifdef __USB_ENABLE__ else if ((factors[PWR_FACTOR_RTC_EXPIRE]&&!factors[PWR_FACTOR_RTCPWRON_FLG])) { //BMT.PWRon = (kal_uint8)RTCPWRON; PWRon=RTCPWRON; } else { PWRon = UNKNOWN_PWRON; } if ((PWRon == ABNRESET) || (PWRon == UNKNOWN_PWRON)) { return_value = 0; } else { return_value = 0; if (factors[PWR_FACTOR_POWER_KEY]) return_value |= PWR_FACTOR_BL_POWER_KEY; if (factors[PWR_FACTOR_CHARGER_IN]) return_value |= PWR_FACTOR_BL_CABLE_IN; if (factors[PWR_FACTOR_RTC_EXPIRE]) return_value |= PWR_FACTOR_BL_RTC_EXPIRE; if (factors[PWR_FACTOR_NORMAL_RESET_FLG]) return_value |= PWR_FACTOR_BL_NORMAL_RESET_FLG; if (factors[PWR_FACTOR_CHRPWRON_FLG]) return_value |= PWR_FACTOR_BL_CHRPWRON_FLG; if (factors[PWR_FACTOR_USBMS_PWRON_FLG]) return_value |= PWR_FACTOR_BL_USBMS_PWRON_FLG; if (factors[PWR_FACTOR_RTCPWRON_FLG]) return_value |= PWR_FACTOR_BL_RTCPWRON_FLG; if (factors[PWR_FACTOR_SWITCH2IDLE_FLG] | factors[PWR_FACTOR_SWITCH2CHR_FLG] | factors[PWR_FACTOR_SWITCH2USB_FLG]) return_value |= PWR_FACTOR_BL_FACTORY_FLG; } return return_value; #else // #if !defined(DRV_RTC_NOT_EXIST) && !defined(DRV_RTC_OFF) //BMT.PWRon = PWRKEYPWRON; PWRon=PWRKEYPWRON; return_value = 0x1; return return_value; #endif // #if !defined(DRV_RTC_NOT_EXIST) && !defined(DRV_RTC_OFF) }
kal_uint32 F32K_Get_FQMTR_DATA_For_EOSC32_Trimming(kal_uint16 eosccal_value, kal_uint16 winset) { kal_uint16 reg_value, reg_xosccal_value; kal_uint32 FQMTR_DATA, wait_count, latency_time_start; DCL_HANDLE rtc_handler; RTC_CTRL_WRITE_OSC32CON_REG_T rtc_osc32_con; reg_xosccal_value = DRV_F32K_Reg(RTC_XOSCCAL); reg_xosccal_value &= ~0x1f; reg_xosccal_value |= eosccal_value; rtc_handler = DclRTC_Open(DCL_RTC, FLAGS_NONE); rtc_osc32_con.OSC32CON_Reg = reg_xosccal_value; DclRTC_Control(rtc_handler, RTC_CMD_WRITE_OSC32CON_REG, (DCL_CTRL_DATA_T *)&rtc_osc32_con); DclRTC_Close(rtc_handler); reg_value = FQMTR_RST; DRV_F32K_WriteReg(FQMTR_CON0, reg_value); // Stop freq-meter /* latency time (of FQMTR_BUSY bit eable) is 2 tick time of fixed clock fixed clock is EOSC32 clock */ latency_time_start = drv_get_current_time(); // 32k clock time tick wait_count = 0; while(wait_count < 0xffffffff) { if (drv_get_duration_tick(latency_time_start, drv_get_current_time()) > 50) // 25*2 tick break; wait_count++; } #if defined(DRV_F32K_FQMTR_AS_6255) while(DRV_F32K_Reg(FQMTR_CON2) & FQMTR_BUSY); reg_value = FQMTR_EN | winset; DRV_F32K_WriteReg(FQMTR_CON0, reg_value); // start freq-meter #elif defined(DRV_F32K_FQMTR_AS_6250) while(DRV_F32K_Reg(FQMTR_CON0) & FQMTR_BUSY); reg_value = winset; DRV_F32K_WriteReg(FQMTR_CON3, reg_value); // start freq-meter reg_value = FQMTR_EN; DRV_F32K_WriteReg(FQMTR_CON0, reg_value); // start freq-meter #endif /* latency time (of FQMTR_BUSY bit eable) is 2 tick time of fixed clock fixed clock is EOSC32 clock */ latency_time_start = drv_get_current_time(); // 32k clock time tick wait_count = 0; while(wait_count < 0xffffffff) { if (drv_get_duration_tick(latency_time_start, drv_get_current_time()) > 50) // 25*2 tick break; wait_count++; } #if defined(DRV_F32K_FQMTR_AS_6255) while(DRV_F32K_Reg(FQMTR_CON2) & FQMTR_BUSY); #elif defined(DRV_F32K_FQMTR_AS_6250) while(DRV_F32K_Reg(FQMTR_CON0) & FQMTR_BUSY); #endif /* latency time (of get fqmtr_data ) is 1 tick time of test clock test clock is 13M clock */ latency_time_start = drv_get_current_time(); wait_count = 0; while(wait_count<0xffffffff) { if (drv_get_duration_tick(latency_time_start, drv_get_current_time()) > 10) // 10 32K tick break; wait_count++; } #if defined(DRV_F32K_FQMTR_AS_6255) //FQMTR_DATA = ((DRV_F32K_Reg(FQMTR_CON3)&0x7fff)<<15)|((DRV_F32K_Reg(FQMTR_CON2)&0x7fff)); FQMTR_DATA = DRV_F32K_Reg(FQMTR_CON2)&0x7fff; #elif defined(DRV_F32K_FQMTR_AS_6250) FQMTR_DATA = DRV_F32K_Reg(FQMTR_CON2); #endif return FQMTR_DATA; }