Low-Energy Muon (LEM) Experiment  0.5.2
sis3820.c
Go to the documentation of this file.
1 /********************************************************************\
2 
3  Name: sis3820.c
4  Created by: Thomas Prokscha, PSI
5 
6  Contents: SIS VME multi-scaler 3820 functions
7 
8  $Id$
9 
10 \********************************************************************/
11 
12 /*===========================================================================*/
13 /* Headers */
14 /*===========================================================================*/
15 #include <stdio.h>
16 /*
17 #include <errno.h>
18 #include <string.h>
19 */
20 #include <sys/types.h>
21 
22 /* SIS 3100/1100 VME-PCI specific */
23 #include "dev/pci/sis1100_var.h"
24 #include "sis3100_vme_calls.h"
25 
26 /* SIS 3820 Scaler module specific */
27 #include "sis3820.h"
28 
29 /*----- sis3820_key_reset ------------------------------------------------------*/
39 int sis3820_key_reset(int device, u_int32_t sis3820_base)
40 {
41  int status;
42 
43 #ifdef HAVE_TEST_RUN
44  status = 0;
45 #else
46  status = vme_A32D32_write(device, sis3820_base+SIS3820_KEY_RESET, SIS3820_KEY_RESET);
47 #endif
48  return status;
49 }
50 
51 /*------ sis3820_key_enable -----------------------------------------------------*/
62 int sis3820_key_enable(int device, u_int32_t sis3820_base)
63 {
64  int status;
65 
66 #ifdef HAVE_TEST_RUN
67  status = 0;
68 #else
69  status = vme_A32D32_write(device, sis3820_base+SIS3820_KEY_OPERATION_ENABLE, SIS3820_KEY_OPERATION_ENABLE);
70 #endif
71  return status;
72 }
73 
74 /*------- sis3820_key_disable ----------------------------------------------------*/
84 int sis3820_key_disable(int device, u_int32_t sis3820_base)
85 {
86  int status;
87 
88 #ifdef HAVE_TEST_RUN
89  status = 0;
90 #else
91  status = vme_A32D32_write(device, sis3820_base+SIS3820_KEY_OPERATION_DISABLE, SIS3820_KEY_OPERATION_DISABLE);
92 #endif
93  return status;
94 }
95 
96 /*------------------------------------------------------------------------------*/
97 int sis3820_operation_mode_read(int device, u_int32_t sis3820_base, u_int32_t* mode)
98 {
99  int status;
100 
101 #ifdef HAVE_TEST_RUN
102  status = 0;
103 #else
104  status = vme_A32D32_read(device, sis3820_base+SIS3820_OPERATION_MODE, mode);
105 #endif
106  return status;
107 }
108 
109 /*------- sis3820_operation_mode_write -----------------------------------------*/
164 /*------------------------------------------------------------------------------*/
165 int sis3820_operation_mode_write(int device, u_int32_t sis3820_base, u_int32_t mode)
166 {
167  int status;
168 
169 #ifdef HAVE_TEST_RUN
170  status = 0;
171 #else
172  status = vme_A32D32_write(device, sis3820_base+SIS3820_OPERATION_MODE, mode);
173 #endif
174  return status;
175 }
176 
177 /*------------------------------------------------------------------------------*/
178 int sis3820_modid_read(int device, u_int32_t sis3820_base, u_int32_t* modid)
179 {
180  int status;
181 
182 #ifdef HAVE_TEST_RUN
183  status = 0;
184 #else
185  status = vme_A32D32_read(device, sis3820_base+SIS3820_MODID, modid);
186 #endif
187  return status;
188 }
189 
190 /*------------------------------------------------------------------------------*/
191 int sis3820_control_read(int device, u_int32_t sis3820_base, u_int32_t* control_status)
192 {
193  int status;
194 
195 #ifdef HAVE_TEST_RUN
196  status = 0;
197 #else
198  status = vme_A32D32_read(device, sis3820_base+SIS3820_CONTROL_STATUS, control_status);
199 #endif
200  return status;
201 }
202 
203 /*------- sis3820_control_write -----------------------------------------*/
229 int sis3820_control_write(int device, u_int32_t sis3820_base, u_int32_t control_status)
230 {
231  int status;
232 
233 #ifdef HAVE_TEST_RUN
234  status = 0;
235 #else
236  status = vme_A32D32_write(device, sis3820_base+SIS3820_CONTROL_STATUS, control_status);
237 #endif
238  return status;
239 }
240 
241 /*------- sis3820_copy_disable_channel -------------------------------------------*/
253 int sis3820_copy_disable_channel(int device, u_int32_t sis3820_base, u_int32_t channel_disable)
254 {
255  int status;
256 
257 #ifdef HAVE_TEST_RUN
258  status = 0;
259 #else
260  status = vme_A32D32_write(device, sis3820_base+SIS3820_COPY_DISABLE, channel_disable);
261 #endif
262  return status;
263 }
264 
265 /*-------- sis3820_scaler_read ----------------------------------------------------*/
281 int sis3820_scaler_read(int device, u_int32_t sis3820_base, int mode, int nwords, u_int32_t* data)
282 {
283  int status ;
284  int gotwords;
285 
286 #ifdef HAVE_TEST_RUN
287  status = 0;
288 #else
289  status = -2;
290 
291  switch (mode)
292  {
293  case A32BLT32:
294  status = vme_A32BLT32_read(device, sis3820_base+SIS3820_COUNTER_CH1, data, nwords, &gotwords) ;
295  if ( nwords != gotwords )
296  {
297  printf("sis3820_scaler_read-E- Severe error, words requested %d != gotwords %d \n", nwords, gotwords);
298  status = -1;
299  }
300  break;
301 
302  case A32MBLT64:
303  status = vme_A32MBLT64_read(device, sis3820_base+SIS3820_SDRAM_BASE, data, nwords,&gotwords);
304  if ( nwords != gotwords )
305  {
306  printf("sis3820_scaler_read-E- Severe error, words requested %d != gotwords %d \n", nwords, gotwords);
307  status = -1;
308  }
309  break;
310 
311  case A32_2eVME:
312  status = vme_A32_2EVME_read(device, sis3820_base+SIS3820_SDRAM_BASE, data, nwords, &gotwords) ;
313  if ( nwords != gotwords )
314  {
315  printf("sis3820_scaler_read-E- Severe error, words requested %d != gotwords %d \n", nwords, gotwords);
316  status = -1;
317  }
318  break;
319 
320  default:
321  break;
322  }
323 #endif
324  return status;
325 }
326 
#define A32BLT32
Definition: sis3820.h:206
#define A32_2eVME
Definition: sis3820.h:208
int sis3820_key_disable(int device, u_int32_t sis3820_base)
Definition: sis3820.c:84
#define SIS3820_SDRAM_BASE
Definition: sis3820.h:88
int sis3820_key_enable(int device, u_int32_t sis3820_base)
Definition: sis3820.c:62
INT mode
scaler mode, see scaler_mode()
Definition: vme_fe.cxx:290
#define SIS3820_OPERATION_MODE
Definition: sis3820.h:54
#define SIS3820_CONTROL_STATUS
Definition: sis3820.h:30
#define SIS3820_COPY_DISABLE
Definition: sis3820.h:55
int sis3820_operation_mode_read(int device, u_int32_t sis3820_base, u_int32_t *mode)
Definition: sis3820.c:97
#define SIS3820_KEY_OPERATION_DISABLE
Definition: sis3820.h:77
int sis3820_operation_mode_write(int device, u_int32_t sis3820_base, u_int32_t mode)
Definition: sis3820.c:165
int sis3820_control_read(int device, u_int32_t sis3820_base, u_int32_t *control_status)
Definition: sis3820.c:191
int sis3820_copy_disable_channel(int device, u_int32_t sis3820_base, u_int32_t channel_disable)
Definition: sis3820.c:253
int sis3820_key_reset(int device, u_int32_t sis3820_base)
Definition: sis3820.c:39
#define SIS3820_MODID
Definition: sis3820.h:31
#define SIS3820_KEY_RESET
Definition: sis3820.h:69
int sis3820_scaler_read(int device, u_int32_t sis3820_base, int mode, int nwords, u_int32_t *data)
Definition: sis3820.c:281
int sis3820_modid_read(int device, u_int32_t sis3820_base, u_int32_t *modid)
Definition: sis3820.c:178
#define SIS3820_COUNTER_CH1
Definition: sis3820.h:85
int sis3820_control_write(int device, u_int32_t sis3820_base, u_int32_t control_status)
Definition: sis3820.c:229
#define A32MBLT64
Definition: sis3820.h:207
#define SIS3820_KEY_OPERATION_ENABLE
Definition: sis3820.h:76