-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathIO.h
420 lines (379 loc) · 8.81 KB
/
IO.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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
// SPDX-License-Identifier: GPL-2.0-only
/*
* Digital Voice Modem - Hotspot Firmware
* GPLv2 Open Source. Use is subject to license terms.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright (C) 2015,2016,2020 Jonathan Naylor, G4KLX
* Copyright (C) 2016,2017,2018,2019,2020 Andy Uribe, CA6JAU
* Copyright (C) 2017 Danilo, DB4PLE
* Copyright (C) 2017-2024 Bryan Biedenkapp, N2PLL
*
*/
/**
* @file IO.h
* @ingroup hotspot_fw
* @file IO.cpp
* @ingroup hotspot_fw
* @file IOSTM.cpp
* @ingroup hotspot_fw
* @file ADF7021.cpp
* @ingroup hotspot_fw
*/
#if !defined(__IO_H__)
#define __IO_H__
#include "Defines.h"
#include "Globals.h"
#include "BitBuffer.h"
// ---------------------------------------------------------------------------
// Constants
// ---------------------------------------------------------------------------
#if defined(DUPLEX)
#define CAL_DLY_LOOP 96100U
#else
#define CAL_DLY_LOOP 104600U
#endif
/**
* @brief ADF7021 Gain Modes
*/
enum ADF_GAIN_MODE {
ADF_GAIN_AUTO = 0U, //! AGC automatic, default settings
ADF_GAIN_AUTO_LIN = 1U, //! AGC automatic with high LNA linearity
ADF_GAIN_LOW = 2U, //! AGC OFF, lowest gain
ADF_GAIN_HIGH = 3U //! AGC OFF, highest gain
};
// ---------------------------------------------------------------------------
// Class Declaration
// ---------------------------------------------------------------------------
/**
* @brief Implements the input/output data path with the radio air interface.
* @ingroup hotspot_fw
*/
class DSP_FW_API IO {
public:
/**
* @brief Initializes a new instance of the IO class.
*/
IO();
/**
* @brief Initializes the air interface sampler.
*/
void init();
/**
* @brief Starts air interface sampler.
*/
void start();
/**
* @brief Process bits from air interface.
*/
void process();
/**
* @brief Write bits to air interface.
* @param data Data to write.
* @param length Length of data buffer.
* @param control
*/
void write(uint8_t* data, uint16_t length, const uint8_t* control = NULL);
/**
* @brief Helper to get how much space the transmit ring buffer has for samples.
* @returns uint16_t Amount of space in the transmit ring buffer for samples.
*/
uint16_t getSpace(void) const;
/**
* @brief
* @param dcd
*/
void setDecode(bool dcd);
/**
* @brief Set modem mode.
* @param modemState
*/
void setMode(DVM_STATE modemState);
/**
* @brief Hardware interrupt handler.
*/
void interrupt1();
#if defined(DUPLEX)
/**
* @brief Hardware interrupt handler.
*/
void interrupt2();
#endif
/**
* @brief Sets the ADF7021 RF configuration.
* @param modemState
* @param reset
*/
void rf1Conf(DVM_STATE modemState, bool reset);
#if defined(DUPLEX)
/**
* @brief Sets the ADF7021 RF configuration.
* @param modemState
*/
void rf2Conf(DVM_STATE modemState);
#endif
/**
* @brief Sets the deviation levels.
* @param dmrTXLevel DMR Transmit Level.
* @param p25TXLevel P25 Transmit Level.
* @param nxdnTXLevel NXDN Transmit Level.
*/
void setDeviations(uint8_t dmrTXLevel, uint8_t p25TXLevel, uint8_t nxdnTXLevel);
/**
* @brief Sets the RF parameters.
* @param rxFreq Receive Frequency (hz).
* @param txFreq Transmit Frequency (hz).
* @param rfPower RF Power Level.
* @param gainMode Gain Mode.
* @returns uint8_t Reason code.
*/
uint8_t setRFParams(uint32_t rxFreq, uint32_t txFreq, uint8_t rfPower, ADF_GAIN_MODE gainMode);
/**
* @brief Sets the RF adjustment parameters.
* @param dmrDiscBWAdj DMR Discriminator Bandwidth Adjust.
* @param p25DiscBWAdj P25 Discriminator Bandwidth Adjust.
* @param nxdnDiscBWAdj NXDN Discriminator Bandwidth Adjust.
* @param dmrPostBWAdj DMR Post Bandwidth Adjust.
* @param p25PostBWAdj P25 Post Bandwidth Adjust.
* @param nxdnPostBWAdj NXDN Post Bandwidth Adjust.
*/
void setRFAdjust(int8_t dmrDiscBWAdj, int8_t p25DiscBWAdj, int8_t nxdnDiscBWAdj, int8_t dmrPostBWAdj, int8_t p25PostBWAdj, int8_t nxdnPostBWAdj);
/**
* @brief Sets the RF AFC adjustment parameters.
* @param afcEnable Flag indicating the Automatic Frequency Correction is enabled.
* @param afcKI
* @param afcKP
* @param afcRange
*/
void setAFCParams(bool afcEnable, uint8_t afcKI, uint8_t afcKP, uint8_t afcRange);
/**
* @brief Flag indicating the TX ring buffer has overflowed.
* @returns bool Flag indicating the TX ring buffer has overflowed.
*/
bool hasTXOverflow(void);
/**
* @brief Flag indicating the RX ring buffer has overflowed.
* @returns bool Flag indicating the RX ring buffer has overflowed.
*/
bool hasRXOverflow(void);
/**
* @brief
*/
void resetWatchdog(void);
/**
* @brief
* @returns uint32_t
*/
uint32_t getWatchdog(void);
/**
* @brief Gets the CPU type the firmware is running on.
* @returns uint8_t
*/
uint8_t getCPU() const;
/**
* @brief Gets the unique identifier for the air interface.
* @param buffer
*/
void getUDID(uint8_t* buffer);
/**
* @brief
* @param modemState
*/
void updateCal(DVM_STATE modemState);
/**
* @brief
*/
void delayBit(void);
/**
* @brief
* @returns uint16_t
*/
uint16_t readRSSI(void);
/**
* @brief
*/
void selfTest();
/**
* @brief
*/
void resetMCU();
/**
* @brief
* @param[out] int1
* @param[out] int2
*/
void getIntCounter(uint16_t& int1, uint16_t& int2);
#if defined(ZUMSPOT_ADF7021) || defined(LONESTAR_USB) || defined(SKYBRIDGE_HS)
/**
* @brief
* @returns bool
*/
bool isDualBand();
#endif
/**
* @brief
* @param on
*/
void SCLK(bool on);
/**
* @brief
* @param on
*/
void SDATA(bool on);
/**
* @brief
* @returns bool
*/
bool SREAD();
/**
* @brief
* @param on
*/
void SLE1(bool on);
#if defined(DUPLEX)
/**
* @brief
* @param on
*/
void SLE2(bool on);
/**
* @brief
* @returns bool
*/
bool RXD2();
#endif
/**
* @brief
* @param on
*/
void CE(bool on);
/**
* @brief
* @returns bool
*/
bool RXD1();
/**
* @brief
* @returns bool
*/
bool CLK();
private:
bool m_started;
BitBuffer m_rxBuffer;
BitBuffer m_txBuffer;
uint32_t m_ledCount;
bool m_ledValue;
volatile uint32_t m_watchdog;
volatile uint16_t m_int1Counter;
volatile uint16_t m_int2Counter;
uint32_t m_rxFrequency;
uint32_t m_txFrequency;
uint8_t m_rfPower;
ADF_GAIN_MODE m_gainMode;
/**
* @brief Helper to check the frequencies are within band ranges of the ADF7021.
* @param rxFreq Receive Frequency (hz).
* @param txFreq Transmit Frequency (hz).
*/
void checkBand(uint32_t rxFreq, uint32_t txFreq);
#if defined(ZUMSPOT_ADF7021) || defined(LONESTAR_USB) || defined(SKYBRIDGE_HS)
/**
* @brief
* @param enable
*/
void setBandVHF(bool enable);
/**
* @brief
* @returns bool
*/
bool hasSingleADF7021();
#endif
/**
* @brief
*/
void configureBand();
/**
* @brief
* @param modemState
*/
void configureTxRx(DVM_STATE modemState);
/**
* @brief
*/
void setTX();
/**
* @brief
* @param doSle
*/
void setRX(bool doSle = true);
/**
* @brief
*/
void delayIfCal();
/**
* @brief
*/
void delayReset();
/**
* @brief
* @param us
*/
void delayUS(uint32_t us);
// Hardware specific routines
/**
* @brief Initializes hardware interrupts.
*/
void initInt();
/**
* @brief Starts hardware interrupts.
*/
void startInt();
/**
* @brief
* @param on
*/
void setTXDInt(bool on);
#if defined(BIDIR_DATA_PIN)
/**
* @brief
* @param dir
*/
void setDataDirOut(bool dir);
/**
* @brief
* @param on
*/
void setRXDInt(bool on);
#endif
/**
* @brief
* @param on
*/
void setLEDInt(bool on);
/**
* @brief
* @param on
*/
void setPTTInt(bool on);
/**
* @brief
* @param on
*/
void setCOSInt(bool on);
/**
* @brief
* @param on
*/
void setDMRInt(bool on);
/**
* @brief
* @param on
*/
void setP25Int(bool on);
/**
* @brief
* @param on
*/
void setNXDNInt(bool on);
};
#endif