00027 :
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
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
00076
00077
00078 value = SET_INHIBIT | SET_2373MODE;
00079 CAMO(camac_slot, CCR, WRITE, value);
00080
00081
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
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
00100
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
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
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
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
00151 }
00152
00153 if (i == 0xFFFF)
00154 break;
00155 }
00156
00157
00158 value = SET_TRANSPARENT | SET_2373MODE;
00159 CAMO(camac_slot, CCR, WRITE, value);
00160
00161
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 }
}