📄 timer.h
字号:
/*-----------------------------------------------------------------------------
@@
@@ (Summary) : LH7953x series Timer Device Driver Header File
@@
@@ (Comment) : Timer Header File
@@
@@ (Author) :
@@
@@ (History) :
@@
@@ (RCS ID) :
@@
-----------------------------------------------------------------------------*/
/*
apd_TIMERInit(timer_num, timer_init,interval);
apd_TIMERSetInterval(timer_num,interval);
apd_TIMERGetInterval(timer_num);
apd_TIMERGetCounter(timer_num);
apd_TIMERClrIntr(timer_num);
apd_TIMERSetPrescale(timer_num,prescale);
apd_TIMEREnable(timer_num)
apd_TIMERSetPeriodicMode(timer_num)
apd_TIMEREnableCarry(timer_num)
apd_TIMER3SetExtClk()
apd_TIMER3TrackExtClk()
apd_TIMERDisable(timer_num)
apd_TIMERSetFreeRunningMode(timer_num)
apd_TIMERDisableCarry(timer_num)
apd_TIMER3SetIntClk()
apd_TIMER3SetNormalOp()
*/
#ifndef TIMER_H
#define TIMER_H
/*+include files*************************************************************/
/* */
/* */
/**************************************************************************-*/
#include "type_def.h"
#include "dev_def.h"
#include "timer_def.h"
/*+Public Macro definitions**************************************************/
/* */
/* */
/**************************************************************************-*/
/*+Public Type definitions***************************************************/
/* */
/* */
/**************************************************************************-*/
/*-----------------------------------------------------------------------------
@@ {Name} : APD_TIMER_ENABLE_TYPE
@@
@@ {Summary}: Timer enable bit setting
@@
@@ {Desc} : Defines if timer is enabled or disabled
@@
@@ {End} :
-----------------------------------------------------------------------------*/
typedef enum {
APD_TIMER_DISABLE = 0, /* Counter/Timer disabled */
APD_TIMER_ENABLE = APD_TIMER_ENABLE_BIT /* Counter/Timer enabled */
} APD_TIMER_ENABLE_TYPE;
/*-----------------------------------------------------------------------------
@@ {Name} : APD_TIMER_MODE_TYPE
@@
@@ {Summary}: Timer mode bit
@@
@@ {Desc} : Defines if timer is free running or periodic mode
@@
@@ {End} :
-----------------------------------------------------------------------------*/
typedef enum {
APD_TIMER_FREERUN = 0, /* Free-running mode */
APD_TIMER_PERIODIC = APD_TIMER_MODE_BIT /* Periodic Timer mode */
} APD_TIMER_MODE_TYPE;
/*-----------------------------------------------------------------------------
@@ {Name} : APD_TIMER_CLEAR_TYPE
@@
@@ {Summary}: Timer clear bit
@@
@@ {Desc} : For LH79531: Available for CT2 only.
@@ For LH79532 and LH79533: Available for CT3 only.
@@ When set, the CTx is automatically reloaded (0xFFFF) after every
@@ underflow
@@
@@ {End} :
-----------------------------------------------------------------------------*/
typedef enum {
// #ifdef LH79531
// APD_TIMER_CT2_SET = APD_TIMER_CLEAR_BIT, /* CT2 automatically reload to 0xFFFF */
// #endif
// #ifdef LH79532_LH79533
APD_TIMER_CT3_SET = APD_TIMER_CLEAR_BIT, /* CT3 automatically reload to 0xFFFF */
// #endif
APD_TIMER_NORM_OP = 0 /* CTx normal operation */
} APD_TIMER_CLEAR_TYPE;
/*-----------------------------------------------------------------------------
@@ {Name} : APD_TIMER_CLOCK_TYPE
@@
@@ {Summary}: Timer external clock bit
@@
@@ {Desc} : For LH79531: Available for CT2 only.
@@ For LH79532 and LH79533: Available for CT3 only.
@@ To set whether CTx uses internal system clock or external
@@ clock for timing purpose
@@
@@ {End} :
-----------------------------------------------------------------------------*/
typedef enum {
APD_TIMER_INT_SYS_CLK = 0, /* use Internal System clock */
APD_TIMER_EXT_CLK = APD_TIMER_X_BIT /* use External clock */
} APD_TIMER_CLOCK_TYPE;
/*-----------------------------------------------------------------------------
@@ {Name} : APD_TIMER_PRESCALE_TYPE
@@
@@ {Summary}: Timer prescale settings
@@
@@ {Desc} : Defines the timer prescale setting
@@
@@ {End} :
-----------------------------------------------------------------------------*/
typedef enum {
APD_TIMER_PRESCALE_4 = 0x0, /* clock divided by 4 */
APD_TIMER_PRESCALE_64 = 0x4, /* clock divided by 64 */
APD_TIMER_PRESCALE_1024 = 0x8, /* clock divided by 1024 */
APD_TIMER_PRESCALE_1 = 0xC /* clock divided by 1 (for LH79531's CT2 or LH79532's CT3 or LH79533's CT3; Reserved for others) */
} APD_TIMER_PRESCALE_TYPE;
/*-----------------------------------------------------------------------------
@@ {Name} : APD_TIMER_CARRY_TYPE
@@
@@ {Summary}: Timer carry bit
@@
@@ {Desc} : Defines if the timer are to be cascaded for use
@@
@@ {End} :
-----------------------------------------------------------------------------*/
typedef enum {
APD_TIMER_DISABLE_CARRY = 0, /* Disable Carry */
APD_TIMER_ENABLE_CARRY = APD_TIMER_CI_BIT /* Enabled Carry from CT0 and/or CT1 and/or CT2 and/or CT3*/
} APD_TIMER_CARRY_TYPE;
/*-----------------------------------------------------------------------------
@@ {Name} : APD_TIMER_NUM
@@
@@ {Summary}: Counter/Timer number
@@
@@ {Desc} : Defines which counter/timer
@@
@@ {End} :
-----------------------------------------------------------------------------*/
typedef enum {
APD_TIMER3 = 3, /* timer 3 */
APD_TIMER2 = 2, /* timer 2 */
APD_TIMER1 = 1, /* timer 1 */
APD_TIMER0 = 0 /* timer 0 */
} APD_TIMER_NUM;
/*-----------------------------------------------------------------------------
@@ {Name} : APD_TIMER_INIT_TYPE
@@
@@ {Summary}: A structure defining how each timer should be initialized to
@@
@@ {Desc} : A structure defining how each timer should be initialized:
@@ enablebit - is timer enable or disable?
@@ modebit - is timer periodic or free running?
@@ clearbit - is timer to be automatically reloaded to 0xFFFF?
@@ (LH79531: for timer 2 only, other will be set as normal operation
@@ LH79432 and LH79533: for timer 3 only, other will be set as normal operation)
@@ clockbit - is timer using internal or external clock?
@@ prescalebit - prescale setting for timer
@@ carrybit - should the timer(x) be cascaded for use with timer(x+1)?
@@
@@ {End} :
-----------------------------------------------------------------------------*/
typedef struct {
APD_TIMER_ENABLE_TYPE enablebit;
APD_TIMER_MODE_TYPE modebit;
APD_TIMER_CLEAR_TYPE clearbit;
APD_TIMER_CLOCK_TYPE clockbit;
APD_TIMER_PRESCALE_TYPE prescalebit;
APD_TIMER_CARRY_TYPE carrybit;
} APD_TIMER_INIT_TYPE;
#ifdef APD_TIMER_C
/*-------------------------- Local context - START -------------------------*/
/*+include files*************************************************************/
/* */
/* */
/**************************************************************************-*/
#define VISIBLE /* Mark as LOCAL context */
/*+Local Type definitions****************************************************/
/* */
/* */
/**************************************************************************-*/
/*+Local Macro definitions***************************************************/
/* */
/* */
/**************************************************************************-*/
/*+Local function prototypes*************************************************/
/* */
/* Name Type Abstract */
/* ---- ---- -------- */
/* */
/**************************************************************************-*/
/*+Local data declarations***************************************************/
/* */
/* Name Description */
/* ---- ----------- */
/**************************************************************************-*/
/*-------------------------- Local context - END ---------------------------*/
#else
#define VISIBLE extern /* Mark as GLOBAL context */
#endif
/*------------------------- Global context - START -------------------------*/
/*+Public data declarations**************************************************/
/* */
/* Name Description */
/* ---- ----------- */
/**************************************************************************-*/
/*+Public function prototypes************************************************/
/* */
/* Name Type Abstract */
/* ---- ---- -------- */
/* */
/**************************************************************************-*/
VISIBLE void apd_TIMERInit(APD_TIMER_NUM timer_num, APD_TIMER_INIT_TYPE timer_init, unsigned short interval);
VISIBLE void apd_TIMERClrControlRegBit(APD_TIMER_NUM timer_num, unsigned char bdata);
VISIBLE void apd_TIMERSetControlRegBit(APD_TIMER_NUM timer_num, unsigned char bdata);
VISIBLE void apd_TIMERSetInterval(APD_TIMER_NUM timer_num, unsigned short interval);
VISIBLE unsigned short apd_TIMERGetInterval(APD_TIMER_NUM timer_num);
VISIBLE unsigned short apd_TIMERGetCounter(APD_TIMER_NUM timer_num);
VISIBLE void apd_TIMERClrIntr(APD_TIMER_NUM timer_num);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -