Skip to content

esp_timer_get_time returning uint64_t but function declares itself as int64_t (IDFGH-15193) #11321

Closed
@NigelGuyLeeming

Description

@NigelGuyLeeming

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

General issue report

esp_timer_get_time is declared
int64_t esp_timer_get_time(void) attribute((alias("esp_timer_impl_get_time")));
which in turn is declared
int64_t ESP_TIMER_IRAM_ATTR esp_timer_impl_get_time(void)
{
return esp_timer_impl_get_counter_reg() / TICKS_PER_US;
}
and calls
uint64_t ESP_TIMER_IRAM_ATTR esp_timer_impl_get_counter_reg(void)

this [return esp_timer_impl_get_counter_reg() / TICKS_PER_US;] will return a uint64_t.

Steps to reproduce in arduino ide

  1. Paste the following code
    int64_t times[15];
    uint64_t timesu[15];
    int count=0;

void setup() {
Serial.begin(115200);
}
void loop() {
times[0]=esp_timer_get_time();
timesu[0]=esp_timer_get_time();
delayMicroseconds(200);
times[1]=esp_timer_get_time();
timesu[1]=esp_timer_get_time();
times[2]=esp_timer_get_time();
timesu[2]=esp_timer_get_time();
Serial.println("int64_t");
Serial.printf("Raw times: %lld %lld %lld\n", times[0], times[1], times[2]);
Serial.printf("Raw timesu: %llu %llu %llu\n", timesu[0], timesu[1], timesu[2]);
Serial.println("uint64_t");
Serial.printf("Diff times: %lld %lld\n", times[1]-times[0], times[2]-times[0]);
Serial.printf("Diff timesu: %llu %llu\n", timesu[1]-timesu[0], timesu[2]-timesu[0]);

delay(2000);

}

  1. Run and observe serial output
    12:58:30.371 -> int64_t
    12:58:30.371 -> Raw times: -5611473693289987786 2098724293209941280 -1945483338840014608
    12:58:30.371 -> Raw timesu: 1226138255 1226138456 1226138457
    12:58:30.371 -> uint64_t
    12:58:30.371 -> Diff times: 7710197986499929066 3665990354449973178
    12:58:30.371 -> Diff timesu: 201 202

The raw and diff times stored as int64_t are meaningless. raw and diff for uint64_t are correct.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions