diff --git a/src/triggerSync/Makefile b/src/triggerSync/Makefile
index 8b9e971..a520aa4 100644
--- a/src/triggerSync/Makefile
+++ b/src/triggerSync/Makefile
@@ -12,28 +12,28 @@ LIB=-L/opt/eldk-4.2/PPMAC_rootfs-7-wheezy/opt/ppmac/libppmac -lppmac -L/opt/eldk
CC=/opt/eldk-4.2/usr/bin/ppc_4xxFP-g++
LD=$(CC)
-all: sampleCode
+all: triggerSync
%.o: %.c
$(CC) -g $(INC) -c $^ -o $@
-sampleCode: sampleCode.o
+triggerSync: triggerSync.o
$(LD) -g $(LIB) $^ -o $@
scp $@ root@$(HOST):/tmp
scp /opt/eldk-4.2/ppc_4xxFP/usr/bin/gdbserver root@$(HOST):/tmp
clean:
- rm -f sampleCode sampleCode *.o
+ rm -f triggerSync triggerSync *.o
Debug: all
cleanDebug: clean
#export LD_LIBRARY_PATH=/opt/ppmac/libppmac/
-#/tmp/sampleCode
-#/tmp/gdbserver localhost:2000 /tmp/sampleCode
+#/tmp/triggerSync
+#/tmp/gdbserver localhost:2000 /tmp/triggerSync
# /opt/eldk-4.2/usr/bin/ppc_4xxFP-gdb
-# file sampleCode
+# file triggerSync
# b main
# target remote MOTTEST-CPPM-CRM0573:2000
# continue
diff --git a/src/triggerSync/c-sample.layout b/src/triggerSync/c-sample.layout
deleted file mode 100644
index 7475a03..0000000
--- a/src/triggerSync/c-sample.layout
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/triggerSync/sampleCode.c b/src/triggerSync/triggerSync.c
similarity index 67%
rename from src/triggerSync/sampleCode.c
rename to src/triggerSync/triggerSync.c
index 818bd5c..90c8f05 100644
--- a/src/triggerSync/sampleCode.c
+++ b/src/triggerSync/triggerSync.c
@@ -1,67 +1,21 @@
+// >>>>>>> https://www.ashwinnarayan.com/post/xenomai-realtime-programming-part-2/
+// >>>>>>> https://xenomai.org/documentation/xenomai-2.4/html/api/group__task.html
+
#include
#include
#include
-
-#include
#include
#include
#include
#include
#include
-#include
extern struct SHM *pshm;
-// >>>>>>> https://www.ashwinnarayan.com/post/xenomai-realtime-programming-part-2/
-
#define CLOCK_RES 1e-9 //Clock resolution is 1 ns by default
#define LOOP_PERIOD 1e7 //Expressed in ticks
-//RTIME period = 1000000000;
-RT_TASK loop_task;
-void loop_task_proc(void *arg)
-{
- RT_TASK *curtask;
- RT_TASK_INFO curtaskinfo;
- int iret = 0;
-
- RTIME tstart, now;
-
- curtask = rt_task_self();
- rt_task_inquire(curtask, &curtaskinfo);
- int ctr = 0;
-
- //Print the info
- printf("Starting task %s with period of 10 ms ....\n", curtaskinfo.name);
-
- //Make the task periodic with a specified loop period
- rt_task_set_periodic(NULL, TM_NOW, LOOP_PERIOD);
-
- tstart = rt_timer_read();
-
- //Start the task loop
- while(1){
- printf("Loop count: %d, Loop time: %.5f ms\n", ctr, (rt_timer_read() - tstart)/1000000.0);
- ctr++;
- rt_task_wait_period(NULL);
- }
-}
-
-void loop_task_run()
-{
- char str[20];
- //Lock the memory to avoid memory swapping for this program
- mlockall(MCL_CURRENT | MCL_FUTURE);
- printf("Starting cyclic task...\n");
- //Create the real time task
- sprintf(str, "cyclic_task");
- rt_task_create(&loop_task, str, 0, 50, 0);
- //Since task starts in suspended mode, start task
- rt_task_start(&loop_task, &loop_task_proc, 0);
- //Wait for Ctrl-C
- pause();
-}
-
+//RTIME period = 10000000;
RT_TASK trigsync_task;
void trigsync_func(void *arg)
@@ -74,7 +28,6 @@ void trigsync_func(void *arg)
curtask = rt_task_self();
rt_task_inquire(curtask, &curtaskinfo);
- int ctr = 0;
//Print the info
printf("Starting task %s with period of 10 ms ....\n", curtaskinfo.name);
@@ -82,13 +35,19 @@ void trigsync_func(void *arg)
//Make the task periodic with a specified loop period
rt_task_set_periodic(NULL, TM_NOW, LOOP_PERIOD);
+ int ctr = 0;
+ unsigned srvStart,srvCnt,diff,maxDiff;
+
tstart = rt_timer_read();
+ pshm = GetSharedMemPtr();
+ srvStart=srvCnt=pshm->ServoCount;
//Start the task loop
- while(1){
- printf("Loop count: %d, Loop time: %.5f ms\n", ctr, (rt_timer_read() - tstart)/1000000.0);
+ while(ctr<200){
+ printf("sLoop count: %d, Loop time: %.5f ms\n", ctr, (rt_timer_read() - tstart)/1000000.0);
ctr++;
rt_task_wait_period(NULL);
+ //int rt_task_sleep_until
}
/* float ang,pos;
int i;
@@ -114,11 +73,12 @@ void trigsync_run()
printf("Starting cyclic task...\n");
//Create the real time task
sprintf(str, "cyclic_task");
- rt_task_create(&trigsync_task, str, 0, 50, 0);
+ rt_task_create(&trigsync_task, str, 0, 50, T_JOINABLE);
//Since task starts in suspended mode, start task
rt_task_start(&trigsync_task, &trigsync_func, 0);
//Wait for Ctrl-C
- pause();
+ printf("Wait for Ctrl-C\n");
+ rt_task_join (&trigsync_task);
}
diff --git a/src/triggerSync/c-samples.cbp b/src/triggerSync/triggerSync.cbp
similarity index 85%
rename from src/triggerSync/c-samples.cbp
rename to src/triggerSync/triggerSync.cbp
index adc923a..adb156c 100644
--- a/src/triggerSync/c-samples.cbp
+++ b/src/triggerSync/triggerSync.cbp
@@ -2,13 +2,13 @@
-
+
-
+
@@ -16,7 +16,7 @@
-
+
@@ -32,7 +32,7 @@
-
+
diff --git a/src/triggerSync/c-samples.layout b/src/triggerSync/triggerSync.layout
similarity index 59%
rename from src/triggerSync/c-samples.layout
rename to src/triggerSync/triggerSync.layout
index fe4d7ab..a846b78 100644
--- a/src/triggerSync/c-samples.layout
+++ b/src/triggerSync/triggerSync.layout
@@ -2,12 +2,12 @@
-
+
-
+
-
+