我需要处理一个计数器,它可以为我的应用程序提供标记。计数器是 32 位的,所以我需要知道的是如何处理它。例如:
我有一个返回 a 的函数,(timestamp + shifttime)
我还有一个返回 1 或 0 的函数,具体取决于时间是否已过,但我的计数器有可能会换行,我该如何处理?
非常感谢大家的回复。我将在此编辑中提供更多详细信息。
我正在使用 STM32 Cortex-M3。我想使用 RTC 计数器将其用作我的应用程序的刻度,以安排需要在特定时间间隔发生的任务。RTC 可以产生溢出中断,因此检测中断不是问题。我遇到的主要问题(或者至少我认为是一个问题)是某些任务获得(timestamp+shift)
ie
int main( void )
{
FlashLedTimeStamp = ReturnCounter( 20 ); // currentcounter value + a shift of 20
StatusLedTimeStamp = ReturnCounter( 3 ); // currentcounter value + a shift of 3
// then later on ....
while(1)
{
/* other tasks could go here */
if( HasTimeElapsed( FlashLedTimeStamp ) )
{
/* do something and get another timestamp value */
FlashLedTimeStamp = ReturnCounter( 20 ); // currentcounter value + a shift of 20
}
if( HasTimeElapsed( StatusLedTimeStamp ) )
{
/* do something and get another timestamp value */
FlashLedTimeStamp = StatusLedTimeStamp( 3 ); // currentcounter value + a shift of 3
}
}
}
让我们假设我的 RTC 计数器只有 8 位长,以便于计算。
FlashLedTimeStamp = 14
如果当我获得时间戳时我当前的计数器为 250 ,这意味着我StatusLedTimeStamp = 253
将如何检查它FlashLedTimeStamp
是否已过期?
请记住,我不一定会一直检查以查看当前计数器是什么以及某些时间戳是否已过期。我希望这能说明我遇到的问题是什么。