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

📄 mpc8260timer2.c

📁 MPC8260的定时器应用程序.该程序可以更好的理解8260的定时器应用方法.
💻 C
字号:
#include "vxWorks.h"
#include "stdlib.h"
#include "memLib.h"
#include "stdio.h"
#include "cachelib.h"
#include "smmemlib.h"
#include "fiolib.h"
#include "String.h"
#include "arch/ppc/vxPpcLib.h"
#include "drv/timer/timerDev.h"
#include "drv/timer/m8260Timer.h"
#include "drv/mem/m8260siu.h"
#include "drv/intrCtl/m8260IntrCtl.h"
#include "m8260IOPort.h"

#ifndef SYS_CPU_FREQ
#define SYS_CPU_FREQ		66000000	/* 66.00 Mhz default */
#endif /* SYS_CPU_FREQ */
#define M8260_TRR_SIZE		16	/* number bits in Reference Register */


LOCAL FUNCPTR sysAuxClkRoutine        = NULL;
LOCAL int     sysAuxClkArg            = NULL;
LOCAL BOOL    sysAuxClkRunning        = FALSE;
LOCAL BOOL    sysAuxClkIntConnected   = FALSE;
STATUS sysAuxClk2Connect(FUNCPTR routine,int arg);
void sysAuxClk2Enable();

int myloop1=0;
int papr = 0;

void testroutine()
{
	
	printf("%d\n",myloop1);
	myloop1++;
	

}

void PortAInit(void)
{
  *M8260_IOP_PADIR( 0x47000000 ) |=   0X80000000;
	*M8260_IOP_PAPAR( 0x47000000 ) &= ~(0X80000000);
	*M8260_IOP_PAODR( 0x47000000 ) &= ~(0X80000000);
	
}

void SetPortA(void)
{
   papr = !papr;  
	
   if(papr)
	*M8260_IOP_PADAT( 0x47000000 ) |=  (0X80000000);
   else
        *M8260_IOP_PADAT( 0x47000000 ) &= ~(0X80000000);	
}


void testtimermain()
{	
	PortAInit();
	sysAuxClk2Connect((FUNCPTR)SetPortA,1);   /*  1.9ns~126ms  */
	sysAuxClk2Enable();
}


STATUS sysAuxClk2Connect(FUNCPTR routine,int arg)
{
	/*初始化定时器*/
	/*将routine连接到定时中断*/	    
                 
	sysAuxClkRoutine   = routine;
        sysAuxClkArg       = arg;          
        return (OK);	
}



LOCAL void sysAuxClkInt (void)
    {
    UINT32 immrVal = vxImmrGet();

    *M8260_TER2(immrVal) = 0X0003;  /*M8260_TER_REF | M8260_TER_CAP;  clear all events */

    if (sysAuxClkRoutine != NULL)
        (*sysAuxClkRoutine) ();
    }



void sysAuxClk2Enable() 
{
	/*允许定时器中断*/
	{
    UINT32  immrVal = vxImmrGet();
   
/*    UINT32  tempDiv = SYS_CPU_FREQ*sysAuxClkArg/0xff/1000;  */   /*SYS_CPU_FREQ 133M */

    UINT32  tempDiv = 66000000*sysAuxClkArg /256;
   
    
   if ((!sysAuxClkRunning) && (tempDiv < ((1 << (M8260_TRR_SIZE-1)) * 16)))
	{
		
		
         *M8260_TGCR1(immrVal) &= ~0x30; /*M8260_TGCR_STP2   clear stop bit ,0x20*/	   
         *M8260_TCN2(immrVal) = 0x0;	                /* clear the timer counter */      
    
    
    /* 
     * Enable the auxiliary clock only if it is not already running 
     * and if the required reference value will fit in the reference register
     * if the general system clock is divided by 16.
     */

     if (tempDiv < (1 <<(M8260_TRR_SIZE-1)))
	{
	*M8260_TRR2(immrVal) = (UINT16) tempDiv;
           *M8260_TMR2(immrVal) = 0xFF1A;
        } 
        else
        {
        *M8260_TRR2(immrVal) = (UINT16) tempDiv/16;
        *M8260_TMR2(immrVal) = 0xFF1c;	
        }
        /* 
	 * start and hold in reset (i.e. disable) timer2 
	 * Note that RST is active low while STP is active high
	 */	  		
	   
		 
	/* clear all timer events */

	   *M8260_TER2(immrVal) = 0x0003;    /*MCC_TER_REF | MCC_TER_CAP;    0x0002,0x0001*/

	/* enable timer interrupt */

	m8260IntEnable(INUM_TIMER2);

        if (! sysAuxClkIntConnected)
            {
            (void) intConnect (INUM_TO_IVEC(INUM_TIMER2), 
			       (VOIDFUNCPTR) sysAuxClkInt, NULL);
            sysAuxClkIntConnected = TRUE;
            }
        
	/* Enable timer by removing reset, which is active low */

	*M8260_TGCR1(immrVal) |=  0x10;   /*MCC_TGCR_RST2;  set reset bit */

	sysAuxClkRunning = TRUE;
     }
    }
  
	return;
}


void sysAuxClk2Disable (void)
    {
    UINT32 immrVal = vxImmrGet();

    if (sysAuxClkRunning)
	{
	m8260IntDisable(INUM_TIMER2);
	*M8260_TGCR1(immrVal) |= M8260_TGCR_STP2;	/* stop timer */

	sysAuxClkRunning = FALSE;		/* clock is no longer running */
	}
    }

⌨️ 快捷键说明

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