Example #1
0
File: Eint.c Project: 12019/mtktest
/*************************************************************************
* FUNCTION
*  EINT_Set_Sensitivity
*
* DESCRIPTION
*   This function dedicates to set the sensitivity of external 
*   interrupts.
*
* CALLS
*
* PARAMETERS
*   eintno   -   External interrupt vector number
*   sens     -   EDGE_SENSITIVE or LEVEL_SENSITIVE
*
* RETURNS
*   0 for success; -1 for failure
*
* GLOBALS AFFECTED
*
*************************************************************************/
kal_uint32 EINT_Set_Sensitivity(kal_uint8 eintno, kal_bool sens)
{
   kal_uint32 savedMask;
#if defined(MT6205) || defined(MT6205B) || defined(MT6208)

   return -1;
   
#else
   if (eintno >= EINT_MAX_CHANNEL) {
      /* not support level trigger */
      return -1;
   }
   /* Save and set MCU's I,F bits to disable interrupts */
   savedMask = LockIRQ();

   if (sens == EDGE_SENSITIVE) {
      *EINT_SENS &= ~(1 << eintno);
   } else if (sens == LEVEL_SENSITIVE) {
      *EINT_SENS |= (1 << eintno);
   }
   /* Restore previous MCU's I,F bits setting */
   RestoreIRQ(savedMask);

   return 0;
#endif
}
Example #2
0
/*************************************************************************
* FUNCTION
*  ADIE_SetINTMask
*
* DESCRIPTION
*  This function mask interrupt line and returned special pattern.
*
* PARAMETERS
*  code : Interrupt source of interrupt controller
*
* RETURNS
*  
*  
*************************************************************************/
void ADIE_SetINTMask(kal_uint8 code)
{
    kal_uint32 savedMask;
    kal_uint8  line;   

    ASSERT(code < ADIE_NUM_IRQ_SOURCES);

    line = ADIE_IRQCode2Line[code];
    
    /*
     * [Important]
     * IRQ mask will be valid around 2T ~ 3T after register is written. 
     * To ensure IRQ is turned off thoroughly, I bit must be disabled in 
     * advanced; otherwise, IRQ may be triggered unexpectedly.
     */
    
    savedMask = LockIRQ();
    
    ASSERT(ADIE_INTMaskCount[line]<254); 
     
    if(++ADIE_INTMaskCount[line]==1)
    {
        *ADIE_IRQ_MASK_SET0 = (1 << line);
    }
    
    RestoreIRQ(savedMask);    
}
Example #3
0
File: Eint.c Project: 12019/mtktest
/*************************************************************************
* FUNCTION
*  EINT_Set_Polarity
*
* DESCRIPTION
*   This function sets the polarity of external interrupts
*
* CALLS
*
* PARAMETERS
*  eintno            -     External interrupt vector number
*  ACT_Polarity      -     Interrupt polarity
*
* RETURNS
*  No return
*
* GLOBALS AFFECTED
*
*************************************************************************/
void EINT_Set_Polarity(kal_uint8 eintno, kal_bool ACT_Polarity)
{
   kal_uint32 savedMask;
   kal_uint32 count;

   /* Save and set MCU's I,F bits to disable interrupts */
   savedMask = LockIRQ();

   /* Set external interrupt polarity */
   if (ACT_Polarity) 
      EINTaddr(eintno) |= EINT_CON_HIGHLEVEL;
   else
      EINTaddr(eintno) &= ~(EINT_CON_HIGHLEVEL);

   for (count=0; count<250; count++) ;  /*250:52M*/

   *EINT_INTACK = EINT_INTACK_EINT(eintno);

#if ( defined(MT6228) || defined(MT6229) || defined(MT6230) || defined(MT6238))

   *IRQ_EOI2 = IRQCode2Line[IRQ_EIT_CODE];

#else   

   *IRQ_EOI = (1 << IRQCode2Line[IRQ_EIT_CODE]);

#endif
   
   /* Restore previous MCU's I,F bits setting */
   RestoreIRQ(savedMask);
}
/*************************************************************************
* FUNCTION
*  USC_Wake_Up_Init
*
* DESCRIPTION
*  This function is used to initialize the us counter variable during waking up to fixed us HW bug. 
*  ths function is only called by  UL1SM_Interrupt (3G wake-up LISR) and L1SM_TDMAInterrupt (2G wake up LISR)
*
* PARAMETERS
*  Timer       -    0: use TDMA timer, 1: use RTR timer
*
* RETURNS
*  none
*
*************************************************************************/
void USC_Wake_Up_Init( kal_uint32  Timer )
{
#if defined(MT6268_S00)

    kal_uint32 irq;
     irq = LockIRQ();
	 
    if( Wake_US_Updated == 0)
    {
      Wake_USCNTI = HW_READ(USCNTI_VAL);
        Wake_Timer = Timer;
        Wake_33us_TimeOut = 0;	
        if( Timer == 0 )
	       Wake_TimerCnt = HW_READ(US_TD_Timer);
        else
         Wake_TimerCnt = HW_READ(US_RTR_Timer) & 0x7FFF ;
	Wake_US_Updated = 1;
	
	//Wake_Temp_Dur = 0;
	//Wake_Timer_Count = 0;
    }

    RestoreIRQ(irq & 0x000000c0);
	
#endif	
	
}
Example #5
0
/*************************************************************************
* FUNCTION
*  ADIE_IRQUnmask
*
* DESCRIPTION
*  Mask certain interrupt source.
*
* PARAMETERS
*  Interrupt source to be masked, it is indexed via IRQCode2Line.
*
* RETURNS
*
*************************************************************************/
void ADIE_IRQUnmask(kal_uint8 code)
{
    kal_uint32 savedMask;
    kal_uint8  line;   
    
    ASSERT(code < ADIE_NUM_IRQ_SOURCES);

    /* Debug code for DIE2DIE IRQ, shouldbe phased out by W12.28 */    
#if 0
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif

    line = ADIE_IRQCode2Line[code];

    savedMask = LockIRQ();

    ASSERT(ADIE_INTMaskCount[line]==0 || ADIE_INTMaskCount[line]==255);

    ADIE_INTMaskCount[line]= 0;
    
    *ADIE_IRQ_MASK_CLR0= (1 << line);

    RestoreIRQ(savedMask);
}  
Example #6
0
/*************************************************************************
* FUNCTION
*  ADIE_IRQMask
*
* DESCRIPTION
*  Mask certain interrupt source.
*
* PARAMETERS
*  Interrupt source to be masked, it is indexed via IRQCode2Line.
*
* RETURNS
*
*************************************************************************/
void ADIE_IRQMask(kal_uint8 code)
{
    kal_uint32 savedMask;
    kal_uint8  line;   
    
    ASSERT(code < ADIE_NUM_IRQ_SOURCES);
    
#if 0
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif

    line = ADIE_IRQCode2Line[code];

    /*
     * [Important]
     * IRQ mask will be valid around 2T ~ 3T after register is written. 
     * To ensure IRQ is turned off thoroughly, I bit must be disabled in 
     * advanced; otherwise, IRQ may be triggered unexpectedly.
     */
    savedMask = LockIRQ();
    
    ASSERT(ADIE_INTMaskCount[line]==0 || ADIE_INTMaskCount[line]==255);
    
    ADIE_INTMaskCount[line] = 255;
    
    *ADIE_IRQ_MASK_SET0= (1 << line);

    RestoreIRQ(savedMask);
}  
Example #7
0
/*************************************************************************
* FUNCTION
*  IRQ_Register_LISR
*
* DESCRIPTION
*   This function implement method to register IRQ's LISR.
*
* CALLS
*
* CALL BY
*
* PARAMETERS
*  irqvector   -  vector number to register
*  reg_lisr    -  register LISR's handler
*  description -  LISR's description pointer to be saved.
*     Remember, the routine won't duplicate the description,
*     therefore, caller shouldn't free the description.
*
* RETURNS
*
*************************************************************************/
void IRQ_Register_LISR_2(kal_uint32 irqvector, void (*reg_lisr)(kal_uint32), char* description)
//void IRQ_Register_LISR(kal_uint32 irqvector, void (*reg_lisr)(kal_uint32), char* description)
{
   kal_uint32 savedMask;

   savedMask = LockIRQ();
   lisr_dispatch_tbl[irqvector].vector = irqvector;
   lisr_dispatch_tbl[irqvector].lisr_handler = reg_lisr;
   lisr_dispatch_tbl[irqvector].description = description;
   RestoreIRQ(savedMask);
}
/*************************************************************************
* FUNCTION
*  IRQ_Register_LISR
*
* DESCRIPTION
*   This function implement method to register IRQ's LISR.
*
* CALLS
*
* CALL BY
*
* PARAMETERS
*  irqvector   -  vector number to register
*  reg_lisr    -  register LISR's handler
*  description -  LISR's description pointer to be saved.
*     Remember, the routine won't duplicate the description,
*     therefore, caller shouldn't free the description.
*
* RETURNS
*
*************************************************************************/
void IRQ_Register_LISR(kal_uint32 code, void (*reg_lisr)(void), char* description)
{
   kal_uint32 savedMask;
   kal_uint32 irqvector;

   savedMask = LockIRQ();
   irqvector = IRQCode2Line[code];
   lisr_dispatch_tbl[irqvector].vector = irqvector;
   lisr_dispatch_tbl[irqvector].lisr_handler = reg_lisr;
   lisr_dispatch_tbl[irqvector].description = description;
   RestoreIRQ(savedMask);
}
Example #9
0
File: Eint.c Project: 12019/mtktest
/*************************************************************************
* FUNCTION
*   EINT_SW_Debounce_Modify
*
* DESCRIPTION
*   Setting debounce time
*
* CALLS
*
* PARAMETERS
*
* RETURNS
*  No return
*
* GLOBALS AFFECTE
*
*************************************************************************/
kal_int32 EINT_SW_Debounce_Modify(kal_uint8 eintno, kal_uint8 debounce_time)
{
   kal_uint32 savedMask;
   
   if ( eintno>=EINT_MAX_CHANNEL )
      return -1;

   savedMask = DisableIRQ();      
   eint_sw_debounce_time_delay[eintno] = debounce_time;
   RestoreIRQ(savedMask);
   
   return 1;
}
Example #10
0
File: Eint.c Project: 12019/mtktest
/*************************************************************************
* FUNCTION
*  EINT_UnMask
*
* DESCRIPTION
*   This function implements Unmask of dedicated external interrupt source
*
* CALLS
*
* PARAMETERS
*  eintno         - external interrupt vector number
*
* RETURNS
*  No return
*
* GLOBALS AFFECTED
*
*************************************************************************/
void EINT_UnMask(kal_uint8 eintno)
{
#if defined(MT6205) || defined(MT6208) || defined(FPGA) 

   kal_uint32 savedMask;
   
   savedMask = LockIRQ();
   *EINT_MASK &= ~(0x0001 << eintno);
   RestoreIRQ(savedMask);
   
#else

   *EINT_MASK_CLR = (0x0001 << eintno);
   
#endif 
}
Example #11
0
/*************************************************************************
* FUNCTION
*  ADIE_RestoreINTMask
*
* DESCRIPTION
*  This function unmask interrupt line and .
*
* PARAMETERS
*  code : Interrupt source of interrupt controller
*
* RETURNS
*  none
*  
*************************************************************************/
void ADIE_RestoreINTMask(kal_uint8 code)
{
    kal_uint32 savedMask;
    kal_uint8  line;   

    ASSERT(code < ADIE_NUM_IRQ_SOURCES);

    line = ADIE_IRQCode2Line[code];
    
    savedMask = LockIRQ();
    
    ASSERT(ADIE_INTMaskCount[line]<254); 
     
    if(--ADIE_INTMaskCount[line]==1)
    {
        *ADIE_IRQ_MASK_CLR0 = (1 << line);
    }
    RestoreIRQ(savedMask);    
}
Example #12
0
File: Eint.c Project: 12019/mtktest
/*************************************************************************
* FUNCTION
*  EINT_RestoreMask
*
* DESCRIPTION
*  This function restores the MASK of the specified external interrupt
*
* PARAMETERS
*  val   -   value to restore
*
* RETURNS
*  No return
*
*************************************************************************/
void EINT_RestoreMask(kal_uint8 eintno, kal_uint32 val)
{
   kal_uint32 savedMask;


   /* lockout interrupt */   
   savedMask = LockIRQ();

   /*
    * NoteXXX: The external interrup should already be masked here (via the
    *          EINT_SaveAndMask() call). Only need to change the EINT_MASK 
    *          when the external interrupt is originally un-masked.
    */
   if (val == 0) {
       *EINT_MASK &= ~(0x0001 << eintno);
   }
   
   /* un-lockout interrupt */
   RestoreIRQ(savedMask);
}
Example #13
0
File: Eint.c Project: 12019/mtktest
/*************************************************************************
* FUNCTION
*  EINT_SaveAndMask
*
* DESCRIPTION
*  This function saves and masks the specified external interrupt
*
* PARAMETERS
*  eintno   -   external interrupt vector number
*
* RETURNS
*  original mask
*
*************************************************************************/
kal_uint32 EINT_SaveAndMask(kal_uint8 eintno)
{
   kal_uint32 savedMask, eint_mask;


   /* lockout interrupt */
   savedMask = LockIRQ();

   /* save EINT mask */
   eint_mask = *EINT_MASK;

   /* mask EINT */
   *EINT_MASK |= (0x0001 << eintno);

   /* un-lockout interrupt */
   RestoreIRQ(savedMask);

   /* clear unnecessary bits */
   eint_mask = eint_mask & (0x0001 << eintno);

   return eint_mask;
}
Example #14
0
File: Eint.c Project: 12019/mtktest
void EINT_Registration(kal_uint8 eintno, kal_bool Dbounce_En, kal_bool ACT_Polarity, \
                       void (reg_hisr)(void), kal_bool auto_umask)
{
   kal_uint32 savedMask;
   kal_uint16 count;


   EXT_ASSERT(eintno < EINT_TOTAL_CHANNEL, eintno, Dbounce_En, ACT_Polarity);
   
   IRQ_Register_LISR(IRQ_EIT_CODE, EINT_LISR, "EINT handler");

   /* Save and set MCU's I,F bits to disable interrupts */
   savedMask = LockIRQ();

   /* Set external interrupt polarity */
   if (ACT_Polarity) 
      EINTaddr(eintno) |= EINT_CON_HIGHLEVEL;
   else
      EINTaddr(eintno) &= ~(EINT_CON_HIGHLEVEL);

   /*
    * NoteXXX: Only EINT 0 ~ (EINT_MAX_CHANNLE - 1) support level trigger.
    *          The de-bounce time is only for level trigger EINT.
    */
   if (eintno < EINT_MAX_CHANNEL) {
      /* Set external interrupt debounce control enable or not */
      if (Dbounce_En) {
         /* check if debounce is enabled */
         if (EINTaddr(eintno) & EINT_CON_DEBOUNCE_EN) {
            /* debounce value is already set; NOP */
         } else {
            EINTaddr(eintno) |= (EINT_CON_DEBOUNCE | EINT_CON_DEBOUNCE_EN);
         }
      }
   else
   {
      /*disable debounce */
      EINTaddr(eintno) &= ~(EINT_CON_DEBOUNCE_EN);
   }
   }

   /* Register external interrupt's HISR */
   EINT_FUNC.eint_func[eintno] = reg_hisr;
   EINT_FUNC.eint_active[eintno] = KAL_FALSE;
   EINT_FUNC.eint_auto_umask[eintno] = auto_umask;

   /* register HISR */
   DRV_Register_HISR(DRV_EINT_HISR_ID, EINT_HISR_Entry);
   
   /* Restore previous MCU's I,F bits setting */
   RestoreIRQ(savedMask);

   /*
    * XXX!!!. Hardware bug
    *    - must wait for 32khz/1 sec to write mask register, will be
    *    fixed in future.
    */
   for (count=0; count<250; count++) ;  /*250:52M*/

   savedMask = LockIRQ();

   *EINT_INTACK = EINT_INTACK_EINT(eintno);
   
#if defined(MT6205) || defined(MT6208) || defined(FPGA) 
   *EINT_MASK &= ~(0x0001 << eintno);
#else
   *EINT_MASK_CLR = (0x0001 << eintno);
#endif

   RestoreIRQ(savedMask);

   /* Set external interrupt is level sensitive */
   #if !defined(__DIRECTION_SENSOR_SUPPORT__)
   
   if( (0)
   #if defined(__DIRECTION_SENSOR_SUPPORT__)
       || eintno == MOTION_SENSOR_EINT_NO1 
       || eintno == MOTION_SENSOR_EINT_NO2
   #endif
   )
   {
	   IRQSensitivity(IRQ_EIT_CODE,EDGE_SENSITIVE);   	
   }else{
   	   IRQSensitivity(IRQ_EIT_CODE,LEVEL_SENSITIVE);
   }

   #endif

   /* Enable external interrupt */
   IRQUnmask(IRQ_EIT_CODE);
}
Example #15
0
/* Note that idle task is only created when MTK_SLEEP_ENABLE is defined. */
void IdleTask( task_entry_struct * task_entry_ptr )
{
#if defined(KAL_ON_NUCLEUS)
	IdleTaskTCB = (NU_TASK*)task_info_g[task_entry_ptr->task_indx].task_id;
#elif defined(KAL_ON_THREADX)
	IdleTaskTCB = (TX_THREAD *)task_info_g[task_entry_ptr->task_indx].task_id;
#endif
	
   while(1)
   {
       /* Partial sleep mode for MCU and AVB block.
          To force MCU and AVB bus CLK stopped when system is in idle task.
          System will run again and CLK resume automatically only when IRQ comes.
       */
   	
#if defined(MTK_SLEEP_ENABLE) || defined(L1D_TEST)
   #if defined( DCM_ENABLE )
      kal_uint32 _savedMask;
      volatile kal_uint16 i,j=0;
      register kal_uint32 start, end, duration, tqwrap;

      _savedMask = LockIRQ();

      start = *((volatile kal_uint16 *)(TDMA_base + 0x00));

      /* Check if DMA, GMC and LCD_DMA is in Power Down Mode. */
      if ( 
#if (IS_CHIP_MT6229)
            (((*(volatile kal_uint32 *)0x80030000) & 0x00055555)==0) &&  /* Check DMA1~10, ignore DMA11~14 */
            (((*PDN_CON0) & 0x0078) == 0x0078) &&           /* Check PDN_CON0 IRDMA, PPP, CHE, and WAVETABLE down */
            ((*PDN_CON1) & 0x0080) &&           /* Check PDN_CON1 LCD down */
            ((*PDN_CON3) == 0xFFFF) &&          /* Check PDN_CON3 all down [GMC]*/
            *MCUCLK_CON == 0x0703 &&
#elif ( (IS_CHIP_MT6238) || (IS_CHIP_MT6235) ) //add by jerry
            (((*DMA_GLBSTA) & 0x00055555)==0) &&  /* Check DMA1~10, ignore DMA11~14 */
            (((*PDN_CON0) & 0x0078) == 0x0078) &&           /* Check PDN_CON0 IRDMA, PPP, CHE, and WAVETABLE down */
            ((*PDN_CON1) & 0x0080) &&           /* Check PDN_CON1 LCD down */
            ((*PDN_CON3) == 0xFFFF) &&          /* Check PDN_CON3 all down [GMC]*/
            *MCUCLK_CON == 0x7F37 &&            /*EMICLK,ARMCLK,AHBX4CLK,AHBX8CLK,104,208,52,104*/  
#elif (IS_CHIP_MT6228)
            (((*(volatile kal_uint32 *)0x80030000) & 0x00055555)==0) &&  /* Check DMA1~10, ignore DMA11~14 */
            (((*PDN_CON0) & 0x0038) == 0x0038) &&           /* Check PDN_CON0 PPP, CHE, and WAVETABLE down */
            ((*PDN_CON1) & 0x0080) &&           /* Check PDN_CON1 LCD down */
            ((*PDN_CON3) == 0xFFFF) &&          /* Check PDN_CON3 all down [GMC]*/
            *MCUCLK_CON == 0x0703 &&
#elif ( IS_CHIP_MT6223)
            (((*(volatile kal_uint32 *)0x80030000) & 0x00055555)==0) &&  /* Check DMA1~10, ignore DMA11~14 */
            (((*PDN_CON0) & 0x0048) == 0x0048) &&           /* Check PDN_CON0 IRDMA, and WAVETABLE down */
            ((*PDN_CON1) & 0x0080) &&           /* Check PDN_CON1 LCD down */
            ((*PDN_CON3) == 0x0001) &&          /* Check PDN_CON3 all down [GMC]*/
            *MCUCLK_CON == 0x0303 &&
#elif ( IS_CHIP_MT6225)
            (((*(volatile kal_uint32 *)0x80030000) & 0x00055555)==0) &&  /* Check DMA1~10, ignore DMA11~14 */
            (((*PDN_CON0) & 0x0048) == 0x0048) &&           /* Check PDN_CON0 IRDMA, and WAVETABLE down */
            ((*PDN_CON1) & 0x0080) &&           /* Check PDN_CON1 LCD down */
            ((*PDN_CON3) == 0x1801) &&          /* Check PDN_CON3 all down [GMC]*/
            *MCUCLK_CON == 0x0703 &&             
#elif ( IS_CHIP_MT6227)
            (((*(volatile kal_uint32 *)0x80030000) & 0x00055555)==0) &&  /* Check DMA1~10, ignore DMA11~14 */
            ((*PDN_CON0) & 0x0008) &&           /* Check PDN_CON0 WAVETABLE down */
            ((*PDN_CON1) & 0x0080) &&           /* Check PDN_CON1 LCD down */
            (((*PDN_CON3) & 0x7F91) == 0x7F91)&&           /* Check PDN_CON3 all down [GMC] (valid:0x7F91) */           
            *MCUCLK_CON == 0x0003 &&
#elif ( IS_CHIP_MT6217 )           
            (((*(volatile kal_uint32 *)0x80030000) & 0x00015555)==0) &&  /* Check DMA1~10, ignore DMA10~13 for 6217 */
            (((*PDN_CON0) & 0x0038) == 0x0038) &&           /* Check PDN_CON0 RESIZER, JPEG, and WAVETABLE down */
            ((*PDN_CON1) & 0x0080) &&           /* Check PDN_CON1 LCD down */
            *MCUCLK_CON == 0x0003 &&
#endif            
            dcm.dcmDisable == 0 
          )
      {
         #if ( (IS_CHIP_MT6228) || (IS_CHIP_MT6229)||(IS_CHIP_MT6235)||(IS_CHIP_MT6238))    
          	/* Gate GMC DMA */
            kal_uint32 tmp;
            tmp = GateDG();
            for (i = 0; i < 20; i++)
                ;
         #endif

         /*To access an address not in existance will ensure that EMI access is complete.*/
         #if ( (IS_CHIP_MT6238) || (IS_CHIP_MT6235) )
            j =  *(volatile kal_uint16 *)0x28000000; 
         #else
         j =  *(volatile kal_uint16 *)0x24000000; 
         #endif
         /*A26=1 means will not get data via data cache, it will access EMI directly.*/
         
         dcm_state = 1; /* DCM @ 104/52->13/26Mhz */ 

         /* Change WS and clock rate. */ 
         /* mtk01940 
           ======================================
	                        Idle      Dedi
	         MT6217         13MHz     x
	         MT6229         26MHz     26MHz
	         MT6227         13MHZ     26MHz
	         MT6223         13MHz     13MHz
	         MT6225
	         MT6228
	         MT6229
	         MT6227D
           ======================================
         */
         #if (IS_CHIP_MT6227 || IS_CHIP_MT6228)
           #ifdef MT6227D
             custom_DynamicClockSwitch( MCU_13MHZ );
           #else
             if(dcm.isIdleMode)
             {         
                custom_DynamicClockSwitch( MCU_13MHZ );
             }
             else
             {
                custom_DynamicClockSwitch( MCU_26MHZ );
             }
           #endif
         #elif (IS_CHIP_MT6229)
             custom_DynamicClockSwitch( MCU_26MHZ );
         #else
             custom_DynamicClockSwitch( MCU_13MHZ );  
         #endif
         /* mtk01940 */       
         
         dcm_state = 2; /* DCM @ 13/26MHz */
         
         #if ((IS_CHIP_MT6228) || (IS_CHIP_MT6229)||(IS_CHIP_MT6235)||(IS_CHIP_MT6238))  
            /* Recover GMC DMA gating */
            UngateDG(tmp);
         #endif
      
         /* check if IRQ is disabled for more than 60 qbits */
         end = *((volatile kal_uint16 *)(TDMA_base + 0x00));
         if (end >= start) {
            duration = end - start;
         } else {
            tqwrap = *(volatile kal_uint16 *)(TDMA_base + 0x04);
            duration = (tqwrap - start) + end;
         }
         if (duration > 60) {
            EXT_ASSERT(0, duration, start, end);
         }
         
         *SLEEP_CON = 0x0003;
         #if ( (IS_CHIP_MT6238) || (IS_CHIP_MT6235) )
            cp15_enter_low_pwr_state();
         #endif /* MT6238 */            
      }
      else
      {
      	*SLEEP_CON = 0x0001;
      	#if ( (IS_CHIP_MT6238) || (IS_CHIP_MT6235) )
           cp15_enter_low_pwr_state();
        #endif  /* MT6238 */   
      	   
      }
      
      RestoreIRQ(_savedMask);
   #elif defined(MT6218B)         
       kal_uint32 _savedMask;
       
       _savedMask = LockIRQ();

       if ( (((*(volatile kal_uint16 *)0x80000300) & 0x0038)==0x0038)  &&
             ((*(volatile kal_uint16 *)0x80000304) & 0x0080) )
       {
          /* Power down AHB only when WT & JPEG & Resizer & LCD is turned off. */	            
          *SLEEP_CON = 0x0003;  
       }	
       else
       {
          *SLEEP_CON = 0x0001;
       }	       
       
       RestoreIRQ(_savedMask);
   #else
      /*To temporarily avoid the problem on AHB.*/
      *SLEEP_CON = 0x0001; 
   #endif /* End #if defined(DCM_ENABLE)*/   
#endif /* End #if defined(MTK_SLEEP_ENABLE) || defined(L1D_TEST) */      
   }    /* Infinite loop */
}
Example #16
0
/** @argu mode : to be defined, currently no usage.
 *
 **/
kal_int32 arm_enter_standby_mode(kal_int32 mode)
{
#if defined (__CPU_ARM7EJ_S__) || defined (__CPU_ARM7TDMI__)   //without cp15 wfi
#if defined (MT6250)
#if !defined (SLEEP_CON)
#define ARM_SLEEP_CON          ((volatile UINT16P)(ARM_CONFG_base+0x0040))
#define SLEEP_CON              ARM_SLEEP_CON
#endif

    kal_uint32 tmp;

    tmp = *PLL_CLK_CONDA;
    ASSERT(((tmp >> 10) & 0x3f) == 0x21); // assert RG_ARM_PLLCK_SEL1 as 87Mhz, and RG_ARM_PLLCK_SEL2 as 260Mhz

    *PLL_CLK_CONDC = (*PLL_CLK_CONDC & ~(0x7<<3)) | (0x2<<3);
    *PLL_CLK_CONDC;
    /** ASTONE,
     * "READ-modify-write" is good for flushing bus transaction, instead of write directly.
     * BUT, take care about side effect of read-modify-write, esp. about read-clear bit.
     **/
    *SLEEP_CON |= 1;
    __nop();
    __nop();
    __nop();
    __nop();
    __nop();
    __nop();

    /* debug code of long irq latency of TDMA issue. Should be removed after W12.26 */
    {
        extern kal_uint32 irq_dbg_time_leave_from_sleep;
        irq_dbg_time_leave_from_sleep = ust_get_current_time();
    }

    *PLL_CLK_CONDC = (*PLL_CLK_CONDC & ~(0x7<<3)) | (0x4<<3);
    *PLL_CLK_CONDC;

#elif defined (MT6260)
#if !defined (SLEEP_CON)
#define ARM_SLEEP_CON          ((volatile UINT16P)(ARM_CONFG_base+0x0040))
#define SLEEP_CON              ARM_SLEEP_CON
#endif
    {
        register kal_uint32 conda, condc, conde;
        kal_uint32 _savedmask;
        kal_uint32 LockIRQ(void);
        void RestoreIRQ(kal_uint32);

        _savedmask = LockIRQ();

        conda = *PLL_CLK_CONDA;
        condc = *PLL_CLK_CONDC;

        /* if (mode != 0) { */
        /*     conde = *PLL_CLK_CONDE; */
        /*     *PLL_CLK_CONDE = conde & (3<<14); */
        /* } */

        // switch MCU to MPLL/3 clock;
        /* *PLL_CLK_CONDA = (conda | (1<<13)); */
        /* *PLL_CLK_CONDC = (condc & ~(0x7<<3) | (0x04 << 3)); */
        *PLL_CLK_CONDC = (condc & ~(0x7<<3) | (0x01 << 3));
        *PLL_CLK_CONDC;

#if defined(MT6260) && defined(__ESD_LU_NEW_SOLUTION__)
#if !defined(__ESD_LU_NEW_SOLUTION_TEST__)
        if (*((volatile unsigned int *)(0xA0700E24)))
#endif /* defined(__ESD_LU_NEW_SOLUTION_TEST__) */
        {
            kal_uint32 t1, t2;

#if !defined(__ESD_LU_NEW_SOLUTION_TEST__)
            if (++dropVoltageCount > 100)
            {
                // 0.8V
                *((volatile kal_uint16 *)(0xA0700230)) = 0x8541;
                *((volatile kal_uint16 *)(0xA0700230));

                EXT_ASSERT(0, 0, 0, 0);
            }
#endif /* defined(__ESD_LU_NEW_SOLUTION_TEST__) */

            // 0.975V
            *((volatile kal_uint16 *)(0xA0700230)) = 0x85B1;
            *((volatile kal_uint16 *)(0xA0700230));

            t1 = ust_get_current_time();
            do
            {
                t2 = ust_get_current_time();
            } while(ust_get_duration(t1, t2) < 500);

            // 1.3V
            *((volatile kal_uint16 *)(0xA0700230)) = 0x8481;
            *((volatile kal_uint16 *)(0xA0700230));

            t1 = ust_get_current_time();
            do
            {
                t2 = ust_get_current_time();
            } while(ust_get_duration(t1, t2) < 200);
        }
#endif /* defined(__ESD_LU_NEW_SOLUTION__) */

        *SLEEP_CON |= 1;
        __nop();
        __nop();
        __nop();
        __nop();
        __nop();
        __nop();

        *PLL_CLK_CONDA = conda;
        *PLL_CLK_CONDC = condc;
        *PLL_CLK_CONDC;

        /* if (mode != 0) { */
        /*     *PLL_CLK_CONDE = conde; */
        /* } */

        /** disable EMI HW DCM,
         * 1. to workaround EMI DCM having long DCM recovery time.
         * 2. to workaround EMI DCM that has slow reponse MMSYS idle that make normal clock too late to reponse MMSYS request.
         **/
        MT6260_EMI_DCM_DISABLE();

        RestoreIRQ(_savedmask);

    }

#else  //#if defined (MT6250)

    ASSERT(0);

#endif //#if defined (MT6250)

#else  //#if defined (__CPU_ARM7EJ_S__) || defined (__CPU_ARM7TDMI__)   //without cp15 wfi
    cp15_enter_low_pwr_state();
#endif //#if defined (__CPU_ARM7EJ_S__) || defined (__CPU_ARM7TDMI__)   //without cp15 wfi

    return 0;
}