diff options
-rw-r--r-- | trasmitter/README.rst.txt | 9 | ||||
-rw-r--r-- | trasmitter/clock.c | 49 |
2 files changed, 58 insertions, 0 deletions
diff --git a/trasmitter/README.rst.txt b/trasmitter/README.rst.txt index 4b9e310..d2fd957 100644 --- a/trasmitter/README.rst.txt +++ b/trasmitter/README.rst.txt @@ -38,3 +38,12 @@ sysfs interface`_, seem to be fast enough for our purposes. See the ``sender-chip.pl`` test program. +The timing via the sysfs interface is awful. + +It looks like we can drive the pins (not the XIO ones) via +memory-mapped registers: the sunxi-tools ``pio.c`` has most of the +code needed. + +We could write a C program to just send the signal train. Look at +``clock.c`` for a way to handle fast / real-time scheduling and +delays. diff --git a/trasmitter/clock.c b/trasmitter/clock.c new file mode 100644 index 0000000..2d8bd61 --- /dev/null +++ b/trasmitter/clock.c @@ -0,0 +1,49 @@ +#include <stdio.h> +#include <time.h> +#include <sched.h> + +void main(int argc,char **argv) { + struct timespec begin_time,end_time,next_step,end_time2; + struct sched_param sp; + + const int width=520000; + const int pulses=30; + + sp.sched_priority=99; + + // to make this work, sudo setcap CAP_SYS_NICE=eip clock + sched_setscheduler(0,SCHED_RR,&sp); + + clock_gettime(CLOCK_REALTIME,&begin_time); + clock_gettime(CLOCK_REALTIME,&next_step); + for (int i=0;i<pulses;++i) { + // do something slow + clock_gettime(CLOCK_REALTIME,&end_time2); + // end of "slow" + + next_step.tv_nsec += width; + + if (next_step.tv_nsec > 1000000000UL) { + next_step.tv_nsec -= 1000000000UL; + ++next_step.tv_sec; + } + + int rc = clock_nanosleep(CLOCK_REALTIME, + TIMER_ABSTIME, + &next_step, + NULL); + if (rc) { + printf("problems: %d\n",rc); + } + } + clock_gettime(CLOCK_REALTIME,&end_time); + clock_gettime(CLOCK_REALTIME,&end_time2); + + printf("began at %ld.09%ld\n",begin_time.tv_sec,begin_time.tv_nsec); + printf("ended at %ld.09%ld\n",end_time.tv_sec,end_time.tv_nsec); + printf("ended at %ld.09%ld\n",end_time2.tv_sec,end_time2.tv_nsec); + + long elapsed = end_time.tv_nsec - begin_time.tv_nsec; + printf("elapsed: %ld\n",elapsed); + printf("error: %ld\n",elapsed-(pulses*width)); +} |