KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
bps_v3.h
Go to the documentation of this file.
1 /*
2  * KM3NeT CLB v2 Firmware
3  *
4  * Copyright 2015 KM3NeT Collaboration
5  *
6  * All Rights Reserved.
7  *
8  *
9  * File : bps_v3.h
10  * Created : 23 feb 2015
11  * Author : Riccardo Travaglini
12  * Modified: Jan 2020 by Stefano Mastroianni for BPS_V3
13  */
14 #ifndef BPS_H_
15 #define BPS_H_
16 
17 /**
18  * @file
19  *
20  * @ingroup uartdrivers
21  *
22  * BPS Uart driver (
23  */
24 
25 #include "stdbool.h"
26 #include "cfg_board.h"
27 #include "errorcode.h"
28 #include "drv/wb/suart.h"
29 
30 
31 
32 #define E_BPS_TIMEOUT E_BPS + 1 ///< Receive timeout
33 #define E_BPS_TIMEOUT_DESCR "BPS Response Timeout"
34 
35 #define E_BPS_CHKERR E_BPS + 2 ///< bad checksum received
36 #define E_BPS_CHKERR_DESCR "BPS Bad checksum"
37 
38 #define E_BPS_NOEOF E_BPS + 3 ///< no EOF received when expected
39 #define E_BPS_NOEOF_DESCR "BPS No EOF received"
40 
41 #define E_BPS_RETADDR E_BPS + 4
42 #define E_BPS_RETADDR_DESCR "BPS Response Bad Addr"
43 
44 #define E_BPS_RETCHK E_BPS + 5
45 #define E_BPS_RETCHK_DESCR "BPS Response Bad Checksum"
46 
47 #define E_BPS_RETSTA E_BPS + 6
48 #define E_BPS_RETSTA_DESCR "BPS Response Bad Start"
49 
50 #define E_BPS_RETTIM E_BPS + 7
51 #define E_BPS_RETTIM_DESCR "BPS Response Tx Was Timeouted"
52 
53 #define E_BPS_RETUNK E_BPS + 8
54 #define E_BPS_RETUNK_DESCR "BPS Response Unknown"
55 
56 #define E_BPS_NOSOF E_BPS + 9 ///< no EOF received when expected
57 #define E_BPS_NOSOF_DESCR "BPS No SOF received"
58 
59 
60 #define BPS_BAUDRATE_DEFAULT SUART_BAUDRATE_19200 //!< Default Baudrate
61 
62 
63 typedef struct {
64  uint8_t single_var_num; // Variable_number
65  uint16_t single_value; // Value
66  uint16_t single_offset; // Offset
67  uint16_t single_maxval; // MAXVALUE
68  uint16_t single_meanval; // MEANVALUE
70 
71 typedef struct {
72  uint16_t mon_5V_i; // MON_5V_I_VALUE 0 to 1023 ADC raw
73  uint16_t mon_LBL_i; // MON_LBL_I_VALUE line 0 to 1023 ADC raw
74  uint16_t mon_DU_i; // MON_DU_I_VALUE from 0 to 1023 ADC raw
75  uint16_t mon_DU_irtn; // MON_DU_IRTN_VALUE
76  uint16_t mon_BPS_v; // MON_BPS_V_VALUE 375V line from 0 to 1023 ADC raw
77  uint16_t mon_HYDRO_i; // MON_HYDRO_I_VALUE from 0 to 1023 ADC raw
78  uint16_t mon_MON_THEATSINK; // MON_THEATSINK_VALUE
79  uint16_t mon_TBOARD; // MON_TBOARD_VALUE
80  uint8_t mon_ALRMPOS1; // MON_ALRMPOS1_STATE
81  uint8_t mon_ALRMPOS2; // MON_ALRMPOS2_STATE
82  uint8_t mon_ALRMNEG1; // MON_ALRMNEG1_STATE
83  uint8_t mon_ALRMNEG2; // MON_ALRMNEG2_STATE
85 
86 typedef struct {
87  uint16_t mon_5V_i_M; // MON_5V_I_VALUE 0 to 1023 ADC raw
88  uint16_t mon_LBL_i_M; // MON_LBL_I_VALUE line 0 to 1023 ADC raw
89  uint16_t mon_DU_i_M; // MON_DU_I_VALUE from 0 to 1023 ADC raw
90  uint16_t mon_DU_irtn_M; // MON_DU_IRTN_VALUE
91  uint16_t mon_BPS_v_M; // MON_BPS_V_VALUE 375V line from 0 to 1023 ADC raw
92  uint16_t mon_HYDRO_i_M; // MON_HYDRO_I_VALUE from 0 to 1023 ADC raw
93  uint16_t mon_MON_THEATSINK_M; // MON_THEATSINK_VALUE
94  uint16_t mon_TBOARD_M; // MON_TBOARD_VALUE
96 
97 typedef struct {
98  uint16_t thr_mon_375i0;
99  uint16_t thr_mon_12v;
100 }BspTh;
101 
102 typedef struct {
103  uint8_t thr_alarm_ch;
104  uint16_t thr_alarm_val;
105 }BspThV3;
106 
107 typedef struct {
108  uint8_t sw_control_ch;
109  uint8_t sw_control_val;
110 }SwCtrlV3;
111 
112 typedef struct {
113  uint8_t alarm_ch;
114  uint8_t alarm_val;
115 }BpsAlarmV3;
116 
117 /*
118 typedef struct {
119  uint8_t alarm_en_ch;
120  uint8_t alarm_en_val;
121 }BpsAlarmEnV3;
122 */
123 
124 typedef struct {
125  uint8_t timeout_ch;
126  uint16_t timeout_val;
128 
129 typedef struct {
130  uint16_t ver;
131  uint16_t year;
132  uint8_t month;
133  uint8_t day;
134  uint8_t hour;
135  uint8_t minute;
136  uint8_t second;
138 
139 /**
140  * Initializes the BPS
141  *
142  * @param
143  */
144 static inline void bpsInit()
145 {
146  suartInit(BPS_UART, BPS_BAUDRATE_DEFAULT);
147 }
148 
149 
150 /**
151  * return all sensors' values
152  *
153  * @param stat = pointer to Status structure
154  */
155 bool bpsReadSensorV3(BpsRdSensAnswV3* stat);
156 
157 
158 /**
159  * return all sensors' max values
160  *
161  * @param stat = pointer to Status structure
162  */
164 
165 
166 /**
167  * return one sensor's current value, offset, max, mean value
168  * @param single_var = VARIABLE_NUMBER
169  * @param stat = pointer to Status structure
170  */
171 bool bpsReadSensorSingleV3(uint8_t single_var, BpsRdSingleAnswV3* stat);
172 
173 
174 /**
175  * return all sensors' mean values
176  *
177  * @param stat = pointer to Status structure
178  */
180 
181 
182 /**
183  * Return current enable status
184  *
185  * @param ch = ALARM_NUMBER
186  * @param val = ENABLESTATE_NC, Enable state
187  * @param AlarmEn_rd = pointer to returned loaded value of alarm status
188  */
189 bool bpsAlarmEnV3(uint8_t ch, uint8_t val, BpsAlarmV3* AlarmEn_rd);
190 
191 /**
192  * Return flag of one alarm
193  *
194  * @param ch = ALARM_NUMBER
195  * @param AlarmFiredGet = pointer to returned loaded value of alarm enable
196  */
197 bool bpsAlarmFiredGetV3(uint8_t ch, BpsAlarmV3* AlarmFiredGet);
198 
199 /**
200  * Set the threshold value of one analog alarm
201  *
202  * @param al_th_ch = ALARM_NUMBER_ANALOG
203  * @param al_th_val = Threshold value
204  */
205 //bool bpsAlarmThSaveV3(uint8_t al_th_ch, uint16_t al_th_val); // ok ma non serve
206 
207 /**
208  * Get the threshold value of one analog alarm
209  * @param th_channel= ALARM_NUMBER_ANALOG
210  * @param th = Threshold value
211  */
212 //bool bpsAlarmThLoadV3(uint8_t th_channel, BspThV3 *th); // ok ma non serve
213 
214 // Stefano
215 /**
216  * Set the timeout of one alarm
217  *
218  * @param time_out_ch = ALARM_NUMBER
219  * @param time_out_val = Timeout value
220  */
221 bool bpsAlarmTimeOutSaveV3(uint8_t time_out_ch, uint16_t time_out_val);
222 
223 
224 /**
225  *
226  *
227  * @param th =
228  */
229 bool bpsAlarmTimeOutLoadV3(uint8_t time_out_ch, BpsAlarmTimeOutV3 *rdtout);
230 
231 /**
232  * switch control
233  *
234  * @param ch = Switch number
235  * @param val = Switch state
236  * @param sw_rd = point to Switch control structure
237  */
238 //bool bpsSwitchControlV3(SwCtrlV3* sw_wr, SwCtrlV3* sw_rd);
239 bool bpsSwitchControlV3(uint8_t ch, uint8_t val, SwCtrlV3* sw_rd);
240 
241 /**
242  * Version
243  * @param stat = pointer to the Version
244  */
245 //bool bpsReadVersion(BpsRdVersionV3* stat);
246 
247 /**
248  * Enable or disable auto-rescue (or read enable status)
249  * @param set_val = Enable state
250  * @param rd_val = returned Enable state
251  * set_val : [0] --> DISABLED;[1] --> ENABLED; [2] --> NO_CHANGE
252  * rd_val : [0] --> DISABLED;[1] --> ENABLED;
253  */
254 bool bpsRescueEnable(uint8_t set_val, uint8_t* rd_val);
255 
256 /**
257  * SENSOR_MAXVALUE_RESET
258  * set_val : Variable number
259  */
260 bool bpsSensorMaxvalueReset(uint8_t set_val);
261 
262 /**
263  * Toggle relay status
264  *
265  * @param breakers = pointer to returned breakers value
266  */
267 //bool bpsRelayToggleBackBone(uint16_t *breakers);
268 //bool bpsRelayToggle12V(uint16_t *breakers);
269 
270 /**
271  * Ping Device
272  *
273  * @param fw = pointer to returned firmware release
274  */
275 //bool bpsPingDevice(uint16_t *fw);
276 
277 /**
278  * Exposes the low-level interface to the BPS.
279  *
280  * @note The usage of this function is discouraged.
281  *
282  * @param cmdCode The command code
283  * @param cmdPData Pointer to the command data
284  * @param cmdNData Length of the data
285  * @param rplCode Expected reply code
286  * @param rplPData Pointer-Pointer which will point to the reply data buffer
287  * @param rplNData Expected length of the reply data.
288  *
289  * @retval true Success
290  * @retval false Failure, check error module for error
291  */
292 bool bpsDbgCmdReply(uint8_t cmdCode, uint8_t * cmdPData, uint8_t cmdNData,
293  uint8_t rplCode, uint8_t ** rplPData, uint8_t rplNData);
294 #endif /* BPS_H_ */
bool bpsSwitchControlV3(uint8_t ch, uint8_t val, SwCtrlV3 *sw_rd)
switch control
Definition: bps_v3.c:1014
Definition: bps.h:75
bool bpsReadSensorMaxV3(BpsRdSensAnswV3 *stat)
return all sensors&#39; max values
Definition: bps_v3.c:857
bool bpsRescueEnable(uint8_t set_val, uint8_t *rd_val)
Version.
Definition: bps_v3.c:1106
bool bpsAlarmFiredGetV3(uint8_t ch, BpsAlarmV3 *AlarmFiredGet)
Return flag of one alarm.
Definition: bps_v3.c:1047
bool bpsDbgCmdReply(uint8_t cmdCode, uint8_t *cmdPData, uint8_t cmdNData, uint8_t rplCode, uint8_t **rplPData, uint8_t rplNData)
Exposes the low-level interface to the BPS.
Definition: bps.c:788
White Rabbit Simple UART Driver.
bool bpsSensorMaxvalueReset(uint8_t set_val)
SENSOR_MAXVALUE_RESET set_val : Variable number.
Definition: bps_v3.c:1130
void suartInit(SUART_Descriptor *desc, unsigned int baudrate)
Initializes the simple UART.
Definition: suart.c:44
bool bpsAlarmTimeOutSaveV3(uint8_t time_out_ch, uint16_t time_out_val)
Set the threshold value of one analog alarm.
Definition: bps_v3.c:665
bool bpsAlarmTimeOutLoadV3(uint8_t time_out_ch, BpsAlarmTimeOutV3 *rdtout)
#define BPS_BAUDRATE_DEFAULT
Default Baudrate.
Definition: bps_v3.h:60
bool bpsReadSensorAverageV3(BpsRdSensAverageAnswV3 *stat)
return all sensors&#39; mean values
Definition: bps_v3.c:773
This module is responsible for distributing error codes.
static void bpsInit()
Initializes the BPS.
Definition: bps_v3.h:144
bool bpsReadSensorV3(BpsRdSensAnswV3 *stat)
return all sensors&#39; values
Definition: bps_v3.c:810
bool bpsAlarmEnV3(uint8_t ch, uint8_t val, BpsAlarmV3 *AlarmEn_rd)
Return current enable status.
Definition: bps_v3.c:1074
bool bpsReadSensorSingleV3(uint8_t single_var, BpsRdSingleAnswV3 *stat)
return one sensor&#39;s current value, offset, max, mean value
Definition: bps_v3.c:733
Configures the board-specific peripherals, like I2C, SPI etc...