pastebin - collaborative debugging tool
eckelmann.kpaste.net RSS


diffUSec rework, try #668
Posted by Anonymous on Mon 21st Oct 2019 15:44
raw | new post
modification of post by Anonymous (view diff)

  1. diff --git a/ptxdist/local_src/ecu01-codesys/io_driver/ecu01softcompcap.cpp b/ptxdist/local_src/ecu01-codesys/io_driver/ecu01softcompcap.cpp
  2. index c5c85b5..33ac9ea 100644
  3. --- a/ptxdist/local_src/ecu01-codesys/io_driver/ecu01softcompcap.cpp
  4. +++ b/ptxdist/local_src/ecu01-codesys/io_driver/ecu01softcompcap.cpp
  5. @@ -32,6 +32,7 @@
  6.  #include <time.h>
  7.  #include <limits.h>
  8.  #include <stdio.h>
  9. +#include <string.h>
  10.  
  11.  /*****************************************************************************/
  12.  /*    here: Defines                                                          */
  13. @@ -47,16 +48,33 @@
  14.  // function: diffUSec
  15.  // ****************************************************************************
  16.  
  17. -static inline int diffUSec(struct timespec t1, struct timespec t2)
  18. +static inline int diffUSec(struct timespec t2, struct timespec t1)
  19.  {
  20. +#define NS_IN_ONE_SEC          (1000000000LL)
  21. +#define SEC_TO_NANOSEC(s) ((s)*NS_IN_ONE_SEC)
  22. +#if 1
  23. +       struct timespec diff;
  24. +       if ((t2.tv_nsec-t1.tv_nsec) < 0) {
  25. +               diff.tv_sec  = t2.tv_sec - t1.tv_sec - 1;
  26. +               diff.tv_nsec = t2.tv_nsec - t1.tv_nsec + 1000000000;
  27. +       } else {
  28. +               diff.tv_sec  = t2.tv_sec - t1.tv_sec;
  29. +               diff.tv_nsec = t2.tv_nsec - t1.tv_nsec;
  30. +       }
  31. +       return (diff.tv_sec * 1000000.0 + (diff.tv_nsec / 1000.0));
  32. +#else
  33.     int diff;
  34.  
  35.     // calculate and return the difference of t1 and t2 in microseconds
  36.  
  37.     diff = USEC_PER_SEC * ((int) t1.tv_sec - (int) t2.tv_sec);
  38. -   diff += ((int) t1.tv_nsec - (int) t2.tv_nsec) / 1000;
  39. +   if (t1.tv_nsec > t2.tv_nsec)
  40. +       diff += ((int) t1.tv_nsec - (int) t2.tv_nsec) / 1000;
  41. +   else
  42. +       diff += (((int) t1.tv_nsec - (int) t2.tv_nsec) / 1000)+USEC_PER_SEC;
  43.  
  44.     return diff;
  45. +#endif
  46.  }
  47.  
  48.  // ****************************************************************************
  49. @@ -245,6 +263,7 @@ Ecu01SoftCompCap::Ecu01SoftCompCap():
  50.  {
  51.     int prio = sched_get_priority_max(SCHED_FIFO);
  52.     struct sched_param param;
  53. +   (void)memset(&param, 0, sizeof(param));
  54.  
  55.     param.sched_priority = prio;

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}





All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at