KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
promis.h
Go to the documentation of this file.
1 /*
2  * KM3NeT CLB v2 Firmware
3  * ----------------------
4  *
5  * Copyright 2013 KM3NeT Collaboration
6  *
7  * All Rights Reserved.
8  *
9  *
10  * File : promis.h
11  * Created : 21 jan. 2014
12  * Author : Vincent van Beveren
13  */
14 
15 #ifndef PROMIS_H_
16 #define PROMIS_H_
17 
18 #include "drv/wb/i2c.h"
19 #include "util/macro.h"
20 
21 /**
22  * @file
23  *
24  * @ingroup i2cdrivers
25  *
26  * This driver interfaces with the PROMiS PMT ASIC.
27  */
28 
29 #define PRMS_THRS_MIN_MV 800 //!< Minimal output of threshold DAC in milliVolt
30 #define PRMS_THRS_MAX_MV 2400 //!< Maximum output of threshold DAC in milliVolt
31 #define PRMS_HV_MIN_V -700 //!< Minimal value of HV DAC in volt
32 #define PRMS_HV_MAX_V -1500 //!< Maximum value of HV DAC in volt
33 
34 #define E_PRMS_ID_FAULT ( E_PRMS + 1 ) ///< PROMiS ID is not consistent
35 #define E_PRMS_ID_FAULT_DESCR "PROMiS ID inconsistent"
36 
37 /**
38  * Converts a threshold value in milliVolts to the DAC value.
39  *
40  * Note: The threshold needs to be between THRS_MIN_MV and THRS_MAX_MV.
41  *
42  * @param MV The threshold value in milliVolt
43  * @return A byte value corresponding to the MV value entered.
44  */
45 #define PRMS_THRS_MV2DAC(MV) \
46  RESCALE(MV, PRMS_THRS_MIN_MV, PRMS_THRS_MAX_MV, 0, 255)
47 
48 /**
49  * Converts the threshold DAC byte value into milliVolts.
50  *
51  * @param BYTE The threshold DAC byte value
52  * @return The resulting DAC value in millivolts
53  */
54 #define PRMS_THRS_DAC2MV(BYTE) \
55  RESCALE(BYTE, 0, 255, PRMS_THRS_MIN_MV, PRMS_THRS_MAX_MV)
56 
57 /**
58  * Converts the high voltage value into the high voltage DAC byte value
59  *
60  * Note: The high voltage needs to be between HV_MIN_V and HV_MAX_V.
61  *
62  * @param V The high-voltage output value in volts.
63  * @return The resulting DAC byte value
64  */
65 #define PRMS_HV_V2DAC(V) \
66  RESCALE(V, PRMS_HV_MIN_V, PRMS_HV_MAX_V, 0, 255)
67 
68 /**
69  * Converts the high voltage DAC byte value into volts.
70  *
71  * @param BYTE The high-voltage byte value
72  * @return The resulting DAC output in volts
73  */
74 #define PRMS_HV_DAC2V(V) \
75  RESCALE(V, 0, 255, PRMS_HV_MIN_V, PRMS_HV_MAX_V)
76 
77 
78 
79 /**
80  * Configuration struct. Note that these are the raw values.
81  */
82 typedef struct {
83  uint8_t threshold; //!< threshold DAC value
84  uint8_t highVolt; //!< high voltage DAC value
85 } PrmsConfig;
86 
87 /**
88  * Status struct.
89  */
90 typedef struct {
91  bool highVoltOn; //!< High voltage on
92  bool anaBuf; //!< Analog buffer
93 } PrmsStatus;
94 
95 /**
96  * Returns the burned ID of the PROMiS device.
97  *
98  * @param dev The WB I2C device
99  * @param addr The I2C address
100  * @param id Pointer to an array of at least 3 bytes. ID will be written into it on success.
101  *
102  * @retval true Success.
103  * @retval false Failure, use err module to get error.
104  */
105 bool prmsID(I2C_Device * dev, uint8_t addr, uint8_t * id);
106 
107 /**
108  * Sets the configuration on the PROMiS device.
109  *
110  * @param dev The WB I2C device
111  * @param addr The I2C address
112  * @param cfg Pointer to the configuration struct
113  *
114  * @retval true Success.
115  * @retval false Failure, use err module to get error.
116  */
117 bool prmsSetConfig(I2C_Device * dev, uint8_t addr, PrmsConfig * cfg);
118 
119 /**
120  * Gets the configuration from the PROMiS device.
121  *
122  * @param dev The WB I2C device
123  * @param addr The I2C address
124  * @param cfg Poiner to the configuration struct to fill
125  *
126  * @retval true Success.
127  * @retval false Failure, use err module to get error.
128  */
129 bool prmsGetConfig(I2C_Device * dev, uint8_t addr, PrmsConfig * cfg);
130 
131 /**
132  * Enables/Disables the high voltage.
133  *
134  * Note: Be careful when high voltage is on!
135  *
136  * @param dev The WB I2C device
137  * @param addr The I2C address
138  * @param enable Set to true to enable, false to disable.
139  *
140  * @retval true Success.
141  * @retval false Failure, use err module to get error.
142  */
143 bool prmsHighVolt(I2C_Device * dev, uint8_t addr, bool enable);
144 
145 /**
146  * Executes a chain test. Note that DAC values will be modified after this test.
147  *
148  * @param dev The WB I2C device
149  * @param addr The I2C address
150  *
151  * @retval true Success.
152  * @retval false Failure, use err module to get error.
153  */
154 bool prmsChainTest(I2C_Device * dev, uint8_t addr);
155 
156 /**
157  * Returns the status of the PROMiS device.
158  *
159  * @param dev The WB I2C device
160  * @param addr The I2C address
161  * @param status Pointer to the status struct to fill.
162  *
163  * @retval true Success.
164  * @retval false Failure, use err module to get error.
165  */
166 bool prmsStatus(I2C_Device * dev, uint8_t addr, PrmsStatus * status);
167 
168 
169 
170 
171 
172 
173 #endif /* PROMIS_H_ */
Configuration struct.
Definition: promis.h:82
Status struct.
Definition: promis.h:90
bool prmsChainTest(I2C_Device *dev, uint8_t addr)
Executes a chain test.
Definition: promis.c:91
Structure defines OpenCores I2C Device.
Definition: dev_i2c.h:55
bool prmsID(I2C_Device *dev, uint8_t addr, uint8_t *id)
Returns the burned ID of the PROMiS device.
Definition: promis.c:41
bool prmsGetConfig(I2C_Device *dev, uint8_t addr, PrmsConfig *cfg)
Gets the configuration from the PROMiS device.
Definition: promis.c:75
uint8_t threshold
threshold DAC value
Definition: promis.h:83
bool anaBuf
Analog buffer.
Definition: promis.h:92
bool prmsSetConfig(I2C_Device *dev, uint8_t addr, PrmsConfig *cfg)
Sets the configuration on the PROMiS device.
Definition: promis.c:68
uint8_t highVolt
high voltage DAC value
Definition: promis.h:84
bool highVoltOn
High voltage on.
Definition: promis.h:91
bool prmsHighVolt(I2C_Device *dev, uint8_t addr, bool enable)
Enables/Disables the high voltage.
Definition: promis.c:85
Provides common macros.
bool prmsStatus(I2C_Device *dev, uint8_t addr, PrmsStatus *status)
Returns the status of the PROMiS device.
Definition: promis.c:106
OpenCores I2C device driver.