#include #include #include #include #include #include #include #include #include #include #include #include #include #include "period.h" volatile float * data; volatile struct my_msg_struct * msg; static void emergency_stop(int d) { msg->command = STOP_TASK; mbuff_free("data",(void*)data); mbuff_free("msg",(void*)msg); exit(1); } int main(int argc, char *argv[]) { int i, j, count; if((data = (volatile float*) mbuff_alloc("data", BUF_LEN * RECORDING_SAMPLES * sizeof(float))) == NULL){ fprintf(stderr, "mbuff_alloc failed for data\n"); return -1; } if((msg = (volatile struct my_msg_struct*) mbuff_alloc("msg", sizeof(struct my_msg_struct))) == NULL){ fprintf(stderr, "mbuff_alloc failed \n"); return -1; } msg->command = STOP_TASK; signal(SIGINT, emergency_stop); data[BUF_LEN * (RECORDING_SAMPLES - 1)] = -1.; /* Now start the tasks */ fprintf(stderr, "Starting real time task ... "); msg->command = START_TASK; fprintf(stderr, "done.\n"); fprintf(stderr, "Waiting for record ... "); while (data[BUF_LEN * (RECORDING_SAMPLES - 1)] < 0.); /* 正常にデータが書きこまれれば,正になる */ fprintf(stderr, "done.\n"); count = 0; for(i = 0; i < RECORDING_SAMPLES; i++){ for(j = 0; j < BUF_LEN; j++){ fprintf(stdout, "%g ", data[count++]); } fprintf(stdout, "\n"); } mbuff_free("data",(void*)data); mbuff_free("msg", (void*)msg); return 0; }