00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <stdio.h>
00018 #include <stdlib.h>
00019 #include "midas.h"
00020 #include "mcstd.h"
00021 #include "experim.h"
00022
00023
00024 #ifdef __cplusplus
00025 extern "C" {
00026 #endif
00027
00028
00029
00030
00031 char *frontend_name = "Sample Frontend";
00032
00033 char *frontend_file_name = __FILE__;
00034
00035
00036 BOOL frontend_call_loop = FALSE;
00037
00038
00039 INT display_period = 3000;
00040
00041
00042 INT max_event_size = 10000;
00043
00044
00045 INT max_event_size_frag = 5 * 1024 * 1024;
00046
00047
00048 INT event_buffer_size = 10 * 10000;
00049
00050
00051 #define N_ADC 4
00052 #define N_TDC 4
00053 #define N_SCLR 4
00054
00055
00056 #define CRATE 0
00057 #define SLOT_IO 23
00058 #define SLOT_ADC 1
00059 #define SLOT_TDC 2
00060 #define SLOT_SCLR 3
00061
00062
00063
00064 INT frontend_init();
00065 INT frontend_exit();
00066 INT begin_of_run(INT run_number, char *error);
00067 INT end_of_run(INT run_number, char *error);
00068 INT pause_run(INT run_number, char *error);
00069 INT resume_run(INT run_number, char *error);
00070 INT frontend_loop();
00071
00072 INT read_trigger_event(char *pevent, INT off);
00073 INT read_scaler_event(char *pevent, INT off);
00074
00075 void register_cnaf_callback(int debug);
00076
00077
00078
00079 #undef USE_INT
00080
00081 EQUIPMENT equipment[] = {
00082
00083 {"Trigger",
00084 {1, 0,
00085 "SYSTEM",
00086 #ifdef USE_INT
00087 EQ_INTERRUPT,
00088 #else
00089 EQ_POLLED,
00090 #endif
00091 LAM_SOURCE(0, 0xFFFFFF),
00092 "MIDAS",
00093 TRUE,
00094 RO_RUNNING |
00095 RO_ODB,
00096 500,
00097 0,
00098 0,
00099 0,
00100 "", "", "",},
00101 read_trigger_event,
00102 },
00103
00104 {"Scaler",
00105 {2, 0,
00106 "SYSTEM",
00107 EQ_PERIODIC | EQ_MANUAL_TRIG,
00108 0,
00109 "MIDAS",
00110 TRUE,
00111 RO_RUNNING | RO_TRANSITIONS |
00112 RO_ODB,
00113 10000,
00114 0,
00115 0,
00116 0,
00117 "", "", "",},
00118 read_scaler_event,
00119 },
00120
00121 {""}
00122 };
00123
00124 #ifdef __cplusplus
00125 }
00126 #endif
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155 INT frontend_init()
00156 {
00157
00158
00159 cam_init();
00160 cam_crate_clear(CRATE);
00161 cam_crate_zinit(CRATE);
00162
00163
00164 camc(CRATE, SLOT_IO, 0, 26);
00165
00166
00167 cam_lam_enable(CRATE, SLOT_IO);
00168
00169
00170 camo(CRATE, SLOT_IO, 1, 16, 0xFF);
00171 camo(CRATE, SLOT_IO, 1, 16, 0);
00172
00173
00174 register_cnaf_callback(1);
00175
00176
00177
00178 return SUCCESS;
00179 }
00180
00181
00182
00183 INT frontend_exit()
00184 {
00185 return SUCCESS;
00186 }
00187
00188
00189
00190 INT begin_of_run(INT run_number, char *error)
00191 {
00192
00193
00194 return SUCCESS;
00195 }
00196
00197
00198
00199 INT end_of_run(INT run_number, char *error)
00200 {
00201 return SUCCESS;
00202 }
00203
00204
00205
00206 INT pause_run(INT run_number, char *error)
00207 {
00208 return SUCCESS;
00209 }
00210
00211
00212
00213 INT resume_run(INT run_number, char *error)
00214 {
00215 return SUCCESS;
00216 }
00217
00218
00219
00220 INT frontend_loop()
00221 {
00222
00223
00224 return SUCCESS;
00225 }
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237 INT poll_event(INT source, INT count, BOOL test)
00238
00239
00240
00241 {
00242 int i;
00243 DWORD lam;
00244
00245 for (i = 0; i < count; i++) {
00246 cam_lam_read(LAM_SOURCE_CRATE(source), &lam);
00247
00248 if (lam & LAM_SOURCE_STATION(source))
00249 if (!test)
00250 return lam;
00251 }
00252
00253 return 0;
00254 }
00255
00256
00257
00258 INT interrupt_configure(INT cmd, INT source, POINTER_T adr)
00259 {
00260 switch (cmd) {
00261 case CMD_INTERRUPT_ENABLE:
00262 break;
00263 case CMD_INTERRUPT_DISABLE:
00264 break;
00265 case CMD_INTERRUPT_ATTACH:
00266 break;
00267 case CMD_INTERRUPT_DETACH:
00268 break;
00269 }
00270 return SUCCESS;
00271 }
00272
00273
00274
00275 INT read_trigger_event(char *pevent, INT off)
00276 {
00277 WORD *pdata, a;
00278 INT q, timeout;
00279
00280
00281 bk_init(pevent);
00282
00283
00284 bk_create(pevent, "ADC0", TID_WORD, &pdata);
00285
00286
00287 for (timeout = 100; timeout > 0; timeout--) {
00288 camc_q(CRATE, SLOT_ADC, 0, 8, &q);
00289 if (q)
00290 break;
00291 }
00292 if (timeout == 0)
00293 ss_printf(0, 10, "No ADC gate!");
00294
00295
00296
00297
00298
00299
00300
00301
00302 for (a = 0; a < N_ADC; a++)
00303 *pdata++ = rand() % 1024;
00304
00305
00306 camc(CRATE, SLOT_ADC, 0, 9);
00307
00308 bk_close(pevent, pdata);
00309
00310
00311 bk_create(pevent, "TDC0", TID_WORD, &pdata);
00312
00313
00314
00315
00316
00317
00318
00319
00320 for (a = 0; a < N_TDC; a++)
00321 *pdata++ = rand() % 1024;
00322
00323
00324 camc(CRATE, SLOT_TDC, 0, 9);
00325
00326 bk_close(pevent, pdata);
00327
00328
00329 camc(CRATE, SLOT_IO, 0, 10);
00330
00331
00332 cam_lam_clear(CRATE, SLOT_IO);
00333
00334
00335 camo(CRATE, SLOT_IO, 1, 16, 0xFF);
00336 camo(CRATE, SLOT_IO, 1, 16, 0);
00337
00338
00339
00340
00341 return 1000;
00342 }
00343
00344
00345
00346 INT read_scaler_event(char *pevent, INT off)
00347 {
00348 DWORD *pdata, a;
00349
00350
00351 bk_init(pevent);
00352
00353
00354 bk_create(pevent, "SCLR", TID_DWORD, &pdata);
00355
00356
00357 for (a = 0; a < N_SCLR; a++)
00358 cam24i(CRATE, SLOT_SCLR, a, 0, pdata++);
00359
00360 bk_close(pevent, pdata);
00361
00362 return bk_size(pevent);
00363 }