-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathIO.h
339 lines (292 loc) · 7.41 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
// SPDX-License-Identifier: GPL-2.0-only
/*
* Digital Voice Modem - Modem 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,2017 Jonathan Naylor, G4KLX
* Copyright (C) 2017-2024 Bryan Biedenkapp, N2PLL
*
*/
/**
* @file IO.h
* @ingroup modem_fw
* @file IO.cpp
* @ingroup modem_fw
* @file IODue.cpp
* @ingroup modem_fw
* @file IOSTM.cpp
* @ingroup modem_fw
*/
#if !defined(__IO_H__)
#define __IO_H__
#include "Defines.h"
#include "Globals.h"
#include "SampleBuffer.h"
#include "RSSIBuffer.h"
// ---------------------------------------------------------------------------
// Class Declaration
// ---------------------------------------------------------------------------
/**
* @brief Implements the input/output data path with the radio air interface.
* @ingroup modem_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 samples from air interface.
*/
void process();
/**
* @brief Write samples to air interface.
* @param mode
* @param samples Samples to write.
* @param length Length of samples buffer.
* @param control
*/
void write(DVM_STATE mode, q15_t* samples, 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() const;
/**
* @brief
* @param dcd
*/
void setDecode(bool dcd);
/**
* @brief
* @param detect
*/
void setADCDetection(bool detect);
/**
* @brief Helper to set the modem air interface state.
*/
void setMode();
/**
* @brief Helper to assert or deassert radio PTT.
*/
void setTransmit();
/**
* @brief Hardware interrupt handler.
*/
void interrupt();
/**
* @brief Sets various air interface parameters.
* @param rxInvert Flag indicating the Rx polarity should be inverted.
* @param txInvert Flag indicating the Tx polarity should be inverted.
* @param pttInvert Flag indicating the PTT polarity should be inverted.
* @param rxLevel Rx Level.
* @param cwIdTXLevel CWID Transmit Level.
* @param dmrTXLevel DMR Transmit Level.
* @param p25TXLevel P25 Transmit Level.
* @param nxdnTXLevel NXDN Transmit Level.
* @param txDCOffset Tx DC offset parameter.
* @param rxDCOffset Rx DC offset parameter.
*/
void setParameters(bool rxInvert, bool txInvert, bool pttInvert, uint8_t rxLevel, uint8_t cwIdTXLevel, uint8_t dmrTXLevel,
uint8_t p25TXLevel, uint8_t nxdnTXLevel, uint16_t txDCOffset, uint16_t rxDCOffset);
/**
* @brief Sets the software Rx sample level.
* @param rxLevel Rx Level.
*/
void setRXLevel(uint8_t rxLevel);
/**
* @brief Helper to get the state of the ADC and DAC overflow flags.
* @param[out] adcOverflow
* @param[out] dacOverflow
*/
void getOverflow(bool& adcOverflow, bool& dacOverflow);
/**
* @brief Flag indicating the TX ring buffer has overflowed.
* @returns bool Flag indicating the TX ring buffer has overflowed.
*/
bool hasTXOverflow();
/**
* @brief Flag indicating the RX ring buffer has overflowed.
* @returns bool Flag indicating the RX ring buffer has overflowed.
*/
bool hasRXOverflow();
/**
* @brief Flag indicating the air interface is locked out from transmitting.
* @returns bool Flag indicating the air interface is locked out from transmitting.
*/
bool hasLockout() const;
/**
* @brief
*/
void resetWatchdog();
/**
* @brief
* @returns uint32_t
*/
uint32_t getWatchdog();
/**
* @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
*/
void selfTest();
/**
* @brief
*/
void resetMCU();
#if SPI_ENABLED
/**
* @brief
* @param bytes
* @param length
*/
void SPI_Write(uint8_t* bytes, uint8_t length);
/**
* @brief
* @returns uint16_t
*/
uint16_t SPI_Read();
#endif
#if DIGIPOT_ENABLED
/**
* @brief
* @param value
*/
void SetDigipot(uint8_t value);
/**
* @brief
* @param value
*/
void SetTxDigipot(uint8_t value);
/**
* @brief
* @param value
*/
void SetRxDigipot(uint8_t value);
/**
* @brief
* @param value
*/
void SetRsDigipot(uint8_t value);
#endif
private:
bool m_started;
SampleBuffer m_rxBuffer;
SampleBuffer m_txBuffer;
RSSIBuffer m_rssiBuffer;
arm_fir_instance_q15 m_rrc_0_2_Filter;
arm_fir_instance_q15 m_boxcar_5_Filter;
arm_biquad_casd_df1_inst_q31 m_dcFilter;
q15_t m_rrc_0_2_State[70U]; // NoTaps + BlockSize - 1, 42 + 20 - 1 plus some spare
q15_t m_boxcar_5_State[30U]; // NoTaps + BlockSize - 1, 6 + 20 - 1 plus some spare
#if NXDN_BOXCAR_FILTER
arm_fir_instance_q15 m_boxcar_10_Filter;
q15_t m_boxcar_10_State[40U]; // NoTaps + BlockSize - 1, 10 + 20 - 1 plus some spare
#else
arm_fir_instance_q15 m_nxdn_0_2_Filter;
arm_fir_instance_q15 m_nxdn_ISinc_Filter;
q15_t m_nxdn_0_2_State[110U]; // NoTaps + BlockSize - 1, 82 + 20 - 1 plus some spare
q15_t m_nxdn_ISinc_State[60U]; // NoTaps + BlockSize - 1, 32 + 20 - 1 plus some spare
#endif
q31_t m_dcState[4];
bool m_pttInvert;
q15_t m_rxLevel;
bool m_rxInvert;
q15_t m_cwIdTXLevel;
q15_t m_dmrTXLevel;
q15_t m_p25TXLevel;
q15_t m_nxdnTXLevel;
uint16_t m_rxDCOffset;
uint16_t m_txDCOffset;
uint32_t m_ledCount;
bool m_ledValue;
bool m_detect;
uint16_t m_adcOverflow;
uint16_t m_dacOverflow;
volatile uint32_t m_watchdog;
bool m_lockout;
// Hardware specific routines
/**
* @brief Initializes hardware interrupts.
*/
void initInt();
/**
* @brief Starts hardware interrupts.
*/
void startInt();
/**
* @brief
*/
bool getCOSInt();
/**
* @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);
/**
* @brief
* @param dly
*/
void delayInt(unsigned int dly);
/**
* @brief
* @param arg
* @returns void*
*/
static void* txThreadHelper(void* arg);
/**
* @brief
* @param interruptRx
*/
void interruptRx();
/**
* @brief
* @param arg
* @returns void*
*/
static void* rxThreadHelper(void* arg);
};
#endif // __IO_H__