KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
bps.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.h
10  * Created : 23 feb 2015
11  * Author : Riccardo Travaglini
12  */
13 #ifndef BPS_H_
14 #define BPS_H_
15 
16 /**
17  * @file
18  *
19  * @ingroup uartdrivers
20  *
21  * BPS Uart driver (
22  */
23 
24 #include "stdbool.h"
25 #include "cfg_board.h"
26 #include "errorcode.h"
27 #include "drv/wb/suart.h"
28 
29 
30 
31 #define E_BPS_TIMEOUT E_BPS + 1 ///< Receive timeout
32 #define E_BPS_TIMEOUT_DESCR "BPS Response Timeout"
33 
34 #define E_BPS_CHKERR E_BPS + 2 ///< bad checksum received
35 #define E_BPS_CHKERR_DESCR "BPS Bad checksum"
36 
37 #define E_BPS_NOEOF E_BPS + 3 ///< no EOF received when expected
38 #define E_BPS_NOEOF_DESCR "BPS No EOF received"
39 
40 #define E_BPS_RETADDR E_BPS + 4
41 #define E_BPS_RETADDR_DESCR "BPS Response Bad Addr"
42 
43 #define E_BPS_RETCHK E_BPS + 5
44 #define E_BPS_RETCHK_DESCR "BPS Response Bad Checksum"
45 
46 #define E_BPS_RETSTA E_BPS + 6
47 #define E_BPS_RETSTA_DESCR "BPS Response Bad Start"
48 
49 #define E_BPS_RETTIM E_BPS + 7
50 #define E_BPS_RETTIM_DESCR "BPS Response Tx Was Timeouted"
51 
52 #define E_BPS_RETUNK E_BPS + 8
53 #define E_BPS_RETUNK_DESCR "BPS Response Unknown"
54 
55 #define E_BPS_NOSOF E_BPS + 9 ///< no EOF received when expected
56 #define E_BPS_NOSOF_DESCR "BPS No SOF received"
57 
58 
59 #define BPS_BAUDRATE_DEFAULT SUART_BAUDRATE_19200 //!< Default Baudrate
60 
61 
62 
63 
64 typedef struct {
65  uint16_t mon_i; // backbone current 0 to 1023 ADC raw
66  uint16_t mon1_i12; // Current of 12V line 0 to 1023 ADC raw
67  uint16_t mon2_v375; //Voltage 375VDC from 0 to 1023 ADC raw
68  uint16_t spare;
69  uint16_t mon3_i375; // Current local 375V line from 0 to 1023 ADC raw
70  uint16_t mon4_v375; //Voltage 5VDC from 0 to 1023 ADC raw
71  uint16_t breaker;
72  uint16_t alarm;
74 
75 typedef struct {
76  uint16_t thr_mon_375i0;
77  uint16_t thr_mon_12v;
78 }BspTh;
79 
80 
81 
82 /**
83  * Initializes the BPS
84  *
85  * @param
86  */
87 static inline void bpsInit()
88 {
90 }
91 
92 
93 /**
94  * return sensor values
95  *
96  * @param stat = pointer to Status structure
97  */
98 bool bpsReadSensor(BpsRdSensAnsw* stat);
99 
100 /**
101  * Load already saved alarm enable
102  *
103  * @param alarms = pointer to returned loaded value of alarm enable
104  */
105 bool bpsAlarmEnLoad(uint16_t *alarms);
106 
107 
108 /**
109  * save alarm enable
110  *
111  * @param newal = enable alarm value to be saved
112  alarms = pointer to returned saved value of alarm enable
113  */
114 bool bpsAlarmEnSave(uint16_t newal, uint16_t *alarms);
115 
116 /**
117  * Clear Status Alarm
118  *
119  * @param alarms = pointer to returned alarm status
120  */
121 bool bpsAlarmClearStat(uint16_t *alarms);
122 
123 /**
124  * load already saved alarm threshold (in mA)
125  *
126  * @param th = pointer to returned saved value of alarm threshold
127  */
128 bool bpsAlarmThLoad(BspTh *th);
129 
130 /**
131  * save alarm threshold (in mA)
132  *
133  * @param newal = threshold alarm value to be saved
134  th = pointer to returned saved value of alarm threshold
135  */
136 bool bpsAlarmThSave(BspTh* newth, BspTh *th);
137 
138 
139 /**
140  * Toggle relay status
141  *
142  * @param breakers = pointer to returned breakers value
143  */
144 bool bpsRelayToggleBackBone(uint16_t *breakers);
145 bool bpsRelayToggle12V(uint16_t *breakers);
146 
147 /**
148  * Ping Device
149  *
150  * @param fw = pointer to returned firmware release
151  */
152 bool bpsPingDevice(uint16_t *fw);
153 
154 /**
155  * Exposes the low-level interface to the BPS.
156  *
157  * @note The usage of this function is discouraged.
158  *
159  * @param cmdCode The command code
160  * @param cmdPData Pointer to the command data
161  * @param cmdNData Length of the data
162  * @param rplCode Expected reply code
163  * @param rplPData Pointer-Pointer which will point to the reply data buffer
164  * @param rplNData Expected length of the reply data.
165  *
166  * @retval true Success
167  * @retval false Failure, check error module for error
168  */
169 bool bpsDbgCmdReply(uint8_t cmdCode, uint8_t * cmdPData, uint8_t cmdNData,
170  uint8_t rplCode, uint8_t ** rplPData, uint8_t rplNData);
171 #endif /* BPS_H_ */
Definition: bps.h:75
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
bool bpsRelayToggleBackBone(uint16_t *breakers)
Toggle relay status.
Definition: bps.c:737
bool bpsAlarmClearStat(uint16_t *alarms)
Clear Status Alarm.
Definition: bps.c:654
bool bpsAlarmThLoad(BspTh *th)
load already saved alarm threshold (in mA)
Definition: bps.c:671
White Rabbit Simple UART Driver.
bool bpsPingDevice(uint16_t *fw)
Ping Device.
Definition: bps.c:770
bool bpsAlarmThSave(BspTh *newth, BspTh *th)
save alarm threshold (in mA)
Definition: bps.c:698
void suartInit(SUART_Descriptor *desc, unsigned int baudrate)
Initializes the simple UART.
Definition: suart.c:44
bool bpsReadSensor(BpsRdSensAnsw *stat)
return sensor values
Definition: bps.c:577
This module is responsible for distributing error codes.
#define BPS_BAUDRATE_DEFAULT
Default Baudrate.
Definition: bps.h:59
static void bpsInit()
Initializes the BPS.
Definition: bps.h:87
bool bpsAlarmEnSave(uint16_t newal, uint16_t *alarms)
save alarm enable
Definition: bps.c:630
bool bpsAlarmEnLoad(uint16_t *alarms)
Load already saved alarm enable.
Definition: bps.c:614
Configures the board-specific peripherals, like I2C, SPI etc...