📄 bbu_dd_timercsl.h
字号:
*
\******************************************************************************/
#define TIMER_CNT_OFFSET 2
#define TIMER_CNT0_ADDR 0x01940008u
#define TIMER_CNT1_ADDR 0x01980008u
#define TIMER_CNT2_ADDR 0x01AC0008u
#define TIMER_CNT_DEFAULT 0x00000000u
#define TIMER_CNT_CNT_MASK 0xFFFFFFFFu
#define TIMER_CNT_CNT_MASK 0xFFFFFFFFu
#define TIMER_CNT_CNT_SHIFT 0x00000000u
#define TIMER_CNT_CNT_DEFAULT 0x00000000u
/*----------------------------------------------------------------------------*/
/******************************************************************************\
* TIMER Raw Registers Access Macro Definitions
\******************************************************************************/
#define TIMER_RSET(REG,x) (*(volatile Uint32*)(TIMER_##REG##_ADDR))=((Uint32)(x))
#define TIMER_RGET(REG) (Uint32)(*(volatile Uint32*)(TIMER_##REG##_ADDR))
#define TIMER_FSET(N,REG,FIELD,x) TIMER_RSET(##REG##N, (TIMER_RGET(##REG##N) & ~TIMER_##REG##_##FIELD##_MASK) \
| (((Uint32)(x) << TIMER_##REG##_##FIELD##_SHIFT) & TIMER_##REG##_##FIELD##_MASK))
#define TIMER_FGET(N,REG,FIELD) (Uint32)((((Uint32)(*(volatile Uint32*)(TIMER_##REG##N##_ADDR))) \
& TIMER_##REG##_##FIELD##_MASK) >> TIMER_##REG##_##FIELD##_SHIFT)
/*----------------------------------------------------------------------------*/
/******************************************************************************\
* Handle Based TIMER Register Macro Definitions
\******************************************************************************/
#define TIMER_ADDRH(h,REG) (Uint32)(&(h->baseAddr[TIMER_##REG##_OFFSET]))
#define TIMER_RSETH(h,REG,x) (*(volatile Uint32*)(TIMER_ADDRH(h,##REG)))=((Uint32)(x))
#define TIMER_RGETH(h,REG) (*(volatile Uint32*)(TIMER_ADDRH(h,##REG)))
#define TIMER_FSETH(h,REG,FIELD,x) TIMER_RSETH(h,##REG, (TIMER_RGETH(h,##REG) & ~TIMER_##REG##_##FIELD##_MASK) \
| (((Uint32)(x) << TIMER_##REG##_##FIELD##_SHIFT) & TIMER_##REG##_##FIELD##_MASK))
#define TIMER_FGETH(h,REG,FIELD) (Uint32)((((Uint32)(*(volatile Uint32*)(TIMER_ADDRH(h,##REG)))) \
& TIMER_##REG##_##FIELD##_MASK) >> TIMER_##REG##_##FIELD##_SHIFT)
/*----------------------------------------------------------------------------*/
/******************************************************************************\
* TIMER Global Typedef Declarations
\******************************************************************************/
/* TIMER Handle Object */
typedef struct {
Uint32 allocated;
Uint32 eventId;
volatile Uint32 *baseAddr;
} TIMER_Handle;
/* TIMER configuration structure */
typedef struct {
Uint32 ctl;
Uint32 prd;
Uint32 cnt;
} TIMER_Config;
/*----------------------------------------------------------------------------*/
/******************************************************************************\
* TIMER global macro declarations
\******************************************************************************/
/* TIMER Device Identifiers for Operation of TIMER */
#define TIMER_DEV0 0
#define TIMER_DEV1 1
#define TIMER_DEV2 2
/* Invalid Pointer to TIMER Handle */
#define TIMER_HINV ((void*)(-1))
#define TIMER_DEVICE_ENTRY(devNum) {FALSE, \
(Uint32)IRQ_EVT_TINT##devNum##, \
(volatile Uint32 *)TIMER_BASE_DEV##devNum##}
/*----------------------------------------------------------------------------*/
/******************************************************************************\
* inline function declarations
\******************************************************************************/
IDECL Uint32 TIMER_getEventId(TIMER_Handle *hTimer);
IDECL void TIMER_start(TIMER_Handle *hTimer);
IDECL void TIMER_pause(TIMER_Handle *hTimer);
IDECL void TIMER_resume(TIMER_Handle *hTimer);
IDECL Uint32 TIMER_getPeriod(TIMER_Handle *hTimer);
IDECL void TIMER_setPeriod(TIMER_Handle *hTimer, Uint32 period);
IDECL Uint32 TIMER_getCount(TIMER_Handle *hTimer);
IDECL void TIMER_setCount(TIMER_Handle *hTimer, Uint32 count);
IDECL Uint32 TIMER_getDatIn(TIMER_Handle *hTimer);
IDECL void TIMER_setDatOut(TIMER_Handle *hTimer, Uint32 Val);
IDECL Uint32 TIMER_getTstat(TIMER_Handle *hTimer);
/******************************************************************************\
* TIMER inline function definitions
\******************************************************************************/
/* Obtains event ID for timer device */
IDECL Uint32 TIMER_getEventId(TIMER_Handle *hTimer)
{
return hTimer->eventId;
}
/*----------------------------------------------------------------------------*/
/* Starts timer device running */
IDECL void TIMER_start(TIMER_Handle *hTimer)
{
TIMER_FSETH(hTimer,CTL,HLD,TIMER_CTL_HLD_NO);
TIMER_FSETH(hTimer,CTL,GO,TIMER_CTL_GO_YES);
}
/*----------------------------------------------------------------------------*/
/* Pauses timer */
IDECL void TIMER_pause(TIMER_Handle *hTimer)
{
TIMER_FSETH(hTimer,CTL,HLD,TIMER_CTL_HLD_YES);
}
/*----------------------------------------------------------------------------*/
/* Resumes timer after pause */
IDECL void TIMER_resume(TIMER_Handle *hTimer)
{
TIMER_FSETH(hTimer,CTL,HLD,TIMER_CTL_HLD_NO);
}
/*----------------------------------------------------------------------------*/
/* Returns period of timer device */
IDECL Uint32 TIMER_getPeriod(TIMER_Handle *hTimer)
{
return TIMER_RGETH(hTimer,PRD);
}
/*----------------------------------------------------------------------------*/
/* Sets timer period */
IDECL void TIMER_setPeriod(TIMER_Handle *hTimer, Uint32 period)
{
TIMER_RSETH(hTimer,PRD,period);
}
/*----------------------------------------------------------------------------*/
/* Returns current timer count value */
IDECL Uint32 TIMER_getCount(TIMER_Handle *hTimer)
{
return TIMER_RGETH(hTimer,CNT);
}
/*----------------------------------------------------------------------------*/
/* Sets count value of timer */
IDECL void TIMER_setCount(TIMER_Handle *hTimer, Uint32 count)
{
TIMER_RSETH(hTimer,CNT,count);
}
/*----------------------------------------------------------------------------*/
/* Reads value of TINP pin */
IDECL Uint32 TIMER_getDatIn(TIMER_Handle *hTimer)
{
return TIMER_FGETH(hTimer,CTL,DATIN);
}
/*----------------------------------------------------------------------------*/
/* Sets data output value */
IDECL void TIMER_setDatOut(TIMER_Handle *hTimer, Uint32 val)
{
TIMER_FSETH(hTimer,CTL,DATOUT,val);
}
/*----------------------------------------------------------------------------*/
/* Reads timer status, value of timer output */
IDECL Uint32 TIMER_getTstat(TIMER_Handle *hTimer)
{
return TIMER_FGETH(hTimer,CTL,TSTAT);
}
/*----------------------------------------------------------------------------*/
#endif /* _BBU_DD_TIMERCSL_H_ */
/******************************************************************************\
* End of BBU_DD_TimerCsl.h
\******************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -