⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timer_fixedtick.c

📁 2443 wince5.0 bsp, source code
💻 C
📖 第 1 页 / 共 2 页
字号:
	return (g_oalTimer.countsPerSysTick - INREG32(&g_pPWMRegs->TCNTO4));
}

//------------------------------------------------------------------------------
//
//  Function: OALTimerUpdate
//
//  This function is called to change length of actual system timer period.
//  If end of actual period is closer than margin period isn't changed (so
//  original period elapse). Function returns time which already expires
//  in new period length units. If end of new period is closer to actual time
//  than margin period end is shifted by margin (but next period should fix
//  this shift - this is reason why OALTimerRecharge doesn't read back 
//  compare register and it uses saved value instead).
//
UINT32 OALTimerUpdate(UINT32 period, UINT32 margin)
{
	UINT32 tcon, ret;
	
	ret = OALTimerCountsSinceSysTick();

	OUTREG32(&g_pPWMRegs->TCNTB4, period);
    tcon = INREG32(&g_pPWMRegs->TCON) & ~(0x0F << 20);
    OUTREG32(&g_pPWMRegs->TCON, tcon | (0x2 << 20) );
    OUTREG32(&g_pPWMRegs->TCON, tcon | (0x5 << 20) );

	return (ret);
}
//------------------------------------------------------------------------------
//
//  Function:   OEMIdle
//
//  This Idle function implements a busy idle. It is intend to be used only
//  in development (when CPU doesn't support idle mode it is better to stub
//  OEMIdle function instead use this busy loop). The busy wait is cleared by
//  an interrupt from interrupt handler setting the g_oalLastSysIntr.
//

//
void OEMIdle(DWORD idleParam)
{
   UINT32 baseMSec;
    INT32 usedCounts, idleCounts;
    ULARGE_INTEGER idle;

    // Get current system timer counter
    baseMSec = CurMSec;
    
    // Find how many hi-res ticks was already used
    usedCounts = OALTimerCountsSinceSysTick();
	if (usedCounts == g_oalTimer.countsPerSysTick)
	{
		return;
	}
    // We should wait this time
    idleCounts = g_oalTimer.actualCountsPerSysTick;
    
    // Move SoC/CPU to idle mode
    OALCPUIdle();

    // When there wasn't timer interrupt modify idle time
    if (CurMSec == baseMSec) {
        idleCounts = OALTimerCountsSinceSysTick();
    }

    // Get real idle value. If result is negative we didn't idle at all.
    idleCounts -= usedCounts;
    if (idleCounts < 0) idleCounts = 0;

    // Update idle counters
    idle.LowPart = curridlelow;
    idle.HighPart = curridlehigh;
    idle.QuadPart += idleCounts;
    curridlelow  = idle.LowPart;
    curridlehigh = idle.HighPart;

#ifdef DVS_EN
	dwCurrentidle = (DWORD)(idle.QuadPart/idleconv);
#endif
}


//------------------------------------------------------------------------------
//
//  Function:   OALCPUIdle
//
//  This Idle function implements a busy idle. It is intend to be used only
//  in development (when CPU doesn't support idle mode it is better to stub
//  OEMIdle function instead use this busy loop). The busy wait is cleared by
//  an interrupt from interrupt handler setting the g_oalLastSysIntr.
//
//
extern void Nop(void);
//extern void MMU_WaitForInterrupt();
VOID OALCPUIdle()
{
    volatile S3C2443_CLKPWR_REG *s2443CLKPWR = (S3C2443_CLKPWR_REG *)OALPAtoVA(S3C2443_BASE_REG_PA_CLOCK_POWER, FALSE);
    volatile S3C2443_INTR_REG *s2443INT = (S3C2443_INTR_REG *)OALPAtoVA(S3C2443_BASE_REG_PA_INTR, FALSE);
    volatile S3C2443_IOPORT_REG *s2443IOPORT = (S3C2443_IOPORT_REG *)OALPAtoVA(S3C2443_BASE_REG_PA_IOPORT, FALSE);

#ifdef DVS_EN
		volatile S3C2443_LCD_REG    *s2443LCD = (S3C2443_LCD_REG *)OALPAtoVA(S3C2443_BASE_REG_PA_LCD, FALSE);
#if(DVS_METHOD == 1)
{

	if ( CurrStateIdle == TRUE )
	{
		s2443INT->INTSUBMSK |= (1 << IRQ_SUB_LCD3);		// masking LCD3 sub interrupt					
		s2443INT->INTMSK |= (1 << IRQ_LCD);		// maksing LCD interrupt
		s2443LCD->VIDINTCON &= ~(0x1);	// disable LCD interrupt
	}
	else
	{
		s2443INT->INTSUBMSK &= ~(1 << IRQ_SUB_LCD3);		// unmasking LCD3 sub interrupt			
		s2443INT->INTMSK &= ~(1 << IRQ_LCD);		// unmasking LCD interrupt
		s2443LCD->VIDINTCON |= (0x1);	// enable LCD interrupt	
	}

	if  ( s2443INT->SUBSRCPND & (1 << IRQ_SUB_LCD3) ) s2443INT->SUBSRCPND = (1 << IRQ_SUB_LCD3);
	if  ( s2443INT->SRCPND & (1 << IRQ_LCD)) s2443INT->SRCPND = (1 << IRQ_LCD);
	if  ( s2443INT->INTPND & (1 << IRQ_LCD)) s2443INT->INTPND = (1 << IRQ_LCD);


	b_oalInterruptFlag = FALSE;
	IDLEflag = TRUE;

	#if IDLELED_ACTIVATE==TRUE
	s2443IOPORT->GPFDAT |= ( 1<< 5);    // GPF5 output data, turn LED on
	#endif
				
	s2443CLKPWR->PWRMODE |=  (1 << 17);
	//MMU_WaitForInterrupt();
	INTERRUPTS_ON();
	while (!b_oalInterruptFlag)	{}
	INTERRUPTS_OFF();	
	s2443CLKPWR->PWRMODE &=  ~(1 << 17);	

	
	IDLEflag = FALSE;

	#if IDLELED_ACTIVATE==TRUE
	s2443IOPORT->GPFDAT &= ~(1 << 5);    // GPF5 output data, turn LED off		
	#endif

	if ( CurrStateIdle == FALSE ){
		s2443INT->INTSUBMSK |= (1 << IRQ_SUB_LCD3);		// masking LCD3 sub interrupt					
		s2443INT->INTMSK |= (1 << IRQ_LCD);		// maksing LCD interrupt
		s2443LCD->VIDINTCON &= ~(0x1);	// disable LCD interrupt
	}
	else
	{
		s2443INT->INTSUBMSK &= ~(1 << IRQ_SUB_LCD3);		// unmasking LCD3 sub interrupt			
		s2443INT->INTMSK &= ~(1 << IRQ_LCD);		// unmasking LCD interrupt
		s2443LCD->VIDINTCON |= (0x1);	// enable LCD interrupt	
	}

	if  ( s2443INT->SUBSRCPND & (1 << IRQ_SUB_LCD3) ) 
	{
		s2443INT->SUBSRCPND = (1 << IRQ_SUB_LCD3);
	}
	if  ( s2443INT->SRCPND & (1 << IRQ_LCD))
	{	
		s2443INT->SRCPND = (1 << IRQ_LCD);
	}
	if  ( s2443INT->INTPND & (1 << IRQ_LCD))
	{
		s2443INT->INTPND = (1 << IRQ_LCD);
	}
}
#elif (DVS_METHOD == 2)
/**
 *	DVS_ON : Sync FCLK to HCLK
 *	Change voltage to lower
 *	set system mode to idle
 *	Wait for interrupt
 *	Change voltage to high
 *	Wait for recovering voltage to high
 *	DVS_OFF : restore FCLK
 */
//	RETAILMSG(1, (TEXT("-I-")));
	DVS_ON();		// FCLK to 133?
	g_oalIoCtlClockSpeed = S3C2443_HCLK;
	ChangeVoltage(LOWVOLTAGE);
	//g_oalLastSysIntr = FALSE;
  	b_oalInterruptFlag = FALSE;


	#if IDLELED_ACTIVATE==TRUE
	s2443IOPORT->GPFDAT |= ( 1<< 5);    // GPF5 output data, turn LED on
	#endif

	s2443CLKPWR->PWRMODE |=  (1 << 17);
	//MMU_WaitForInterrupt();
	INTERRUPTS_ON();
	while (!b_oalInterruptFlag)	{}
	INTERRUPTS_OFF();	
	s2443CLKPWR->PWRMODE &=  ~(1 << 17);	

	#if IDLELED_ACTIVATE==TRUE
	s2443IOPORT->GPFDAT &= ~(1 << 5);    // GPF5 output data, turn LED off		
	#endif

	ChangeVoltage(HIGHVOLTAGE);
	{	
		// Voltage Difference : 0.55V needs 100usec --> in 133MHZ, 13300 cycles
	 	volatile int i;
		for(i=0;i<VOLTAGEDELAY;i++)
		{
			INREG32(&s2443IOPORT->GPFDAT);  // for loop operation, just read.
		}	
	}
	DVS_OFF();
	g_oalIoCtlClockSpeed = S3C2443_FCLK;
//	RETAILMSG(1, (TEXT("-O-")));	
#elif (DVS_METHOD == 3)
	if ( CurrentState == Active )	// Active -> Idle
	{
		#if IDLELED_ACTIVATE==TRUE
		s2443IOPORT->GPFDAT &= ~(1 << 5);    // GPF5 output data, turn LED off		
		#endif	

		DVS_ON();
		g_oalIoCtlClockSpeed = S3C2443_HCLK;
		ChangeVoltage(MIDVOLTAGE);

		b_oalInterruptFlag = FALSE;
		IDLEflag = TRUE;
//		RETAILMSG(1, (TEXT("-I-")));


		s2443CLKPWR->PWRMODE |=  (1 << 17);
//		MMU_WaitForInterrupt();
		INTERRUPTS_ON();
		while (!b_oalInterruptFlag)	{}
		INTERRUPTS_OFF();		
		s2443CLKPWR->PWRMODE &=  ~(1 << 17);
		
		

		IDLEflag = FALSE;
		#if IDLELED_ACTIVATE==TRUE
		s2443IOPORT->GPFDAT |= ( 1<< 5);    // GPF5 output data, turn LED on		
		#endif
	}
	else if ( CurrentState == SlowActive )	// Slow Active -> Deep Idle
	{
		#if IDLELED_ACTIVATE==TRUE
		s2443IOPORT->GPFDAT &= ~(1 << 5);    // GPF5 output data, turn LED off		
		#endif	

		if ( CurrStateIdle == TRUE )
		{
			s2443INT->INTSUBMSK |= (1 << IRQ_SUB_LCD3);		// masking LCD3 sub interrupt					
			s2443INT->INTMSK |= (1 << IRQ_LCD);		// maksing LCD interrupt
			s2443LCD->VIDINTCON &= ~(0x1);	// disable LCD interrupt
		}
		else
		{
			s2443INT->INTSUBMSK &= ~(1 << IRQ_SUB_LCD3);		// unmasking LCD3 sub interrupt			
			s2443INT->INTMSK &= ~(1 << IRQ_LCD);		// unmasking LCD interrupt
			s2443LCD->VIDINTCON |= (0x1);	// enable LCD interrupt	
		}

		if  ( s2443INT->SUBSRCPND & (1 << IRQ_SUB_LCD3) ) s2443INT->SUBSRCPND = (1<<IRQ_SUB_LCD3);
		if  ( s2443INT->SRCPND & (1 << IRQ_LCD)) s2443INT->SRCPND = (1 << IRQ_LCD);
		if  ( s2443INT->INTPND & (1 << IRQ_LCD)) s2443INT->INTPND = (1 << IRQ_LCD);
		

		b_oalInterruptFlag = FALSE;
		IDLEflag = TRUE;
//		RETAILMSG(1, (TEXT("-D-")));

		s2443CLKPWR->PWRMODE |=  (1 << 17);
//		MMU_WaitForInterrupt();
		INTERRUPTS_ON();
		while (!b_oalInterruptFlag)	{}
		INTERRUPTS_OFF();	
		s2443CLKPWR->PWRMODE &=  ~(1 << 17);
		

		IDLEflag = FALSE;
		#if IDLELED_ACTIVATE==TRUE
		s2443IOPORT->GPFDAT |= ( 1<< 5);    // GPF5 output data, turn LED on
		#endif

		if  ( s2443INT->SUBSRCPND & (1 << IRQ_SUB_LCD3) ) s2443INT->SUBSRCPND = (1<<IRQ_SUB_LCD3);
		if  ( s2443INT->SRCPND & (1 << IRQ_LCD)) s2443INT->SRCPND = (1 << IRQ_LCD);
		if  ( s2443INT->INTPND & (1 << IRQ_LCD)) s2443INT->INTPND = (1 << IRQ_LCD);

		if ( CurrStateIdle == FALSE ){
			s2443INT->INTSUBMSK |= (1 << IRQ_SUB_LCD3);		// masking LCD3 sub interrupt					
			s2443INT->INTMSK |= (1 << IRQ_LCD);		// maksing LCD interrupt
			s2443LCD->VIDINTCON &= ~(0x1);	// disable LCD interrupt
		}
		else
		{
			s2443INT->INTSUBMSK &= ~(1 << IRQ_SUB_LCD3);		// unmasking LCD3 sub interrupt			
			s2443INT->INTMSK &= ~(1 << IRQ_LCD);		// unmasking LCD interrupt
			s2443LCD->VIDINTCON |= (0x1);	// enable LCD interrupt	
		}
	}
#endif //DVS_METHOD
#else
    
	// Clear last SYSINTR global value
	//g_oalLastSysIntr = SYSINTR_NOP;
	b_oalInterruptFlag = FALSE;

	s2443IOPORT->GPFDAT |= ( 1<< 5);    // GPF5 output data, turn LED on
	s2443CLKPWR->PWRMODE |=  (1 << 17);
	
	//MMU_WaitForInterrupt();
	INTERRUPTS_ON();
	while (!b_oalInterruptFlag)	{}
	INTERRUPTS_OFF();
	s2443CLKPWR->PWRMODE &=  ~(1 << 17);
	s2443IOPORT->GPFDAT &= ~(1 << 5);    // GPF5 output data, turn LED off
	
#endif //DVS_EN	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -