前言
OS Timer定时器功能比较简单,这个定时器一般作为间隔定时器使用,对于OS系统,可以作为节拍(tick)定时器。在间隔定时器模式,是一个32bit倒计时,计数到0,产生中断。
- OS Timer定时器寄存器介绍
1.1、OSTMn比较寄存器OSTMnCMP — OSTMn Compare Register
Bit position | Bit Name | Function |
31 - 0 | OSTMnCMP | 间隔定时模式:倒计时初始值 比较模式:比较寄存器值 |
1.2、OSTMn计数器寄存器OSTMnCNT — OSTMn Counter Register
Bit position | Bit Name | Function |
31 - 0 | OSTMnCNT | 间隔定时模式:向下计时 比较模式:向上计数 |
1.3、OSTMn计数使能寄存器OSTMnTE—OSTMn Count Enable Status Register
Bit position | Bit Name | Function |
0 | OSTMnTE | 0:计时禁止 1:使能计数 |
使用定时器,寄存器置1使能。
1.4、OSTMn计数开始寄存器OSTMnTS — OSTMn Count Start Trigger Register
Bit position | Bit Name | Function |
0 | OSTMnTS | 0:无效 1:开始计数 |
使用定时器,使能寄存器置1使能,开始寄存器置1开始计时。
1.5、OSTMn计数停止寄存器OSTMnTT — OSTMn Count Stop Trigger Register
Bit position | Bit Name | Function |
0 | OSTMnTT | 0:无效 1:停止计数并且清使能位 |
例程:
Void OSTIM_init(void)
{
OSTM0EMU = 0x00u; /* Counter is stopped when Debugger takes control */
OSTM0CTL = 0x01u; /* IntervalTimer Mode / Interrupt on CounterStart enabled */
OSTM0CMP = 40000u; /* OSTM0 Cycle = 40000/40MHz = 1ms */
/* StartTrigger */
OSTM0TS = 0x01u;
INTC2TBOSTM0 = 1u; /* Table interrupt is enabled by setting the table bit to 1 */
INTC2MKOSTM0 = 0u; /* Interrupt is unmasked by setting the mask bit to 0 */
INTC2P2OSTM0 = 0u;
INTC2P1OSTM0 = 1u;
INTC2P0OSTM0 = 0u;
}