Gizmo Control Programming Techniques
Gizmo Device Driver and Test Program
The gizmo device driver and test program
are available as a single tar-file, gizmo_code.tar.gz.
Device Driver
- A parallel port device driver module is provided for the gizmo, in file daq.c
- Do not compile the Linux kernel with the standard parallel port driver.
- Do remember to load the kernel module daq.ko
- The effects of the read/write operations with this driver are not at all standard.
- write with count=1
- write with count=2
- sends one byte of output to the analog port
- only the first first byte in data will be used
- will apply the corresponding number of volts
- output of 5 will activate the solenoid, pulling the hacksaw blade
- output of 0 will deactivate the solenoid, releasing the hacksaw blade
- do not output a value higher than 5; it may harm the circuit
- code example to activate the solenoid:
data = 5;
write (gfd, &data, 2);
- code example to deactivate the solenoid:
data = 0;
write (gfd, &data, 2);
- do not use any other value of count
- read
- only works for count=2
- of the 2 bytes read only the first two bits will be needed
- provides the access to the the two sensors on the sides of the hacksaw blade
- as the hacksaw blade makes and breaks contact with springs the values will change
- code example to read the the sensor values:
read (gfd, &data, 2);
Test Program
- source code is in daq_test.c
- has three modes, controlled by command-line options
- no options tests the LEDs
- enter CR to step to the next LED
- -i tests the input sensors
- enter CR to read the values
- enter control-C to terminate
- -5 tests the solenoid
- enter CR to shut it back off again
Coding a Periodic Task
- main.c illustrates system calls needed to build a periodic task
- does not use threads, other than the thread of the main program
- use sched_setscheduler() to set priority to system maximum real-time priority
- build a loop around call to clock_nanosleep() with absolute time to schedule periodic delays
A more complete periodic task program is given
in periodic.c.
pthreads
rel_jitter_test.c
utils.c
Some common functions:
- int pthread_create(pthread_t * thread, pthread_attr_t * attr, void * (*start_routine)(void *), void * arg);
- int pthread_join(pthread_t th, void **thread_return);
- int pthread_attr_init(pthread_attr_t *attr);
- int pthread_attr_setscope(pthread_attr_t *attr, int scope);
- int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy);
- int pthread_attr_setschedparam(pthread_attr_t *attr, const struct sched_param *param);
- int pthread_attr_setinheritsched(pthread_attr_t *attr, int inherit);
- int sched_get_priority_max(int policy);
- int mlockall(int flags);
Libraries needed when linking
Graphs showing effect of real-time priority on release-time jitter
$Id: gizmo_notes.html,v 1.1 2008/08/25 11:18:48 baker Exp baker $ |