lrs2373.c

Go to the documentation of this file.
00001 /*********************************************************************
00002 
00003   Name:         lrs2373.c
00004   Created by:   Stefan Ritt
00005 
00006   Cotents:      Routines for accessing LeCroy 2372 MLU
00007                 
00008   $Id: lrs2373.c 2753 2005-10-07 14:55:31Z ritt $
00009 
00010 *********************************************************************/
00011 
00012 #include <stdio.h>
00013 #include <dos.h>
00014 #include <string.h>
00015 
00016 #include "midas.h"
00017 
00018 #define CAMAC_BASE_DEFINED
00019 #define BYTE_DEFINED
00020 #include "hyt1331.h"
00021 #include "lrs2373.h"
00022 
00023 /*------------------------------------------------------------------*/
00024 
00025 int lrs2373_set(int camac_slot, char *filename)
00026 /**********************************************************************\
00027    Description:
00028 
00029    Loads the memory of a LeCroy 2373 memory lookup unit.  Data to
00030    be loaded is taken from the file <filename>, in the format:
00031              <input1 (HEX)>  <output1 (HEX)>
00032              <input2 (HEX)>  <output2 (HEX)>
00033              <input3 (HEX)>  <output3 (HEX)>
00034              .
00035              .
00036              .
00037    giving the MLU output to be associated with each possible MLU input
00038    (0x0000 to 0xFFFF).  Each output is verified after loading.  The
00039    parameter <camac_slot> gives the number of the CAMAC slot in which the
00040    MLU resides.
00041 
00042    Alternatively, following filenames are reserved. The data
00043    is generated directly and stored in the MLU, which is faster
00044    than reading in a file:
00045 
00046    "1TO1"   Output equals input
00047    "OR1"    Output one is the or of all inputs
00048    "ORALL"  All outputs are the or of all inputs
00049 
00050 \**********************************************************************/
00051 {
00052    int q, x;
00053    WORD i, value, mode;
00054    WORD data;
00055    FILE *fd;
00056 
00057    mode = 0;
00058    if (strcmp(filename, "1TO1") == 0)
00059       mode = 1;
00060    else if (strcmp(filename, "OR_1") == 0)
00061       mode = 2;
00062    else if (strcmp(filename, "OR_ALL") == 0)
00063       mode = 3;
00064 
00065    /* Open input file */
00066    if (mode == 0) {
00067       fd = fopen(filename, "r");
00068       if (fd == NULL) {
00069          printf("lrs2373_set: Cannot find file \"%s\".\n", filename);
00070          return -1;
00071       }
00072    }
00073    printf("Loading %s into MLU in slot %d...\n", filename, camac_slot);
00074 
00075    /* Crate setup is done in InitUserDown */
00076 
00077    /* Set MLU inhibit and 2373 mode */
00078    value = SET_INHIBIT | SET_2373MODE;
00079    CAMO(camac_slot, CCR, WRITE, value);
00080 
00081    /* Verify MLU mode */
00082    data = 0;
00083    CAMI(camac_slot, CCR, READ, &data);
00084    if (data != value) {
00085       printf("lrs2373_set: Error setting inhibit/2373 mode. CCR is %X, should be %X.\n",
00086              data, SET_INHIBIT | SET_2373MODE);
00087       return -1;
00088    }
00089 
00090    /* set CAR to zero and verify */
00091    CAMO(camac_slot, CAR, WRITE, 0);
00092    CAMI(camac_slot, CAR, READ, &value);
00093    if (value != 0) {
00094       printf("lrs2373_set: Error setting CAR register. CAR is %X, should be %X.\n",
00095              value, 0);
00096       return -1;
00097    }
00098 
00099    /* Loop through input permutations, setting and verifying
00100       output for each */
00101 
00102    for (i = 0;; i++) {
00103       if (mode == 0)
00104          fscanf(fd, "%X", &value);
00105       else if (mode == 1)
00106          value = i;
00107       else if (mode == 2)
00108          value = i == 0 ? 0 : 1;
00109       else if (mode == 3)
00110          value = i == 0 ? 0 : 0xFFFF;
00111 
00112       if ((i & 0x0FFF) == 0xFFF)
00113          printf(".");
00114 
00115       /* Write output data */
00116       if (i == 0) {
00117          CAMO_RSTART(camac_slot, DATA, WRITE, value);
00118       } else {
00119          CAMO_REPEAT(value);
00120       }
00121 
00122       if (i == 0xFFFF)
00123          break;
00124    }
00125 
00126    /* Verify data */
00127    if (mode == 0)
00128       rewind(fd);
00129 
00130    CAMO(camac_slot, CAR, WRITE, 0);
00131    for (i = 0;; i++) {
00132       if (mode == 0)
00133          fscanf(fd, "%X", &value);
00134       else if (mode == 1)
00135          value = i;
00136       else if (mode == 2)
00137          value = i == 0 ? 0 : 1;
00138       else if (mode == 3)
00139          value = i == 0 ? 0 : 0xFFFF;
00140 
00141       if ((i & 0x0FFF) == 0xFFF)
00142          printf("=");
00143 
00144       /* Read data and compare */
00145       data = 0;
00146       CAMI(camac_slot, DATA, READ, &data);
00147 
00148       if (data != value) {
00149          printf("Error verifying data: Was %X, should be %X\n", data, value);
00150 //      return -1;
00151       }
00152 
00153       if (i == 0xFFFF)
00154          break;
00155    }
00156 
00157    /* Set Transparent and 2373 mode */
00158    value = SET_TRANSPARENT | SET_2373MODE;
00159    CAMO(camac_slot, CCR, WRITE, value);
00160 
00161    /* Verify MLU mode */
00162    data = 0;
00163    CAMI(camac_slot, CCR, READ, &data);
00164    if (data != value) {
00165       printf("Error setting transparent/2373 mode.  CCR was %X, should be %X.\n",
00166              data, value);
00167       return -1;
00168    }
00169 
00170    if (mode == 0)
00171       fclose(fd);
00172 
00173    printf("\n");
00174 
00175    return (0);
00176 }

Midas DOC Version 3.0.0 ---- PSI Stefan Ritt ----
Contributions: Pierre-Andre Amaudruz - Sergio Ballestrero - Suzannah Daviel - Doxygen - Peter Green - Qing Gu - Greg Hackman - Gertjan Hofman - Paul Knowles - Exaos Lee - Rudi Meier - Glenn Moloney - Dave Morris - John M O'Donnell - Konstantin Olchanski - Renee Poutissou - Tamsen Schurman - Andreas Suter - Jan M.Wouters - Piotr Adam Zolnierczuk