Ejemplo n.º 1
0
Archivo: gpt.c Proyecto: 12019/mtktest
/*
* FUNCTION                                                            
*	GPTI_StopItem
*
* DESCRIPTION                                                           
*   	GPT stop a item.
*
* CALLS  
*
* PARAMETERS
*	moudle = UART_Module, SIM_Module, GPT_Module
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*   external_global
*/
void GPTI_StopItem(kal_uint8 module)
{
   kal_uint32 savedMask;
   savedMask = SaveAndSetIRQMask();
   GPTTimer.status &= ~(1<<module);
   if (GPTTimer.status == 0)
   {
      GPTTimer.GPTSTOP = KAL_TRUE;
      GPTTimer.GPT_TICK = 0;
      RestoreIRQMask(savedMask);
      savedMask = SaveAndSetIRQMask();
      if (((volatile kal_bool)GPTTimer.GPTSTOP) == KAL_TRUE)
         GPT_Stop(gptimer_num);
   }
   RestoreIRQMask(savedMask);
}
Ejemplo n.º 2
0
Archivo: gpt.c Proyecto: 12019/mtktest
/*
* FUNCTION                                                            
*	GPTI_HISR
*
* DESCRIPTION                                                           
*   	GPTI HISR
*
* CALLS
*
* PARAMETERS
*	void
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*   external_global
*/
void GPTI_HISR(void)
{
   kal_uint8 index;
   
   for (index = 0;index < GPTTimer.MAX_GPTIMER_ITEMS;index++)
   {
      GPTProcess(index);
   }
   
   GPTTimer.GPT_TICK++;
   
   if (GPTTimer.status == 0)
   {
      GPTTimer.GPTSTOP = KAL_TRUE;
      GPTTimer.GPT_TICK = 0;
      GPT_Stop(gptimer_num);
   }
}
/*-----------------------------------------------------------------------*
* 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;
}
Ejemplo n.º 4
0
void sc_dpidle_after_wfi(void)
{
#ifdef PROFILE_DPIDLE
    dpidle_tick_pos = GPT_GetCounter(GPT2);
    dpidle_wakeup_src = DRV_Reg32(SC_WAKEUP_SRC);
    if (dpidle_debug_mask & DEBUG_PROFILE) {
#ifdef CONFIG_LOCAL_TIMERS
        dcm_info("[%s]%5d %10u %10u %10u %10u %08x\n", __func__, 
                dpidle_profile_idx, dpidle_tick_pre, dpidle_tick_mid, dpidle_tick_pos,
                dpidle_counter, dpidle_wakeup_src);
#else
        dcm_info("[%s]%5d %10u %10u %10u %10u %10u %10u %08x\n", __func__, 
                dpidle_profile_idx, dpidle_tick_pre, dpidle_tick_mid, dpidle_tick_pos,
                dpidle_counter, dpidle_compare, dpidle_compare_update, dpidle_wakeup_src);

#endif
        dpidle_profile_idx++;
    }
#endif

#ifdef CONFIG_LOCAL_WDT
    wdt_tick_pos = GPT_GetCounter(GPT2);
    if (wdt_counter_pre > (wdt_tick_pos - wdt_tick_pre)) {
        wdt_counter_pos = wdt_counter_pre - (wdt_tick_pos - wdt_tick_pre);
        mpcore_wdt_set_counter(wdt_counter_pos);
    } else {
        dcm_info("[%s]:wdt_counter_pre=%10lu, wdt_tick_pre=%10lu, wdt_tick_pos=%10lu\n", 
                __func__, wdt_counter_pre, wdt_tick_pre, wdt_tick_pos);
        mpcore_wdt_set_counter(1);
    }
#endif

#ifdef CONFIG_LOCAL_TIMERS
    if (GPT_Get_IRQ(WAKEUP_GPT)) {
        /* waked up by WAKEUP_GPT */
        localtimer_set_next_event(1);
    } else {
        /* waked up by other wakeup source */
        unsigned int temp1 = GPT_GetCompare(WAKEUP_GPT);
        unsigned int temp2 = GPT_GetCounter(WAKEUP_GPT);
        if (unlikely(temp1 <= temp2)) {
            dcm_err("[%s]GPT%d: counter = %10u, compare = %10u\n", __func__, temp1, temp2);
            BUG();
        }

        localtimer_set_next_event(temp1-temp2);
        GPT_Stop(WAKEUP_GPT);
        GPT_ClearCount(WAKEUP_GPT);
    }
#endif

    if (get_chip_eco_ver() == CHIP_E1) {
        DRV_SetReg32(WPLL_CON0, 0x1);        
    } else {
        if (mmsys_switched_off) {
            DRV_ClrReg16(MDPLL_CON0, 0x1);
            udelay(20);
            mm_clk_sq2pll();
            mmsys_switched_off = 0;
        }
    }   

#if 0
    /* restore TOP_MISC */
    DRV_WriteReg32(TOP_MISC, topmisc);
#endif

    dpidle_count++;
    if ((dpidle_debug_mask & DEBUG_TRACING)) {
        dpidle_single_count++;
    }
}
/*-----------------------------------------------------------------------*
* 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;
}