Rev 264 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
188 | f9daq | 1 | #include <ansi_c.h> |
264 | f9daq | 2 | |
283 | f9daq | 3 | #ifdef WIENVME |
4 | #include "wienvme_dll.h" |
||
5 | #define VME_START(NODE) WIENVME_VME_START((NODE)) |
||
6 | #define VME_STOP() WIENVME_VME_STOP() |
||
7 | #define VME_RESET() WIENVME_VME_RESET() |
||
8 | #define VME_A24D8_R(VME,DATA) WIENVME_VME_A24D8_R((VME),(DATA)) |
||
9 | #define VME_A24D16_R(VME,DATA) WIENVME_VME_A24D16_R((VME),(DATA)) |
||
10 | #define VME_A24D32_R(VME,DATA) WIENVME_VME_A24D32_R((VME),(DATA)) |
||
11 | #define VME_A24D8_W(VME,DATA) WIENVME_VME_A24D8_W((VME),(DATA)) |
||
12 | #define VME_A24D16_W(VME,DATA) WIENVME_VME_A24D16_W((VME),(DATA)) |
||
13 | #define VME_A24D32_W(VME,DATA) WIENVME_VME_A24D32_W((VME),(DATA)) |
||
14 | #define VME_A32D8_R(VME,DATA) WIENVME_VME_A32D8_R((VME),(DATA)) |
||
15 | #define VME_A32D16_R(VME,DATA) WIENVME_VME_A32D16_R((VME),(DATA)) |
||
16 | #define VME_A32D32_R(VME,DATA) WIENVME_VME_A32D32_R((VME),(DATA)) |
||
17 | #define VME_A32D8_W(VME,DATA) WIENVME_VME_A32D8_W((VME),(DATA)) |
||
18 | #define VME_A32D16_W(VME,DATA) WIENVME_VME_A32D16_W((VME),(DATA)) |
||
19 | #define VME_A32D32_W(VME,DATA) WIENVME_VME_A32D32_W((VME),(DATA)) |
||
20 | #else |
||
264 | f9daq | 21 | #include "vme.h" |
283 | f9daq | 22 | #endif |
188 | f9daq | 23 | #include "CAENV965.h" |
24 | #include "CAENV965_DEF.h" |
||
25 | |||
26 | |||
27 | static unsigned long ModuleAddress[10]; |
||
28 | |||
29 | int _VI_FUNC V965_map (int ModuleNumber, unsigned long ModuleOffset, int print) |
||
30 | { |
||
31 | int i; |
||
32 | unsigned short geo, fw, ah, al; |
||
33 | |||
34 | ModuleAddress[ModuleNumber] = ModuleOffset; |
||
35 | VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV965_FW, &fw); |
||
36 | geo = 0; |
||
37 | VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_CRN, &geo); |
||
38 | for (i=0;i<32;i++) |
||
39 | VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_THM + 2*i, &geo); |
||
40 | geo = ModuleNumber; |
||
41 | VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_GEO, &geo); |
||
42 | VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV965_GEO, &geo); |
||
43 | VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV965_ADH, &ah); |
||
44 | VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV965_ADL, &al); |
||
45 | if (print) { |
||
46 | printf("firmware = %d.%d\n", (fw>>8)&0xff, fw&0xff); |
||
47 | printf("geo = %d\n", geo&0x1f ); |
||
48 | printf("addr = 0x%04X0000\n", (ah<<8)|(al&0xff)); |
||
49 | } |
||
50 | return 0; |
||
51 | } |
||
52 | |||
53 | |||
54 | int _VI_FUNC V965_init (int ModuleNumber, unsigned short ped) |
||
55 | { |
||
56 | unsigned short dum16; |
||
57 | |||
58 | dum16= 0x80; |
||
59 | VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_BS1, &dum16); |
||
60 | VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_BC1, &dum16); |
||
61 | dum16= ped; |
||
62 | VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_PED, &dum16); |
||
63 | dum16= 0x5000; |
||
64 | VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_BS2, &dum16); |
||
65 | dum16= 0x4; |
||
66 | VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_BS2, &dum16); |
||
67 | VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_BC2, &dum16); |
||
68 | VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_ECR, &dum16); |
||
69 | |||
70 | printf ( "Module %d initialized!\n", ModuleNumber ) ; |
||
71 | return 0; |
||
72 | } |
||
73 | |||
74 | int _VI_FUNC V965_clear (int ModuleNumber) |
||
75 | { |
||
76 | |||
77 | unsigned short dum16; |
||
78 | |||
79 | dum16= 0x4; |
||
80 | VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_BS2, &dum16); |
||
81 | VME_A24D16_W(ModuleAddress[ModuleNumber] + CAENV965_BC2, &dum16); |
||
82 | |||
83 | return 0; |
||
84 | |||
85 | } |
||
86 | |||
87 | int _VI_FUNC V965_status (int ModuleNumber) |
||
88 | { |
||
89 | unsigned short dum16; |
||
90 | |||
91 | VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV965_SR1, &dum16); |
||
92 | |||
93 | return (int)dum16; |
||
94 | } |
||
95 | |||
96 | int _VI_FUNC V965_status2 (int ModuleNumber) |
||
97 | { |
||
98 | |||
99 | unsigned short dum16; |
||
100 | |||
101 | VME_A24D16_R(ModuleAddress[ModuleNumber] + CAENV965_SR2, &dum16); |
||
102 | |||
103 | return (int)dum16; |
||
104 | } |
||
105 | |||
106 | int _VI_FUNC V965_read (int ModuleNumber, unsigned long whereto[]) |
||
107 | { |
||
108 | int status, ndata, i; |
||
109 | |||
110 | ndata = 0; |
||
111 | |||
112 | do { |
||
113 | VME_A24D32_R(ModuleAddress[ModuleNumber] + CAENV965_OB, &whereto[ndata]); |
||
114 | i=(whereto[ndata]>>25)&0x3; |
||
115 | if (i<3) ndata++; |
||
116 | } while (i<2); |
||
117 | |||
118 | return ndata; |
||
119 | } |