Пример #1
0
void *sys_time_thread_main(void *data)
{
  int fd;

  /* Create the timer */
  fd = timerfd_create(CLOCK_MONOTONIC, 0);
  if (fd == -1) {
    perror("Could not set up timer.");
    return NULL;
  }

  get_rt_prio(SYS_TIME_THREAD_PRIO);

  /* Make the timer periodic */
  struct itimerspec timer;
  /* timer expires after sys_time.resolution sec */
  timer.it_value.tv_sec = 0;
  timer.it_value.tv_nsec = NSEC_OF_SEC(sys_time.resolution);
  /* and every SYS_TIME_RESOLUTION sec after that */
  timer.it_interval.tv_sec = 0;
  timer.it_interval.tv_nsec = NSEC_OF_SEC(sys_time.resolution);

  if (timerfd_settime(fd, 0, &timer, NULL) == -1) {
    perror("Could not set up timer.");
    return NULL;
  }

  while (1) {
    unsigned long long missed;
    /* Wait for the next timer event. If we have missed any the
     number is written to "missed" */
    int r = read(fd, &missed, sizeof(missed));
    if (r == -1) {
      perror("Couldn't read timer!");
    }
    if (missed > 1) {
      fprintf(stderr, "Missed %lld timer events!\n", missed);
    }
    /* set current sys_time */
    sys_tick_handler();
  }
  return NULL;
}
Пример #2
0
void nps_autopilot_run_systime_step( void ) {
  sys_tick_handler();
}
Пример #3
0
/** needs to be called at SYS_TIME_FREQUENCY */
value sim_sys_time_task(value unit)
{
  sys_tick_handler();
  return unit;
}