#ifndef __AQUISITION_C__ #define __AQUISITION_C__ #endif #include #include #include #include #include #include #include #include #include #include #include #include "camac.h" #include "dc_int.h" #include "daq.h" #define CAMAC_FLAG_ZERO 0 #define CAMAC_FLAG_ONE 1 void main(void) { struct io_control *i_cntl; int io_id; int ioc_flag; short int fadc_module, fadc_channel; short int data_taking_flag; /* * Fadc_Station Number of FADC */ #include "station.h" fadc_module = sizeof(fadc_station)/sizeof(short int); /* * Allocate shared memory to control file I/O */ if ((io_id = shmget(DAQKEY, sizeof(struct io_control), 0600)) != -1) { i_cntl = (struct io_control *)shmat(io_id, 0, 0); } else if ((io_id = shmget(DAQKEY, sizeof(struct io_control), IPC_CREAT|0600)) == -1) { syserr("shmget@main(entry)"); exit(2); } else { i_cntl = (struct io_control *)shmat(io_id, 0, 0); } /* * Open device driver */ if ((i_cntl->CC_fd = open(CC_DEVICE, O_RDWR)) < 0) { sprintf(i_cntl->warning_comment, "%s", "Can't open device file"); exit(2); } /* * Initialize shared memory */ daq_initial(i_cntl); /* * Crate Initialize */ daq_camac(i_cntl, CAMAC_FLAG_ZERO); while (1) { /* Infinit loop */ data_taking_flag = 0; /* * Write header (Call back routine when start button was push.) */ if (i_cntl->status) { /* Disk I/O control */ ioc_flag = 0; daq_I_O_cntl(i_cntl, ioc_flag); } /* * Data taking */ while (i_cntl->status && i_cntl->real_events < i_cntl->number_of_events) { data_taking_flag = 1; /* test LAM */ daq_camac(i_cntl, CAMAC_FLAG_ONE); /* Read/Writ CAMAC buffer (FADC) */ if (i_cntl->status) { i_cntl->real_events++; i_cntl->reset_flag = 0; for (fadc_channel = 0; fadc_channel < fadc_module * 2; fadc_channel++) { daq_camac_fadc_read(i_cntl, fadc_channel); /*daq_camac_fadc_ped(i_cntl, fadc_channel);*/ if (i_cntl->word_point > 2000) { ioc_flag = 1; daq_I_O_cntl(i_cntl, ioc_flag); } } /* Read from nomal ADC and TDC */ daq_camac_sadc_read(i_cntl); daq_camac_tdc_read(i_cntl); if (i_cntl->word_point > 2000) { ioc_flag = 1; daq_I_O_cntl(i_cntl, ioc_flag); } } /* end Read/Write CAMAC */ /* over 2000 word_point */ if (i_cntl->word_point > 2000) { ioc_flag = 1; daq_I_O_cntl(i_cntl, ioc_flag); } /* write reset flag */ i_cntl->word[++i_cntl->word_point] = i_cntl->reset_flag; } /* End Data taking */ /* * Run-end procedure */ if (data_taking_flag == 1) { time(&i_cntl->stop_time); if (i_cntl->disk_flag || i_cntl->status) { i_cntl->status = 2; while (i_cntl->status) sleep(1); ioc_flag = 2; daq_I_O_cntl(i_cntl, ioc_flag); /* write end comment */ } } /* end run-end procedure */ } /* end of inf. loop */ }