#include #include #include #include #include #include #include #include #include "adc.h" // to use device driver of D/A board #define SAMPLING_PERIOD 100e-6 // sampling period [sec] pthread_t mytask; void *thread_code(void *arg) { int count = 0; while(1){ int ret; ret = pthread_wait_np(); count++; if(count == 2){ da_conv(1.0, 0); // output 1[V] at CH0 count = 0; }else{ da_conv(0, 0); // output 0[V] at CH0 } } return 0; } int init_module(void) { pthread_attr_t attr; struct sched_param sched_param; int ret; pthread_attr_init (&attr); // Initialization for attributes pthread_attr_setfp_np(&attr, 1); // Set FPU available sched_param.sched_priority = 1; // Set the task priority highest pthread_attr_setschedparam (&attr, &sched_param); ret = pthread_create (&mytask, &attr, thread_code, (void *)0); pthread_make_periodic_np(mytask, gethrtime(), SAMPLING_PERIOD * 1.0e9); init_dac(); return 0; } void cleanup_module(void) { pthread_cancel(mytask); pthread_join(mytask, NULL); cleanup_dac(); }