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

📄 timer.c

📁 philips arm7 lpc2103的常用功能的库函数第二部分
💻 C
📖 第 1 页 / 共 5 页
字号:
    volatile uint32 *puiBaseAddr;
    
    if (uiID >= __TIMER_MAX_NUM) {                                      /*  检查参数有效性              */
	    return (uint32)(OPERATE_FAIL);
	}    
	
	pRsv = pRsv ;                                                       /*  为了防止编译器警告          */
	
    /*
     *  在停止定时器之前,确保定时器已进行工作,否则返回错误.
     */
    if (GpTimerStruInfoData[uiID]->uiTimerInitInfo == FALSE) {
         return (uint32)(OPERATE_FAIL);
    }
    
	uiOffsetBase = GpTimerStruInfoData[uiID]->uiOffsetBase;
    puiBaseAddr  = GpTimerStruInfoData[uiID]->puiAddrBase;
    
    puiBaseAddr[__B_TIMER_TCR  << uiOffsetBase] = 0x00;                 /*  TCR= 0;停止定时器           */ 
 
    return (uint32)(OPERATE_SUCCESS);
}

/*********************************************************************************************************
** Function name:      timeReset
** Descriptions:       复位定时器
** Input parameters:   uiID  --部件设备号 :0-Time0;1-Time1;2-Time2;3-Time3		          
**                     pRsv  --保留指针参数,可输入NULL.
** Output parameters:  OPERATE_FAIL    -- 操作失败
** Returned value:     OPERATE_SUCCESS -- 操作成功
*********************************************************************************************************/
uint32    timeReset (uint32 uiID, void  *pRsv)

{
    uint32 i;
    
    volatile uint32  uiOffsetBase;
    volatile uint32 *puiBaseAddr;
    
    if (uiID >= __TIMER_MAX_NUM) {                                      /*  检查参数有效性              */
	    return (uint32)(OPERATE_FAIL);
	}    
	
	pRsv = pRsv ;                                                       /*  为了防止编译器警告          */
    
    IRQDisable();                                                       /*  关IRQ中断                   */

    GpTimerStruInfoData[uiID]->uiOffsetBase = 0;                        /*  获取定时器部件的物理地址    */
   	GpTimerStruInfoData[uiID]->puiAddrBase  = (uint32*)__GuiTimerBaseAddrTab[uiID];
    
    uiOffsetBase = GpTimerStruInfoData[uiID]->uiOffsetBase;
    puiBaseAddr  = GpTimerStruInfoData[uiID]->puiAddrBase;
   
    IRQEnable();                                                        /*  开IRQ中断                   */
    
    puiBaseAddr[__B_TIMER_IR << uiOffsetBase] = 0xFF;                   /*  清零定时器所有中断标志      */ 

    for (i = 1; i < 16; i++) {
        puiBaseAddr[i << uiOffsetBase] = 0x00;                          /*  清除余下的定时器寄存器内容  */   
    } 

    puiBaseAddr[__B_TIMER_CTCR << uiOffsetBase] = 0x00;                 /*  CTCR = 0;重新设置为定时功能 */

    return (uint32)(OPERATE_SUCCESS);
}

/*********************************************************************************************************
** Function name:       __timeMatGpioInit
**
** Descriptions:        定时器匹配引脚初始化
**
** input parameters:    pTimerInfo -- 定时器设备描述符结构体指针
**		                uiMatN     -- 匹配通道号.如0,1,2,3.
**                      pRsv       -- 保留指针参数,可输入NULL.
** Returned value:      OPERATE_SUCCESS 操作正确
**                      OPERATE_FAIL 操作错误
**
** NOTICE :             此函数由于涉及到具体不同ARM处理器芯片的硬件配置,不一定适用于所有LPC2000/2200系列.
**                      用户须确认所用芯片为:LPC2290, LPC2294 才能确定使用此配置函数!!
*********************************************************************************************************/
#if __TIMER_MAT_GPIO > 0

static uint32    __timeMatGpioInit (__PTIMER_INFO pTimerInfo,
                                    uint32        uiMatN, 
                                    void         *pRsv)
{
    volatile uint32  uiGpioOffset;
    volatile uint32 *puiGpioAddr;
    
    if (pTimerInfo == NULL) {                                           /*  检查结构体指针是否有效       */
        return (uint32)(OPERATE_FAIL);
    }
    
    /*
     *  管脚功能选择寄存器基址设置
     */
    puiGpioAddr =(uint32*) __GuiTPinBaseAddrTab[0];                     /*  此处获取PINSEL寄存器的基址   */
    uiGpioOffset = 0;                                                   /*  因为PINSELx寄存器长度为32位,
                                                                            所以定义的指针puiGpioAddr长度
                                                                            为32位,故一次数组单位偏移长度
                                                                            为4*8 = 32位,故偏移数值取0   */
    /*
     *  选择定时器器件编号.
     */
    if (pTimerInfo->uiTimerID == TIME_0) {                              /*  定时器0                     */   
	    switch (uiMatN) {
	    
	    case 0:
	        puiGpioAddr[__B_TIMER_PINSEL0 << uiGpioOffset] &=  ~(0x03 <<  6 );
	                                                                    /*  屏蔽相关的引脚设置位,位清零 */
	        puiGpioAddr[__B_TIMER_PINSEL0 << uiGpioOffset] |=   (0x02 <<  6 );
	                                                                    /*  设置P0_3 引脚为 匹配0  功能 */                                                                                                                                                                              
	        break;
	    case 1:
	        puiGpioAddr[__B_TIMER_PINSEL0 << uiGpioOffset] &=  ~(0x03 <<  10);
	                                                                    /*  屏蔽相关的引脚设置位,位清零 */
	        puiGpioAddr[__B_TIMER_PINSEL0 << uiGpioOffset] |=   (0x02 <<  10);
	                                                                    /*  设置P0_5 引脚为 匹配1 功能  */                                                            
	        break;
	    case 2:
	        puiGpioAddr[__B_TIMER_PINSEL1 << uiGpioOffset] &=  ~(0x03 <<  0 );
	                                                                    /*  屏蔽相关的引脚设置位,位清零 */
	        puiGpioAddr[__B_TIMER_PINSEL1 << uiGpioOffset] |=   (0x02 <<  0 );
	                                                                    /*  设置P0_16 引脚为 匹配2 功能 */
	        break;
	   
	    default:
	        { return (uint32)(PIN_ERR); }                               /*  通道参数错误返回            */
	              
	     } 
    } else if (pTimerInfo->uiTimerID == TIME_1){                                                            /*  定时器1                     */      
    
       	switch (uiMatN) {
	    
	    case 0:
	        puiGpioAddr[__B_TIMER_PINSEL0 << uiGpioOffset] &=  ~(0x03 <<  24);
	                                                                    /*  屏蔽相关的引脚设置位,位清零 */
	        puiGpioAddr[__B_TIMER_PINSEL0 << uiGpioOffset] |=   (0x02 <<  24);
	                                                                    /*  设置P0_12 引脚为 匹配0 功能 */
	        break;
	    case 1:
	        puiGpioAddr[__B_TIMER_PINSEL0 << uiGpioOffset] &=  ~(0x03 <<  26);
	                                                                    /*  屏蔽相关的引脚设置位,位清零 */
	        puiGpioAddr[__B_TIMER_PINSEL0 << uiGpioOffset] |=   (0x02 <<  26);
	                                                                    /*  设置P0_13 引脚为 匹配1 功能 */
	        break;
	    case 2:
	      
	        puiGpioAddr[__B_TIMER_PINSEL1 << uiGpioOffset] &=  ~(0x03 <<  6 );
	                                                                    /*  屏蔽相关的引脚设置位,位清零 */
	        puiGpioAddr[__B_TIMER_PINSEL1 << uiGpioOffset] |=   (0x02 <<  6 );
	                                                                    /*  设置P0_19 引脚为 匹配3 功能 */                                                           /*  设置P0_17 引脚为 匹配2 功能 */
	        break;
	    case 3:
	       
	        puiGpioAddr[__B_TIMER_PINSEL1 << uiGpioOffset] &=  ~(0x03 <<  8 );
	                                                                    /*  屏蔽相关的引脚设置位,位清零 */
	        puiGpioAddr[__B_TIMER_PINSEL1 << uiGpioOffset] |=   (0x02 <<  8 );
	                                                                    /*  设置P0_20 引脚为 匹配3 功能 */                                                            /*  设置P0_18 引脚为 匹配3 功能 */
	       
	        break;
	    default:
	        { return (uint32)(PIN_ERR); }                               /*  通道参数错误返回            */
	     } 
    }else if (pTimerInfo->uiTimerID == TIME_2){                                                            /*  定时器1                     */      
    
       	switch (uiMatN) {
	    
	    case 0:
	        puiGpioAddr[__B_TIMER_PINSEL0 << uiGpioOffset] &=  ~(0x03 <<  14);
	                                                                    /*  屏蔽相关的引脚设置位,位清零 */
	        puiGpioAddr[__B_TIMER_PINSEL0 << uiGpioOffset] |=   (0x02 <<  14);
	                                                                    /*  设置P0_07 引脚为 匹配0 功能 */
	        break;
	    case 1:
	        puiGpioAddr[__B_TIMER_PINSEL0 << uiGpioOffset] &=  ~(0x03 <<  16);
	                                                                    /*  屏蔽相关的引脚设置位,位清零 */
	        puiGpioAddr[__B_TIMER_PINSEL0 << uiGpioOffset] |=   (0x02 <<  16);
	                                                                    /*  设置P0_08 引脚为 匹配1 功能 */
	        break;
	    case 2:
	      
	        puiGpioAddr[__B_TIMER_PINSEL0 << uiGpioOffset] &=  ~(0x03 <<  18 );
	                                                                    /*  屏蔽相关的引脚设置位,位清零 */
	        puiGpioAddr[__B_TIMER_PINSEL0 << uiGpioOffset] |=   (0x02 <<  18 );
	                                                                    /*  设置P0_09 引脚为 匹配3 功能 */                                                           /*  设置P0_17 引脚为 匹配2 功能 */
	        break;
	   
	    default:
	        { return (uint32)(PIN_ERR); }                               /*  通道参数错误返回            */
	     } 
    }else if (pTimerInfo->uiTimerID == TIME_3){                                                            /*  定时器1                     */      
    
       	switch (uiMatN) {
	    
	    case 0:
	        puiGpioAddr[__B_TIMER_PINSEL1 << uiGpioOffset] &=  ~(0x03 <<  10);
	                                                                    /*  屏蔽相关的引脚设置位,位清零 */
	        puiGpioAddr[__B_TIMER_PINSEL1 << uiGpioOffset] |=   (0x02 <<  10);
	                                                                    /*  设置P0_21 引脚为 匹配0 功能 */
	        break;
	    case 1:
	        puiGpioAddr[__B_TIMER_PINSEL0 << uiGpioOffset] &=  ~(0x03 <<  0);
	                                                                    /*  屏蔽相关的引脚设置位,位清零 */
	        puiGpioAddr[__B_TIMER_PINSEL0 << uiGpioOffset] |=   (0x02 <<  0);
	                                                                    /*  设置P0_0 引脚为 匹配1 功能 */
	        break;
	    case 2:
	      
	        puiGpioAddr[__B_TIMER_PINSEL0 << uiGpioOffset] &=  ~(0x03 <<  2 );
	                                                                    /*  屏蔽相关的引脚设置位,位清零 */
	        puiGpioAddr[__B_TIMER_PINSEL0 << uiGpioOffset] |=   (0x02 <<  2 );
	                                                                    /*  设置P0_1 引脚为 匹配2 功能 */                                                           /*  设置P0_17 引脚为 匹配2 功能 */
	        break;
	    case 3:
	       
	        puiGpioAddr[__B_TIMER_PINSEL1 << uiGpioOffset] &=  ~(0x03 <<  28 );
	                                                                    /*  屏蔽相关的引脚设置位,位清零 */
	        puiGpioAddr[__B_TIMER_PINSEL1 << uiGpioOffset] |=   (0x02 <<  28 );
	                                                                    /*  设置P0_30 引脚为 匹配3 功能 */                                                            /*  设置P0_18 引脚为 匹配3 功能 */
	       
	        break;
	    default:
	        { return (uint32)(PIN_ERR); }                               /*  通道参数错误返回            */
	     } 
    }
    return (uint32)(OPERATE_SUCCESS);
}

#endif

/*********************************************************************************************************
** Function name:    timerMatInit
** Descriptions:     定时器用作匹配功能的初始化
**
** Input parameters: uiID  -- 部件设备号。0-Time0;1-Time1;2-Time2;3-Time3
**                   pcArg -- 字符串输入指针参数,输入参数格式为:关键字0=值0[空格]关键字1=值1[空格]......
**                   关键字  T_C       :0表示用内部计数器进行匹配,1表示用外部计数进行匹配 
**                           CountN    :计数采样通道选择,0~3分别表示通道0(CAPn.0)至通道3(CAPn.3),当T_C等于0时无意义   
**                           CountMode :计数控制模式,0表示CAP输入的上升沿递增计数,

⌨️ 快捷键说明

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