GPT tick problem in IMX6SX

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

GPT tick problem in IMX6SX

338 Views
piljae
Contributor I

hello
I want to make timer using GPT.
Using pthread, we are going to check the event every 50ms and time measurement.
CPU : IMX6XS

OS : QNX

timer_create example code
------------------------------------------------------------------------------------
/*
* * Demonstrate how to set up a timer that, on expiry,
* * sends us a pulse. This example sets the first
* * expiry to 0.05 seconds and the repetition interval
* * to 0.05 seconds.
*/

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <pthread.h>
#include <sys/netmgr.h>
#include <sys/neutrino.h>

#define MY_PULSE_CODE _PULSE_CODE_MINAVAIL

typedef union {
struct _pulse pulse;
/* /* your other message structures would go
here too */
}  my_message_t;

int main()
{
  struct sigevent event;
  struct itimerspec itime;
  timer_t timer_id;
  int chid;
  int rcvid;
  my_message_t msg;
  struct sched_param scheduling_params;
  int prio;

  chid = ChannelCreate(0);

  /* Get our priority. */
  if (SchedGet( 0, 0, &scheduling_params) != -1)
  {
     prio = scheduling_params.sched_priority;
   }
   else
   {
      prio = 10;
   }

   event.sigev_notify = SIGEV_PULSE;
   event.sigev_coid = ConnectAttach(ND_LOCAL_NODE, 0,chid,_NTO_SIDE_CHANNEL, 0);
   event.sigev_priority = prio;
   event.sigev_code = MY_PULSE_CODE;
   timer_create(CLOCK_MONOTONIC, &event, &timer_id);

   itime.it_value.tv_sec = 0;
   /* 50 million nsecs = .05 secs */
   itime.it_value.tv_nsec = 50000000;
   itime.it_interval.tv_sec = 0;
   /* 50 million nsecs = .05 secs */
   itime.it_interval.tv_nsec = 50000000;
   timer_settime(timer_id, 0, &itime, NULL);

   /*
   * * As of the timer_settime(), we will receive our pulse
   * * in 0.05 seconds (the itime.it_value) and every 0.05
   * * seconds thereafter (the itime.it_interval)
   */
   calulateTick(START);
   for (;;) {
      rcvid = MsgReceive(chid, &msg, sizeof(msg), NULL);
      if (rcvid == 0) { /* we got a pulse */
          if (msg.pulse.code == MY_PULSE_CODE) {
               calulateTick(END);
           } /* else other pulses ... */
       } /* else other messages ... */
   }
   return(EXIT_SUCCESS);
}

0x02098024 : GPT_CNT register address
clockValue = 24MHz / 2^3 = 3Mhz

calculateTick(int startEnd)
{
   if(START == startEnd){
      startTime = ReadReg(0x02098024);
    }else if(END == startEnd){
      endTime = ReadReg(0x02098024);
      diffTimeToMs = (endTime - startTime) / (clockValue);
      startTime = endTime;
     }
--------------------------------------------------------------
in action
The difference between DiffTimeToMs is not exactly 50ms.
The difference between the values is about 49947 to 49968us.

However, using the function of clock_getime shows a difference of exactly 50 ms.
I would like to know why the difference between reading directly from the register and clock_getime, which is the qnxos function.

0 Kudos
Reply
0 Replies