1 | #ifndef HV_H_SEEN
|
---|
2 | #define HV_H_SEEN
|
---|
3 |
|
---|
4 | #include "Types.h"
|
---|
5 | #include "Utilities.h"
|
---|
6 |
|
---|
7 | #include <ftdi.h>
|
---|
8 | #include <sys/ioctl.h>
|
---|
9 |
|
---|
10 |
|
---|
11 | #ifndef NULL
|
---|
12 | #ifdef __cplusplus
|
---|
13 | #define NULL 0
|
---|
14 | #else
|
---|
15 | #define NULL ((void *)0)
|
---|
16 | #endif
|
---|
17 | #endif
|
---|
18 |
|
---|
19 |
|
---|
20 | // Have a look at http://www.linux-usb.org/usb.ids
|
---|
21 | // Vendor: Future Technology Devices International, Ltd (FTDI)
|
---|
22 | #define USB_VENDOR 0X0403
|
---|
23 | // Product: FT232 USB-Serial (UART) IC (USB <-> Serial converter, UM245R)
|
---|
24 | #define USB_PRODUCT 0X6001
|
---|
25 |
|
---|
26 |
|
---|
27 | #define USB_BAUDRATE 115000
|
---|
28 | #define USB_LATENCY_TIMER 1
|
---|
29 |
|
---|
30 |
|
---|
31 | // HV board control registers
|
---|
32 | #define REG_VREF0 0X00
|
---|
33 | #define REG_VREF1 0X08
|
---|
34 | #define REG_VREF2 0X10
|
---|
35 | #define REG_VREF3 0X18
|
---|
36 |
|
---|
37 | #define REG_HV0 0X20
|
---|
38 | #define REG_HV1 0X28
|
---|
39 | #define REG_HV2 0X30
|
---|
40 | #define REG_HV3 0X38
|
---|
41 |
|
---|
42 | #define REG_RESET 0XF8
|
---|
43 | #define REG_STATUS 0X80
|
---|
44 |
|
---|
45 | #define REG_PD1 0X04
|
---|
46 | #define REG_PD2 0X02
|
---|
47 |
|
---|
48 |
|
---|
49 | // HV board status bits
|
---|
50 | #define BIT_OC0 (1<<3)
|
---|
51 | #define BIT_OC1 (1<<4)
|
---|
52 | #define BIT_OC2 (1<<5)
|
---|
53 | #define BIT_OC3 (1<<6)
|
---|
54 |
|
---|
55 | #define BIT_RESET (1<<7)
|
---|
56 |
|
---|
57 |
|
---|
58 | class HVBoard {
|
---|
59 |
|
---|
60 | public:
|
---|
61 |
|
---|
62 | HVBoard(char* serial, int number, struct ftdi_context* ftdic, bool TestMode);
|
---|
63 | ~HVBoard();
|
---|
64 |
|
---|
65 | bool fTestMode;
|
---|
66 |
|
---|
67 | int Init(bool verbose);
|
---|
68 | int Reset(FILE* fptr, unsigned char* rbuf, bool verbose);
|
---|
69 | int GetStatus(FILE* fptr, unsigned char* rbuf, bool verbose);
|
---|
70 | int SetVRef(FILE* fptr, int chain, unsigned int vref, unsigned char* rbuf, bool verbose);
|
---|
71 | int SetHV(FILE* fptr, int chain, unsigned int channel, unsigned int hv, unsigned char* rbuf, bool verbose);
|
---|
72 | struct ftdi_context* GetFTDI_C() {return FTDI_C;}
|
---|
73 | char* GetSerial() {return Serial;}
|
---|
74 | int GetBoardNumber() {return BoardNumber;}
|
---|
75 | int Write(unsigned char* data, int size);
|
---|
76 | int Read(unsigned char* data, int size);
|
---|
77 | int TRead(FILE* fptr, unsigned char* rbuf, bool verbose);
|
---|
78 | void SetTimeOut(float t) {fTimeOut = t;}
|
---|
79 | float GetTimeOut() {return fTimeOut;}
|
---|
80 | void TestIO(); // Warning: NEVER use this function with a real HV board!!!
|
---|
81 | int DecodeWrap(unsigned char* rbuf);
|
---|
82 | void DecodeOC(bool OC[], unsigned char* rbuf);
|
---|
83 | bool DecodeReset(unsigned char* rbuf);
|
---|
84 |
|
---|
85 | struct ftdi_context* FTDI_C;
|
---|
86 | char Serial[STR_LENGTH];
|
---|
87 | int BoardNumber;
|
---|
88 | float fTimeOut; // [s] timeout to return from read
|
---|
89 | int fTestModeWrap;
|
---|
90 |
|
---|
91 | };
|
---|
92 |
|
---|
93 |
|
---|
94 |
|
---|
95 | class HV {
|
---|
96 |
|
---|
97 | public:
|
---|
98 |
|
---|
99 | HV(char** usbdevice, int* usbdevicenumber, FILE* f,bool TestMode);
|
---|
100 | ~HV();
|
---|
101 |
|
---|
102 | int fNumberOfBoards;
|
---|
103 | int fMaxNumberOfBoards;
|
---|
104 |
|
---|
105 | bool fTestMode;
|
---|
106 |
|
---|
107 | HVBoard* fHVBoard[MAX_NUM_HVBOARDS];
|
---|
108 | int GetNumberOfBoards() {return fNumberOfBoards;}
|
---|
109 | void SetNumberOfBoards(int i) {fNumberOfBoards = i;}
|
---|
110 | HVBoard* GetHVBoard(int i) {return fHVBoard[i];}
|
---|
111 |
|
---|
112 | protected:
|
---|
113 |
|
---|
114 | // For FTDI USB <-> serial converter
|
---|
115 | struct ftdi_context ftdic[MAX_NUM_HVBOARDS];
|
---|
116 | struct ftdi_context ftdic_dummy;
|
---|
117 | struct ftdi_device_list *devlist, *curdev;
|
---|
118 |
|
---|
119 | void ArrangeHVBoards(HVBoard** fHVBoard, int size);
|
---|
120 |
|
---|
121 | };
|
---|
122 |
|
---|
123 | #endif
|
---|