This fix a segfault in xenomai_posix example when calling pthread_setschedparam(cyclic_thread, ...) from main thread. As a side effect EL2004 becomes EL2088 - that's what IU have for testing. stable-1.5
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Sat, 29 Sep 2018 23:58:09 +0200
branchstable-1.5
changeset 2714 ec417efca1fd
parent 2713 2e2f57fd2131
child 2715 bdd336fd8132
This fix a segfault in xenomai_posix example when calling pthread_setschedparam(cyclic_thread, ...) from main thread. As a side effect EL2004 becomes EL2088 - that's what IU have for testing.
examples/xenomai_posix/main.c
--- a/examples/xenomai_posix/main.c	Thu Sep 27 17:56:16 2018 +0200
+++ b/examples/xenomai_posix/main.c	Sat Sep 29 23:58:09 2018 +0200
@@ -71,7 +71,7 @@
 #define DigOutSlave01_Pos 0, 1
 
 #define Beckhoff_EK1100 0x00000002, 0x044c2c52
-#define Beckhoff_EL2004 0x00000002, 0x07d43052
+#define Beckhoff_EL2088 0x00000002, 0x08283052
 
 // offsets for PDO entries
 static unsigned int off_dig_out0 = 0;
@@ -79,7 +79,7 @@
 // process data
 
 const static ec_pdo_entry_reg_t domain1_regs[] = {
-   {DigOutSlave01_Pos, Beckhoff_EL2004, 0x7000, 0x01, &off_dig_out0, NULL},
+   {DigOutSlave01_Pos, Beckhoff_EL2088, 0x7000, 0x01, &off_dig_out0, NULL},
    {}
 };
 
@@ -161,8 +161,11 @@
     struct timespec next_period;
     int cycle_counter = 0;
 	unsigned int blink = 0;
-
-    clock_gettime(CLOCK_REALTIME, &next_period);
+    struct sched_param  param = { .sched_priority = 80 };
+
+    pthread_setschedparam(pthread_self(), SCHED_FIFO, &param);
+    
+    clock_gettime(CLOCK_MONOTONIC, &next_period);
 
     while (run) {
         next_period.tv_nsec += cycle_us * 1000;
@@ -171,7 +174,7 @@
 			next_period.tv_sec++;
 		}
 
-        clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &next_period, NULL);
+        clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &next_period, NULL);
 
         cycle_counter++;
 
@@ -242,7 +245,7 @@
     }
 
     sc_dig_out_01 =
-        ecrt_master_slave_config(master, DigOutSlave01_Pos, Beckhoff_EL2004);
+        ecrt_master_slave_config(master, DigOutSlave01_Pos, Beckhoff_EL2088);
     if (!sc_dig_out_01) {
         fprintf(stderr, "Failed to get slave configuration.\n");
         return -1;
@@ -268,15 +271,9 @@
         return -1;
     }
 
-    /* Create cyclic RT-thread */
-    struct sched_param param = { .sched_priority = 82 };
-
     pthread_attr_t thattr;
     pthread_attr_init(&thattr);
     pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE);
-    pthread_attr_setinheritsched(&thattr, PTHREAD_EXPLICIT_SCHED);
-    pthread_attr_setschedpolicy(&thattr, SCHED_FIFO);
-    pthread_setschedparam(cyclic_thread, SCHED_FIFO, &param);
 
     ret = pthread_create(&cyclic_thread, &thattr, &my_thread, NULL);
     if (ret) {