]> git.feebdaed.xyz Git - 0xmirror/SOEM.git/commitdiff
Let coetest/redtest build on other platforms
authorHans-Erik Floryd <hans-erik.floryd@rt-labs.com>
Thu, 26 Jun 2025 11:45:23 +0000 (13:45 +0200)
committerHans-Erik Floryd <hans-erik.floryd@rt-labs.com>
Thu, 10 Jul 2025 08:23:07 +0000 (10:23 +0200)
Use the new osal functions to let tests build on all supported
platforms.

Change-Id: I6519ee55588e7bf0dff8d412679db268abbe86ce

CMakeLists.txt
samples/coetest/coetest.c
samples/red_test/red_test.c

index 43c89eeb2a2c0c2217325366f97a34bc0f9abb91..cf7e3d82f70781d423df7eaecda6856b1ba3e136 100644 (file)
@@ -158,16 +158,16 @@ install(FILES
 )
 
 if(SOEM_BUILD_UTILS)
+  add_subdirectory(samples/coetest)
   add_subdirectory(samples/eepromtool)
   add_subdirectory(samples/firm_update)
+  add_subdirectory(samples/red_test)
   add_subdirectory(samples/simple_ng)
   add_subdirectory(samples/simple_test)
   add_subdirectory(samples/slaveinfo)
 
   if (${CMAKE_SYSTEM_NAME} STREQUAL Linux)
-    add_subdirectory(samples/coetest)
     add_subdirectory(samples/eoe_test)
-    add_subdirectory(samples/red_test)
   endif()
 
   find_package (Python3 QUIET)
index 5189713d4c6e69475a4366b7e044fa1a91967713..8e5d3624a710eef9abd44bf8ed1fd60c2c6a93c4 100644 (file)
@@ -68,21 +68,14 @@ static ecx_contextt ctx = {
     .userdata = NULL,
 };
 
-/* add ns to timespec */
-void add_timespec(struct timespec *ts, int64 addtime)
+/* add ns to ec_timet */
+void add_time_ns(ec_timet *ts, int64 addtime)
 {
-   int64 sec, nsec;
+   ec_timet addts;
 
-   nsec = addtime % NSEC_PER_SEC;
-   sec = (addtime - 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;
-   }
+   addts.tv_nsec = addtime % NSEC_PER_SEC;
+   addts.tv_sec = (addtime - addts.tv_nsec) / NSEC_PER_SEC;
+   osal_timespecadd(ts, &addts, ts);
 }
 
 static float pgain = 0.01f;
@@ -109,7 +102,7 @@ void ec_sync(int64 reftime, int64 cycletime, int64 *offsettime)
 /* RT EtherCAT thread */
 OSAL_THREAD_FUNC_RT ecatthread(void)
 {
-   struct timespec ts, tleft;
+   ec_timet ts;
    int ht, wkc;
    static int64_t toff = 0;
 
@@ -118,16 +111,16 @@ OSAL_THREAD_FUNC_RT ecatthread(void)
    {
       osal_usleep(100);
    }
-   clock_gettime(CLOCK_MONOTONIC, &ts);
+   osal_get_monotonic_time(&ts);
    ht = (ts.tv_nsec / 1000000) + 1; /* round to nearest ms */
    ts.tv_nsec = ht * 1000000;
    ecx_send_processdata(&ctx);
    while (1)
    {
       /* calculate next cycle start */
-      add_timespec(&ts, cycletime + toff);
+      add_time_ns(&ts, cycletime + toff);
       /* wait to cycle start */
-      clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts, &tleft);
+      osal_monotonic_sleep(&ts);
       if (dorun > 0)
       {
          wkc = ecx_receive_processdata(&ctx, EC_TIMEOUTRET);
index d86cf3a6d7df47076b3ff53fa2adde4f59ba9448..b09c9302ab5df919a8c27e524415280d05c755a4 100644 (file)
@@ -197,21 +197,14 @@ void redtest(char *ifname, char *ifname2)
    }
 }
 
-/* add ns to timespec */
-void add_timespec(struct timespec *ts, int64 addtime)
+/* add ns to ec_timet */
+void add_time_ns(ec_timet *ts, int64 addtime)
 {
-   int64 sec, nsec;
+   ec_timet addts;
 
-   nsec = addtime % NSEC_PER_SEC;
-   sec = (addtime - 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;
-   }
+   addts.tv_nsec = addtime % NSEC_PER_SEC;
+   addts.tv_sec = (addtime - addts.tv_nsec) / NSEC_PER_SEC;
+   osal_timespecadd(ts, &addts, ts);
 }
 
 /* PI calculation to get linux time synced to DC time */
@@ -240,11 +233,11 @@ void ec_sync(int64 reftime, int64 cycletime, int64 *offsettime)
 /* RT EtherCAT thread */
 OSAL_THREAD_FUNC_RT ecatthread(void *ptr)
 {
-   struct timespec ts, tleft;
+   ec_timet ts;
    int ht;
    int64 cycletime;
 
-   clock_gettime(CLOCK_MONOTONIC, &ts);
+   osal_get_monotonic_time(&ts);
    ht = (ts.tv_nsec / 1000000) + 1; /* round to nearest ms */
    ts.tv_nsec = ht * 1000000;
    if (ts.tv_nsec >= NSEC_PER_SEC)
@@ -259,9 +252,9 @@ OSAL_THREAD_FUNC_RT ecatthread(void *ptr)
    while (1)
    {
       /* calculate next cycle start */
-      add_timespec(&ts, cycletime + toff);
+      add_time_ns(&ts, cycletime + toff);
       /* wait to cycle start */
-      clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts, &tleft);
+      osal_monotonic_sleep(&ts);
       if (dorun > 0)
       {
          wkc = ecx_receive_processdata(&ctx, EC_TIMEOUTRET);