source: trigger/v560.c@ 9621

Last change on this file since 9621 was 115, checked in by daqct3, 15 years ago
New Functions
File size: 9.3 KB
Line 
1#include <stdio.h>
2//#include "rcc_error/rcc_error.h"
3//#include "vme_rcc/vme_rcc.h"
4#include "v560.h"
5//******************************************************************************
6//Constants
7//******************************************************************************
8
9#define NMAX_V560_MODULES 10 //maximum 65535, probably more than enough...
10#define V560_CHANNELS 16
11
12//******************************************************************************
13//Type definitions
14//******************************************************************************
15
16//This struct maps the memory of a v560 module.
17
18//This struct contains the information necessary to handle one module
19
20
21//******************************************************************************
22//Global Variables
23//******************************************************************************
24
25v560_module_t v560_modules[NMAX_V560_MODULES];
26
27//******************************************************************************
28//Function Definitions
29//******************************************************************************
30
31VME_ErrorCode_t V560_Open()
32{
33 VME_ErrorCode_t error_code;
34 //first open connection to VME:
35 /*if(error_code = VME_Open()) {
36 VME_ErrorPrint(error_code);
37 printf("VME open not successful.\n");
38 return error_code;
39 }*/
40 u_int tmp_virtual_address, tmp_base_address;
41 u_short i=0;
42
43 VME_MasterMap_t master_map;
44
45 master_map.vmebus_address = 0x00010000;
46 master_map.window_size = 0x1000;
47 master_map.address_modifier = VME_A24;
48 master_map.options = 0;
49
50 for(i=0; i<NMAX_V560_MODULES; i++) {
51 v560_modules[i].present = 0;
52 }
53
54 //opening the file containing the base addresses
55 FILE *datfile = fopen("v560_base.dat","r");
56 char line[256];
57
58 i=0;
59 if (datfile!=NULL) {
60 while(fgets(line,255,datfile)) {
61
62 //excluding comment lines
63 if(line[0] == '%') {
64 continue;
65 }
66
67 //reading the hex address
68 if(!sscanf(&line[2],"%8x",&tmp_base_address)) {
69 printf("Reading input file v560_base.dat: non-comment line without address found. Please delete or comment this line.\n");
70 }
71
72 //check address, assign to the master map
73 if(tmp_base_address & 0x0000FFFF) {
74 printf("Reading input file v560_base.dat: 0x%08x is no valid base address (0xXXXX0000)\n",tmp_base_address);
75 continue;
76 }
77 if(i>=NMAX_V560_MODULES) {
78 printf("Reading input file v560_base.dat: More addresses found than memory space provided.\nIncrease NMAX_V560_MODULES in v560.h and v560.c.\n");
79 break;
80 }
81 master_map.vmebus_address = tmp_base_address;
82
83 if(error_code = VME_MasterMap(&master_map,&v560_modules[i].master_mapping)) {
84 VME_ErrorPrint(error_code);
85 return error_code;
86 }
87
88 if(error_code = VME_MasterMapVirtualAddress(v560_modules[i].master_mapping,&tmp_virtual_address)) {
89 VME_ErrorPrint(error_code);
90 return error_code;
91 }
92 printf("%i\n",sizeof(v560_registers_t));
93 v560_modules[i].registers = (v560_registers_t *) tmp_virtual_address;
94 printf("%i\n",sizeof(*(v560_modules[i].registers)));
95 u_short zahl= v560_modules[i].registers->manufacturer_type;
96 //u_short zahl= v560_modules[i].registers[0xFC];
97
98 //printf
99 printf("0x%01X%01X%01X%01X\n", zahl>>12 & 0xF,zahl>>8 & 0xF, zahl>>4 & 0xF,zahl & 0xF);
100 zahl= v560_modules[i].registers-> fixed_code;
101
102 printf("0x%01X%01X%01X%01X\n", zahl>>12 & 0xF,zahl>>8 & 0xF, zahl>>4 & 0xF,zahl & 0xF);
103 zahl= v560_modules[i].registers-> version_series;
104 printf("0x%01X%01X%01X%01X\n", zahl>>12 & 0xF,zahl>>8 & 0xF, zahl>>4 & 0xF,zahl & 0xF);
105
106 //printf("%h",v560_modules[i].registers->manufacturer_type);
107 //if(v560_modules[i].registers->manufacturer_type==0x0818) {
108 if(v560_modules[i].registers->manufacturer_type==0x083A) {
109 //printf("v560-module %i found at address 0x%08x:\n\tMaster mapping: %i\n\tVirtual address: 0x%08x\n\n",i+1,tmp_base_address,v560_modules[i].master_mapping,v560_modules[i].registers);
110 v560_modules[i].present = 1;
111 }
112 else {
113 printf("Module %i at address 0x%08x is not of type v560, or module not found. Please check the v560_base.dat-file.\n\n",i+1,tmp_base_address);
114 v560_modules[i].present = 0;
115 if(error_code = VME_MasterUnmap(v560_modules[i].master_mapping)) {
116 VME_ErrorPrint(error_code);
117 return error_code;
118 }
119 }
120
121 i++;
122 }
123 fclose(datfile);
124 }
125 else { printf("File v560_base.dat containing the base addresses of the v560-modules not found.\n"); error_code = VME_FILE; return error_code; }
126
127 return VME_SUCCESS;
128}
129
130//******************************************************************************
131
132int V560_Send_Scale_Increment(short module)
133{
134 if((module>NMAX_V560_MODULES) || (v560_modules[module-1].present != 1)) { return 1; }
135 //read or write access to base + %56 increases all counters by one:
136 v560_modules[module-1].registers->scale_increase =1;
137 return 0;
138}
139
140//******************************************************************************
141
142int V560_Set_Veto(short module)
143{
144 if((module>NMAX_V560_MODULES) || (v560_modules[module-1].present != 1)) { return 1; }
145 //read or write access to base + %56 increases all counters by one:
146 v560_modules[module-1].registers-> VME_veto_set =1;
147 return 0;
148}
149//******************************************************************************
150
151int V560_Reset_Veto(short module)
152{
153 if((module>NMAX_V560_MODULES) || (v560_modules[module-1].present != 1)) { return 1; }
154 //read or write access to base + %56 increases all counters by one:
155 v560_modules[module-1].registers-> VME_veto_reset =1;
156 return 0;
157}
158
159//******************************************************************************
160int V560_Clear_Scales(short module)
161{
162 if((module>NMAX_V560_MODULES) || (v560_modules[module-1].present != 1)) { return 1; }
163 //read or write access to base + %56 increases all counters by one:
164 v560_modules[module-1].registers-> scale_clear =1;
165 return 0;
166}
167//******************************************************************************
168
169u_short V560_Read_Request_Register(short module){
170 if((module>NMAX_V560_MODULES) || (v560_modules[module-1].present != 1)) { return 1; }
171 //read or write access to base + %56 increases all counters by one:
172 return v560_modules[module-1].registers-> request_register;
173}
174//******************************************************************************
175
176int V560_Write_Request_Register(short module,short request){
177 if((module>NMAX_V560_MODULES) || (v560_modules[module-1].present != 1)) { return 1; }
178 //read or write access to base + %56 increases all counters by one:
179 v560_modules[module-1].registers-> request_register = request;
180 return 0;
181}
182//******************************************************************************
183int V560_Clear_VME_Interrupt(short module)
184{
185 if((module>NMAX_V560_MODULES) || (v560_modules[module-1].present != 1)) { return 1; }
186 //read or write access to base + %56 increases all counters by one:
187 v560_modules[module-1].registers-> clear_VME_interrupt =1;
188 return 0;
189}
190//******************************************************************************
191int V560_Read_Counter(short module, short channel)
192{
193 if((module>NMAX_V560_MODULES) || (v560_modules[module-1].present != 1)) { return 1; }
194 if((channel >V560_CHANNELS ) || (channel<0)) {return 1;}
195
196 int counts = v560_modules[module-1].registers->counter[channel];
197 return counts;
198
199
200}
201
202
203//******************************************************************************
204
205//******************************************************************************
206
207
208
209//******************************************************************************
210
211
212
213//******************************************************************************
214
215//******************************************************************************
216
217int V560_Print_Info(void)
218{
219 //return values
220 //0: print to stdio successful
221
222 u_short manufacturer, type, version, sn, i;
223
224 for(i=0; i<NMAX_V560_MODULES; i++) {
225 if(v560_modules[i].present != 1) {
226 //printf("Module %i is not present.\n",i+1);
227 continue;
228 }
229
230 printf("v560-module %i (master mapping %i) found:\n",i+1,v560_modules[i].master_mapping);
231 manufacturer = v560_modules[i].registers->manufacturer_type; manufacturer &= 0xFC00; // 0b1111 1100 0000 0000
232 type = v560_modules[i].registers->manufacturer_type; type &= 0x03FF; // 0b0000 0011 1111 1111
233 version = v560_modules[i].registers-> version_series; version &= 0xF000; // 0b1111 0000 0000 0000
234 sn = v560_modules[i].registers-> version_series; sn &= 0x0FFF; // 0b0000 1111 1111 1111
235 printf("Manufacturer: 0x%04x\nType: 0x%04x\nVersion: 0x%04x\nSerial Number:0x%04x\n\n", manufacturer, type, version, sn);
236 }
237 return 0;
238}
239
240//******************************************************************************
241
242VME_ErrorCode_t V560_Close(void)
243{
244 VME_ErrorCode_t error_code;
245 u_short i;
246
247 for(i=0; i<NMAX_V560_MODULES; i++) {
248 if(v560_modules[i].present != 1) continue;
249
250 printf("Closing v560-module %i with master mapping %i...",i+1,v560_modules[i].master_mapping);
251 if(error_code = VME_MasterUnmap(v560_modules[i].master_mapping)) {
252 VME_ErrorPrint(error_code);
253 return error_code;
254 }
255 printf("closed.\n");
256 }
257 //and close the VME:
258 /*if(error_code = VME_Close()) {
259 VME_ErrorPrint(error_code);
260 printf("VME close not succesful.\n");
261 return error_code;
262 }*/
263
264 return VME_SUCCESS;
265}
266
267//******************************************************************************
Note: See TracBrowser for help on using the repository browser.