mirror of
https://github.com/g4klx/MMDVM.git
synced 2026-10-16 16:54:12 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
02000c8049 | ||
|
|
2509ab5ba1 | ||
|
|
2de9e4d533 | ||
|
|
fda1e3dcf4 | ||
|
|
cb3ed795d0 | ||
|
|
632ddda68b | ||
|
|
b6093406ad | ||
|
|
8d9b49bdb0 | ||
|
|
625ec93af8 | ||
|
|
b2111553c6 | ||
|
|
252d54a484 | ||
|
|
1ad9799123 | ||
|
|
2a001f491d | ||
|
|
b5ba384495 | ||
|
|
d8f138066e | ||
|
|
6964251122 | ||
|
|
9ff59570c7 | ||
|
|
5960fb97f3 | ||
|
|
d29a0bc3a6 | ||
|
|
ad77fd60fd | ||
|
|
aab8f5469f | ||
|
|
f1d6a8b36e | ||
|
|
843997ccad | ||
|
|
d5f2d1c382 | ||
|
|
c99f50575d | ||
|
|
29c8cf9414 | ||
|
|
2c6e2c2a11 | ||
|
|
8d10555dc9 | ||
|
|
14d5098018 | ||
|
|
52a351d0f1 | ||
|
|
43f84ae968 | ||
|
|
a73376671c | ||
|
|
759efd1da4 | ||
|
|
ea0c1953cc | ||
|
|
a29cb23a75 | ||
|
|
bb66c72ef3 | ||
|
|
0ea732780d | ||
|
|
1309ad9326 | ||
|
|
411d439d78 | ||
|
|
ec9428d63e | ||
|
|
2a4b28c35e | ||
|
|
4f060c0047 | ||
|
|
1ed3a4c9d5 | ||
|
|
f414288c9b | ||
|
|
72cd2ce03e | ||
|
|
9137af8e3f | ||
|
|
cdfe3d0ec9 | ||
|
|
4dfab06a50 | ||
|
|
47649171fc | ||
|
|
0bd79fa440 | ||
|
|
26d055a67b | ||
|
|
5db1adb5ea | ||
|
|
f86b5435bb | ||
|
|
31f0e24588 | ||
|
|
04d0b15545 | ||
|
|
f14222e77d | ||
|
|
5039dfbe68 | ||
|
|
f9f81b9b8e | ||
|
|
3cc5d67696 | ||
|
|
3f960f9fc5 | ||
|
|
489853f200 | ||
|
|
96e1a765f9 | ||
|
|
04982c25c0 | ||
|
|
a3ffa9ed36 | ||
|
|
e7a22482db | ||
|
|
625749a546 | ||
|
|
d75042dc4c | ||
|
|
296ac88842 | ||
|
|
48e863d1d0 | ||
|
|
7b915f9cac | ||
|
|
e330c9f52a | ||
|
|
9470b1d6d3 | ||
|
|
388620b182 | ||
|
|
72e45177f3 | ||
|
|
90b82621f2 | ||
|
|
cfcb7ed852 | ||
|
|
b245be464f | ||
|
|
139003d4c7 | ||
|
|
c47eacd010 | ||
|
|
6b01f12602 | ||
|
|
4f93c6022c | ||
|
|
81f6b6be53 | ||
|
|
fa9f89700f | ||
|
|
9023b6ae13 | ||
|
|
df23e15c91 | ||
|
|
51e5e7b851 | ||
|
|
056dd908b3 | ||
|
|
62f239ccc9 | ||
|
|
994226e4b1 | ||
|
|
2cc6c1f68f | ||
|
|
8e8cf35b19 | ||
|
|
66de35b6d8 | ||
|
|
7dc420c8ff | ||
|
|
df0a9ebe72 | ||
|
|
e957f0154e | ||
|
|
b10c72fd78 | ||
|
|
496afcb40e | ||
|
|
9467b10e5c | ||
|
|
13c5f7b0b4 | ||
|
|
b64712f657 | ||
|
|
d23c0900c1 | ||
|
|
a0a3080da2 | ||
|
|
0fad84b46d | ||
|
|
1b40044a23 | ||
|
|
a671263398 | ||
|
|
ca1cc7096a | ||
|
|
a5aabd8fac | ||
|
|
6d0e57ea88 | ||
|
|
1d04c1e903 | ||
|
|
042c26b3bb | ||
|
|
b4a125a759 | ||
|
|
8ecf80ff8f | ||
|
|
6786b9b6b1 | ||
|
|
86ffc69b30 | ||
|
|
5d4df6ffd9 | ||
|
|
eac2aa4ac1 | ||
|
|
8cbd52aa72 | ||
|
|
99b853a976 | ||
|
|
15bc1a4027 | ||
|
|
1836ba928e | ||
|
|
4a5a260c28 | ||
|
|
4bcc1e88c4 | ||
|
|
89458a2c93 | ||
|
|
c91a42f53d | ||
|
|
470a070d96 | ||
|
|
36537c981c | ||
|
|
c85978a4e3 | ||
|
|
3ad443dc2a | ||
|
|
da16ee277c | ||
|
|
0f51ddd0bd | ||
|
|
aaa72e769f | ||
|
|
0e8fdb381a | ||
|
|
0b31c40c2b | ||
|
|
2b3df4e901 | ||
|
|
807f01ba72 | ||
|
|
03f18451f7 | ||
|
|
16c3d418eb | ||
|
|
55df5fe04c | ||
|
|
b0ba3b5dd8 | ||
|
|
05d21c0a14 | ||
|
|
26a703c68c | ||
|
|
6c3dd265ab | ||
|
|
c04e207821 | ||
|
|
67e0bf02e2 | ||
|
|
7302dc8bd7 | ||
|
|
bb7383a301 | ||
|
|
61a69d8536 | ||
|
|
5a11fcea5b | ||
|
|
05775f0bfa | ||
|
|
973a1391d7 | ||
|
|
5d45649096 | ||
|
|
e91c4417cb | ||
|
|
ff3e6feeb6 | ||
|
|
0e2a83bc7b | ||
|
|
c84dbd02e5 | ||
|
|
c0aad5effa | ||
|
|
e0234dfc00 | ||
|
|
7c9385beab | ||
|
|
4c6601d778 | ||
|
|
e3a951b33b | ||
|
|
97192602d8 | ||
|
|
604957b3e2 | ||
|
|
bb731e7890 | ||
|
|
c81d13395b | ||
|
|
18bc0a75b8 | ||
|
|
f1a43ee520 | ||
|
|
b73bca237d | ||
|
|
e7ff0d1898 | ||
|
|
880df2536d | ||
|
|
09b6929100 | ||
|
|
9afcf3acc9 | ||
|
|
d7cd7096d0 | ||
|
|
5d1b66dde3 | ||
|
|
96364dc189 | ||
|
|
a816818e3f |
+59
-11
@@ -30,21 +30,29 @@ const uint16_t DELAY_LEN = 11U;
|
|||||||
const float32_t SAMPLES_PER_SYMBOL = SAMPLE_RATE / SYMBOL_RATE;
|
const float32_t SAMPLES_PER_SYMBOL = SAMPLE_RATE / SYMBOL_RATE;
|
||||||
const float32_t PLL_LIMIT = SAMPLES_PER_SYMBOL / 2.0F;
|
const float32_t PLL_LIMIT = SAMPLES_PER_SYMBOL / 2.0F;
|
||||||
|
|
||||||
const uint32_t LPF_FILTER_LEN = 96U;
|
const uint32_t LPF_FILTER_LEN = 48U;
|
||||||
|
|
||||||
q15_t LPF_FILTER_COEFFS[] = {
|
q15_t LPF_FILTER_COEFFS[] = {
|
||||||
0, 0, 0, 1, 2, 5, 8, 12, 18, 23,
|
-2, -8, -17, -28, -40, -47, -47, -34,
|
||||||
29, 33, 36, 36, 33, 25, 13, -5, -28, -57,
|
-5, 46, 122, 224, 354, 510, 689, 885,
|
||||||
-89, -123, -159, -194, -225, -249, -264, -267, -254, -224,
|
1092, 1302, 1506, 1693, 1856, 1987, 2077, 2124,
|
||||||
-175, -104, -12, 102, 236, 389, 557, 738, 926, 1117,
|
2124, 2077, 1987, 1856, 1693, 1506, 1302, 1092,
|
||||||
1306, 1486, 1654, 1802, 1927, 2025, 2092, 2126, 2126, 2092,
|
885, 689, 510, 354, 224, 122, 46, -5,
|
||||||
2025, 1927, 1802, 1654, 1486, 1306, 1117, 926, 738, 557,
|
-34, -47, -47, -40, -28, -17, -8, -2
|
||||||
389, 236, 102, -12, -104, -175, -224, -254, -267, -264,
|
|
||||||
-249, -225, -194, -159, -123, -89, -57, -28, -5, 13,
|
|
||||||
25, 33, 36, 36, 33, 29, 23, 18, 12, 8,
|
|
||||||
5, 2, 1, 0, 0, 0
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Lock low-pass filter taps (80Hz Bessel)
|
||||||
|
// scipy.signal:
|
||||||
|
// b, a = bessel(4, [80.0/(1200/2)], 'lowpass')
|
||||||
|
//
|
||||||
|
const uint8_t PLL_IIR_SIZE = 5U;
|
||||||
|
|
||||||
|
const float32_t PLL_LOCK_B[] = {
|
||||||
|
1.077063e-03,4.308253e-03,6.462379e-03,4.308253e-03,1.077063e-03};
|
||||||
|
|
||||||
|
const float32_t PLL_LOCK_A[] = {
|
||||||
|
1.000000e+00,-2.774567e+00,2.962960e+00,-1.437990e+00,2.668296e-01};
|
||||||
|
|
||||||
// 64 Hz loop filter.
|
// 64 Hz loop filter.
|
||||||
// scipy.signal:
|
// scipy.signal:
|
||||||
// loop_coeffs = firwin(9, [64.0/(1200/2)], width = None,
|
// loop_coeffs = firwin(9, [64.0/(1200/2)], width = None,
|
||||||
@@ -67,6 +75,9 @@ m_pllState(),
|
|||||||
m_pllLast(false),
|
m_pllLast(false),
|
||||||
m_pllBits(1U),
|
m_pllBits(1U),
|
||||||
m_pllCount(0.0F),
|
m_pllCount(0.0F),
|
||||||
|
m_pllJitter(0.0F),
|
||||||
|
m_pllDCD(false),
|
||||||
|
m_iirHistory(),
|
||||||
m_hdlcOnes(0U),
|
m_hdlcOnes(0U),
|
||||||
m_hdlcFlag(false),
|
m_hdlcFlag(false),
|
||||||
m_hdlcBuffer(0U),
|
m_hdlcBuffer(0U),
|
||||||
@@ -82,6 +93,9 @@ m_hdlcState(AX25_IDLE)
|
|||||||
m_pllFilter.numTaps = PLL_FILTER_LEN;
|
m_pllFilter.numTaps = PLL_FILTER_LEN;
|
||||||
m_pllFilter.pState = m_pllState;
|
m_pllFilter.pState = m_pllState;
|
||||||
m_pllFilter.pCoeffs = PLL_FILTER_COEFFS;
|
m_pllFilter.pCoeffs = PLL_FILTER_COEFFS;
|
||||||
|
|
||||||
|
for (uint8_t i = 0U; i < PLL_IIR_SIZE; i++)
|
||||||
|
m_iirHistory[i] = 0.0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CAX25Demodulator::process(q15_t* samples, uint8_t length, CAX25Frame& frame)
|
bool CAX25Demodulator::process(q15_t* samples, uint8_t length, CAX25Frame& frame)
|
||||||
@@ -158,10 +172,18 @@ bool CAX25Demodulator::PLL(bool input)
|
|||||||
if (m_pllCount > PLL_LIMIT)
|
if (m_pllCount > PLL_LIMIT)
|
||||||
m_pllCount -= SAMPLES_PER_SYMBOL;
|
m_pllCount -= SAMPLES_PER_SYMBOL;
|
||||||
|
|
||||||
|
float32_t adjust = m_pllBits > 16U ? 5.0F : 0.0F;
|
||||||
float32_t offset = m_pllCount / float32_t(m_pllBits);
|
float32_t offset = m_pllCount / float32_t(m_pllBits);
|
||||||
float32_t jitter;
|
float32_t jitter;
|
||||||
::arm_fir_f32(&m_pllFilter, &offset, &jitter, 1U);
|
::arm_fir_f32(&m_pllFilter, &offset, &jitter, 1U);
|
||||||
|
|
||||||
|
float32_t absOffset = adjust;
|
||||||
|
if (offset < 0.0F)
|
||||||
|
absOffset -= offset;
|
||||||
|
else
|
||||||
|
absOffset += offset;
|
||||||
|
m_pllJitter = iir(absOffset);
|
||||||
|
|
||||||
m_pllCount -= jitter / 2.0F;
|
m_pllCount -= jitter / 2.0F;
|
||||||
m_pllBits = 1U;
|
m_pllBits = 1U;
|
||||||
} else {
|
} else {
|
||||||
@@ -264,3 +286,29 @@ void CAX25Demodulator::setTwist(int8_t n)
|
|||||||
m_twist.setTwist(n);
|
m_twist.setTwist(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CAX25Demodulator::isDCD()
|
||||||
|
{
|
||||||
|
if (m_pllJitter <= (SAMPLES_PER_SYMBOL * 0.03F))
|
||||||
|
m_pllDCD = true;
|
||||||
|
else if (m_pllJitter >= (SAMPLES_PER_SYMBOL * 0.15F))
|
||||||
|
m_pllDCD = false;
|
||||||
|
|
||||||
|
return m_pllDCD;
|
||||||
|
}
|
||||||
|
|
||||||
|
float32_t CAX25Demodulator::iir(float32_t input)
|
||||||
|
{
|
||||||
|
for (int8_t i = int8_t(PLL_IIR_SIZE) - 1; i != 0; i--)
|
||||||
|
m_iirHistory[i] = m_iirHistory[i - 1];
|
||||||
|
|
||||||
|
m_iirHistory[0] = input;
|
||||||
|
for (uint8_t i = 1U; i < PLL_IIR_SIZE; i++)
|
||||||
|
m_iirHistory[0] -= PLL_LOCK_A[i] * m_iirHistory[i];
|
||||||
|
|
||||||
|
float32_t result = 0.0F;
|
||||||
|
for (uint8_t i = 0U; i < PLL_IIR_SIZE; i++)
|
||||||
|
result += PLL_LOCK_B[i] * m_iirHistory[i];
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-1
@@ -38,11 +38,13 @@ public:
|
|||||||
|
|
||||||
void setTwist(int8_t n);
|
void setTwist(int8_t n);
|
||||||
|
|
||||||
|
bool isDCD();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CAX25Frame m_frame;
|
CAX25Frame m_frame;
|
||||||
CAX25Twist m_twist;
|
CAX25Twist m_twist;
|
||||||
arm_fir_instance_q15 m_lpfFilter;
|
arm_fir_instance_q15 m_lpfFilter;
|
||||||
q15_t m_lpfState[120U]; // NoTaps + BlockSize - 1, 96 + 20 - 1 plus some spare
|
q15_t m_lpfState[70U]; // NoTaps + BlockSize - 1, 48 + 20 - 1 plus some spare
|
||||||
bool* m_delayLine;
|
bool* m_delayLine;
|
||||||
uint16_t m_delayPos;
|
uint16_t m_delayPos;
|
||||||
bool m_nrziState;
|
bool m_nrziState;
|
||||||
@@ -51,6 +53,9 @@ private:
|
|||||||
bool m_pllLast;
|
bool m_pllLast;
|
||||||
uint8_t m_pllBits;
|
uint8_t m_pllBits;
|
||||||
float32_t m_pllCount;
|
float32_t m_pllCount;
|
||||||
|
float32_t m_pllJitter;
|
||||||
|
bool m_pllDCD;
|
||||||
|
float32_t m_iirHistory[5U];
|
||||||
uint16_t m_hdlcOnes;
|
uint16_t m_hdlcOnes;
|
||||||
bool m_hdlcFlag;
|
bool m_hdlcFlag;
|
||||||
uint16_t m_hdlcBuffer;
|
uint16_t m_hdlcBuffer;
|
||||||
@@ -61,6 +66,7 @@ private:
|
|||||||
bool NRZI(bool b);
|
bool NRZI(bool b);
|
||||||
bool PLL(bool b);
|
bool PLL(bool b);
|
||||||
bool HDLC(bool b);
|
bool HDLC(bool b);
|
||||||
|
float32_t iir(float32_t input);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+102
-17
@@ -39,22 +39,23 @@
|
|||||||
* window='hann') * 32768,
|
* window='hann') * 32768,
|
||||||
* dtype=int)[10:-10]
|
* dtype=int)[10:-10]
|
||||||
*/
|
*/
|
||||||
const uint32_t FILTER_LEN = 132;
|
|
||||||
|
const uint32_t FILTER_LEN = 130U;
|
||||||
|
|
||||||
q15_t FILTER_COEFFS[] = {
|
q15_t FILTER_COEFFS[] = {
|
||||||
0, 5, 12, 18, 21, 19, 11, -2, -15, -25,
|
5, 12, 18, 21, 19, 11, -2, -15, -25, -27,
|
||||||
-27, -21, -11, -3, -5, -19, -43, -69, -83, -73,
|
-21, -11, -3, -5, -19, -43, -69, -83, -73, -35,
|
||||||
-35, 27, 98, 155, 180, 163, 109, 39, -20, -45,
|
27, 98, 155, 180, 163, 109, 39, -20, -45, -26,
|
||||||
-26, 23, 74, 89, 39, -81, -247, -407, -501, -480,
|
23, 74, 89, 39, -81, -247, -407, -501, -480, -334,
|
||||||
-334, -92, 175, 388, 479, 429, 275, 99, 5, 68,
|
-92, 175, 388, 479, 429, 275, 99, 5, 68, 298,
|
||||||
298, 626, 913, 994, 740, 115, -791, -1770, -2544, -2847,
|
626, 913, 994, 740, 115, -791, -1770, -2544, -2847, -2509,
|
||||||
-2509, -1527, -76, 1518, 2875, 3653, 3653, 2875, 1518, -76,
|
-1527, -76, 1518, 2875, 3653, 3653, 2875, 1518, -76, -1527,
|
||||||
-1527, -2509, -2847, -2544, -1770, -791, 115, 740, 994, 913,
|
-2509, -2847, -2544, -1770, -791, 115, 740, 994, 913, 626,
|
||||||
626, 298, 68, 5, 99, 275, 429, 479, 388, 175,
|
298, 68, 5, 99, 275, 429, 479, 388, 175, -92,
|
||||||
-92, -334, -480, -501, -407, -247, -81, 39, 89, 74,
|
-334, -480, -501, -407, -247, -81, 39, 89, 74, 23,
|
||||||
23, -26, -45, -20, 39, 109, 163, 180, 155, 98,
|
-26, -45, -20, 39, 109, 163, 180, 155, 98, 27,
|
||||||
27, -35, -73, -83, -69, -43, -19, -5, -3, -11,
|
-35, -73, -83, -69, -43, -19, -5, -3, -11, -21,
|
||||||
-21, -27, -25, -15, -2, 11, 19, 21, 18, 12,
|
-27, -25, -15, -2, 11, 19, 21, 18, 12, 5
|
||||||
5, 0
|
|
||||||
};
|
};
|
||||||
|
|
||||||
CAX25RX::CAX25RX() :
|
CAX25RX::CAX25RX() :
|
||||||
@@ -64,11 +65,22 @@ m_demod1(3),
|
|||||||
m_demod2(6),
|
m_demod2(6),
|
||||||
m_demod3(9),
|
m_demod3(9),
|
||||||
m_lastFCS(0U),
|
m_lastFCS(0U),
|
||||||
m_count(0U)
|
m_count(0U),
|
||||||
|
m_slotTime(30U),
|
||||||
|
m_slotCount(0U),
|
||||||
|
m_pPersist(128U),
|
||||||
|
m_dcd(false),
|
||||||
|
m_canTX(false),
|
||||||
|
m_x(1U),
|
||||||
|
m_a(0xB7U),
|
||||||
|
m_b(0x73U),
|
||||||
|
m_c(0xF6U)
|
||||||
{
|
{
|
||||||
m_filter.numTaps = FILTER_LEN;
|
m_filter.numTaps = FILTER_LEN;
|
||||||
m_filter.pState = m_state;
|
m_filter.pState = m_state;
|
||||||
m_filter.pCoeffs = FILTER_COEFFS;
|
m_filter.pCoeffs = FILTER_COEFFS;
|
||||||
|
|
||||||
|
initRand();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAX25RX::samples(q15_t* samples, uint8_t length)
|
void CAX25RX::samples(q15_t* samples, uint8_t length)
|
||||||
@@ -109,12 +121,85 @@ void CAX25RX::samples(q15_t* samples, uint8_t length)
|
|||||||
}
|
}
|
||||||
DEBUG1("Decoder 3 reported");
|
DEBUG1("Decoder 3 reported");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_slotCount += RX_BLOCK_SIZE;
|
||||||
|
if (m_slotCount >= m_slotTime) {
|
||||||
|
m_slotCount = 0U;
|
||||||
|
|
||||||
|
bool dcd1 = m_demod1.isDCD();
|
||||||
|
bool dcd2 = m_demod2.isDCD();
|
||||||
|
bool dcd3 = m_demod3.isDCD();
|
||||||
|
|
||||||
|
if (dcd1 || dcd2 || dcd3) {
|
||||||
|
if (!m_dcd) {
|
||||||
|
io.setDecode(true);
|
||||||
|
io.setADCDetection(true);
|
||||||
|
m_dcd = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_canTX = false;
|
||||||
|
} else {
|
||||||
|
if (m_dcd) {
|
||||||
|
io.setDecode(false);
|
||||||
|
io.setADCDetection(false);
|
||||||
|
m_dcd = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_canTX = m_pPersist >= rand();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAX25RX::setParams(int8_t twist)
|
bool CAX25RX::canTX() const
|
||||||
|
{
|
||||||
|
return m_canTX;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CAX25RX::setParams(int8_t twist, uint8_t slotTime, uint8_t pPersist)
|
||||||
{
|
{
|
||||||
m_demod1.setTwist(twist - 3);
|
m_demod1.setTwist(twist - 3);
|
||||||
m_demod2.setTwist(twist);
|
m_demod2.setTwist(twist);
|
||||||
m_demod3.setTwist(twist + 3);
|
m_demod3.setTwist(twist + 3);
|
||||||
|
|
||||||
|
m_slotTime = slotTime * 240U; // Slot time in samples
|
||||||
|
m_pPersist = pPersist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Taken from https://www.electro-tech-online.com/threads/ultra-fast-pseudorandom-number-generator-for-8-bit.124249/
|
||||||
|
//X ABC Algorithm Random Number Generator for 8-Bit Devices:
|
||||||
|
//This is a small PRNG, experimentally verified to have at least a 50 million byte period
|
||||||
|
//by generating 50 million bytes and observing that there were no overapping sequences and repeats.
|
||||||
|
//This generator passes serial correlation, entropy , Monte Carlo Pi value, arithmetic mean,
|
||||||
|
//And many other statistical tests. This generator may have a period of up to 2^32, but this has
|
||||||
|
//not been verified.
|
||||||
|
//
|
||||||
|
// By XORing 3 bytes into the a,b, and c registers, you can add in entropy from
|
||||||
|
//an external source easily.
|
||||||
|
//
|
||||||
|
//This generator is free to use, but is not suitable for cryptography due to its short period(by //cryptographic standards) and simple construction. No attempt was made to make this generator
|
||||||
|
// suitable for cryptographic use.
|
||||||
|
//
|
||||||
|
//Due to the use of a constant counter, the generator should be resistant to latching up.
|
||||||
|
//A significant performance gain is had in that the x variable is only ever incremented.
|
||||||
|
//
|
||||||
|
//Only 4 bytes of ram are needed for the internal state, and generating a byte requires 3 XORs , //2 ADDs, one bit shift right , and one increment. Difficult or slow operations like multiply, etc
|
||||||
|
//were avoided for maximum speed on ultra low power devices.
|
||||||
|
|
||||||
|
|
||||||
|
void CAX25RX::initRand() //Can also be used to seed the rng with more entropy during use.
|
||||||
|
{
|
||||||
|
m_a = (m_a ^ m_c ^ m_x);
|
||||||
|
m_b = (m_b + m_a);
|
||||||
|
m_c = (m_c + (m_b >> 1) ^ m_a);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t CAX25RX::rand()
|
||||||
|
{
|
||||||
|
m_x++; //x is incremented every round and is not affected by any other variable
|
||||||
|
|
||||||
|
m_a = (m_a ^ m_c ^ m_x); //note the mix of addition and XOR
|
||||||
|
m_b = (m_b + m_a); //And the use of very few instructions
|
||||||
|
m_c = (m_c + (m_b >> 1) ^ m_a); //the right shift is to ensure that high-order bits from b can affect
|
||||||
|
|
||||||
|
return uint8_t(m_c); //low order bits of other variables
|
||||||
|
}
|
||||||
|
|||||||
@@ -29,16 +29,30 @@ public:
|
|||||||
|
|
||||||
void samples(q15_t* samples, uint8_t length);
|
void samples(q15_t* samples, uint8_t length);
|
||||||
|
|
||||||
void setParams(int8_t twist);
|
void setParams(int8_t twist, uint8_t slotTime, uint8_t pPersist);
|
||||||
|
|
||||||
|
bool canTX() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
arm_fir_instance_q15 m_filter;
|
arm_fir_instance_q15 m_filter;
|
||||||
q15_t m_state[160U]; // NoTaps + BlockSize - 1, 132 + 20 - 1 plus some spare
|
q15_t m_state[160U]; // NoTaps + BlockSize - 1, 130 + 20 - 1 plus some spare
|
||||||
CAX25Demodulator m_demod1;
|
CAX25Demodulator m_demod1;
|
||||||
CAX25Demodulator m_demod2;
|
CAX25Demodulator m_demod2;
|
||||||
CAX25Demodulator m_demod3;
|
CAX25Demodulator m_demod3;
|
||||||
uint16_t m_lastFCS;
|
uint16_t m_lastFCS;
|
||||||
uint32_t m_count;
|
uint32_t m_count;
|
||||||
|
uint32_t m_slotTime;
|
||||||
|
uint32_t m_slotCount;
|
||||||
|
uint8_t m_pPersist;
|
||||||
|
bool m_dcd;
|
||||||
|
bool m_canTX;
|
||||||
|
uint8_t m_x;
|
||||||
|
uint8_t m_a;
|
||||||
|
uint8_t m_b;
|
||||||
|
uint8_t m_c;
|
||||||
|
|
||||||
|
void initRand();
|
||||||
|
uint8_t rand();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+28
-22
@@ -49,11 +49,10 @@ const q15_t AUDIO_TABLE_DATA[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
CAX25TX::CAX25TX() :
|
CAX25TX::CAX25TX() :
|
||||||
m_twist(-6),
|
|
||||||
m_poBuffer(),
|
m_poBuffer(),
|
||||||
m_poLen(0U),
|
m_poLen(0U),
|
||||||
m_poPtr(0U),
|
m_poPtr(0U),
|
||||||
m_txDelay(120U),
|
m_txDelay(360U),
|
||||||
m_tablePtr(0U),
|
m_tablePtr(0U),
|
||||||
m_nrzi(false)
|
m_nrzi(false)
|
||||||
{
|
{
|
||||||
@@ -64,6 +63,14 @@ void CAX25TX::process()
|
|||||||
if (m_poLen == 0U)
|
if (m_poLen == 0U)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (!m_duplex) {
|
||||||
|
if (m_poPtr == 0U) {
|
||||||
|
bool tx = ax25RX.canTX();
|
||||||
|
if (!tx)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
uint16_t space = io.getSpace();
|
uint16_t space = io.getSpace();
|
||||||
|
|
||||||
while (space > AX25_RADIO_SYMBOL_LENGTH) {
|
while (space > AX25_RADIO_SYMBOL_LENGTH) {
|
||||||
@@ -92,9 +99,11 @@ uint8_t CAX25TX::writeData(const uint8_t* data, uint16_t length)
|
|||||||
m_nrzi = false;
|
m_nrzi = false;
|
||||||
m_tablePtr = 0U;
|
m_tablePtr = 0U;
|
||||||
|
|
||||||
// Add TX delay (already NRZI)
|
// Add TX delay
|
||||||
for (uint16_t i = 0U; i < m_txDelay; i++, m_poLen++)
|
for (uint16_t i = 0U; i < m_txDelay; i++, m_poLen++) {
|
||||||
WRITE_BIT1(m_poBuffer, m_poLen, false);
|
bool preamble = NRZI(false);
|
||||||
|
WRITE_BIT1(m_poBuffer, m_poLen, preamble);
|
||||||
|
}
|
||||||
|
|
||||||
// Add the Start Flag
|
// Add the Start Flag
|
||||||
for (uint16_t i = 0U; i < 8U; i++, m_poLen++) {
|
for (uint16_t i = 0U; i < 8U; i++, m_poLen++) {
|
||||||
@@ -136,27 +145,25 @@ uint8_t CAX25TX::writeData(const uint8_t* data, uint16_t length)
|
|||||||
|
|
||||||
void CAX25TX::writeBit(bool b)
|
void CAX25TX::writeBit(bool b)
|
||||||
{
|
{
|
||||||
q15_t in[AX25_RADIO_SYMBOL_LENGTH];
|
q15_t buffer[AX25_RADIO_SYMBOL_LENGTH];
|
||||||
for (uint8_t i = 0U; i < AX25_RADIO_SYMBOL_LENGTH; i++) {
|
for (uint8_t i = 0U; i < AX25_RADIO_SYMBOL_LENGTH; i++) {
|
||||||
in[i] = AUDIO_TABLE_DATA[m_tablePtr];
|
q15_t value = AUDIO_TABLE_DATA[m_tablePtr];
|
||||||
if (b)
|
|
||||||
|
if (b) {
|
||||||
|
// De-emphasise the lower frequency by 6dB
|
||||||
|
value >>= 2;
|
||||||
m_tablePtr += 6U;
|
m_tablePtr += 6U;
|
||||||
else
|
} else {
|
||||||
m_tablePtr += 11U;
|
m_tablePtr += 11U;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer[i] = value;
|
||||||
|
|
||||||
if (m_tablePtr >= AUDIO_TABLE_LEN)
|
if (m_tablePtr >= AUDIO_TABLE_LEN)
|
||||||
m_tablePtr -= AUDIO_TABLE_LEN;
|
m_tablePtr -= AUDIO_TABLE_LEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
q15_t out[AX25_RADIO_SYMBOL_LENGTH];
|
io.write(STATE_AX25, buffer, AX25_RADIO_SYMBOL_LENGTH);
|
||||||
m_twist.process(in, out, AX25_RADIO_SYMBOL_LENGTH);
|
|
||||||
|
|
||||||
io.write(STATE_AX25, out, AX25_RADIO_SYMBOL_LENGTH);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CAX25TX::setParams(int8_t twist)
|
|
||||||
{
|
|
||||||
m_twist.setTwist(twist);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAX25TX::setTXDelay(uint8_t delay)
|
void CAX25TX::setTXDelay(uint8_t delay)
|
||||||
@@ -171,10 +178,9 @@ uint8_t CAX25TX::getSpace() const
|
|||||||
|
|
||||||
bool CAX25TX::NRZI(bool b)
|
bool CAX25TX::NRZI(bool b)
|
||||||
{
|
{
|
||||||
bool result = (b == m_nrzi);
|
if (!b)
|
||||||
|
m_nrzi = !m_nrzi;
|
||||||
|
|
||||||
m_nrzi = b;
|
return m_nrzi;
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,8 +21,6 @@
|
|||||||
|
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
|
||||||
#include "AX25Twist.h"
|
|
||||||
|
|
||||||
class CAX25TX {
|
class CAX25TX {
|
||||||
public:
|
public:
|
||||||
CAX25TX();
|
CAX25TX();
|
||||||
@@ -31,14 +29,11 @@ public:
|
|||||||
|
|
||||||
void process();
|
void process();
|
||||||
|
|
||||||
void setParams(int8_t twist);
|
|
||||||
|
|
||||||
void setTXDelay(uint8_t delay);
|
void setTXDelay(uint8_t delay);
|
||||||
|
|
||||||
uint8_t getSpace() const;
|
uint8_t getSpace() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CAX25Twist m_twist;
|
|
||||||
uint8_t m_poBuffer[600U];
|
uint8_t m_poBuffer[600U];
|
||||||
uint16_t m_poLen;
|
uint16_t m_poLen;
|
||||||
uint16_t m_poPtr;
|
uint16_t m_poPtr;
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ void CCalFM::process()
|
|||||||
{
|
{
|
||||||
const TONE_TABLE* entry = NULL;
|
const TONE_TABLE* entry = NULL;
|
||||||
|
|
||||||
if (m_modemState!=m_lastState)
|
if (m_modemState != m_lastState)
|
||||||
{
|
{
|
||||||
switch (m_modemState) {
|
switch (m_modemState) {
|
||||||
case STATE_FMCAL10K:
|
case STATE_FMCAL10K:
|
||||||
|
|||||||
@@ -35,6 +35,14 @@
|
|||||||
// For 19.2 MHz
|
// For 19.2 MHz
|
||||||
// #define EXTERNAL_OSC 19200000
|
// #define EXTERNAL_OSC 19200000
|
||||||
|
|
||||||
|
// Use a higher baudrate for host communication. Required for FM network !
|
||||||
|
#define SERIAL_SPEED 115200 //suitable for most older boards (Arduino, Due STM32F1_POG etc). External FM will NOT work with this !
|
||||||
|
// #define SERIAL_SPEED 230400 // Only works on newer board M4, M7, Teensy. External FM might work with this
|
||||||
|
// #define SERIAL_SPEED 460800 // Only works on newer board M4, M7, Teensy. External FM should work with this
|
||||||
|
|
||||||
|
// Allow the use of the COS line to lockout the modem
|
||||||
|
// #define USE_COS_AS_LOCKOUT
|
||||||
|
|
||||||
// Use pins to output the current mode via LEDs
|
// Use pins to output the current mode via LEDs
|
||||||
#define MODE_LEDS
|
#define MODE_LEDS
|
||||||
|
|
||||||
@@ -85,3 +93,4 @@
|
|||||||
#define USE_ALTERNATE_FM_LEDS
|
#define USE_ALTERNATE_FM_LEDS
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -74,7 +74,7 @@ void CDMRDMOTX::process()
|
|||||||
m_poLen = m_txDelay;
|
m_poLen = m_txDelay;
|
||||||
} else {
|
} else {
|
||||||
for (unsigned int i = 0U; i < DMR_FRAME_LENGTH_BYTES; i++)
|
for (unsigned int i = 0U; i < DMR_FRAME_LENGTH_BYTES; i++)
|
||||||
m_poBuffer[i] = m_fifo.get();
|
m_fifo.get(m_poBuffer[i]);
|
||||||
|
|
||||||
for (unsigned int i = 0U; i < 39U; i++)
|
for (unsigned int i = 0U; i < 39U; i++)
|
||||||
m_poBuffer[i + DMR_FRAME_LENGTH_BYTES] = PR_FILL[i];
|
m_poBuffer[i + DMR_FRAME_LENGTH_BYTES] = PR_FILL[i];
|
||||||
|
|||||||
+2
-2
@@ -23,7 +23,7 @@
|
|||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "DMRDefines.h"
|
#include "DMRDefines.h"
|
||||||
|
|
||||||
#include "SerialRB.h"
|
#include "RingBuffer.h"
|
||||||
|
|
||||||
class CDMRDMOTX {
|
class CDMRDMOTX {
|
||||||
public:
|
public:
|
||||||
@@ -38,7 +38,7 @@ public:
|
|||||||
uint8_t getSpace() const;
|
uint8_t getSpace() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CSerialRB m_fifo;
|
CRingBuffer<uint8_t> m_fifo;
|
||||||
arm_fir_interpolate_instance_q15 m_modFilter;
|
arm_fir_interpolate_instance_q15 m_modFilter;
|
||||||
q15_t m_modState[16U]; // blockSize + phaseLength - 1, 4 + 9 - 1 plus some spare
|
q15_t m_modState[16U]; // blockSize + phaseLength - 1, 4 + 9 - 1 plus some spare
|
||||||
uint8_t m_poBuffer[1200U];
|
uint8_t m_poBuffer[1200U];
|
||||||
|
|||||||
@@ -293,7 +293,7 @@ void CDMRTX::createData(uint8_t slotIndex)
|
|||||||
{
|
{
|
||||||
if (m_fifo[slotIndex].getData() >= DMR_FRAME_LENGTH_BYTES && m_frameCount >= STARTUP_COUNT && m_abortCount[slotIndex] >= ABORT_COUNT) {
|
if (m_fifo[slotIndex].getData() >= DMR_FRAME_LENGTH_BYTES && m_frameCount >= STARTUP_COUNT && m_abortCount[slotIndex] >= ABORT_COUNT) {
|
||||||
for (unsigned int i = 0U; i < DMR_FRAME_LENGTH_BYTES; i++) {
|
for (unsigned int i = 0U; i < DMR_FRAME_LENGTH_BYTES; i++) {
|
||||||
m_poBuffer[i] = m_fifo[slotIndex].get();
|
m_fifo[slotIndex].get(m_poBuffer[i]);
|
||||||
m_markBuffer[i] = MARK_NONE;
|
m_markBuffer[i] = MARK_NONE;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "DMRDefines.h"
|
#include "DMRDefines.h"
|
||||||
|
|
||||||
#include "SerialRB.h"
|
#include "RingBuffer.h"
|
||||||
|
|
||||||
enum DMRTXSTATE {
|
enum DMRTXSTATE {
|
||||||
DMRTXSTATE_IDLE,
|
DMRTXSTATE_IDLE,
|
||||||
@@ -59,7 +59,7 @@ public:
|
|||||||
void setColorCode(uint8_t colorCode);
|
void setColorCode(uint8_t colorCode);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CSerialRB m_fifo[2U];
|
CRingBuffer<uint8_t> m_fifo[2U];
|
||||||
arm_fir_interpolate_instance_q15 m_modFilter;
|
arm_fir_interpolate_instance_q15 m_modFilter;
|
||||||
q15_t m_modState[16U]; // blockSize + phaseLength - 1, 4 + 9 - 1 plus some spare
|
q15_t m_modState[16U]; // blockSize + phaseLength - 1, 4 + 9 - 1 plus some spare
|
||||||
DMRTXSTATE m_state;
|
DMRTXSTATE m_state;
|
||||||
|
|||||||
+8
-5
@@ -216,12 +216,13 @@ void CDStarTX::process()
|
|||||||
for (uint16_t i = 0U; i < m_txDelay; i++)
|
for (uint16_t i = 0U; i < m_txDelay; i++)
|
||||||
m_poBuffer[m_poLen++] = BIT_SYNC;
|
m_poBuffer[m_poLen++] = BIT_SYNC;
|
||||||
} else {
|
} else {
|
||||||
|
uint8_t dummy;
|
||||||
// Pop the type byte off
|
// Pop the type byte off
|
||||||
m_buffer.get();
|
m_buffer.get(dummy);
|
||||||
|
|
||||||
uint8_t header[DSTAR_HEADER_LENGTH_BYTES];
|
uint8_t header[DSTAR_HEADER_LENGTH_BYTES];
|
||||||
for (uint8_t i = 0U; i < DSTAR_HEADER_LENGTH_BYTES; i++)
|
for (uint8_t i = 0U; i < DSTAR_HEADER_LENGTH_BYTES; i++)
|
||||||
header[i] = m_buffer.get();
|
m_buffer.get(header[i]);
|
||||||
|
|
||||||
uint8_t buffer[86U];
|
uint8_t buffer[86U];
|
||||||
txHeader(header, buffer + 2U);
|
txHeader(header, buffer + 2U);
|
||||||
@@ -239,17 +240,19 @@ void CDStarTX::process()
|
|||||||
|
|
||||||
if (type == DSTAR_DATA && m_poLen == 0U) {
|
if (type == DSTAR_DATA && m_poLen == 0U) {
|
||||||
// Pop the type byte off
|
// Pop the type byte off
|
||||||
m_buffer.get();
|
uint8_t dummy;
|
||||||
|
m_buffer.get(dummy);
|
||||||
|
|
||||||
for (uint8_t i = 0U; i < DSTAR_DATA_LENGTH_BYTES; i++)
|
for (uint8_t i = 0U; i < DSTAR_DATA_LENGTH_BYTES; i++)
|
||||||
m_poBuffer[m_poLen++] = m_buffer.get();
|
m_buffer.get(m_poBuffer[m_poLen++]);
|
||||||
|
|
||||||
m_poPtr = 0U;
|
m_poPtr = 0U;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == DSTAR_EOT && m_poLen == 0U) {
|
if (type == DSTAR_EOT && m_poLen == 0U) {
|
||||||
// Pop the type byte off
|
// Pop the type byte off
|
||||||
m_buffer.get();
|
uint8_t dummy;
|
||||||
|
m_buffer.get(dummy);
|
||||||
|
|
||||||
for (uint8_t j = 0U; j < 3U; j++) {
|
for (uint8_t j = 0U; j < 3U; j++) {
|
||||||
for (uint8_t i = 0U; i < DSTAR_EOT_LENGTH_BYTES; i++)
|
for (uint8_t i = 0U; i < DSTAR_EOT_LENGTH_BYTES; i++)
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
|
||||||
#include "SerialRB.h"
|
#include "RingBuffer.h"
|
||||||
|
|
||||||
class CDStarTX {
|
class CDStarTX {
|
||||||
public:
|
public:
|
||||||
@@ -38,7 +38,7 @@ public:
|
|||||||
uint8_t getSpace() const;
|
uint8_t getSpace() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CSerialRB m_buffer;
|
CRingBuffer<uint8_t> m_buffer;
|
||||||
arm_fir_interpolate_instance_q15 m_modFilter;
|
arm_fir_interpolate_instance_q15 m_modFilter;
|
||||||
q15_t m_modState[20U]; // blockSize + phaseLength - 1, 8 + 9 - 1 plus some spare
|
q15_t m_modState[20U]; // blockSize + phaseLength - 1, 8 + 9 - 1 plus some spare
|
||||||
uint8_t m_poBuffer[600U];
|
uint8_t m_poBuffer[600U];
|
||||||
|
|||||||
@@ -27,28 +27,33 @@
|
|||||||
#include "FMTimeout.h"
|
#include "FMTimeout.h"
|
||||||
#include "FMKeyer.h"
|
#include "FMKeyer.h"
|
||||||
#include "FMTimer.h"
|
#include "FMTimer.h"
|
||||||
#include "FMRB.h"
|
#include "RingBuffer.h"
|
||||||
#include "FMDirectForm1.h"
|
#include "FMDirectForm1.h"
|
||||||
#include "FMDownsampler.h"
|
#include "FMDownSampler.h"
|
||||||
|
#include "FMUpSampler.h"
|
||||||
|
#include "FMNoiseSquelch.h"
|
||||||
|
|
||||||
enum FM_STATE {
|
enum FM_STATE {
|
||||||
FS_LISTENING,
|
FS_LISTENING,
|
||||||
FS_KERCHUNK,
|
FS_KERCHUNK_RF,
|
||||||
FS_RELAYING,
|
FS_RELAYING_RF,
|
||||||
FS_RELAYING_WAIT,
|
FS_RELAYING_WAIT_RF,
|
||||||
FS_TIMEOUT,
|
FS_TIMEOUT_RF,
|
||||||
FS_TIMEOUT_WAIT,
|
FS_TIMEOUT_WAIT_RF,
|
||||||
|
FS_KERCHUNK_EXT,
|
||||||
|
FS_RELAYING_EXT,
|
||||||
|
FS_RELAYING_WAIT_EXT,
|
||||||
|
FS_TIMEOUT_EXT,
|
||||||
|
FS_TIMEOUT_WAIT_EXT,
|
||||||
FS_HANG
|
FS_HANG
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class CFM {
|
class CFM {
|
||||||
public:
|
public:
|
||||||
CFM();
|
CFM();
|
||||||
|
|
||||||
void samples(bool cos, const q15_t* samples, uint8_t length);
|
void samples(bool cos, q15_t* samples, uint8_t length);
|
||||||
|
|
||||||
void process();
|
void process();
|
||||||
|
|
||||||
@@ -56,13 +61,20 @@ public:
|
|||||||
|
|
||||||
uint8_t setCallsign(const char* callsign, uint8_t speed, uint16_t frequency, uint8_t time, uint8_t holdoff, uint8_t highLevel, uint8_t lowLevel, bool callsignAtStart, bool callsignAtEnd, bool callsignAtLatch);
|
uint8_t setCallsign(const char* callsign, uint8_t speed, uint16_t frequency, uint8_t time, uint8_t holdoff, uint8_t highLevel, uint8_t lowLevel, bool callsignAtStart, bool callsignAtEnd, bool callsignAtLatch);
|
||||||
uint8_t setAck(const char* rfAck, uint8_t speed, uint16_t frequency, uint8_t minTime, uint16_t delay, uint8_t level);
|
uint8_t setAck(const char* rfAck, uint8_t speed, uint16_t frequency, uint8_t minTime, uint16_t delay, uint8_t level);
|
||||||
uint8_t setMisc(uint16_t timeout, uint8_t timeoutLevel, uint8_t ctcssFrequency, uint8_t ctcssHighThreshold, uint8_t ctcssLowThreshold, uint8_t ctcssLevel, uint8_t kerchunkTime, uint8_t hangTime, uint8_t accessMode, bool cosInvert, uint8_t rfAudioBoost, uint8_t maxDev, uint8_t rxLevel);
|
uint8_t setMisc(uint16_t timeout, uint8_t timeoutLevel, uint8_t ctcssFrequency, uint8_t ctcssHighThreshold, uint8_t ctcssLowThreshold, uint8_t ctcssLevel, uint8_t kerchunkTime, uint8_t hangTime, uint8_t accessMode, bool cosInvert, bool noiseSquelch, uint8_t squelchHighThreshold, uint8_t squelchLowThreshold, uint8_t rfAudioBoost, uint8_t maxDev, uint8_t rxLevel);
|
||||||
|
uint8_t setExt(const char* ack, uint8_t audioBoost, uint8_t speed, uint16_t frequency, uint8_t level);
|
||||||
|
|
||||||
|
uint8_t getSpace() const;
|
||||||
|
|
||||||
|
uint8_t writeData(const uint8_t* data, uint8_t length);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CFMKeyer m_callsign;
|
CFMKeyer m_callsign;
|
||||||
CFMKeyer m_rfAck;
|
CFMKeyer m_rfAck;
|
||||||
|
CFMKeyer m_extAck;
|
||||||
CFMCTCSSRX m_ctcssRX;
|
CFMCTCSSRX m_ctcssRX;
|
||||||
CFMCTCSSTX m_ctcssTX;
|
CFMCTCSSTX m_ctcssTX;
|
||||||
|
CFMNoiseSquelch m_squelch;
|
||||||
CFMTimeout m_timeoutTone;
|
CFMTimeout m_timeoutTone;
|
||||||
FM_STATE m_state;
|
FM_STATE m_state;
|
||||||
bool m_callsignAtStart;
|
bool m_callsignAtStart;
|
||||||
@@ -75,27 +87,51 @@ private:
|
|||||||
CFMTimer m_ackMinTimer;
|
CFMTimer m_ackMinTimer;
|
||||||
CFMTimer m_ackDelayTimer;
|
CFMTimer m_ackDelayTimer;
|
||||||
CFMTimer m_hangTimer;
|
CFMTimer m_hangTimer;
|
||||||
|
CFMTimer m_statusTimer;
|
||||||
CFMTimer m_reverseTimer;
|
CFMTimer m_reverseTimer;
|
||||||
|
bool m_needReverse;
|
||||||
CFMDirectFormI m_filterStage1;
|
CFMDirectFormI m_filterStage1;
|
||||||
CFMDirectFormI m_filterStage2;
|
CFMDirectFormI m_filterStage2;
|
||||||
CFMDirectFormI m_filterStage3;
|
CFMDirectFormI m_filterStage3;
|
||||||
CFMBlanking m_blanking;
|
CFMBlanking m_blanking;
|
||||||
uint8_t m_accessMode;
|
uint8_t m_accessMode;
|
||||||
bool m_cosInvert;
|
bool m_cosInvert;
|
||||||
|
bool m_noiseSquelch;
|
||||||
q15_t m_rfAudioBoost;
|
q15_t m_rfAudioBoost;
|
||||||
CFMDownsampler m_downsampler;
|
q15_t m_extAudioBoost;
|
||||||
|
CFMDownSampler m_downSampler;
|
||||||
|
bool m_extEnabled;
|
||||||
q15_t m_rxLevel;
|
q15_t m_rxLevel;
|
||||||
CFMRB m_inputRB;
|
CRingBuffer<q15_t> m_inputRFRB;
|
||||||
CFMRB m_outputRB;
|
CRingBuffer<q15_t> m_outputRFRB;
|
||||||
|
CFMUpSampler m_inputExtRB;
|
||||||
|
|
||||||
void stateMachine(bool validSignal);
|
void stateMachine(bool validRFSignal, bool validExtSignal);
|
||||||
void listeningState(bool validSignal);
|
|
||||||
void kerchunkState(bool validSignal);
|
void duplexStateMachine(bool validRFSignal, bool validExtSignal);
|
||||||
void relayingState(bool validSignal);
|
void listeningStateDuplex(bool validRFSignal, bool validExtSignal);
|
||||||
void relayingWaitState(bool validSignal);
|
void kerchunkRFStateDuplex(bool validSignal);
|
||||||
void timeoutState(bool validSignal);
|
void relayingRFStateDuplex(bool validSignal);
|
||||||
void timeoutWaitState(bool validSignal);
|
void relayingRFWaitStateDuplex(bool validSignal);
|
||||||
void hangState(bool validSignal);
|
void timeoutRFStateDuplex(bool validSignal);
|
||||||
|
void timeoutRFWaitStateDuplex(bool validSignal);
|
||||||
|
void kerchunkExtStateDuplex(bool validSignal);
|
||||||
|
void relayingExtStateDuplex(bool validSignal);
|
||||||
|
void relayingExtWaitStateDuplex(bool validSignal);
|
||||||
|
void timeoutExtStateDuplex(bool validSignal);
|
||||||
|
void timeoutExtWaitStateDuplex(bool validSignal);
|
||||||
|
void hangStateDuplex(bool validRFSignal, bool validExtSignal);
|
||||||
|
|
||||||
|
void simplexStateMachine(bool validRFSignal, bool validExtSignal);
|
||||||
|
void listeningStateSimplex(bool validRFSignal, bool validExtSignal);
|
||||||
|
void relayingRFStateSimplex(bool validSignal);
|
||||||
|
void relayingRFWaitStateSimplex(bool validSignal);
|
||||||
|
void timeoutRFStateSimplex(bool validSignal);
|
||||||
|
void timeoutRFWaitStateSimplex(bool validSignal);
|
||||||
|
void relayingExtStateSimplex(bool validSignal);
|
||||||
|
void relayingExtWaitStateSimplex(bool validSignal);
|
||||||
|
void timeoutExtStateSimplex(bool validSignal);
|
||||||
|
void timeoutExtWaitStateSimplex(bool validSignal);
|
||||||
|
|
||||||
void clock(uint8_t length);
|
void clock(uint8_t length);
|
||||||
|
|
||||||
|
|||||||
+9
-15
@@ -87,7 +87,7 @@ m_lowThreshold(0),
|
|||||||
m_count(0U),
|
m_count(0U),
|
||||||
m_q0(0),
|
m_q0(0),
|
||||||
m_q1(0),
|
m_q1(0),
|
||||||
m_result(CTS_NONE)
|
m_state(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,13 +111,11 @@ uint8_t CFMCTCSSRX::setParams(uint8_t frequency, uint8_t highThreshold, uint8_t
|
|||||||
return 0U;
|
return 0U;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t CFMCTCSSRX::process(q15_t sample)
|
bool CFMCTCSSRX::process(q15_t sample)
|
||||||
{
|
{
|
||||||
//get more dynamic into the decoder by multiplying the sample by 1.5
|
//get more dynamic into the decoder by multiplying the sample by 1.5
|
||||||
q31_t sample31 = q31_t(sample) + (q31_t(sample) >> 1);
|
q31_t sample31 = q31_t(sample) + (q31_t(sample) >> 1);
|
||||||
|
|
||||||
m_result &= ~CTS_READY;
|
|
||||||
|
|
||||||
q31_t q2 = m_q1;
|
q31_t q2 = m_q1;
|
||||||
m_q1 = m_q0;
|
m_q1 = m_q0;
|
||||||
|
|
||||||
@@ -149,33 +147,29 @@ uint8_t CFMCTCSSRX::process(q15_t sample)
|
|||||||
// value = m_q0 * m_q0 + m_q1 * m_q1 - m_q0 * m_q1 * m_coeffDivTwo * 2
|
// value = m_q0 * m_q0 + m_q1 * m_q1 - m_q0 * m_q1 * m_coeffDivTwo * 2
|
||||||
q31_t value = t2 + t4 - t9;
|
q31_t value = t2 + t4 - t9;
|
||||||
|
|
||||||
bool previousCTCSSValid = CTCSS_VALID(m_result);
|
bool previousState = m_state;
|
||||||
|
|
||||||
q31_t threshold = m_highThreshold;
|
q31_t threshold = m_highThreshold;
|
||||||
if (previousCTCSSValid)
|
if (previousState)
|
||||||
threshold = m_lowThreshold;
|
threshold = m_lowThreshold;
|
||||||
|
|
||||||
m_result |= CTS_READY;
|
m_state = value >= threshold;
|
||||||
if (value >= threshold)
|
|
||||||
m_result |= CTS_VALID;
|
|
||||||
else
|
|
||||||
m_result &= ~CTS_VALID;
|
|
||||||
|
|
||||||
if (previousCTCSSValid != CTCSS_VALID(m_result))
|
if (previousState != m_state)
|
||||||
DEBUG4("CTCSS Value / Threshold / Valid", value, threshold, CTCSS_VALID(m_result));
|
DEBUG4("CTCSS Value / Threshold / Valid", value, threshold, m_state);
|
||||||
|
|
||||||
m_count = 0U;
|
m_count = 0U;
|
||||||
m_q0 = 0;
|
m_q0 = 0;
|
||||||
m_q1 = 0;
|
m_q1 = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_result;
|
return m_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFMCTCSSRX::reset()
|
void CFMCTCSSRX::reset()
|
||||||
{
|
{
|
||||||
m_q0 = 0;
|
m_q0 = 0;
|
||||||
m_q1 = 0;
|
m_q1 = 0;
|
||||||
m_result = CTS_NONE;
|
m_state = false;
|
||||||
m_count = 0U;
|
m_count = 0U;
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-11
@@ -21,22 +21,13 @@
|
|||||||
|
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
|
||||||
const uint8_t CTS_NONE = 0U;
|
|
||||||
const uint8_t CTS_READY = 1U;
|
|
||||||
const uint8_t CTS_VALID = 2U;
|
|
||||||
|
|
||||||
#define CTCSS_READY(a) ((a & CTS_READY) != 0)
|
|
||||||
#define CTCSS_NOT_READY(a) ((a & CTS_READY) == 0)
|
|
||||||
#define CTCSS_VALID(a) ((a & CTS_VALID) != 0)
|
|
||||||
#define CTCSS_NOT_VALID(a) ((a & CTS_VALID) == 0)
|
|
||||||
|
|
||||||
class CFMCTCSSRX {
|
class CFMCTCSSRX {
|
||||||
public:
|
public:
|
||||||
CFMCTCSSRX();
|
CFMCTCSSRX();
|
||||||
|
|
||||||
uint8_t setParams(uint8_t frequency, uint8_t highThreshold, uint8_t lowThreshold);
|
uint8_t setParams(uint8_t frequency, uint8_t highThreshold, uint8_t lowThreshold);
|
||||||
|
|
||||||
uint8_t process(q15_t sample);
|
bool process(q15_t sample);
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
@@ -47,7 +38,7 @@ private:
|
|||||||
uint16_t m_count;
|
uint16_t m_count;
|
||||||
q31_t m_q0;
|
q31_t m_q0;
|
||||||
q31_t m_q1;
|
q31_t m_q1;
|
||||||
uint8_t m_result;
|
bool m_state;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+1
-1
@@ -29,7 +29,7 @@ THE SOFTWARE.
|
|||||||
|
|
||||||
// based on https://raw.githubusercontent.com/berndporr/iir_fixed_point/master/DirectFormI.h
|
// based on https://raw.githubusercontent.com/berndporr/iir_fixed_point/master/DirectFormI.h
|
||||||
|
|
||||||
#include "Globals.h"
|
#include <cstdint>
|
||||||
|
|
||||||
#ifndef DIRECTFORMI_H_
|
#ifndef DIRECTFORMI_H_
|
||||||
#define DIRECTFORMI_H_
|
#define DIRECTFORMI_H_
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 by Jonathan Naylor G4KLX
|
||||||
|
* Copyright (C) 2020 by Geoffrey Merck F4FXL - KC3FRA
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Config.h"
|
||||||
|
#include "FMDownSampler.h"
|
||||||
|
|
||||||
|
CFMDownSampler::CFMDownSampler(uint16_t length) :
|
||||||
|
m_ringBuffer(length),
|
||||||
|
m_samplePack(0U),
|
||||||
|
m_samplePackPointer(NULL),
|
||||||
|
m_sampleIndex(0U)
|
||||||
|
{
|
||||||
|
m_samplePackPointer = (uint8_t*)&m_samplePack;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CFMDownSampler::addSample(q15_t sample)
|
||||||
|
{
|
||||||
|
uint32_t usample = uint32_t(int32_t(sample) + 2048);
|
||||||
|
//only take one of three samples
|
||||||
|
switch(m_sampleIndex){
|
||||||
|
case 0:
|
||||||
|
m_samplePack = usample << 12;
|
||||||
|
break;
|
||||||
|
case 3:{
|
||||||
|
m_samplePack |= usample;
|
||||||
|
|
||||||
|
//we did not use MSB; skip it
|
||||||
|
TSamplePairPack pair{m_samplePackPointer[0U], m_samplePackPointer[1U], m_samplePackPointer[2U]};
|
||||||
|
|
||||||
|
m_ringBuffer.put(pair);
|
||||||
|
|
||||||
|
m_samplePack = 0U;//reset the sample pack
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
//Just skip this sample
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_sampleIndex++;
|
||||||
|
if (m_sampleIndex >= 6U)//did we pack two samples ?
|
||||||
|
m_sampleIndex = 0U;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CFMDownSampler::getPackedData(TSamplePairPack& data)
|
||||||
|
{
|
||||||
|
return m_ringBuffer.get(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t CFMDownSampler::getData()
|
||||||
|
{
|
||||||
|
return m_ringBuffer.getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CFMDownSampler::reset()
|
||||||
|
{
|
||||||
|
m_sampleIndex = 0U;
|
||||||
|
}
|
||||||
@@ -21,23 +21,27 @@
|
|||||||
#define FMDOWNSAMPLER_H
|
#define FMDOWNSAMPLER_H
|
||||||
|
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "FMDownsampleRB.h"
|
#include "RingBuffer.h"
|
||||||
|
#include "FMSamplePairPack.h"
|
||||||
|
|
||||||
class CFMDownsampler {
|
class CFMDownSampler {
|
||||||
public:
|
public:
|
||||||
CFMDownsampler(uint16_t length);
|
CFMDownSampler(uint16_t length);
|
||||||
|
|
||||||
void addSample(q15_t sample);
|
void addSample(q15_t sample);
|
||||||
inline bool getPackedData(uint8_t& data){ return m_ringBuffer.get(data); };
|
|
||||||
inline bool hasOverflowed() { return m_ringBuffer.hasOverflowed(); };
|
bool getPackedData(TSamplePairPack& data);
|
||||||
|
|
||||||
|
uint16_t getData();
|
||||||
|
|
||||||
|
void reset();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CFMDownsampleRB m_ringBuffer;
|
CRingBuffer<TSamplePairPack> m_ringBuffer;
|
||||||
union {
|
uint32_t m_samplePack;
|
||||||
int32_t m_samplePack;
|
uint8_t* m_samplePackPointer;
|
||||||
int8_t m_samplePackBytes[4];
|
uint8_t m_sampleIndex;
|
||||||
};
|
|
||||||
uint8_t m_packIndex;
|
|
||||||
uint8_t m_downSampleIndex;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2020 by Jonathan Naylor G4KLX
|
|
||||||
* Copyright (C) 2020 by Geoffrey Merck F4FXL - KC3FRA
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "Config.h"
|
|
||||||
#include "FMDownsampler.h"
|
|
||||||
|
|
||||||
|
|
||||||
CFMDownsampler::CFMDownsampler(uint16_t length) :
|
|
||||||
m_ringBuffer(length),//length might need tweaking
|
|
||||||
m_packIndex(0),
|
|
||||||
m_downSampleIndex(0)
|
|
||||||
{
|
|
||||||
m_samplePack = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CFMDownsampler::addSample(q15_t sample)
|
|
||||||
{
|
|
||||||
//only take one of three samples
|
|
||||||
if(m_downSampleIndex == 0) {
|
|
||||||
switch(m_packIndex){
|
|
||||||
case 0:
|
|
||||||
m_samplePack = int32_t(sample) << 12;
|
|
||||||
break;
|
|
||||||
case 1:{
|
|
||||||
m_samplePack |= int32_t(sample);
|
|
||||||
|
|
||||||
//we did not use MSB; skip it
|
|
||||||
m_ringBuffer.put(m_samplePackBytes[1]);
|
|
||||||
m_ringBuffer.put(m_samplePackBytes[2]);
|
|
||||||
m_ringBuffer.put(m_samplePackBytes[3]);
|
|
||||||
|
|
||||||
m_samplePack = 0;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
//should never happen
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
m_packIndex++;
|
|
||||||
if(m_packIndex >= 2)
|
|
||||||
m_packIndex = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_downSampleIndex++;
|
|
||||||
if(m_downSampleIndex >= 3)
|
|
||||||
m_downSampleIndex = 0;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,127 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 by Jonathan Naylor G4KLX
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Config.h"
|
||||||
|
#include "Globals.h"
|
||||||
|
#include "FMNoiseSquelch.h"
|
||||||
|
|
||||||
|
// 4500Hz centre frequency
|
||||||
|
const q31_t COEFF_DIV_TWO = 821806413;
|
||||||
|
|
||||||
|
// 400Hz bandwidth
|
||||||
|
const uint16_t N = 24000U / 400U;
|
||||||
|
|
||||||
|
CFMNoiseSquelch::CFMNoiseSquelch() :
|
||||||
|
m_highThreshold(0),
|
||||||
|
m_lowThreshold(0),
|
||||||
|
m_count(0U),
|
||||||
|
m_q0(0),
|
||||||
|
m_q1(0),
|
||||||
|
m_state(false),
|
||||||
|
m_validCount(0U)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void CFMNoiseSquelch::setParams(uint8_t highThreshold, uint8_t lowThreshold)
|
||||||
|
{
|
||||||
|
m_highThreshold = q31_t(highThreshold);
|
||||||
|
m_lowThreshold = q31_t(lowThreshold);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CFMNoiseSquelch::process(q15_t sample)
|
||||||
|
{
|
||||||
|
//get more dynamic into the decoder by multiplying the sample by 64
|
||||||
|
q31_t sample31 = q31_t(sample) << 6; //+ (q31_t(sample) >> 1);
|
||||||
|
|
||||||
|
q31_t q2 = m_q1;
|
||||||
|
m_q1 = m_q0;
|
||||||
|
|
||||||
|
// Q31 multiplication, t3 = m_coeffDivTwo * 2 * m_q1
|
||||||
|
q63_t t1 = COEFF_DIV_TWO * m_q1;
|
||||||
|
q31_t t2 = __SSAT((t1 >> 31), 31);
|
||||||
|
q31_t t3 = t2 * 2;
|
||||||
|
|
||||||
|
// m_q0 = m_coeffDivTwo * m_q1 * 2 - q2 + sample
|
||||||
|
m_q0 = t3 - q2 + sample31;
|
||||||
|
|
||||||
|
m_count++;
|
||||||
|
if (m_count == N) {
|
||||||
|
// Q31 multiplication, t2 = m_q0 * m_q0
|
||||||
|
q63_t t1 = q63_t(m_q0) * q63_t(m_q0);
|
||||||
|
q31_t t2 = __SSAT((t1 >> 31), 31);
|
||||||
|
|
||||||
|
// Q31 multiplication, t4 = m_q0 * m_q0
|
||||||
|
q63_t t3 = q63_t(m_q1) * q63_t(m_q1);
|
||||||
|
q31_t t4 = __SSAT((t3 >> 31), 31);
|
||||||
|
|
||||||
|
// Q31 multiplication, t9 = m_q0 * m_q1 * m_coeffDivTwo * 2
|
||||||
|
q63_t t5 = q63_t(m_q0) * q63_t(m_q1);
|
||||||
|
q31_t t6 = __SSAT((t5 >> 31), 31);
|
||||||
|
q63_t t7 = t6 * COEFF_DIV_TWO;
|
||||||
|
q31_t t8 = __SSAT((t7 >> 31), 31);
|
||||||
|
q31_t t9 = t8 * 2;
|
||||||
|
|
||||||
|
// value = m_q0 * m_q0 + m_q1 * m_q1 - m_q0 * m_q1 * m_coeffDivTwo * 2
|
||||||
|
q31_t value = t2 + t4 - t9;
|
||||||
|
|
||||||
|
bool previousState = m_state;
|
||||||
|
|
||||||
|
q31_t threshold = m_highThreshold;
|
||||||
|
if (previousState)
|
||||||
|
threshold = m_lowThreshold;
|
||||||
|
|
||||||
|
if (!m_state) {
|
||||||
|
if (value < threshold)
|
||||||
|
m_validCount++;
|
||||||
|
else
|
||||||
|
m_validCount = 0U;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_state) {
|
||||||
|
if (value >= threshold)
|
||||||
|
m_invalidCount++;
|
||||||
|
else
|
||||||
|
m_invalidCount = 0U;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_state = m_validCount >= 10U && m_invalidCount < 10U;
|
||||||
|
|
||||||
|
if(previousState && !m_state)
|
||||||
|
m_invalidCount = 0U;
|
||||||
|
|
||||||
|
if (previousState != m_state) {
|
||||||
|
DEBUG4("Noise Squelch Value / Threshold / Valid", value, threshold, m_state);
|
||||||
|
DEBUG3("Valid Count / Invalid Count", m_validCount, m_invalidCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_count = 0U;
|
||||||
|
m_q0 = 0;
|
||||||
|
m_q1 = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_state;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CFMNoiseSquelch::reset()
|
||||||
|
{
|
||||||
|
m_q0 = 0;
|
||||||
|
m_q1 = 0;
|
||||||
|
m_state = false;
|
||||||
|
m_count = 0U;
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 by Jonathan Naylor G4KLX
|
||||||
|
*
|
||||||
|
* 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(FMNOISESQUELCH_H)
|
||||||
|
#define FMNOISESQUELCH_H
|
||||||
|
|
||||||
|
#include "Config.h"
|
||||||
|
|
||||||
|
class CFMNoiseSquelch {
|
||||||
|
public:
|
||||||
|
CFMNoiseSquelch();
|
||||||
|
|
||||||
|
void setParams(uint8_t highThreshold, uint8_t lowThreshold);
|
||||||
|
|
||||||
|
bool process(q15_t sample);
|
||||||
|
|
||||||
|
void reset();
|
||||||
|
|
||||||
|
private:
|
||||||
|
q31_t m_highThreshold;
|
||||||
|
q31_t m_lowThreshold;
|
||||||
|
uint16_t m_count;
|
||||||
|
q31_t m_q0;
|
||||||
|
q31_t m_q1;
|
||||||
|
bool m_state;
|
||||||
|
uint8_t m_validCount;
|
||||||
|
uint8_t m_invalidCount;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,110 +0,0 @@
|
|||||||
/*
|
|
||||||
TX fifo control - Copyright (C) KI6ZUM 2015
|
|
||||||
Copyright (C) 2015,2016,2020 by Jonathan Naylor G4KLX
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Library General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library 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
|
|
||||||
Library General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Library General Public
|
|
||||||
License along with this library; if not, write to the
|
|
||||||
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
||||||
Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "FMRB.h"
|
|
||||||
|
|
||||||
CFMRB::CFMRB(uint16_t length) :
|
|
||||||
m_length(length),
|
|
||||||
m_head(0U),
|
|
||||||
m_tail(0U),
|
|
||||||
m_full(false),
|
|
||||||
m_overflow(false)
|
|
||||||
{
|
|
||||||
m_samples = new q15_t[length];
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t CFMRB::getSpace() const
|
|
||||||
{
|
|
||||||
uint16_t n = 0U;
|
|
||||||
|
|
||||||
if (m_tail == m_head)
|
|
||||||
n = m_full ? 0U : m_length;
|
|
||||||
else if (m_tail < m_head)
|
|
||||||
n = m_length - m_head + m_tail;
|
|
||||||
else
|
|
||||||
n = m_tail - m_head;
|
|
||||||
|
|
||||||
if (n > m_length)
|
|
||||||
n = 0U;
|
|
||||||
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t CFMRB::getData() const
|
|
||||||
{
|
|
||||||
if (m_tail == m_head)
|
|
||||||
return m_full ? m_length : 0U;
|
|
||||||
else if (m_tail < m_head)
|
|
||||||
return m_head - m_tail;
|
|
||||||
else
|
|
||||||
return m_length - m_tail + m_head;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CFMRB::put(q15_t sample)
|
|
||||||
{
|
|
||||||
if (m_full) {
|
|
||||||
m_overflow = true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_samples[m_head] = sample;
|
|
||||||
|
|
||||||
m_head++;
|
|
||||||
if (m_head >= m_length)
|
|
||||||
m_head = 0U;
|
|
||||||
|
|
||||||
if (m_head == m_tail)
|
|
||||||
m_full = true;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CFMRB::get(q15_t& sample)
|
|
||||||
{
|
|
||||||
if (m_head == m_tail && !m_full)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
sample = m_samples[m_tail];
|
|
||||||
|
|
||||||
m_full = false;
|
|
||||||
|
|
||||||
m_tail++;
|
|
||||||
if (m_tail >= m_length)
|
|
||||||
m_tail = 0U;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CFMRB::hasOverflowed()
|
|
||||||
{
|
|
||||||
bool overflow = m_overflow;
|
|
||||||
|
|
||||||
m_overflow = false;
|
|
||||||
|
|
||||||
return overflow;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CFMRB::reset()
|
|
||||||
{
|
|
||||||
m_head = 0U;
|
|
||||||
m_tail = 0U;
|
|
||||||
m_full = false;
|
|
||||||
m_overflow = false;
|
|
||||||
}
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
/*
|
|
||||||
Serial fifo control - Copyright (C) KI6ZUM 2015
|
|
||||||
Copyright (C) 2015,2016,2020 by Jonathan Naylor G4KLX
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Library General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library 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
|
|
||||||
Library General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Library General Public
|
|
||||||
License along with this library; if not, write to the
|
|
||||||
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
||||||
Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if !defined(FMRB_H)
|
|
||||||
#define FMRB_H
|
|
||||||
|
|
||||||
#if defined(STM32F4XX)
|
|
||||||
#include "stm32f4xx.h"
|
|
||||||
#elif defined(STM32F7XX)
|
|
||||||
#include "stm32f7xx.h"
|
|
||||||
#elif defined(STM32F105xC)
|
|
||||||
#include "stm32f1xx.h"
|
|
||||||
#include <cstddef>
|
|
||||||
#else
|
|
||||||
#include <Arduino.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__SAM3X8E__) || defined(STM32F105xC)
|
|
||||||
#define ARM_MATH_CM3
|
|
||||||
#elif defined(STM32F7XX)
|
|
||||||
#define ARM_MATH_CM7
|
|
||||||
#elif defined(STM32F4XX) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__)
|
|
||||||
#define ARM_MATH_CM4
|
|
||||||
#else
|
|
||||||
#error "Unknown processor type"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <arm_math.h>
|
|
||||||
|
|
||||||
class CFMRB {
|
|
||||||
public:
|
|
||||||
CFMRB(uint16_t length);
|
|
||||||
|
|
||||||
uint16_t getSpace() const;
|
|
||||||
|
|
||||||
uint16_t getData() const;
|
|
||||||
|
|
||||||
bool put(q15_t sample);
|
|
||||||
|
|
||||||
bool get(q15_t& sample);
|
|
||||||
|
|
||||||
bool hasOverflowed();
|
|
||||||
|
|
||||||
void reset();
|
|
||||||
|
|
||||||
private:
|
|
||||||
uint16_t m_length;
|
|
||||||
volatile q15_t* m_samples;
|
|
||||||
volatile uint16_t m_head;
|
|
||||||
volatile uint16_t m_tail;
|
|
||||||
volatile bool m_full;
|
|
||||||
bool m_overflow;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 by Jonathan Naylor G4KLX
|
||||||
|
* Copyright (C) 2020 by Geoffrey Merck F4FXL - KC3FRA
|
||||||
|
*
|
||||||
|
* 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(TSAMPLEPACK_H)
|
||||||
|
#define TSAMPLEPACK_H
|
||||||
|
|
||||||
|
struct TSamplePairPack {
|
||||||
|
uint8_t byte0;
|
||||||
|
uint8_t byte1;
|
||||||
|
uint8_t byte2;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 by Jonathan Naylor G4KLX
|
||||||
|
* Copyright (C) 2020 by Geoffrey Merck F4FXL - KC3FRA
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "FMUpSampler.h"
|
||||||
|
|
||||||
|
const uint32_t FM_UPSAMPLE_MASK = 0x00000FFFU;
|
||||||
|
|
||||||
|
CFMUpSampler::CFMUpSampler() :
|
||||||
|
m_upSampleIndex(0),
|
||||||
|
m_pack(0U),
|
||||||
|
m_packPointer(NULL),
|
||||||
|
m_samples(3600U), //300ms of 12 bit 8kHz audio
|
||||||
|
m_running(false)
|
||||||
|
{
|
||||||
|
m_packPointer = (uint8_t*)&m_pack;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CFMUpSampler::reset()
|
||||||
|
{
|
||||||
|
m_upSampleIndex = 0U;
|
||||||
|
m_pack = 0U;
|
||||||
|
m_samples.reset();
|
||||||
|
m_running = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CFMUpSampler::addData(const uint8_t* data, uint16_t length)
|
||||||
|
{
|
||||||
|
TSamplePairPack* packPointer = (TSamplePairPack*)data;
|
||||||
|
TSamplePairPack* packPointerEnd = packPointer + (length / 3U);
|
||||||
|
while(packPointer != packPointerEnd) {
|
||||||
|
m_samples.put(*packPointer);
|
||||||
|
packPointer++;
|
||||||
|
}
|
||||||
|
if(!m_running)
|
||||||
|
m_running = m_samples.getData() > 300U;//75ms of audio
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CFMUpSampler::getSample(q15_t& sample)
|
||||||
|
{
|
||||||
|
if(!m_running)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
switch (m_upSampleIndex)
|
||||||
|
{
|
||||||
|
case 0: {
|
||||||
|
TSamplePairPack pairPack;
|
||||||
|
if(!m_samples.get(pairPack)) {
|
||||||
|
m_running = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_pack = 0U;
|
||||||
|
m_packPointer = (uint8_t*)&m_pack;
|
||||||
|
|
||||||
|
m_packPointer[0U] = pairPack.byte0;
|
||||||
|
m_packPointer[1U] = pairPack.byte1;
|
||||||
|
m_packPointer[2U] = pairPack.byte2;
|
||||||
|
|
||||||
|
sample = q15_t(m_pack >> 12) - 2048;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 3:
|
||||||
|
sample = q15_t(m_pack & FM_UPSAMPLE_MASK) - 2048;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
sample = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_upSampleIndex++;
|
||||||
|
if(m_upSampleIndex >= 6U)
|
||||||
|
m_upSampleIndex = 0U;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t CFMUpSampler::getSpace() const
|
||||||
|
{
|
||||||
|
//return available space in bytes
|
||||||
|
return m_samples.getSpace() * sizeof(TSamplePairPack);
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 by Jonathan Naylor G4KLX
|
||||||
|
* Copyright (C) 2020 by Geoffrey Merck F4FXL - KC3FRA
|
||||||
|
*
|
||||||
|
* 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(FMUPSAMPLER_H)
|
||||||
|
#define FMUPSAMPLER_H
|
||||||
|
|
||||||
|
#include "Config.h"
|
||||||
|
#include "RingBuffer.h"
|
||||||
|
#include "FMSamplePairPack.h"
|
||||||
|
|
||||||
|
class CFMUpSampler {
|
||||||
|
public:
|
||||||
|
CFMUpSampler();
|
||||||
|
|
||||||
|
void reset();
|
||||||
|
|
||||||
|
void addData(const uint8_t* data, uint16_t length);
|
||||||
|
|
||||||
|
bool getSample(q15_t& sample);
|
||||||
|
|
||||||
|
uint16_t getSpace() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint8_t m_upSampleIndex;
|
||||||
|
uint32_t m_pack;
|
||||||
|
uint8_t * m_packPointer;
|
||||||
|
CRingBuffer<TSamplePairPack> m_samples;
|
||||||
|
bool m_running;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -28,6 +28,7 @@
|
|||||||
#include "STM32Utils.h"
|
#include "STM32Utils.h"
|
||||||
#else
|
#else
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#undef PI //Undefine PI to get rid of annoying warning as it is also defined in arm_math.h.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__SAM3X8E__) || defined(STM32F105xC)
|
#if defined(__SAM3X8E__) || defined(STM32F105xC)
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ void CIO::selfTest()
|
|||||||
{
|
{
|
||||||
bool ledValue = false;
|
bool ledValue = false;
|
||||||
|
|
||||||
for (uint8_t i = 0; i < 6; i++) {
|
for (uint8_t i = 0U; i < 6U; i++) {
|
||||||
ledValue = !ledValue;
|
ledValue = !ledValue;
|
||||||
|
|
||||||
// We exclude PTT to avoid trigger the transmitter
|
// We exclude PTT to avoid trigger the transmitter
|
||||||
@@ -145,21 +145,34 @@ void CIO::selfTest()
|
|||||||
setDMRInt(ledValue);
|
setDMRInt(ledValue);
|
||||||
setYSFInt(ledValue);
|
setYSFInt(ledValue);
|
||||||
setP25Int(ledValue);
|
setP25Int(ledValue);
|
||||||
|
#if !defined(USE_ALTERNATE_NXDN_LEDS)
|
||||||
setNXDNInt(ledValue);
|
setNXDNInt(ledValue);
|
||||||
|
#endif
|
||||||
|
#if !defined(USE_ALTERNATE_POCSAG_LEDS)
|
||||||
setPOCSAGInt(ledValue);
|
setPOCSAGInt(ledValue);
|
||||||
|
#endif
|
||||||
|
#if !defined(USE_ALTERNATE_FM_LEDS)
|
||||||
setFMInt(ledValue);
|
setFMInt(ledValue);
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
delayInt(250);
|
delayInt(250);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(MODE_LEDS)
|
#if defined(MODE_LEDS)
|
||||||
setDStarInt(true);
|
setDStarInt(false);
|
||||||
setDMRInt(false);
|
setDMRInt(false);
|
||||||
setYSFInt(false);
|
setYSFInt(false);
|
||||||
setP25Int(false);
|
setP25Int(false);
|
||||||
|
#if !defined(USE_ALTERNATE_NXDN_LEDS)
|
||||||
setNXDNInt(false);
|
setNXDNInt(false);
|
||||||
|
#endif
|
||||||
|
#if !defined(USE_ALTERNATE_POCSAG_LEDS)
|
||||||
setPOCSAGInt(false);
|
setPOCSAGInt(false);
|
||||||
|
#endif
|
||||||
|
#if !defined(USE_ALTERNATE_FM_LEDS)
|
||||||
setFMInt(false);
|
setFMInt(false);
|
||||||
|
#endif
|
||||||
|
setDStarInt(true);
|
||||||
|
|
||||||
delayInt(250);
|
delayInt(250);
|
||||||
setDMRInt(true);
|
setDMRInt(true);
|
||||||
@@ -221,7 +234,7 @@ void CIO::start()
|
|||||||
|
|
||||||
m_started = true;
|
m_started = true;
|
||||||
|
|
||||||
setMode();
|
setMode(STATE_IDLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CIO::process()
|
void CIO::process()
|
||||||
@@ -233,8 +246,7 @@ void CIO::process()
|
|||||||
if (m_modemState == STATE_DSTAR || m_modemState == STATE_DMR || m_modemState == STATE_YSF || m_modemState == STATE_P25 || m_modemState == STATE_NXDN || m_modemState == STATE_POCSAG) {
|
if (m_modemState == STATE_DSTAR || m_modemState == STATE_DMR || m_modemState == STATE_YSF || m_modemState == STATE_P25 || m_modemState == STATE_NXDN || m_modemState == STATE_POCSAG) {
|
||||||
if (m_modemState == STATE_DMR && m_tx)
|
if (m_modemState == STATE_DMR && m_tx)
|
||||||
dmrTX.setStart(false);
|
dmrTX.setStart(false);
|
||||||
m_modemState = STATE_IDLE;
|
setMode(STATE_IDLE);
|
||||||
setMode();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_watchdog = 0U;
|
m_watchdog = 0U;
|
||||||
@@ -265,6 +277,7 @@ void CIO::process()
|
|||||||
if (m_txBuffer.getData() == 0U && m_tx) {
|
if (m_txBuffer.getData() == 0U && m_tx) {
|
||||||
m_tx = false;
|
m_tx = false;
|
||||||
setPTTInt(m_pttInvert ? true : false);
|
setPTTInt(m_pttInvert ? true : false);
|
||||||
|
DEBUG1("TX OFF");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_rxBuffer.getData() >= RX_BLOCK_SIZE) {
|
if (m_rxBuffer.getData() >= RX_BLOCK_SIZE) {
|
||||||
@@ -273,15 +286,16 @@ void CIO::process()
|
|||||||
uint16_t rssi[RX_BLOCK_SIZE];
|
uint16_t rssi[RX_BLOCK_SIZE];
|
||||||
|
|
||||||
for (uint16_t i = 0U; i < RX_BLOCK_SIZE; i++) {
|
for (uint16_t i = 0U; i < RX_BLOCK_SIZE; i++) {
|
||||||
uint16_t sample;
|
TSample sample;
|
||||||
m_rxBuffer.get(sample, control[i]);
|
m_rxBuffer.get(sample);
|
||||||
|
control[i] = sample.control;
|
||||||
m_rssiBuffer.get(rssi[i]);
|
m_rssiBuffer.get(rssi[i]);
|
||||||
|
|
||||||
// Detect ADC overflow
|
// Detect ADC overflow
|
||||||
if (m_detect && (sample == 0U || sample == 4095U))
|
if (m_detect && (sample.sample == 0U || sample.sample == 4095U))
|
||||||
m_adcOverflow++;
|
m_adcOverflow++;
|
||||||
|
|
||||||
q15_t res1 = q15_t(sample) - m_rxDCOffset;
|
q15_t res1 = q15_t(sample.sample) - m_rxDCOffset;
|
||||||
q31_t res2 = res1 * m_rxLevel;
|
q31_t res2 = res1 * m_rxLevel;
|
||||||
samples[i] = q15_t(__SSAT((res2 >> 15), 16));
|
samples[i] = q15_t(__SSAT((res2 >> 15), 16));
|
||||||
}
|
}
|
||||||
@@ -465,6 +479,7 @@ void CIO::write(MMDVM_STATE mode, q15_t* samples, uint16_t length, const uint8_t
|
|||||||
if (!m_tx) {
|
if (!m_tx) {
|
||||||
m_tx = true;
|
m_tx = true;
|
||||||
setPTTInt(m_pttInvert ? false : true);
|
setPTTInt(m_pttInvert ? false : true);
|
||||||
|
DEBUG1("TX ON");
|
||||||
}
|
}
|
||||||
|
|
||||||
q15_t txLevel = 0;
|
q15_t txLevel = 0;
|
||||||
@@ -508,9 +523,9 @@ void CIO::write(MMDVM_STATE mode, q15_t* samples, uint16_t length, const uint8_t
|
|||||||
m_dacOverflow++;
|
m_dacOverflow++;
|
||||||
|
|
||||||
if (control == NULL)
|
if (control == NULL)
|
||||||
m_txBuffer.put(res3, MARK_NONE);
|
m_txBuffer.put({res3, MARK_NONE});
|
||||||
else
|
else
|
||||||
m_txBuffer.put(res3, control[i]);
|
m_txBuffer.put({res3, control[i]});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -532,17 +547,34 @@ void CIO::setADCDetection(bool detect)
|
|||||||
m_detect = detect;
|
m_detect = detect;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CIO::setMode()
|
void CIO::setMode(MMDVM_STATE state)
|
||||||
{
|
{
|
||||||
|
if (state == m_modemState)
|
||||||
|
return;
|
||||||
|
|
||||||
#if defined(MODE_LEDS)
|
#if defined(MODE_LEDS)
|
||||||
setDStarInt(m_modemState == STATE_DSTAR);
|
switch (m_modemState) {
|
||||||
setDMRInt(m_modemState == STATE_DMR);
|
case STATE_DSTAR: setDStarInt(false); break;
|
||||||
setYSFInt(m_modemState == STATE_YSF);
|
case STATE_DMR: setDMRInt(false); break;
|
||||||
setP25Int(m_modemState == STATE_P25);
|
case STATE_YSF: setYSFInt(false); break;
|
||||||
setNXDNInt(m_modemState == STATE_NXDN);
|
case STATE_P25: setP25Int(false); break;
|
||||||
setPOCSAGInt(m_modemState == STATE_POCSAG);
|
case STATE_NXDN: setNXDNInt(false); break;
|
||||||
setFMInt(m_modemState == STATE_FM);
|
case STATE_POCSAG: setPOCSAGInt(false); break;
|
||||||
|
case STATE_FM: setFMInt(false); break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (state) {
|
||||||
|
case STATE_DSTAR: setDStarInt(true); break;
|
||||||
|
case STATE_DMR: setDMRInt(true); break;
|
||||||
|
case STATE_YSF: setYSFInt(true); break;
|
||||||
|
case STATE_P25: setP25Int(true); break;
|
||||||
|
case STATE_NXDN: setNXDNInt(true); break;
|
||||||
|
case STATE_POCSAG: setPOCSAGInt(true); break;
|
||||||
|
case STATE_FM: setFMInt(true); break;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
m_modemState = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CIO::setParameters(bool rxInvert, bool txInvert, bool pttInvert, uint8_t rxLevel, uint8_t cwIdTXLevel, uint8_t dstarTXLevel, uint8_t dmrTXLevel, uint8_t ysfTXLevel, uint8_t p25TXLevel, uint8_t nxdnTXLevel, uint8_t pocsagTXLevel, uint8_t fmTXLevel, uint8_t ax25TXLevel, int16_t txDCOffset, int16_t rxDCOffset, bool useCOSAsLockout)
|
void CIO::setParameters(bool rxInvert, bool txInvert, bool pttInvert, uint8_t rxLevel, uint8_t cwIdTXLevel, uint8_t dstarTXLevel, uint8_t dmrTXLevel, uint8_t ysfTXLevel, uint8_t p25TXLevel, uint8_t nxdnTXLevel, uint8_t pocsagTXLevel, uint8_t fmTXLevel, uint8_t ax25TXLevel, int16_t txDCOffset, int16_t rxDCOffset, bool useCOSAsLockout)
|
||||||
|
|||||||
@@ -21,8 +21,12 @@
|
|||||||
|
|
||||||
#include "Globals.h"
|
#include "Globals.h"
|
||||||
|
|
||||||
#include "SampleRB.h"
|
#include "RingBuffer.h"
|
||||||
#include "RSSIRB.h"
|
|
||||||
|
struct TSample {
|
||||||
|
volatile uint16_t sample;
|
||||||
|
volatile uint8_t control;
|
||||||
|
};
|
||||||
|
|
||||||
class CIO {
|
class CIO {
|
||||||
public:
|
public:
|
||||||
@@ -38,7 +42,7 @@ public:
|
|||||||
|
|
||||||
void setDecode(bool dcd);
|
void setDecode(bool dcd);
|
||||||
void setADCDetection(bool detect);
|
void setADCDetection(bool detect);
|
||||||
void setMode();
|
void setMode(MMDVM_STATE state);
|
||||||
|
|
||||||
void interrupt();
|
void interrupt();
|
||||||
|
|
||||||
@@ -59,9 +63,9 @@ public:
|
|||||||
private:
|
private:
|
||||||
bool m_started;
|
bool m_started;
|
||||||
|
|
||||||
CSampleRB m_rxBuffer;
|
CRingBuffer<TSample> m_rxBuffer;
|
||||||
CSampleRB m_txBuffer;
|
CRingBuffer<TSample> m_txBuffer;
|
||||||
CRSSIRB m_rssiBuffer;
|
CRingBuffer<uint16_t> m_rssiBuffer;
|
||||||
|
|
||||||
arm_biquad_casd_df1_inst_q31 m_dcFilter;
|
arm_biquad_casd_df1_inst_q31 m_dcFilter;
|
||||||
q31_t m_dcState[4];
|
q31_t m_dcState[4];
|
||||||
|
|||||||
@@ -185,14 +185,13 @@ void CIO::startInt()
|
|||||||
void CIO::interrupt()
|
void CIO::interrupt()
|
||||||
{
|
{
|
||||||
if ((ADC->ADC_ISR & ADC_ISR_EOC_Chan) == ADC_ISR_EOC_Chan) { // Ensure there was an End-of-Conversion and we read the ISR reg
|
if ((ADC->ADC_ISR & ADC_ISR_EOC_Chan) == ADC_ISR_EOC_Chan) { // Ensure there was an End-of-Conversion and we read the ISR reg
|
||||||
uint8_t control = MARK_NONE;
|
TSample sample = {DC_OFFSET, MARK_NONE};
|
||||||
uint16_t sample = DC_OFFSET;
|
|
||||||
|
|
||||||
m_txBuffer.get(sample, control);
|
m_txBuffer.get(sample);
|
||||||
DACC->DACC_CDR = sample;
|
DACC->DACC_CDR = sample.sample;
|
||||||
|
|
||||||
sample = ADC->ADC_CDR[ADC_CDR_Chan];
|
sample.sample = ADC->ADC_CDR[ADC_CDR_Chan];
|
||||||
m_rxBuffer.put(sample, control);
|
m_rxBuffer.put(sample);
|
||||||
|
|
||||||
#if defined(SEND_RSSI_DATA)
|
#if defined(SEND_RSSI_DATA)
|
||||||
m_rssiBuffer.put(ADC->ADC_CDR[RSSI_CDR_Chan]);
|
m_rssiBuffer.put(ADC->ADC_CDR[RSSI_CDR_Chan]);
|
||||||
|
|||||||
@@ -326,25 +326,24 @@ void CIO::startInt()
|
|||||||
|
|
||||||
void CIO::interrupt()
|
void CIO::interrupt()
|
||||||
{
|
{
|
||||||
uint8_t control = MARK_NONE;
|
TSample sample = {DC_OFFSET, MARK_NONE};
|
||||||
uint16_t sample = DC_OFFSET;
|
|
||||||
uint16_t rawRSSI = 0U;
|
uint16_t rawRSSI = 0U;
|
||||||
|
|
||||||
m_txBuffer.get(sample, control);
|
m_txBuffer.get(sample);
|
||||||
|
|
||||||
// Send the value to the DAC
|
// Send the value to the DAC
|
||||||
#if defined(STM32F4_NUCLEO) && defined(STM32F4_NUCLEO_ARDUINO_HEADER)
|
#if defined(STM32F4_NUCLEO) && defined(STM32F4_NUCLEO_ARDUINO_HEADER)
|
||||||
DAC_SetChannel2Data(DAC_Align_12b_R, sample);
|
DAC_SetChannel2Data(DAC_Align_12b_R, sample.sample);
|
||||||
#else
|
#else
|
||||||
DAC_SetChannel1Data(DAC_Align_12b_R, sample);
|
DAC_SetChannel1Data(DAC_Align_12b_R, sample.sample);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Read value from ADC1 and ADC2
|
// Read value from ADC1 and ADC2
|
||||||
if ((ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET)) {
|
if ((ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET)) {
|
||||||
// shouldn't be still in reset at this point so null the sample value?
|
// shouldn't be still in reset at this point so null the sample value?
|
||||||
sample = 0U;
|
sample.sample = 0U;
|
||||||
} else {
|
} else {
|
||||||
sample = ADC_GetConversionValue(ADC1);
|
sample.sample = ADC_GetConversionValue(ADC1);
|
||||||
#if defined(SEND_RSSI_DATA)
|
#if defined(SEND_RSSI_DATA)
|
||||||
rawRSSI = ADC_GetConversionValue(ADC2);
|
rawRSSI = ADC_GetConversionValue(ADC2);
|
||||||
#endif
|
#endif
|
||||||
@@ -354,7 +353,7 @@ void CIO::interrupt()
|
|||||||
ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
|
ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
|
||||||
ADC_SoftwareStartConv(ADC1);
|
ADC_SoftwareStartConv(ADC1);
|
||||||
|
|
||||||
m_rxBuffer.put(sample, control);
|
m_rxBuffer.put(sample);
|
||||||
m_rssiBuffer.put(rawRSSI);
|
m_rssiBuffer.put(rawRSSI);
|
||||||
|
|
||||||
m_watchdog++;
|
m_watchdog++;
|
||||||
|
|||||||
+5
-6
@@ -367,8 +367,7 @@ void CIO::startInt()
|
|||||||
|
|
||||||
void CIO::interrupt()
|
void CIO::interrupt()
|
||||||
{
|
{
|
||||||
uint8_t control = MARK_NONE;
|
TSample sample = {DC_OFFSET, MARK_NONE};
|
||||||
uint16_t sample = DC_OFFSET;
|
|
||||||
#if defined(SEND_RSSI_DATA)
|
#if defined(SEND_RSSI_DATA)
|
||||||
uint16_t rawRSSI = 0U;
|
uint16_t rawRSSI = 0U;
|
||||||
#endif
|
#endif
|
||||||
@@ -385,12 +384,12 @@ void CIO::interrupt()
|
|||||||
*rssi_adon = 1;
|
*rssi_adon = 1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_txBuffer.get(sample, control);
|
m_txBuffer.get(sample);
|
||||||
DAC->DHR12R1 = sample; // Send the value to the DAC
|
DAC->DHR12R1 = sample.sample; // Send the value to the DAC
|
||||||
|
|
||||||
// Read value from ADC1 and ADC2
|
// Read value from ADC1 and ADC2
|
||||||
sample = ADC1->DR; // read conversion result; EOC is cleared by this read
|
sample.sample = ADC1->DR; // read conversion result; EOC is cleared by this read
|
||||||
m_rxBuffer.put(sample, control);
|
m_rxBuffer.put(sample);
|
||||||
#if defined(SEND_RSSI_DATA)
|
#if defined(SEND_RSSI_DATA)
|
||||||
rawRSSI = ADC2->DR;
|
rawRSSI = ADC2->DR;
|
||||||
m_rssiBuffer.put(rawRSSI);
|
m_rssiBuffer.put(rawRSSI);
|
||||||
|
|||||||
+5
-6
@@ -161,15 +161,14 @@ void CIO::startInt()
|
|||||||
|
|
||||||
void CIO::interrupt()
|
void CIO::interrupt()
|
||||||
{
|
{
|
||||||
uint8_t control = MARK_NONE;
|
TSample sample = {DC_OFFSET, MARK_NONE};
|
||||||
uint16_t sample = DC_OFFSET;
|
|
||||||
|
|
||||||
m_txBuffer.get(sample, control);
|
m_txBuffer.get(sample);
|
||||||
*(int16_t *)&(DAC0_DAT0L) = sample;
|
*(int16_t *)&(DAC0_DAT0L) = sample.sample;
|
||||||
|
|
||||||
if ((ADC0_SC1A & ADC_SC1_COCO) == ADC_SC1_COCO) {
|
if ((ADC0_SC1A & ADC_SC1_COCO) == ADC_SC1_COCO) {
|
||||||
sample = ADC0_RA;
|
sample.sample = ADC0_RA;
|
||||||
m_rxBuffer.put(sample, control);
|
m_rxBuffer.put(sample);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(SEND_RSSI_DATA)
|
#if defined(SEND_RSSI_DATA)
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ CPOCSAGTX pocsagTX;
|
|||||||
|
|
||||||
CFM fm;
|
CFM fm;
|
||||||
CAX25RX ax25RX;
|
CAX25RX ax25RX;
|
||||||
CAX25 ax25TX;
|
CAX25TX ax25TX;
|
||||||
|
|
||||||
CCalDStarRX calDStarRX;
|
CCalDStarRX calDStarRX;
|
||||||
CCalDStarTX calDStarTX;
|
CCalDStarTX calDStarTX;
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/make
|
#!/usr/bin/make
|
||||||
# makefile for the arduino due (works with arduino IDE 1.6.11)
|
# makefile for the arduino due (works with arduino IDE 1.6.12)
|
||||||
#
|
#
|
||||||
# The original file can be found at https://github.com/pauldreik/arduino-due-makefile
|
# The original file can be found at https://github.com/pauldreik/arduino-due-makefile
|
||||||
#
|
#
|
||||||
@@ -34,7 +34,7 @@ OBJCOPY:=$(ADIR)/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-n
|
|||||||
|
|
||||||
C:=$(CC)
|
C:=$(CC)
|
||||||
#SAM:=arduino/sam/
|
#SAM:=arduino/sam/
|
||||||
SAM:=$(ADIR)/packages/arduino/hardware/sam/1.6.11
|
SAM:=$(ADIR)/packages/arduino/hardware/sam/1.6.12
|
||||||
#CMSIS:=arduino/sam/system/CMSIS/
|
#CMSIS:=arduino/sam/system/CMSIS/
|
||||||
#LIBSAM:=arduino/sam/system/libsam
|
#LIBSAM:=arduino/sam/system/libsam
|
||||||
TMPDIR:=$(PWD)/build
|
TMPDIR:=$(PWD)/build
|
||||||
|
|||||||
+2
-1
@@ -81,7 +81,8 @@ void CNXDNTX::process()
|
|||||||
m_poBuffer[m_poLen++] = NXDN_PREAMBLE[2U];
|
m_poBuffer[m_poLen++] = NXDN_PREAMBLE[2U];
|
||||||
} else {
|
} else {
|
||||||
for (uint8_t i = 0U; i < NXDN_FRAME_LENGTH_BYTES; i++) {
|
for (uint8_t i = 0U; i < NXDN_FRAME_LENGTH_BYTES; i++) {
|
||||||
uint8_t c = m_buffer.get();
|
uint8_t c = 0U;
|
||||||
|
m_buffer.get(c);
|
||||||
m_poBuffer[m_poLen++] = c;
|
m_poBuffer[m_poLen++] = c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
|
||||||
#include "SerialRB.h"
|
#include "RingBuffer.h"
|
||||||
|
|
||||||
class CNXDNTX {
|
class CNXDNTX {
|
||||||
public:
|
public:
|
||||||
@@ -38,7 +38,7 @@ public:
|
|||||||
void setParams(uint8_t txHang);
|
void setParams(uint8_t txHang);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CSerialRB m_buffer;
|
CRingBuffer<uint8_t> m_buffer;
|
||||||
arm_fir_interpolate_instance_q15 m_modFilter;
|
arm_fir_interpolate_instance_q15 m_modFilter;
|
||||||
arm_fir_instance_q15 m_sincFilter;
|
arm_fir_instance_q15 m_sincFilter;
|
||||||
q15_t m_modState[16U]; // blockSize + phaseLength - 1, 4 + 9 - 1 plus some spare
|
q15_t m_modState[16U]; // blockSize + phaseLength - 1, 4 + 9 - 1 plus some spare
|
||||||
|
|||||||
@@ -75,9 +75,11 @@ void CP25TX::process()
|
|||||||
for (uint16_t i = 0U; i < m_txDelay; i++)
|
for (uint16_t i = 0U; i < m_txDelay; i++)
|
||||||
m_poBuffer[m_poLen++] = P25_START_SYNC;
|
m_poBuffer[m_poLen++] = P25_START_SYNC;
|
||||||
} else {
|
} else {
|
||||||
uint8_t length = m_buffer.get();
|
uint8_t length;
|
||||||
|
m_buffer.get(length);
|
||||||
for (uint8_t i = 0U; i < length; i++) {
|
for (uint8_t i = 0U; i < length; i++) {
|
||||||
uint8_t c = m_buffer.get();
|
uint8_t c = 0U;
|
||||||
|
m_buffer.get(c);
|
||||||
m_poBuffer[m_poLen++] = c;
|
m_poBuffer[m_poLen++] = c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
|
||||||
#include "SerialRB.h"
|
#include "RingBuffer.h"
|
||||||
|
|
||||||
class CP25TX {
|
class CP25TX {
|
||||||
public:
|
public:
|
||||||
@@ -38,7 +38,7 @@ public:
|
|||||||
void setParams(uint8_t txHang);
|
void setParams(uint8_t txHang);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CSerialRB m_buffer;
|
CRingBuffer<uint8_t> m_buffer;
|
||||||
arm_fir_interpolate_instance_q15 m_modFilter;
|
arm_fir_interpolate_instance_q15 m_modFilter;
|
||||||
arm_fir_instance_q15 m_lpFilter;
|
arm_fir_instance_q15 m_lpFilter;
|
||||||
q15_t m_modState[16U]; // blockSize + phaseLength - 1, 4 + 9 - 1 plus some spare
|
q15_t m_modState[16U]; // blockSize + phaseLength - 1, 4 + 9 - 1 plus some spare
|
||||||
|
|||||||
+2
-2
@@ -61,7 +61,8 @@ void CPOCSAGTX::process()
|
|||||||
m_poBuffer[m_poLen++] = POCSAG_SYNC;
|
m_poBuffer[m_poLen++] = POCSAG_SYNC;
|
||||||
} else {
|
} else {
|
||||||
for (uint8_t i = 0U; i < POCSAG_FRAME_LENGTH_BYTES; i++) {
|
for (uint8_t i = 0U; i < POCSAG_FRAME_LENGTH_BYTES; i++) {
|
||||||
uint8_t c = m_buffer.get();
|
uint8_t c = 0U;
|
||||||
|
m_buffer.get(c);
|
||||||
m_poBuffer[m_poLen++] = c;
|
m_poBuffer[m_poLen++] = c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -146,4 +147,3 @@ uint8_t CPOCSAGTX::getSpace() const
|
|||||||
{
|
{
|
||||||
return m_buffer.getSpace() / POCSAG_FRAME_LENGTH_BYTES;
|
return m_buffer.getSpace() / POCSAG_FRAME_LENGTH_BYTES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
|
||||||
#include "SerialRB.h"
|
#include "RingBuffer.h"
|
||||||
|
|
||||||
class CPOCSAGTX {
|
class CPOCSAGTX {
|
||||||
public:
|
public:
|
||||||
@@ -40,7 +40,7 @@ public:
|
|||||||
bool busy();
|
bool busy();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CSerialRB m_buffer;
|
CRingBuffer<uint8_t> m_buffer;
|
||||||
arm_fir_instance_q15 m_modFilter;
|
arm_fir_instance_q15 m_modFilter;
|
||||||
q15_t m_modState[170U]; // NoTaps + BlockSize - 1, 6 + 160 - 1 plus some spare
|
q15_t m_modState[170U]; // NoTaps + BlockSize - 1, 6 + 160 - 1 plus some spare
|
||||||
uint8_t m_poBuffer[200U];
|
uint8_t m_poBuffer[200U];
|
||||||
|
|||||||
-102
@@ -1,102 +0,0 @@
|
|||||||
/*
|
|
||||||
TX fifo control - Copyright (C) KI6ZUM 2015
|
|
||||||
Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Library General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library 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
|
|
||||||
Library General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Library General Public
|
|
||||||
License along with this library; if not, write to the
|
|
||||||
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
||||||
Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "RSSIRB.h"
|
|
||||||
|
|
||||||
CRSSIRB::CRSSIRB(uint16_t length) :
|
|
||||||
m_length(length),
|
|
||||||
m_head(0U),
|
|
||||||
m_tail(0U),
|
|
||||||
m_full(false),
|
|
||||||
m_overflow(false)
|
|
||||||
{
|
|
||||||
m_rssi = new uint16_t[length];
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t CRSSIRB::getSpace() const
|
|
||||||
{
|
|
||||||
uint16_t n = 0U;
|
|
||||||
|
|
||||||
if (m_tail == m_head)
|
|
||||||
n = m_full ? 0U : m_length;
|
|
||||||
else if (m_tail < m_head)
|
|
||||||
n = m_length - m_head + m_tail;
|
|
||||||
else
|
|
||||||
n = m_tail - m_head;
|
|
||||||
|
|
||||||
if (n > m_length)
|
|
||||||
n = 0U;
|
|
||||||
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t CRSSIRB::getData() const
|
|
||||||
{
|
|
||||||
if (m_tail == m_head)
|
|
||||||
return m_full ? m_length : 0U;
|
|
||||||
else if (m_tail < m_head)
|
|
||||||
return m_head - m_tail;
|
|
||||||
else
|
|
||||||
return m_length - m_tail + m_head;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CRSSIRB::put(uint16_t rssi)
|
|
||||||
{
|
|
||||||
if (m_full) {
|
|
||||||
m_overflow = true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_rssi[m_head] = rssi;
|
|
||||||
|
|
||||||
m_head++;
|
|
||||||
if (m_head >= m_length)
|
|
||||||
m_head = 0U;
|
|
||||||
|
|
||||||
if (m_head == m_tail)
|
|
||||||
m_full = true;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CRSSIRB::get(uint16_t& rssi)
|
|
||||||
{
|
|
||||||
if (m_head == m_tail && !m_full)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
rssi = m_rssi[m_tail];
|
|
||||||
|
|
||||||
m_full = false;
|
|
||||||
|
|
||||||
m_tail++;
|
|
||||||
if (m_tail >= m_length)
|
|
||||||
m_tail = 0U;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CRSSIRB::hasOverflowed()
|
|
||||||
{
|
|
||||||
bool overflow = m_overflow;
|
|
||||||
|
|
||||||
m_overflow = false;
|
|
||||||
|
|
||||||
return overflow;
|
|
||||||
}
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
/*
|
|
||||||
Serial fifo control - Copyright (C) KI6ZUM 2015
|
|
||||||
Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Library General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library 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
|
|
||||||
Library General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Library General Public
|
|
||||||
License along with this library; if not, write to the
|
|
||||||
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
||||||
Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if !defined(RSSIRB_H)
|
|
||||||
#define RSSIRB_H
|
|
||||||
|
|
||||||
#if defined(STM32F4XX)
|
|
||||||
#include "stm32f4xx.h"
|
|
||||||
#elif defined(STM32F7XX)
|
|
||||||
#include "stm32f7xx.h"
|
|
||||||
#elif defined(STM32F105xC)
|
|
||||||
#include "stm32f1xx.h"
|
|
||||||
#include <cstddef>
|
|
||||||
#else
|
|
||||||
#include <Arduino.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class CRSSIRB {
|
|
||||||
public:
|
|
||||||
CRSSIRB(uint16_t length);
|
|
||||||
|
|
||||||
uint16_t getSpace() const;
|
|
||||||
|
|
||||||
uint16_t getData() const;
|
|
||||||
|
|
||||||
bool put(uint16_t rssi);
|
|
||||||
|
|
||||||
bool get(uint16_t& rssi);
|
|
||||||
|
|
||||||
bool hasOverflowed();
|
|
||||||
|
|
||||||
private:
|
|
||||||
uint16_t m_length;
|
|
||||||
volatile uint16_t* m_rssi;
|
|
||||||
volatile uint16_t m_head;
|
|
||||||
volatile uint16_t m_tail;
|
|
||||||
volatile bool m_full;
|
|
||||||
bool m_overflow;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2020 by Jonathan Naylor G4KLX
|
* Copyright (C) 2020 by Jonathan Naylor G4KLX
|
||||||
|
* Copyright (C) 2020 by Geoffrey Merck F4FXL - KC3FRA
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -16,8 +17,8 @@
|
|||||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if !defined(FMDOWNSAMPLERB_H)
|
#if !defined(RINGBUFFER_H)
|
||||||
#define FMDOWNSAMPLERB_H
|
#define RINGBUFFER_H
|
||||||
|
|
||||||
#if defined(STM32F4XX)
|
#if defined(STM32F4XX)
|
||||||
#include "stm32f4xx.h"
|
#include "stm32f4xx.h"
|
||||||
@@ -28,6 +29,7 @@
|
|||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#else
|
#else
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#undef PI
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__SAM3X8E__) || defined(STM32F105xC)
|
#if defined(__SAM3X8E__) || defined(STM32F105xC)
|
||||||
@@ -42,27 +44,34 @@
|
|||||||
|
|
||||||
#include <arm_math.h>
|
#include <arm_math.h>
|
||||||
|
|
||||||
class CFMDownsampleRB {
|
template <typename TDATATYPE>
|
||||||
|
class CRingBuffer {
|
||||||
public:
|
public:
|
||||||
CFMDownsampleRB(uint16_t length);
|
CRingBuffer(uint16_t length = 370U);
|
||||||
|
|
||||||
uint16_t getSpace() const;
|
uint16_t getSpace() const;
|
||||||
|
|
||||||
uint16_t getData() const;
|
uint16_t getData() const;
|
||||||
|
|
||||||
bool put(uint8_t sample);
|
bool put(TDATATYPE item) volatile;
|
||||||
|
|
||||||
bool get(uint8_t& sample);
|
bool get(TDATATYPE& item) volatile;
|
||||||
|
|
||||||
|
TDATATYPE peek() const;
|
||||||
|
|
||||||
bool hasOverflowed();
|
bool hasOverflowed();
|
||||||
|
|
||||||
|
void reset();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint16_t m_length;
|
uint16_t m_length;
|
||||||
volatile uint8_t* m_samples;
|
TDATATYPE* m_buffer;
|
||||||
volatile uint16_t m_head;
|
volatile uint16_t m_head;
|
||||||
volatile uint16_t m_tail;
|
volatile uint16_t m_tail;
|
||||||
volatile bool m_full;
|
volatile bool m_full;
|
||||||
bool m_overflow;
|
bool m_overflow;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#include "RingBuffer.impl.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2020 by Jonathan Naylor G4KLX
|
* Copyright (C) 2020 by Jonathan Naylor G4KLX
|
||||||
|
* Copyright (C) 2020 by Geoffrey Merck F4FXL - KC3FRA
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -16,20 +17,19 @@
|
|||||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "RingBuffer.h"
|
||||||
|
|
||||||
#include "FMDownsampleRB.h"
|
template <typename TDATATYPE> CRingBuffer<TDATATYPE>::CRingBuffer(uint16_t length) :
|
||||||
|
|
||||||
CFMDownsampleRB::CFMDownsampleRB(uint16_t length) :
|
|
||||||
m_length(length),
|
m_length(length),
|
||||||
m_head(0U),
|
m_head(0U),
|
||||||
m_tail(0U),
|
m_tail(0U),
|
||||||
m_full(false),
|
m_full(false),
|
||||||
m_overflow(false)
|
m_overflow(false)
|
||||||
{
|
{
|
||||||
m_samples = new uint8_t[length];
|
m_buffer = new TDATATYPE[length];
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t CFMDownsampleRB::getSpace() const
|
template <typename TDATATYPE> uint16_t CRingBuffer<TDATATYPE>::getSpace() const
|
||||||
{
|
{
|
||||||
uint16_t n = 0U;
|
uint16_t n = 0U;
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ uint16_t CFMDownsampleRB::getSpace() const
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t CFMDownsampleRB::getData() const
|
template <typename TDATATYPE> uint16_t CRingBuffer<TDATATYPE>::getData() const
|
||||||
{
|
{
|
||||||
if (m_tail == m_head)
|
if (m_tail == m_head)
|
||||||
return m_full ? m_length : 0U;
|
return m_full ? m_length : 0U;
|
||||||
@@ -56,14 +56,14 @@ uint16_t CFMDownsampleRB::getData() const
|
|||||||
return m_length - m_tail + m_head;
|
return m_length - m_tail + m_head;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CFMDownsampleRB::put(uint8_t sample)
|
template <typename TDATATYPE> bool CRingBuffer<TDATATYPE>::put(TDATATYPE item) volatile
|
||||||
{
|
{
|
||||||
if (m_full) {
|
if (m_full) {
|
||||||
m_overflow = true;
|
m_overflow = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_samples[m_head] = sample;
|
m_buffer[m_head] = item;
|
||||||
|
|
||||||
m_head++;
|
m_head++;
|
||||||
if (m_head >= m_length)
|
if (m_head >= m_length)
|
||||||
@@ -75,12 +75,17 @@ bool CFMDownsampleRB::put(uint8_t sample)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CFMDownsampleRB::get(uint8_t& sample)
|
template <typename TDATATYPE> TDATATYPE CRingBuffer<TDATATYPE>::peek() const
|
||||||
|
{
|
||||||
|
return m_buffer[m_tail];
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename TDATATYPE> bool CRingBuffer<TDATATYPE>::get(TDATATYPE& item) volatile
|
||||||
{
|
{
|
||||||
if (m_head == m_tail && !m_full)
|
if (m_head == m_tail && !m_full)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
sample = m_samples[m_tail];
|
item = m_buffer[m_tail];
|
||||||
|
|
||||||
m_full = false;
|
m_full = false;
|
||||||
|
|
||||||
@@ -91,7 +96,7 @@ bool CFMDownsampleRB::get(uint8_t& sample)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CFMDownsampleRB::hasOverflowed()
|
template <typename TDATATYPE> bool CRingBuffer<TDATATYPE>::hasOverflowed()
|
||||||
{
|
{
|
||||||
bool overflow = m_overflow;
|
bool overflow = m_overflow;
|
||||||
|
|
||||||
@@ -99,3 +104,11 @@ bool CFMDownsampleRB::hasOverflowed()
|
|||||||
|
|
||||||
return overflow;
|
return overflow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename TDATATYPE> void CRingBuffer<TDATATYPE>::reset()
|
||||||
|
{
|
||||||
|
m_head = 0U;
|
||||||
|
m_tail = 0U;
|
||||||
|
m_full = false;
|
||||||
|
m_overflow = false;
|
||||||
|
}
|
||||||
+100
@@ -0,0 +1,100 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020 by Jonathan Naylor G4KLX
|
||||||
|
* Copyright (c) 2020 by Geoffrey Merck F4FXL - KC3FRA
|
||||||
|
*
|
||||||
|
* 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(STM32F4XX) || defined(STM32F7XX)
|
||||||
|
|
||||||
|
#include "STMUART.h"
|
||||||
|
|
||||||
|
CSTMUART::CSTMUART() :
|
||||||
|
m_usart(NULL)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSTMUART::init(USART_TypeDef* usart)
|
||||||
|
{
|
||||||
|
m_usart = usart;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSTMUART::write(const uint8_t * data, uint16_t length)
|
||||||
|
{
|
||||||
|
if(length == 0U || m_usart == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
|
||||||
|
m_txFifo.put(data[0]);
|
||||||
|
USART_ITConfig(m_usart, USART_IT_TXE, ENABLE);//switch TX IRQ is on
|
||||||
|
|
||||||
|
for(uint16_t i = 1U; i < length; i++) {
|
||||||
|
m_txFifo.put(data[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
USART_ITConfig(m_usart, USART_IT_TXE, ENABLE);//make sure TX IRQ is on
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t CSTMUART::read()
|
||||||
|
{
|
||||||
|
return m_rxFifo.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSTMUART::handleIRQ()
|
||||||
|
{
|
||||||
|
if(m_usart == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (USART_GetITStatus(m_usart, USART_IT_RXNE)) {
|
||||||
|
if(!m_rxFifo.isFull())
|
||||||
|
m_rxFifo.put((uint8_t) USART_ReceiveData(m_usart));
|
||||||
|
USART_ClearITPendingBit(USART1, USART_IT_RXNE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (USART_GetITStatus(m_usart, USART_IT_TXE)) {
|
||||||
|
if(!m_txFifo.isEmpty())
|
||||||
|
USART_SendData(m_usart, m_txFifo.get());
|
||||||
|
|
||||||
|
USART_ClearITPendingBit(m_usart, USART_IT_TXE);
|
||||||
|
|
||||||
|
if (m_txFifo.isEmpty()) // if there's no more data to transmit then turn off TX interrupts
|
||||||
|
USART_ITConfig(m_usart, USART_IT_TXE, DISABLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Flushes the transmit shift register
|
||||||
|
// warning: this call is blocking
|
||||||
|
void CSTMUART::flush()
|
||||||
|
{
|
||||||
|
if(m_usart == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// wait until the TXE shows the shift register is empty
|
||||||
|
while (USART_GetITStatus(m_usart, USART_FLAG_TXE))
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t CSTMUART::available()
|
||||||
|
{
|
||||||
|
return m_rxFifo.isEmpty() ? 0U : 1U;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t CSTMUART::availableForWrite()
|
||||||
|
{
|
||||||
|
return m_txFifo.isFull() ? 0U : 1U;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020 by Jonathan Naylor G4KLX
|
||||||
|
* Copyright (c) 2020 by Geoffrey Merck F4FXL - KC3FRA
|
||||||
|
*
|
||||||
|
* 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(STM32F4XX) || defined(STM32F7XX)
|
||||||
|
#if !defined(STMUART_H)
|
||||||
|
#define STMUART_H
|
||||||
|
|
||||||
|
#if defined(STM32F4XX)
|
||||||
|
#include "stm32f4xx.h"
|
||||||
|
#elif defined(STM32F7XX)
|
||||||
|
#include "stm32f7xx.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const uint16_t BUFFER_SIZE = 2048U; //needs to be a power of 2 !
|
||||||
|
const uint16_t BUFFER_MASK = BUFFER_SIZE - 1;
|
||||||
|
|
||||||
|
class CSTMUARTFIFO {
|
||||||
|
public:
|
||||||
|
CSTMUARTFIFO() :
|
||||||
|
m_head(0U),
|
||||||
|
m_tail(0U)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void put(uint8_t data)
|
||||||
|
{
|
||||||
|
m_buffer[BUFFER_MASK & (m_head++)] = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t get()
|
||||||
|
{
|
||||||
|
return m_buffer[BUFFER_MASK & (m_tail++)];
|
||||||
|
}
|
||||||
|
|
||||||
|
void reset()
|
||||||
|
{
|
||||||
|
m_tail = 0U;
|
||||||
|
m_head = 0U;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isEmpty()
|
||||||
|
{
|
||||||
|
return m_tail == m_head;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isFull()
|
||||||
|
{
|
||||||
|
return ((m_head + 1U) & BUFFER_MASK) == (m_tail & BUFFER_MASK);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
volatile uint8_t m_buffer[BUFFER_SIZE];
|
||||||
|
volatile uint16_t m_head;
|
||||||
|
volatile uint16_t m_tail;
|
||||||
|
};
|
||||||
|
|
||||||
|
class CSTMUART {
|
||||||
|
public:
|
||||||
|
CSTMUART();
|
||||||
|
void init(USART_TypeDef* usart);
|
||||||
|
void write(const uint8_t * data, uint16_t length);
|
||||||
|
uint8_t read();
|
||||||
|
void handleIRQ();
|
||||||
|
void flush();
|
||||||
|
uint16_t available();
|
||||||
|
uint16_t availableForWrite();
|
||||||
|
|
||||||
|
private:
|
||||||
|
USART_TypeDef * m_usart;
|
||||||
|
CSTMUARTFIFO m_rxFifo;
|
||||||
|
CSTMUARTFIFO m_txFifo;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
-106
@@ -1,106 +0,0 @@
|
|||||||
/*
|
|
||||||
TX fifo control - Copyright (C) KI6ZUM 2015
|
|
||||||
Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Library General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library 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
|
|
||||||
Library General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Library General Public
|
|
||||||
License along with this library; if not, write to the
|
|
||||||
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
||||||
Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "SampleRB.h"
|
|
||||||
|
|
||||||
CSampleRB::CSampleRB(uint16_t length) :
|
|
||||||
m_length(length),
|
|
||||||
m_head(0U),
|
|
||||||
m_tail(0U),
|
|
||||||
m_full(false),
|
|
||||||
m_overflow(false)
|
|
||||||
{
|
|
||||||
m_samples = new uint16_t[length];
|
|
||||||
m_control = new uint8_t[length];
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t CSampleRB::getSpace() const
|
|
||||||
{
|
|
||||||
uint16_t n = 0U;
|
|
||||||
|
|
||||||
if (m_tail == m_head)
|
|
||||||
n = m_full ? 0U : m_length;
|
|
||||||
else if (m_tail < m_head)
|
|
||||||
n = m_length - m_head + m_tail;
|
|
||||||
else
|
|
||||||
n = m_tail - m_head;
|
|
||||||
|
|
||||||
if (n > m_length)
|
|
||||||
n = 0U;
|
|
||||||
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t CSampleRB::getData() const
|
|
||||||
{
|
|
||||||
if (m_tail == m_head)
|
|
||||||
return m_full ? m_length : 0U;
|
|
||||||
else if (m_tail < m_head)
|
|
||||||
return m_head - m_tail;
|
|
||||||
else
|
|
||||||
return m_length - m_tail + m_head;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CSampleRB::put(uint16_t sample, uint8_t control)
|
|
||||||
{
|
|
||||||
if (m_full) {
|
|
||||||
m_overflow = true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_samples[m_head] = sample;
|
|
||||||
m_control[m_head] = control;
|
|
||||||
|
|
||||||
m_head++;
|
|
||||||
if (m_head >= m_length)
|
|
||||||
m_head = 0U;
|
|
||||||
|
|
||||||
if (m_head == m_tail)
|
|
||||||
m_full = true;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CSampleRB::get(uint16_t& sample, uint8_t& control)
|
|
||||||
{
|
|
||||||
if (m_head == m_tail && !m_full)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
sample = m_samples[m_tail];
|
|
||||||
control = m_control[m_tail];
|
|
||||||
|
|
||||||
m_full = false;
|
|
||||||
|
|
||||||
m_tail++;
|
|
||||||
if (m_tail >= m_length)
|
|
||||||
m_tail = 0U;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CSampleRB::hasOverflowed()
|
|
||||||
{
|
|
||||||
bool overflow = m_overflow;
|
|
||||||
|
|
||||||
m_overflow = false;
|
|
||||||
|
|
||||||
return overflow;
|
|
||||||
}
|
|
||||||
|
|
||||||
-60
@@ -1,60 +0,0 @@
|
|||||||
/*
|
|
||||||
Serial fifo control - Copyright (C) KI6ZUM 2015
|
|
||||||
Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Library General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library 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
|
|
||||||
Library General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Library General Public
|
|
||||||
License along with this library; if not, write to the
|
|
||||||
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
||||||
Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if !defined(SAMPLERB_H)
|
|
||||||
#define SAMPLERB_H
|
|
||||||
|
|
||||||
#if defined(STM32F4XX)
|
|
||||||
#include "stm32f4xx.h"
|
|
||||||
#elif defined(STM32F7XX)
|
|
||||||
#include "stm32f7xx.h"
|
|
||||||
#elif defined(STM32F105xC)
|
|
||||||
#include "stm32f1xx.h"
|
|
||||||
#include <cstddef>
|
|
||||||
#else
|
|
||||||
#include <Arduino.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class CSampleRB {
|
|
||||||
public:
|
|
||||||
CSampleRB(uint16_t length);
|
|
||||||
|
|
||||||
uint16_t getSpace() const;
|
|
||||||
|
|
||||||
uint16_t getData() const;
|
|
||||||
|
|
||||||
bool put(uint16_t sample, uint8_t control);
|
|
||||||
|
|
||||||
bool get(uint16_t& sample, uint8_t& control);
|
|
||||||
|
|
||||||
bool hasOverflowed();
|
|
||||||
|
|
||||||
private:
|
|
||||||
uint16_t m_length;
|
|
||||||
volatile uint16_t* m_samples;
|
|
||||||
volatile uint8_t* m_control;
|
|
||||||
volatile uint16_t m_head;
|
|
||||||
volatile uint16_t m_tail;
|
|
||||||
volatile bool m_full;
|
|
||||||
bool m_overflow;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
+141
-19
@@ -70,6 +70,10 @@ const uint8_t MMDVM_AX25_DATA = 0x55U;
|
|||||||
const uint8_t MMDVM_FM_PARAMS1 = 0x60U;
|
const uint8_t MMDVM_FM_PARAMS1 = 0x60U;
|
||||||
const uint8_t MMDVM_FM_PARAMS2 = 0x61U;
|
const uint8_t MMDVM_FM_PARAMS2 = 0x61U;
|
||||||
const uint8_t MMDVM_FM_PARAMS3 = 0x62U;
|
const uint8_t MMDVM_FM_PARAMS3 = 0x62U;
|
||||||
|
const uint8_t MMDVM_FM_PARAMS4 = 0x63U;
|
||||||
|
const uint8_t MMDVM_FM_DATA = 0x65U;
|
||||||
|
const uint8_t MMDVM_FM_STATUS = 0x66U;
|
||||||
|
const uint8_t MMDVM_FM_EOT = 0x67U;
|
||||||
|
|
||||||
const uint8_t MMDVM_ACK = 0x70U;
|
const uint8_t MMDVM_ACK = 0x70U;
|
||||||
const uint8_t MMDVM_NAK = 0x7FU;
|
const uint8_t MMDVM_NAK = 0x7FU;
|
||||||
@@ -105,7 +109,7 @@ const uint8_t MMDVM_DEBUG5 = 0xF5U;
|
|||||||
#define HW_TYPE "MMDVM"
|
#define HW_TYPE "MMDVM"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define DESCRIPTION "20200714 (D-Star/DMR/System Fusion/P25/NXDN/POCSAG/FM/AX.25)"
|
#define DESCRIPTION "20200901 (D-Star/DMR/System Fusion/P25/NXDN/POCSAG/FM/AX.25)"
|
||||||
|
|
||||||
#if defined(GITVERSION)
|
#if defined(GITVERSION)
|
||||||
#define concat(h, a, b, c) h " " a " " b " GitID #" c ""
|
#define concat(h, a, b, c) h " " a " " b " GitID #" c ""
|
||||||
@@ -160,7 +164,7 @@ void CSerialPort::getStatus()
|
|||||||
|
|
||||||
// Send all sorts of interesting internal values
|
// Send all sorts of interesting internal values
|
||||||
reply[0U] = MMDVM_FRAME_START;
|
reply[0U] = MMDVM_FRAME_START;
|
||||||
reply[1U] = 13U;
|
reply[1U] = 15U;
|
||||||
reply[2U] = MMDVM_GET_STATUS;
|
reply[2U] = MMDVM_GET_STATUS;
|
||||||
|
|
||||||
reply[3U] = 0x00U;
|
reply[3U] = 0x00U;
|
||||||
@@ -244,12 +248,17 @@ void CSerialPort::getStatus()
|
|||||||
else
|
else
|
||||||
reply[12U] = 0U;
|
reply[12U] = 0U;
|
||||||
|
|
||||||
if (m_ax25Enable)
|
if (m_fmEnable)
|
||||||
reply[13U] = ax25TX.getSpace();
|
reply[13U] = fm.getSpace();
|
||||||
else
|
else
|
||||||
reply[13U] = 0U;
|
reply[13U] = 0U;
|
||||||
|
|
||||||
writeInt(1U, reply, 14);
|
if (m_ax25Enable)
|
||||||
|
reply[14U] = ax25TX.getSpace();
|
||||||
|
else
|
||||||
|
reply[14U] = 0U;
|
||||||
|
|
||||||
|
writeInt(1U, reply, 15);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSerialPort::getVersion()
|
void CSerialPort::getVersion()
|
||||||
@@ -273,7 +282,7 @@ void CSerialPort::getVersion()
|
|||||||
|
|
||||||
uint8_t CSerialPort::setConfig(const uint8_t* data, uint16_t length)
|
uint8_t CSerialPort::setConfig(const uint8_t* data, uint16_t length)
|
||||||
{
|
{
|
||||||
if (length < 24U)
|
if (length < 26U)
|
||||||
return 4U;
|
return 4U;
|
||||||
|
|
||||||
bool rxInvert = (data[0U] & 0x01U) == 0x01U;
|
bool rxInvert = (data[0U] & 0x01U) == 0x01U;
|
||||||
@@ -352,9 +361,11 @@ uint8_t CSerialPort::setConfig(const uint8_t* data, uint16_t length)
|
|||||||
if (ax25RXTwist < -4 || ax25RXTwist > 10)
|
if (ax25RXTwist < -4 || ax25RXTwist > 10)
|
||||||
return 4U;
|
return 4U;
|
||||||
|
|
||||||
int8_t ax25TXTwist = int8_t(data[23U]) - 128;
|
uint8_t ax25TXDelay = data[23U];
|
||||||
if (ax25TXTwist < -4 || ax25TXTwist > 10)
|
|
||||||
return 4U;
|
uint8_t ax25SlotTime = data[24U];
|
||||||
|
|
||||||
|
uint8_t ax25PPersist = data[25U];
|
||||||
|
|
||||||
setMode(modemState);
|
setMode(modemState);
|
||||||
|
|
||||||
@@ -374,7 +385,7 @@ uint8_t CSerialPort::setConfig(const uint8_t* data, uint16_t length)
|
|||||||
dmrDMOTX.setTXDelay(txDelay);
|
dmrDMOTX.setTXDelay(txDelay);
|
||||||
nxdnTX.setTXDelay(txDelay);
|
nxdnTX.setTXDelay(txDelay);
|
||||||
pocsagTX.setTXDelay(txDelay);
|
pocsagTX.setTXDelay(txDelay);
|
||||||
ax25TX.setTXDelay(txDelay);
|
ax25TX.setTXDelay(ax25TXDelay);
|
||||||
|
|
||||||
dmrTX.setColorCode(colorCode);
|
dmrTX.setColorCode(colorCode);
|
||||||
dmrRX.setColorCode(colorCode);
|
dmrRX.setColorCode(colorCode);
|
||||||
@@ -385,8 +396,7 @@ uint8_t CSerialPort::setConfig(const uint8_t* data, uint16_t length)
|
|||||||
ysfTX.setParams(ysfLoDev, ysfTXHang);
|
ysfTX.setParams(ysfLoDev, ysfTXHang);
|
||||||
p25TX.setParams(p25TXHang);
|
p25TX.setParams(p25TXHang);
|
||||||
nxdnTX.setParams(nxdnTXHang);
|
nxdnTX.setParams(nxdnTXHang);
|
||||||
ax25RX.setParams(ax25RXTwist);
|
ax25RX.setParams(ax25RXTwist, ax25SlotTime, ax25PPersist);
|
||||||
ax25TX.setParams(ax25TXTwist);
|
|
||||||
|
|
||||||
io.setParameters(rxInvert, txInvert, pttInvert, rxLevel, cwIdTXLevel, dstarTXLevel, dmrTXLevel, ysfTXLevel, p25TXLevel, nxdnTXLevel, pocsagTXLevel, fmTXLevel, ax25TXLevel, txDCOffset, rxDCOffset, useCOSAsLockout);
|
io.setParameters(rxInvert, txInvert, pttInvert, rxLevel, cwIdTXLevel, dstarTXLevel, dmrTXLevel, ysfTXLevel, p25TXLevel, nxdnTXLevel, pocsagTXLevel, fmTXLevel, ax25TXLevel, txDCOffset, rxDCOffset, useCOSAsLockout);
|
||||||
|
|
||||||
@@ -442,7 +452,7 @@ uint8_t CSerialPort::setFMParams2(const uint8_t* data, uint16_t length)
|
|||||||
|
|
||||||
uint8_t CSerialPort::setFMParams3(const uint8_t* data, uint16_t length)
|
uint8_t CSerialPort::setFMParams3(const uint8_t* data, uint16_t length)
|
||||||
{
|
{
|
||||||
if (length < 12U)
|
if (length < 14U)
|
||||||
return 4U;
|
return 4U;
|
||||||
|
|
||||||
uint16_t timeout = data[0U] * 5U;
|
uint16_t timeout = data[0U] * 5U;
|
||||||
@@ -456,14 +466,37 @@ uint8_t CSerialPort::setFMParams3(const uint8_t* data, uint16_t length)
|
|||||||
uint8_t kerchunkTime = data[6U];
|
uint8_t kerchunkTime = data[6U];
|
||||||
uint8_t hangTime = data[7U];
|
uint8_t hangTime = data[7U];
|
||||||
|
|
||||||
uint8_t accessMode = data[8U] & 0x7FU;
|
uint8_t accessMode = data[8U] & 0x0FU;
|
||||||
|
bool noiseSquelch = (data[8U] & 0x40U) == 0x40U;
|
||||||
bool cosInvert = (data[8U] & 0x80U) == 0x80U;
|
bool cosInvert = (data[8U] & 0x80U) == 0x80U;
|
||||||
|
|
||||||
uint8_t rfAudioBoost = data[9U];
|
uint8_t rfAudioBoost = data[9U];
|
||||||
uint8_t maxDev = data[10U];
|
uint8_t maxDev = data[10U];
|
||||||
uint8_t rxLevel = data[11U];
|
uint8_t rxLevel = data[11U];
|
||||||
|
|
||||||
return fm.setMisc(timeout, timeoutLevel, ctcssFrequency, ctcssHighThreshold, ctcssLowThreshold, ctcssLevel, kerchunkTime, hangTime, accessMode, cosInvert, rfAudioBoost, maxDev, rxLevel);
|
uint8_t squelchHighThreshold = data[12U];
|
||||||
|
uint8_t squelchLowThreshold = data[13U];
|
||||||
|
|
||||||
|
return fm.setMisc(timeout, timeoutLevel, ctcssFrequency, ctcssHighThreshold, ctcssLowThreshold, ctcssLevel, kerchunkTime, hangTime, accessMode, cosInvert, noiseSquelch, squelchHighThreshold, squelchLowThreshold, rfAudioBoost, maxDev, rxLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t CSerialPort::setFMParams4(const uint8_t* data, uint16_t length)
|
||||||
|
{
|
||||||
|
if (length < 4U)
|
||||||
|
return 4U;
|
||||||
|
|
||||||
|
uint8_t audioBoost = data[0U];
|
||||||
|
uint8_t speed = data[1U];
|
||||||
|
uint16_t frequency = data[2U] * 10U;
|
||||||
|
uint8_t level = data[3U];
|
||||||
|
|
||||||
|
char ack[50U];
|
||||||
|
uint8_t n = 0U;
|
||||||
|
for (uint8_t i = 4U; i < length; i++, n++)
|
||||||
|
ack[n] = data[i];
|
||||||
|
ack[n] = '\0';
|
||||||
|
|
||||||
|
return fm.setExt(ack, audioBoost, speed, frequency, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t CSerialPort::setMode(const uint8_t* data, uint16_t length)
|
uint8_t CSerialPort::setMode(const uint8_t* data, uint16_t length)
|
||||||
@@ -592,14 +625,12 @@ void CSerialPort::setMode(MMDVM_STATE modemState)
|
|||||||
|
|
||||||
cwIdTX.reset();
|
cwIdTX.reset();
|
||||||
|
|
||||||
m_modemState = modemState;
|
io.setMode(modemState);
|
||||||
|
|
||||||
io.setMode();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSerialPort::start()
|
void CSerialPort::start()
|
||||||
{
|
{
|
||||||
beginInt(1U, 115200);
|
beginInt(1U, SERIAL_SPEED);
|
||||||
|
|
||||||
#if defined(SERIAL_REPEATER)
|
#if defined(SERIAL_REPEATER)
|
||||||
beginInt(3U, 9600);
|
beginInt(3U, 9600);
|
||||||
@@ -739,6 +770,16 @@ void CSerialPort::processMessage(const uint8_t* buffer, uint16_t length)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case MMDVM_FM_PARAMS4:
|
||||||
|
err = setFMParams4(buffer, length);
|
||||||
|
if (err == 0U) {
|
||||||
|
sendACK();
|
||||||
|
} else {
|
||||||
|
DEBUG2("Received invalid FM params 4", err);
|
||||||
|
sendNAK(err);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case MMDVM_CAL_DATA:
|
case MMDVM_CAL_DATA:
|
||||||
if (m_modemState == STATE_DSTARCAL)
|
if (m_modemState == STATE_DSTARCAL)
|
||||||
err = calDStarTX.write(buffer, length);
|
err = calDStarTX.write(buffer, length);
|
||||||
@@ -955,6 +996,20 @@ void CSerialPort::processMessage(const uint8_t* buffer, uint16_t length)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case MMDVM_FM_DATA:
|
||||||
|
if (m_fmEnable) {
|
||||||
|
if (m_modemState == STATE_IDLE || m_modemState == STATE_FM)
|
||||||
|
err = fm.writeData(m_buffer + 3U, m_len - 3U);
|
||||||
|
}
|
||||||
|
if (err == 0U) {
|
||||||
|
if (m_modemState == STATE_IDLE)
|
||||||
|
setMode(STATE_FM);
|
||||||
|
} else {
|
||||||
|
DEBUG2("Received invalid FM data", err);
|
||||||
|
sendNAK(err);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case MMDVM_AX25_DATA:
|
case MMDVM_AX25_DATA:
|
||||||
if (m_ax25Enable) {
|
if (m_ax25Enable) {
|
||||||
if (m_modemState == STATE_IDLE || m_modemState == STATE_FM)
|
if (m_modemState == STATE_IDLE || m_modemState == STATE_FM)
|
||||||
@@ -1251,6 +1306,73 @@ void CSerialPort::writeNXDNLost()
|
|||||||
writeInt(1U, reply, 3);
|
writeInt(1U, reply, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSerialPort::writeFMData(const uint8_t* data, uint16_t length)
|
||||||
|
{
|
||||||
|
if (m_modemState != STATE_FM && m_modemState != STATE_IDLE)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!m_fmEnable)
|
||||||
|
return;
|
||||||
|
|
||||||
|
uint8_t reply[512U];
|
||||||
|
|
||||||
|
reply[0U] = MMDVM_FRAME_START;
|
||||||
|
|
||||||
|
if (length > 252U) {
|
||||||
|
reply[1U] = 0U;
|
||||||
|
reply[2U] = (length + 4U) - 255U;
|
||||||
|
reply[3U] = MMDVM_FM_DATA;
|
||||||
|
|
||||||
|
for (uint8_t i = 0U; i < length; i++)
|
||||||
|
reply[i + 4U] = data[i];
|
||||||
|
|
||||||
|
writeInt(1U, reply, length + 4U);
|
||||||
|
} else {
|
||||||
|
reply[1U] = length + 3U;
|
||||||
|
reply[2U] = MMDVM_FM_DATA;
|
||||||
|
|
||||||
|
for (uint8_t i = 0U; i < length; i++)
|
||||||
|
reply[i + 3U] = data[i];
|
||||||
|
|
||||||
|
writeInt(1U, reply, length + 3U);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSerialPort::writeFMStatus(uint8_t status)
|
||||||
|
{
|
||||||
|
if (m_modemState != STATE_FM && m_modemState != STATE_IDLE)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!m_fmEnable)
|
||||||
|
return;
|
||||||
|
|
||||||
|
uint8_t reply[10U];
|
||||||
|
|
||||||
|
reply[0U] = MMDVM_FRAME_START;
|
||||||
|
reply[1U] = 4U;
|
||||||
|
reply[2U] = MMDVM_FM_STATUS;
|
||||||
|
reply[3U] = status;
|
||||||
|
|
||||||
|
writeInt(1U, reply, 4U);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSerialPort::writeFMEOT()
|
||||||
|
{
|
||||||
|
if (m_modemState != STATE_FM && m_modemState != STATE_IDLE)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!m_fmEnable)
|
||||||
|
return;
|
||||||
|
|
||||||
|
uint8_t reply[10U];
|
||||||
|
|
||||||
|
reply[0U] = MMDVM_FRAME_START;
|
||||||
|
reply[1U] = 3U;
|
||||||
|
reply[2U] = MMDVM_FM_EOT;
|
||||||
|
|
||||||
|
writeInt(1U, reply, 3U);
|
||||||
|
}
|
||||||
|
|
||||||
void CSerialPort::writeAX25Data(const uint8_t* data, uint16_t length)
|
void CSerialPort::writeAX25Data(const uint8_t* data, uint16_t length)
|
||||||
{
|
{
|
||||||
if (m_modemState != STATE_FM && m_modemState != STATE_IDLE)
|
if (m_modemState != STATE_FM && m_modemState != STATE_IDLE)
|
||||||
|
|||||||
+11
-2
@@ -21,7 +21,11 @@
|
|||||||
|
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "Globals.h"
|
#include "Globals.h"
|
||||||
#include "SerialRB.h"
|
#include "RingBuffer.h"
|
||||||
|
|
||||||
|
#if !defined(SERIAL_SPEED)
|
||||||
|
#define SERIAL_SPEED 115200
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
class CSerialPort {
|
class CSerialPort {
|
||||||
@@ -52,6 +56,10 @@ public:
|
|||||||
|
|
||||||
void writeAX25Data(const uint8_t* data, uint16_t length);
|
void writeAX25Data(const uint8_t* data, uint16_t length);
|
||||||
|
|
||||||
|
void writeFMData(const uint8_t* data, uint16_t length);
|
||||||
|
void writeFMStatus(uint8_t status);
|
||||||
|
void writeFMEOT();
|
||||||
|
|
||||||
void writeCalData(const uint8_t* data, uint8_t length);
|
void writeCalData(const uint8_t* data, uint8_t length);
|
||||||
void writeRSSIData(const uint8_t* data, uint8_t length);
|
void writeRSSIData(const uint8_t* data, uint8_t length);
|
||||||
|
|
||||||
@@ -66,7 +74,7 @@ private:
|
|||||||
uint16_t m_ptr;
|
uint16_t m_ptr;
|
||||||
uint16_t m_len;
|
uint16_t m_len;
|
||||||
bool m_debug;
|
bool m_debug;
|
||||||
CSerialRB m_repeat;
|
CRingBuffer<uint8_t> m_repeat;
|
||||||
|
|
||||||
void sendACK();
|
void sendACK();
|
||||||
void sendNAK(uint8_t err);
|
void sendNAK(uint8_t err);
|
||||||
@@ -78,6 +86,7 @@ private:
|
|||||||
uint8_t setFMParams1(const uint8_t* data, uint16_t length);
|
uint8_t setFMParams1(const uint8_t* data, uint16_t length);
|
||||||
uint8_t setFMParams2(const uint8_t* data, uint16_t length);
|
uint8_t setFMParams2(const uint8_t* data, uint16_t length);
|
||||||
uint8_t setFMParams3(const uint8_t* data, uint16_t length);
|
uint8_t setFMParams3(const uint8_t* data, uint16_t length);
|
||||||
|
uint8_t setFMParams4(const uint8_t* data, uint16_t length);
|
||||||
void processMessage(const uint8_t* data, uint16_t length);
|
void processMessage(const uint8_t* data, uint16_t length);
|
||||||
|
|
||||||
// Hardware versions
|
// Hardware versions
|
||||||
|
|||||||
-100
@@ -1,100 +0,0 @@
|
|||||||
/*
|
|
||||||
Serial RB control - Copyright (C) KI6ZUM 2015
|
|
||||||
Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Library General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library 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
|
|
||||||
Library General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Library General Public
|
|
||||||
License along with this library; if not, write to the
|
|
||||||
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
||||||
Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "SerialRB.h"
|
|
||||||
|
|
||||||
CSerialRB::CSerialRB(uint16_t length) :
|
|
||||||
m_length(length),
|
|
||||||
m_head(0U),
|
|
||||||
m_tail(0U),
|
|
||||||
m_full(false)
|
|
||||||
{
|
|
||||||
m_buffer = new uint8_t[length];
|
|
||||||
}
|
|
||||||
|
|
||||||
void CSerialRB::reset()
|
|
||||||
{
|
|
||||||
m_head = 0U;
|
|
||||||
m_tail = 0U;
|
|
||||||
m_full = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t CSerialRB::getSpace() const
|
|
||||||
{
|
|
||||||
uint16_t n = 0U;
|
|
||||||
|
|
||||||
if (m_tail == m_head)
|
|
||||||
n = m_full ? 0U : m_length;
|
|
||||||
else if (m_tail < m_head)
|
|
||||||
n = m_length - m_head + m_tail;
|
|
||||||
else
|
|
||||||
n = m_tail - m_head;
|
|
||||||
|
|
||||||
if (n > m_length)
|
|
||||||
n = 0U;
|
|
||||||
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t CSerialRB::getData() const
|
|
||||||
{
|
|
||||||
if (m_tail == m_head)
|
|
||||||
return m_full ? m_length : 0U;
|
|
||||||
else if (m_tail < m_head)
|
|
||||||
return m_head - m_tail;
|
|
||||||
else
|
|
||||||
return m_length - m_tail + m_head;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CSerialRB::put(uint8_t c)
|
|
||||||
{
|
|
||||||
if (m_full)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
m_buffer[m_head] = c;
|
|
||||||
|
|
||||||
m_head++;
|
|
||||||
if (m_head >= m_length)
|
|
||||||
m_head = 0U;
|
|
||||||
|
|
||||||
if (m_head == m_tail)
|
|
||||||
m_full = true;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t CSerialRB::peek() const
|
|
||||||
{
|
|
||||||
return m_buffer[m_tail];
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t CSerialRB::get()
|
|
||||||
{
|
|
||||||
uint8_t value = m_buffer[m_tail];
|
|
||||||
|
|
||||||
m_full = false;
|
|
||||||
|
|
||||||
m_tail++;
|
|
||||||
if (m_tail >= m_length)
|
|
||||||
m_tail = 0U;
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
-62
@@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
Serial fifo control - Copyright (C) KI6ZUM 2015
|
|
||||||
Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Library General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library 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
|
|
||||||
Library General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Library General Public
|
|
||||||
License along with this library; if not, write to the
|
|
||||||
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
||||||
Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if !defined(SERIALRB_H)
|
|
||||||
#define SERIALRB_H
|
|
||||||
|
|
||||||
#if defined(STM32F4XX)
|
|
||||||
#include "stm32f4xx.h"
|
|
||||||
#elif defined(STM32F7XX)
|
|
||||||
#include "stm32f7xx.h"
|
|
||||||
#elif defined(STM32F105xC)
|
|
||||||
#include "stm32f1xx.h"
|
|
||||||
#include <cstddef>
|
|
||||||
#else
|
|
||||||
#include <Arduino.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
const uint16_t SERIAL_RINGBUFFER_SIZE = 370U;
|
|
||||||
|
|
||||||
class CSerialRB {
|
|
||||||
public:
|
|
||||||
CSerialRB(uint16_t length = SERIAL_RINGBUFFER_SIZE);
|
|
||||||
|
|
||||||
uint16_t getSpace() const;
|
|
||||||
|
|
||||||
uint16_t getData() const;
|
|
||||||
|
|
||||||
void reset();
|
|
||||||
|
|
||||||
bool put(uint8_t c);
|
|
||||||
|
|
||||||
uint8_t peek() const;
|
|
||||||
|
|
||||||
uint8_t get();
|
|
||||||
|
|
||||||
private:
|
|
||||||
uint16_t m_length;
|
|
||||||
volatile uint8_t* m_buffer;
|
|
||||||
volatile uint16_t m_head;
|
|
||||||
volatile uint16_t m_tail;
|
|
||||||
volatile bool m_full;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
+49
-584
@@ -39,9 +39,7 @@ UART5 - TXD PC12 - RXD PD2 (Discovery, MMDVM-Pi, MMDVM-Pi F722 board, MMDVM-F4M
|
|||||||
|
|
||||||
#if defined(STM32F4XX) || defined(STM32F7XX)
|
#if defined(STM32F4XX) || defined(STM32F7XX)
|
||||||
|
|
||||||
#define TX_SERIAL_FIFO_SIZE 512U
|
#include "STMUART.h"
|
||||||
#define RX_SERIAL_FIFO_SIZE 512U
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
void USART1_IRQHandler();
|
void USART1_IRQHandler();
|
||||||
void USART2_IRQHandler();
|
void USART2_IRQHandler();
|
||||||
@@ -52,111 +50,12 @@ extern "C" {
|
|||||||
/* ************* USART1 ***************** */
|
/* ************* USART1 ***************** */
|
||||||
#if defined(STM32F4_PI) || defined(STM32F4_F4M) || defined(STM32F722_F7M) || defined(STM32F722_PI) || defined(STM32F722_RPT_HAT) || defined(STM32F4_DVM) || (defined(STM32F4_NUCLEO) && defined(STM32F4_NUCLEO_ARDUINO_HEADER)) || defined(DRCC_DVM) || defined(STM32F4_EDA_405) || defined(STM32F4_EDA_446)
|
#if defined(STM32F4_PI) || defined(STM32F4_F4M) || defined(STM32F722_F7M) || defined(STM32F722_PI) || defined(STM32F722_RPT_HAT) || defined(STM32F4_DVM) || (defined(STM32F4_NUCLEO) && defined(STM32F4_NUCLEO_ARDUINO_HEADER)) || defined(DRCC_DVM) || defined(STM32F4_EDA_405) || defined(STM32F4_EDA_446)
|
||||||
|
|
||||||
volatile uint8_t TXSerialfifo1[TX_SERIAL_FIFO_SIZE];
|
|
||||||
volatile uint8_t RXSerialfifo1[RX_SERIAL_FIFO_SIZE];
|
|
||||||
volatile uint16_t TXSerialfifohead1, TXSerialfifotail1;
|
|
||||||
volatile uint16_t RXSerialfifohead1, RXSerialfifotail1;
|
|
||||||
|
|
||||||
// Init queues
|
static CSTMUART m_USART1;
|
||||||
void TXSerialfifoinit1()
|
|
||||||
{
|
|
||||||
TXSerialfifohead1 = 0U;
|
|
||||||
TXSerialfifotail1 = 0U;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RXSerialfifoinit1()
|
|
||||||
{
|
|
||||||
RXSerialfifohead1 = 0U;
|
|
||||||
RXSerialfifotail1 = 0U;
|
|
||||||
}
|
|
||||||
|
|
||||||
// How full is queue
|
|
||||||
// TODO decide if how full or how empty is preferred info to return
|
|
||||||
uint16_t TXSerialfifolevel1()
|
|
||||||
{
|
|
||||||
uint32_t tail = TXSerialfifotail1;
|
|
||||||
uint32_t head = TXSerialfifohead1;
|
|
||||||
|
|
||||||
if (tail > head)
|
|
||||||
return TX_SERIAL_FIFO_SIZE + head - tail;
|
|
||||||
else
|
|
||||||
return head - tail;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t RXSerialfifolevel1()
|
|
||||||
{
|
|
||||||
uint32_t tail = RXSerialfifotail1;
|
|
||||||
uint32_t head = RXSerialfifohead1;
|
|
||||||
|
|
||||||
if (tail > head)
|
|
||||||
return RX_SERIAL_FIFO_SIZE + head - tail;
|
|
||||||
else
|
|
||||||
return head - tail;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Flushes the transmit shift register
|
|
||||||
// warning: this call is blocking
|
|
||||||
void TXSerialFlush1()
|
|
||||||
{
|
|
||||||
// wait until the TXE shows the shift register is empty
|
|
||||||
while (USART_GetITStatus(USART1, USART_FLAG_TXE))
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t TXSerialfifoput1(uint8_t next)
|
|
||||||
{
|
|
||||||
if (TXSerialfifolevel1() < TX_SERIAL_FIFO_SIZE) {
|
|
||||||
TXSerialfifo1[TXSerialfifohead1] = next;
|
|
||||||
|
|
||||||
TXSerialfifohead1++;
|
|
||||||
if (TXSerialfifohead1 >= TX_SERIAL_FIFO_SIZE)
|
|
||||||
TXSerialfifohead1 = 0U;
|
|
||||||
|
|
||||||
// make sure transmit interrupts are enabled as long as there is data to send
|
|
||||||
USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
|
|
||||||
return 1U;
|
|
||||||
} else {
|
|
||||||
return 0U; // signal an overflow occurred by returning a zero count
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void USART1_IRQHandler()
|
void USART1_IRQHandler()
|
||||||
{
|
{
|
||||||
uint8_t c;
|
m_USART1.handleIRQ();
|
||||||
|
|
||||||
if (USART_GetITStatus(USART1, USART_IT_RXNE)) {
|
|
||||||
c = (uint8_t) USART_ReceiveData(USART1);
|
|
||||||
|
|
||||||
if (RXSerialfifolevel1() < RX_SERIAL_FIFO_SIZE) {
|
|
||||||
RXSerialfifo1[RXSerialfifohead1] = c;
|
|
||||||
|
|
||||||
RXSerialfifohead1++;
|
|
||||||
if (RXSerialfifohead1 >= RX_SERIAL_FIFO_SIZE)
|
|
||||||
RXSerialfifohead1 = 0U;
|
|
||||||
} else {
|
|
||||||
// TODO - do something if rx fifo is full?
|
|
||||||
}
|
|
||||||
|
|
||||||
USART_ClearITPendingBit(USART1, USART_IT_RXNE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (USART_GetITStatus(USART1, USART_IT_TXE)) {
|
|
||||||
c = 0U;
|
|
||||||
|
|
||||||
if (TXSerialfifohead1 != TXSerialfifotail1) { // if the fifo is not empty
|
|
||||||
c = TXSerialfifo1[TXSerialfifotail1];
|
|
||||||
|
|
||||||
TXSerialfifotail1++;
|
|
||||||
if (TXSerialfifotail1 >= TX_SERIAL_FIFO_SIZE)
|
|
||||||
TXSerialfifotail1 = 0U;
|
|
||||||
|
|
||||||
USART_SendData(USART1, c);
|
|
||||||
} else { // if there's no more data to transmit then turn off TX interrupts
|
|
||||||
USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
USART_ClearITPendingBit(USART1, USART_IT_TXE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitUSART1(int speed)
|
void InitUSART1(int speed)
|
||||||
@@ -201,41 +100,7 @@ void InitUSART1(int speed)
|
|||||||
|
|
||||||
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
|
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
|
||||||
|
|
||||||
// initialize the fifos
|
m_USART1.init(USART1);
|
||||||
TXSerialfifoinit1();
|
|
||||||
RXSerialfifoinit1();
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t AvailUSART1()
|
|
||||||
{
|
|
||||||
if (RXSerialfifolevel1() > 0U)
|
|
||||||
return 1U;
|
|
||||||
else
|
|
||||||
return 0U;
|
|
||||||
}
|
|
||||||
|
|
||||||
int AvailForWriteUSART1()
|
|
||||||
{
|
|
||||||
return TX_SERIAL_FIFO_SIZE - TXSerialfifolevel1();
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t ReadUSART1()
|
|
||||||
{
|
|
||||||
uint8_t data_c = RXSerialfifo1[RXSerialfifotail1];
|
|
||||||
|
|
||||||
RXSerialfifotail1++;
|
|
||||||
if (RXSerialfifotail1 >= RX_SERIAL_FIFO_SIZE)
|
|
||||||
RXSerialfifotail1 = 0U;
|
|
||||||
|
|
||||||
return data_c;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WriteUSART1(const uint8_t* data, uint16_t length)
|
|
||||||
{
|
|
||||||
for (uint16_t i = 0U; i < length; i++)
|
|
||||||
TXSerialfifoput1(data[i]);
|
|
||||||
|
|
||||||
USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -243,111 +108,12 @@ void WriteUSART1(const uint8_t* data, uint16_t length)
|
|||||||
/* ************* USART2 ***************** */
|
/* ************* USART2 ***************** */
|
||||||
#if defined(STM32F4_NUCLEO) || defined(STM32F4_RPT_HAT_TGO) || defined(DRCC_DVM)
|
#if defined(STM32F4_NUCLEO) || defined(STM32F4_RPT_HAT_TGO) || defined(DRCC_DVM)
|
||||||
|
|
||||||
volatile uint8_t TXSerialfifo2[TX_SERIAL_FIFO_SIZE];
|
static CSTMUART m_USART2;
|
||||||
volatile uint8_t RXSerialfifo2[RX_SERIAL_FIFO_SIZE];
|
|
||||||
volatile uint16_t TXSerialfifohead2, TXSerialfifotail2;
|
|
||||||
volatile uint16_t RXSerialfifohead2, RXSerialfifotail2;
|
|
||||||
|
|
||||||
// Init queues
|
|
||||||
void TXSerialfifoinit2()
|
|
||||||
{
|
|
||||||
TXSerialfifohead2 = 0U;
|
|
||||||
TXSerialfifotail2 = 0U;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RXSerialfifoinit2()
|
|
||||||
{
|
|
||||||
RXSerialfifohead2 = 0U;
|
|
||||||
RXSerialfifotail2 = 0U;
|
|
||||||
}
|
|
||||||
|
|
||||||
// How full is queue
|
|
||||||
// TODO decide if how full or how empty is preferred info to return
|
|
||||||
uint16_t TXSerialfifolevel2()
|
|
||||||
{
|
|
||||||
uint32_t tail = TXSerialfifotail2;
|
|
||||||
uint32_t head = TXSerialfifohead2;
|
|
||||||
|
|
||||||
if (tail > head)
|
|
||||||
return TX_SERIAL_FIFO_SIZE + head - tail;
|
|
||||||
else
|
|
||||||
return head - tail;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t RXSerialfifolevel2()
|
|
||||||
{
|
|
||||||
uint32_t tail = RXSerialfifotail2;
|
|
||||||
uint32_t head = RXSerialfifohead2;
|
|
||||||
|
|
||||||
if (tail > head)
|
|
||||||
return RX_SERIAL_FIFO_SIZE + head - tail;
|
|
||||||
else
|
|
||||||
return head - tail;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Flushes the transmit shift register
|
|
||||||
// warning: this call is blocking
|
|
||||||
void TXSerialFlush2()
|
|
||||||
{
|
|
||||||
// wait until the TXE shows the shift register is empty
|
|
||||||
while (USART_GetITStatus(USART2, USART_FLAG_TXE))
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t TXSerialfifoput2(uint8_t next)
|
|
||||||
{
|
|
||||||
if (TXSerialfifolevel2() < TX_SERIAL_FIFO_SIZE) {
|
|
||||||
TXSerialfifo2[TXSerialfifohead2] = next;
|
|
||||||
|
|
||||||
TXSerialfifohead2++;
|
|
||||||
if (TXSerialfifohead2 >= TX_SERIAL_FIFO_SIZE)
|
|
||||||
TXSerialfifohead2 = 0U;
|
|
||||||
|
|
||||||
// make sure transmit interrupts are enabled as long as there is data to send
|
|
||||||
USART_ITConfig(USART2, USART_IT_TXE, ENABLE);
|
|
||||||
return 1U;
|
|
||||||
} else {
|
|
||||||
return 0U; // signal an overflow occurred by returning a zero count
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void USART2_IRQHandler()
|
void USART2_IRQHandler()
|
||||||
{
|
{
|
||||||
uint8_t c;
|
m_USART2.handleIRQ();
|
||||||
|
|
||||||
if (USART_GetITStatus(USART2, USART_IT_RXNE)) {
|
|
||||||
c = (uint8_t) USART_ReceiveData(USART2);
|
|
||||||
|
|
||||||
if (RXSerialfifolevel2() < RX_SERIAL_FIFO_SIZE) {
|
|
||||||
RXSerialfifo2[RXSerialfifohead2] = c;
|
|
||||||
|
|
||||||
RXSerialfifohead2++;
|
|
||||||
if (RXSerialfifohead2 >= RX_SERIAL_FIFO_SIZE)
|
|
||||||
RXSerialfifohead2 = 0U;
|
|
||||||
} else {
|
|
||||||
// TODO - do something if rx fifo is full?
|
|
||||||
}
|
|
||||||
|
|
||||||
USART_ClearITPendingBit(USART2, USART_IT_RXNE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (USART_GetITStatus(USART2, USART_IT_TXE)) {
|
|
||||||
c = 0U;
|
|
||||||
|
|
||||||
if (TXSerialfifohead2 != TXSerialfifotail2) { // if the fifo is not empty
|
|
||||||
c = TXSerialfifo2[TXSerialfifotail2];
|
|
||||||
|
|
||||||
TXSerialfifotail2++;
|
|
||||||
if (TXSerialfifotail2 >= TX_SERIAL_FIFO_SIZE)
|
|
||||||
TXSerialfifotail2 = 0U;
|
|
||||||
|
|
||||||
USART_SendData(USART2, c);
|
|
||||||
} else { // if there's no more data to transmit then turn off TX interrupts
|
|
||||||
USART_ITConfig(USART2, USART_IT_TXE, DISABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
USART_ClearITPendingBit(USART2, USART_IT_TXE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitUSART2(int speed)
|
void InitUSART2(int speed)
|
||||||
@@ -392,41 +158,7 @@ void InitUSART2(int speed)
|
|||||||
|
|
||||||
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
|
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
|
||||||
|
|
||||||
// initialize the fifos
|
m_USART2.init(USART2);
|
||||||
TXSerialfifoinit2();
|
|
||||||
RXSerialfifoinit2();
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t AvailUSART2()
|
|
||||||
{
|
|
||||||
if (RXSerialfifolevel2() > 0U)
|
|
||||||
return 1U;
|
|
||||||
else
|
|
||||||
return 0U;
|
|
||||||
}
|
|
||||||
|
|
||||||
int AvailForWriteUSART2()
|
|
||||||
{
|
|
||||||
return TX_SERIAL_FIFO_SIZE - TXSerialfifolevel2();
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t ReadUSART2()
|
|
||||||
{
|
|
||||||
uint8_t data_c = RXSerialfifo2[RXSerialfifotail2];
|
|
||||||
|
|
||||||
RXSerialfifotail2++;
|
|
||||||
if (RXSerialfifotail2 >= RX_SERIAL_FIFO_SIZE)
|
|
||||||
RXSerialfifotail2 = 0U;
|
|
||||||
|
|
||||||
return data_c;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WriteUSART2(const uint8_t* data, uint16_t length)
|
|
||||||
{
|
|
||||||
for (uint16_t i = 0U; i < length; i++)
|
|
||||||
TXSerialfifoput2(data[i]);
|
|
||||||
|
|
||||||
USART_ITConfig(USART2, USART_IT_TXE, ENABLE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -434,111 +166,11 @@ void WriteUSART2(const uint8_t* data, uint16_t length)
|
|||||||
/* ************* USART3 ***************** */
|
/* ************* USART3 ***************** */
|
||||||
#if defined(STM32F4_DISCOVERY) || defined(STM32F7_NUCLEO)
|
#if defined(STM32F4_DISCOVERY) || defined(STM32F7_NUCLEO)
|
||||||
|
|
||||||
volatile uint8_t TXSerialfifo3[TX_SERIAL_FIFO_SIZE];
|
static CSTMUART m_USART3;
|
||||||
volatile uint8_t RXSerialfifo3[RX_SERIAL_FIFO_SIZE];
|
|
||||||
volatile uint16_t TXSerialfifohead3, TXSerialfifotail3;
|
|
||||||
volatile uint16_t RXSerialfifohead3, RXSerialfifotail3;
|
|
||||||
|
|
||||||
// Init queues
|
|
||||||
void TXSerialfifoinit3()
|
|
||||||
{
|
|
||||||
TXSerialfifohead3 = 0U;
|
|
||||||
TXSerialfifotail3 = 0U;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RXSerialfifoinit3()
|
|
||||||
{
|
|
||||||
RXSerialfifohead3 = 0U;
|
|
||||||
RXSerialfifotail3 = 0U;
|
|
||||||
}
|
|
||||||
|
|
||||||
// How full is queue
|
|
||||||
// TODO decide if how full or how empty is preferred info to return
|
|
||||||
uint16_t TXSerialfifolevel3()
|
|
||||||
{
|
|
||||||
uint32_t tail = TXSerialfifotail3;
|
|
||||||
uint32_t head = TXSerialfifohead3;
|
|
||||||
|
|
||||||
if (tail > head)
|
|
||||||
return TX_SERIAL_FIFO_SIZE + head - tail;
|
|
||||||
else
|
|
||||||
return head - tail;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t RXSerialfifolevel3()
|
|
||||||
{
|
|
||||||
uint32_t tail = RXSerialfifotail3;
|
|
||||||
uint32_t head = RXSerialfifohead3;
|
|
||||||
|
|
||||||
if (tail > head)
|
|
||||||
return RX_SERIAL_FIFO_SIZE + head - tail;
|
|
||||||
else
|
|
||||||
return head - tail;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Flushes the transmit shift register
|
|
||||||
// warning: this call is blocking
|
|
||||||
void TXSerialFlush3()
|
|
||||||
{
|
|
||||||
// wait until the TXE shows the shift register is empty
|
|
||||||
while (USART_GetITStatus(USART3, USART_FLAG_TXE))
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t TXSerialfifoput3(uint8_t next)
|
|
||||||
{
|
|
||||||
if (TXSerialfifolevel3() < TX_SERIAL_FIFO_SIZE) {
|
|
||||||
TXSerialfifo3[TXSerialfifohead3] = next;
|
|
||||||
|
|
||||||
TXSerialfifohead3++;
|
|
||||||
if (TXSerialfifohead3 >= TX_SERIAL_FIFO_SIZE)
|
|
||||||
TXSerialfifohead3 = 0U;
|
|
||||||
|
|
||||||
// make sure transmit interrupts are enabled as long as there is data to send
|
|
||||||
USART_ITConfig(USART3, USART_IT_TXE, ENABLE);
|
|
||||||
return 1U;
|
|
||||||
} else {
|
|
||||||
return 0U; // signal an overflow occurred by returning a zero count
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void USART3_IRQHandler()
|
void USART3_IRQHandler()
|
||||||
{
|
{
|
||||||
uint8_t c;
|
m_USART3.handleIRQ();
|
||||||
|
|
||||||
if (USART_GetITStatus(USART3, USART_IT_RXNE)) {
|
|
||||||
c = (uint8_t) USART_ReceiveData(USART3);
|
|
||||||
|
|
||||||
if (RXSerialfifolevel3() < RX_SERIAL_FIFO_SIZE) {
|
|
||||||
RXSerialfifo3[RXSerialfifohead3] = c;
|
|
||||||
|
|
||||||
RXSerialfifohead3++;
|
|
||||||
if (RXSerialfifohead3 >= RX_SERIAL_FIFO_SIZE)
|
|
||||||
RXSerialfifohead3 = 0U;
|
|
||||||
} else {
|
|
||||||
// TODO - do something if rx fifo is full?
|
|
||||||
}
|
|
||||||
|
|
||||||
USART_ClearITPendingBit(USART3, USART_IT_RXNE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (USART_GetITStatus(USART3, USART_IT_TXE)) {
|
|
||||||
c = 0U;
|
|
||||||
|
|
||||||
if (TXSerialfifohead3 != TXSerialfifotail3) { // if the fifo is not empty
|
|
||||||
c = TXSerialfifo3[TXSerialfifotail3];
|
|
||||||
|
|
||||||
TXSerialfifotail3++;
|
|
||||||
if (TXSerialfifotail3 >= TX_SERIAL_FIFO_SIZE)
|
|
||||||
TXSerialfifotail3 = 0U;
|
|
||||||
|
|
||||||
USART_SendData(USART3, c);
|
|
||||||
} else { // if there's no more data to transmit then turn off TX interrupts
|
|
||||||
USART_ITConfig(USART3, USART_IT_TXE, DISABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
USART_ClearITPendingBit(USART3, USART_IT_TXE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(STM32F7_NUCLEO)
|
#if defined(STM32F7_NUCLEO)
|
||||||
@@ -600,41 +232,7 @@ void InitUSART3(int speed)
|
|||||||
|
|
||||||
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
|
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
|
||||||
|
|
||||||
// initialize the fifos
|
m_USART3.init(USART3);
|
||||||
TXSerialfifoinit3();
|
|
||||||
RXSerialfifoinit3();
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t AvailUSART3()
|
|
||||||
{
|
|
||||||
if (RXSerialfifolevel3() > 0U)
|
|
||||||
return 1U;
|
|
||||||
else
|
|
||||||
return 0U;
|
|
||||||
}
|
|
||||||
|
|
||||||
int AvailForWriteUSART3()
|
|
||||||
{
|
|
||||||
return TX_SERIAL_FIFO_SIZE - TXSerialfifolevel3();
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t ReadUSART3()
|
|
||||||
{
|
|
||||||
uint8_t data_c = RXSerialfifo3[RXSerialfifotail3];
|
|
||||||
|
|
||||||
RXSerialfifotail3++;
|
|
||||||
if (RXSerialfifotail3 >= RX_SERIAL_FIFO_SIZE)
|
|
||||||
RXSerialfifotail3 = 0U;
|
|
||||||
|
|
||||||
return data_c;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WriteUSART3(const uint8_t* data, uint16_t length)
|
|
||||||
{
|
|
||||||
for (uint16_t i = 0U; i < length; i++)
|
|
||||||
TXSerialfifoput3(data[i]);
|
|
||||||
|
|
||||||
USART_ITConfig(USART3, USART_IT_TXE, ENABLE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -642,111 +240,11 @@ void WriteUSART3(const uint8_t* data, uint16_t length)
|
|||||||
/* ************* UART5 ***************** */
|
/* ************* UART5 ***************** */
|
||||||
#if !(defined(STM32F4_NUCLEO) && defined(STM32F4_NUCLEO_ARDUINO_HEADER))
|
#if !(defined(STM32F4_NUCLEO) && defined(STM32F4_NUCLEO_ARDUINO_HEADER))
|
||||||
|
|
||||||
volatile uint8_t TXSerialfifo5[TX_SERIAL_FIFO_SIZE];
|
static CSTMUART m_UART5;
|
||||||
volatile uint8_t RXSerialfifo5[RX_SERIAL_FIFO_SIZE];
|
|
||||||
volatile uint16_t TXSerialfifohead5, TXSerialfifotail5;
|
|
||||||
volatile uint16_t RXSerialfifohead5, RXSerialfifotail5;
|
|
||||||
|
|
||||||
// Init queues
|
|
||||||
void TXSerialfifoinit5()
|
|
||||||
{
|
|
||||||
TXSerialfifohead5 = 0U;
|
|
||||||
TXSerialfifotail5 = 0U;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RXSerialfifoinit5()
|
|
||||||
{
|
|
||||||
RXSerialfifohead5 = 0U;
|
|
||||||
RXSerialfifotail5 = 0U;
|
|
||||||
}
|
|
||||||
|
|
||||||
// How full is queue
|
|
||||||
// TODO decide if how full or how empty is preferred info to return
|
|
||||||
uint16_t TXSerialfifolevel5()
|
|
||||||
{
|
|
||||||
uint32_t tail = TXSerialfifotail5;
|
|
||||||
uint32_t head = TXSerialfifohead5;
|
|
||||||
|
|
||||||
if (tail > head)
|
|
||||||
return TX_SERIAL_FIFO_SIZE + head - tail;
|
|
||||||
else
|
|
||||||
return head - tail;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t RXSerialfifolevel5()
|
|
||||||
{
|
|
||||||
uint32_t tail = RXSerialfifotail5;
|
|
||||||
uint32_t head = RXSerialfifohead5;
|
|
||||||
|
|
||||||
if (tail > head)
|
|
||||||
return RX_SERIAL_FIFO_SIZE + head - tail;
|
|
||||||
else
|
|
||||||
return head - tail;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Flushes the transmit shift register
|
|
||||||
// warning: this call is blocking
|
|
||||||
void TXSerialFlush5()
|
|
||||||
{
|
|
||||||
// wait until the TXE shows the shift register is empty
|
|
||||||
while (USART_GetITStatus(UART5, USART_FLAG_TXE))
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t TXSerialfifoput5(uint8_t next)
|
|
||||||
{
|
|
||||||
if (TXSerialfifolevel5() < TX_SERIAL_FIFO_SIZE) {
|
|
||||||
TXSerialfifo5[TXSerialfifohead5] = next;
|
|
||||||
|
|
||||||
TXSerialfifohead5++;
|
|
||||||
if (TXSerialfifohead5 >= TX_SERIAL_FIFO_SIZE)
|
|
||||||
TXSerialfifohead5 = 0U;
|
|
||||||
|
|
||||||
// make sure transmit interrupts are enabled as long as there is data to send
|
|
||||||
USART_ITConfig(UART5, USART_IT_TXE, ENABLE);
|
|
||||||
return 1U;
|
|
||||||
} else {
|
|
||||||
return 0U; // signal an overflow occurred by returning a zero count
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void UART5_IRQHandler()
|
void UART5_IRQHandler()
|
||||||
{
|
{
|
||||||
uint8_t c;
|
m_UART5.handleIRQ();
|
||||||
|
|
||||||
if (USART_GetITStatus(UART5, USART_IT_RXNE)) {
|
|
||||||
c = (uint8_t) USART_ReceiveData(UART5);
|
|
||||||
|
|
||||||
if (RXSerialfifolevel5() < RX_SERIAL_FIFO_SIZE) {
|
|
||||||
RXSerialfifo5[RXSerialfifohead5] = c;
|
|
||||||
|
|
||||||
RXSerialfifohead5++;
|
|
||||||
if (RXSerialfifohead5 >= RX_SERIAL_FIFO_SIZE)
|
|
||||||
RXSerialfifohead5 = 0U;
|
|
||||||
} else {
|
|
||||||
// TODO - do something if rx fifo is full?
|
|
||||||
}
|
|
||||||
|
|
||||||
USART_ClearITPendingBit(UART5, USART_IT_RXNE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (USART_GetITStatus(UART5, USART_IT_TXE)) {
|
|
||||||
c = 0U;
|
|
||||||
|
|
||||||
if (TXSerialfifohead5 != TXSerialfifotail5) { // if the fifo is not empty
|
|
||||||
c = TXSerialfifo5[TXSerialfifotail5];
|
|
||||||
|
|
||||||
TXSerialfifotail5++;
|
|
||||||
if (TXSerialfifotail5 >= TX_SERIAL_FIFO_SIZE)
|
|
||||||
TXSerialfifotail5 = 0U;
|
|
||||||
|
|
||||||
USART_SendData(UART5, c);
|
|
||||||
} else { // if there's no more data to transmit then turn off TX interrupts
|
|
||||||
USART_ITConfig(UART5, USART_IT_TXE, DISABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
USART_ClearITPendingBit(UART5, USART_IT_TXE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitUART5(int speed)
|
void InitUART5(int speed)
|
||||||
@@ -795,41 +293,7 @@ void InitUART5(int speed)
|
|||||||
|
|
||||||
USART_ITConfig(UART5, USART_IT_RXNE, ENABLE);
|
USART_ITConfig(UART5, USART_IT_RXNE, ENABLE);
|
||||||
|
|
||||||
// initialize the fifos
|
m_UART5.init(UART5);
|
||||||
TXSerialfifoinit5();
|
|
||||||
RXSerialfifoinit5();
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t AvailUART5()
|
|
||||||
{
|
|
||||||
if (RXSerialfifolevel5() > 0U)
|
|
||||||
return 1U;
|
|
||||||
else
|
|
||||||
return 0U;
|
|
||||||
}
|
|
||||||
|
|
||||||
int AvailForWriteUART5()
|
|
||||||
{
|
|
||||||
return TX_SERIAL_FIFO_SIZE - TXSerialfifolevel5();
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t ReadUART5()
|
|
||||||
{
|
|
||||||
uint8_t data_c = RXSerialfifo5[RXSerialfifotail5];
|
|
||||||
|
|
||||||
RXSerialfifotail5++;
|
|
||||||
if (RXSerialfifotail5 >= RX_SERIAL_FIFO_SIZE)
|
|
||||||
RXSerialfifotail5 = 0U;
|
|
||||||
|
|
||||||
return data_c;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WriteUART5(const uint8_t* data, uint16_t length)
|
|
||||||
{
|
|
||||||
for (uint16_t i = 0U; i < length; i++)
|
|
||||||
TXSerialfifoput5(data[i]);
|
|
||||||
|
|
||||||
USART_ITConfig(UART5, USART_IT_TXE, ENABLE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -868,21 +332,21 @@ int CSerialPort::availableInt(uint8_t n)
|
|||||||
switch (n) {
|
switch (n) {
|
||||||
case 1U:
|
case 1U:
|
||||||
#if defined(STM32F4_DISCOVERY) || defined(STM32F7_NUCLEO)
|
#if defined(STM32F4_DISCOVERY) || defined(STM32F7_NUCLEO)
|
||||||
return AvailUSART3();
|
return m_USART3.availble();//AvailUSART3();
|
||||||
#elif defined(STM32F4_PI) || defined(STM32F4_F4M) || defined(STM32F722_PI) || defined(STM32F722_F7M) || defined(STM32F722_RPT_HAT) || defined(STM32F4_DVM) || defined(STM32F4_EDA_405) || defined(STM32F4_EDA_446)
|
#elif defined(STM32F4_PI) || defined(STM32F4_F4M) || defined(STM32F722_PI) || defined(STM32F722_F7M) || defined(STM32F722_RPT_HAT) || defined(STM32F4_DVM) || defined(STM32F4_EDA_405) || defined(STM32F4_EDA_446)
|
||||||
return AvailUSART1();
|
return m_USART1.available();//AvailUSART1();
|
||||||
#elif defined(STM32F4_NUCLEO) || defined(STM32F4_RPT_HAT_TGO)
|
#elif defined(STM32F4_NUCLEO) || defined(STM32F4_RPT_HAT_TGO)
|
||||||
return AvailUSART2();
|
return m_USART2.available();//AvailUSART2();
|
||||||
#elif defined(DRCC_DVM)
|
#elif defined(DRCC_DVM)
|
||||||
return AvailUSART1();
|
return m_USART1.available();//AvailUSART1();
|
||||||
#endif
|
#endif
|
||||||
case 3U:
|
case 3U:
|
||||||
#if defined(STM32F4_NUCLEO) && defined(STM32F4_NUCLEO_ARDUINO_HEADER)
|
#if defined(STM32F4_NUCLEO) && defined(STM32F4_NUCLEO_ARDUINO_HEADER)
|
||||||
return AvailUSART1();
|
return m_USART1.available(); //AvailUSART1();
|
||||||
#elif defined(DRCC_DVM)
|
#elif defined(DRCC_DVM)
|
||||||
return AvailUSART2();
|
return m_USART2.available(); //AvailUSART2();
|
||||||
#else
|
#else
|
||||||
return AvailUART5();
|
return m_UART5.available();//AvailUART5();
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
@@ -894,21 +358,21 @@ int CSerialPort::availableForWriteInt(uint8_t n)
|
|||||||
switch (n) {
|
switch (n) {
|
||||||
case 1U:
|
case 1U:
|
||||||
#if defined(STM32F4_DISCOVERY) || defined(STM32F7_NUCLEO)
|
#if defined(STM32F4_DISCOVERY) || defined(STM32F7_NUCLEO)
|
||||||
return AvailForWriteUSART3();
|
return m_USART3.availableForWrite(); //AvailForWriteUSART3();
|
||||||
#elif defined(STM32F4_PI) || defined(STM32F4_F4M) || defined(STM32F722_PI) || defined(STM32F722_F7M) || defined(STM32F722_RPT_HAT) || defined(STM32F4_DVM) || defined(STM32F4_EDA_405) || defined(STM32F4_EDA_446)
|
#elif defined(STM32F4_PI) || defined(STM32F4_F4M) || defined(STM32F722_PI) || defined(STM32F722_F7M) || defined(STM32F722_RPT_HAT) || defined(STM32F4_DVM) || defined(STM32F4_EDA_405) || defined(STM32F4_EDA_446)
|
||||||
return AvailForWriteUSART1();
|
return m_USART1.availableForWrite(); //AvailForWriteUSART1();
|
||||||
#elif defined(STM32F4_NUCLEO) || defined(STM32F4_RPT_HAT_TGO)
|
#elif defined(STM32F4_NUCLEO) || defined(STM32F4_RPT_HAT_TGO)
|
||||||
return AvailForWriteUSART2();
|
return m_USART2.availableForWrite();//AvailForWriteUSART2();
|
||||||
#elif defined(DRCC_DVM)
|
#elif defined(DRCC_DVM)
|
||||||
return AvailForWriteUSART1();
|
return m_USART1.availableForWrite();//AvailForWriteUSART1();
|
||||||
#endif
|
#endif
|
||||||
case 3U:
|
case 3U:
|
||||||
#if defined(STM32F4_NUCLEO) && defined(STM32F4_NUCLEO_ARDUINO_HEADER)
|
#if defined(STM32F4_NUCLEO) && defined(STM32F4_NUCLEO_ARDUINO_HEADER)
|
||||||
return AvailForWriteUSART1();
|
return m_USART1.availableForWrite(); //AvailForWriteUSART1();
|
||||||
#elif defined(DRCC_DVM)
|
#elif defined(DRCC_DVM)
|
||||||
return AvailForWriteUSART2();
|
return m_USART2.availableForWrite();//AvailForWriteUSART2();
|
||||||
#else
|
#else
|
||||||
return AvailForWriteUART5();
|
return m_UART5.availableForWrite();//AvailForWriteUART5();
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
@@ -920,21 +384,21 @@ uint8_t CSerialPort::readInt(uint8_t n)
|
|||||||
switch (n) {
|
switch (n) {
|
||||||
case 1U:
|
case 1U:
|
||||||
#if defined(STM32F4_DISCOVERY) || defined(STM32F7_NUCLEO)
|
#if defined(STM32F4_DISCOVERY) || defined(STM32F7_NUCLEO)
|
||||||
return ReadUSART3();
|
return m_USART3.read();//ReadUSART3();
|
||||||
#elif defined(STM32F4_PI) || defined(STM32F4_F4M) || defined(STM32F722_PI) || defined(STM32F722_F7M) || defined(STM32F722_RPT_HAT) || defined(STM32F4_DVM) || defined(STM32F4_EDA_405) || defined(STM32F4_EDA_446)
|
#elif defined(STM32F4_PI) || defined(STM32F4_F4M) || defined(STM32F722_PI) || defined(STM32F722_F7M) || defined(STM32F722_RPT_HAT) || defined(STM32F4_DVM) || defined(STM32F4_EDA_405) || defined(STM32F4_EDA_446)
|
||||||
return ReadUSART1();
|
return m_USART1.read();//ReadUSART1();
|
||||||
#elif defined(STM32F4_NUCLEO) || defined(STM32F4_RPT_HAT_TGO)
|
#elif defined(STM32F4_NUCLEO) || defined(STM32F4_RPT_HAT_TGO)
|
||||||
return ReadUSART2();
|
return m_USART2.read();//ReadUSART2();
|
||||||
#elif defined(DRCC_DVM)
|
#elif defined(DRCC_DVM)
|
||||||
return ReadUSART1();
|
return m_USART1.read();//ReadUSART1();
|
||||||
#endif
|
#endif
|
||||||
case 3U:
|
case 3U:
|
||||||
#if defined(STM32F4_NUCLEO) && defined(STM32F4_NUCLEO_ARDUINO_HEADER)
|
#if defined(STM32F4_NUCLEO) && defined(STM32F4_NUCLEO_ARDUINO_HEADER)
|
||||||
return ReadUSART1();
|
return m_USART1.read();//ReadUSART1();
|
||||||
#elif defined(DRCC_DVM)
|
#elif defined(DRCC_DVM)
|
||||||
return ReadUSART2();
|
return m_USART2.read();//ReadUSART2();
|
||||||
#else
|
#else
|
||||||
return ReadUART5();
|
return m_UART5.read();//ReadUART5();
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
return 0U;
|
return 0U;
|
||||||
@@ -946,36 +410,36 @@ void CSerialPort::writeInt(uint8_t n, const uint8_t* data, uint16_t length, bool
|
|||||||
switch (n) {
|
switch (n) {
|
||||||
case 1U:
|
case 1U:
|
||||||
#if defined(STM32F4_DISCOVERY) || defined(STM32F7_NUCLEO)
|
#if defined(STM32F4_DISCOVERY) || defined(STM32F7_NUCLEO)
|
||||||
WriteUSART3(data, length);
|
m_USART3.write(data, length); //WriteUSART3(data, length);
|
||||||
if (flush)
|
if (flush)
|
||||||
TXSerialFlush3();
|
m_USART3.flush();//TXSerialFlush3();
|
||||||
#elif defined(STM32F4_PI) || defined(STM32F4_F4M) || defined(STM32F722_PI) || defined(STM32F722_F7M) || defined(STM32F722_RPT_HAT) || defined(STM32F4_DVM) || defined(STM32F4_EDA_405) || defined(STM32F4_EDA_446)
|
#elif defined(STM32F4_PI) || defined(STM32F4_F4M) || defined(STM32F722_PI) || defined(STM32F722_F7M) || defined(STM32F722_RPT_HAT) || defined(STM32F4_DVM) || defined(STM32F4_EDA_405) || defined(STM32F4_EDA_446)
|
||||||
WriteUSART1(data, length);
|
m_USART1.write(data, length);//WriteUSART1(data, length);
|
||||||
if (flush)
|
if (flush)
|
||||||
TXSerialFlush1();
|
m_USART1.flush();//TXSerialFlush1();
|
||||||
#elif defined(STM32F4_NUCLEO) || defined(STM32F4_RPT_HAT_TGO)
|
#elif defined(STM32F4_NUCLEO) || defined(STM32F4_RPT_HAT_TGO)
|
||||||
WriteUSART2(data, length);
|
m_USART2.write(data, length);//WriteUSART2(data, length);
|
||||||
if (flush)
|
if (flush)
|
||||||
TXSerialFlush2();
|
m_USART2.flush();//TXSerialFlush2();
|
||||||
#elif defined(DRCC_DVM)
|
#elif defined(DRCC_DVM)
|
||||||
WriteUSART1(data, length);
|
m_USART1.write(data, length);//WriteUSART1(data, length);
|
||||||
if (flush)
|
if (flush)
|
||||||
TXSerialFlush1();
|
m_USART1.flush();//TXSerialFlush1();
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
case 3U:
|
case 3U:
|
||||||
#if defined(STM32F4_NUCLEO) && defined(STM32F4_NUCLEO_ARDUINO_HEADER)
|
#if defined(STM32F4_NUCLEO) && defined(STM32F4_NUCLEO_ARDUINO_HEADER)
|
||||||
WriteUSART1(data, length);
|
m_USART1.write(data, length); //WriteUSART1(data, length);
|
||||||
if (flush)
|
if (flush)
|
||||||
TXSerialFlush1();
|
m_USART1.flush();
|
||||||
#elif defined(DRCC_DVM)
|
#elif defined(DRCC_DVM)
|
||||||
WriteUSART2(data, length);
|
m_USART2.write(data, length);//WriteUSART2(data, length);
|
||||||
if (flush)
|
if (flush)
|
||||||
TXSerialFlush2();
|
m_USART2.flush();//TXSerialFlush2();
|
||||||
#else
|
#else
|
||||||
WriteUART5(data, length);
|
m_UART5.write(data, length);//WriteUART5(data, length);
|
||||||
if (flush)
|
if (flush)
|
||||||
TXSerialFlush5();
|
m_UART5.flush();//TXSerialFlush5();
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -984,3 +448,4 @@ void CSerialPort::writeInt(uint8_t n, const uint8_t* data, uint16_t length, bool
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -17,30 +17,30 @@ f2 = 2700
|
|||||||
rp = 0.2
|
rp = 0.2
|
||||||
|
|
||||||
# scaling factor in bits, do not change !
|
# scaling factor in bits, do not change !
|
||||||
q = 0
|
q = 15
|
||||||
# scaling factor as facor...
|
# scaling factor as facor...
|
||||||
scaling_factor = 2**q
|
scaling_factor = 2**q
|
||||||
|
|
||||||
# let's generate a sequence of 2nd order IIR filters
|
# let's generate a sequence of 2nd order IIR filters
|
||||||
sos = signal.cheby1(3,rp,[f1, f2],'bandpass', output='sos', fs=fs)
|
sos = signal.cheby1(3,rp,[f1, f2],'bandpass', output='sos', fs=fs)
|
||||||
#sos = signal.cheby1(1, rp, 2122, 'lowpass', output='sos', fs=fs) #deemphasis filter
|
#os = signal.cheby1(4, rp, f2, 'lowpass', output='sos', fs=fs) #deemphasis filter
|
||||||
#sos = signal.cheby1(1, rp, 2122, 'highpass', output='sos', fs=fs) #deemphasis filter
|
#sos = signal.cheby1(1, rp, 2122, 'highpass', output='sos', fs=fs) #deemphasis filter
|
||||||
|
|
||||||
#sos = np.round((sos) * scaling_factor)
|
sosrounded = np.round((sos) * scaling_factor)
|
||||||
|
|
||||||
# print coefficients
|
# print coefficients
|
||||||
for biquad in sos:
|
for biquad in sosrounded:
|
||||||
for coeff in biquad:
|
for coeff in biquad:
|
||||||
#print(int(coeff),",",sep="",end="")
|
print(int(coeff),",",sep="",end="")
|
||||||
print((coeff),",",sep="",end="")
|
#print((coeff),",",sep="",end="")
|
||||||
print("")
|
print("")
|
||||||
|
|
||||||
# plot the frequency response
|
# plot the frequency response
|
||||||
b,a = signal.sos2tf(sos)
|
b,a = signal.sos2tf(sos)
|
||||||
w,h = signal.freqz(b,a)
|
w,h = signal.freqz(b,a, worN=2048)
|
||||||
pl.plot(w/np.pi/2*fs,20*np.log(np.abs(h)))
|
pl.plot(w/np.pi/2*fs,20*np.log(np.abs(h)))
|
||||||
pl.xlabel('frequency/Hz');
|
pl.xlabel('frequency/Hz');
|
||||||
pl.ylabel('gain/dB');
|
pl.ylabel('gain/dB');
|
||||||
pl.ylim(top=1,bottom=-20);
|
pl.ylim(top=1,bottom=-30);
|
||||||
pl.xlim(left=250, right=12000);
|
pl.xlim(left=250, right=12000);
|
||||||
pl.show()
|
pl.show()
|
||||||
@@ -73,7 +73,8 @@ void CYSFTX::process()
|
|||||||
m_poBuffer[m_poLen++] = YSF_START_SYNC;
|
m_poBuffer[m_poLen++] = YSF_START_SYNC;
|
||||||
} else {
|
} else {
|
||||||
for (uint8_t i = 0U; i < YSF_FRAME_LENGTH_BYTES; i++) {
|
for (uint8_t i = 0U; i < YSF_FRAME_LENGTH_BYTES; i++) {
|
||||||
uint8_t c = m_buffer.get();
|
uint8_t c = 0U;
|
||||||
|
m_buffer.get(c);
|
||||||
m_poBuffer[m_poLen++] = c;
|
m_poBuffer[m_poLen++] = c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
|
||||||
#include "SerialRB.h"
|
#include "RingBuffer.h"
|
||||||
|
|
||||||
class CYSFTX {
|
class CYSFTX {
|
||||||
public:
|
public:
|
||||||
@@ -38,7 +38,7 @@ public:
|
|||||||
void setParams(bool on, uint8_t txHang);
|
void setParams(bool on, uint8_t txHang);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CSerialRB m_buffer;
|
CRingBuffer<uint8_t> m_buffer;
|
||||||
arm_fir_interpolate_instance_q15 m_modFilter;
|
arm_fir_interpolate_instance_q15 m_modFilter;
|
||||||
q15_t m_modState[16U]; // blockSize + phaseLength - 1, 4 + 9 - 1 plus some spare
|
q15_t m_modState[16U]; // blockSize + phaseLength - 1, 4 + 9 - 1 plus some spare
|
||||||
uint8_t m_poBuffer[1200U];
|
uint8_t m_poBuffer[1200U];
|
||||||
|
|||||||
Reference in New Issue
Block a user