3

組み込み ARM デバイスで gettimeofday を使用しようとしていますが、使用できないようです。

gnychis@ubuntu:~/Documents/coexisyst/econotag_firmware$ make
Building for board: redbee-econotag
       CC obj_redbee-econotag/econotag_coexisyst_firmware.o
LINK (romvars) econotag_coexisyst_firmware_redbee-econotag.elf
/home/gnychis/Documents/CodeSourcery/Sourcery_G++_Lite/bin/../lib/gcc/arm-none- eabi/4.3.2/../../../../arm-none-eabi/lib/libc.a(lib_a-gettimeofdayr.o): In function `_gettimeofday_r':
gettimeofdayr.c:(.text+0x1c): undefined reference to `_gettimeofday'
/home/gnychis/Documents/CodeSourcery/Sourcery_G++_Lite/bin/../lib/gcc/arm-none-eabi/4.3.2/../../../../arm-none-eabi/lib/libc.a(lib_a-sbrkr.o): In function `_sbrk_r':
sbrkr.c:(.text+0x18): undefined reference to `_sbrk'
collect2: ld returned 1 exit status
make[1]: *** [econotag_coexisyst_firmware_redbee-econotag.elf] Error 1
make: *** [mc1322x-default] Error 2

gettimeofday() を使用できないと仮定していますか? 経過時間を知ることができるようにするための提案はありますか? (例: 100ms)

4

5 に答える 5

6

適切にリンクするには、独自の _gettimeofday() 関数を作成する必要があります。この関数は、適切なコードを使用してプロセッサの時間を取得できますが、フリーランニング システム タイマーが利用可能であると仮定します。

#include <sys/time.h>

int _gettimeofday( struct timeval *tv, void *tzvp )
{
    uint64_t t = __your_system_time_function_here__();  // get uptime in nanoseconds
    tv->tv_sec = t / 1000000000;  // convert to seconds
    tv->tv_usec = ( t % 1000000000 ) / 1000;  // get remaining microseconds
    return 0;  // return non-zero for error
} // end _gettimeofday()
于 2014-07-08T18:43:20.710 に答える
2

私が通常行うことは、タイマーを1khzで実行することです。これにより、ミリ秒ごとに割り込みが生成されます。割り込みハンドラーで、グローバル変数を1つインクリメントし、次のms_ticksようにします。

volatile unsigned int ms_ticks = 0;

void timer_isr() { //every ms
    ms_ticks++;
}

void delay(int ms) {
    ms += ms_ticks;
    while (ms > ms_ticks)
        ;
}

これをタイムスタンプとして使用することも可能であるため、500ミリ秒ごとに何かを実行したいとします。

last_action = ms_ticks;

while (1) {  //app super loop

    if (ms_ticks - last_action >= 500) {
        last_action = ms_ticks;
        //action code here
    }

    //rest of the code
}

別の方法として、ARMは32ビットであり、タイマーはおそらく32ビットであるため、1kHzの割り込みを生成する代わりに、フリーランニングのままにして、カウンターをとして使用することもできますms_ticks

于 2011-08-10T01:01:09.533 に答える
2

チップ内のタイマーの 1 つを使用してください...

于 2011-08-10T03:26:06.777 に答える
-2

私は自分のアプリケーションの 1 つでこれを行ったことがあります。使用するだけです:

while(1)
{
...
}
于 2011-08-10T02:28:22.383 に答える