-
Notifications
You must be signed in to change notification settings - Fork 0
/
ES100.h
247 lines (214 loc) · 7.93 KB
/
ES100.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/*!
* @file ES100.h
*
* Everset ES100 WWVB (BPSK) receiver Library V2.1
*/
#ifndef ES100_h
#define ES100_h
/** @brief DST State decode names */
enum dstState_codes{
DSTinactive = 0b00,
DSTend = 0b01,
DSTbegin = 0b10,
DSTactive = 0b11
};
/** @brief Leap Second decode names */
enum leapSecond_codes{
noLeapSecond = 0b00,
positiveLeapSecond = 0b10,
negativeLeapSecond = 0b11
};
/** @brief Control0 register data */
struct ES100Control0
{
bool start; /**< When the START bit is written with a 1, the status, date, and time registers are all cleared,
// bits 4:1 are sampled, and the ES100 begins receiving and processing the input signal.
// Writing 0 to ES100 stops receiving and processing the input signal. This will automatically occur at the end
// of a successful reception. It can be forced to occur by the host processor writing a 0. (default) */
bool ant1off; /**< 1: Antenna 1 input disabled or 0: Antenna 1 input enabled. (default) */
bool ant2off; /**< 1: Antenna 2 input disabled or 0: Antenna 2 input enabled. (default) */
bool startAntenna; /**< 1:Start reception with antenna 2 or 0: Start reception with antenna 1. (default) */
bool trackingEnable; /**< 1: Tracking mode enabled or 0: Tracking mode disabled. (default) */
};
/** @brief IRQ Status register data */
struct ES100IRQstatus
{
bool rxComplete; /**< 1: Reception Complete. Indicates that IRQ- went active due to a successful reception. */
bool cycleComplete; /**< 1: Cycle Complete. Indicates that IRQ- went active due to the unsuccessful completion of a reception attempt. */
};
/** @brief Status0 register data */
struct ES100Status0
{
// Data in the struct is only valid when rxOk = 1.
bool rxOk; /**< 0 (0b0) Indicates that a successful reception has not occured.
1 (0b1) Indicated that a successful reception has occured. */
bool antenna; /**< 0 (0b0) Indicates that the reception occured on Antenna 1.
1 (0b1) Indicates that the reception occured on Antenna 2. */
leapSecond_codes leapSecond; /**< noLeapSecond: 0 (0b00) Indicates that the current month WILL NOT have a leap second.
noLeapSecond: 1 (0b01) Also indicates that the current month WILL NOT have a leap second.
positiveLeapSecond: 2 (0b10) Indicates that the current month WILL have a negative leap second.
negativeLeapSecond: 3 (0b11) Indicates that the current month WILL have a positive leap second. */
dstState_codes dstState; /**< DSTinactive: 0 (0b00) Indicates that Daylight Savings Time (DST) is not in effect.
DSTend: 1 (0b01) Indicates that DST ends today.
DSTbegin: 2 (0b10) Indicates that DST begins totay.
DSTactive: 3 (0b11) Indicates that DST is in effect. */
bool tracking; /**< 0 (0b0) Indicates that the reception attenpt was a 1-minute frame operation.
1 (0b1) Indicates that the reception attemps was a tracking operation. */
};
/** @brief Combined date/time register data */
struct ES100DateTime
{
uint8_t hour;
uint8_t minute;
uint8_t second;
uint8_t day;
uint8_t month;
uint8_t year;
};
/** @brief Next DST register data */
struct ES100NextDst
{
uint8_t month;
uint8_t day;
uint8_t hour;
};
/** @brief Superset of Status0 and DateTime */
struct ES100Data
{
ES100Status0 Status0; /**< struct ES100Status0 */
ES100DateTime DateTimeUTC; /**< struct ES100DateTime */
};
/** @brief ES100 Antenna Selection */
enum es100Antenna : bool {
ANT_1,
ANT_2
};
/*!
@brief Class to interface with ES100 Receiver
*/
class ES100
{
public:
/*!
@brief Setup hardware to interface with ES100 Receiver
@param int_pin Pin number of interrupt request (IRQ) pin
@param en_pin Pin number of enable pin
*/
void begin(uint8_t int_pin, uint8_t en_pin);
/*!
@brief Handshake to enable ES100 Receiver
*/
void enable();
/*!
@brief Brings enable pin low to disable ES100 Receiver
*/
void disable();
/*!
@brief Start a 1-Minute Frame Reception
@param startAntenna ANT_1 or ANT_2
@param singleAntenna True disables the other antenna
@return EXIT_SUCCESS or EXIT_FAILURE
*/
uint8_t startRx(es100Antenna startAntenna = ANT_1, bool singleAntenna = false);
/*!
@brief Start a Tracking Reception
@param startAntenna ANT_1 or ANT_2
@param singleAntenna True disables the other antenna
@return EXIT_SUCCESS or EXIT_FAILURE
*/
uint8_t startRxTracking(es100Antenna startAntenna = ANT_1);
/*!
@brief Write stop bit and end reception
@return EXIT_SUCCESS or EXIT_FAILURE
*/
uint8_t stopRx();
/*!
@brief read Status0 and combined UTC date registers from receiver
@return ES100Data struct
*/
ES100Data getData();
/*!
@brief read Control0 register from receiver
@return ES100Control0 struct
*/
ES100Control0 getControl0();
/*!
@brief read IRQ Status register from receiver
@return ES100IRQstatus struct
*/
ES100IRQstatus getIRQStatus();
/*!
@brief read Status0 register from receiver
@return ES100Status0 struct
*/
ES100Status0 getStatus0();
/*!
@brief read year, month, day, hour, minute, second registers from receiver
convert received data from BCD to decimal
@return ES100DateTime struct
*/
ES100DateTime getUTCdateTime();
/*!
@brief read Next DST egisters from receiver and convert from BCD to decimal
@return ES100NextDst struct
*/
ES100NextDst getNextDst();
/*!
@brief read Device ID register from receiver
@return hexadecimal device ID
*/
uint8_t getDeviceID();
private:
const uint32_t CLOCK_FREQ = 100000; // Hz
const uint32_t DEFAULT_CLOCK = 400000; // Hz
const uint8_t ES100_ADDR = 0x32; // ES100 i2c Address
const uint8_t ES100_CONTROL0_REG = 0x00;
const uint8_t ES100_CONTROL1_REG = 0x01;
const uint8_t ES100_IRQ_STATUS_REG = 0x02;
const uint8_t ES100_STATUS0_REG = 0x03;
const uint8_t ES100_YEAR_REG = 0x04;
const uint8_t ES100_MONTH_REG = 0x05;
const uint8_t ES100_DAY_REG = 0x06;
const uint8_t ES100_HOUR_REG = 0x07;
const uint8_t ES100_MINUTE_REG = 0x08;
const uint8_t ES100_SECOND_REG = 0x09;
const uint8_t ES100_NEXT_DST_MONTH_REG = 0x0A;
const uint8_t ES100_NEXT_DST_DAY_REG = 0x0B;
const uint8_t ES100_NEXT_DST_HOUR_REG = 0x0C;
const uint8_t ES100_DEVICE_ID_REG = 0x0D;
uint8_t _int_pin;
uint8_t _en_pin;
/*!
@brief convert Binary Coded Decimal data to decimal
@param value
@return decimal data
*/
uint8_t bcdToDec(uint8_t value);
/*!
@brief Write data to receiver register
@param addr Register address
@param data Data to write
*/
void _writeRegister(uint8_t addr, uint8_t data);
/*!
@brief Read data to receiver register
@param addr Register address
@return Data from register
*/
uint8_t _readRegister(uint8_t addr);
/*!
@brief Write data over I2C
@param addr Register Address
@param numBytes Number of bytes to write
@param *ptr pointer to data to write
*/
void _I2Cwrite(uint8_t addr, uint8_t numBytes, uint8_t *ptr);
/*!
@brief Read data over I2C
@param addr Register Address
@param numBytes Number of bytes to read
@param *ptr pointer to read data into
*/
void _I2Cread(uint8_t addr, uint8_t numBytes, uint8_t *ptr);
};
#endif