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

📄 s3c44btimer.c

📁 vxworks bsp,s3c2410的vxworks开发资料
💻 C
📖 第 1 页 / 共 2 页
字号:
/* s3c44bTimer.c - Samsung S3C44B0X timer library *//* Copyright 1984-2001 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01b, 28apr04, jhf  add delay ms function01a, 20feb04, jhf  created from wrsbcarm7 template.*//*DESCRIPTIONThis is a timer driver for Samsung's KS32C50100 microprocessor which isan ARM based processor with several integrated peripherals.It has an interrupt controller, two 32-bit timers, one Ethernet controller,two HDLC controllers, one IIC controller, general purpose I/O ports, and a 2-channel DMA controller.The 32-bit timers can be programmed in interval mode or toggle mode.  Ininterval mode, an output pulse is generated when the countdown value inthe count register reaches  zero.  This will generate a frequency of(SYSCLK/count).  On the other hand, in the toggle mode, the output togglesits state for each time the countdown value reaches zero.  In this case, theoutput frequency will be (SYSCLK/(2*count)).The Timer Data register is used to load the countdown value.  When the timeris enabled using the Timer Mode register, the Timer Count register is loadedwith the count in Timer Data register.  The count value is decremented for everyinternal clock edge.  Once the count becomes zero, an interrupt is generated(if enabled in the interrupt controller) and the Timer Count register isreloaded automatically.The internal timer registers are accessed in a straight-forward fashion.They are accessible as 32-bit integers from the internal system registeroffsets, as given in s3c44bTimer.h file.  The macros S3C44B_TIMER_REG_WRITEand S3C44B_TIMER_REG_READ does nothing but reading and writing 32-bitintegers from and to the given addresses.This driver provides 3 main functions, system clock support, auxiliaryclock support, and timestamp timer support.  If necessary, each functionmay be conditioned by a separate INCLUDE_ macro.  The timestamp functionis always conditional upon the INCLUDE_TIMESTAMP macro.The S3C44B0X ARM7 timer register definitions are given in s3c44bTimer.h file.The macros SYS_CLK_RATE_MIN, SYS_CLK_RATE_MAX, AUX_CLK_RATE_MIN, andAUX_CLK_RATE_MAX must be defined in s3cboard.h to provide parameter checking for the sys[Aux]ClkRateSet() routines.INCLUDES:s3c44bTimer.htimestampDev.hSEE ALSO:<Samsung KS32C50100 User's Manual>*//* includes */#include "vxWorks.h"#include "config.h"#include "drv/timer/timerDev.h"#include "drv/timer/timestampDev.h"#include "s3c44bTimer.h"/* defines *//* The default is to assume memory mapped I/O */#ifndef S3C44B_TIMER_REG_READ#define S3C44B_TIMER_REG_READ(reg, result) \    ((result) = *(volatile UINT32 *)(reg))#endif /*S3C44B_TIMER_REG_READ*/#ifndef S3C44B_TIMER_REG_WRITE#define S3C44B_TIMER_REG_WRITE(reg, data) \    (*((volatile UINT32 *)(reg)) = (data))#endif /*S3C44B_TIMER_REG_WRITE*/#ifndef S3C44B_TIMER_INT_ENABLE#define S3C44B_TIMER_INT_ENABLE(level) intEnable(level)#endif#ifndef S3C44B_TIMER_INT_DISABLE#define S3C44B_TIMER_INT_DISABLE(level) intDisable(level)#endif/* locals */LOCAL FUNCPTR sysClkRoutine    = NULL; /* routine to call on clock tick */LOCAL int sysClkArg            = (int)NULL; /* its argument */LOCAL int sysClkRunning        = FALSE;LOCAL int sysClkConnected      = FALSE;LOCAL int sysClkTicksPerSecond = 60;LOCAL FUNCPTR sysAuxClkRoutine    = NULL;LOCAL int sysAuxClkArg            = (int)NULL;LOCAL int sysAuxClkRunning        = FALSE;LOCAL int sysAuxClkTicksPerSecond = 100;LOCAL int sysAuxClkTicks;#ifdef INCLUDE_TIMESTAMPLOCAL BOOL      sysTimestampRunning     = FALSE;         /* running flag */LOCAL FUNCPTR   sysTimestampRoutine     = NULL;          /* routine to call on intr */LOCAL int       sysTimestampArg         = 0;             /* arg for routine */      void      sysTimestampInt (void);                  /* forward declaration */#endif  /* INCLUDE_TIMESTAMP */void sysDelayMs( int );int timerMsOut = 0;/********************************************************************************* sysClkInt - interrupt level processing for system clock** This routine handles a system clock interrupt.  It acknowledges the* interrupt and calls the routine installed by sysClkConnect().*/void sysClkInt (void)    {     /* call system clock service routine */    if (sysClkRoutine != NULL) {        (* sysClkRoutine) (sysClkArg);       }    S3C44B_REG_WRITEW(S3C44B_I_ISPC,(1 << INT_LVL_TIMER5));    }/********************************************************************************* sysClkConnect - connect a routine to the system clock interrupt** This routine specifies the interrupt service routine to be called at each* clock interrupt.  Normally, it is called from usrRoot() in usrConfig.c to * connect usrClock() to the system clock interrupt.** RETURN: OK, or ERROR if the routine cannot be connected to the interrupt.** SEE ALSO: intConnect(), usrClock(), sysClkEnable()*/STATUS sysClkConnect    (    FUNCPTR routine,    /* routine to be called at each clock interrupt */    int arg        /* argument with which to call routine */    )    {         if (sysClkConnected == FALSE)        {         S3C44B_TIMER_REG_WRITE (S3C44B_TCON, S3C44B_TIMER_INIT);        sysHwInit2 ();        sysClkConnected = TRUE;                }    sysClkRoutine   = NULL;    sysClkArg        = arg;#if ((CPU_FAMILY == ARM) && ARM_THUMB)    /* set b0 so that sysClkConnect() can be used from shell */    sysClkRoutine = (FUNCPTR)((UINT32)routine | 1);#else    sysClkRoutine = routine;#endif /* CPU_FAMILY == ARM */    return (OK);    }/********************************************************************************* sysClkDisable - turn off system clock interrupts** This routine disables system clock interrupts.** RETURNS: N/A** SEE ALSO: sysClkEnable()*/void sysClkDisable (void)    {    int oier;        if (sysClkRunning)        {                S3C44B_TIMER_REG_READ (S3C44B_TCON, oier);       /* S3C44B_TIMER_REG_WRITE (S3C44B_TCON, oier & ~(S3C44B_TIMER0_START)); */        S3C44B_TIMER_REG_WRITE (S3C44B_TCON, oier &~ (S3C44B_TIMER5_START));        /* disable timer interrupt in the interrupt controller */            S3C44B_TIMER_INT_DISABLE (SYS_TIMER_INT_LVL);        sysClkRunning = FALSE;                }        }/********************************************************************************* sysClkEnable - turn on system clock interrupts** This routine enables system clock interrupts.** RETURNS: N/A** SEE ALSO: sysClkConnect(), sysClkDisable(), sysClkRateSet()*/void sysClkEnable (void)    {       UINT32 oier;    /*    UINT32 pres; */    oier = 0;    if (!sysClkRunning)        {        /*         * Load the match register with a new value calculated by         * adding the ticks per interrupt to the current value of the         * counter register.  Note that this may wraparound to a value         * less than the current counter value but thats OK.         */        /* write prescaler */        S3C44B_TIMER_REG_WRITE (S3C44B_TCFG0, 0x00ff0000);                /* write divider 32 = divider */        S3C44B_TIMER_REG_WRITE (S3C44B_TCFG1, S3C44B_TIMER5_DIV_4);        /* count */        S3C44B_TIMER_REG_WRITE (S3C44B_TCNTB5, 0x411);                        /* load counter */        S3C44B_TIMER_REG_WRITE (S3C44B_TCON, S3C44B_TIMER5_MANUAL);        S3C44B_TIMER_REG_READ (S3C44B_TCON,oier);        /* clear manual bit */        oier &= ~S3C44B_TIMER5_MANUAL;        S3C44B_TIMER_REG_WRITE (S3C44B_TCON,oier);        S3C44B_TIMER_INT_ENABLE (INT_LVL_GLOBAL);        S3C44B_TIMER_INT_ENABLE (SYS_TIMER_INT_LVL);                S3C44B_TIMER_REG_WRITE (S3C44B_TCON, (S3C44B_TIMER5_START|S3C44B_TIMER5_AUTO));        /* enable clock interrupt in interrupt controller */                /*        sysDebug("sys clk enable 1 "); */                sysClkRunning = TRUE;                }    return;    }/********************************************************************************* sysClkRateGet - get the system clock rate** This routine returns the system clock rate.** RETURNS: The number of ticks per second of the system clock.** SEE ALSO: sysClkEnable(), sysClkRateSet()*/int sysClkRateGet (void)    {    return (sysClkTicksPerSecond);        }/********************************************************************************* sysClkRateSet - set the system clock rate** This routine sets the interrupt rate of the system clock.* It is called by usrRoot() in usrConfig.c.** RETURNS: OK, or ERROR if the tick rate is invalid or the timer cannot be set.** SEE ALSO: sysClkEnable(), sysClkRateGet()*/STATUS sysClkRateSet    (    int ticksPerSecond        /* number of clock interrupts per second */    )    {    if (ticksPerSecond < SYS_CLK_RATE_MIN )        return (ERROR);    if ( ticksPerSecond > SYS_CLK_RATE_MAX)        return (ERROR);    sysClkTicksPerSecond = ticksPerSecond;    if (sysClkRunning)        {               sysClkDisable ();        sysClkEnable ();               }        return (OK);    }/********************************************************************************* sysAuxClkInt - handle an auxiliary clock interrupt** This routine handles an auxiliary clock interrupt.  It acknowledges the* interrupt and calls the routine installed by sysAuxClkConnect().** RETURNS: N/A*/void sysAuxClkInt (void)    {    /* call auxiliary clock service routine */    if (sysAuxClkRoutine != NULL)        (*sysAuxClkRoutine) (sysAuxClkArg);    }/********************************************************************************* sysAuxClkConnect - connect a routine to the auxiliary clock interrupt** This routine specifies the interrupt service routine to be called at each* auxiliary clock interrupt.  It does not enable auxiliary clock interrupts.** RETURNS: OK, or ERROR if the routine cannot be connected to the interrupt.** SEE ALSO: intConnect(), sysAuxClkEnable()*/STATUS sysAuxClkConnect    (    FUNCPTR routine,    /* routine called at each aux clock interrupt */    int arg             /* argument to auxiliary clock interrupt routine */    )    {    sysAuxClkRoutine    = NULL;    sysAuxClkArg        = arg;#if ((CPU_FAMILY == ARM) && ARM_THUMB)    /* set b0 so that sysClkConnect() can be used from shell */    sysAuxClkRoutine = (FUNCPTR)((UINT32)routine | 1);#else    sysAuxClkRoutine = routine;#endif /* CPU_FAMILY == ARM */    return (OK);    }/********************************************************************************* sysAuxClkDisable - turn off auxiliary clock interrupts** This routine disables auxiliary clock interrupts.** RETURNS: N/A** SEE ALSO: sysAuxClkEnable()*/void sysAuxClkDisable (void)    {    UINT32 oier;        if (sysAuxClkRunning)        {        /* disable timer interrupt in the timer */                S3C44B_TIMER_REG_READ (S3C44B_TCON, oier);        S3C44B_TIMER_REG_WRITE (S3C44B_TCON, oier & ~S3C44B_TIMER4_START);        /* disable timer interrupt in the interrupt controller */        S3C44B_TIMER_INT_DISABLE (AUX_TIMER_INT_LVL);        sysAuxClkRunning = FALSE;                }    }

⌨️ 快捷键说明

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