📄 lpc_timer.h
字号:
#ifndef __LPC_TIMER_H
#define __LPC_TIMER_H
/***********************************************************************
* BU MMS China, Philips Semiconductor Software Support
* Embest info&Tech Co. Software Support
*---------------------------------------------------------------------------
* The software is delivered "AS IS" without warranty or condition of any
* kind, either express, implied or statutory. Everybody can use it as
* it is opened and without copyright. We will not take any law responsibility
* for any problem produced by using this software.
*---------------------------------------------------------------------------
* File name: LPC_Timer.h
* Description: define Timer structure and relative micro
*
* History:
* 1. Date: Aug 12, 2004
* Author: Shawn Zhang
* Description: Create
*
* $Revision: 1.0 $
**********************************************************************/
#include "LPC_Base.h"
#include "LPC_Type.h"
#include "LPC_SysControl.h"
/* Timer Control register bit descriptions */
#define TCR_ENABLE_BIT 0
#define TCR_RESET_BIT 1
/* The channel name which is used in matching, in fact they represent
corresponding Match Register */
#define CH_MAXNUM 4
#define CH0 0
#define CH1 1
#define CH2 2
#define CH3 3
/* The channel name which is used in capturing, in fact they represent
corresponding Capture Register */
#define CPCH_MAXNUM 4
#define CPCH0 0
#define CPCH1 1
#define CPCH2 2
#define CPCH3 3
/* The actions when matching */
#define TimerAction_Interrupt 0x1
#define TimerAction_ResetTimer 0x2
#define TimerAction_StopTimer 0x4
/* The trigger type when capturing */
#define TimerCPTrigger_Rising 0x1
#define TimerCPTrigger_Falling 0x2
/* Interrupt source type */
#define TIMERMR0Int 0x01
#define TIMERMR1Int 0x02
#define TIMERMR2Int 0x04
#define TIMERMR3Int 0x08
#define TIMERCR0Int 0x10
#define TIMERCR1Int 0x20
#define TIMERCR2Int 0x40
#define TIMERCR3Int 0x80
#define TIMERALLInt 0xFF
/* Device number */
typedef enum {
TIMER0 = 0,
TIMER1
} LPC_Timer_Channel_t;
/* External Match Control Action Type */
typedef enum {
DONOTHING = 0,
SETTOLOW,
SETTOHIGH,
TOGGLE
} LPC_Timer_ExtAction_t;
typedef struct {
bool Enable;
lpc_uint8 Action;
long TimeValue;
void (* Fnpr)(void *);
void * FnprArg;
} LPC_Timer_MatchChannel_t;
typedef struct {
bool Enable;
lpc_uint8 TriggerType;
bool EnableInt;
void (* Fnpr)(void *);
void * FnprArg;
long CPValue;
} LPC_Timer_CaptureChannel_t;
typedef struct {
unsigned int Precision;
unsigned long Prescaler;
LPC_Timer_MatchChannel_t MatchCH[CH_MAXNUM];
LPC_Timer_CaptureChannel_t CaptureCH[CPCH_MAXNUM];
LPC_Timer_ExtAction_t ExtAction[CH_MAXNUM];
lpc_uint8 ExtBitValue[CH_MAXNUM]; // low or high, only 1 bit
} LPC_Timer_Config_t;
/* Declare functions */
#if TIMER_Init_EN == 1
int TIMER_Init(LPC_Timer_Channel_t DevNum, unsigned long precision);
#endif
#if TIMER_Reset_EN == 1
int TIMER_Reset(LPC_Timer_Channel_t DevNum);
#endif
#if TIMER_Start_EN == 1
int TIMER_Start(LPC_Timer_Channel_t DevNum);
#endif
#if TIMER_Stop_EN == 1
int TIMER_Stop(LPC_Timer_Channel_t DevNum);
#endif
#if TIMER_GetPrescaler_EN == 1
unsigned long TIMER_GetPrescaler(LPC_Timer_Channel_t DevNum);
#endif
#if TIMER_SetMatchAction_EN == 1
int TIMER_SetMatchAction(LPC_Timer_Channel_t DevNum,
lpc_uint8 CHNum,
lpc_uint8 action ,
unsigned long TimeValue,
void (* Fnpr)(void *),
void * FnprArg,
LPC_Timer_ExtAction_t ExtAction);
#endif
#if TIMER_GetTimerMatch_EN == 1
int TIMER_GetTimerMatch(LPC_Timer_Channel_t DevNum, lpc_uint8 CHNum,
lpc_uint8 * pAction , unsigned long *pMatchValue);
#endif
#if TIMER_GetTimerExternalMatch_EN == 1
int TIMER_GetTimerExternalMatch(LPC_Timer_Channel_t DevNum, lpc_uint8 CHNum,
unsigned int * pAction , unsigned int *pExternalMatchValue);
#endif
#if TIMER_SetCaptureAction_EN == 1
int TIMER_SetCaptureAction (LPC_Timer_Channel_t DevNum,
lpc_uint8 CPCHNum,
lpc_uint8 TriggerType,
bool EnableInt,
void (* Fnpr)(void *),
void * FnprArg );
#endif
#if TIMER_GetTimerCapture_EN == 1
int TIMER_GetTimerCapture(LPC_Timer_Channel_t DevNum, lpc_uint8 CPCHNum,
unsigned long *pCaptureValue, lpc_uint8 *pTriggerType, bool *pEnableInt);
#endif
#if TIMER_CheckIntType_EN == 1
int TIMER_CheckIntType(LPC_Timer_Channel_t DevNum);
#endif
#if TIMER_ClearInt_EN == 1
int TIMER_ClearInt(LPC_Timer_Channel_t DevNum, int IntType);
#endif
#if TIMER_GetREGValue_CR_EN == 1
unsigned long TIMER_GetREGValue_CR(LPC_Timer_Channel_t DevNum, int CRNum);
#endif
#if TIMER_GetREGValue_TC_EN == 1
unsigned long TIMER_GetREGValue_TC(LPC_Timer_Channel_t DevNum);
#endif
__irq void TIMER0_ISR (void);
void TIMER1_ISR (void);
extern void TIMER0_VectISR (void);
extern void TIMER1_VectISR (void);
/* Time definition */
#define sec_T0 *(SYS_GetFpclk()/TIMER_GetPrescaler(TIMER0))
#define msec_T0 *(SYS_GetFpclk()/(TIMER_GetPrescaler(TIMER0)*1000))
#define usec_T0 *(SYS_GetFpclk()/(TIMER_GetPrescaler(TIMER0)*1000000))
#define sec_T1 *(SYS_GetFpclk()/TIMER_GetPrescaler(TIMER1))
#define msec_T1 *(SYS_GetFpclk()/(TIMER_GetPrescaler(TIMER1)*1000))
#define usec_T1 *(SYS_GetFpclk()/(TIMER_GetPrescaler(TIMER1)*1000000))
#endif //__LPC_TIMER_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -