This commit is contained in:
2019-01-15 12:10:54 +01:00
parent 29b6af46fe
commit ee70ff070a
5 changed files with 28 additions and 83 deletions

View File

@@ -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++ CC=/opt/eldk-4.2/usr/bin/ppc_4xxFP-g++
LD=$(CC) LD=$(CC)
all: sampleCode all: triggerSync
%.o: %.c %.o: %.c
$(CC) -g $(INC) -c $^ -o $@ $(CC) -g $(INC) -c $^ -o $@
sampleCode: sampleCode.o triggerSync: triggerSync.o
$(LD) -g $(LIB) $^ -o $@ $(LD) -g $(LIB) $^ -o $@
scp $@ root@$(HOST):/tmp scp $@ root@$(HOST):/tmp
scp /opt/eldk-4.2/ppc_4xxFP/usr/bin/gdbserver root@$(HOST):/tmp scp /opt/eldk-4.2/ppc_4xxFP/usr/bin/gdbserver root@$(HOST):/tmp
clean: clean:
rm -f sampleCode sampleCode *.o rm -f triggerSync triggerSync *.o
Debug: all Debug: all
cleanDebug: clean cleanDebug: clean
#export LD_LIBRARY_PATH=/opt/ppmac/libppmac/ #export LD_LIBRARY_PATH=/opt/ppmac/libppmac/
#/tmp/sampleCode #/tmp/triggerSync
#/tmp/gdbserver localhost:2000 /tmp/sampleCode #/tmp/gdbserver localhost:2000 /tmp/triggerSync
# /opt/eldk-4.2/usr/bin/ppc_4xxFP-gdb # /opt/eldk-4.2/usr/bin/ppc_4xxFP-gdb
# file sampleCode # file triggerSync
# b main # b main
# target remote MOTTEST-CPPM-CRM0573:2000 # target remote MOTTEST-CPPM-CRM0573:2000
# continue # continue

View File

@@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="sampleCode.c" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="337" topLine="0" />
</Cursor>
</File>
<File name="Makefile" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="735" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>

View File

@@ -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 <stdio.h> #include <stdio.h>
#include <gplib.h> #include <gplib.h>
#include <math.h> #include <math.h>
#include <stdio.h>
#include <signal.h> #include <signal.h>
#include <unistd.h> #include <unistd.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <native/task.h> #include <native/task.h>
#include <native/timer.h> #include <native/timer.h>
#include <math.h>
extern struct SHM *pshm; 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 CLOCK_RES 1e-9 //Clock resolution is 1 ns by default
#define LOOP_PERIOD 1e7 //Expressed in ticks #define LOOP_PERIOD 1e7 //Expressed in ticks
//RTIME period = 1000000000; //RTIME period = 10000000;
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();
}
RT_TASK trigsync_task; RT_TASK trigsync_task;
void trigsync_func(void *arg) void trigsync_func(void *arg)
@@ -74,7 +28,6 @@ void trigsync_func(void *arg)
curtask = rt_task_self(); curtask = rt_task_self();
rt_task_inquire(curtask, &curtaskinfo); rt_task_inquire(curtask, &curtaskinfo);
int ctr = 0;
//Print the info //Print the info
printf("Starting task %s with period of 10 ms ....\n", curtaskinfo.name); 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 //Make the task periodic with a specified loop period
rt_task_set_periodic(NULL, TM_NOW, LOOP_PERIOD); rt_task_set_periodic(NULL, TM_NOW, LOOP_PERIOD);
int ctr = 0;
unsigned srvStart,srvCnt,diff,maxDiff;
tstart = rt_timer_read(); tstart = rt_timer_read();
pshm = GetSharedMemPtr();
srvStart=srvCnt=pshm->ServoCount;
//Start the task loop //Start the task loop
while(1){ while(ctr<200){
printf("Loop count: %d, Loop time: %.5f ms\n", ctr, (rt_timer_read() - tstart)/1000000.0); printf("sLoop count: %d, Loop time: %.5f ms\n", ctr, (rt_timer_read() - tstart)/1000000.0);
ctr++; ctr++;
rt_task_wait_period(NULL); rt_task_wait_period(NULL);
//int rt_task_sleep_until
} }
/* float ang,pos; /* float ang,pos;
int i; int i;
@@ -114,11 +73,12 @@ void trigsync_run()
printf("Starting cyclic task...\n"); printf("Starting cyclic task...\n");
//Create the real time task //Create the real time task
sprintf(str, "cyclic_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 //Since task starts in suspended mode, start task
rt_task_start(&trigsync_task, &trigsync_func, 0); rt_task_start(&trigsync_task, &trigsync_func, 0);
//Wait for Ctrl-C //Wait for Ctrl-C
pause(); printf("Wait for Ctrl-C\n");
rt_task_join (&trigsync_task);
} }

View File

@@ -2,13 +2,13 @@
<CodeBlocks_project_file> <CodeBlocks_project_file>
<FileVersion major="1" minor="6" /> <FileVersion major="1" minor="6" />
<Project> <Project>
<Option title="c-samples" /> <Option title="triggerSync" />
<Option makefile_is_custom="1" /> <Option makefile_is_custom="1" />
<Option pch_mode="2" /> <Option pch_mode="2" />
<Option compiler="deltatau_gcc" /> <Option compiler="deltatau_gcc" />
<Build> <Build>
<Target title="Debug"> <Target title="Debug">
<Option output="bin/c-samples" prefix_auto="1" extension_auto="1" /> <Option output="bin" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/" /> <Option object_output="obj/" />
<Option type="1" /> <Option type="1" />
<Option compiler="deltatau_gcc" /> <Option compiler="deltatau_gcc" />
@@ -16,7 +16,7 @@
</Build> </Build>
<Unit filename="Makefile" /> <Unit filename="Makefile" />
<Unit filename="Readme.md" /> <Unit filename="Readme.md" />
<Unit filename="sampleCode.c"> <Unit filename="triggerSync.c">
<Option compilerVar="CC" /> <Option compilerVar="CC" />
</Unit> </Unit>
<Extensions> <Extensions>
@@ -32,7 +32,7 @@
<search_path add="/opt/eldk-4.2/PPMAC_rootfs-7-wheezy/opt/ppmac/rtpmac" /> <search_path add="/opt/eldk-4.2/PPMAC_rootfs-7-wheezy/opt/ppmac/rtpmac" />
<search_path add="/opt/eldk-4.2/ppc_4xxFP/usr/include" /> <search_path add="/opt/eldk-4.2/ppc_4xxFP/usr/include" />
<remote_debugging> <remote_debugging>
<options conn_type="0" serial_baud="115200" ip_address="MOTTEST-CPPM-CRM0573" ip_port="2000" additional_cmds_before="file sampleCode" /> <options conn_type="0" serial_baud="115200" ip_address="MOTTEST-CPPM-CRM0573" ip_port="2000" additional_cmds_before="file triggerSync" />
</remote_debugging> </remote_debugging>
</debugger> </debugger>
</Extensions> </Extensions>

View File

@@ -2,12 +2,12 @@
<CodeBlocks_layout_file> <CodeBlocks_layout_file>
<FileVersion major="1" minor="0" /> <FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" /> <ActiveTarget name="Debug" />
<File name="Makefile" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="Makefile" open="1" top="1" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="687" topLine="3" /> <Cursor1 position="853" topLine="12" />
</Cursor> </Cursor>
</File> </File>
<File name="sampleCode.c" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="triggerSync.c" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="835" topLine="9" /> <Cursor1 position="835" topLine="9" />
</Cursor> </Cursor>