forked from DVMProject/dvmfirmware-hs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IO.h
251 lines (210 loc) · 7.15 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
/**
* Digital Voice Modem - DSP Firmware (Hotspot)
* GPLv2 Open Source. Use is subject to license terms.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* @package DVM / DSP Firmware (Hotspot)
*
*/
//
// Based on code from the MMDVM_HS project. (https://github.com/juribeparada/MMDVM_HS)
// Licensed under the GPLv2 License (https://opensource.org/licenses/GPL-2.0)
//
/*
* Copyright (C) 2015,2016,2020 by Jonathan Naylor G4KLX
* Copyright (C) 2016,2017,2018,2019,2020 by Andy Uribe CA6JAU
* Copyright (C) 2017 by Danilo DB4PLE
* Copyright (C) 2017-2021 Bryan Biedenkapp N2PLL
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#if !defined(__IO_H__)
#define __IO_H__
#include "Defines.h"
#include "Globals.h"
#include "BitBuffer.h"
// ---------------------------------------------------------------------------
// Constants
// ---------------------------------------------------------------------------
#if defined(DUPLEX)
#if defined(STM32_USB_HOST)
#define CAL_DLY_LOOP 98950U
#else
#define CAL_DLY_LOOP 96100U
#endif
#else
#if defined(STM32_USB_HOST)
#define CAL_DLY_LOOP 110850U
#else
#define CAL_DLY_LOOP 104600U
#endif
#endif
// ---------------------------------------------------------------------------
// Constants
// ---------------------------------------------------------------------------
enum ADF_GAIN_MODE {
// AGC automatic, default settings
ADF_GAIN_AUTO = 0U,
// AGC automatic with high LNA linearity
ADF_GAIN_AUTO_LIN = 1U,
// AGC OFF, lowest gain
ADF_GAIN_LOW = 2U,
// AGC OFF, highest gain
ADF_GAIN_HIGH = 3U
};
// ---------------------------------------------------------------------------
// Class Declaration
// Implements the input/output data path with the radio air interface.
// ---------------------------------------------------------------------------
class DSP_FW_API IO {
public:
/// <summary>Initializes a new instance of the IO class.</summary>
IO();
/// <summary>Starts air interface sampler.</summary>
void start();
/// <summary>Process bits from air interface.</summary>
void process();
/// <summary>Write bits to air interface.</summary>
void write(uint8_t* data, uint16_t length, const uint8_t* control = NULL);
/// <summary>Helper to get how much space the transmit ring buffer has for samples.</summary>
uint16_t getSpace(void) const;
/// <summary></summary>
void setDecode(bool dcd);
/// <summary>Set modem mode.</summary>
void setMode(DVM_STATE modemState);
/// <summary>Hardware interrupt handler.</summary>
void interrupt1();
#if defined(DUPLEX)
/// <summary>Hardware interrupt handler.</summary>
void interrupt2();
#endif
/// <summary>Sets the ADF7021 RF configuration.</summary>
void rf1Conf(DVM_STATE modemState, bool reset);
#if defined(DUPLEX)
/// <summary>Sets the ADF7021 RF configuration.</summary>
void rf2Conf(DVM_STATE modemState);
#endif
/// <summary></summary>
void setDeviations(uint8_t dmrTXLevel, uint8_t p25TXLevel);
/// <summary>Sets the RF parameters.</summary>
uint8_t setRFParams(uint32_t rxFreq, uint32_t txFreq, uint8_t rfPower, ADF_GAIN_MODE gainMode);
/// <summary>Sets the RF adjustment parameters.</summary>
void setRFAdjust(int8_t dmrDiscBWAdj, int8_t p25DiscBWAdj, int8_t dmrPostBWAdj, int8_t p25PostBWAdj);
/// <summary>Flag indicating the TX ring buffer has overflowed.</summary>
bool hasTXOverflow(void);
/// <summary>Flag indicating the RX ring buffer has overflowed.</summary>
bool hasRXOverflow(void);
/// <summary></summary>
void resetWatchdog(void);
/// <summary></summary>
uint32_t getWatchdog(void);
/// <summary>Gets the CPU type the firmware is running on.</summary>
uint8_t getCPU() const;
/// <summary>Gets the unique identifier for the air interface.</summary>
void getUDID(uint8_t* buffer);
/// <summary></summary>
void updateCal(DVM_STATE modemState);
/// <summary></summary>
void delayBit(void);
/// <summary></summary>
uint16_t readRSSI(void);
/// <summary></summary>
void selfTest();
/// <summary></summary>
void getIntCounter(uint16_t& int1, uint16_t& int2);
#if defined(ZUMSPOT_ADF7021) || defined(LONESTAR_USB) || defined(SKYBRIDGE_HS)
/// <summary></summary>
bool isDualBand();
#endif
/// <summary></summary>
void SCLK(bool on);
/// <summary></summary>
void SDATA(bool on);
/// <summary></summary>
bool SREAD();
/// <summary></summary>
void SLE1(bool on);
#if defined(DUPLEX)
/// <summary></summary>
void SLE2(bool on);
/// <summary></summary>
bool RXD2();
#endif
/// <summary></summary>
void CE(bool on);
/// <summary></summary>
bool RXD1();
/// <summary></summary>
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;
/// <summary>Helper to check the frequencies are within band ranges of the ADF7021.</summary>
void checkBand(uint32_t rxFreq, uint32_t txFreq);
#if defined(ZUMSPOT_ADF7021) || defined(LONESTAR_USB) || defined(SKYBRIDGE_HS)
/// <summary></summary>
void setBandVHF(bool enable);
/// <summary></summary>
bool hasSingleADF7021();
#endif
/// <summary></summary>
void configureBand();
/// <summary></summary>
void configureTxRx(DVM_STATE modemState);
/// <summary></summary>
void setTX();
/// <summary></summary>
void setRX(bool doSle = true);
/// <summary></summary>
void delayIfCal();
/// <summary></summary>
void delayReset();
/// <summary></summary>
void delayUS(uint32_t us);
// Hardware specific routines
/// <summary>Initializes hardware interrupts.</summary>
void initInt();
/// <summary>Starts hardware interrupts.</summary>
void startInt();
/// <summary></summary>
void setTXDInt(bool on);
#if defined(BIDIR_DATA_PIN)
/// <summary></summary>
void setDataDirOut(bool dir);
/// <summary></summary>
void setRXDInt(bool on);
#endif
/// <summary></summary>
void setLEDInt(bool on);
/// <summary></summary>
void setPTTInt(bool on);
/// <summary></summary>
void setCOSInt(bool on);
/// <summary></summary>
void setDMRInt(bool on);
/// <summary></summary>
void setP25Int(bool on);
};
#endif