Example #1
0
File: gpt.c Project: 12019/mtktest
/*
* FUNCTION                                                            
*	GPTI_init
*
* DESCRIPTION                                                           
*   	Initialize the GPTI module with GPT
*
* CALLS
*
* PARAMETERS
*	None
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*   external_global
*/
void GPTI_init(void)
{
   if (GPTTimer.hisr == NULL)
   {
      //GPTTimer.hisr = kal_create_hisr("GPTIMER",2,512,GPTI_HISR,NULL);
      GPTTimer.hisr= (void*)0x1234;
      DRV_Register_HISR(DRV_GPT_HISR_ID, GPTI_HISR);
   }   
   GPT_init(gptimer_num,GPTI_Callback);
   GPT_ResetTimer(gptimer_num,gptimer_interval-1,KAL_TRUE);
   GPTTimer.GPT_TICK = 0;
   GPTTimer.MAX_GPTIMER_ITEMS = 0;
   GPTTimer.GPTSTOP = KAL_TRUE;
   GPTTimer.status =0;
}
Example #2
0
/*
* 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();
}
/*-----------------------------------------------------------------------*
* FUNCTION
*  DclHGPT_Control
*
* DESCRIPTION
*  This function is to send command to control the HW GPT module.
*
* PARAMETERS
*	handle - a valid handle return by DclHGPT_Open()
*  cmd   - a control command for HW GPT module
*          1. HGPT_CMD_CLK: to set clock for a HW GPT timer
*          2. HGPT_CMD_RESET: to reset a HWGPT timer
*          3. HGPT_CMD_START: to start a HW GPT timer
*          4. HGPT_CMD_STOP: to stop a HWGPT timer
*  data - for 1. HGPT_CMD_CLK: pointer to a HGPT_CTRL_CLK_T structure
*             2. HGPT_CMD_RESET: pointer to a HGPT_CTRL_RESET_T structure
*             3. HGPT_CMD_START: a NULL pointer
*             4. HGPT_CMD_STOP: a NULL pointer
*
* RETURNS
*	STATUS_OK - command is executed successfully.
*	STATUS_FAIL - command is failed.
*  STATUS_INVALID_CMD - The command is invalid.
*  STATUS_INVALID_DCL_HANDLE - The handle is invalid.
*  STATUS_INVALID_CTRL_DATA - The ctrl data is not valid.
*
*------------------------------------------------------------------------*/
DCL_STATUS DclHGPT_Control(DCL_HANDLE handle, HGPT_CMD cmd, HGPT_CTRL *data)
{
   DCL_DEV  eDev;
   kal_uint8 u1TimerNum = 0;
   register kal_uint32 savedMask;
   if (!DCL_HGPT_IS_HANDLE_MAGIC(handle))
   {
      ASSERT(0);
      return STATUS_INVALID_DCL_HANDLE;
   }
   eDev = DCL_HGPT_GET_DEV(handle);
   switch(eDev)
   {
   	case GPT1:
	      if (KAL_FALSE == fgGPT1Open)
	      {
	         return STATUS_NOT_OPENED;//should we add assert ?
	      }
	      u1TimerNum = 1;
	      break;
		case GPT2:
	      if (KAL_FALSE == fgGPT2Open)
	      {
				return STATUS_NOT_OPENED;
	      }
	      u1TimerNum = 2;
	      break;
   	default:
	      ASSERT(0);
	      return STATUS_INVALID_DCL_HANDLE;
   }
   switch(cmd)
   {
   	case HGPT_CMD_CLK:
      {
         HGPT_CTRL_CLK_T   *prClock;
         prClock = &(data->rHGPTClk);
         switch(prClock->u4Clock)
         {
	         case CLK_16K:
	            eClock[u1TimerNum-1] = clk_16k;
	            break;
	         case CLK_8K:
	            eClock[u1TimerNum-1] = clk_8k;
	            break;
	         case CLK_4K:
	            eClock[u1TimerNum-1] = clk_4k;
	            break;
	         case CLK_2K:
	            eClock[u1TimerNum-1] = clk_2k;
	            break;
	         case CLK_1K:
	            eClock[u1TimerNum-1] = clk_1k;
	            break;
	         case CLK_500:
	            eClock[u1TimerNum-1] = clk_500;
	            break;
	         case CLK_250:
	            eClock[u1TimerNum-1]= clk_250;
	            break;
	         case CLK_125:
	            eClock[u1TimerNum-1]= clk_125;
	            break;
	         default:
	            ASSERT(0);
	            return STATUS_INVALID_CTRL_DATA;
			}
		 
			GPT_PDN_enable();
			GPT_clock(u1TimerNum, eClock[u1TimerNum-1]);
                        if(KAL_TRUE==GPT_IsStop())			
                            GPT_PDN_disable();
			break;
      }
   	case HGPT_CMD_RESET:
      {
         HGPT_CTRL_RESET_T   *prReset;
         prReset = &(data->rHGPTReset);
		 GPT_PDN_enable();
         GPT_ResetTimer(u1TimerNum, prReset->u2CountValue, prReset->fgAutoReload);
               if(KAL_TRUE==GPT_IsStop())		 
                   GPT_PDN_disable();
      }
      break;
   	case HGPT_CMD_START:
      	GPT_Start(u1TimerNum);
      	break;
   	case HGPT_CMD_STOP:
   	{
   	#if defined(__ENABLE_GPT_PROTECTION__)
      //savedMask = SaveAndSetIRQMask();
      savedMask = kal_take_thread_protect();
	if(u1TimerNum==1)
	{
      if ((GPTTimer.GPTSTOP) == KAL_TRUE)
         GPT_Stop(u1TimerNum);
	}
	else
	{
	   GPT_Stop(u1TimerNum);
	}
	 kal_give_thread_protect(savedMask);
     // RestoreIRQMask(savedMask); 
    #else
	if(u1TimerNum==1)
	{
            savedMask = SaveAndSetIRQMask();
            if ((GPTTimer.GPTSTOP) == KAL_TRUE)
            #if defined(DRV_GPT_STOP_2_STEP)
            {
               GPT_Stop_Step1(u1TimerNum);
               RestoreIRQMask(savedMask);
               savedMask = SaveAndSetIRQMask();
               if ((GPTTimer.GPTSTOP) == KAL_TRUE)
                   GPT_Stop_Step2();
             }
            #else
      	    GPT_Stop(u1TimerNum);
            #endif //#if defined(DRV_GPT_STOP_2_STEP)
            RestoreIRQMask(savedMask);
        }
        else
        {
            	savedMask = SaveAndSetIRQMask();
    	        #if defined(DRV_GPT_STOP_2_STEP)
                {
            	   GPT_Stop_Step1(u1TimerNum);
               	   RestoreIRQMask(savedMask);
               	   savedMask = SaveAndSetIRQMask();
                   GPT_Stop_Step2();
                }
            	#else
                GPT_Stop(u1TimerNum);
    	        #endif //#if defined(DRV_GPT_STOP_2_STEP)
                RestoreIRQMask(savedMask);				
        }
	  #endif
        }  
      	break;
   	default:
      	ASSERT(0);
      	return STATUS_INVALID_CMD;
   }
   return STATUS_OK;
}