Skip to content

gettimeofday() does not work #27

@Hermann-SW

Description

@Hermann-SW

struct timeval seconds are always 0, regardless how much time passed (also for sleep_ms(3333)):

tud_cdc_connected()                                    
0 / 536877456                                          
0 / 3758157056                                         
0 / 536873932

Code:

#include <stdio.h>
#include "pico/stdlib.h"
#include <tusb.h>
#include <sys/time.h>

int main(void)
{
  stdio_init_all();
  while (!tud_cdc_connected()) { sleep_ms(100);  }
  printf("tud_cdc_connected()\n");

  struct timeval tv0,tv1,tv2;
  gettimeofday(&tv0, NULL);
  sleep_ms(1);
  gettimeofday(&tv1, NULL);
  sleep_ms(2);
  gettimeofday(&tv2, NULL);

  printf("%ld / %u\n",tv0.tv_sec,tv0.tv_usec);
  printf("%ld / %u\n",tv1.tv_sec,tv1.tv_usec);
  printf("%ld / %u\n",tv2.tv_sec,tv2.tv_usec);

  return 0;
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions