/*
uCOS-II定义频率,以改变钟节拍的速率.
在DOS下,每秒产生18.20648次时钟节拍,或每隔54.925ms一次.这是因为82C54定时器芯片没有初始化,而使用默认值65535的结果.
如果初始化为58659,那么时钟节拍的速率就会精确地为20.000Hz
*/
void PC_SetTickRate (INT16U freq)
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
INT16U count;
//1.193Mhz/65536 ≈ 18.2HZ每秒18次中断
if (freq == 18) { /* See if we need to restore the DOS frequency */
count = 0;
} else if (freq > 0) {
/* Compute 8254 counts for desired frequency and ... */
/* ... round to nearest count */
//设置计数count=1.193Mhz/f + 0.5
count = (INT16U)(((INT32U)2386360L / freq + 1) >> 1);
} else {
count = 0;
}
OS_ENTER_CRITICAL();
//控制字设置为通道0; 先读低字节,再读高字节; mode3-方波信号发生器; 计数器使用二进制.
outp(TICK_T0_8254_CWR, TICK_T0_8254_CTR0_MODE3); /* Load the 8254 with desired frequency */
outp(TICK_T0_8254_CTR0, count & 0xFF); /* Low byte */
outp(TICK_T0_8254_CTR0, (count >> 8) & 0xFF); /* High byte */
OS_EXIT_CRITICAL();
}