无法链接到嵌入式系统上的 gettimeofday,经过时间建议?
我正在尝试在嵌入式 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() ?有人对能够判断经过的时间有什么建议吗? (例如,100 毫秒)
I am trying to use gettimeofday on an embedded ARM device, however it seems as though I am unable to use it:
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
I am assuming I cannot use gettimeofday() ? Does anyone have any suggestions for being able to tell elapsed time? (e.g., 100ms)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要做的是创建自己的 _gettimeofday() 函数以使其正确链接。假设您有一个自由运行的系统计时器可用,此函数可以使用适当的代码来获取处理器的时间。
What you need to do is create your own _gettimeofday() function to get it to link properly. This function could use the appropriate code to get the time for your processor, assuming you have a free-running system timer available.
我通常做的是让一个定时器以 1khz 运行,这样它就会每毫秒生成一个中断,在中断处理程序中我将全局变量加一,比如
ms_ticks
然后执行如下操作:也可以使用它作为时间戳,所以假设我想每 500 毫秒执行一些操作:
另一种选择是,由于 ARM 是 32 位,并且您的计时器可能是 32 位,因此不生成一个 1khz 中断,您可以让它自由运行,只需使用计数器作为您的
ms_ticks
。What I usually do, is to have a timer running at 1khz, so it will generate an interrupt every millisecond, in the interrupt handler I increment a global var by one, say
ms_ticks
then do something like:It is also possible to use this as a timestamp, so let's say I want to do something every 500ms:
Another alternative, since ARMs are 32bits and your timer will probably be a 32bits one, is to instead of generating a 1khz interrupt, you leave it free running and simply use the counter as your
ms_ticks
.使用芯片中的定时器之一...
Use one of the timers in the chip...
看起来您正在使用基于 Freescale MC13224v 的 Econotag。
MACA_CLK 寄存器提供了一个非常好的时基(假设无线电正在运行)。您还可以使用带有 CRM->RTC_COUNT 的 RTC。 RTC 可能非常好,也可能不太好,具体取决于您是否有外部 32kHz 晶体(econotag 没有)。
例如,使用 MACA_CLK:
另请参阅 libmc1322x 中的计时器示例:
http://git.devl.org/?p=malvira/libmc1322x.git;a=blob;f=tests/tmr.c
替代方法是在 Contiki 中使用 etimers 或 rtimers (对 Econotag 有良好的支持)。 (参见http://www.sics.se/contiki/wiki/index.php /计时器)
It looks like you are using the Econotag which is based on the MC13224v from Freescale.
The MACA_CLK register provides a very good timebase (assuming the radio is running). You can also use the the RTC with CRM->RTC_COUNT. The RTC may or may not be very good depending on if you have an external 32kHz crystal or not (the econotag does NOT).
e.g. with MACA_CLK:
See also the timer examples in libmc1322x:
http://git.devl.org/?p=malvira/libmc1322x.git;a=blob;f=tests/tmr.c
Alternate methods are to use etimers or rtimers in Contiki (which has good support for the Econotag). (see http://www.sics.se/contiki/wiki/index.php/Timers )