Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4906

SDK • Re: troubletrouble defining a macro to replace a zero argument fn call: micros()

$
0
0
Hi,

I'm having trouble with printf when using time_us_64() in a macro definition:

Code:

    #if (USE_SDK)       #define delay(x)  sleep_ms(x)  // done in pico-rp2040 ???       typedef  uint64_ttimestamp_t ;       #define micros() time_us_64()      // uint64_t time_us_64 (void)       ....

Code:

  timestamp_t t=(micros()-loop_start_time);  printf("# end main time = %d us on core%d\n",t, get_core_num());  printf("mean time over %d reads =%5.4f us\n", loop_cnt, (t)/1e0/loop_cnt); 
The second printf gives expected output showing it's all working but for some reason I can not get it to print total time in the first line:

Code:

# end main time = 0 us on core7118mean time over 30 reads =237.2667 us
printf with %d or %u it seems to fail to deal with uint64_t and then messes up the return value of get_core_num() too.

The following works

Code:

   printf("# end main time = %5.0f us on core%d\n",t*1.0, get_core_num()); 
Am I making a dumb mistake? shouldn't %d handle a uint64_t?

TIA.

Statistics: Posted by pie_face — Fri Nov 15, 2024 10:15 am



Viewing all articles
Browse latest Browse all 4906

Trending Articles