我有一些通用的标题,我在其中声明它(在std.h
):
static volatile unsigned int timestamp;
我有中断,我增加它(在main.c
):
void ISR_Pit(void) {
unsigned int status;
/// Read the PIT status register
status = PIT_GetStatus() & AT91C_PITC_PITS;
if (status != 0) {
/// 1 = The Periodic Interval timer has reached PIV since the last read of PIT_PIVR.
/// Read the PIVR to acknowledge interrupt and get number of ticks
///Returns the number of occurrences of periodic intervals since the last read of PIT_PIVR.
timestamp += (PIT_GetPIVR() >> 20);
//printf(" --> TIMERING :: %u \n\r", timestamp);
}
}
在另一个模块中,我有必须使用它的程序(在meta.c
):
void Wait(unsigned long delay) {
volatile unsigned int start = timestamp;
unsigned int elapsed;
do {
elapsed = timestamp;
elapsed -= start;
//printf(" --> TIMERING :: %u \n\r", timestamp);
}
while (elapsed < delay);
}
首先printf
显示正确增加timestamp
,但等待printf
总是显示0
。为什么?