📄 systimer.h
字号:
#include "73x_lib.h"
#include "def.h"
void SysTimerInit(void)
{
CMU_InitTypeDef CMU_InitStruct;
TB_InitTypeDef TB_InitStructure;
PRCCU_InitTypeDef PRCCU_InitStructure;
/* TB0 Clock Enable */
CFG_PeripheralClockConfig(CFG_CLK_TB0 , DISABLE);
CFG_PeripheralClockConfig(CFG_CLK_TB0 , ENABLE);
/* EIC Configuration */
EIC_IRQChannelConfig(TB0_IRQChannel, ENABLE );
EIC_IRQChannelPriorityConfig(TB0_IRQChannel,1);
CMU_InitStruct.CMU_CKSEL0 = CMU_CKSEL0_CKOSC;
CMU_Init (&CMU_InitStruct);
PRCCU_InitStructure.PRCCU_DIV2 = ENABLE;
PRCCU_InitStructure.PRCCU_MCLKSRC_SRC = PRCCU_MCLKSRC_PLL ;
PRCCU_InitStructure.PRCCU_PLLDIV = PRCCU_PLLDIV_2;
PRCCU_InitStructure.PRCCU_PLLMUL = PRCCU_PLLMUL_16;
PRCCU_InitStructure.PRCCU_FREEN = DISABLE;
PRCCU_Init(&PRCCU_InitStructure);
TB_InitStructure.TB_CLK_Source = TB_CLK_INTERNAL ;
TB_InitStructure.TB_Prescaler =31;
TB_InitStructure.TB_Preload =0xffff;
TB_Init (TB0, &TB_InitStructure);
TB_ITConfig (TB0,ENABLE);
TB_Cmd(TB0, ENABLE);
TsysCnt = 0xffff0000;
}
void SetUserTimer(uint32 *timer)
{
uint32 temp;
uint16 TBx_SR;
EIC_IRQCmd(DISABLE);
temp = TB0->CNT;
*timer = TsysCnt + temp; //notice: 必须先计算完成才能开中断。
TBx_SR = TB0->SR;
EIC_IRQCmd(DISABLE);
if (TBx_SR&0X01)
{
if (temp > 0x8000) //4096 TB0 Ticks
*timer -= 0x10000;
}
}
uint32 ReadUserTimer(uint32 *timer)
{
uint32 temp;
uint32 currentT;
uint16 TBx_SR;
EIC_IRQCmd(DISABLE);
temp = TB0->CNT;
currentT = TsysCnt + temp; //notice: 必须先计算完成才能开中断。
TBx_SR = TB0->SR;
EIC_IRQCmd(ENABLE);
if (TBx_SR&0X01)
{
if (temp > 0x8000) //4096 TB0 Ticks
currentT -= 0x10000;
}
return (*timer - currentT);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -