Example #1
0
File: gpt.c Project: 12019/mtktest
/*
* FUNCTION                                                            
*	GPTI_StartItem
*
* DESCRIPTION                                                           
*   	GPT start a item.
*
* CALLS  
*
* PARAMETERS
*	moudle = UART_Module, SIM_Module, GPT_Module
*	tick = the delay(the unit is 10ms)
*  gptimer_func = the callback function when the tick is reached.
*  parameter = the parameter inputed into gptimer_func
*
* RETURNS
*	KAL_TRUE, start item successfully
*  KAL_FALSE, start item fail
*
* GLOBALS AFFECTED
*   external_global
*/
kal_bool GPTI_StartItem(kal_uint8 module,kal_uint16 tick,void (*gptimer_func)(void *),void *parameter)
{
   kal_uint32 savedMask;
   if (GPTTimer.status & (1<<module))
   {
      return KAL_FALSE;
   }
   
   GPTTimer.GPTItems[module].tick = GPTTimer.GPT_TICK+tick;
   GPTTimer.GPTItems[module].gptimer_func = gptimer_func;
   GPTTimer.GPTItems[module].parameter = parameter;
   savedMask = SaveAndSetIRQMask();
   //if (tick == 0)
   //   tick =1;

   GPTTimer.status |= (1<<module);
   if(GPTTimer.GPTSTOP == KAL_TRUE)
   {
      GPTTimer.GPTSTOP = KAL_FALSE;
      RestoreIRQMask(savedMask);
      savedMask = SaveAndSetIRQMask();
      if (((volatile kal_bool)GPTTimer.GPTSTOP) == KAL_FALSE)
         GPT_Start(gptimer_num);
   }
   
   RestoreIRQMask(savedMask);
   return KAL_TRUE;
}
Example #2
0
File: dbg.c Project: janfj/dd-wrt
/* for driver profile */
#define TICKS_ONE_MS  (13000)
u32 gpt_enable = 0;
u32 sdio_pro_enable = 0;   /* make sure gpt is enabled */
u32 sdio_pro_time = 0;     /* no more than 30s */
struct sdio_profile sdio_perfomance = {0};  

#if 0 /* --- chhung */
void msdc_init_gpt(void)
{
    GPT_CONFIG config;	
    
    config.num  = GPT6;
    config.mode = GPT_FREE_RUN;
    config.clkSrc = GPT_CLK_SRC_SYS;
    config.clkDiv = GPT_CLK_DIV_1;   /* 13MHz GPT6 */
            
    if (GPT_Config(config) == FALSE )
        return;                       
        
    GPT_Start(GPT6);	
}
Example #3
0
bool sc_dpidle_can_enter(void)
{
#ifdef PROFILE_IDLE
    dpidle_tick_pre = GPT_GetCounter(GPT2);
#endif

#ifdef CONFIG_LOCAL_TIMERS
    dpidle_counter = localtimer_get_counter();
    if (dpidle_counter >= dpidle_time_critera) { // 13000 => 1ms
        GPT_SetCompare(WAKEUP_GPT, dpidle_counter);
        GPT_Start(WAKEUP_GPT);
        dpidle_state = 1;
        return true; 
    }

    if (dpidle_debug_mask & DEBUG_TRACING) {
        if (dpidle_counter > dpidle_block_interval) {
            dpidle_block_interval = dpidle_counter;
        }
        dpidle_sc_block_cnt++;
    }
#else /* !SMP */
    dpidle_counter = GPT_GetCounter(GPT1);
    dpidle_compare = GPT_GetCompare(GPT1);

    if (dpidle_compare >= dpidle_counter + dpidle_time_critera) { // 13000 => 1ms
        dpidle_state = 1;
        return true; 
    }

    if (dpidle_debug_mask & DEBUG_TRACING) {
        unsigned int delta = dpidle_compare - dpidle_counter;
        if (delta > dpidle_block_interval) {
            dpidle_block_interval = delta;
        }
        dpidle_sc_block_cnt++;
    }
#endif

    dpidle_state = 0;
    return false;
}
Example #4
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
*  DclFHGPT_Control
*
* DESCRIPTION
*  This function is to send command to control the free run GPT module.
*
* PARAMETERS
*	handle - a valid handle return by DclFHGPT_Open()
*  cmd   - a control command for free ryb GPT module
*          FHGPT_CMD_RETURN_COUNT: to get the timer count
*  data - for FHGPT_CMD_RETURN_COUNT: pointer to a FGPT_CTRL_RETURN_COUNT_T type
*
* RETURNS
*	STATUS_OK - command is executed successfully.
*	STATUS_FAIL - command is failed. No free run GPT is supported.
*  STATUS_INVALID_CMD - The command is invalid.
*  STATUS_INVALID_DCL_HANDLE - The handle is invalid.
*
*------------------------------------------------------------------------*/
DCL_STATUS DclFHGPT_Control(DCL_HANDLE handle, HGPT_CMD cmd, HGPT_CTRL *data)
{
   DCL_DEV  eDev;
   if(!DCL_FGPT_IS_HANDLE_MAGIC(handle))
   {
		ASSERT(0);
		return STATUS_INVALID_DCL_HANDLE;
   }
   
   eDev = DCL_FGPT_GET_DEV(handle);
   if(eDev != GPT3 && eDev != GPT4)
   {
		ASSERT(0);
		return DCL_HANDLE_INVALID;
   }
   switch(cmd)
   {
		case FHGPT_CMD_START:
			#if defined(DRV_GPT_GPT3)
			if (eDev==GPT3)
			{
      		GPT_Start(GPT3);
			}
			#endif
			
			#if defined(DRV_GPT_GPT4)
			if (eDev==GPT4)
			{
				GPT_Start(GPT4);
			}
			#endif
			//this judgment can be move to front and only do once.
			#if !defined(DRV_GPT_GPT3) && !defined(DRV_GPT_GPT4)
      	return STATUS_FAIL;
			#endif
      break;
		case FHGPT_CMD_STOP:
			#if defined(DRV_GPT_GPT3)
			if (eDev==GPT3)
			{
		      GPT_Stop(GPT3);
			}
			#endif
		
			#if defined(DRV_GPT_GPT4)
			if (eDev==GPT4)
			{
				GPT_Stop(GPT4);
			}
			#endif
		
			#if !defined(DRV_GPT_GPT3) && !defined(DRV_GPT_GPT4)
			return STATUS_FAIL;
			#endif
		break;
		case FHGPT_CMD_RETURN_COUNT:
			#if defined(DRV_GPT_GPT3)
			if (eDev==GPT3)
			{
		      data->u2RetCount = GPT_return_current_count();
			}
			#endif
		
			#if defined(DRV_GPT_GPT4)
			if (eDev==GPT4)
			{
				 data->u2RetCount_32bit = GPT4_return_current_count();
			}
			#endif
			#if !defined(DRV_GPT_GPT3) && !defined(DRV_GPT_GPT4)
		      return STATUS_FAIL;
			#endif
		break;
		case FHGPT_CMD_LOCK:
		#if defined(DRV_GPT_GPT4)  
		if(eDev==GPT4)
		{
			if(data->ulock ==0)
				GPT4_Lock(KAL_FALSE);
			else if(data->ulock ==1)
				GPT4_Lock(KAL_TRUE);
			else
				{
					ASSERT(0);
				}	  		
		}
		#endif 
		break;		
		default:
			ASSERT(0);
			return STATUS_INVALID_CMD;
	}
   return STATUS_OK;
}
/*-----------------------------------------------------------------------*
* 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;
}