国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

ARM上怎么用 gettimeofday 函數

2019-11-14 09:17:59
字體:
來源:轉載
供稿:網友
0down votefavorite

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$ makeBuilding for board: redbee-econotag       CC obj_redbee-econotag/econotag_coexisyst_firmware.oLINK (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 statusmake[1]: *** [econotag_coexisyst_firmware_redbee-econotag.elf] Error 1make: *** [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)

c embedded arm gettimeofday
shareimPRove this questionasked Aug 10 '11 at 0:49gnychis1,55354077
 
1 
This error seems to indicate that your standard library installation is badly broken... – R.. Aug 10 '11 at 1:53
add a comment

6 Answers

activeoldestvotes
up vote2down vote

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:

volatile unsigned int ms_ticks = 0;void timer_isr() { //every ms    ms_ticks++;}void delay(int ms) {    ms += ms_ticks;    while (ms > ms_ticks)        ;}

It is also possible to use this as a timestamp, so let's say I want to do something every 500ms:

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}

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.

shareimprove this answeranswered Aug 10 '11 at 1:01Vinicius Kamakura6,1761535
 
 
thanks for your answer! do you have any good documentation on how to set up the timer and interrupt handler? is this easy to do on the system? – gnychis Aug 10 '11 at 1:19
add a comment
up vote2down vote

Use one of the timers in the chip...

shareimprove this answeranswered Aug 10 '11 at 3:26old_timer38.4k548101
 add a comment
up vote1down vote

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.

#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()
shareimprove this answeranswered Jul 8 '14 at 18:43JonS14911
 
 
Any idea what your_system_time_function_here might be? – jjxtra May 19 '16 at 20:17
 
It entirely depends on your hardware and how you access the system timer, if you even have one available. – JonS May 26 '16 at 1:57
add a comment
up vote0down vote

You could use the performance timer as shown in the accepted answer of this question...

How to measure program execution time in ARM Cortex-A8 processor?

shareimprove this answeranswered Aug 10 '11 at 0:59Skyler Saleh3,1911433
 add a comment
up vote0down vote

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:

uint32_t t;t = *MACA_CLK;while (*MACA_CLK - t > SOMETIME);

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 )

shareimprove this answeredited Aug 5 '12 at 15:17Spudley121k29163248answered Aug 5 '12 at 2:32Mariano Alvira20613
 add a comment
up vote-1down vote

I've done this before in one of my applications. Just use :

while(1){...}
0down votefavorite

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$ makeBuilding for board: redbee-econotag       CC obj_redbee-econotag/econotag_coexisyst_firmware.oLINK (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 statusmake[1]: *** [econotag_coexisyst_firmware_redbee-econotag.elf] Error 1make: *** [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)

c embedded arm gettimeofday
shareimprove this questionasked Aug 10 '11 at 0:49gnychis1,55354077
 
1 
This error seems to indicate that your standard library installation is badly broken... – R.. Aug 10 '11 at 1:53
add a comment

6 Answers

activeoldestvotes
up vote2down vote

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:

volatile unsigned int ms_ticks = 0;void timer_isr() { //every ms    ms_ticks++;}void delay(int ms) {    ms += ms_ticks;    while (ms > ms_ticks)        ;}

It is also possible to use this as a timestamp, so let's say I want to do something every 500ms:

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}

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.

shareimprove this answeranswered Aug 10 '11 at 1:01Vinicius Kamakura6,1761535
 
   
thanks for your answer! do you have any good documentation on how to set up the timer and interrupt handler? is this easy to do on the system? – gnychis Aug 10 '11 at 1:19
add a comment
up vote2down vote

Use one of the timers in the chip...

shareimprove this answeranswered Aug 10 '11 at 3:26old_timer38.4k548101
 add a comment
up vote1down vote

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.

#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()
shareimprove this answeranswered Jul 8 '14 at 18:43JonS14911
 
   
Any idea what your_system_time_function_here might be? – jjxtra May 19 '16 at 20:17
   
It entirely depends on your hardware and how you access the system timer, if you even have one available. – JonS May 26 '16 at 1:57
add a comment
up vote0down vote

You could use the performance timer as shown in the accepted answer of this question...

How to measure program execution time in ARM Cortex-A8 processor?

shareimprove this answeranswered Aug 10 '11 at 0:59Skyler Saleh3,1911433
 add a comment
up vote0down vote

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:

uint32_t t;t = *MACA_CLK;while (*MACA_CLK - t > SOMETIME);

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 )

shareimprove this answeredited Aug 5 '12 at 15:17Spudley121k29163248answered Aug 5 '12 at 2:32Mariano Alvira20613
 add a comment
up vote-1down vote

I've done this before in one of my applications. Just use :

while(1){...}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 宿松县| 蒙阴县| 柳林县| 涟源市| 济宁市| 房产| 双流县| 临泽县| 东辽县| 韶关市| 福泉市| 南雄市| 沽源县| 清原| 大新县| 夏津县| 伊吾县| 郸城县| 安平县| 南昌市| 温泉县| 高唐县| 团风县| 泾川县| 昌黎县| 芜湖县| 宿州市| 陆川县| 正宁县| 洛川县| 环江| 诸暨市| 武胜县| 绥江县| 昭通市| 东乡县| 赤峰市| 新津县| 肇州县| 东兰县| 和静县|