0

私はそれを宣言するいくつかの一般的なヘッダーを持っています (で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。なんで?

4

1 に答える 1

4

変数をとして宣言します。これは、変数staticが含まれているファイルに対してローカルであることを意味します。inは。の変数timestampmain.cは異なりmeta.cます。

次のように宣言timestampすることで、これを修正できます。main.c

volatile unsigned int timestamp = 0;

そしてmeta.cそのように:

extern volatile unsigned int timestamp;
于 2012-12-21T10:57:58.483 に答える