[Xenomai] task sleep time is getting added when I move my mouse

Ashok kumar ashokkumar.bb at gmail.com
Tue Jul 24 14:52:06 CEST 2018


I mention below a sample code of my project using soem I use the task
function as below.

ret4 = rt_task_create(&Dc_Pll_task, "Dc_time_Pll_task", 0, 99, 0);

void Dc_time_Pll_function()

     struct timespec   ts, tleft;

     static int64 integral = 0;

     int64 sec, nsec,delta, cycletime=1000000;

     clock_gettime(CLOCK_MONOTONIC, &ts);
             previous1 = rt_timer_read();   //read time

             input_ek1818  = (Ek1818_data_inputt *)
pointers to slave I/O pointers inputs//
             output_ek1818 = (Ek1818_data_outputt*) ec_slave[slave_pos_beck_
             in_EL5101     = (in_EL5101t*) ec_slave[slave_pos_beck_
             out_EL5101    = (out_EL5101t*) ec_slave[slave_pos_beck_

             nsec = (cycletime + offsettime) % NSEC_PER_SEC;
             sec  = ((cycletime + offsettime) - nsec) / NSEC_PER_SEC;

             ts.tv_sec += sec;
             ts.tv_nsec += nsec;

             if (ts.tv_nsec >= NSEC_PER_SEC )
               nsec = ts.tv_nsec % NSEC_PER_SEC;
               ts.tv_sec += (ts.tv_nsec - nsec) / NSEC_PER_SEC;
               ts.tv_nsec = nsec;
             clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts,
           // Loop user code here

        if (ec_slave[0].hasdc)
          //ec_Dctime is the system time synchronised with Ethercat
              delta = (ec_DCtime -(cycletime/4)) % cycletime;
                  if(delta > (cycletime / 2))
                       delta= delta - cycletime;


                  offsettime = -(delta / 100) - (integral / 20);


and I am using clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts,
&tleft);     to wait for a time untill the sleep wakes up this routine
works good,

but when I move a mouse the clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME,
&ts, &tleft);  gets some amount of microsecond added then, and my ethercat
slave loss frame but the slave is synchronised with master.

can anybody solve the problem such that when I move my mouse or keyboard
clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts, &tleft);  nanosleep
time should not get jumped or time get added to it so that

I dont loss any ethercat frames.

ret4 = rt_task_create(&Dc_Pll_task, "Dc_time_Pll_task", 0, 99, 0);
and the task priority I set is high.

Thank you

R. Ashokkumar

<https://mailtrack.io/> Sent with Mailtrack

More information about the Xenomai mailing list