1kHz timer behavior on Cyclone V

Janet Schneider janetsc at fb.com
Thu Dec 8 20:47:41 UTC 2016


I've pasted my program below.

I don't think I'm having issues printing the output, since I only print once a second.  But I'm seeing the max period between the timer firing go as high as 3000 microseconds.


Thanks,

Janet


*******************


#include <bsp.h>
#include "../../testmacros.h"

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

// Timer statistics
volatile uint64_t g_prevUpTimeUsec;
volatile uint64_t g_totalProcessingPeriodUsec;
volatile uint64_t g_maxProcessingDeltaUsec;
volatile uint64_t g_minProcessingDeltaUsec;
volatile uint32_t g_numTimerIntervals;
static const uint32_t kNumTimerIntervals=1000;

rtems_id main_task;

rtems_timer_service_routine test_timer(
  rtems_id  timer,
  void     *arg
)
{
    // restart the timer
    (void)rtems_timer_reset(timer);

    uint64_t currUpTimeUsec;
    uint64_t processingDeltaUsec;

    currUpTimeUsec = rtems_clock_get_uptime_nanoseconds() / 1000;
    assert (currUpTimeUsec > g_prevUpTimeUsec);
    processingDeltaUsec = currUpTimeUsec - g_prevUpTimeUsec;
    g_totalProcessingPeriodUsec += processingDeltaUsec;
    assert(g_totalProcessingPeriodUsec > 0);
    g_numTimerIntervals++;
    g_prevUpTimeUsec = currUpTimeUsec;
    if (processingDeltaUsec > g_maxProcessingDeltaUsec) {
      g_maxProcessingDeltaUsec = processingDeltaUsec;
    }
    if (processingDeltaUsec < g_minProcessingDeltaUsec) {
      g_minProcessingDeltaUsec = processingDeltaUsec;
    }
    if (g_numTimerIntervals == kNumTimerIntervals) {
      uint64_t avgProcessingPeriodUsec;

      avgProcessingPeriodUsec = (g_totalProcessingPeriodUsec /
                                   g_numTimerIntervals);

      printk("total %d\n",(int)g_totalProcessingPeriodUsec);
      printk("avg %d\n",(int)avgProcessingPeriodUsec);
      printk("min %d\n",(int)g_minProcessingDeltaUsec);
      printk("max %d\n",(int)g_maxProcessingDeltaUsec);

      g_totalProcessingPeriodUsec = 0;
      g_maxProcessingDeltaUsec = 0;
      g_minProcessingDeltaUsec = 0xffffffffffffffff;
      g_numTimerIntervals = 0;
    }
}

rtems_task Init(
  rtems_task_argument argument
)
{
  rtems_status_code     status;
  rtems_id              timer;

  puts( "\n\n*** 1kHz TIMER TEST START ***" );

  main_task = rtems_task_self();

  status = rtems_timer_create( 1, &timer );
  assert( status == RTEMS_SUCCESSFUL );

  // Set up timer
  rtems_interval timer_ticks;
  timer_ticks = (rtems_clock_get_ticks_per_second() / 1000);
  assert (timer_ticks == 2); // 500 usec per "tick"

  // Set timer globals
  g_prevUpTimeUsec = rtems_clock_get_uptime_nanoseconds() / 1000;
  assert (g_prevUpTimeUsec > 0);
  g_totalProcessingPeriodUsec = 0;
  g_maxProcessingDeltaUsec = 0;
  g_minProcessingDeltaUsec = 0xffffffffffffffff;
  g_numTimerIntervals = 0;

  status = rtems_timer_fire_after(timer, timer_ticks, test_timer, NULL);
  assert( status == RTEMS_SUCCESSFUL );

  int i;
  for(i = 0; i < 60; i++) { // Run for 2 min...
    rtems_task_wake_after(timer_ticks * 1000);
  }

  rtems_timer_cancel(timer);
  rtems_task_wake_after(timer_ticks * 1000);

  puts("*** 1kHz TIMER TEST END ***\n\n");
  exit( 0 );
}

/* configuration information */
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER

#define CONFIGURE_MICROSECONDS_PER_TICK 500

#define CONFIGURE_RTEMS_INIT_TASKS_TABLE

#define CONFIGURE_MAXIMUM_TASKS             1
#define CONFIGURE_MAXIMUM_TIMERS            1

#define CONFIGURE_INIT
#include <rtems/confdefs.h>



________________________________
From: Sebastian Huber <sebastian.huber at embedded-brains.de>
Sent: Wednesday, December 7, 2016 10:52:59 PM
To: RTEMS
Cc: Janet Schneider
Subject: Re: 1kHz timer behavior on Cyclone V

Hello Janet,

could you send your test program to the list? How do you report the
timestamps? Via a serial line?

--
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.huber at embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/users/attachments/20161208/bd7d7387/attachment-0002.html>


More information about the users mailing list