请问:
/* system clock initial */
sysClkOringnalRate = sysClkRateGet();
printf("\n system clock original rate = %d", sysClkOringnalRate);
if (sysClkConnect ((FUNCPTR)clock_main,NO_ARG ) == ERROR)
{
printf("\n System clock ISR connecting failure!");
return (ERROR);
}
if (sysClkRateSet(SYSCLK_TICK) == ERROR)
{
printf("\n System clock rat setting failure!");
return (ERROR);
}
sysClkOringnalRate = sysClkRateGet();
printf("\n system clock rate right now = %d", sysClkOringnalRate);
sysClkEnable();
/* system aux clock */
sysAuxClkRateSet(500);
sysAuxClkConnect((FUNCPTR)interrupt,0);
printf("\n system aux clock rate right now = %d", sysAuxClkRateGet());
sysAuxClkEnable();
/*end clock*/
假如设置SYSCLK_TICK 为500。RateGet两个时钟频率都打印输出是500。但是
void *clock_main(void)
{
tickAnnounce ();
tot_secs = tickets/60;
secs = tot_secs%60;
mins = tot_secs / 60;
hrs = mins / 60;
mins = mins % 60;
return ;
}
/*clock prog*/
void interrupt(void)
{
tickets++;
tot_secs = tickets/60;
secs = tot_secs%60;
mins = tot_secs / 60;
hrs = mins / 60;
mins = mins % 60;
return ;
}
时间都没有变化。就是说实际运行还是每1秒采用默认的60ticks。
请问各位大人可能是什么原因?谢谢!
没研究过,是不是只能在启动时初始化设置一次,后面就不能改了?
是不是你初始化的地方太早了,system初始化值(60)把你的配置又覆盖了?
sysClkRateSet( )
NAME
sysClkRateSet( ) - set the system clock rate
SYNOPSIS
STATUS sysClkRateSet
(
int ticksPerSecond /* number of clock interrupts per second */
)
DESCRIPTION
This routine sets the interrupt rate of the system clock. It is called by usrRoot( ) in usrConfig.c.
There may be interactions between this routine and the POSIX clockLib routines. Refer to the clockLib reference entry.
NOTE
This is a generic page for a BSP-specific routine; this description contains general information only. To determine if this routine is supported by your BSP, or for information specific to your BSP's version of this routine, see the reference pages for your BSP.
[/COLOR]
RETURNS
OK, or ERROR if the tick rate is invalid or the timer cannot be set.
SEE ALSO
sysLib, sysClkEnable( ), sysClkRateGet( ), clockLib, and BSP-specific reference pages for this routine.
也就是说呢,你在这里修改tick了,问题是你BSP里有没有实际的修改时钟?
我读的几个BSP里这个sysClkRateSet都仅仅是改变了一个全局变量而已。而实际上tick是由时钟中断引起的,不改变时钟的参数的话使用这个函数就仅仅改了个全局变量,对系统运行一点作用都没有,除非BSP支持你随便修改时钟,并将这些修改的函数挂到了sysclkrateSet下。这就涉及到BSP里计算时钟的定时了,无非就是频率/tick数得到多少个脉冲出现一个时钟中断,然后把这个数值写到对应的定时器里。
因此我觉得可能是BSP里不支持这个时钟修改。
比如说某个BSP里这个函数大概这么写:
sysClkRateSet(int tps)
{
if((tps>maxtps)||(tips<0))
return error;
systickpersecond=tps;
sysclockdisable();
sysclockenable();
return ok;
}
其中
sysclockdisable();
sysclockenable();
这两行中间应该插入对硬件定时器的更改,否则只修改了全局变量而已