Compare commits

..
46 Commits
Author SHA1 Message Date
Jonathan Naylor 73866ab591 Merge branch 'M17_AX25_FM' into I2C 2021-05-08 23:49:51 +01:00
Jonathan Naylor ed84db6ee4 Merge branch 'M17_AX25_FM' into I2C 2021-05-08 23:25:57 +01:00
Jonathan Naylor 406a60d787 Merge branch 'M17_AX25_FM' into I2C 2021-05-05 21:01:38 +01:00
Jonathan Naylor f06774aadd Fix mistakes in the OLED initialisation values. 2021-04-24 12:47:59 +01:00
Jonathan Naylor e32f13d3df Merge branch 'M17_AX25_FM' into I2C 2021-04-20 20:38:48 +01:00
Jonathan Naylor 7db7bbb02e Re-add the STM32F7XX_Lib submodule. 2021-04-13 19:22:28 +01:00
Jonathan Naylor 794acf1df8 Remove the STM32F7XX_Lib submodule. 2021-04-13 19:06:45 +01:00
Jonathan Naylor 02ba20401b Include the GPIO initialisation for I2C3. 2021-04-12 21:50:27 +01:00
Jonathan Naylor ee3ab88b2a Extract the HAL functions and explicitely initailise I2C3. 2021-04-12 19:50:57 +01:00
Jonathan Naylor a5d4295cce Add the STM32F7XX_Lib tree as part of the MMDVM repository 2021-04-12 18:32:00 +01:00
Jonathan Naylor 1e97e7c2a0 Remove STM32F7XX_Lib as a submodule 2021-04-12 18:30:17 +01:00
Jonathan Naylor 246539526d Fix compilation issues with a compiler. 2021-04-12 18:28:27 +01:00
Jonathan Naylor 3c6a1f262a Begin synchronising the code with the STM32Cube HAL code. 2021-04-12 17:19:58 +01:00
Jonathan Naylor 51b275d4c7 Simplify the data transfer. 2021-04-11 23:24:23 +01:00
Jonathan Naylor 639caa03ee Simplify the OLED text creation code. 2021-04-11 21:49:20 +01:00
Jonathan Naylor 4f3e6935d2 Simplify the OLED initialisation. 2021-04-11 20:43:28 +01:00
Jonathan Naylor a3e0ad82e2 More I2C changes. 2021-04-11 20:34:42 +01:00
Jonathan Naylor 4aa30664b9 Rename the I2 port class. 2021-04-11 20:31:10 +01:00
Jonathan Naylor c83879d89d Simplify the I2C display support. 2021-04-11 20:22:46 +01:00
Jonathan Naylor 683c5afccb Merge branch 'M17_AX25_FM' into I2C 2021-04-11 18:15:55 +01:00
Jonathan Naylor c70540a8ac Merge branch 'M17_AX25_FM' into I2C 2021-04-08 18:11:21 +01:00
Jonathan Naylor 93115c8931 Merge branch 'M17_AX25_FM' into I2C 2021-03-07 19:02:57 +00:00
Jonathan Naylor 2ae731e78c Use information from STM32Cube to update the I2C driver. 2021-02-28 13:23:17 +00:00
Jonathan Naylor f033fea2fb Update for the STM32F722. 2021-01-31 23:23:32 +00:00
Jonathan Naylor 4539f48af2 Merge branch 'M17_AX25_FM' into I2C 2021-01-02 12:24:48 +00:00
Jonathan Naylor 8747794e27 Merge branch 'M17_AX25_FM' into I2C 2021-01-01 13:18:07 +00:00
Jonathan Naylor e94f5bb13a Merge branch 'M17_AX25_FM' into I2C 2020-12-26 12:43:04 +00:00
Jonathan Naylor 28a0910638 Merge branch 'M17_AX25_FM' into I2C 2020-12-14 09:54:03 +00:00
Jonathan Naylor 2dd8b74346 Merge branch 'M17_AX25_FM' into I2C 2020-11-30 09:11:43 +00:00
Jonathan Naylor 2190dc1042 Merge branch 'M17_AX25_FM' into I2C 2020-11-26 10:05:13 +00:00
Jonathan Naylor 9b76867548 Merge branch 'M17_AX25_FM' into I2C 2020-11-24 16:22:47 +00:00
Jonathan Naylor df749d3286 Use a proper master I2C driver. 2020-11-24 10:46:25 +00:00
Jonathan Naylor 5e8e0577da More work on the low-level I2C handler. 2020-11-23 15:29:28 +00:00
Jonathan Naylor 6c8cf7a838 Most of the I2C work completed, now need to review the low-level I2C code. 2020-11-23 14:24:14 +00:00
Jonathan Naylor 112a136060 Add the OLED display handling code. 2020-11-23 12:11:59 +00:00
Jonathan Naylor b4ff147a19 Begin the display of the modes on the display. 2020-11-23 11:00:43 +00:00
Jonathan Naylor 757c3ce0d5 Merge branch 'M17_AX25_FM' into I2C 2020-11-20 10:37:49 +00:00
Jonathan Naylor a119311d93 Add the TX FIFO the I2C driver. 2020-11-19 16:50:21 +00:00
Jonathan Naylor 7f7ce2072a Start filling in the I2C initialisation code. 2020-11-19 14:55:53 +00:00
Jonathan Naylor 1978b2b357 Small code updates to the new I2C driver. 2020-11-19 13:34:41 +00:00
Jonathan Naylor 6f1fe8d4b9 Merge branch 'M17_AX25_FM' into I2C 2020-11-18 20:35:40 +00:00
Jonathan Naylor f0804b46e5 Add skeleton I2C files. 2020-11-18 20:21:36 +00:00
Jonathan Naylor 2285f9bd82 Initial I2C driver code. 2020-11-18 14:06:18 +00:00
Jonathan Naylor 53b5659639 Merge branch 'M17_AX25_FM' into I2C 2020-11-17 10:37:37 +00:00
Jonathan Naylor 864dfa9221 Merge branch 'M17_AX25_FM' into I2C 2020-11-17 10:08:54 +00:00
Jonathan Naylor 335c32c540 I2C support is write only. 2020-11-15 17:51:10 +00:00
65 changed files with 5824 additions and 757 deletions
-2
View File
@@ -1,5 +1,3 @@
.pio
.vscode
*.o *.o
obj/ obj/
bin/ bin/
+4 -1
View File
@@ -1,6 +1,9 @@
[submodule "STM32F4XX_Lib"] [submodule "STM32F4XX_Lib"]
path = STM32F4XX_Lib path = STM32F4XX_Lib
url = https://github.com/juribeparada/STM32F4XX_Lib.git url = https://github.com/juribeparada/STM32F4XX_Lib.git
[submodule "STM32F10X_Lib"]
path = STM32F10X_Lib
url = https://github.com/shawnchain/STM32F10X_Lib.git
[submodule "STM32F7XX_Lib"] [submodule "STM32F7XX_Lib"]
path = STM32F7XX_Lib path = STM32F7XX_Lib
url = https://github.com/juribeparada/STM32F7XX_Lib.git url = https://github.com/g4klx/STM32F7XX_Lib.git
+36
View File
@@ -0,0 +1,36 @@
/*
* 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(AX25DEFINES_H)
#define AX25DEFINES_H
const uint8_t AX25_RADIO_SYMBOL_LENGTH = 20U; // At 24 kHz sample rate
const uint8_t AX25_FRAME_START = 0x7EU;
const uint8_t AX25_FRAME_END = 0x7EU;
const uint8_t AX25_FRAME_ABORT = 0xFEU;
const uint8_t AX25_MAX_ONES = 5U;
const uint16_t AX25_MIN_FRAME_LENGTH = 17U; // Callsign (7) + Callsign (7) + Control (1) + Checksum (2)
const uint16_t AX25_MAX_FRAME_LENGTH = 330U; // Callsign (7) + Callsign (7) + 8 Digipeaters (56) +
// Control (1) + PID (1) + Data (256) + Checksum (2)
#endif
+319
View File
@@ -0,0 +1,319 @@
/*
* Copyright (C) 2020 by Jonathan Naylor G4KLX
* Copyright 2015-2019 Mobilinkd LLC <[email protected]>
*
* 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"
#if defined(MODE_AX25)
#include "Globals.h"
#include "AX25Demodulator.h"
#include "AX25Defines.h"
const float32_t SAMPLE_RATE = 24000.0F;
const float32_t SYMBOL_RATE = 1200.0F;
const uint16_t DELAY_LEN = 11U;
const float32_t SAMPLES_PER_SYMBOL = SAMPLE_RATE / SYMBOL_RATE;
const float32_t PLL_LIMIT = SAMPLES_PER_SYMBOL / 2.0F;
const uint32_t LPF_FILTER_LEN = 48U;
q15_t LPF_FILTER_COEFFS[] = {
-2, -8, -17, -28, -40, -47, -47, -34,
-5, 46, 122, 224, 354, 510, 689, 885,
1092, 1302, 1506, 1693, 1856, 1987, 2077, 2124,
2124, 2077, 1987, 1856, 1693, 1506, 1302, 1092,
885, 689, 510, 354, 224, 122, 46, -5,
-34, -47, -47, -40, -28, -17, -8, -2
};
// 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.
// scipy.signal:
// loop_coeffs = firwin(9, [64.0/(1200/2)], width = None,
// pass_zero = True, scale = True, window='hann')
//
const uint32_t PLL_FILTER_LEN = 7U;
float32_t PLL_FILTER_COEFFS[] = {3.196252e-02F, 1.204223e-01F, 2.176819e-01F, 2.598666e-01F, 2.176819e-01F, 1.204223e-01F, 3.196252e-02F};
CAX25Demodulator::CAX25Demodulator(int8_t n) :
m_frame(),
m_twist(n),
m_lpfFilter(),
m_lpfState(),
m_delayLine(NULL),
m_delayPos(0U),
m_nrziState(false),
m_pllFilter(),
m_pllState(),
m_pllLast(false),
m_pllBits(1U),
m_pllCount(0.0F),
m_pllJitter(0.0F),
m_pllDCD(false),
m_iirHistory(),
m_hdlcOnes(0U),
m_hdlcFlag(false),
m_hdlcBuffer(0U),
m_hdlcBits(0U),
m_hdlcState(AX25_IDLE)
{
m_delayLine = new bool[DELAY_LEN];
m_lpfFilter.numTaps = LPF_FILTER_LEN;
m_lpfFilter.pState = m_lpfState;
m_lpfFilter.pCoeffs = LPF_FILTER_COEFFS;
m_pllFilter.numTaps = PLL_FILTER_LEN;
m_pllFilter.pState = m_pllState;
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 result = false;
q15_t fa[RX_BLOCK_SIZE];
m_twist.process(samples, fa, RX_BLOCK_SIZE);
int16_t buffer[RX_BLOCK_SIZE];
for (uint8_t i = 0; i < length; i++) {
bool level = (fa[i] >= 0);
bool delayed = delay(level);
buffer[i] = (int16_t(level ^ delayed) << 1) - 1;
}
q15_t fc[RX_BLOCK_SIZE];
::arm_fir_fast_q15(&m_lpfFilter, buffer, fc, RX_BLOCK_SIZE);
for (uint8_t i = 0; i < length; i++) {
bool bit = fc[i] >= 0;
bool sample = PLL(bit);
if (sample) {
// We will only ever get one frame because there are
// not enough bits in a block for more than one.
if (result) {
HDLC(NRZI(bit));
} else {
result = HDLC(NRZI(bit));
if (result) {
// Copy the frame data.
::memcpy(frame.m_data, m_frame.m_data, AX25_MAX_PACKET_LEN);
frame.m_length = m_frame.m_length;
frame.m_fcs = m_frame.m_fcs;
m_frame.m_length = 0U;
}
}
}
}
return result;
}
bool CAX25Demodulator::delay(bool b)
{
bool r = m_delayLine[m_delayPos];
m_delayLine[m_delayPos++] = b;
if (m_delayPos >= DELAY_LEN)
m_delayPos = 0U;
return r;
}
bool CAX25Demodulator::NRZI(bool b)
{
bool result = (b == m_nrziState);
m_nrziState = b;
return result;
}
bool CAX25Demodulator::PLL(bool input)
{
bool sample = false;
if (input != m_pllLast || m_pllBits > 16U) {
// Record transition.
m_pllLast = input;
if (m_pllCount > PLL_LIMIT)
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 jitter;
::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_pllBits = 1U;
} else {
if (m_pllCount > PLL_LIMIT) {
sample = true;
m_pllCount -= SAMPLES_PER_SYMBOL;
m_pllBits++;
}
}
m_pllCount += 1.0F;
return sample;
}
bool CAX25Demodulator::HDLC(bool b)
{
if (m_hdlcOnes == AX25_MAX_ONES) {
if (b) {
// flag byte
m_hdlcFlag = true;
} else {
// bit stuffing...
m_hdlcFlag = false;
m_hdlcOnes = 0U;
return false;
}
}
m_hdlcBuffer >>= 1;
m_hdlcBuffer |= b ? 128U : 0U;
m_hdlcBits++; // Free-running until Sync byte.
if (b)
m_hdlcOnes++;
else
m_hdlcOnes = 0U;
if (m_hdlcFlag) {
bool result = false;
switch (m_hdlcBuffer) {
case AX25_FRAME_END:
if (m_frame.m_length >= AX25_MIN_FRAME_LENGTH) {
result = m_frame.checkCRC();
if (!result)
m_frame.m_length = 0U;
} else {
m_frame.m_length = 0U;
}
m_hdlcState = AX25_SYNC;
m_hdlcFlag = false;
m_hdlcBits = 0U;
break;
case AX25_FRAME_ABORT:
// Frame aborted
m_frame.m_length = 0U;
m_hdlcState = AX25_IDLE;
m_hdlcFlag = false;
m_hdlcBits = 0U;
break;
default:
break;
}
return result;
}
switch (m_hdlcState) {
case AX25_IDLE:
break;
case AX25_SYNC:
if (m_hdlcBits == 8U) { // 8th bit.
// Start of frame data.
m_hdlcState = AX25_RECEIVE;
m_frame.append(m_hdlcBuffer);
m_hdlcBits = 0U;
}
break;
case AX25_RECEIVE:
if (m_hdlcBits == 8U) { // 8th bit.
m_frame.append(m_hdlcBuffer);
m_hdlcBits = 0U;
}
break;
default:
break;
}
return false;
}
void CAX25Demodulator::setTwist(int8_t 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;
}
#endif
+77
View File
@@ -0,0 +1,77 @@
/*
* 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"
#if defined(MODE_AX25)
#if !defined(AX25Demodulator_H)
#define AX25Demodulator_H
#include "AX25Frame.h"
#include "AX25Twist.h"
enum AX25_STATE {
AX25_IDLE,
AX25_SYNC,
AX25_RECEIVE
};
class CAX25Demodulator {
public:
CAX25Demodulator(int8_t n);
bool process(q15_t* samples, uint8_t length, CAX25Frame& frame);
void setTwist(int8_t n);
bool isDCD();
private:
CAX25Frame m_frame;
CAX25Twist m_twist;
arm_fir_instance_q15 m_lpfFilter;
q15_t m_lpfState[70U]; // NoTaps + BlockSize - 1, 48 + 20 - 1 plus some spare
bool* m_delayLine;
uint16_t m_delayPos;
bool m_nrziState;
arm_fir_instance_f32 m_pllFilter;
float32_t m_pllState[20U]; // NoTaps + BlockSize - 1, 7 + 1 - 1 plus some spare
bool m_pllLast;
uint8_t m_pllBits;
float32_t m_pllCount;
float32_t m_pllJitter;
bool m_pllDCD;
float32_t m_iirHistory[5U];
uint16_t m_hdlcOnes;
bool m_hdlcFlag;
uint16_t m_hdlcBuffer;
uint16_t m_hdlcBits;
AX25_STATE m_hdlcState;
bool delay(bool b);
bool NRZI(bool b);
bool PLL(bool b);
bool HDLC(bool b);
float32_t iir(float32_t input);
};
#endif
#endif
+127
View File
@@ -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"
#if defined(MODE_AX25)
#include "Globals.h"
#include "AX25Frame.h"
const uint16_t CCITT_TABLE[] = {
0x0000,0x1189,0x2312,0x329b,0x4624,0x57ad,0x6536,0x74bf,
0x8c48,0x9dc1,0xaf5a,0xbed3,0xca6c,0xdbe5,0xe97e,0xf8f7,
0x1081,0x0108,0x3393,0x221a,0x56a5,0x472c,0x75b7,0x643e,
0x9cc9,0x8d40,0xbfdb,0xae52,0xdaed,0xcb64,0xf9ff,0xe876,
0x2102,0x308b,0x0210,0x1399,0x6726,0x76af,0x4434,0x55bd,
0xad4a,0xbcc3,0x8e58,0x9fd1,0xeb6e,0xfae7,0xc87c,0xd9f5,
0x3183,0x200a,0x1291,0x0318,0x77a7,0x662e,0x54b5,0x453c,
0xbdcb,0xac42,0x9ed9,0x8f50,0xfbef,0xea66,0xd8fd,0xc974,
0x4204,0x538d,0x6116,0x709f,0x0420,0x15a9,0x2732,0x36bb,
0xce4c,0xdfc5,0xed5e,0xfcd7,0x8868,0x99e1,0xab7a,0xbaf3,
0x5285,0x430c,0x7197,0x601e,0x14a1,0x0528,0x37b3,0x263a,
0xdecd,0xcf44,0xfddf,0xec56,0x98e9,0x8960,0xbbfb,0xaa72,
0x6306,0x728f,0x4014,0x519d,0x2522,0x34ab,0x0630,0x17b9,
0xef4e,0xfec7,0xcc5c,0xddd5,0xa96a,0xb8e3,0x8a78,0x9bf1,
0x7387,0x620e,0x5095,0x411c,0x35a3,0x242a,0x16b1,0x0738,
0xffcf,0xee46,0xdcdd,0xcd54,0xb9eb,0xa862,0x9af9,0x8b70,
0x8408,0x9581,0xa71a,0xb693,0xc22c,0xd3a5,0xe13e,0xf0b7,
0x0840,0x19c9,0x2b52,0x3adb,0x4e64,0x5fed,0x6d76,0x7cff,
0x9489,0x8500,0xb79b,0xa612,0xd2ad,0xc324,0xf1bf,0xe036,
0x18c1,0x0948,0x3bd3,0x2a5a,0x5ee5,0x4f6c,0x7df7,0x6c7e,
0xa50a,0xb483,0x8618,0x9791,0xe32e,0xf2a7,0xc03c,0xd1b5,
0x2942,0x38cb,0x0a50,0x1bd9,0x6f66,0x7eef,0x4c74,0x5dfd,
0xb58b,0xa402,0x9699,0x8710,0xf3af,0xe226,0xd0bd,0xc134,
0x39c3,0x284a,0x1ad1,0x0b58,0x7fe7,0x6e6e,0x5cf5,0x4d7c,
0xc60c,0xd785,0xe51e,0xf497,0x8028,0x91a1,0xa33a,0xb2b3,
0x4a44,0x5bcd,0x6956,0x78df,0x0c60,0x1de9,0x2f72,0x3efb,
0xd68d,0xc704,0xf59f,0xe416,0x90a9,0x8120,0xb3bb,0xa232,
0x5ac5,0x4b4c,0x79d7,0x685e,0x1ce1,0x0d68,0x3ff3,0x2e7a,
0xe70e,0xf687,0xc41c,0xd595,0xa12a,0xb0a3,0x8238,0x93b1,
0x6b46,0x7acf,0x4854,0x59dd,0x2d62,0x3ceb,0x0e70,0x1ff9,
0xf78f,0xe606,0xd49d,0xc514,0xb1ab,0xa022,0x92b9,0x8330,
0x7bc7,0x6a4e,0x58d5,0x495c,0x3de3,0x2c6a,0x1ef1,0x0f78 };
CAX25Frame::CAX25Frame(const uint8_t* data, uint16_t length) :
m_data(),
m_length(0U),
m_fcs(0U)
{
for (uint16_t i = 0U; i < length && i < (AX25_MAX_PACKET_LEN - 2U); i++)
m_data[m_length++] = data[i];
}
CAX25Frame::CAX25Frame() :
m_data(),
m_length(0U),
m_fcs(0U)
{
}
bool CAX25Frame::append(uint16_t c)
{
if (m_length == AX25_MAX_PACKET_LEN)
return false;
m_data[m_length++] = uint8_t(c);
return true;
}
bool CAX25Frame::checkCRC()
{
union {
uint16_t crc16;
uint8_t crc8[2U];
};
crc16 = 0xFFFFU;
for (uint16_t i = 0U; i < (m_length - 2U); i++)
crc16 = uint16_t(crc8[1U]) ^ CCITT_TABLE[crc8[0U] ^ m_data[i]];
crc16 = ~crc16;
if (crc8[0U] == m_data[m_length - 2U] && crc8[1U] == m_data[m_length - 1U]) {
m_fcs = crc16;
return true;
} else {
return false;
}
}
void CAX25Frame::addCRC()
{
union {
uint16_t crc16;
uint8_t crc8[2U];
};
crc16 = 0xFFFFU;
for (uint16_t i = 0U; i < m_length; i++)
crc16 = uint16_t(crc8[1U]) ^ CCITT_TABLE[crc8[0U] ^ m_data[i]];
crc16 = ~crc16;
m_fcs = crc16;
m_data[m_length++] = crc8[0U];
m_data[m_length++] = crc8[1U];
}
#endif
+47
View File
@@ -0,0 +1,47 @@
/*
* 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"
#if defined(MODE_AX25)
#if !defined(AX25Frame_H)
#define AX25Frame_H
const uint16_t AX25_MAX_PACKET_LEN = 300U;
class CAX25Frame {
public:
CAX25Frame(const uint8_t* data, uint16_t length);
CAX25Frame();
bool append(uint16_t c);
bool checkCRC();
void addCRC();
uint8_t m_data[AX25_MAX_PACKET_LEN];
uint16_t m_length;
uint16_t m_fcs;
};
#endif
#endif
+211
View File
@@ -0,0 +1,211 @@
/*
* 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"
#if defined(MODE_AX25)
#include "Globals.h"
#include "AX25RX.h"
/*
* Generated with Scipy Filter, 152 coefficients, 1100-2300Hz bandpass,
* Hann window, starting and ending 0 value coefficients removed.
*
* np.array(
* firwin2(152,
* [
* 0.0,
* 1000.0/(sample_rate/2),
* 1100.0/(sample_rate/2),
* 2350.0/(sample_rate/2),
* 2500.0/(sample_rate/2),
* 1.0
* ],
* [0,0,1,1,0,0],
* antisymmetric = False,
* window='hann') * 32768,
* dtype=int)[10:-10]
*/
const uint32_t FILTER_LEN = 130U;
q15_t FILTER_COEFFS[] = {
5, 12, 18, 21, 19, 11, -2, -15, -25, -27,
-21, -11, -3, -5, -19, -43, -69, -83, -73, -35,
27, 98, 155, 180, 163, 109, 39, -20, -45, -26,
23, 74, 89, 39, -81, -247, -407, -501, -480, -334,
-92, 175, 388, 479, 429, 275, 99, 5, 68, 298,
626, 913, 994, 740, 115, -791, -1770, -2544, -2847, -2509,
-1527, -76, 1518, 2875, 3653, 3653, 2875, 1518, -76, -1527,
-2509, -2847, -2544, -1770, -791, 115, 740, 994, 913, 626,
298, 68, 5, 99, 275, 429, 479, 388, 175, -92,
-334, -480, -501, -407, -247, -81, 39, 89, 74, 23,
-26, -45, -20, 39, 109, 163, 180, 155, 98, 27,
-35, -73, -83, -69, -43, -19, -5, -3, -11, -21,
-27, -25, -15, -2, 11, 19, 21, 18, 12, 5
};
CAX25RX::CAX25RX() :
m_filter(),
m_state(),
m_demod1(3),
m_demod2(6),
m_demod3(9),
m_lastFCS(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.pState = m_state;
m_filter.pCoeffs = FILTER_COEFFS;
initRand();
}
void CAX25RX::samples(q15_t* samples, uint8_t length)
{
q15_t output[RX_BLOCK_SIZE];
::arm_fir_fast_q15(&m_filter, samples, output, RX_BLOCK_SIZE);
m_count++;
CAX25Frame frame;
bool ret = m_demod1.process(output, length, frame);
if (ret) {
if (frame.m_fcs != m_lastFCS || m_count > 2U) {
m_lastFCS = frame.m_fcs;
m_count = 0U;
serial.writeAX25Data(frame.m_data, frame.m_length - 2U);
}
DEBUG1("Decoder 1 reported");
}
ret = m_demod2.process(output, length, frame);
if (ret) {
if (frame.m_fcs != m_lastFCS || m_count > 2U) {
m_lastFCS = frame.m_fcs;
m_count = 0U;
serial.writeAX25Data(frame.m_data, frame.m_length - 2U);
}
DEBUG1("Decoder 2 reported");
}
ret = m_demod3.process(output, length, frame);
if (ret) {
if (frame.m_fcs != m_lastFCS || m_count > 2U) {
m_lastFCS = frame.m_fcs;
m_count = 0U;
serial.writeAX25Data(frame.m_data, frame.m_length - 2U);
}
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();
}
}
}
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_demod2.setTwist(twist);
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
}
#endif
+63
View File
@@ -0,0 +1,63 @@
/*
* 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"
#if defined(MODE_AX25)
#if !defined(AX25RX_H)
#define AX25RX_H
#include "AX25Demodulator.h"
class CAX25RX {
public:
CAX25RX();
void samples(q15_t* samples, uint8_t length);
void setParams(int8_t twist, uint8_t slotTime, uint8_t pPersist);
bool canTX() const;
private:
arm_fir_instance_q15 m_filter;
q15_t m_state[160U]; // NoTaps + BlockSize - 1, 130 + 20 - 1 plus some spare
CAX25Demodulator m_demod1;
CAX25Demodulator m_demod2;
CAX25Demodulator m_demod3;
uint16_t m_lastFCS;
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
+191
View File
@@ -0,0 +1,191 @@
/*
* 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"
#if defined(MODE_AX25)
#include "Globals.h"
#include "AX25TX.h"
#include "AX25Defines.h"
#include "AX25Frame.h"
const uint8_t START_FLAG[] = { AX25_FRAME_START };
const uint8_t END_FLAG[] = { AX25_FRAME_END };
const uint8_t BIT_MASK_TABLE1[] = { 0x80U, 0x40U, 0x20U, 0x10U, 0x08U, 0x04U, 0x02U, 0x01U };
#define WRITE_BIT1(p,i,b) p[(i)>>3] = (b) ? (p[(i)>>3] | BIT_MASK_TABLE1[(i)&7]) : (p[(i)>>3] & ~BIT_MASK_TABLE1[(i)&7])
#define READ_BIT1(p,i) (p[(i)>>3] & BIT_MASK_TABLE1[(i)&7])
const uint8_t BIT_MASK_TABLE2[] = { 0x01U, 0x02U, 0x04U, 0x08U, 0x10U, 0x20U, 0x40U, 0x80U };
#define WRITE_BIT2(p,i,b) p[(i)>>3] = (b) ? (p[(i)>>3] | BIT_MASK_TABLE2[(i)&7]) : (p[(i)>>3] & ~BIT_MASK_TABLE2[(i)&7])
#define READ_BIT2(p,i) (p[(i)>>3] & BIT_MASK_TABLE2[(i)&7])
const uint16_t AUDIO_TABLE_LEN = 120U;
const q15_t AUDIO_TABLE_DATA[] = {
0, 214, 428, 641, 851, 1060, 1265, 1468, 1666, 1859, 2048, 2230, 2407, 2577, 2740, 2896, 3043, 3182, 3313, 3434, 3546, 3649,
3741, 3823, 3895, 3955, 4006, 4045, 4073, 4089, 4095, 4089, 4073, 4045, 4006, 3955, 3895, 3823, 3741, 3649, 3546, 3434, 3313,
3182, 3043, 2896, 2740, 2577, 2407, 2230, 2048, 1859, 1666, 1468, 1265, 1060, 851, 641, 428, 214, 0, -214, -428, -641, -851,
-1060, -1265, -1468, -1666, -1859, -2047, -2230, -2407, -2577, -2740, -2896, -3043, -3182, -3313, -3434, -3546, -3649, -3741,
-3823, -3895, -3955, -4006, -4045, -4073, -4089, -4095, -4089, -4073, -4045, -4006, -3955, -3895, -3823, -3741, -3649, -3546,
-3434, -3313, -3182, -3043, -2896, -2740, -2577, -2407, -2230, -2047, -1859, -1666, -1468, -1265, -1060, -851, -641, -428, -214
};
CAX25TX::CAX25TX() :
m_poBuffer(),
m_poLen(0U),
m_poPtr(0U),
m_txDelay(360U),
m_tablePtr(0U),
m_nrzi(false)
{
}
void CAX25TX::process()
{
if (m_poLen == 0U)
return;
if (!m_duplex) {
if (m_poPtr == 0U) {
bool tx = ax25RX.canTX();
if (!tx)
return;
}
}
uint16_t space = io.getSpace();
while (space > AX25_RADIO_SYMBOL_LENGTH) {
bool b = READ_BIT1(m_poBuffer, m_poPtr) != 0U;
m_poPtr++;
writeBit(b);
space -= AX25_RADIO_SYMBOL_LENGTH;
if (m_poPtr >= m_poLen) {
m_poPtr = 0U;
m_poLen = 0U;
return;
}
}
}
uint8_t CAX25TX::writeData(const uint8_t* data, uint16_t length)
{
CAX25Frame frame(data, length);
frame.addCRC();
m_poLen = 0U;
m_poPtr = 0U;
m_nrzi = false;
m_tablePtr = 0U;
// Add TX delay
for (uint16_t i = 0U; i < m_txDelay; i++, m_poLen++) {
bool preamble = NRZI(false);
WRITE_BIT1(m_poBuffer, m_poLen, preamble);
}
// Add the Start Flag
for (uint16_t i = 0U; i < 8U; i++, m_poLen++) {
bool b1 = READ_BIT1(START_FLAG, i) != 0U;
bool b2 = NRZI(b1);
WRITE_BIT1(m_poBuffer, m_poLen, b2);
}
uint8_t ones = 0U;
for (uint16_t i = 0U; i < (frame.m_length * 8U); i++) {
bool b1 = READ_BIT2(frame.m_data, i) != 0U;
bool b2 = NRZI(b1);
WRITE_BIT1(m_poBuffer, m_poLen, b2);
m_poLen++;
if (b1) {
ones++;
if (ones == AX25_MAX_ONES) {
// Bit stuffing
bool b = NRZI(false);
WRITE_BIT1(m_poBuffer, m_poLen, b);
m_poLen++;
ones = 0U;
}
} else {
ones = 0U;
}
}
// Add the End Flag
for (uint16_t i = 0U; i < 8U; i++, m_poLen++) {
bool b1 = READ_BIT1(END_FLAG, i) != 0U;
bool b2 = NRZI(b1);
WRITE_BIT1(m_poBuffer, m_poLen, b2);
}
return 0U;
}
void CAX25TX::writeBit(bool b)
{
q15_t buffer[AX25_RADIO_SYMBOL_LENGTH];
for (uint8_t i = 0U; i < AX25_RADIO_SYMBOL_LENGTH; i++) {
q15_t value = AUDIO_TABLE_DATA[m_tablePtr];
if (b) {
// De-emphasise the lower frequency by 6dB
value >>= 2;
m_tablePtr += 6U;
} else {
m_tablePtr += 11U;
}
buffer[i] = value;
if (m_tablePtr >= AUDIO_TABLE_LEN)
m_tablePtr -= AUDIO_TABLE_LEN;
}
io.write(STATE_AX25, buffer, AX25_RADIO_SYMBOL_LENGTH);
}
void CAX25TX::setTXDelay(uint8_t delay)
{
m_txDelay = delay * 12U;
}
uint8_t CAX25TX::getSpace() const
{
return m_poLen == 0U ? 255U : 0U;
}
bool CAX25TX::NRZI(bool b)
{
if (!b)
m_nrzi = !m_nrzi;
return m_nrzi;
}
#endif
+53
View File
@@ -0,0 +1,53 @@
/*
* 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"
#if defined(MODE_AX25)
#if !defined(AX25TX_H)
#define AX25TX_H
class CAX25TX {
public:
CAX25TX();
uint8_t writeData(const uint8_t* data, uint16_t length);
void process();
void setTXDelay(uint8_t delay);
uint8_t getSpace() const;
private:
uint8_t m_poBuffer[600U];
uint16_t m_poLen;
uint16_t m_poPtr;
uint16_t m_txDelay;
uint16_t m_tablePtr;
bool m_nrzi;
void writeBit(bool b);
bool NRZI(bool b);
};
#endif
#endif
+316
View File
@@ -0,0 +1,316 @@
/*
* 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"
#if defined(MODE_AX25)
#include "Globals.h"
#include "AX25Twist.h"
// 1200Hz = -12dB, 2200Hz = 0dB; 3381Hz cutoff; cosine.
q15_t dB12[] = {
176,
-812,
-3916,
-7586,
23536,
-7586,
-3916,
-812,
176
};
// 1200Hz = -11dB, 2200Hz = 0dB; 3258Hz cutoff; cosine.
q15_t dB11[] = {
121,
-957,
-3959,
-7383,
23871,
-7383,
-3959,
-957,
121
};
// 1200Hz = -10dB, 2200Hz = 0dB; 3118Hz cutoff; cosine.
q15_t dB10[] = {
56,
-1110,
-3987,
-7141,
24254,
-7141,
-3987,
-1110,
56
};
// 1200Hz = -9dB, 2200Hz = 0dB; 2959Hz cutoff; cosine.
q15_t dB9[] = {
-19,
-1268,
-3994,
-6856,
24688,
-6856,
-3994,
-1268,
-19
};
// 1200Hz = -8dB, 2200Hz = 0dB; 2778Hz cutoff; cosine.
q15_t dB8[] = {
-104,
-1424,
-3968,
-6516,
25182,
-6516,
-3968,
-1424,
-104
};
// 1200Hz = -7dB, 2200Hz = 0dB; 2573Hz cutoff; cosine.
q15_t dB7[] = {
-196,
-1565,
-3896,
-6114,
25742,
-6114,
-3896,
-1565,
-196
};
// 1200Hz = -6dB, 2200Hz = 0dB; 2343Hz cutoff; cosine.
q15_t dB6[] = {
-288,
-1676,
-3761,
-5642,
26370,
-5642,
-3761,
-1676,
-288
};
// 1200Hz = -5dB, 2200Hz = 0dB; 2085Hz cutoff; cosine.
q15_t dB5[] = {
-370,
-1735,
-3545,
-5088,
27075,
-5088,
-3545,
-1735,
-370
};
// 1200Hz = -4dB, 2200Hz = 0dB; 1790Hz cutoff; cosine.
q15_t dB4[] = {
-432,
-1715,
-3220,
-4427,
27880,
-4427,
-3220,
-1715,
-432
};
// 1200Hz = -3dB, 2200Hz = 0dB; 1456Hz cutoff; cosine.
q15_t dB3[] = {
-452,
-1582,
-2759,
-3646,
28792,
-3646,
-2759,
-1582,
-452
};
// 1200Hz = -2dB, 2200Hz = 0dB; 1070Hz cutoff; cosine.
q15_t dB2[] = {
-408,
-1295,
-2123,
-2710,
29846,
-2710,
-2123,
-1295,
-408
};
// 1200Hz = -1dB, 2200Hz = 0dB; 605Hz cutoff; cosine.
q15_t dB1[] = {
-268,
-795,
-1244,
-1546,
31116,
-1546,
-1244,
-795,
-268
};
q15_t dB0[] = {
0,
0,
0,
0,
32767,
0,
0,
0,
0,
};
// 1200Hz = 0dB, 2200Hz = -1dB; 4130Hz cutoff; cosine.
q15_t dB_1[] = {
-419,
-177,
3316,
8650,
11278,
8650,
3316,
-177,
-419
};
// 1200Hz = 0dB, 2200Hz = -2dB; 3190Hz cutoff; cosine.
q15_t dB_2[] = {
-90,
1033,
3975,
7267,
8711,
7267,
3975,
1033,
-90
};
// 1200Hz = 0dB, 2200Hz = -3dB; 2330Hz cutoff; cosine.
q15_t dB_3[] = {
292,
1680,
3752,
5615,
6362,
5615,
3752,
1680,
292
};
// 1200Hz = 0dB, 2200Hz = -4dB; 2657Hz cutoff; boxcar.
q15_t dB_4[] = {
917,
3024,
5131,
6684,
7255,
6684,
5131,
3024,
917
};
// 1200Hz = 0dB, 2200Hz = -5dB; 2360Hz cutoff; boxcar.
q15_t dB_5[] = {
1620,
3339,
4925,
6042,
6444,
6042,
4925,
3339,
1620
};
// 1200Hz = 0dB, 2200Hz = -6dB; 2067Hz cutoff; boxcar.
q15_t dB_6[] = {
2161,
3472,
4605,
5373,
5644,
5373,
4605,
3472,
2161
};
q15_t* coeffs[] = {
dB12,
dB11,
dB10,
dB9,
dB8,
dB7,
dB6,
dB5,
dB4,
dB3,
dB2,
dB1,
dB0,
dB_1,
dB_2,
dB_3,
dB_4,
dB_5,
dB_6
};
CAX25Twist::CAX25Twist(int8_t n) :
m_filter(),
m_state()
{
setTwist(n);
}
void CAX25Twist::process(q15_t* in, q15_t* out, uint8_t length)
{
::arm_fir_fast_q15(&m_filter, in, out, length);
}
void CAX25Twist::setTwist(int8_t n)
{
uint8_t twist = uint8_t(n + 6);
m_filter.numTaps = 9;
m_filter.pState = m_state;
m_filter.pCoeffs = coeffs[twist];
}
#endif
+42
View File
@@ -0,0 +1,42 @@
/*
* 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"
#if defined(MODE_AX25)
#if !defined(AX25Twist_H)
#define AX25Twist_H
class CAX25Twist {
public:
CAX25Twist(int8_t n);
void process(q15_t* in, q15_t* out, uint8_t length);
void setTwist(int8_t n);
private:
arm_fir_instance_q15 m_filter;
q15_t m_state[40U]; // NoTaps + BlockSize - 1, 9 + 20 - 1 plus some spare
};
#endif
#endif
+35 -18
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2015,2016,2017,2018,2020,2025 by Jonathan Naylor G4KLX * Copyright (C) 2015,2016,2017,2018,2020 by Jonathan Naylor G4KLX
* *
* 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
@@ -20,7 +20,7 @@
#define CONFIG_H #define CONFIG_H
// Allow for the selection of which modes to compile into the firmware. This is particularly useful for processors // Allow for the selection of which modes to compile into the firmware. This is particularly useful for processors
// which have limited code space and processing power. // which have limited code space and processing power like the STM32F103, which is found on older/cheaper boards.
// Enable D-Star support. // Enable D-Star support.
#define MODE_DSTAR #define MODE_DSTAR
@@ -38,12 +38,18 @@
#define MODE_NXDN #define MODE_NXDN
#define USE_NXDN_BOXCAR #define USE_NXDN_BOXCAR
// Enable M17 support.
#define MODE_M17
// Enable POCSAG support. // Enable POCSAG support.
#define MODE_POCSAG #define MODE_POCSAG
// Enable FM support. // Enable FM support.
#define MODE_FM #define MODE_FM
// Enable AX.25 support, this is only enabled if FM is also enabled.
#define MODE_AX25
// Allow for the use of high quality external clock oscillators // Allow for the use of high quality external clock oscillators
// The number is the frequency of the oscillator in Hertz. // The number is the frequency of the oscillator in Hertz.
// //
@@ -52,7 +58,7 @@
// Frequencies such as 10.0 Mhz (48000 * 208.333) or 20 Mhz (48000 * 416.666) are not suitable. // Frequencies such as 10.0 Mhz (48000 * 208.333) or 20 Mhz (48000 * 416.666) are not suitable.
// //
// For 12 MHz // For 12 MHz
#define EXTERNAL_OSC 12000000 // #define EXTERNAL_OSC 12000000
// For 12.288 MHz // For 12.288 MHz
// #define EXTERNAL_OSC 12288000 // #define EXTERNAL_OSC 12288000
// For 14.4 MHz // For 14.4 MHz
@@ -60,20 +66,30 @@
// For 19.2 MHz // For 19.2 MHz
// #define EXTERNAL_OSC 19200000 // #define EXTERNAL_OSC 19200000
// Select a baud rate for host communication. The faster speeds are needed for external FM to work. // Use a higher baudrate for host communication. Required for FM network !
// #define SERIAL_SPEED 115200 // Suitable for most older boards (Arduino Due, etc). External FM will NOT work with this! // #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 boards like fast M4, M7, Teensy 3.x. External FM might 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 boards like fast M4, M7, Teensy 3.x. External FM should work with this #define SERIAL_SPEED 460800 // Only works on newer board M4, M7, Teensy. External FM should work with this
//#define SERIAL_SPEED 500000 // Used with newer boards and Armbian on AllWinner SOCs (H2, H3) that do not support 460800
// 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
// Use an OLED to show the current mode via a small screen (64x32) on I2C3
#define MODE_OLED
// For the original Arduino Due pin layout // For the original Arduino Due pin layout
// #define ARDUINO_DUE_PAPA // #define ARDUINO_DUE_PAPA
#if defined(STM32F1)
// For the SQ6POG board
#define STM32F1_POG
#else
// For the ZUM V1.0 and V1.0.1 boards pin layout // For the ZUM V1.0 and V1.0.1 boards pin layout
// #define ARDUINO_DUE_ZUM_V10 // #define ARDUINO_DUE_ZUM_V10
#endif
// For the SP8NTH board // For the SP8NTH board
// #define ARDUINO_DUE_NTH // #define ARDUINO_DUE_NTH
@@ -92,13 +108,7 @@
#define SEND_RSSI_DATA #define SEND_RSSI_DATA
// Use the modem as a serial repeater for Nextion displays // Use the modem as a serial repeater for Nextion displays
#define SERIAL_REPEATER // #define SERIAL_REPEATER
// Set the baud rate of the modem serial repeater for Nextion displays
#define SERIAL_REPEATER_BAUD_RATE 9600
// Use the modem as an I2C repeater for OLED displays
// #define I2C_REPEATER
// To reduce CPU load, you can remove the DC blocker by commenting out the next line // To reduce CPU load, you can remove the DC blocker by commenting out the next line
#define USE_DCBLOCKER #define USE_DCBLOCKER
@@ -110,11 +120,18 @@
// Use the YSF and P25 LEDs for NXDN // Use the YSF and P25 LEDs for NXDN
// #define USE_ALTERNATE_NXDN_LEDS // #define USE_ALTERNATE_NXDN_LEDS
// Use the D-Star and P25 LEDs for M17
// #define USE_ALTERNATE_M17_LEDS
// Use the D-Star and DMR LEDs for POCSAG // Use the D-Star and DMR LEDs for POCSAG
#define USE_ALTERNATE_POCSAG_LEDS // #define USE_ALTERNATE_POCSAG_LEDS
// Use the D-Star and YSF LEDs for FM // Use the D-Star and YSF LEDs for FM
#define USE_ALTERNATE_FM_LEDS // #define USE_ALTERNATE_FM_LEDS
#if defined(MODE_OLED)
#undef MODE_LEDS
#endif
#endif #endif
+11 -64
View File
@@ -2,7 +2,6 @@
* Copyright (C) 2009-2017,2020 by Jonathan Naylor G4KLX * Copyright (C) 2009-2017,2020 by Jonathan Naylor G4KLX
* Copyright (C) 2016 by Colin Durbridge G4EML * Copyright (C) 2016 by Colin Durbridge G4EML
* Copyright (C) 2017 by Andy Uribe CA6JAU * Copyright (C) 2017 by Andy Uribe CA6JAU
* Copyright (C) 2022,2023,2026 by Adrian Musceac YO8RZZ
* *
* 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
@@ -43,12 +42,6 @@ const uint8_t IDLE_DATA[] =
0x36U, 0x00U, 0x0DU, 0xFFU, 0x57U, 0xD7U, 0x5DU, 0xF5U, 0xD0U, 0x03U, 0xF6U, 0x36U, 0x00U, 0x0DU, 0xFFU, 0x57U, 0xD7U, 0x5DU, 0xF5U, 0xD0U, 0x03U, 0xF6U,
0xE4U, 0x65U, 0x17U, 0x1BU, 0x48U, 0xCAU, 0x6DU, 0x4FU, 0xC6U, 0x10U, 0xB4U}; 0xE4U, 0x65U, 0x17U, 0x1BU, 0x48U, 0xCAU, 0x6DU, 0x4FU, 0xC6U, 0x10U, 0xB4U};
// DT Terminator with LC, empty
const uint8_t TERMINATOR_DATA[] =
{0x00U, 0xCCU, 0x01U, 0x80U, 0x01U, 0x94U, 0x01U, 0x48U, 0x08U, 0xB0U, 0x08U,
0x80U, 0x04U, 0xADU, 0xFFU, 0x57U, 0xD7U, 0x5DU, 0xF5U, 0xD9U, 0x65U, 0x90U,
0x01U, 0x78U, 0x00U, 0xD0U, 0x08U, 0x40U, 0x14U, 0x00U, 0x0DU, 0x80U, 0x15U};
const uint8_t CACH_INTERLEAVE[] = const uint8_t CACH_INTERLEAVE[] =
{ 1U, 2U, 3U, 5U, 6U, 7U, 9U, 10U, 11U, 13U, 15U, 16U, 17U, 19U, 20U, 21U, 23U, { 1U, 2U, 3U, 5U, 6U, 7U, 9U, 10U, 11U, 13U, 15U, 16U, 17U, 19U, 20U, 21U, 23U,
25U, 26U, 27U, 29U, 30U, 31U, 33U, 34U, 35U, 37U, 39U, 40U, 41U, 43U, 44U, 45U, 47U, 25U, 26U, 27U, 29U, 30U, 31U, 33U, 34U, 35U, 37U, 39U, 40U, 41U, 43U, 44U, 45U, 47U,
@@ -72,7 +65,6 @@ m_modFilter(),
m_modState(), m_modState(),
m_state(DMRTXSTATE_IDLE), m_state(DMRTXSTATE_IDLE),
m_idle(), m_idle(),
m_aloha(),
m_cachPtr(0U), m_cachPtr(0U),
m_shortLC(), m_shortLC(),
m_newShortLC(), m_newShortLC(),
@@ -82,10 +74,7 @@ m_poLen(0U),
m_poPtr(0U), m_poPtr(0U),
m_frameCount(0U), m_frameCount(0U),
m_abortCount(), m_abortCount(),
m_abort(), m_abort()
m_controlChannel(false),
m_trunking(false),
m_colorCode(0U)
{ {
::memset(m_modState, 0x00U, 16U * sizeof(q15_t)); ::memset(m_modState, 0x00U, 16U * sizeof(q15_t));
@@ -222,23 +211,6 @@ uint8_t CDMRTX::writeShortLC(const uint8_t* data, uint16_t length)
return 0U; return 0U;
} }
uint8_t CDMRTX::writeAloha(const uint8_t* data, uint16_t length)
{
if (length != DMR_FRAME_LENGTH_BYTES)
return 4U;
::memcpy(m_aloha, data, length);
// Stamp the slot type with the current colour code so that the result
// doesn't depend on the ordering of the ALOHA and SET_CONFIG commands.
CDMRSlotType slotType;
slotType.encode(m_colorCode, DT_CSBK, m_aloha);
m_controlChannel = true;
return 0U;
}
uint8_t CDMRTX::writeAbort(const uint8_t* data, uint16_t length) uint8_t CDMRTX::writeAbort(const uint8_t* data, uint16_t length)
{ {
if (length != 1U) if (length != 1U)
@@ -322,7 +294,7 @@ uint8_t CDMRTX::getSpace2() const
void CDMRTX::createData(uint8_t slotIndex) 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_fifo[slotIndex].get(m_poBuffer[i]); m_fifo[slotIndex].get(m_poBuffer[i]);
m_markBuffer[i] = MARK_NONE; m_markBuffer[i] = MARK_NONE;
@@ -331,11 +303,7 @@ void CDMRTX::createData(uint8_t slotIndex)
m_abort[slotIndex] = false; m_abort[slotIndex] = false;
// Transmit an idle message // Transmit an idle message
for (unsigned int i = 0U; i < DMR_FRAME_LENGTH_BYTES; i++) { for (unsigned int i = 0U; i < DMR_FRAME_LENGTH_BYTES; i++) {
if ((slotIndex == 0U) && m_controlChannel && m_trunking) m_poBuffer[i] = m_idle[i];
m_poBuffer[i] = m_aloha[i];
else
m_poBuffer[i] = m_idle[i];
m_markBuffer[i] = MARK_NONE; m_markBuffer[i] = MARK_NONE;
} }
} }
@@ -386,14 +354,10 @@ void CDMRTX::createCACH(uint8_t txSlotIndex, uint8_t rxSlotIndex)
m_cachPtr = 0U; m_cachPtr = 0U;
if (m_cachPtr == 0U) { if (m_cachPtr == 0U) {
if ((m_fifo[0U].getData() == 0U) && (m_fifo[1U].getData() == 0U)) { if (m_fifo[0U].getData() == 0U && m_fifo[1U].getData() == 0U)
if (m_trunking) ::memcpy(m_shortLC, EMPTY_SHORT_LC, 12U);
::memcpy(m_shortLC, m_newShortLC, 12U); else
else
::memcpy(m_shortLC, EMPTY_SHORT_LC, 12U);
} else {
::memcpy(m_shortLC, m_newShortLC, 12U); ::memcpy(m_shortLC, m_newShortLC, 12U);
}
} }
::memcpy(m_poBuffer, m_shortLC + m_cachPtr, 3U); ::memcpy(m_poBuffer, m_shortLC + m_cachPtr, 3U);
@@ -403,8 +367,8 @@ void CDMRTX::createCACH(uint8_t txSlotIndex, uint8_t rxSlotIndex)
bool at = false; bool at = false;
if (m_frameCount >= STARTUP_COUNT) if (m_frameCount >= STARTUP_COUNT)
at = (m_fifo[rxSlotIndex].getData() > 0U); at = m_fifo[rxSlotIndex].getData() > 0U;
bool tc = (txSlotIndex == 1U); bool tc = txSlotIndex == 1U;
bool ls0 = true; // For 1 and 2 bool ls0 = true; // For 1 and 2
bool ls1 = true; bool ls1 = true;
@@ -433,20 +397,10 @@ void CDMRTX::createCACH(uint8_t txSlotIndex, uint8_t rxSlotIndex)
void CDMRTX::setColorCode(uint8_t colorCode) void CDMRTX::setColorCode(uint8_t colorCode)
{ {
m_colorCode = colorCode; ::memcpy(m_idle, IDLE_DATA, DMR_FRAME_LENGTH_BYTES);
if (m_trunking)
::memcpy(m_idle, TERMINATOR_DATA, DMR_FRAME_LENGTH_BYTES);
else
::memcpy(m_idle, IDLE_DATA, DMR_FRAME_LENGTH_BYTES);
CDMRSlotType slotType; CDMRSlotType slotType;
if (m_trunking) { slotType.encode(colorCode, DT_IDLE, m_idle);
slotType.encode(colorCode, DT_TERMINATOR_WITH_LC, m_idle);
slotType.encode(colorCode, DT_CSBK, m_aloha);
} else {
slotType.encode(colorCode, DT_IDLE, m_idle);
}
} }
void CDMRTX::resetFifo1() void CDMRTX::resetFifo1()
@@ -464,12 +418,5 @@ uint32_t CDMRTX::getFrameCount()
return m_frameCount; return m_frameCount;
} }
void CDMRTX::setTrunking(bool trunking)
{
m_trunking = trunking;
if (!trunking)
m_controlChannel = false;
}
#endif #endif
+2 -8
View File
@@ -1,7 +1,6 @@
/* /*
* Copyright (C) 2015,2016,2017,2020 by Jonathan Naylor G4KLX * Copyright (C) 2015,2016,2017,2020 by Jonathan Naylor G4KLX
* Copyright (C) 2016 by Colin Durbridge G4EML * Copyright (C) 2016 by Colin Durbridge G4EML
* Copyright (C) 2026 by Adrian Musceac YO8RZZ
* *
* 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
@@ -46,12 +45,10 @@ public:
uint8_t writeData2(const uint8_t* data, uint16_t length); uint8_t writeData2(const uint8_t* data, uint16_t length);
uint8_t writeShortLC(const uint8_t* data, uint16_t length); uint8_t writeShortLC(const uint8_t* data, uint16_t length);
uint8_t writeAloha(const uint8_t* data, uint16_t length);
uint8_t writeAbort(const uint8_t* data, uint16_t length); uint8_t writeAbort(const uint8_t* data, uint16_t length);
void setStart(bool start); void setStart(bool start);
void setCal(bool start); void setCal(bool start);
void setTrunking(bool trunking);
void process(); void process();
@@ -65,12 +62,11 @@ public:
void setColorCode(uint8_t colorCode); void setColorCode(uint8_t colorCode);
private: private:
CRingBuffer<uint8_t> 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;
uint8_t m_idle[DMR_FRAME_LENGTH_BYTES]; uint8_t m_idle[DMR_FRAME_LENGTH_BYTES];
uint8_t m_aloha[DMR_FRAME_LENGTH_BYTES];
uint8_t m_cachPtr; uint8_t m_cachPtr;
uint8_t m_shortLC[12U]; uint8_t m_shortLC[12U];
uint8_t m_newShortLC[12U]; uint8_t m_newShortLC[12U];
@@ -81,9 +77,6 @@ private:
uint32_t m_frameCount; uint32_t m_frameCount;
uint32_t m_abortCount[2U]; uint32_t m_abortCount[2U];
bool m_abort[2U]; bool m_abort[2U];
bool m_controlChannel;
bool m_trunking;
uint8_t m_colorCode;
void createData(uint8_t slotIndex); void createData(uint8_t slotIndex);
void createCACH(uint8_t txSlotIndex, uint8_t rxSlotIndex); void createCACH(uint8_t txSlotIndex, uint8_t rxSlotIndex);
@@ -94,3 +87,4 @@ private:
#endif #endif
#endif #endif
+45 -340
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2020,2021,2023,2025 by Jonathan Naylor G4KLX * Copyright (C) 2020,2021 by Jonathan Naylor G4KLX
* *
* 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
@@ -27,21 +27,14 @@ const uint16_t FM_TX_BLOCK_SIZE = 100U;
const uint16_t FM_SERIAL_BLOCK_SIZE = 80U;//this is the number of sample pairs to send over serial. One sample pair is 3bytes. const uint16_t FM_SERIAL_BLOCK_SIZE = 80U;//this is the number of sample pairs to send over serial. One sample pair is 3bytes.
//three times this value shall never exceed 252 //three times this value shall never exceed 252
const uint16_t FM_SERIAL_BLOCK_SIZE_BYTES = FM_SERIAL_BLOCK_SIZE * 3U; const uint16_t FM_SERIAL_BLOCK_SIZE_BYTES = FM_SERIAL_BLOCK_SIZE * 3U;
const uint16_t FM_LINK_EXT_GAP_MS = 60U;// How long a link-mode external-audio underrun is tolerated before it is
// treated as a real end of transmission (see linkStateMachine()).
const uint8_t FS_LISTENING = 0U;
const uint8_t FS_KERCHUNK_RF = 1U;
const uint8_t FS_RELAYING_RF = 2U;
const uint8_t FS_RELAYING_WAIT_RF = 3U;
const uint8_t FS_TIMEOUT_RF = 4U;
const uint8_t FS_TIMEOUT_WAIT_RF = 5U;
const uint8_t FS_KERCHUNK_EXT = 6U;
const uint8_t FS_RELAYING_EXT = 7U;
const uint8_t FS_RELAYING_WAIT_EXT = 8U;
const uint8_t FS_TIMEOUT_EXT = 9U;
const uint8_t FS_TIMEOUT_WAIT_EXT = 10U;
const uint8_t FS_HANG = 11U;
/*
* Access Mode values are:
* 0 - Carrier access with COS
* 1 - CTCSS only access without COS
* 2 - CTCSS only access with COS
* 3 - CTCSS only access with COS to start, then carrier access with COS
*/
CFM::CFM() : CFM::CFM() :
m_callsign(), m_callsign(),
@@ -62,21 +55,14 @@ m_kerchunkTimer(),
m_ackMinTimer(), m_ackMinTimer(),
m_ackDelayTimer(), m_ackDelayTimer(),
m_hangTimer(), m_hangTimer(),
m_statusTimer(),
m_reverseTimer(), m_reverseTimer(),
m_extGapTimer(),
m_needReverse(false), m_needReverse(false),
m_filterStage1( 724, 1448, 724, 32768, -37895, 21352),//3rd order Cheby Filter 300 to 2700Hz, 0.2dB passband ripple, sampling rate 24kHz m_filterStage1( 724, 1448, 724, 32768, -37895, 21352),//3rd order Cheby Filter 300 to 2700Hz, 0.2dB passband ripple, sampling rate 24kHz
m_filterStage2(32768, 0,-32768, 32768, -50339, 19052), m_filterStage2(32768, 0,-32768, 32768, -50339, 19052),
m_filterStage3(32768, -65536, 32768, 32768, -64075, 31460), m_filterStage3(32768, -65536, 32768, 32768, -64075, 31460),
m_dsFilterStage1(m_filterStage1),//same coefficients, separate state
m_dsFilterStage2(m_filterStage2),
m_dsFilterStage3(m_filterStage3),
m_usFilterStage1(m_filterStage1),//same coefficients, separate state
m_usFilterStage2(m_filterStage2),
m_usFilterStage3(m_filterStage3),
m_blanking(), m_blanking(),
m_accessMode(1U), m_accessMode(1U),
m_linkMode(false),
m_cosInvert(false), m_cosInvert(false),
m_noiseSquelch(false), m_noiseSquelch(false),
m_rfAudioBoost(1U), m_rfAudioBoost(1U),
@@ -86,27 +72,15 @@ m_extEnabled(false),
m_rxLevel(1), m_rxLevel(1),
m_inputRFRB(2401U), // 100ms of audio + 1 sample m_inputRFRB(2401U), // 100ms of audio + 1 sample
m_outputRFRB(2400U), // 100ms of audio m_outputRFRB(2400U), // 100ms of audio
m_inputExtRB(), m_inputExtRB()
m_rfSignal(false),
m_extSignal(false),
m_rssiAccum(0U),
m_rssiCount(0U)
{ {
m_statusTimer.setTimeout(1U, 0U);
m_reverseTimer.setTimeout(0U, 150U); m_reverseTimer.setTimeout(0U, 150U);
m_extGapTimer.setTimeout(0U, FM_LINK_EXT_GAP_MS);
insertDelay(100U); insertDelay(100U);
} }
void CFM::samples(bool cos, q15_t* samples, const uint16_t* rssi, uint8_t length) void CFM::samples(bool cos, q15_t* samples, uint8_t length)
{
if (m_linkMode)
linkSamples(cos, samples, length);
else
repeaterSamples(cos, samples, rssi, length);
}
void CFM::repeaterSamples(bool cos, q15_t* samples, const uint16_t* rssi, uint8_t length)
{ {
if (m_cosInvert) if (m_cosInvert)
cos = !cos; cos = !cos;
@@ -115,11 +89,6 @@ void CFM::repeaterSamples(bool cos, q15_t* samples, const uint16_t* rssi, uint8_
uint8_t i = 0U; uint8_t i = 0U;
for (; i < length; i++) { for (; i < length; i++) {
if (m_state == FS_RELAYING_RF) {
m_rssiAccum += rssi[i];
m_rssiCount++;
}
// ARMv7-M has hardware integer division // ARMv7-M has hardware integer division
q15_t currentRFSample = q15_t((q31_t(samples[i]) << 8) / m_rxLevel); q15_t currentRFSample = q15_t((q31_t(samples[i]) << 8) / m_rxLevel);
@@ -128,7 +97,6 @@ void CFM::repeaterSamples(bool cos, q15_t* samples, const uint16_t* rssi, uint8_
q15_t currentExtSample; q15_t currentExtSample;
bool inputExt = m_inputExtRB.getSample(currentExtSample);//always consume the external input data so it does not overflow bool inputExt = m_inputExtRB.getSample(currentExtSample);//always consume the external input data so it does not overflow
currentExtSample = m_usFilterStage3.filter(m_usFilterStage2.filter(m_usFilterStage1.filter(currentExtSample)));
inputExt = inputExt && m_extEnabled; inputExt = inputExt && m_extEnabled;
switch (m_accessMode) { switch (m_accessMode) {
@@ -210,10 +178,8 @@ void CFM::repeaterSamples(bool cos, q15_t* samples, const uint16_t* rssi, uint8_
if (m_duplex) { if (m_duplex) {
if (m_state == FS_RELAYING_RF || m_state == FS_KERCHUNK_RF || m_state == FS_RELAYING_EXT || m_state == FS_KERCHUNK_EXT) { if (m_state == FS_RELAYING_RF || m_state == FS_KERCHUNK_RF || m_state == FS_RELAYING_EXT || m_state == FS_KERCHUNK_EXT) {
currentSample = m_blanking.process(currentSample); currentSample = m_blanking.process(currentSample);
if (m_extEnabled && (m_state == FS_RELAYING_RF || m_state == FS_KERCHUNK_RF)) { if (m_extEnabled && (m_state == FS_RELAYING_RF || m_state == FS_KERCHUNK_RF))
q15_t dsSample = m_dsFilterStage3.filter(m_dsFilterStage2.filter(m_dsFilterStage1.filter(currentSample))); m_downSampler.addSample(currentSample);
m_downSampler.addSample(dsSample);
}
currentSample *= currentBoost; currentSample *= currentBoost;
} else { } else {
@@ -223,11 +189,9 @@ void CFM::repeaterSamples(bool cos, q15_t* samples, const uint16_t* rssi, uint8_
if (m_state == FS_RELAYING_EXT || m_state == FS_KERCHUNK_EXT) { if (m_state == FS_RELAYING_EXT || m_state == FS_KERCHUNK_EXT) {
currentSample *= currentBoost; currentSample *= currentBoost;
} else { } else {
if (m_extEnabled && (m_state == FS_RELAYING_RF || m_state == FS_KERCHUNK_RF)) { if (m_extEnabled && (m_state == FS_RELAYING_RF || m_state == FS_KERCHUNK_RF))
q15_t dsSample = m_dsFilterStage3.filter(m_dsFilterStage2.filter(m_dsFilterStage1.filter(currentSample))); m_downSampler.addSample(currentSample);
m_downSampler.addSample(dsSample); continue;
}
continue;
} }
} }
@@ -255,112 +219,6 @@ void CFM::repeaterSamples(bool cos, q15_t* samples, const uint16_t* rssi, uint8_
} }
} }
void CFM::linkSamples(bool cos, q15_t* samples, uint8_t length)
{
if (m_cosInvert)
cos = !cos;
clock(length);
uint8_t i = 0U;
for (; i < length; i++) {
q15_t currentRFSample = q15_t((q31_t(samples[i]) << 8) / m_rxLevel);
if (m_noiseSquelch)
cos = m_squelch.process(currentRFSample);
// Zero-initialized: getSample() leaves this untouched on underrun, and
// with the ext-gap debounce below, m_extSignal can now stay true for a
// few samples past that point
q15_t currentExtSample = 0;
bool inputExt = m_inputExtRB.getSample(currentExtSample);//always consume the external input data so it does not overflow
currentExtSample = m_usFilterStage3.filter(m_usFilterStage2.filter(m_usFilterStage1.filter(currentExtSample)));
inputExt = inputExt && m_extEnabled;
switch (m_accessMode) {
case 0U:
if (!inputExt && !cos && m_modemState != STATE_FM)
continue;
else
stateMachine(cos, inputExt);
break;
case 1U: {
bool ctcss = m_ctcssRX.process(currentRFSample);
// Delay the audio by 100ms to better match the CTCSS detector output
m_inputRFRB.put(currentRFSample);
m_inputRFRB.get(currentRFSample);
if (!inputExt && !ctcss && m_modemState != STATE_FM) {
// No CTCSS detected, just carry on
continue;
} else if ((inputExt || ctcss) && m_modemState != STATE_FM) {
// We had CTCSS or external input
stateMachine(ctcss, inputExt);
if (m_state == FS_LISTENING)
continue;
} else {
stateMachine(ctcss, inputExt);
}
}
break;
case 2U: {
bool ctcss = m_ctcssRX.process(currentRFSample);
if (!inputExt && !ctcss && m_modemState != STATE_FM) {
// No CTCSS detected, just carry on
continue;
} else if ((inputExt || (ctcss && cos)) && m_modemState != STATE_FM) {
// We had CTCSS or external input
stateMachine(ctcss && cos, inputExt);
if (m_state == FS_LISTENING)
continue;
} else {
stateMachine(ctcss && cos, inputExt);
}
}
break;
default: {
bool ctcss = m_ctcssRX.process(currentRFSample);
if (!inputExt && !ctcss && m_modemState != STATE_FM) {
// No CTCSS detected, just carry on
continue;
} else if ((inputExt || (ctcss && cos)) && m_modemState != STATE_FM) {
// We had CTCSS or external input
stateMachine(ctcss && cos, inputExt);
if (m_state == FS_LISTENING)
continue;
} else {
stateMachine(cos, inputExt);
}
}
break;
}
if (m_modemState != STATE_FM)
continue;
if (m_rfSignal && m_extEnabled) {
q15_t currentSample = m_blanking.process(currentRFSample);
q15_t dsSample = m_dsFilterStage3.filter(m_dsFilterStage2.filter(m_dsFilterStage1.filter(currentSample)));
m_downSampler.addSample(dsSample);
}
if (!m_extSignal)
continue;
q15_t currentSample = currentExtSample * m_extAudioBoost;
currentSample = m_filterStage3.filter(m_filterStage2.filter(m_filterStage1.filter(currentSample)));
currentSample += m_ctcssTX.getAudio(m_reverseTimer.isRunning());
m_outputRFRB.put(currentSample);
}
}
void CFM::process() void CFM::process()
{ {
uint16_t space = io.getSpace(); uint16_t space = io.getSpace();
@@ -413,6 +271,7 @@ void CFM::reset()
m_ackMinTimer.stop(); m_ackMinTimer.stop();
m_ackDelayTimer.stop(); m_ackDelayTimer.stop();
m_hangTimer.stop(); m_hangTimer.stop();
m_statusTimer.stop();
m_reverseTimer.stop(); m_reverseTimer.stop();
m_ctcssRX.reset(); m_ctcssRX.reset();
@@ -425,17 +284,9 @@ void CFM::reset()
m_inputExtRB.reset(); m_inputExtRB.reset();
m_downSampler.reset(); m_downSampler.reset();
m_dsFilterStage1.reset();
m_dsFilterStage2.reset();
m_dsFilterStage3.reset();
m_usFilterStage1.reset();
m_usFilterStage2.reset();
m_usFilterStage3.reset();
m_squelch.reset(); m_squelch.reset();
m_needReverse = false; m_needReverse = false;
m_rfSignal = false;
m_extSignal = false;
} }
uint8_t CFM::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 CFM::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)
@@ -466,10 +317,9 @@ uint8_t CFM::setAck(const char* rfAck, uint8_t speed, uint16_t frequency, uint8_
return m_rfAck.setParams(rfAck, speed, frequency, level, level); return m_rfAck.setParams(rfAck, speed, frequency, level, level);
} }
uint8_t CFM::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 linkMode, bool cosInvert, bool noiseSquelch, uint8_t squelchHighThreshold, uint8_t squelchLowThreshold, uint8_t rfAudioBoost, uint8_t maxDev, uint8_t rxLevel) uint8_t CFM::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)
{ {
m_accessMode = accessMode; m_accessMode = accessMode;
m_linkMode = linkMode;
m_cosInvert = cosInvert; m_cosInvert = cosInvert;
m_noiseSquelch = noiseSquelch; m_noiseSquelch = noiseSquelch;
@@ -506,14 +356,10 @@ uint8_t CFM::setExt(const char* ack, uint8_t audioBoost, uint8_t speed, uint16_t
void CFM::stateMachine(bool validRFSignal, bool validExtSignal) void CFM::stateMachine(bool validRFSignal, bool validExtSignal)
{ {
if (m_linkMode) { if (m_duplex)
linkStateMachine(validRFSignal, validExtSignal); duplexStateMachine(validRFSignal, validExtSignal);
} else { else
if (m_duplex) simplexStateMachine(validRFSignal, validExtSignal);
duplexStateMachine(validRFSignal, validExtSignal);
else
simplexStateMachine(validRFSignal, validExtSignal);
}
} }
void CFM::simplexStateMachine(bool validRFSignal, bool validExtSignal) void CFM::simplexStateMachine(bool validRFSignal, bool validExtSignal)
@@ -624,8 +470,13 @@ void CFM::clock(uint8_t length)
m_ackMinTimer.clock(length); m_ackMinTimer.clock(length);
m_ackDelayTimer.clock(length); m_ackDelayTimer.clock(length);
m_hangTimer.clock(length); m_hangTimer.clock(length);
m_statusTimer.clock(length);
m_reverseTimer.clock(length); m_reverseTimer.clock(length);
m_extGapTimer.clock(length);
if (m_statusTimer.isRunning() && m_statusTimer.hasExpired()) {
serial.writeFMStatus(m_state);
m_statusTimer.start();
}
} }
void CFM::listeningStateDuplex(bool validRFSignal, bool validExtSignal) void CFM::listeningStateDuplex(bool validRFSignal, bool validExtSignal)
@@ -634,19 +485,12 @@ void CFM::listeningStateDuplex(bool validRFSignal, bool validExtSignal)
if (m_kerchunkTimer.getTimeout() > 0U) { if (m_kerchunkTimer.getTimeout() > 0U) {
DEBUG1("State to KERCHUNK_RF"); DEBUG1("State to KERCHUNK_RF");
m_state = FS_KERCHUNK_RF; m_state = FS_KERCHUNK_RF;
serial.writeFMStatus(m_state);
m_kerchunkTimer.start(); m_kerchunkTimer.start();
if (m_callsignAtStart && !m_callsignAtLatch) if (m_callsignAtStart && !m_callsignAtLatch)
sendCallsign(); sendCallsign();
} else { } else {
DEBUG1("State to RELAYING_RF"); DEBUG1("State to RELAYING_RF");
m_state = FS_RELAYING_RF; m_state = FS_RELAYING_RF;
serial.writeFMStatus(m_state);
m_rssiAccum = 0U;
m_rssiCount = 0U;
if (m_callsignAtStart) if (m_callsignAtStart)
sendCallsign(); sendCallsign();
} }
@@ -661,21 +505,20 @@ void CFM::listeningStateDuplex(bool validRFSignal, bool validExtSignal)
io.setDecode(true); io.setDecode(true);
io.setADCDetection(true); io.setADCDetection(true);
m_statusTimer.start();
serial.writeFMStatus(m_state);
} }
} else if (validExtSignal) { } else if (validExtSignal) {
if (m_kerchunkTimer.getTimeout() > 0U) { if (m_kerchunkTimer.getTimeout() > 0U) {
DEBUG1("State to KERCHUNK_EXT"); DEBUG1("State to KERCHUNK_EXT");
m_state = FS_KERCHUNK_EXT; m_state = FS_KERCHUNK_EXT;
serial.writeFMStatus(m_state);
m_kerchunkTimer.start(); m_kerchunkTimer.start();
if (m_callsignAtStart && !m_callsignAtLatch) if (m_callsignAtStart && !m_callsignAtLatch)
sendCallsign(); sendCallsign();
} else { } else {
DEBUG1("State to RELAYING_EXT"); DEBUG1("State to RELAYING_EXT");
m_state = FS_RELAYING_EXT; m_state = FS_RELAYING_EXT;
serial.writeFMStatus(m_state);
if (m_callsignAtStart) if (m_callsignAtStart)
sendCallsign(); sendCallsign();
} }
@@ -687,6 +530,9 @@ void CFM::listeningStateDuplex(bool validRFSignal, bool validExtSignal)
m_callsignTimer.start(); m_callsignTimer.start();
m_reverseTimer.stop(); m_reverseTimer.stop();
m_statusTimer.start();
serial.writeFMStatus(m_state);
} }
} }
} }
@@ -696,22 +542,26 @@ void CFM::listeningStateSimplex(bool validRFSignal, bool validExtSignal)
if (validRFSignal) { if (validRFSignal) {
DEBUG1("State to RELAYING_RF"); DEBUG1("State to RELAYING_RF");
m_state = FS_RELAYING_RF; m_state = FS_RELAYING_RF;
serial.writeFMStatus(m_state);
io.setDecode(true); io.setDecode(true);
io.setADCDetection(true); io.setADCDetection(true);
m_timeoutTimer.start(); m_timeoutTimer.start();
m_reverseTimer.stop(); m_reverseTimer.stop();
m_statusTimer.start();
serial.writeFMStatus(m_state);
} else if (validExtSignal) { } else if (validExtSignal) {
DEBUG1("State to RELAYING_EXT"); DEBUG1("State to RELAYING_EXT");
m_state = FS_RELAYING_EXT; m_state = FS_RELAYING_EXT;
serial.writeFMStatus(m_state);
insertSilence(50U); insertSilence(50U);
m_timeoutTimer.start(); m_timeoutTimer.start();
m_reverseTimer.stop(); m_reverseTimer.stop();
m_statusTimer.start();
serial.writeFMStatus(m_state);
} }
} }
@@ -721,11 +571,6 @@ void CFM::kerchunkRFStateDuplex(bool validSignal)
if (m_kerchunkTimer.hasExpired()) { if (m_kerchunkTimer.hasExpired()) {
DEBUG1("State to RELAYING_RF"); DEBUG1("State to RELAYING_RF");
m_state = FS_RELAYING_RF; m_state = FS_RELAYING_RF;
serial.writeFMStatus(m_state);
m_rssiAccum = 0U;
m_rssiCount = 0U;
m_kerchunkTimer.stop(); m_kerchunkTimer.stop();
if (m_callsignAtStart && m_callsignAtLatch) { if (m_callsignAtStart && m_callsignAtLatch) {
sendCallsign(); sendCallsign();
@@ -738,12 +583,11 @@ void CFM::kerchunkRFStateDuplex(bool validSignal)
DEBUG1("State to LISTENING"); DEBUG1("State to LISTENING");
m_state = FS_LISTENING; m_state = FS_LISTENING;
serial.writeFMStatus(m_state);
m_kerchunkTimer.stop(); m_kerchunkTimer.stop();
m_timeoutTimer.stop(); m_timeoutTimer.stop();
m_ackMinTimer.stop(); m_ackMinTimer.stop();
m_callsignTimer.stop(); m_callsignTimer.stop();
m_statusTimer.stop();
m_needReverse = true; m_needReverse = true;
if (m_extEnabled) if (m_extEnabled)
serial.writeFMEOT(); serial.writeFMEOT();
@@ -753,21 +597,9 @@ void CFM::kerchunkRFStateDuplex(bool validSignal)
void CFM::relayingRFStateDuplex(bool validSignal) void CFM::relayingRFStateDuplex(bool validSignal)
{ {
if (validSignal) { if (validSignal) {
#if defined(SEND_RSSI_DATA)
if (m_rssiCount >= 24000U) {
uint16_t rssi = m_rssiAccum / m_rssiCount;
serial.writeFMRSSI(rssi);
m_rssiAccum = 0U;
m_rssiCount = 0U;
}
#endif
if (m_timeoutTimer.isRunning() && m_timeoutTimer.hasExpired()) { if (m_timeoutTimer.isRunning() && m_timeoutTimer.hasExpired()) {
DEBUG1("State to TIMEOUT_RF"); DEBUG1("State to TIMEOUT_RF");
m_state = FS_TIMEOUT_RF; m_state = FS_TIMEOUT_RF;
serial.writeFMStatus(m_state);
m_ackMinTimer.stop(); m_ackMinTimer.stop();
m_timeoutTimer.stop(); m_timeoutTimer.stop();
m_timeoutTone.start(); m_timeoutTone.start();
@@ -781,8 +613,6 @@ void CFM::relayingRFStateDuplex(bool validSignal)
DEBUG1("State to RELAYING_WAIT_RF"); DEBUG1("State to RELAYING_WAIT_RF");
m_state = FS_RELAYING_WAIT_RF; m_state = FS_RELAYING_WAIT_RF;
serial.writeFMStatus(m_state);
m_ackDelayTimer.start(); m_ackDelayTimer.start();
if (m_extEnabled) if (m_extEnabled)
@@ -801,7 +631,6 @@ void CFM::relayingRFStateSimplex(bool validSignal)
if (m_timeoutTimer.isRunning() && m_timeoutTimer.hasExpired()) { if (m_timeoutTimer.isRunning() && m_timeoutTimer.hasExpired()) {
DEBUG1("State to TIMEOUT_RF"); DEBUG1("State to TIMEOUT_RF");
m_state = FS_TIMEOUT_RF; m_state = FS_TIMEOUT_RF;
serial.writeFMStatus(m_state);
m_timeoutTimer.stop(); m_timeoutTimer.stop();
@@ -814,8 +643,6 @@ void CFM::relayingRFStateSimplex(bool validSignal)
DEBUG1("State to RELAYING_WAIT_RF"); DEBUG1("State to RELAYING_WAIT_RF");
m_state = FS_RELAYING_WAIT_RF; m_state = FS_RELAYING_WAIT_RF;
serial.writeFMStatus(m_state);
m_ackDelayTimer.start(); m_ackDelayTimer.start();
if (m_extEnabled) if (m_extEnabled)
@@ -831,17 +658,11 @@ void CFM::relayingRFWaitStateDuplex(bool validSignal)
DEBUG1("State to RELAYING_RF"); DEBUG1("State to RELAYING_RF");
m_state = FS_RELAYING_RF; m_state = FS_RELAYING_RF;
serial.writeFMStatus(m_state);
m_rssiAccum = 0U;
m_rssiCount = 0U;
m_ackDelayTimer.stop(); m_ackDelayTimer.stop();
} else { } else {
if (m_ackDelayTimer.isRunning() && m_ackDelayTimer.hasExpired()) { if (m_ackDelayTimer.isRunning() && m_ackDelayTimer.hasExpired()) {
DEBUG1("State to HANG"); DEBUG1("State to HANG");
m_state = FS_HANG; m_state = FS_HANG;
serial.writeFMStatus(m_state);
if (m_ackMinTimer.isRunning()) { if (m_ackMinTimer.isRunning()) {
if (m_ackMinTimer.hasExpired()) { if (m_ackMinTimer.hasExpired()) {
@@ -875,15 +696,11 @@ void CFM::relayingRFWaitStateSimplex(bool validSignal)
DEBUG1("State to RELAYING_RF"); DEBUG1("State to RELAYING_RF");
m_state = FS_RELAYING_RF; m_state = FS_RELAYING_RF;
serial.writeFMStatus(m_state);
m_ackDelayTimer.stop(); m_ackDelayTimer.stop();
} else { } else {
if (m_ackDelayTimer.isRunning() && m_ackDelayTimer.hasExpired()) { if (m_ackDelayTimer.isRunning() && m_ackDelayTimer.hasExpired()) {
DEBUG1("State to LISTENING"); DEBUG1("State to LISTENING");
m_state = FS_LISTENING; m_state = FS_LISTENING;
serial.writeFMStatus(m_state);
m_ackDelayTimer.stop(); m_ackDelayTimer.stop();
m_timeoutTimer.stop(); m_timeoutTimer.stop();
} }
@@ -896,8 +713,6 @@ void CFM::kerchunkExtStateDuplex(bool validSignal)
if (m_kerchunkTimer.hasExpired()) { if (m_kerchunkTimer.hasExpired()) {
DEBUG1("State to RELAYING_EXT"); DEBUG1("State to RELAYING_EXT");
m_state = FS_RELAYING_EXT; m_state = FS_RELAYING_EXT;
serial.writeFMStatus(m_state);
m_kerchunkTimer.stop(); m_kerchunkTimer.stop();
if (m_callsignAtStart && m_callsignAtLatch) { if (m_callsignAtStart && m_callsignAtLatch) {
sendCallsign(); sendCallsign();
@@ -907,12 +722,11 @@ void CFM::kerchunkExtStateDuplex(bool validSignal)
} else { } else {
DEBUG1("State to LISTENING"); DEBUG1("State to LISTENING");
m_state = FS_LISTENING; m_state = FS_LISTENING;
serial.writeFMStatus(m_state);
m_kerchunkTimer.stop(); m_kerchunkTimer.stop();
m_timeoutTimer.stop(); m_timeoutTimer.stop();
m_ackMinTimer.stop(); m_ackMinTimer.stop();
m_callsignTimer.stop(); m_callsignTimer.stop();
m_statusTimer.stop();
m_needReverse = true; m_needReverse = true;
} }
} }
@@ -923,8 +737,6 @@ void CFM::relayingExtStateDuplex(bool validSignal)
if (m_timeoutTimer.isRunning() && m_timeoutTimer.hasExpired()) { if (m_timeoutTimer.isRunning() && m_timeoutTimer.hasExpired()) {
DEBUG1("State to TIMEOUT_EXT"); DEBUG1("State to TIMEOUT_EXT");
m_state = FS_TIMEOUT_EXT; m_state = FS_TIMEOUT_EXT;
serial.writeFMStatus(m_state);
m_ackMinTimer.stop(); m_ackMinTimer.stop();
m_timeoutTimer.stop(); m_timeoutTimer.stop();
m_timeoutTone.start(); m_timeoutTone.start();
@@ -932,7 +744,6 @@ void CFM::relayingExtStateDuplex(bool validSignal)
} else { } else {
DEBUG1("State to RELAYING_WAIT_EXT"); DEBUG1("State to RELAYING_WAIT_EXT");
m_state = FS_RELAYING_WAIT_EXT; m_state = FS_RELAYING_WAIT_EXT;
serial.writeFMStatus(m_state);
m_ackDelayTimer.start(); m_ackDelayTimer.start();
} }
@@ -948,14 +759,12 @@ void CFM::relayingExtStateSimplex(bool validSignal)
if (m_timeoutTimer.isRunning() && m_timeoutTimer.hasExpired()) { if (m_timeoutTimer.isRunning() && m_timeoutTimer.hasExpired()) {
DEBUG1("State to TIMEOUT_EXT"); DEBUG1("State to TIMEOUT_EXT");
m_state = FS_TIMEOUT_EXT; m_state = FS_TIMEOUT_EXT;
serial.writeFMStatus(m_state);
m_timeoutTimer.stop(); m_timeoutTimer.stop();
} }
} else { } else {
DEBUG1("State to RELAYING_WAIT_EXT"); DEBUG1("State to RELAYING_WAIT_EXT");
m_state = FS_RELAYING_WAIT_EXT; m_state = FS_RELAYING_WAIT_EXT;
serial.writeFMStatus(m_state);
m_ackDelayTimer.start(); m_ackDelayTimer.start();
} }
} }
@@ -965,13 +774,11 @@ void CFM::relayingExtWaitStateDuplex(bool validSignal)
if (validSignal) { if (validSignal) {
DEBUG1("State to RELAYING_EXT"); DEBUG1("State to RELAYING_EXT");
m_state = FS_RELAYING_EXT; m_state = FS_RELAYING_EXT;
serial.writeFMStatus(m_state);
m_ackDelayTimer.stop(); m_ackDelayTimer.stop();
} else { } else {
if (m_ackDelayTimer.isRunning() && m_ackDelayTimer.hasExpired()) { if (m_ackDelayTimer.isRunning() && m_ackDelayTimer.hasExpired()) {
DEBUG1("State to HANG"); DEBUG1("State to HANG");
m_state = FS_HANG; m_state = FS_HANG;
serial.writeFMStatus(m_state);
if (m_ackMinTimer.isRunning()) { if (m_ackMinTimer.isRunning()) {
if (m_ackMinTimer.hasExpired()) { if (m_ackMinTimer.hasExpired()) {
@@ -1002,14 +809,11 @@ void CFM::relayingExtWaitStateSimplex(bool validSignal)
if (validSignal) { if (validSignal) {
DEBUG1("State to RELAYING_EXT"); DEBUG1("State to RELAYING_EXT");
m_state = FS_RELAYING_EXT; m_state = FS_RELAYING_EXT;
serial.writeFMStatus(m_state);
m_ackDelayTimer.stop(); m_ackDelayTimer.stop();
} else { } else {
if (m_ackDelayTimer.isRunning() && m_ackDelayTimer.hasExpired()) { if (m_ackDelayTimer.isRunning() && m_ackDelayTimer.hasExpired()) {
DEBUG1("State to LISTENING"); DEBUG1("State to LISTENING");
m_state = FS_LISTENING; m_state = FS_LISTENING;
serial.writeFMStatus(m_state);
m_ackDelayTimer.stop(); m_ackDelayTimer.stop();
m_timeoutTimer.stop(); m_timeoutTimer.stop();
m_needReverse = true; m_needReverse = true;
@@ -1025,11 +829,6 @@ void CFM::hangStateDuplex(bool validRFSignal, bool validExtSignal)
DEBUG1("State to RELAYING_RF"); DEBUG1("State to RELAYING_RF");
m_state = FS_RELAYING_RF; m_state = FS_RELAYING_RF;
serial.writeFMStatus(m_state);
m_rssiAccum = 0U;
m_rssiCount = 0U;
DEBUG1("Stop ack"); DEBUG1("Stop ack");
m_rfAck.stop(); m_rfAck.stop();
m_extAck.stop(); m_extAck.stop();
@@ -1037,8 +836,6 @@ void CFM::hangStateDuplex(bool validRFSignal, bool validExtSignal)
} else if (validExtSignal) { } else if (validExtSignal) {
DEBUG1("State to RELAYING_EXT"); DEBUG1("State to RELAYING_EXT");
m_state = FS_RELAYING_EXT; m_state = FS_RELAYING_EXT;
serial.writeFMStatus(m_state);
DEBUG1("Stop ack"); DEBUG1("Stop ack");
m_rfAck.stop(); m_rfAck.stop();
m_extAck.stop(); m_extAck.stop();
@@ -1047,9 +844,8 @@ void CFM::hangStateDuplex(bool validRFSignal, bool validExtSignal)
if (m_hangTimer.isRunning() && m_hangTimer.hasExpired()) { if (m_hangTimer.isRunning() && m_hangTimer.hasExpired()) {
DEBUG1("State to LISTENING"); DEBUG1("State to LISTENING");
m_state = FS_LISTENING; m_state = FS_LISTENING;
serial.writeFMStatus(m_state);
m_hangTimer.stop(); m_hangTimer.stop();
m_statusTimer.stop();
if (m_callsignAtEnd) if (m_callsignAtEnd)
sendCallsign(); sendCallsign();
@@ -1073,7 +869,6 @@ void CFM::timeoutRFStateDuplex(bool validSignal)
DEBUG1("State to TIMEOUT_WAIT_RF"); DEBUG1("State to TIMEOUT_WAIT_RF");
m_state = FS_TIMEOUT_WAIT_RF; m_state = FS_TIMEOUT_WAIT_RF;
serial.writeFMStatus(m_state);
if (m_callsignAtEnd) if (m_callsignAtEnd)
sendCallsign(); sendCallsign();
@@ -1095,7 +890,6 @@ void CFM::timeoutRFStateSimplex(bool validSignal)
DEBUG1("State to TIMEOUT_WAIT_RF"); DEBUG1("State to TIMEOUT_WAIT_RF");
m_state = FS_TIMEOUT_WAIT_RF; m_state = FS_TIMEOUT_WAIT_RF;
serial.writeFMStatus(m_state);
m_ackDelayTimer.start(); m_ackDelayTimer.start();
} }
@@ -1109,14 +903,11 @@ void CFM::timeoutRFWaitStateDuplex(bool validSignal)
DEBUG1("State to TIMEOUT_RF"); DEBUG1("State to TIMEOUT_RF");
m_state = FS_TIMEOUT_RF; m_state = FS_TIMEOUT_RF;
serial.writeFMStatus(m_state);
m_ackDelayTimer.stop(); m_ackDelayTimer.stop();
} else { } else {
if (m_ackDelayTimer.isRunning() && m_ackDelayTimer.hasExpired()) { if (m_ackDelayTimer.isRunning() && m_ackDelayTimer.hasExpired()) {
DEBUG1("State to HANG"); DEBUG1("State to HANG");
m_state = FS_HANG; m_state = FS_HANG;
serial.writeFMStatus(m_state);
m_timeoutTone.stop(); m_timeoutTone.stop();
DEBUG1("Send RF ack"); DEBUG1("Send RF ack");
m_rfAck.start(); m_rfAck.start();
@@ -1141,14 +932,11 @@ void CFM::timeoutRFWaitStateSimplex(bool validSignal)
DEBUG1("State to TIMEOUT_RF"); DEBUG1("State to TIMEOUT_RF");
m_state = FS_TIMEOUT_RF; m_state = FS_TIMEOUT_RF;
serial.writeFMStatus(m_state);
m_ackDelayTimer.stop(); m_ackDelayTimer.stop();
} else { } else {
if (m_ackDelayTimer.isRunning() && m_ackDelayTimer.hasExpired()) { if (m_ackDelayTimer.isRunning() && m_ackDelayTimer.hasExpired()) {
DEBUG1("State to LISTENING"); DEBUG1("State to LISTENING");
m_state = FS_LISTENING; m_state = FS_LISTENING;
serial.writeFMStatus(m_state);
m_ackDelayTimer.stop(); m_ackDelayTimer.stop();
m_timeoutTimer.stop(); m_timeoutTimer.stop();
} }
@@ -1160,7 +948,6 @@ void CFM::timeoutExtStateDuplex(bool validSignal)
if (!validSignal) { if (!validSignal) {
DEBUG1("State to TIMEOUT_WAIT_EXT"); DEBUG1("State to TIMEOUT_WAIT_EXT");
m_state = FS_TIMEOUT_WAIT_EXT; m_state = FS_TIMEOUT_WAIT_EXT;
serial.writeFMStatus(m_state);
m_ackDelayTimer.start(); m_ackDelayTimer.start();
} }
@@ -1175,7 +962,6 @@ void CFM::timeoutExtStateSimplex(bool validSignal)
if (!validSignal) { if (!validSignal) {
DEBUG1("State to TIMEOUT_WAIT_EXT"); DEBUG1("State to TIMEOUT_WAIT_EXT");
m_state = FS_TIMEOUT_WAIT_EXT; m_state = FS_TIMEOUT_WAIT_EXT;
serial.writeFMStatus(m_state);
m_ackDelayTimer.start(); m_ackDelayTimer.start();
} }
} }
@@ -1185,14 +971,11 @@ void CFM::timeoutExtWaitStateDuplex(bool validSignal)
if (validSignal) { if (validSignal) {
DEBUG1("State to TIMEOUT_EXT"); DEBUG1("State to TIMEOUT_EXT");
m_state = FS_TIMEOUT_EXT; m_state = FS_TIMEOUT_EXT;
serial.writeFMStatus(m_state);
m_ackDelayTimer.stop(); m_ackDelayTimer.stop();
} else { } else {
if (m_ackDelayTimer.isRunning() && m_ackDelayTimer.hasExpired()) { if (m_ackDelayTimer.isRunning() && m_ackDelayTimer.hasExpired()) {
DEBUG1("State to HANG"); DEBUG1("State to HANG");
m_state = FS_HANG; m_state = FS_HANG;
serial.writeFMStatus(m_state);
m_timeoutTone.stop(); m_timeoutTone.stop();
DEBUG1("Send Ext ack"); DEBUG1("Send Ext ack");
m_extAck.start(); m_extAck.start();
@@ -1214,14 +997,11 @@ void CFM::timeoutExtWaitStateSimplex(bool validSignal)
if (validSignal) { if (validSignal) {
DEBUG1("State to TIMEOUT_EXT"); DEBUG1("State to TIMEOUT_EXT");
m_state = FS_TIMEOUT_EXT; m_state = FS_TIMEOUT_EXT;
serial.writeFMStatus(m_state);
m_ackDelayTimer.stop(); m_ackDelayTimer.stop();
} else { } else {
if (m_ackDelayTimer.isRunning() && m_ackDelayTimer.hasExpired()) { if (m_ackDelayTimer.isRunning() && m_ackDelayTimer.hasExpired()) {
DEBUG1("State to LISTENING"); DEBUG1("State to LISTENING");
m_state = FS_LISTENING; m_state = FS_LISTENING;
serial.writeFMStatus(m_state);
m_ackDelayTimer.stop(); m_ackDelayTimer.stop();
m_timeoutTimer.stop(); m_timeoutTimer.stop();
m_needReverse = true; m_needReverse = true;
@@ -1229,81 +1009,6 @@ void CFM::timeoutExtWaitStateSimplex(bool validSignal)
} }
} }
void CFM::linkStateMachine(bool validRFSignal, bool validExtSignal)
{
if (validRFSignal && !m_rfSignal) {
io.setDecode(true);
io.setADCDetection(true);
if (!m_extSignal) {
DEBUG1("State to RELAYING_RF");
m_state = FS_RELAYING_RF;
serial.writeFMStatus(m_state);
}
m_rfSignal = true;
}
if (validExtSignal && !m_extSignal) {
if (!m_rfSignal) {
DEBUG1("State to RELAYING_EXT");
m_state = FS_RELAYING_EXT;
serial.writeFMStatus(m_state);
}
insertSilence(50U);
m_extSignal = true;
}
if (validExtSignal && m_extGapTimer.isRunning()) {
// Recovered before the gap timer committed to a real loss below --
// m_extSignal was never flipped, so there is nothing else to undo.
m_extGapTimer.stop();
}
if (!validRFSignal && m_rfSignal) {
io.setDecode(false);
io.setADCDetection(false);
if (!m_extSignal) {
DEBUG1("State to LISTENING");
m_state = FS_LISTENING;
serial.writeFMStatus(m_state);
}
m_rfSignal = false;
if (m_extEnabled)
serial.writeFMEOT();
}
if (!validExtSignal && m_extSignal) {
// A missed/late sample used to flip m_extSignal false right here, on
// the very first bad sample, with zero debounce -- that is what
// actually keys the transmitter off (IO::process() drops PTT the
// instant the downstream TX buffer runs dry, see IO.cpp). A gap well
// under FM_LINK_EXT_GAP_MS is less offensive than the PTT
// drop-and-rekey it triggers. Give it a short grace period
// mirroring the RELAYING_EXT/RELAYING_WAIT_EXT pattern the
// non-link duplex/simplex paths already use for exactly this
// situation (see relayingExtStateDuplex()/relayingExtWaitStateDuplex()).
if (!m_extGapTimer.isRunning()) {
m_extGapTimer.start();
} else if (m_extGapTimer.hasExpired()) {
if (!m_rfSignal) {
DEBUG1("State to LISTENING");
m_state = FS_LISTENING;
serial.writeFMStatus(m_state);
}
m_needReverse = true;
m_extSignal = false;
m_extGapTimer.stop();
}
}
}
void CFM::sendCallsign() void CFM::sendCallsign()
{ {
if (m_holdoffTimer.isRunning()) { if (m_holdoffTimer.isRunning()) {
@@ -1330,7 +1035,7 @@ uint8_t CFM::getSpace() const
return m_inputExtRB.getSpace() / FM_SERIAL_BLOCK_SIZE_BYTES; return m_inputExtRB.getSpace() / FM_SERIAL_BLOCK_SIZE_BYTES;
} }
uint8_t CFM::writeData(const uint8_t* data, uint16_t length) uint8_t CFM::writeData(const uint8_t* data, uint8_t length)
{ {
//todo check if length is a multiple of 3 //todo check if length is a multiple of 3
m_inputExtRB.addData(data, length); m_inputExtRB.addData(data, length);
+21 -22
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2020,2021,2023,2025 by Jonathan Naylor G4KLX * Copyright (C) 2020 by Jonathan Naylor G4KLX
* *
* 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
@@ -35,12 +35,27 @@
#include "FMUpSampler.h" #include "FMUpSampler.h"
#include "FMNoiseSquelch.h" #include "FMNoiseSquelch.h"
enum FM_STATE {
FS_LISTENING,
FS_KERCHUNK_RF,
FS_RELAYING_RF,
FS_RELAYING_WAIT_RF,
FS_TIMEOUT_RF,
FS_TIMEOUT_WAIT_RF,
FS_KERCHUNK_EXT,
FS_RELAYING_EXT,
FS_RELAYING_WAIT_EXT,
FS_TIMEOUT_EXT,
FS_TIMEOUT_WAIT_EXT,
FS_HANG
};
class CFM { class CFM {
public: public:
CFM(); CFM();
void samples(bool cos, q15_t* samples, const uint16_t* rssi, uint8_t length); void samples(bool cos, q15_t* samples, uint8_t length);
void process(); void process();
@@ -48,12 +63,12 @@ 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 linkMode, bool cosInvert, bool noiseSquelch, uint8_t squelchHighThreshold, uint8_t squelchLowThreshold, 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 setExt(const char* ack, uint8_t audioBoost, uint8_t speed, uint16_t frequency, uint8_t level);
uint8_t getSpace() const; uint8_t getSpace() const;
uint8_t writeData(const uint8_t* data, uint16_t length); uint8_t writeData(const uint8_t* data, uint8_t length);
private: private:
CFMKeyer m_callsign; CFMKeyer m_callsign;
@@ -63,7 +78,7 @@ private:
CFMCTCSSTX m_ctcssTX; CFMCTCSSTX m_ctcssTX;
CFMNoiseSquelch m_squelch; CFMNoiseSquelch m_squelch;
CFMTimeout m_timeoutTone; CFMTimeout m_timeoutTone;
uint8_t m_state; FM_STATE m_state;
bool m_callsignAtStart; bool m_callsignAtStart;
bool m_callsignAtEnd; bool m_callsignAtEnd;
bool m_callsignAtLatch; bool m_callsignAtLatch;
@@ -74,21 +89,14 @@ 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;
CFMTimer m_extGapTimer; // debounce for link-mode ext-audio underrun, see linkStateMachine()
bool m_needReverse; bool m_needReverse;
CFMDirectFormI m_filterStage1; CFMDirectFormI m_filterStage1;
CFMDirectFormI m_filterStage2; CFMDirectFormI m_filterStage2;
CFMDirectFormI m_filterStage3; CFMDirectFormI m_filterStage3;
CFMDirectFormI m_dsFilterStage1; // anti-alias filter for the downsampler, own state
CFMDirectFormI m_dsFilterStage2;
CFMDirectFormI m_dsFilterStage3;
CFMDirectFormI m_usFilterStage1; // reconstruction filter for the upsampler, own state
CFMDirectFormI m_usFilterStage2;
CFMDirectFormI m_usFilterStage3;
CFMBlanking m_blanking; CFMBlanking m_blanking;
uint8_t m_accessMode; uint8_t m_accessMode;
bool m_linkMode;
bool m_cosInvert; bool m_cosInvert;
bool m_noiseSquelch; bool m_noiseSquelch;
q15_t m_rfAudioBoost; q15_t m_rfAudioBoost;
@@ -99,16 +107,9 @@ private:
CRingBuffer<q15_t> m_inputRFRB; CRingBuffer<q15_t> m_inputRFRB;
CRingBuffer<q15_t> m_outputRFRB; CRingBuffer<q15_t> m_outputRFRB;
CFMUpSampler m_inputExtRB; CFMUpSampler m_inputExtRB;
bool m_rfSignal;
bool m_extSignal;
uint32_t m_rssiAccum;
uint16_t m_rssiCount;
void stateMachine(bool validRFSignal, bool validExtSignal); void stateMachine(bool validRFSignal, bool validExtSignal);
void repeaterSamples(bool cos, q15_t* samples, const uint16_t* rssi, uint8_t length);
void linkSamples(bool cos, q15_t* samples, uint8_t length);
void duplexStateMachine(bool validRFSignal, bool validExtSignal); void duplexStateMachine(bool validRFSignal, bool validExtSignal);
void listeningStateDuplex(bool validRFSignal, bool validExtSignal); void listeningStateDuplex(bool validRFSignal, bool validExtSignal);
void kerchunkRFStateDuplex(bool validSignal); void kerchunkRFStateDuplex(bool validSignal);
@@ -134,8 +135,6 @@ private:
void timeoutExtStateSimplex(bool validSignal); void timeoutExtStateSimplex(bool validSignal);
void timeoutExtWaitStateSimplex(bool validSignal); void timeoutExtWaitStateSimplex(bool validSignal);
void linkStateMachine(bool validRFSignal, bool validExtSignal);
void clock(uint8_t length); void clock(uint8_t length);
void sendCallsign(); void sendCallsign();
+11 -6
View File
@@ -42,7 +42,8 @@ class CFMDirectFormI
public: public:
// convenience function which takes the a0 argument but ignores it! // convenience function which takes the a0 argument but ignores it!
CFMDirectFormI(const q31_t b0, const q31_t b1, const q31_t b2, const q31_t, const q31_t a1, const q31_t a2) CFMDirectFormI(const q31_t b0, const q31_t b1, const q31_t b2,
const q31_t, const q31_t a1, const q31_t a2)
{ {
// FIR coefficients // FIR coefficients
c_b0 = b0; c_b0 = b0;
@@ -56,21 +57,21 @@ public:
CFMDirectFormI(const CFMDirectFormI &my) CFMDirectFormI(const CFMDirectFormI &my)
{ {
// delay line // delay line
m_x2 = my.m_x2; // x[n-2] m_x2 = my.m_x2; // x[n-2]
m_y2 = my.m_y2; // y[n-2] m_y2 = my.m_y2; // y[n-2]
m_x1 = my.m_x1; // x[n-1] m_x1 = my.m_x1; // x[n-1]
m_y1 = my.m_y1; // y[n-1] m_y1 = my.m_y1; // y[n-1]
// coefficients // coefficients
c_b0 = my.c_b0; c_b0 = my.c_b0;
c_b1 = my.c_b1; c_b1 = my.c_b1;
c_b2 = my.c_b2; // FIR c_b2 = my.c_b2; // FIR
c_a1 = my.c_a1; c_a1 = my.c_a1;
c_a2 = my.c_a2; // IIR c_a2 = my.c_a2; // IIR
} }
void reset() void reset ()
{ {
m_x1 = 0; m_x1 = 0;
m_x2 = 0; m_x2 = 0;
@@ -82,7 +83,11 @@ public:
inline q15_t filter(const q15_t in) inline q15_t filter(const q15_t in)
{ {
// calculate the output // calculate the output
q31_t out_upscaled = c_b0 * in + c_b1 * m_x1 + c_b2 * m_x2 - c_a1 * m_y1 - c_a2 * m_y2; register q31_t out_upscaled = c_b0 * in
+ c_b1 * m_x1
+ c_b2 * m_x2
- c_a1 * m_y1
- c_a2 * m_y2;
q15_t out = __SSAT(out_upscaled >> 15, 15); q15_t out = __SSAT(out_upscaled >> 15, 15);
-3
View File
@@ -34,7 +34,6 @@ m_sampleIndex(0U)
void CFMDownSampler::addSample(q15_t sample) void CFMDownSampler::addSample(q15_t sample)
{ {
sample = __SSAT(sample, 12);//clamp before packing to 12 bits
uint32_t usample = uint32_t(int32_t(sample) + 2048); uint32_t usample = uint32_t(int32_t(sample) + 2048);
//only take one of three samples //only take one of three samples
switch(m_sampleIndex){ switch(m_sampleIndex){
@@ -75,8 +74,6 @@ uint16_t CFMDownSampler::getData()
void CFMDownSampler::reset() void CFMDownSampler::reset()
{ {
m_sampleIndex = 0U; m_sampleIndex = 0U;
m_samplePack = 0U;
m_ringBuffer.reset();
} }
#endif #endif
+1 -4
View File
@@ -36,8 +36,7 @@ m_count(0U),
m_q0(0), m_q0(0),
m_q1(0), m_q1(0),
m_state(false), m_state(false),
m_validCount(0U), m_validCount(0U)
m_invalidCount(0U)
{ {
} }
@@ -128,8 +127,6 @@ void CFMNoiseSquelch::reset()
m_q1 = 0; m_q1 = 0;
m_state = false; m_state = false;
m_count = 0U; m_count = 0U;
m_validCount = 0U;
m_invalidCount = 0U;
} }
#endif #endif
+30 -3
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2015,2016,2017,2018,2020,2021,2025 by Jonathan Naylor G4KLX * Copyright (C) 2015,2016,2017,2018,2020,2021 by Jonathan Naylor G4KLX
* *
* 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
@@ -23,12 +23,15 @@
#include "stm32f4xx.h" #include "stm32f4xx.h"
#elif defined(STM32F7XX) #elif defined(STM32F7XX)
#include "stm32f7xx.h" #include "stm32f7xx.h"
#elif defined(STM32F105xC)
#include "stm32f1xx.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. #undef PI //Undefine PI to get rid of annoying warning as it is also defined in arm_math.h.
#endif #endif
#if defined(__SAM3X8E__) #if defined(__SAM3X8E__) || defined(STM32F105xC)
#define ARM_MATH_CM3 #define ARM_MATH_CM3
#elif defined(STM32F7XX) #elif defined(STM32F7XX)
#define ARM_MATH_CM7 #define ARM_MATH_CM7
@@ -48,7 +51,9 @@ enum MMDVM_STATE {
STATE_P25 = 4, STATE_P25 = 4,
STATE_NXDN = 5, STATE_NXDN = 5,
STATE_POCSAG = 6, STATE_POCSAG = 6,
STATE_M17 = 7,
STATE_FM = 10, STATE_FM = 10,
STATE_AX25 = 11,
// Dummy states start at 90 // Dummy states start at 90
STATE_NXDNCAL1K = 91, STATE_NXDNCAL1K = 91,
@@ -82,6 +87,8 @@ enum MMDVM_STATE {
#include "YSFTX.h" #include "YSFTX.h"
#include "P25RX.h" #include "P25RX.h"
#include "P25TX.h" #include "P25TX.h"
#include "M17RX.h"
#include "M17TX.h"
#include "NXDNRX.h" #include "NXDNRX.h"
#include "NXDNTX.h" #include "NXDNTX.h"
#include "POCSAGTX.h" #include "POCSAGTX.h"
@@ -93,8 +100,12 @@ enum MMDVM_STATE {
#include "CalNXDN.h" #include "CalNXDN.h"
#include "CalPOCSAG.h" #include "CalPOCSAG.h"
#include "CalRSSI.h" #include "CalRSSI.h"
#include "I2COLED.h"
#include "CWIdTX.h" #include "CWIdTX.h"
#include "AX25RX.h"
#include "AX25TX.h"
#include "Debug.h" #include "Debug.h"
#include "I2C3.h"
#include "IO.h" #include "IO.h"
#include "FM.h" #include "FM.h"
@@ -107,7 +118,7 @@ const uint16_t RX_BLOCK_SIZE = 2U;
const uint16_t TX_RINGBUFFER_SIZE = 500U; const uint16_t TX_RINGBUFFER_SIZE = 500U;
const uint16_t RX_RINGBUFFER_SIZE = 600U; const uint16_t RX_RINGBUFFER_SIZE = 600U;
#if defined(__MK20DX256__) #if defined(STM32F105xC) || defined(__MK20DX256__)
const uint16_t TX_BUFFER_LEN = 2000U; const uint16_t TX_BUFFER_LEN = 2000U;
#else #else
const uint16_t TX_BUFFER_LEN = 4000U; const uint16_t TX_BUFFER_LEN = 4000U;
@@ -121,7 +132,9 @@ extern bool m_ysfEnable;
extern bool m_p25Enable; extern bool m_p25Enable;
extern bool m_nxdnEnable; extern bool m_nxdnEnable;
extern bool m_pocsagEnable; extern bool m_pocsagEnable;
extern bool m_m17Enable;
extern bool m_fmEnable; extern bool m_fmEnable;
extern bool m_ax25Enable;
extern bool m_duplex; extern bool m_duplex;
@@ -131,6 +144,10 @@ extern bool m_dcd;
extern CSerialPort serial; extern CSerialPort serial;
extern CIO io; extern CIO io;
#if defined(MODE_OLED)
extern CI2COLED oled;
#endif
#if defined(MODE_DSTAR) #if defined(MODE_DSTAR)
extern CDStarRX dstarRX; extern CDStarRX dstarRX;
extern CDStarTX dstarTX; extern CDStarTX dstarTX;
@@ -174,11 +191,21 @@ extern CPOCSAGTX pocsagTX;
extern CCalPOCSAG calPOCSAG; extern CCalPOCSAG calPOCSAG;
#endif #endif
#if defined(MODE_M17)
extern CM17RX m17RX;
extern CM17TX m17TX;
#endif
#if defined(MODE_FM) #if defined(MODE_FM)
extern CFM fm; extern CFM fm;
extern CCalFM calFM; extern CCalFM calFM;
#endif #endif
#if defined(MODE_AX25)
extern CAX25RX ax25RX;
extern CAX25TX ax25TX;
#endif
extern CCalRSSI calRSSI; extern CCalRSSI calRSSI;
extern CCWIdTX cwIdTX; extern CCWIdTX cwIdTX;
+284
View File
@@ -0,0 +1,284 @@
/*
* Copyright (C) 2020,2021 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"
#if defined(MODE_OLED)
#include "I2C3.h"
#include "Globals.h"
#define I2C_WRITE_REG(REG, VAL) ((REG) = (VAL))
#define I2C_READ_REG(REG) ((REG))
#define I2C_CLEAR_FLAG(__FLAG__) (((__FLAG__) == I2C_FLAG_TXE) ? (I2C3->ISR |= (__FLAG__)) : (I2C3->ICR = (__FLAG__)))
#define I2C_GET_FLAG(__FLAG__) ((((I2C3->ISR) & (__FLAG__)) == (__FLAG__)) ? SET : RESET)
#define I2C_RESET_CR2() (I2C3->CR2 &= (uint32_t)~((uint32_t)(I2C_CR2_SADD | I2C_CR2_HEAD10R | I2C_CR2_NBYTES | I2C_CR2_RELOAD | I2C_CR2_RD_WRN)))
#define I2C_MODIFY_REG(REG, CLEARMASK, SETMASK) I2C_WRITE_REG((REG), (((I2C_READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK)))
#define TIMING_CLEAR_MASK (0xF0FFFFFFU)
#define I2C_DUALADDRESS_DISABLE (0x00000000U)
#define I2C_DUALADDRESS_ENABLE I2C_OAR2_OA2EN
#define I2C_GENERALCALL_DISABLE (0x00000000U)
#define I2C_NOSTRETCH_DISABLE (0x00000000U)
#define I2C_ANALOGFILTER_ENABLE 0x00000000U
#define RCC_I2C3CLKSOURCE_PCLK1 ((uint32_t)0x00000000U)
#define I2C_OA2_NOMASK ((uint8_t)0x00U)
#define GPIO_MODE_AF_OD ((uint32_t)0x00000012U)
#define GPIO_OUTPUT_TYPE ((uint32_t)0x00000010U)
#define GPIO_MODE ((uint32_t)0x00000003U)
#define GPIO_NUMBER (16U)
#define I2C_ENABLE() (SET_BIT(I2C3->CR1, I2C_CR1_PE))
#define I2C_DISABLE() (CLEAR_BIT(I2C3->CR1, I2C_CR1_PE))
#define RCC_GPIOA_CLK_ENABLE() do { \
__IO uint32_t tmpreg; \
SET_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIOAEN);\
tmpreg = READ_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIOAEN);\
} while(0)
#define RCC_GPIOC_CLK_ENABLE() do { \
__IO uint32_t tmpreg; \
SET_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIOCEN);\
tmpreg = READ_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIOCEN);\
} while(0)
#define RCC_I2C3_CLK_ENABLE() do { \
__IO uint32_t tmpreg; \
SET_BIT(RCC->APB1ENR, RCC_APB1ENR_I2C3EN);\
tmpreg = READ_BIT(RCC->APB1ENR, RCC_APB1ENR_I2C3EN);\
} while(0)
CI2C3::CI2C3()
{
}
void CI2C3::init()
{
// Enable the I2C3 clock
I2C_MODIFY_REG(RCC->DCKCFGR2, RCC_DCKCFGR2_I2C3SEL, RCC_I2C3CLKSOURCE_PCLK1);
// Enable the GPIOs for the SCL/SDA Pins
RCC_GPIOC_CLK_ENABLE();
RCC_GPIOA_CLK_ENABLE();
initI2C3();
// Configure Analogue filter
configAnalogFilter(I2C_ANALOGFILTER_ENABLE);
// Configure Digital filter
configDigitalFilter(0U);
}
void CI2C3::write(uint16_t addr, const uint8_t* data, uint8_t length)
{
DEBUG2("OLED Data", addr);
DEBUG_DUMP(data, length);
// Shift the address to the left
addr <<= 3;
// Wait for the I2C transmitter to become free
while (I2C_GET_FLAG(I2C_FLAG_BUSY) == SET)
;
// Configure the data transfer
transferConfig(addr, length, I2C_CR2_AUTOEND, I2C_Generate_Start_Write);
// Start Writing Data
for (uint16_t i = 0U; i < length; i++) {
// Wait for the TXIS flag to be set
while (I2C_GET_FLAG(I2C_FLAG_TXIS) == RESET)
;
// Write the byte to the TXDR
I2C3->TXDR = data[i];
}
// No need to Check TC flag, with AUTOEND mode the stop is automatically generated Wait until STOPF flag is set
while (I2C_GET_FLAG(I2C_FLAG_STOPF) == RESET)
;
// Clear STOP flag
I2C_CLEAR_FLAG(I2C_FLAG_STOPF);
// Clear Configuration Register 2
I2C_RESET_CR2();
}
void CI2C3::transferConfig(uint16_t addr, uint8_t length, uint32_t mode, uint32_t request)
{
// Update CR2 register
I2C_MODIFY_REG(I2C3->CR2, ((I2C_CR2_SADD | I2C_CR2_NBYTES | I2C_CR2_RELOAD | I2C_CR2_AUTOEND | \
(I2C_CR2_RD_WRN & (uint32_t)(request >> (31U - I2C_CR2_RD_WRN_Pos))) | I2C_CR2_START | I2C_CR2_STOP)), \
(uint32_t)(((uint32_t)addr & I2C_CR2_SADD) |
(((uint32_t)length << I2C_CR2_NBYTES_Pos) & I2C_CR2_NBYTES) | (uint32_t)mode | (uint32_t)request));
}
void CI2C3::configAnalogFilter(uint32_t AnalogFilter)
{
// Disable the selected I2C peripheral
I2C_DISABLE();
// Reset I2Cx ANOFF bit
I2C3->CR1 &= ~(I2C_CR1_ANFOFF);
// Set analog filter bit
I2C3->CR1 |= AnalogFilter;
I2C_ENABLE();
}
void CI2C3::configDigitalFilter(uint32_t DigitalFilter)
{
// Disable the selected I2C peripheral
I2C_DISABLE();
// Get the old register value
uint32_t tmpreg = I2C3->CR1;
// Reset I2Cx DNF bits [11:8]
tmpreg &= ~(I2C_CR1_DNF);
// Set I2Cx DNF coefficient
tmpreg |= DigitalFilter << 8U;
// Store the new register value
I2C3->CR1 = tmpreg;
I2C_ENABLE();
}
void CI2C3::initI2C3()
{
initMSP();
/* Disable the selected I2C peripheral */
I2C_DISABLE();
/*---------------------------- I2Cx TIMINGR Configuration ------------------*/
/* Configure I2Cx: Frequency range */
I2C3->TIMINGR = 0x0010061AU & TIMING_CLEAR_MASK;
/*---------------------------- I2Cx OAR1 Configuration ---------------------*/
/* Disable Own Address1 before set the Own Address1 configuration */
I2C3->OAR1 &= ~I2C_OAR1_OA1EN;
/* Configure I2Cx: Own Address1 and ack own address1 mode */
I2C3->OAR1 = (I2C_OAR1_OA1EN | 0U);
/*---------------------------- I2Cx CR2 Configuration ----------------------*/
/* Enable the AUTOEND by default, and enable NACK (should be disable only during Slave process */
I2C3->CR2 |= (I2C_CR2_AUTOEND | I2C_CR2_NACK);
/*---------------------------- I2Cx OAR2 Configuration ---------------------*/
/* Disable Own Address2 before set the Own Address2 configuration */
I2C3->OAR2 &= ~I2C_DUALADDRESS_ENABLE;
/* Configure I2Cx: Dual mode and Own Address2 */
I2C3->OAR2 = (I2C_DUALADDRESS_DISABLE | 0U | (I2C_OA2_NOMASK << 8));
/*---------------------------- I2Cx CR1 Configuration ----------------------*/
/* Configure I2Cx: Generalcall and NoStretch mode */
I2C3->CR1 = (I2C_GENERALCALL_DISABLE | I2C_NOSTRETCH_DISABLE);
/* Enable the selected I2C peripheral */
I2C_ENABLE();
}
void CI2C3::initMSP()
{
RCC_GPIOC_CLK_ENABLE();
RCC_GPIOA_CLK_ENABLE();
/* I2C3 GPIO Configuration
PC9 ------> I2C3_SDA
PA8 ------> I2C3_SCL
*/
initGPIO(GPIOC, GPIO_Pin_9);
initGPIO(GPIOA, GPIO_Pin_8);
// Peripheral clock enable
RCC_I2C3_CLK_ENABLE();
}
void CI2C3::initGPIO(GPIO_TypeDef* GPIOx, uint32_t Pin)
{
// Configure the port pins
for (uint32_t position = 0U; position < GPIO_NUMBER; position++)
{
// Get the IO position
uint32_t ioposition = ((uint32_t)0x01) << position;
// Get the current IO position
uint32_t iocurrent = Pin & ioposition;
if (iocurrent == ioposition)
{
// Configure the IO Speed
uint32_t temp = GPIOx->OSPEEDR;
temp &= ~(GPIO_OSPEEDER_OSPEEDR0 << (position * 2));
temp |= (GPIO_High_Speed << (position * 2));
GPIOx->OSPEEDR = temp;
// Configure the IO Output Type
temp = GPIOx->OTYPER;
temp &= ~(GPIO_OTYPER_OT_0 << position) ;
temp |= (((GPIO_MODE_AF_OD & GPIO_OUTPUT_TYPE) >> 4) << position);
GPIOx->OTYPER = temp;
// Activate the Pull Up resistor for the current IO
temp = GPIOx->PUPDR;
temp &= ~(GPIO_PUPDR_PUPDR0 << (position * 2));
temp |= ((GPIO_PuPd_UP) << (position * 2));
GPIOx->PUPDR = temp;
// Configure Alternate function mapped with the current IO
temp = GPIOx->AFR[position >> 3];
temp &= ~((uint32_t)0xF << ((uint32_t)(position & (uint32_t)0x07) * 4)) ;
temp |= ((uint32_t)(GPIO_AF4_I2C3) << (((uint32_t)position & (uint32_t)0x07) * 4));
GPIOx->AFR[position >> 3] = temp;
// Configure IO Direction mode (Input, Output, Alternate or Analog)
temp = GPIOx->MODER;
temp &= ~(GPIO_MODER_MODER0 << (position * 2));
temp |= ((GPIO_MODE_AF_OD & GPIO_MODE) << (position * 2));
GPIOx->MODER = temp;
}
}
}
#endif
+52
View File
@@ -0,0 +1,52 @@
/*
* Copyright (C) 2020,2021 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"
#if defined(MODE_OLED)
#if !defined(I2C3_H)
#define I2C3_H
#if defined(STM32F7XX)
#include "stm32f7xx.h"
#include "stm32f7xx_i2c.h"
#endif
class CI2C3 {
public:
CI2C3();
void init();
void write(uint16_t addr, const uint8_t* data, uint8_t length);
private:
void transferConfig(uint16_t addr, uint8_t length, uint32_t mode, uint32_t request);
void configAnalogFilter(uint32_t AnalogFilter);
void configDigitalFilter(uint32_t DigitalFilter);
void initI2C3();
void initMSP();
void initGPIO(GPIO_TypeDef* GPIOx, uint32_t Pin);
};
#endif
#endif
+509
View File
@@ -0,0 +1,509 @@
/*
* Copyright (C) 2020,2021 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"
#if defined(MODE_OLED)
#include "I2COLED.h"
#include "I2C3.h"
#include "Globals.h"
const uint8_t OLED_ADDRESS = 0x78U;
const uint8_t OLED_WIDTH = 64U;
const uint8_t OLED_HEIGHT = 32U;
const uint16_t OLED_BUFFER_SIZE = (OLED_HEIGHT * OLED_WIDTH) / 8U;
const uint8_t SSD_Command_Mode = 0x00U; /* C0 and DC bit are 0 */
const uint8_t SSD_Data_Mode = 0x40U; /* C0 bit is 0 and DC bit is 1 */
const uint8_t SSD1306_Set_Lower_Column_Start_Address = 0x00U;
const uint8_t SSD1306_Set_Higher_Column_Start_Address = 0x10U;
const uint8_t SSD1306_Set_Start_Line = 0x40U;
const uint8_t CHAR_HEIGHT = 5U;
const uint8_t CHAR_WIDTH = 7U;
// Standard ascii 5x7 font
const uint8_t FONT[] = {
0x00U, 0x00U, 0x00U, 0x00U, 0x00U,
0x3EU, 0x5BU, 0x4FU, 0x5BU, 0x3EU,
0x3EU, 0x6BU, 0x4FU, 0x6BU, 0x3EU,
0x1CU, 0x3EU, 0x7CU, 0x3EU, 0x1CU,
0x18U, 0x3CU, 0x7EU, 0x3CU, 0x18U,
0x1CU, 0x57U, 0x7DU, 0x57U, 0x1CU,
0x1CU, 0x5EU, 0x7FU, 0x5EU, 0x1CU,
0x00U, 0x18U, 0x3CU, 0x18U, 0x00U,
0xFFU, 0xE7U, 0xC3U, 0xE7U, 0xFFU,
0x00U, 0x18U, 0x24U, 0x18U, 0x00U,
0xFFU, 0xE7U, 0xDBU, 0xE7U, 0xFFU,
0x30U, 0x48U, 0x3AU, 0x06U, 0x0EU,
0x26U, 0x29U, 0x79U, 0x29U, 0x26U,
0x40U, 0x7FU, 0x05U, 0x05U, 0x07U,
0x40U, 0x7FU, 0x05U, 0x25U, 0x3FU,
0x5AU, 0x3CU, 0xE7U, 0x3CU, 0x5AU,
0x7FU, 0x3EU, 0x1CU, 0x1CU, 0x08U,
0x08U, 0x1CU, 0x1CU, 0x3EU, 0x7FU,
0x14U, 0x22U, 0x7FU, 0x22U, 0x14U,
0x5FU, 0x5FU, 0x00U, 0x5FU, 0x5FU,
0x06U, 0x09U, 0x7FU, 0x01U, 0x7FU,
0x00U, 0x66U, 0x89U, 0x95U, 0x6AU,
0x60U, 0x60U, 0x60U, 0x60U, 0x60U,
0x94U, 0xA2U, 0xFFU, 0xA2U, 0x94U,
0x08U, 0x04U, 0x7EU, 0x04U, 0x08U,
0x10U, 0x20U, 0x7EU, 0x20U, 0x10U,
0x08U, 0x08U, 0x2AU, 0x1CU, 0x08U,
0x08U, 0x1CU, 0x2AU, 0x08U, 0x08U,
0x1EU, 0x10U, 0x10U, 0x10U, 0x10U,
0x0CU, 0x1EU, 0x0CU, 0x1EU, 0x0CU,
0x30U, 0x38U, 0x3EU, 0x38U, 0x30U,
0x06U, 0x0EU, 0x3EU, 0x0EU, 0x06U,
0x00U, 0x00U, 0x00U, 0x00U, 0x00U,
0x00U, 0x00U, 0x5FU, 0x00U, 0x00U,
0x00U, 0x07U, 0x00U, 0x07U, 0x00U,
0x14U, 0x7FU, 0x14U, 0x7FU, 0x14U,
0x24U, 0x2AU, 0x7FU, 0x2AU, 0x12U,
0x23U, 0x13U, 0x08U, 0x64U, 0x62U,
0x36U, 0x49U, 0x56U, 0x20U, 0x50U,
0x00U, 0x08U, 0x07U, 0x03U, 0x00U,
0x00U, 0x1CU, 0x22U, 0x41U, 0x00U,
0x00U, 0x41U, 0x22U, 0x1CU, 0x00U,
0x2AU, 0x1CU, 0x7FU, 0x1CU, 0x2AU,
0x08U, 0x08U, 0x3EU, 0x08U, 0x08U,
0x00U, 0x80U, 0x70U, 0x30U, 0x00U,
0x08U, 0x08U, 0x08U, 0x08U, 0x08U,
0x00U, 0x00U, 0x60U, 0x60U, 0x00U,
0x20U, 0x10U, 0x08U, 0x04U, 0x02U,
0x3EU, 0x51U, 0x49U, 0x45U, 0x3EU,
0x00U, 0x42U, 0x7FU, 0x40U, 0x00U,
0x72U, 0x49U, 0x49U, 0x49U, 0x46U,
0x21U, 0x41U, 0x49U, 0x4DU, 0x33U,
0x18U, 0x14U, 0x12U, 0x7FU, 0x10U,
0x27U, 0x45U, 0x45U, 0x45U, 0x39U,
0x3CU, 0x4AU, 0x49U, 0x49U, 0x31U,
0x41U, 0x21U, 0x11U, 0x09U, 0x07U,
0x36U, 0x49U, 0x49U, 0x49U, 0x36U,
0x46U, 0x49U, 0x49U, 0x29U, 0x1EU,
0x00U, 0x00U, 0x14U, 0x00U, 0x00U,
0x00U, 0x40U, 0x34U, 0x00U, 0x00U,
0x00U, 0x08U, 0x14U, 0x22U, 0x41U,
0x14U, 0x14U, 0x14U, 0x14U, 0x14U,
0x00U, 0x41U, 0x22U, 0x14U, 0x08U,
0x02U, 0x01U, 0x59U, 0x09U, 0x06U,
0x3EU, 0x41U, 0x5DU, 0x59U, 0x4EU,
0x7CU, 0x12U, 0x11U, 0x12U, 0x7CU,
0x7FU, 0x49U, 0x49U, 0x49U, 0x36U,
0x3EU, 0x41U, 0x41U, 0x41U, 0x22U,
0x7FU, 0x41U, 0x41U, 0x41U, 0x3EU,
0x7FU, 0x49U, 0x49U, 0x49U, 0x41U,
0x7FU, 0x09U, 0x09U, 0x09U, 0x01U,
0x3EU, 0x41U, 0x41U, 0x51U, 0x73U,
0x7FU, 0x08U, 0x08U, 0x08U, 0x7FU,
0x00U, 0x41U, 0x7FU, 0x41U, 0x00U,
0x20U, 0x40U, 0x41U, 0x3FU, 0x01U,
0x7FU, 0x08U, 0x14U, 0x22U, 0x41U,
0x7FU, 0x40U, 0x40U, 0x40U, 0x40U,
0x7FU, 0x02U, 0x1CU, 0x02U, 0x7FU,
0x7FU, 0x04U, 0x08U, 0x10U, 0x7FU,
0x3EU, 0x41U, 0x41U, 0x41U, 0x3EU,
0x7FU, 0x09U, 0x09U, 0x09U, 0x06U,
0x3EU, 0x41U, 0x51U, 0x21U, 0x5EU,
0x7FU, 0x09U, 0x19U, 0x29U, 0x46U,
0x26U, 0x49U, 0x49U, 0x49U, 0x32U,
0x03U, 0x01U, 0x7FU, 0x01U, 0x03U,
0x3FU, 0x40U, 0x40U, 0x40U, 0x3FU,
0x1FU, 0x20U, 0x40U, 0x20U, 0x1FU,
0x3FU, 0x40U, 0x38U, 0x40U, 0x3FU,
0x63U, 0x14U, 0x08U, 0x14U, 0x63U,
0x03U, 0x04U, 0x78U, 0x04U, 0x03U,
0x61U, 0x59U, 0x49U, 0x4DU, 0x43U,
0x00U, 0x7FU, 0x41U, 0x41U, 0x41U,
0x02U, 0x04U, 0x08U, 0x10U, 0x20U,
0x00U, 0x41U, 0x41U, 0x41U, 0x7FU,
0x04U, 0x02U, 0x01U, 0x02U, 0x04U,
0x40U, 0x40U, 0x40U, 0x40U, 0x40U,
0x00U, 0x03U, 0x07U, 0x08U, 0x00U,
0x20U, 0x54U, 0x54U, 0x78U, 0x40U,
0x7FU, 0x28U, 0x44U, 0x44U, 0x38U,
0x38U, 0x44U, 0x44U, 0x44U, 0x28U,
0x38U, 0x44U, 0x44U, 0x28U, 0x7FU,
0x38U, 0x54U, 0x54U, 0x54U, 0x18U,
0x00U, 0x08U, 0x7EU, 0x09U, 0x02U,
0x18U, 0xA4U, 0xA4U, 0x9CU, 0x78U,
0x7FU, 0x08U, 0x04U, 0x04U, 0x78U,
0x00U, 0x44U, 0x7DU, 0x40U, 0x00U,
0x20U, 0x40U, 0x40U, 0x3DU, 0x00U,
0x7FU, 0x10U, 0x28U, 0x44U, 0x00U,
0x00U, 0x41U, 0x7FU, 0x40U, 0x00U,
0x7CU, 0x04U, 0x78U, 0x04U, 0x78U,
0x7CU, 0x08U, 0x04U, 0x04U, 0x78U,
0x38U, 0x44U, 0x44U, 0x44U, 0x38U,
0xFCU, 0x18U, 0x24U, 0x24U, 0x18U,
0x18U, 0x24U, 0x24U, 0x18U, 0xFCU,
0x7CU, 0x08U, 0x04U, 0x04U, 0x08U,
0x48U, 0x54U, 0x54U, 0x54U, 0x24U,
0x04U, 0x04U, 0x3FU, 0x44U, 0x24U,
0x3CU, 0x40U, 0x40U, 0x20U, 0x7CU,
0x1CU, 0x20U, 0x40U, 0x20U, 0x1CU,
0x3CU, 0x40U, 0x30U, 0x40U, 0x3CU,
0x44U, 0x28U, 0x10U, 0x28U, 0x44U,
0x4CU, 0x90U, 0x90U, 0x90U, 0x7CU,
0x44U, 0x64U, 0x54U, 0x4CU, 0x44U,
0x00U, 0x08U, 0x36U, 0x41U, 0x00U,
0x00U, 0x00U, 0x77U, 0x00U, 0x00U,
0x00U, 0x41U, 0x36U, 0x08U, 0x00U,
0x02U, 0x01U, 0x02U, 0x04U, 0x02U,
0x3CU, 0x26U, 0x23U, 0x26U, 0x3CU,
0x1EU, 0xA1U, 0xA1U, 0x61U, 0x12U,
0x3AU, 0x40U, 0x40U, 0x20U, 0x7AU,
0x38U, 0x54U, 0x54U, 0x55U, 0x59U,
0x21U, 0x55U, 0x55U, 0x79U, 0x41U,
0x21U, 0x54U, 0x54U, 0x78U, 0x41U,
0x21U, 0x55U, 0x54U, 0x78U, 0x40U,
0x20U, 0x54U, 0x55U, 0x79U, 0x40U,
0x0CU, 0x1EU, 0x52U, 0x72U, 0x12U,
0x39U, 0x55U, 0x55U, 0x55U, 0x59U,
0x39U, 0x54U, 0x54U, 0x54U, 0x59U,
0x39U, 0x55U, 0x54U, 0x54U, 0x58U,
0x00U, 0x00U, 0x45U, 0x7CU, 0x41U,
0x00U, 0x02U, 0x45U, 0x7DU, 0x42U,
0x00U, 0x01U, 0x45U, 0x7CU, 0x40U,
0xF0U, 0x29U, 0x24U, 0x29U, 0xF0U,
0xF0U, 0x28U, 0x25U, 0x28U, 0xF0U,
0x7CU, 0x54U, 0x55U, 0x45U, 0x00U,
0x20U, 0x54U, 0x54U, 0x7CU, 0x54U,
0x7CU, 0x0AU, 0x09U, 0x7FU, 0x49U,
0x32U, 0x49U, 0x49U, 0x49U, 0x32U,
0x32U, 0x48U, 0x48U, 0x48U, 0x32U,
0x32U, 0x4AU, 0x48U, 0x48U, 0x30U,
0x3AU, 0x41U, 0x41U, 0x21U, 0x7AU,
0x3AU, 0x42U, 0x40U, 0x20U, 0x78U,
0x00U, 0x9DU, 0xA0U, 0xA0U, 0x7DU,
0x39U, 0x44U, 0x44U, 0x44U, 0x39U,
0x3DU, 0x40U, 0x40U, 0x40U, 0x3DU,
0x3CU, 0x24U, 0xFFU, 0x24U, 0x24U,
0x48U, 0x7EU, 0x49U, 0x43U, 0x66U,
0x2BU, 0x2FU, 0xFCU, 0x2FU, 0x2BU,
0xFFU, 0x09U, 0x29U, 0xF6U, 0x20U,
0xC0U, 0x88U, 0x7EU, 0x09U, 0x03U,
0x20U, 0x54U, 0x54U, 0x79U, 0x41U,
0x00U, 0x00U, 0x44U, 0x7DU, 0x41U,
0x30U, 0x48U, 0x48U, 0x4AU, 0x32U,
0x38U, 0x40U, 0x40U, 0x22U, 0x7AU,
0x00U, 0x7AU, 0x0AU, 0x0AU, 0x72U,
0x7DU, 0x0DU, 0x19U, 0x31U, 0x7DU,
0x26U, 0x29U, 0x29U, 0x2FU, 0x28U,
0x26U, 0x29U, 0x29U, 0x29U, 0x26U,
0x30U, 0x48U, 0x4DU, 0x40U, 0x20U,
0x38U, 0x08U, 0x08U, 0x08U, 0x08U,
0x08U, 0x08U, 0x08U, 0x08U, 0x38U,
0x2FU, 0x10U, 0xC8U, 0xACU, 0xBAU,
0x2FU, 0x10U, 0x28U, 0x34U, 0xFAU,
0x00U, 0x00U, 0x7BU, 0x00U, 0x00U,
0x08U, 0x14U, 0x2AU, 0x14U, 0x22U,
0x22U, 0x14U, 0x2AU, 0x14U, 0x08U,
0xAAU, 0x00U, 0x55U, 0x00U, 0xAAU,
0xAAU, 0x55U, 0xAAU, 0x55U, 0xAAU,
0x00U, 0x00U, 0x00U, 0xFFU, 0x00U,
0x10U, 0x10U, 0x10U, 0xFFU, 0x00U,
0x14U, 0x14U, 0x14U, 0xFFU, 0x00U,
0x10U, 0x10U, 0xFFU, 0x00U, 0xFFU,
0x10U, 0x10U, 0xF0U, 0x10U, 0xF0U,
0x14U, 0x14U, 0x14U, 0xFCU, 0x00U,
0x14U, 0x14U, 0xF7U, 0x00U, 0xFFU,
0x00U, 0x00U, 0xFFU, 0x00U, 0xFFU,
0x14U, 0x14U, 0xF4U, 0x04U, 0xFCU,
0x14U, 0x14U, 0x17U, 0x10U, 0x1FU,
0x10U, 0x10U, 0x1FU, 0x10U, 0x1FU,
0x14U, 0x14U, 0x14U, 0x1FU, 0x00U,
0x10U, 0x10U, 0x10U, 0xF0U, 0x00U,
0x00U, 0x00U, 0x00U, 0x1FU, 0x10U,
0x10U, 0x10U, 0x10U, 0x1FU, 0x10U,
0x10U, 0x10U, 0x10U, 0xF0U, 0x10U,
0x00U, 0x00U, 0x00U, 0xFFU, 0x10U,
0x10U, 0x10U, 0x10U, 0x10U, 0x10U,
0x10U, 0x10U, 0x10U, 0xFFU, 0x10U,
0x00U, 0x00U, 0x00U, 0xFFU, 0x14U,
0x00U, 0x00U, 0xFFU, 0x00U, 0xFFU,
0x00U, 0x00U, 0x1FU, 0x10U, 0x17U,
0x00U, 0x00U, 0xFCU, 0x04U, 0xF4U,
0x14U, 0x14U, 0x17U, 0x10U, 0x17U,
0x14U, 0x14U, 0xF4U, 0x04U, 0xF4U,
0x00U, 0x00U, 0xFFU, 0x00U, 0xF7U,
0x14U, 0x14U, 0x14U, 0x14U, 0x14U,
0x14U, 0x14U, 0xF7U, 0x00U, 0xF7U,
0x14U, 0x14U, 0x14U, 0x17U, 0x14U,
0x10U, 0x10U, 0x1FU, 0x10U, 0x1FU,
0x14U, 0x14U, 0x14U, 0xF4U, 0x14U,
0x10U, 0x10U, 0xF0U, 0x10U, 0xF0U,
0x00U, 0x00U, 0x1FU, 0x10U, 0x1FU,
0x00U, 0x00U, 0x00U, 0x1FU, 0x14U,
0x00U, 0x00U, 0x00U, 0xFCU, 0x14U,
0x00U, 0x00U, 0xF0U, 0x10U, 0xF0U,
0x10U, 0x10U, 0xFFU, 0x10U, 0xFFU,
0x14U, 0x14U, 0x14U, 0xFFU, 0x14U,
0x10U, 0x10U, 0x10U, 0x1FU, 0x00U,
0x00U, 0x00U, 0x00U, 0xF0U, 0x10U,
0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU,
0xF0U, 0xF0U, 0xF0U, 0xF0U, 0xF0U,
0xFFU, 0xFFU, 0xFFU, 0x00U, 0x00U,
0x00U, 0x00U, 0x00U, 0xFFU, 0xFFU,
0x0FU, 0x0FU, 0x0FU, 0x0FU, 0x0FU,
0x38U, 0x44U, 0x44U, 0x38U, 0x44U,
0x7CU, 0x2AU, 0x2AU, 0x3EU, 0x14U,
0x7EU, 0x02U, 0x02U, 0x06U, 0x06U,
0x02U, 0x7EU, 0x02U, 0x7EU, 0x02U,
0x63U, 0x55U, 0x49U, 0x41U, 0x63U,
0x38U, 0x44U, 0x44U, 0x3CU, 0x04U,
0x40U, 0x7EU, 0x20U, 0x1EU, 0x20U,
0x06U, 0x02U, 0x7EU, 0x02U, 0x02U,
0x99U, 0xA5U, 0xE7U, 0xA5U, 0x99U,
0x1CU, 0x2AU, 0x49U, 0x2AU, 0x1CU,
0x4CU, 0x72U, 0x01U, 0x72U, 0x4CU,
0x30U, 0x4AU, 0x4DU, 0x4DU, 0x30U,
0x30U, 0x48U, 0x78U, 0x48U, 0x30U,
0xBCU, 0x62U, 0x5AU, 0x46U, 0x3DU,
0x3EU, 0x49U, 0x49U, 0x49U, 0x00U,
0x7EU, 0x01U, 0x01U, 0x01U, 0x7EU,
0x2AU, 0x2AU, 0x2AU, 0x2AU, 0x2AU,
0x44U, 0x44U, 0x5FU, 0x44U, 0x44U,
0x40U, 0x51U, 0x4AU, 0x44U, 0x40U,
0x40U, 0x44U, 0x4AU, 0x51U, 0x40U,
0x00U, 0x00U, 0xFFU, 0x01U, 0x03U,
0xE0U, 0x80U, 0xFFU, 0x00U, 0x00U,
0x08U, 0x08U, 0x6BU, 0x6BU, 0x08U,
0x36U, 0x12U, 0x36U, 0x24U, 0x36U,
0x06U, 0x0FU, 0x09U, 0x0FU, 0x06U,
0x00U, 0x00U, 0x18U, 0x18U, 0x00U,
0x00U, 0x00U, 0x10U, 0x10U, 0x00U,
0x30U, 0x40U, 0xFFU, 0x01U, 0x01U,
0x00U, 0x1FU, 0x01U, 0x01U, 0x1EU,
0x00U, 0x19U, 0x1DU, 0x17U, 0x12U,
0x00U, 0x3CU, 0x3CU, 0x3CU, 0x3CU,
0x00U, 0x00U, 0x00U, 0x00U, 0x00U};
// Arduino Compatible Macro
#define _BV(bit) (1 << (bit))
CI2COLED::CI2COLED() :
m_i2c(),
m_oledBuffer(NULL)
{
m_oledBuffer = new uint8_t[OLED_BUFFER_SIZE];
clear();
}
void CI2COLED::init()
{
m_i2c.init();
// Initialise the VG-6432TSWEG02 OLED display
// Taken from https://datasheet.lcsc.com/szlcsc/1912111437_WiseChip-VG-6432TSWAG01-IIC-sh1106_C194312.pdf
sendCommand(0xAEU); // Display off
sendCommand(0x00U); // Set lower column address
sendCommand(0x12U); // Set higher column address
sendCommand(0x00U); // Set display start line
sendCommand(0xB0U); // Set page address
sendCommand(0x81U, 0x4FU); // Contract control, 128
sendCommand(0xA1U); // Set segment remap
sendCommand(0xA6U); // Normal/reverse
sendCommand(0xA8U, 0x1FU); // Multiplex ratio, duty = 1/32
sendCommand(0xC8U); // Com scan direction
sendCommand(0xD3U, 0x00U); // Set display offset
sendCommand(0xD5U, 0x80U); // Set osc division
sendCommand(0xD9U, 0x1FU); // Set pre-charge period
sendCommand(0xDAU, 0x12U); // Set COM pins
sendCommand(0xDBU, 0x40U); // Set vcomh
sendCommand(0x8DU, 0x14U); // Set charge pump enable
sendCommand(0xAFU); // Display on
}
void CI2COLED::setMode(int state)
{
clear();
switch (MMDVM_STATE(state)) {
case STATE_IDLE:
write("Idle");
break;
case STATE_DSTAR:
write("D-Star");
break;
case STATE_DMR:
write("DMR");
break;
case STATE_YSF:
write("YSF");
break;
case STATE_P25:
write("P25");
break;
case STATE_NXDN:
write("NXDN");
break;
case STATE_FM:
write("FM");
break;
case STATE_M17:
write("M17");
break;
case STATE_POCSAG:
write("POCSAG");
break;
case STATE_AX25:
write("AX.25");
break;
default:
write("Calibrate");
break;
}
display();
}
void CI2COLED::sendCommand(uint8_t c0, uint8_t c1)
{
uint8_t buff[3U];
buff[0U] = SSD_Command_Mode;
buff[1U] = c0;
buff[2U] = c1;
// Write Data on I2C
m_i2c.write(OLED_ADDRESS, buff, 3U);
}
void CI2COLED::sendCommand(uint8_t c)
{
uint8_t buff[2U];
buff[0U] = SSD_Command_Mode;
buff[1U] = c;
// Write Data on I2C
m_i2c.write(OLED_ADDRESS, buff, 2U);
}
void CI2COLED::sendData(const uint8_t* data, uint16_t length)
{
uint8_t buff[20U];
buff[0U] = SSD_Data_Mode;
::memcpy(buff + 1U, data, length * sizeof(uint8_t));
// Write Data on I2C
m_i2c.write(OLED_ADDRESS, buff, length + 1U);
}
void CI2COLED::clear()
{
::memset(m_oledBuffer, 0x00U, OLED_BUFFER_SIZE);
}
void CI2COLED::write(const char* text)
{
size_t len = ::strlen(text);
uint16_t scale = OLED_WIDTH / (len * (CHAR_WIDTH + 1U));
if (scale == 0U) scale = 1U;
uint8_t charHeight = CHAR_HEIGHT * scale;
uint8_t charWidth = (CHAR_WIDTH + 1U) * scale;
uint8_t x = (OLED_HEIGHT - charHeight) / 2U;
uint8_t y = (OLED_WIDTH - charWidth) / 2U;
for (size_t i = 0U; i < len; i++) {
write(x, y, text[i], scale);
y += charWidth;
}
}
void CI2COLED::write(uint8_t x, uint8_t y, char c, uint8_t size)
{
for (uint8_t i = 0U; i < 6U; i++) {
uint8_t line;
if (i == 5U)
line = 0U;
else
line = FONT[(c * 5U) + i];
for (uint8_t j = 0U; j < 8U; j++) {
if (line & 0x1U) {
if (size == 1U) // default size
drawPixel(x + i, y + j);
else // big size
fillRect(x + (i * size), y + (j * size), size, size);
}
line >>= 1;
}
}
}
void CI2COLED::fillRect(uint8_t x, uint8_t y, uint8_t width, uint8_t height)
{
for (uint8_t i = x; i < (x + height - 1U); i++) {
for (uint8_t j = y; j < (y + width - 1U); j++)
drawPixel(i, j);
}
}
void CI2COLED::drawPixel(uint8_t x, uint8_t y)
{
// Get where to do the change in the buffer
uint8_t* p = m_oledBuffer + (x + (y / 8U) * OLED_WIDTH);
// x is which column
*p |= _BV((y % 8U));
}
void CI2COLED::display()
{
sendCommand(SSD1306_Set_Lower_Column_Start_Address | 0x00U); // Low col = 0
sendCommand(SSD1306_Set_Higher_Column_Start_Address | 0x00U); // High col = 0
sendCommand(SSD1306_Set_Start_Line | 0x00U); // Line #0
// loop trough all OLED buffer and send a bunch of 16 data byte in one transmission
for (uint16_t i = 0U; i < OLED_BUFFER_SIZE; i += 16U)
sendData(m_oledBuffer + i, 16U);
}
#endif
+55
View File
@@ -0,0 +1,55 @@
/*
* Copyright (C) 2020,2021 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"
#if defined(MODE_OLED)
#if !defined(I2COLED_H)
#define I2COLED_H
#include "I2C3.h"
class CI2COLED {
public:
CI2COLED();
void init();
void setMode(int state);
private:
CI2C3 m_i2c;
uint8_t* m_oledBuffer;
void write(const char* text);
void write(uint8_t x, uint8_t y, char c, uint8_t size);
void drawPixel(uint8_t x, uint8_t y);
void fillRect(uint8_t x, uint8_t y, uint8_t width, uint8_t height);
void clear();
void display();
void sendCommand(uint8_t c);
void sendCommand(uint8_t c0, uint8_t c1);
void sendData(const uint8_t* c, uint16_t length);
};
#endif
#endif
+120 -35
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2015,2016,2017,2018,2020,2021,2023,2025,2026 by Jonathan Naylor G4KLX * Copyright (C) 2015,2016,2017,2018,2020 by Jonathan Naylor G4KLX
* Copyright (C) 2015 by Jim Mclaughlin KI6ZUM * Copyright (C) 2015 by Jim Mclaughlin KI6ZUM
* Copyright (C) 2016 by Colin Durbridge G4EML * Copyright (C) 2016 by Colin Durbridge G4EML
* *
@@ -36,6 +36,14 @@ static q15_t RRC_0_2_FILTER[] = {401, 104, -340, -731, -847, -553, 112, 909, 147
const uint16_t RRC_0_2_FILTER_LEN = 42U; const uint16_t RRC_0_2_FILTER_LEN = 42U;
#endif #endif
#if defined(MODE_M17)
// Generated using rcosdesign(0.5, 8, 5, 'sqrt') in MATLAB
static q15_t RRC_0_5_FILTER[] = {-147, -88, 72, 220, 223, 46, -197, -285, -79, 334, 623, 390, -498, -1691, -2363, -1556, 1284, 5872, 11033,
15109, 16656, 15109, 11033, 5872, 1284, -1556, -2363, -1691, -498, 390, 623, 334, -79, -285, -197, 46, 223,
220, 72, -88, -147, 0};
const uint16_t RRC_0_5_FILTER_LEN = 42U;
#endif
#if defined(MODE_NXDN) #if defined(MODE_NXDN)
#if defined(USE_NXDN_BOXCAR) #if defined(USE_NXDN_BOXCAR)
// One symbol boxcar filter // One symbol boxcar filter
@@ -83,13 +91,9 @@ m_dcState(),
m_gaussianFilter(), m_gaussianFilter(),
m_gaussianState(), m_gaussianState(),
#endif #endif
#if defined(MODE_DMR) #if defined(MODE_DMR) || defined(MODE_YSF)
m_rrc02Filter1(), m_rrc02Filter(),
m_rrc02State1(), m_rrc02State(),
#endif
#if defined(MODE_YSF)
m_rrc02Filter2(),
m_rrc02State2(),
#endif #endif
#if defined(MODE_P25) #if defined(MODE_P25)
m_boxcar5Filter(), m_boxcar5Filter(),
@@ -106,6 +110,10 @@ m_nxdnState(),
m_nxdnISincState(), m_nxdnISincState(),
#endif #endif
#endif #endif
#if defined(MODE_M17)
m_rrc05Filter(),
m_rrc05State(),
#endif
m_pttInvert(false), m_pttInvert(false),
m_rxLevel(128 * 128), m_rxLevel(128 * 128),
m_cwIdTXLevel(128 * 128), m_cwIdTXLevel(128 * 128),
@@ -114,8 +122,10 @@ m_dmrTXLevel(128 * 128),
m_ysfTXLevel(128 * 128), m_ysfTXLevel(128 * 128),
m_p25TXLevel(128 * 128), m_p25TXLevel(128 * 128),
m_nxdnTXLevel(128 * 128), m_nxdnTXLevel(128 * 128),
m_m17TXLevel(128 * 128),
m_pocsagTXLevel(128 * 128), m_pocsagTXLevel(128 * 128),
m_fmTXLevel(128 * 128), m_fmTXLevel(128 * 128),
m_ax25TXLevel(128 * 128),
m_rxDCOffset(DC_OFFSET), m_rxDCOffset(DC_OFFSET),
m_txDCOffset(DC_OFFSET), m_txDCOffset(DC_OFFSET),
m_useCOSAsLockout(false), m_useCOSAsLockout(false),
@@ -128,7 +138,7 @@ m_watchdog(0U),
m_lockout(false) m_lockout(false)
{ {
#if defined(USE_DCBLOCKER) #if defined(USE_DCBLOCKER)
::memset(m_dcState, 0x00U, 4U * sizeof(q31_t)); ::memset(m_dcState, 0x00U, 4U * sizeof(q31_t));
m_dcFilter.numStages = DC_FILTER_STAGES; m_dcFilter.numStages = DC_FILTER_STAGES;
m_dcFilter.pState = m_dcState; m_dcFilter.pState = m_dcState;
m_dcFilter.pCoeffs = DC_FILTER; m_dcFilter.pCoeffs = DC_FILTER;
@@ -142,18 +152,11 @@ m_lockout(false)
m_gaussianFilter.pCoeffs = GAUSSIAN_0_5_FILTER; m_gaussianFilter.pCoeffs = GAUSSIAN_0_5_FILTER;
#endif #endif
#if defined(MODE_DMR) #if defined(MODE_DMR) || defined(MODE_YSF)
::memset(m_rrc02State1, 0x00U, 70U * sizeof(q15_t)); ::memset(m_rrc02State, 0x00U, 70U * sizeof(q15_t));
m_rrc02Filter1.numTaps = RRC_0_2_FILTER_LEN; m_rrc02Filter.numTaps = RRC_0_2_FILTER_LEN;
m_rrc02Filter1.pState = m_rrc02State1; m_rrc02Filter.pState = m_rrc02State;
m_rrc02Filter1.pCoeffs = RRC_0_2_FILTER; m_rrc02Filter.pCoeffs = RRC_0_2_FILTER;
#endif
#if defined(MODE_YSF)
::memset(m_rrc02State2, 0x00U, 70U * sizeof(q15_t));
m_rrc02Filter2.numTaps = RRC_0_2_FILTER_LEN;
m_rrc02Filter2.pState = m_rrc02State2;
m_rrc02Filter2.pCoeffs = RRC_0_2_FILTER;
#endif #endif
#if defined(MODE_P25) #if defined(MODE_P25)
@@ -183,6 +186,13 @@ m_lockout(false)
#endif #endif
#endif #endif
#if defined(MODE_M17)
::memset(m_rrc05State, 0x00U, 70U * sizeof(q15_t));
m_rrc05Filter.numTaps = RRC_0_5_FILTER_LEN;
m_rrc05Filter.pState = m_rrc05State;
m_rrc05Filter.pCoeffs = RRC_0_5_FILTER;
#endif
initInt(); initInt();
selfTest(); selfTest();
@@ -206,6 +216,9 @@ void CIO::selfTest()
#if !defined(USE_ALTERNATE_NXDN_LEDS) #if !defined(USE_ALTERNATE_NXDN_LEDS)
setNXDNInt(ledValue); setNXDNInt(ledValue);
#endif #endif
#if !defined(USE_ALTERNATE_M17_LEDS)
setM17Int(ledValue);
#endif
#if !defined(USE_ALTERNATE_POCSAG_LEDS) #if !defined(USE_ALTERNATE_POCSAG_LEDS)
setPOCSAGInt(ledValue); setPOCSAGInt(ledValue);
#endif #endif
@@ -224,6 +237,9 @@ void CIO::selfTest()
#if !defined(USE_ALTERNATE_NXDN_LEDS) #if !defined(USE_ALTERNATE_NXDN_LEDS)
setNXDNInt(false); setNXDNInt(false);
#endif #endif
#if !defined(USE_ALTERNATE_M17_LEDS)
setM17Int(false);
#endif
#if !defined(USE_ALTERNATE_POCSAG_LEDS) #if !defined(USE_ALTERNATE_POCSAG_LEDS)
setPOCSAGInt(false); setPOCSAGInt(false);
#endif #endif
@@ -246,6 +262,11 @@ void CIO::selfTest()
setNXDNInt(true); setNXDNInt(true);
#endif #endif
#if !defined(USE_ALTERNATE_M17_LEDS)
delayInt(250);
setM17Int(true);
#endif
#if !defined(USE_ALTERNATE_POCSAG_LEDS) #if !defined(USE_ALTERNATE_POCSAG_LEDS)
delayInt(250); delayInt(250);
setPOCSAGInt(true); setPOCSAGInt(true);
@@ -264,6 +285,11 @@ void CIO::selfTest()
setPOCSAGInt(false); setPOCSAGInt(false);
#endif #endif
#if !defined(USE_ALTERNATE_M17_LEDS)
delayInt(250);
setM17Int(false);
#endif
#if !defined(USE_ALTERNATE_NXDN_LEDS) #if !defined(USE_ALTERNATE_NXDN_LEDS)
delayInt(250); delayInt(250);
setNXDNInt(false); setNXDNInt(false);
@@ -301,7 +327,7 @@ void CIO::process()
if (m_started) { if (m_started) {
// Two seconds timeout // Two seconds timeout
if (m_watchdog >= 48000U) { if (m_watchdog >= 48000U) {
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_M17 || m_modemState == STATE_POCSAG) {
#if defined(MODE_DMR) #if defined(MODE_DMR)
if (m_modemState == STATE_DMR && m_tx) if (m_modemState == STATE_DMR && m_tx)
dmrTX.setStart(false); dmrTX.setStart(false);
@@ -432,7 +458,7 @@ void CIO::process()
#if defined(MODE_DMR) #if defined(MODE_DMR)
if (m_dmrEnable) { if (m_dmrEnable) {
q15_t DMRVals[RX_BLOCK_SIZE]; q15_t DMRVals[RX_BLOCK_SIZE];
::arm_fir_fast_q15(&m_rrc02Filter1, samples, DMRVals, RX_BLOCK_SIZE); ::arm_fir_fast_q15(&m_rrc02Filter, samples, DMRVals, RX_BLOCK_SIZE);
if (m_duplex) if (m_duplex)
dmrIdleRX.samples(DMRVals, RX_BLOCK_SIZE); dmrIdleRX.samples(DMRVals, RX_BLOCK_SIZE);
@@ -445,21 +471,43 @@ void CIO::process()
if (m_ysfEnable) { if (m_ysfEnable) {
q15_t YSFVals[RX_BLOCK_SIZE]; q15_t YSFVals[RX_BLOCK_SIZE];
#if defined(USE_DCBLOCKER) #if defined(USE_DCBLOCKER)
::arm_fir_fast_q15(&m_rrc02Filter2, dcSamples, YSFVals, RX_BLOCK_SIZE); ::arm_fir_fast_q15(&m_rrc02Filter, dcSamples, YSFVals, RX_BLOCK_SIZE);
#else #else
::arm_fir_fast_q15(&m_rrc02Filter2, samples, YSFVals, RX_BLOCK_SIZE); ::arm_fir_fast_q15(&m_rrc02Filter, samples, YSFVals, RX_BLOCK_SIZE);
#endif #endif
ysfRX.samples(YSFVals, rssi, RX_BLOCK_SIZE); ysfRX.samples(YSFVals, rssi, RX_BLOCK_SIZE);
} }
#endif #endif
#if defined(MODE_M17)
if (m_m17Enable) {
q15_t RRCVals[RX_BLOCK_SIZE];
#if defined(USE_DCBLOCKER)
::arm_fir_fast_q15(&m_rrc05Filter, dcSamples, RRCVals, RX_BLOCK_SIZE);
#else
::arm_fir_fast_q15(&m_rrc05Filter, samples, RRCVals, RX_BLOCK_SIZE);
#endif
m17RX.samples(RRCVals, rssi, RX_BLOCK_SIZE);
}
#endif
#if defined(MODE_FM) #if defined(MODE_FM)
if (m_fmEnable) { if (m_fmEnable) {
bool cos = getCOSInt(); bool cos = getCOSInt();
#if defined(USE_DCBLOCKER) #if defined(USE_DCBLOCKER)
fm.samples(cos, dcSamples, rssi, RX_BLOCK_SIZE); fm.samples(cos, dcSamples, RX_BLOCK_SIZE);
#else #else
fm.samples(cos, samples, rssi, RX_BLOCK_SIZE); fm.samples(cos, samples, RX_BLOCK_SIZE);
#endif
}
#endif
#if defined(MODE_FM) && defined(MODE_AX25)
if (m_ax25Enable) {
#if defined(USE_DCBLOCKER)
ax25RX.samples(dcSamples, RX_BLOCK_SIZE);
#else
ax25RX.samples(samples, RX_BLOCK_SIZE);
#endif #endif
} }
#endif #endif
@@ -483,7 +531,7 @@ void CIO::process()
else if (m_modemState == STATE_DMR) { else if (m_modemState == STATE_DMR) {
if (m_dmrEnable) { if (m_dmrEnable) {
q15_t DMRVals[RX_BLOCK_SIZE]; q15_t DMRVals[RX_BLOCK_SIZE];
::arm_fir_fast_q15(&m_rrc02Filter1, samples, DMRVals, RX_BLOCK_SIZE); ::arm_fir_fast_q15(&m_rrc02Filter, samples, DMRVals, RX_BLOCK_SIZE);
if (m_duplex) { if (m_duplex) {
// If the transmitter isn't on, use the DMR idle RX to detect the wakeup CSBKs // If the transmitter isn't on, use the DMR idle RX to detect the wakeup CSBKs
@@ -503,9 +551,9 @@ void CIO::process()
if (m_ysfEnable) { if (m_ysfEnable) {
q15_t YSFVals[RX_BLOCK_SIZE]; q15_t YSFVals[RX_BLOCK_SIZE];
#if defined(USE_DCBLOCKER) #if defined(USE_DCBLOCKER)
::arm_fir_fast_q15(&m_rrc02Filter2, dcSamples, YSFVals, RX_BLOCK_SIZE); ::arm_fir_fast_q15(&m_rrc02Filter, dcSamples, YSFVals, RX_BLOCK_SIZE);
#else #else
::arm_fir_fast_q15(&m_rrc02Filter2, samples, YSFVals, RX_BLOCK_SIZE); ::arm_fir_fast_q15(&m_rrc02Filter, samples, YSFVals, RX_BLOCK_SIZE);
#endif #endif
ysfRX.samples(YSFVals, rssi, RX_BLOCK_SIZE); ysfRX.samples(YSFVals, rssi, RX_BLOCK_SIZE);
} }
@@ -550,13 +598,37 @@ void CIO::process()
} }
#endif #endif
#if defined(MODE_M17)
else if (m_modemState == STATE_M17) {
if (m_m17Enable) {
q15_t M17Vals[RX_BLOCK_SIZE];
#if defined(USE_DCBLOCKER)
::arm_fir_fast_q15(&m_rrc05Filter, dcSamples, M17Vals, RX_BLOCK_SIZE);
#else
::arm_fir_fast_q15(&m_rrc05Filter, samples, M17Vals, RX_BLOCK_SIZE);
#endif
m17RX.samples(M17Vals, rssi, RX_BLOCK_SIZE);
}
}
#endif
#if defined(MODE_FM) #if defined(MODE_FM)
else if (m_modemState == STATE_FM) { else if (m_modemState == STATE_FM) {
bool cos = getCOSInt(); bool cos = getCOSInt();
#if defined(USE_DCBLOCKER) #if defined(USE_DCBLOCKER)
fm.samples(cos, dcSamples, rssi, RX_BLOCK_SIZE); fm.samples(cos, dcSamples, RX_BLOCK_SIZE);
#if defined(MODE_AX25)
if (m_ax25Enable)
ax25RX.samples(dcSamples, RX_BLOCK_SIZE);
#endif
#else #else
fm.samples(cos, samples, rssi, RX_BLOCK_SIZE); fm.samples(cos, samples, RX_BLOCK_SIZE);
#if defined(MODE_AX25)
if (m_ax25Enable)
ax25RX.samples(samples, RX_BLOCK_SIZE);
#endif
#endif #endif
} }
#endif #endif
@@ -608,12 +680,18 @@ void CIO::write(MMDVM_STATE mode, q15_t* samples, uint16_t length, const uint8_t
case STATE_NXDN: case STATE_NXDN:
txLevel = m_nxdnTXLevel; txLevel = m_nxdnTXLevel;
break; break;
case STATE_M17:
txLevel = m_m17TXLevel;
break;
case STATE_POCSAG: case STATE_POCSAG:
txLevel = m_pocsagTXLevel; txLevel = m_pocsagTXLevel;
break; break;
case STATE_FM: case STATE_FM:
txLevel = m_fmTXLevel; txLevel = m_fmTXLevel;
break; break;
case STATE_AX25:
txLevel = m_ax25TXLevel;
break;
default: default:
txLevel = m_cwIdTXLevel; txLevel = m_cwIdTXLevel;
break; break;
@@ -665,9 +743,9 @@ void CIO::setMode(MMDVM_STATE state)
case STATE_YSF: setYSFInt(false); break; case STATE_YSF: setYSFInt(false); break;
case STATE_P25: setP25Int(false); break; case STATE_P25: setP25Int(false); break;
case STATE_NXDN: setNXDNInt(false); break; case STATE_NXDN: setNXDNInt(false); break;
case STATE_M17: setM17Int(false); break;
case STATE_POCSAG: setPOCSAGInt(false); break; case STATE_POCSAG: setPOCSAGInt(false); break;
case STATE_FM: setFMInt(false); break; case STATE_FM: setFMInt(false); break;
default: break;
} }
switch (state) { switch (state) {
@@ -676,16 +754,20 @@ void CIO::setMode(MMDVM_STATE state)
case STATE_YSF: setYSFInt(true); break; case STATE_YSF: setYSFInt(true); break;
case STATE_P25: setP25Int(true); break; case STATE_P25: setP25Int(true); break;
case STATE_NXDN: setNXDNInt(true); break; case STATE_NXDN: setNXDNInt(true); break;
case STATE_M17: setM17Int(true); break;
case STATE_POCSAG: setPOCSAGInt(true); break; case STATE_POCSAG: setPOCSAGInt(true); break;
case STATE_FM: setFMInt(true); break; case STATE_FM: setFMInt(true); break;
default: break;
} }
#endif #endif
#if defined(MODE_OLED)
oled.setMode(state);
#endif
m_modemState = state; 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, 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 m17TXLevel, uint8_t pocsagTXLevel, uint8_t fmTXLevel, uint8_t ax25TXLevel, int16_t txDCOffset, int16_t rxDCOffset, bool useCOSAsLockout)
{ {
m_pttInvert = pttInvert; m_pttInvert = pttInvert;
@@ -696,8 +778,10 @@ void CIO::setParameters(bool rxInvert, bool txInvert, bool pttInvert, uint8_t rx
m_ysfTXLevel = q15_t(ysfTXLevel * 128); m_ysfTXLevel = q15_t(ysfTXLevel * 128);
m_p25TXLevel = q15_t(p25TXLevel * 128); m_p25TXLevel = q15_t(p25TXLevel * 128);
m_nxdnTXLevel = q15_t(nxdnTXLevel * 128); m_nxdnTXLevel = q15_t(nxdnTXLevel * 128);
m_m17TXLevel = q15_t(m17TXLevel * 128);
m_pocsagTXLevel = q15_t(pocsagTXLevel * 128); m_pocsagTXLevel = q15_t(pocsagTXLevel * 128);
m_fmTXLevel = q15_t(fmTXLevel * 128); m_fmTXLevel = q15_t(fmTXLevel * 128);
m_ax25TXLevel = q15_t(ax25TXLevel * 128);
m_rxDCOffset = DC_OFFSET + rxDCOffset; m_rxDCOffset = DC_OFFSET + rxDCOffset;
m_txDCOffset = DC_OFFSET + txDCOffset; m_txDCOffset = DC_OFFSET + txDCOffset;
@@ -713,6 +797,7 @@ void CIO::setParameters(bool rxInvert, bool txInvert, bool pttInvert, uint8_t rx
m_ysfTXLevel = -m_ysfTXLevel; m_ysfTXLevel = -m_ysfTXLevel;
m_p25TXLevel = -m_p25TXLevel; m_p25TXLevel = -m_p25TXLevel;
m_nxdnTXLevel = -m_nxdnTXLevel; m_nxdnTXLevel = -m_nxdnTXLevel;
m_m17TXLevel = -m_m17TXLevel;
m_pocsagTXLevel = -m_pocsagTXLevel; m_pocsagTXLevel = -m_pocsagTXLevel;
} }
} }
+13 -11
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2015,2016,2017,2018,2020,2021,2025 by Jonathan Naylor G4KLX * Copyright (C) 2015,2016,2017,2018,2020 by Jonathan Naylor G4KLX
* *
* 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
@@ -46,7 +46,7 @@ public:
void interrupt(); void interrupt();
void 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, int16_t txDCOffset, int16_t rxDCOffset, bool useCOSAsLockout); void 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 m17TXLevel, uint8_t pocsagTXLevel, uint8_t fmTXLevel, uint8_t ax25TXLevel, int16_t txDCOffset, int16_t rxDCOffset, bool useCOSAsLockout);
void getOverflow(bool& adcOverflow, bool& dacOverflow); void getOverflow(bool& adcOverflow, bool& dacOverflow);
@@ -81,14 +81,9 @@ private:
q15_t m_gaussianState[40U]; // NoTaps + BlockSize - 1, 12 + 20 - 1 plus some spare q15_t m_gaussianState[40U]; // NoTaps + BlockSize - 1, 12 + 20 - 1 plus some spare
#endif #endif
#if defined(MODE_DMR) #if defined(MODE_DMR) || defined(MODE_YSF)
arm_fir_instance_q15 m_rrc02Filter1; arm_fir_instance_q15 m_rrc02Filter;
q15_t m_rrc02State1[70U]; // NoTaps + BlockSize - 1, 42 + 20 - 1 plus some spare q15_t m_rrc02State[70U]; // NoTaps + BlockSize - 1, 42 + 20 - 1 plus some spare
#endif
#if defined(MODE_YSF)
arm_fir_instance_q15 m_rrc02Filter2;
q15_t m_rrc02State2[70U]; // NoTaps + BlockSize - 1, 42 + 20 - 1 plus some spare
#endif #endif
#if defined(MODE_P25) #if defined(MODE_P25)
@@ -108,6 +103,11 @@ private:
#endif #endif
#endif #endif
#if defined(MODE_M17)
arm_fir_instance_q15 m_rrc05Filter;
q15_t m_rrc05State[70U]; // NoTaps + BlockSize - 1, 42 + 20 - 1 plus some spare
#endif
bool m_pttInvert; bool m_pttInvert;
q15_t m_rxLevel; q15_t m_rxLevel;
q15_t m_cwIdTXLevel; q15_t m_cwIdTXLevel;
@@ -116,8 +116,10 @@ private:
q15_t m_ysfTXLevel; q15_t m_ysfTXLevel;
q15_t m_p25TXLevel; q15_t m_p25TXLevel;
q15_t m_nxdnTXLevel; q15_t m_nxdnTXLevel;
q15_t m_m17TXLevel;
q15_t m_pocsagTXLevel; q15_t m_pocsagTXLevel;
q15_t m_fmTXLevel; q15_t m_fmTXLevel;
q15_t m_ax25TXLevel;
uint16_t m_rxDCOffset; uint16_t m_rxDCOffset;
uint16_t m_txDCOffset; uint16_t m_txDCOffset;
@@ -152,10 +154,10 @@ private:
void setP25Int(bool on); void setP25Int(bool on);
void setNXDNInt(bool on); void setNXDNInt(bool on);
void setPOCSAGInt(bool on); void setPOCSAGInt(bool on);
void setM17Int(bool on);
void setFMInt(bool on); void setFMInt(bool on);
void delayInt(unsigned int dly); void delayInt(unsigned int dly);
}; };
#endif #endif
+15 -2
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2015,2016,2017,2018,2020,2025 by Jonathan Naylor G4KLX * Copyright (C) 2015,2016,2017,2018,2020 by Jonathan Naylor G4KLX
* Copyright (C) 2015 by Jim Mclaughlin KI6ZUM * Copyright (C) 2015 by Jim Mclaughlin KI6ZUM
* Copyright (C) 2016 by Colin Durbridge G4EML * Copyright (C) 2016 by Colin Durbridge G4EML
* *
@@ -107,10 +107,13 @@ void CIO::initInt()
#if !defined(USE_ALTERNATE_NXDN_LEDS) #if !defined(USE_ALTERNATE_NXDN_LEDS)
pinMode(PIN_NXDN, OUTPUT); pinMode(PIN_NXDN, OUTPUT);
#endif #endif
#if !defined(USE_ALTERNATE_M17_LEDS)
pinMode(PIN_M17, OUTPUT);
#endif
#if !defined(USE_ALTERNATE_POCSAG_LEDS) #if !defined(USE_ALTERNATE_POCSAG_LEDS)
pinMode(PIN_POCSAG, OUTPUT); pinMode(PIN_POCSAG, OUTPUT);
#endif #endif
#if !defined(USE_ALTERNATE_FM_LEDS) #if !defined(USE_ALTERNATE_POCSAG_LEDS)
pinMode(PIN_FM, OUTPUT); pinMode(PIN_FM, OUTPUT);
#endif #endif
#endif #endif
@@ -253,6 +256,16 @@ void CIO::setNXDNInt(bool on)
#endif #endif
} }
void CIO::setM17Int(bool on)
{
#if defined(USE_ALTERNATE_M17_LEDS)
digitalWrite(PIN_DSTAR, on ? HIGH : LOW);
digitalWrite(PIN_P25, on ? HIGH : LOW);
#else
digitalWrite(PIN_M17, on ? HIGH : LOW);
#endif
}
void CIO::setPOCSAGInt(bool on) void CIO::setPOCSAGInt(bool on)
{ {
#if defined(USE_ALTERNATE_POCSAG_LEDS) #if defined(USE_ALTERNATE_POCSAG_LEDS)
+43 -8
View File
@@ -1,7 +1,7 @@
/* /*
* Copyright (C) 2016 by Jim McLaughlin KI6ZUM * Copyright (C) 2016 by Jim McLaughlin KI6ZUM
* Copyright (C) 2016,2017,2018 by Andy Uribe CA6JAU * Copyright (C) 2016,2017,2018 by Andy Uribe CA6JAU
* Copyright (C) 2017,2018,2020,2023,2025 by Jonathan Naylor G4KLX * Copyright (C) 2017,2018,2020,2021 by Jonathan Naylor G4KLX
* Copyright (C) 2019,2020 by BG5HHP * Copyright (C) 2019,2020 by BG5HHP
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@@ -106,6 +106,14 @@ void CIO::initInt()
GPIO_Init(PORT_NXDN, &GPIO_InitStruct); GPIO_Init(PORT_NXDN, &GPIO_InitStruct);
#endif #endif
#if !defined(USE_ALTERNATE_M17_LEDS)
// M17 pin
RCC_AHB1PeriphClockCmd(RCC_Per_M17, ENABLE);
GPIO_InitStruct.GPIO_Pin = PIN_M17;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
GPIO_Init(PORT_M17, &GPIO_InitStruct);
#endif
#if !defined(USE_ALTERNATE_POCSAG_LEDS) #if !defined(USE_ALTERNATE_POCSAG_LEDS)
// POCSAG pin // POCSAG pin
RCC_AHB1PeriphClockCmd(RCC_Per_POCSAG, ENABLE); RCC_AHB1PeriphClockCmd(RCC_Per_POCSAG, ENABLE);
@@ -157,6 +165,14 @@ void CIO::initInt()
GPIO_Init(PORT_MNXDN, &GPIO_InitStruct); GPIO_Init(PORT_MNXDN, &GPIO_InitStruct);
#endif #endif
#if !defined(USE_ALTERNATE_M17_LEDS)
// M17 mode pin
RCC_AHB1PeriphClockCmd(RCC_Per_MM17, ENABLE);
GPIO_InitStruct.GPIO_Pin = PIN_MM17;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
GPIO_Init(PORT_MM17, &GPIO_InitStruct);
#endif
#if !defined(USE_ALTERNATE_POCSAG_LEDS) #if !defined(USE_ALTERNATE_POCSAG_LEDS)
// POCSAG mode pin // POCSAG mode pin
RCC_AHB1PeriphClockCmd(RCC_Per_MPOCSAG, ENABLE); RCC_AHB1PeriphClockCmd(RCC_Per_MPOCSAG, ENABLE);
@@ -174,6 +190,10 @@ void CIO::initInt()
#endif #endif
#endif #endif
#if defined(MODE_OLED)
oled.init();
#endif
} }
void CIO::startInt() void CIO::startInt()
@@ -349,16 +369,10 @@ void CIO::interrupt()
#endif #endif
} }
// Trigger next ADC1 // trigger next ADC1
ADC_ClearFlag(ADC1, ADC_FLAG_EOC); ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
ADC_SoftwareStartConv(ADC1); ADC_SoftwareStartConv(ADC1);
#if defined(SEND_RSSI_DATA)
// Trigger next ADC2
ADC_ClearFlag(ADC2, ADC_FLAG_EOC);
ADC_SoftwareStartConv(ADC2);
#endif
m_rxBuffer.put(sample); m_rxBuffer.put(sample);
m_rssiBuffer.put(rawRSSI); m_rssiBuffer.put(rawRSSI);
@@ -446,6 +460,27 @@ void CIO::setNXDNInt(bool on)
#endif #endif
} }
void CIO::setM17Int(bool on)
{
#if defined(MODE_LEDS)
#if defined(USE_ALTERNATE_M17_LEDS)
GPIO_WriteBit(PORT_DSTAR, PIN_DSTAR, on ? Bit_SET : Bit_RESET);
GPIO_WriteBit(PORT_P25, PIN_P25, on ? Bit_SET : Bit_RESET);
#else
GPIO_WriteBit(PORT_M17, PIN_M17, on ? Bit_SET : Bit_RESET);
#endif
#endif
#if defined(MODE_PINS) && defined(STM32F4_NUCLEO_MORPHO_HEADER) && (defined(STM32F4_NUCLEO) || defined(STM32F722_RPT_HAT))
#if defined(USE_ALTERNATE_M17_LEDS)
GPIO_WriteBit(PORT_MDSTAR, PIN_MDSTAR, on ? Bit_SET : Bit_RESET);
GPIO_WriteBit(PORT_MP25, PIN_MP25, on ? Bit_SET : Bit_RESET);
#else
GPIO_WriteBit(PORT_MM17, PIN_MM17, on ? Bit_SET : Bit_RESET);
#endif
#endif
}
void CIO::setPOCSAGInt(bool on) void CIO::setPOCSAGInt(bool on)
{ {
#if defined(MODE_LEDS) #if defined(MODE_LEDS)
+507
View File
@@ -0,0 +1,507 @@
/*
* Copyright (C) 2016 by Jim McLaughlin KI6ZUM
* Copyright (C) 2016, 2017 by Andy Uribe CA6JAU
* Copyright (C) 2017,2018,2020,2021 by Jonathan Naylor G4KLX
* Copyright (C) 2017 by Wojciech Krutnik N0CALL
*
* 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 "IO.h"
#if defined(STM32F1)
#if defined(STM32F1_POG)
/*
Pin definitions for STM32F1 POG Board:
PTT PB12 output
COSLED PB5 output
LED PB4 output
COS PB13 input/PD
DSTAR PB7 output
DMR PB6 output
YSF PB8 output
P25 PB9 output
NXDN PB10 output
POCSAG PB11 output
RX PB0 analog input (ADC1_8)
RSSI PB1 analog input (ADC2_9)
TX PA4 analog output (DAC_OUT1)
EXT_CLK PA15 input (AF: TIM2_CH1_ETR)
USART1_TXD PA9 output (AF)
USART1_RXD PA10 input (AF)
*/
#define PIN_PTT 12
#define PORT_PTT GPIOB
#define BB_PTT *((bitband_t)BITBAND_PERIPH(&PORT_PTT->ODR, PIN_PTT))
#define PIN_COSLED 5
#define PORT_COSLED GPIOB
#define BB_COSLED *((bitband_t)BITBAND_PERIPH(&PORT_COSLED->ODR, PIN_COSLED))
#define PIN_LED 4
#define PORT_LED GPIOB
#define BB_LED *((bitband_t)BITBAND_PERIPH(&PORT_LED->ODR, PIN_LED))
#define PIN_COS 13
#define PORT_COS GPIOB
#define BB_COS *((bitband_t)BITBAND_PERIPH(&PORT_COS->IDR, PIN_COS))
#define PIN_DSTAR 7
#define PORT_DSTAR GPIOB
#define BB_DSTAR *((bitband_t)BITBAND_PERIPH(&PORT_DSTAR->ODR, PIN_DSTAR))
#define PIN_DMR 6
#define PORT_DMR GPIOB
#define BB_DMR *((bitband_t)BITBAND_PERIPH(&PORT_DMR->ODR, PIN_DMR))
#define PIN_YSF 8
#define PORT_YSF GPIOB
#define BB_YSF *((bitband_t)BITBAND_PERIPH(&PORT_YSF->ODR, PIN_YSF))
#define PIN_P25 9
#define PORT_P25 GPIOB
#define BB_P25 *((bitband_t)BITBAND_PERIPH(&PORT_P25->ODR, PIN_P25))
#define PIN_NXDN 10
#define PORT_NXDN GPIOB
#define BB_NXDN *((bitband_t)BITBAND_PERIPH(&PORT_NXDN->ODR, PIN_NXDN))
#define PIN_POCSAG 11
#define PORT_POCSAG GPIOB
#define BB_POCSAG *((bitband_t)BITBAND_PERIPH(&PORT_POCSAG->ODR, PIN_POCSAG))
#define PIN_RX 0
#define PIN_RX_ADC_CH 8
#define PORT_RX GPIOB
#define PIN_RSSI 1
#define PIN_RSSI_ADC_CH 9
#define PORT_RSSI GPIOB
#define PIN_TX 4
#define PIN_TX_DAC_CH 1
#define PORT_TX GPIOA
#define PIN_EXT_CLK 15
#define SRC_EXT_CLK 15
#define PORT_EXT_CLK GPIOA
#define PIN_USART1_TXD 9
#define PORT_USART1_TXD GPIOA
#define PIN_USART1_RXD 10
#define PORT_USART1_RXD GPIOA
#else // defined(STM32F1_POG)
#error "Either STM32F1_POG, or sth need to be defined"
#endif // defined(STM32F1_POG)
const uint16_t DC_OFFSET = 2048U;
// Sampling frequency
#define SAMP_FREQ 24000
extern "C" {
void TIM2_IRQHandler() {
if ((TIM2->SR & TIM_SR_UIF) == TIM_SR_UIF) {
TIM2->SR = ~TIM_SR_UIF; // clear UI flag
io.interrupt();
}
}
}
void delay(uint32_t cnt)
{
while(cnt--)
asm("nop");
}
// source: http://www.freddiechopin.info/
void GPIOConfigPin(GPIO_TypeDef *port_ptr, uint32_t pin, uint32_t mode_cnf_value)
{
volatile uint32_t *cr_ptr;
uint32_t cr_value;
cr_ptr = &port_ptr->CRL; // configuration of pins [0,7] is in CRL
if (pin >= 8) // is pin in [8; 15]?
{ // configuration of pins [8,15] is in CRH
cr_ptr++; // advance to next struct element CRL -> CRH
pin -= 8; // crop the pin number
}
cr_value = *cr_ptr; // localize the CRL / CRH value
cr_value &= ~(0xF << (pin * 4)); // clear the MODE and CNF fields (now that pin is an analog input)
cr_value |= (mode_cnf_value << (pin * 4)); // save new MODE and CNF value for desired pin
*cr_ptr = cr_value; // save localized value to CRL / CRL
}
#if defined(STM32F1_POG)
void FancyLEDEffect()
{
bitband_t foo[] = {&BB_LED, &BB_COSLED, &BB_PTT, &BB_DMR, &BB_DSTAR, &BB_YSF, &BB_P25};
for(int i=0; i<7; i++){
*foo[i] = 0x01;
}
GPIOConfigPin(PORT_USART1_TXD, PIN_USART1_TXD, GPIO_CRL_MODE0_1);
*((bitband_t)BITBAND_PERIPH(&PORT_USART1_TXD->ODR, PIN_USART1_TXD)) = 0x00;
delay(SystemCoreClock/1000*100);
for(int i=0; i<7; i++){
*foo[i] = 0x00;
}
*((bitband_t)BITBAND_PERIPH(&PORT_USART1_TXD->ODR, PIN_USART1_TXD)) = 0x01;
delay(SystemCoreClock/1000*20);
*((bitband_t)BITBAND_PERIPH(&PORT_USART1_TXD->ODR, PIN_USART1_TXD)) = 0x00;
delay(SystemCoreClock/1000*10);
*((bitband_t)BITBAND_PERIPH(&PORT_USART1_TXD->ODR, PIN_USART1_TXD)) = 0x01;
*foo[0] = 0x01;
for(int i=1; i<7; i++){
delay(SystemCoreClock/1000*10);
*foo[i-1] = 0x00;
*foo[i] = 0x01;
}
for(int i=5; i>=0; i--){
delay(SystemCoreClock/1000*10);
*foo[i+1] = 0x00;
*foo[i] = 0x01;
}
delay(SystemCoreClock/1000*10);
*foo[5+1-6] = 0x00;
*((bitband_t)BITBAND_PERIPH(&PORT_USART1_TXD->ODR, PIN_USART1_TXD)) = 0x00;
delay(SystemCoreClock/1000*10);
*((bitband_t)BITBAND_PERIPH(&PORT_USART1_TXD->ODR, PIN_USART1_TXD)) = 0x01;
GPIOConfigPin(PORT_USART1_TXD, PIN_USART1_TXD, GPIO_CRL_MODE0_1|GPIO_CRL_CNF0_1);
delay(SystemCoreClock/1000*50);
}
#endif
static inline void GPIOInit()
{
RCC->APB2ENR |= RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN
| RCC_APB2ENR_IOPCEN | RCC_APB2ENR_IOPDEN
| RCC_APB2ENR_AFIOEN; // enable all GPIOs
// set all ports to input with pull-down
GPIOA->CRL = 0x88888888;
GPIOA->CRH = 0x88888888;
GPIOA->ODR = 0;
GPIOB->CRL = 0x88888888;
GPIOB->CRH = 0x88888888;
GPIOB->ODR = 0;
GPIOC->CRL = 0x88888888;
GPIOC->CRH = 0x88888888;
GPIOC->ODR = 0;
GPIOD->CRL = 0x88888888;
GPIOD->CRH = 0x88888888;
GPIOD->ODR = 0;
// configure ports
GPIOConfigPin(PORT_PTT, PIN_PTT, GPIO_CRL_MODE0_1);
GPIOConfigPin(PORT_COSLED, PIN_COSLED, GPIO_CRL_MODE0_1);
GPIOConfigPin(PORT_LED, PIN_LED, GPIO_CRL_MODE0_1);
GPIOConfigPin(PORT_COS, PIN_COS, GPIO_CRL_CNF0_1);
#if defined(MODE_LEDS)
GPIOConfigPin(PORT_DSTAR, PIN_DSTAR, GPIO_CRL_MODE0_1);
GPIOConfigPin(PORT_DMR, PIN_DMR, GPIO_CRL_MODE0_1);
GPIOConfigPin(PORT_YSF, PIN_YSF, GPIO_CRL_MODE0_1);
GPIOConfigPin(PORT_P25, PIN_P25, GPIO_CRL_MODE0_1);
#if !defined(USE_ALTERNATE_NXDN_LEDS)
GPIOConfigPin(PORT_NXDN, PIN_NXDN, GPIO_CRL_MODE0_1);
#endif
#if !defined(USE_ALTERNATE_M17_LEDS)
GPIOConfigPin(PORT_M17, PIN_M17, GPIO_CRL_MODE0_1);
#endif
#if !defined(USE_ALTERNATE_POCSAG_LEDS)
GPIOConfigPin(PORT_POCSAG, PIN_POCSAG, GPIO_CRL_MODE0_1);
#endif
#endif
GPIOConfigPin(PORT_RX, PIN_RX, 0);
#if defined(SEND_RSSI_DATA)
GPIOConfigPin(PORT_RSSI, PIN_RSSI, 0);
#endif
GPIOConfigPin(PORT_TX, PIN_TX, 0);
#if defined(EXTERNAL_OSC)
#if defined(STM32F1_POG)
GPIOConfigPin(PORT_EXT_CLK, PIN_EXT_CLK, GPIO_CRL_CNF0_0);
AFIO->MAPR = (AFIO->MAPR & ~AFIO_MAPR_TIM2_REMAP) | AFIO_MAPR_TIM2_REMAP_0;
#endif
#endif
GPIOConfigPin(PORT_USART1_TXD, PIN_USART1_TXD, GPIO_CRL_MODE0_1|GPIO_CRL_CNF0_1);
GPIOConfigPin(PORT_USART1_RXD, PIN_USART1_RXD, GPIO_CRL_CNF0_0);
AFIO->MAPR = (AFIO->MAPR & ~AFIO_MAPR_SWJ_CFG) | AFIO_MAPR_SWJ_CFG_1;
}
static inline void ADCInit()
{
RCC->CFGR = (RCC->CFGR & ~RCC_CFGR_ADCPRE_Msk)
| RCC_CFGR_ADCPRE_DIV6; // ADC clock divided by 6 (72MHz/6 = 12MHz)
RCC->APB2ENR |= RCC_APB2ENR_ADC1EN;
#if defined(SEND_RSSI_DATA)
RCC->APB2ENR |= RCC_APB2ENR_ADC2EN;
#endif
// Init ADCs in dual mode (RSSI)
#if defined(SEND_RSSI_DATA)
ADC1->CR1 = ADC_CR1_DUALMOD_1|ADC_CR1_DUALMOD_2; // Regular simultaneous mode
#endif
// Set sampling time to 7.5 cycles
if (PIN_RX_ADC_CH < 10) {
ADC1->SMPR2 = ADC_SMPR2_SMP0_0 << (3*PIN_RX_ADC_CH);
} else {
ADC1->SMPR1 = ADC_SMPR1_SMP10_0 << (3*PIN_RX_ADC_CH);
}
#if defined(SEND_RSSI_DATA)
if (PIN_RSSI_ADC_CH < 10) {
ADC2->SMPR2 = ADC_SMPR2_SMP0_0 << (3*PIN_RSSI_ADC_CH);
} else {
ADC2->SMPR1 = ADC_SMPR1_SMP10_0 << (3*PIN_RSSI_ADC_CH);
}
#endif
// Set conversion channel (single conversion)
ADC1->SQR3 = PIN_RX_ADC_CH;
#if defined(SEND_RSSI_DATA)
ADC2->SQR3 = PIN_RSSI_ADC_CH;
#endif
// Enable ADC
ADC1->CR2 |= ADC_CR2_ADON;
#if defined(SEND_RSSI_DATA)
// Enable ADC2
ADC2->CR2 |= ADC_CR2_ADON;
#endif
// Start calibration
delay(6*2);
ADC1->CR2 |= ADC_CR2_CAL;
while((ADC1->CR2 & ADC_CR2_CAL) == ADC_CR2_CAL)
;
#if defined(SEND_RSSI_DATA)
ADC2->CR2 |= ADC_CR2_CAL;
while((ADC2->CR2 & ADC_CR2_CAL) == ADC_CR2_CAL)
;
#endif
// Trigger first conversion
ADC1->CR2 |= ADC_CR2_ADON;
#if defined(SEND_RSSI_DATA)
ADC2->CR2 |= ADC_CR2_ADON;
#endif
}
static inline void DACInit()
{
RCC->APB1ENR |= RCC_APB1ENR_DACEN;
DAC->CR = DAC_CR_EN1;
}
static inline void TimerInit()
{
RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;
#if defined(EXTERNAL_OSC)
// Enable external clock, prescaler /4
TIM2->SMCR = TIM_SMCR_ECE | TIM_SMCR_ETPS_1;
#endif
// TIM2 output frequency
TIM2->PSC = 0;
#if defined(EXTERNAL_OSC)
// TimerCount = ExternalOsc
// /4 (external clock prescaler)
// /SAMP_FREQ
TIM2->ARR = (uint16_t) ((EXTERNAL_OSC/(4*SAMP_FREQ)) - 1);
#else
TIM2->ARR = (uint16_t) ((SystemCoreClock/(SAMP_FREQ)) - 1);
#endif
// Enable TIse 1%-tolerance comM2 interrupt
TIM2->DIER = TIM_DIER_UIE;
NVIC_EnableIRQ(TIM2_IRQn);
// Enable TIM2
TIM2->CR1 |= TIM_CR1_CEN;
}
void CIO::initInt()
{
GPIOInit();
ADCInit();
DACInit();
#if defined(STM32F1_POG)
FancyLEDEffect();
#endif
#if defined(MODE_OLED)
oled.init();
#endif
}
void CIO::startInt()
{
TimerInit();
BB_COSLED = 0;
BB_LED = 1;
}
void CIO::interrupt()
{
TSample sample = {DC_OFFSET, MARK_NONE};
#if defined(SEND_RSSI_DATA)
uint16_t rawRSSI = 0U;
#endif
bitband_t eoc = (bitband_t)BITBAND_PERIPH(&ADC1->SR, ADC_SR_EOS_Pos);
bitband_t adon = (bitband_t)BITBAND_PERIPH(&ADC1->CR2, ADC_CR2_ADON_Pos);
#if defined(SEND_RSSI_DATA)
bitband_t rssi_adon = (bitband_t)BITBAND_PERIPH(&ADC2->CR2, ADC_CR2_ADON_Pos);
#endif
if (*eoc) {
// trigger next conversion
*adon = 1;
#if defined(SEND_RSSI_DATA)
*rssi_adon = 1;
#endif
m_txBuffer.get(sample);
DAC->DHR12R1 = sample.sample; // Send the value to the DAC
// Read value from ADC1 and ADC2
sample.sample = ADC1->DR; // read conversion result; EOC is cleared by this read
m_rxBuffer.put(sample);
#if defined(SEND_RSSI_DATA)
rawRSSI = ADC2->DR;
m_rssiBuffer.put(rawRSSI);
#endif
m_watchdog++;
}
}
bool CIO::getCOSInt()
{
return BB_COS;
}
void CIO::setLEDInt(bool on)
{
BB_LED = !!on;
}
void CIO::setPTTInt(bool on)
{
BB_PTT = !!on;
}
void CIO::setCOSInt(bool on)
{
BB_COSLED = !!on;
}
#if defined(MODE_LEDS)
void CIO::setDStarInt(bool on)
{
BB_DSTAR = !!on;
}
void CIO::setDMRInt(bool on)
{
BB_DMR = !!on;
}
void CIO::setYSFInt(bool on)
{
BB_YSF = !!on;
}
void CIO::setP25Int(bool on)
{
BB_P25 = !!on;
}
void CIO::setNXDNInt(bool on)
{
#if defined(USE_ALTERNATE_NXDN_LEDS)
BB_YSF = !!on;
BB_P25 = !!on;
#else
BB_NXDN = !!on;
#endif
}
void CIO::setM17Int(bool on)
{
#if defined(USE_ALTERNATE_M17_LEDS)
BB_DSTAR = !!on;
BB_P25 = !!on;
#else
BB_M17 = !!on;
#endif
}
void CIO::setPOCSAGInt(bool on)
{
#if defined(USE_ALTERNATE_POCSAG_LEDS)
BB_DSTAR = !!on;
BB_DMR = !!on;
#else
BB_POCSAG = !!on;
#endif
}
void CIO::setFMInt(bool on)
{
#if defined(USE_ALTERNATE_FM_LEDS)
BB_DSTAR = !!on;
BB_YSF = !!on;
#endif
}
#endif
void CIO::delayInt(unsigned int dly)
{
delay(dly);
}
uint8_t CIO::getCPU() const
{
return 2U;
}
void CIO::getUDID(uint8_t* buffer)
{
#if defined(STM32F105xC)
::memcpy(buffer, (void *)0x1FFFF7E8, 12U);
#endif
}
#endif
+14 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2016,2017,2018,2020,2025 by Jonathan Naylor G4KLX * Copyright (C) 2016,2017,2018,2020 by Jonathan Naylor G4KLX
* *
* 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
@@ -75,6 +75,9 @@ void CIO::initInt()
#if !defined(USE_ALTERNATE_NXDN_LEDS) #if !defined(USE_ALTERNATE_NXDN_LEDS)
pinMode(PIN_NXDN, OUTPUT); pinMode(PIN_NXDN, OUTPUT);
#endif #endif
#if !defined(USE_ALTERNATE_M17_LEDS)
pinMode(PIN_M17, OUTPUT);
#endif
#if !defined(USE_ALTERNATE_POCSAG_LEDS) #if !defined(USE_ALTERNATE_POCSAG_LEDS)
pinMode(PIN_POCSAG, OUTPUT); pinMode(PIN_POCSAG, OUTPUT);
#endif #endif
@@ -237,6 +240,16 @@ void CIO::setNXDNInt(bool on)
#endif #endif
} }
void CIO::setM17Int(bool on)
{
#if defined(USE_ALTERNATE_M17_LEDS)
digitalWrite(PIN_DSTAR, on ? HIGH : LOW);
digitalWrite(PIN_P25, on ? HIGH : LOW);
#else
digitalWrite(PIN_M17, on ? HIGH : LOW);
#endif
}
void CIO::setPOCSAGInt(bool on) void CIO::setPOCSAGInt(bool on)
{ {
#if defined(USE_ALTERNATE_POCSAG_LEDS) #if defined(USE_ALTERNATE_POCSAG_LEDS)
+68
View File
@@ -0,0 +1,68 @@
/*
* Copyright (C) 2016,2017,2018,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(M17DEFINES_H)
#define M17DEFINES_H
const unsigned int M17_RADIO_SYMBOL_LENGTH = 5U; // At 24 kHz sample rate
const unsigned int M17_FRAME_LENGTH_BITS = 384U;
const unsigned int M17_FRAME_LENGTH_BYTES = M17_FRAME_LENGTH_BITS / 8U;
const unsigned int M17_FRAME_LENGTH_SYMBOLS = M17_FRAME_LENGTH_BITS / 2U;
const unsigned int M17_FRAME_LENGTH_SAMPLES = M17_FRAME_LENGTH_SYMBOLS * M17_RADIO_SYMBOL_LENGTH;
const unsigned int M17_SYNC_LENGTH_BITS = 16U;
const unsigned int M17_SYNC_LENGTH_SYMBOLS = M17_SYNC_LENGTH_BITS / 2U;
const unsigned int M17_SYNC_LENGTH_SAMPLES = M17_SYNC_LENGTH_SYMBOLS * M17_RADIO_SYMBOL_LENGTH;
const uint8_t M17_LINK_SETUP_SYNC_BYTES[] = {0x55U, 0xF7U};
const uint8_t M17_STREAM_SYNC_BYTES[] = {0xFFU, 0x5DU};
const uint8_t M17_PACKET_SYNC_BYTES[] = {0x75U, 0xFFU};
const uint8_t M17_SYNC_BYTES_LENGTH = 2U;
const uint16_t M17_LINK_SETUP_SYNC_BITS = 0x55F7U;
const uint16_t M17_STREAM_SYNC_BITS = 0xFF5DU;
const uint16_t M17_PACKET_SYNC_BITS = 0x75FFU;
// 5 5 F 7
// 01 01 01 01 11 11 01 11
// +3 +3 +3 +3 -3 -3 +3 -3
const int8_t M17_LINK_SETUP_SYNC_SYMBOLS_VALUES[] = {+3, +3, +3, +3, -3, -3, +3, -3};
const uint8_t M17_LINK_SETUP_SYNC_SYMBOLS = 0xF2U;
// F F 5 D
// 11 11 11 11 01 01 11 01
// -3 -3 -3 -3 +3 +3 -3 +3
const int8_t M17_STREAM_SYNC_SYMBOLS_VALUES[] = {-3, -3, -3, -3, +3, +3, -3, +3};
const uint8_t M17_STREAM_SYNC_SYMBOLS = 0x0DU;
// 7 5 F F
// 01 11 01 01 11 11 11 11
// +3 -3 +3 +3 -3 -3 -3 -3
const int8_t M17_PACKET_SYNC_SYMBOLS_VALUES[] = {+3, -3, +3, +3, -3, -3, -3, -3};
const uint8_t M17_PACKET_SYNC_SYMBOLS = 0xB0U;
#endif
+498
View File
@@ -0,0 +1,498 @@
/*
* Copyright (C) 2009-2017,2020,2021 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"
#if defined(MODE_M17)
#include "Globals.h"
#include "M17RX.h"
#include "Utils.h"
const q15_t SCALING_FACTOR = 18750; // Q15(0.55)
const uint8_t MAX_SYNC_BIT_START_ERRS = 0U;
const uint8_t MAX_SYNC_BIT_RUN_ERRS = 2U;
const uint8_t MAX_SYNC_SYMBOL_START_ERRS = 0U;
const uint8_t MAX_SYNC_SYMBOL_RUN_ERRS = 1U;
const uint8_t BIT_MASK_TABLE[] = {0x80U, 0x40U, 0x20U, 0x10U, 0x08U, 0x04U, 0x02U, 0x01U};
#define WRITE_BIT1(p,i,b) p[(i)>>3] = (b) ? (p[(i)>>3] | BIT_MASK_TABLE[(i)&7]) : (p[(i)>>3] & ~BIT_MASK_TABLE[(i)&7])
const uint8_t NOAVEPTR = 99U;
const uint16_t NOENDPTR = 9999U;
const unsigned int MAX_SYNC_FRAMES = 3U + 1U;
CM17RX::CM17RX() :
m_state(M17RXS_NONE),
m_bitBuffer(),
m_buffer(),
m_bitPtr(0U),
m_dataPtr(0U),
m_startPtr(NOENDPTR),
m_endPtr(NOENDPTR),
m_syncPtr(NOENDPTR),
m_minSyncPtr(NOENDPTR),
m_maxSyncPtr(NOENDPTR),
m_maxCorr(0),
m_lostCount(0U),
m_countdown(0U),
m_nextState(M17RXS_NONE),
m_centre(),
m_centreVal(0),
m_threshold(),
m_thresholdVal(0),
m_averagePtr(NOAVEPTR),
m_rssiAccum(0U),
m_rssiCount(0U)
{
}
void CM17RX::reset()
{
m_state = M17RXS_NONE;
m_dataPtr = 0U;
m_bitPtr = 0U;
m_maxCorr = 0;
m_averagePtr = NOAVEPTR;
m_startPtr = NOENDPTR;
m_endPtr = NOENDPTR;
m_syncPtr = NOENDPTR;
m_minSyncPtr = NOENDPTR;
m_maxSyncPtr = NOENDPTR;
m_centreVal = 0;
m_thresholdVal = 0;
m_lostCount = 0U;
m_countdown = 0U;
m_nextState = M17RXS_NONE;
m_rssiAccum = 0U;
m_rssiCount = 0U;
}
void CM17RX::samples(const q15_t* samples, uint16_t* rssi, uint8_t length)
{
for (uint8_t i = 0U; i < length; i++) {
q15_t sample = samples[i];
m_rssiAccum += rssi[i];
m_rssiCount++;
m_bitBuffer[m_bitPtr] <<= 1;
if (sample < 0)
m_bitBuffer[m_bitPtr] |= 0x01U;
m_buffer[m_dataPtr] = sample;
switch (m_state) {
case M17RXS_LINK_SETUP:
case M17RXS_STREAM:
case M17RXS_PACKET:
processData(sample);
break;
default:
processNone(sample);
break;
}
m_dataPtr++;
if (m_dataPtr >= M17_FRAME_LENGTH_SAMPLES)
m_dataPtr = 0U;
m_bitPtr++;
if (m_bitPtr >= M17_RADIO_SYMBOL_LENGTH)
m_bitPtr = 0U;
}
}
void CM17RX::processNone(q15_t sample)
{
bool ret1 = correlateSync(M17_LINK_SETUP_SYNC_SYMBOLS, M17_LINK_SETUP_SYNC_SYMBOLS_VALUES, M17_LINK_SETUP_SYNC_BYTES, MAX_SYNC_SYMBOL_START_ERRS, MAX_SYNC_BIT_START_ERRS);
bool ret2 = correlateSync(M17_STREAM_SYNC_SYMBOLS, M17_STREAM_SYNC_SYMBOLS_VALUES, M17_STREAM_SYNC_BYTES, MAX_SYNC_SYMBOL_START_ERRS, MAX_SYNC_BIT_START_ERRS);
// bool ret3 = correlateSync(M17_PACKET_SYNC_SYMBOLS, M17_PACKET_SYNC_SYMBOLS_VALUES, M17_PACKET_SYNC_BYTES, MAX_SYNC_SYMBOL_START_ERRS, MAX_SYNC_BIT_START_ERRS);
if (ret1 || ret2 /* || ret3 */ ) {
// On the first sync, start the countdown to the state change
if (m_countdown == 0U) {
m_rssiAccum = 0U;
m_rssiCount = 0U;
io.setDecode(true);
io.setADCDetection(true);
m_averagePtr = NOAVEPTR;
m_countdown = 5U;
if (ret1) m_nextState = M17RXS_LINK_SETUP;
if (ret2) m_nextState = M17RXS_STREAM;
// if (ret3) m_nextState = M17RXS_PACKET;
}
}
if (m_countdown > 0U)
m_countdown--;
if (m_countdown == 1U) {
m_minSyncPtr = m_syncPtr + M17_FRAME_LENGTH_SAMPLES - 1U;
if (m_minSyncPtr >= M17_FRAME_LENGTH_SAMPLES)
m_minSyncPtr -= M17_FRAME_LENGTH_SAMPLES;
m_maxSyncPtr = m_syncPtr + 1U;
if (m_maxSyncPtr >= M17_FRAME_LENGTH_SAMPLES)
m_maxSyncPtr -= M17_FRAME_LENGTH_SAMPLES;
m_state = m_nextState;
m_countdown = 0U;
m_nextState = M17RXS_NONE;
}
}
void CM17RX::processData(q15_t sample)
{
if (m_minSyncPtr < m_maxSyncPtr) {
if (m_dataPtr >= m_minSyncPtr && m_dataPtr <= m_maxSyncPtr) {
bool ret1 = correlateSync(M17_LINK_SETUP_SYNC_SYMBOLS, M17_LINK_SETUP_SYNC_SYMBOLS_VALUES, M17_LINK_SETUP_SYNC_BYTES, MAX_SYNC_SYMBOL_RUN_ERRS, MAX_SYNC_BIT_RUN_ERRS);
bool ret2 = correlateSync(M17_STREAM_SYNC_SYMBOLS, M17_STREAM_SYNC_SYMBOLS_VALUES, M17_STREAM_SYNC_BYTES, MAX_SYNC_SYMBOL_RUN_ERRS, MAX_SYNC_BIT_RUN_ERRS);
// bool ret3 = correlateSync(M17_PACKET_SYNC_SYMBOLS, M17_PACKET_SYNC_SYMBOLS_VALUES, M17_PACKET_SYNC_BYTES, MAX_SYNC_SYMBOL_RUN_ERRS, MAX_SYNC_BIT_RUN_ERRS);
if (ret1) m_state = M17RXS_LINK_SETUP;
if (ret2) m_state = M17RXS_STREAM;
// if (ret3) m_state = M17RXS_PACKET;
}
} else {
if (m_dataPtr >= m_minSyncPtr || m_dataPtr <= m_maxSyncPtr) {
bool ret1 = correlateSync(M17_LINK_SETUP_SYNC_SYMBOLS, M17_LINK_SETUP_SYNC_SYMBOLS_VALUES, M17_LINK_SETUP_SYNC_BYTES, MAX_SYNC_SYMBOL_RUN_ERRS, MAX_SYNC_BIT_RUN_ERRS);
bool ret2 = correlateSync(M17_STREAM_SYNC_SYMBOLS, M17_STREAM_SYNC_SYMBOLS_VALUES, M17_STREAM_SYNC_BYTES, MAX_SYNC_SYMBOL_RUN_ERRS, MAX_SYNC_BIT_RUN_ERRS);
// bool ret3 = correlateSync(M17_PACKET_SYNC_SYMBOLS, M17_PACKET_SYNC_SYMBOLS_VALUES, M17_PACKET_SYNC_BYTES, MAX_SYNC_SYMBOL_RUN_ERRS, MAX_SYNC_BIT_RUN_ERRS);
if (ret1) m_state = M17RXS_LINK_SETUP;
if (ret2) m_state = M17RXS_STREAM;
// if (ret3) m_state = M17RXS_PACKET;
}
}
if (m_dataPtr == m_endPtr) {
// Only update the centre and threshold if they are from a good sync
if (m_lostCount == MAX_SYNC_FRAMES) {
m_minSyncPtr = m_syncPtr + M17_FRAME_LENGTH_SAMPLES - 1U;
if (m_minSyncPtr >= M17_FRAME_LENGTH_SAMPLES)
m_minSyncPtr -= M17_FRAME_LENGTH_SAMPLES;
m_maxSyncPtr = m_syncPtr + 1U;
if (m_maxSyncPtr >= M17_FRAME_LENGTH_SAMPLES)
m_maxSyncPtr -= M17_FRAME_LENGTH_SAMPLES;
}
calculateLevels(m_startPtr, M17_FRAME_LENGTH_SYMBOLS);
switch (m_state) {
case M17RXS_LINK_SETUP:
DEBUG4("M17RX: link setup sync found pos/centre/threshold", m_syncPtr, m_centreVal, m_thresholdVal);
break;
case M17RXS_STREAM:
DEBUG4("M17RX: stream sync found pos/centre/threshold", m_syncPtr, m_centreVal, m_thresholdVal);
break;
case M17RXS_PACKET:
DEBUG4("M17RX: packet sync found pos/centre/threshold", m_syncPtr, m_centreVal, m_thresholdVal);
break;
}
uint8_t frame[M17_FRAME_LENGTH_BYTES + 3U];
samplesToBits(m_startPtr, M17_FRAME_LENGTH_SYMBOLS, frame, 8U, m_centreVal, m_thresholdVal);
// We've not seen a stream sync for too long, signal RXLOST and change to RX_NONE
m_lostCount--;
if (m_lostCount == 0U) {
DEBUG1("M17RX: sync timed out, lost lock");
io.setDecode(false);
io.setADCDetection(false);
serial.writeM17Lost();
m_state = M17RXS_NONE;
m_endPtr = NOENDPTR;
m_averagePtr = NOAVEPTR;
m_countdown = 0U;
m_nextState = M17RXS_NONE;
m_maxCorr = 0;
} else {
frame[0U] = 0x00U;
frame[0U] |= m_lostCount == (MAX_SYNC_FRAMES - 1U) ? 0x01U : 0x00U;
switch (m_state) {
case M17RXS_LINK_SETUP:
writeRSSILinkSetup(frame);
break;
case M17RXS_STREAM:
writeRSSIStream(frame);
break;
case M17RXS_PACKET:
writeRSSIPacket(frame);
break;
}
m_maxCorr = 0;
m_nextState = M17RXS_NONE;
}
}
}
bool CM17RX::correlateSync(uint8_t syncSymbols, const int8_t* syncSymbolValues, const uint8_t* syncBytes, uint8_t maxSymbolErrs, uint8_t maxBitErrs)
{
if (countBits8(m_bitBuffer[m_bitPtr] ^ syncSymbols) <= maxSymbolErrs) {
uint16_t ptr = m_dataPtr + M17_FRAME_LENGTH_SAMPLES - M17_SYNC_LENGTH_SAMPLES + M17_RADIO_SYMBOL_LENGTH;
if (ptr >= M17_FRAME_LENGTH_SAMPLES)
ptr -= M17_FRAME_LENGTH_SAMPLES;
q31_t corr = 0;
q15_t min = 16000;
q15_t max = -16000;
for (uint8_t i = 0U; i < M17_SYNC_LENGTH_SYMBOLS; i++) {
q15_t val = m_buffer[ptr];
if (val > max)
max = val;
if (val < min)
min = val;
switch (syncSymbolValues[i]) {
case +3:
corr -= (val + val + val);
break;
case +1:
corr -= val;
break;
case -1:
corr += val;
break;
default: // -3
corr += (val + val + val);
break;
}
ptr += M17_RADIO_SYMBOL_LENGTH;
if (ptr >= M17_FRAME_LENGTH_SAMPLES)
ptr -= M17_FRAME_LENGTH_SAMPLES;
}
if (corr > m_maxCorr) {
if (m_averagePtr == NOAVEPTR) {
m_centreVal = (max + min) >> 1;
q31_t v1 = (max - m_centreVal) * SCALING_FACTOR;
m_thresholdVal = q15_t(v1 >> 15);
}
uint16_t startPtr = m_dataPtr + M17_FRAME_LENGTH_SAMPLES - M17_SYNC_LENGTH_SAMPLES + M17_RADIO_SYMBOL_LENGTH;
if (startPtr >= M17_FRAME_LENGTH_SAMPLES)
startPtr -= M17_FRAME_LENGTH_SAMPLES;
uint8_t sync[M17_SYNC_BYTES_LENGTH];
samplesToBits(startPtr, M17_SYNC_LENGTH_SYMBOLS, sync, 0U, m_centreVal, m_thresholdVal);
uint8_t errs = 0U;
for (uint8_t i = 0U; i < M17_SYNC_BYTES_LENGTH; i++)
errs += countBits8(sync[i] ^ syncBytes[i]);
if (errs <= maxBitErrs) {
m_maxCorr = corr;
m_lostCount = MAX_SYNC_FRAMES;
m_syncPtr = m_dataPtr;
m_startPtr = startPtr;
m_endPtr = m_dataPtr + M17_FRAME_LENGTH_SAMPLES - M17_SYNC_LENGTH_SAMPLES - 1U;
if (m_endPtr >= M17_FRAME_LENGTH_SAMPLES)
m_endPtr -= M17_FRAME_LENGTH_SAMPLES;
return true;
}
}
}
return false;
}
void CM17RX::calculateLevels(uint16_t start, uint16_t count)
{
q15_t maxPos = -16000;
q15_t minPos = 16000;
q15_t maxNeg = 16000;
q15_t minNeg = -16000;
for (uint16_t i = 0U; i < count; i++) {
q15_t sample = m_buffer[start];
if (sample > 0) {
if (sample > maxPos)
maxPos = sample;
if (sample < minPos)
minPos = sample;
} else {
if (sample < maxNeg)
maxNeg = sample;
if (sample > minNeg)
minNeg = sample;
}
start += M17_RADIO_SYMBOL_LENGTH;
if (start >= M17_FRAME_LENGTH_SAMPLES)
start -= M17_FRAME_LENGTH_SAMPLES;
}
q15_t posThresh = (maxPos + minPos) >> 1;
q15_t negThresh = (maxNeg + minNeg) >> 1;
q15_t centre = (posThresh + negThresh) >> 1;
q15_t threshold = posThresh - centre;
DEBUG5("M17RX: pos/neg/centre/threshold", posThresh, negThresh, centre, threshold);
if (m_averagePtr == NOAVEPTR) {
for (uint8_t i = 0U; i < 16U; i++) {
m_centre[i] = centre;
m_threshold[i] = threshold;
}
m_averagePtr = 0U;
} else {
m_centre[m_averagePtr] = centre;
m_threshold[m_averagePtr] = threshold;
m_averagePtr++;
if (m_averagePtr >= 16U)
m_averagePtr = 0U;
}
m_centreVal = 0;
m_thresholdVal = 0;
for (uint8_t i = 0U; i < 16U; i++) {
m_centreVal += m_centre[i];
m_thresholdVal += m_threshold[i];
}
m_centreVal >>= 4;
m_thresholdVal >>= 4;
}
void CM17RX::samplesToBits(uint16_t start, uint16_t count, uint8_t* buffer, uint16_t offset, q15_t centre, q15_t threshold)
{
for (uint16_t i = 0U; i < count; i++) {
q15_t sample = m_buffer[start] - centre;
if (sample < -threshold) {
WRITE_BIT1(buffer, offset, false);
offset++;
WRITE_BIT1(buffer, offset, true);
offset++;
} else if (sample < 0) {
WRITE_BIT1(buffer, offset, false);
offset++;
WRITE_BIT1(buffer, offset, false);
offset++;
} else if (sample < threshold) {
WRITE_BIT1(buffer, offset, true);
offset++;
WRITE_BIT1(buffer, offset, false);
offset++;
} else {
WRITE_BIT1(buffer, offset, true);
offset++;
WRITE_BIT1(buffer, offset, true);
offset++;
}
start += M17_RADIO_SYMBOL_LENGTH;
if (start >= M17_FRAME_LENGTH_SAMPLES)
start -= M17_FRAME_LENGTH_SAMPLES;
}
}
void CM17RX::writeRSSILinkSetup(uint8_t* data)
{
#if defined(SEND_RSSI_DATA)
if (m_rssiCount > 0U) {
uint16_t rssi = m_rssiAccum / m_rssiCount;
data[121U] = (rssi >> 8) & 0xFFU;
data[122U] = (rssi >> 0) & 0xFFU;
serial.writeM17LinkSetup(data, M17_FRAME_LENGTH_BYTES + 3U);
} else {
serial.writeM17LinkSetup(data, M17_FRAME_LENGTH_BYTES + 1U);
}
#else
serial.writeM17LinkSetup(data, M17_FRAME_LENGTH_BYTES + 1U);
#endif
m_rssiAccum = 0U;
m_rssiCount = 0U;
}
void CM17RX::writeRSSIStream(uint8_t* data)
{
#if defined(SEND_RSSI_DATA)
if (m_rssiCount > 0U) {
uint16_t rssi = m_rssiAccum / m_rssiCount;
data[121U] = (rssi >> 8) & 0xFFU;
data[122U] = (rssi >> 0) & 0xFFU;
serial.writeM17Stream(data, M17_FRAME_LENGTH_BYTES + 3U);
} else {
serial.writeM17Stream(data, M17_FRAME_LENGTH_BYTES + 1U);
}
#else
serial.writeM17Stream(data, M17_FRAME_LENGTH_BYTES + 1U);
#endif
m_rssiAccum = 0U;
m_rssiCount = 0U;
}
void CM17RX::writeRSSIPacket(uint8_t* data)
{
#if defined(SEND_RSSI_DATA)
if (m_rssiCount > 0U) {
uint16_t rssi = m_rssiAccum / m_rssiCount;
data[121U] = (rssi >> 8) & 0xFFU;
data[122U] = (rssi >> 0) & 0xFFU;
serial.writeM17Packet(data, M17_FRAME_LENGTH_BYTES + 3U);
} else {
serial.writeM17Packet(data, M17_FRAME_LENGTH_BYTES + 1U);
}
#else
serial.writeM17Packet(data, M17_FRAME_LENGTH_BYTES + 1U);
#endif
m_rssiAccum = 0U;
m_rssiCount = 0U;
}
#endif
+79
View File
@@ -0,0 +1,79 @@
/*
* Copyright (C) 2015,2016,2017,2020,2021 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"
#if defined(MODE_M17)
#if !defined(M17RX_H)
#define M17RX_H
#include "M17Defines.h"
enum M17RX_STATE {
M17RXS_NONE,
M17RXS_LINK_SETUP,
M17RXS_STREAM,
M17RXS_PACKET
};
class CM17RX {
public:
CM17RX();
void samples(const q15_t* samples, uint16_t* rssi, uint8_t length);
void reset();
private:
M17RX_STATE m_state;
uint8_t m_bitBuffer[M17_RADIO_SYMBOL_LENGTH];
q15_t m_buffer[M17_FRAME_LENGTH_SAMPLES];
uint16_t m_bitPtr;
uint16_t m_dataPtr;
uint16_t m_startPtr;
uint16_t m_endPtr;
uint16_t m_syncPtr;
uint16_t m_minSyncPtr;
uint16_t m_maxSyncPtr;
q31_t m_maxCorr;
uint16_t m_lostCount;
uint8_t m_countdown;
M17RX_STATE m_nextState;
q15_t m_centre[16U];
q15_t m_centreVal;
q15_t m_threshold[16U];
q15_t m_thresholdVal;
uint8_t m_averagePtr;
uint32_t m_rssiAccum;
uint16_t m_rssiCount;
void processNone(q15_t sample);
void processData(q15_t sample);
bool correlateSync(uint8_t syncSymbols, const int8_t* syncSymbolValues, const uint8_t* syncBytes, uint8_t maxSymbolErrs, uint8_t maxBitErrs);
void calculateLevels(uint16_t start, uint16_t count);
void samplesToBits(uint16_t start, uint16_t count, uint8_t* buffer, uint16_t offset, q15_t centre, q15_t threshold);
void writeRSSILinkSetup(uint8_t* data);
void writeRSSIStream(uint8_t* data);
void writeRSSIPacket(uint8_t* data);
};
#endif
#endif
+190
View File
@@ -0,0 +1,190 @@
/*
* Copyright (C) 2009-2018,2020 by Jonathan Naylor G4KLX
* Copyright (C) 2017 by Andy Uribe CA6JAU
*
* 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"
#if defined(MODE_M17)
#include "Globals.h"
#include "M17TX.h"
#include "M17Defines.h"
// Generated using rcosdesign(0.5, 8, 5, 'sqrt') in MATLAB
static q15_t RRC_0_5_FILTER[] = {0, 0, 0, 0, -290, -174, 142, 432, 438, 90, -387, -561, -155, 658, 1225, 767,
-980, -3326, -4648, -3062, 2527, 11552, 21705, 29724, 32767, 29724, 21705,
11552, 2527, -3062, -4648, -3326, -980, 767, 1225, 658, -155, -561, -387, 90,
438, 432, 142, -174, -290}; // numTaps = 45, L = 5
const uint16_t RRC_0_5_FILTER_PHASE_LEN = 9U; // phaseLength = numTaps/L
const q15_t M17_LEVELA = 1683;
const q15_t M17_LEVELB = 561;
const q15_t M17_LEVELC = -561;
const q15_t M17_LEVELD = -1683;
const uint8_t M17_START_SYNC = 0x77U;
const uint8_t M17_END_SYNC = 0xFFU;
const uint8_t M17_HANG = 0x00U;
CM17TX::CM17TX() :
m_buffer(TX_BUFFER_LEN),
m_modFilter(),
m_modState(),
m_poBuffer(),
m_poLen(0U),
m_poPtr(0U),
m_txDelay(240U), // 200ms
m_txHang(4800U), // 4s
m_txCount(0U)
{
::memset(m_modState, 0x00U, 16U * sizeof(q15_t));
m_modFilter.L = M17_RADIO_SYMBOL_LENGTH;
m_modFilter.phaseLength = RRC_0_5_FILTER_PHASE_LEN;
m_modFilter.pCoeffs = RRC_0_5_FILTER;
m_modFilter.pState = m_modState;
}
void CM17TX::process()
{
// If we have M17 data to transmit, do so.
if (m_poLen == 0U && m_buffer.getData() > 0U) {
if (!m_tx) {
for (uint16_t i = 0U; i < m_txDelay; i++)
m_poBuffer[m_poLen++] = M17_START_SYNC;
} else {
for (uint8_t i = 0U; i < M17_FRAME_LENGTH_BYTES; i++) {
uint8_t c = 0U;
m_buffer.get(c);
m_poBuffer[m_poLen++] = c;
}
}
m_poPtr = 0U;
}
if (m_poLen > 0U) {
// Transmit M17 data.
uint16_t space = io.getSpace();
while (space > (4U * M17_RADIO_SYMBOL_LENGTH)) {
uint8_t c = m_poBuffer[m_poPtr++];
writeByte(c);
// Reduce space and reset the hang timer.
space -= 4U * M17_RADIO_SYMBOL_LENGTH;
if (m_duplex)
m_txCount = m_txHang;
if (m_poPtr >= m_poLen) {
m_poPtr = 0U;
m_poLen = 0U;
return;
}
}
} else if (m_txCount > 0U) {
// Transmit silence until the hang timer has expired.
uint16_t space = io.getSpace();
while (space > (4U * M17_RADIO_SYMBOL_LENGTH)) {
writeSilence();
space -= 4U * M17_RADIO_SYMBOL_LENGTH;
m_txCount--;
if (m_txCount == 0U)
return;
}
}
}
uint8_t CM17TX::writeData(const uint8_t* data, uint8_t length)
{
if (length != (M17_FRAME_LENGTH_BYTES + 1U))
return 4U;
uint16_t space = m_buffer.getSpace();
if (space < M17_FRAME_LENGTH_BYTES)
return 5U;
for (uint8_t i = 0U; i < M17_FRAME_LENGTH_BYTES; i++)
m_buffer.put(data[i + 1U]);
return 0U;
}
void CM17TX::writeByte(uint8_t c)
{
q15_t inBuffer[4U];
q15_t outBuffer[M17_RADIO_SYMBOL_LENGTH * 4U];
const uint8_t MASK = 0xC0U;
for (uint8_t i = 0U; i < 4U; i++, c <<= 2) {
switch (c & MASK) {
case 0xC0U:
inBuffer[i] = M17_LEVELA;
break;
case 0x80U:
inBuffer[i] = M17_LEVELB;
break;
case 0x00U:
inBuffer[i] = M17_LEVELC;
break;
default:
inBuffer[i] = M17_LEVELD;
break;
}
}
::arm_fir_interpolate_q15(&m_modFilter, inBuffer, outBuffer, 4U);
io.write(STATE_M17, outBuffer, M17_RADIO_SYMBOL_LENGTH * 4U);
}
void CM17TX::writeSilence()
{
q15_t inBuffer[4U] = {0x00U, 0x00U, 0x00U, 0x00U};
q15_t outBuffer[M17_RADIO_SYMBOL_LENGTH * 4U];
::arm_fir_interpolate_q15(&m_modFilter, inBuffer, outBuffer, 4U);
io.write(STATE_M17, outBuffer, M17_RADIO_SYMBOL_LENGTH * 4U);
}
void CM17TX::setTXDelay(uint8_t delay)
{
m_txDelay = 600U + uint16_t(delay) * 12U; // 500ms + tx delay
if (m_txDelay > 1200U)
m_txDelay = 1200U;
}
uint8_t CM17TX::getSpace() const
{
return m_buffer.getSpace() / M17_FRAME_LENGTH_BYTES;
}
void CM17TX::setParams(uint8_t txHang)
{
m_txHang = txHang * 1200U;
}
#endif
+60
View File
@@ -0,0 +1,60 @@
/*
* Copyright (C) 2015,2016,2017,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"
#if defined(MODE_M17)
#if !defined(M17TX_H)
#define M17TX_H
#include "RingBuffer.h"
class CM17TX {
public:
CM17TX();
uint8_t writeData(const uint8_t* data, uint8_t length);
void process();
void setTXDelay(uint8_t delay);
uint8_t getSpace() const;
void setParams(uint8_t txHang);
private:
CRingBuffer<uint8_t> m_buffer;
arm_fir_interpolate_instance_q15 m_modFilter;
q15_t m_modState[16U]; // blockSize + phaseLength - 1, 4 + 9 - 1 plus some spare
uint8_t m_poBuffer[1200U];
uint16_t m_poLen;
uint16_t m_poPtr;
uint16_t m_txDelay;
uint32_t m_txHang;
uint32_t m_txCount;
void writeByte(uint8_t c);
void writeSilence();
};
#endif
#endif
+28 -3
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2015,2016,2017,2018,2020,2021,2025 by Jonathan Naylor G4KLX * Copyright (C) 2015,2016,2017,2018,2020,2021 by Jonathan Naylor G4KLX
* Copyright (C) 2016 by Mathis Schmieder DB9MAT * Copyright (C) 2016 by Mathis Schmieder DB9MAT
* Copyright (C) 2016 by Colin Durbridge G4EML * Copyright (C) 2016 by Colin Durbridge G4EML
* *
@@ -18,7 +18,7 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
#if defined(STM32F4XX) || defined(STM32F7XX) #if defined(STM32F4XX) || defined(STM32F7XX) || defined(STM32F105xC)
#include "Config.h" #include "Config.h"
#include "Globals.h" #include "Globals.h"
@@ -31,14 +31,20 @@ bool m_dmrEnable = true;
bool m_ysfEnable = true; bool m_ysfEnable = true;
bool m_p25Enable = true; bool m_p25Enable = true;
bool m_nxdnEnable = true; bool m_nxdnEnable = true;
bool m_m17Enable = true;
bool m_pocsagEnable = true; bool m_pocsagEnable = true;
bool m_fmEnable = true; bool m_fmEnable = true;
bool m_ax25Enable = true;
bool m_duplex = true; bool m_duplex = true;
bool m_tx = false; bool m_tx = false;
bool m_dcd = false; bool m_dcd = false;
#if defined(MODE_OLED)
CI2COLED oled;
#endif
#if defined(MODE_DSTAR) #if defined(MODE_DSTAR)
CDStarRX dstarRX; CDStarRX dstarRX;
CDStarTX dstarTX; CDStarTX dstarTX;
@@ -77,6 +83,11 @@ CNXDNTX nxdnTX;
CCalNXDN calNXDN; CCalNXDN calNXDN;
#endif #endif
#if defined(MODE_M17)
CM17RX m17RX;
CM17TX m17TX;
#endif
#if defined(MODE_POCSAG) #if defined(MODE_POCSAG)
CPOCSAGTX pocsagTX; CPOCSAGTX pocsagTX;
CCalPOCSAG calPOCSAG; CCalPOCSAG calPOCSAG;
@@ -87,6 +98,11 @@ CFM fm;
CCalFM calFM; CCalFM calFM;
#endif #endif
#if defined(MODE_AX25)
CAX25RX ax25RX;
CAX25TX ax25TX;
#endif
CCalRSSI calRSSI; CCalRSSI calRSSI;
CCWIdTX cwIdTX; CCWIdTX cwIdTX;
@@ -135,11 +151,21 @@ void loop()
nxdnTX.process(); nxdnTX.process();
#endif #endif
#if defined(MODE_M17)
if (m_m17Enable && m_modemState == STATE_M17)
m17TX.process();
#endif
#if defined(MODE_POCSAG) #if defined(MODE_POCSAG)
if (m_pocsagEnable && (m_modemState == STATE_POCSAG || pocsagTX.busy())) if (m_pocsagEnable && (m_modemState == STATE_POCSAG || pocsagTX.busy()))
pocsagTX.process(); pocsagTX.process();
#endif #endif
#if defined(MODE_AX25)
if (m_ax25Enable && (m_modemState == STATE_IDLE || m_modemState == STATE_FM))
ax25TX.process();
#endif
#if defined(MODE_FM) #if defined(MODE_FM)
if (m_fmEnable && m_modemState == STATE_FM) if (m_fmEnable && m_modemState == STATE_FM)
fm.process(); fm.process();
@@ -188,4 +214,3 @@ int main()
} }
#endif #endif
+27 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2015,2016,2017,2018,2020,2021,2025 by Jonathan Naylor G4KLX * Copyright (C) 2015,2016,2017,2018,2020,2021 by Jonathan Naylor G4KLX
* Copyright (C) 2016 by Colin Durbridge G4EML * Copyright (C) 2016 by Colin Durbridge G4EML
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@@ -28,14 +28,20 @@ bool m_dmrEnable = true;
bool m_ysfEnable = true; bool m_ysfEnable = true;
bool m_p25Enable = true; bool m_p25Enable = true;
bool m_nxdnEnable = true; bool m_nxdnEnable = true;
bool m_m17Enable = true;
bool m_pocsagEnable = true; bool m_pocsagEnable = true;
bool m_fmEnable = true; bool m_fmEnable = true;
bool m_ax25Enable = true;
bool m_duplex = true; bool m_duplex = true;
bool m_tx = false; bool m_tx = false;
bool m_dcd = false; bool m_dcd = false;
#if defined(MODE_OLED)
CI2COLED oled;
#endif
#if defined(MODE_DSTAR) #if defined(MODE_DSTAR)
CDStarRX dstarRX; CDStarRX dstarRX;
CDStarTX dstarTX; CDStarTX dstarTX;
@@ -74,6 +80,11 @@ CNXDNTX nxdnTX;
CCalNXDN calNXDN; CCalNXDN calNXDN;
#endif #endif
#if defined(MODE_M17)
CM17RX m17RX;
CM17TX m17TX;
#endif
#if defined(MODE_POCSAG) #if defined(MODE_POCSAG)
CPOCSAGTX pocsagTX; CPOCSAGTX pocsagTX;
CCalPOCSAG calPOCSAG; CCalPOCSAG calPOCSAG;
@@ -84,6 +95,11 @@ CFM fm;
CCalFM calFM; CCalFM calFM;
#endif #endif
#if defined(MODE_AX25)
CAX25RX ax25RX;
CAX25TX ax25TX;
#endif
CCalRSSI calRSSI; CCalRSSI calRSSI;
CCWIdTX cwIdTX; CCWIdTX cwIdTX;
@@ -132,11 +148,21 @@ void loop()
nxdnTX.process(); nxdnTX.process();
#endif #endif
#if defined(MODE_M17)
if (m_m17Enable && m_modemState == STATE_M17)
m17TX.process();
#endif
#if defined(MODE_POCSAG) #if defined(MODE_POCSAG)
if (m_pocsagEnable && (m_modemState == STATE_POCSAG || pocsagTX.busy())) if (m_pocsagEnable && (m_modemState == STATE_POCSAG || pocsagTX.busy()))
pocsagTX.process(); pocsagTX.process();
#endif #endif
#if defined(MODE_AX25)
if (m_ax25Enable && (m_modemState == STATE_IDLE || m_modemState == STATE_FM))
ax25TX.process();
#endif
#if defined(MODE_FM) #if defined(MODE_FM)
if (m_fmEnable && m_modemState == STATE_FM) if (m_fmEnable && m_modemState == STATE_FM)
fm.process(); fm.process();
Binary file not shown.
+2 -2
View File
@@ -149,9 +149,9 @@ DEFS_EDA_446=-DUSE_STDPERIPH_DRIVER -DSTM32F4XX -DSTM32F446xx -DSTM32F4_EDA_446
# Build compiler flags # Build compiler flags
CFLAGS_F4=-c $(MCFLAGS_F4) $(INCLUDES_F4) CFLAGS_F4=-c $(MCFLAGS_F4) $(INCLUDES_F4)
CXXFLAGS_F4=-c $(MCFLAGS_F4) $(INCLUDES_F4) -std=c++11 CXXFLAGS_F4=-c $(MCFLAGS_F4) $(INCLUDES_F4)
CFLAGS_F7=-c $(MCFLAGS_F7) $(INCLUDES_F7) CFLAGS_F7=-c $(MCFLAGS_F7) $(INCLUDES_F7)
CXXFLAGS_F7=-c $(MCFLAGS_F7) $(INCLUDES_F7) -std=c++11 CXXFLAGS_F7=-c $(MCFLAGS_F7) $(INCLUDES_F7)
# Linker flags # Linker flags
LDFLAGS_F4 =-T stm32f4xx_link.ld $(MCFLAGS_F4) --specs=nosys.specs $(INCLUDES_LIBS_F4) LDFLAGS_F4 =-T stm32f4xx_link.ld $(MCFLAGS_F4) --specs=nosys.specs $(INCLUDES_LIBS_F4)
+165
View File
@@ -0,0 +1,165 @@
# The name for the project
TARGET:=mmdvm
# The CPU architecture (will be used for -mcpu)
MCPU:=cortex-m3
MCU:=STM32F105xC
# The source files of the project
CSRC:=
CXXSRC:=$(wildcard *.cpp)
# Include directory for the system include files and system source file
SYSDIR:=system_stm32f1xx
SYSSRC:=$(SYSDIR)/system_stm32f1xx.c
# Other include directories
INCDIR:=
# Definitions
CDEFS:=
CXXDEFS:=
# The name of the startup file which matches to the architecture (MCPU)
STARTUP:=$(SYSDIR)/startup_stm32f105xc.S
STARTUP_DEFS=
# Include directory for CMSIS
CMSISDIR:=STM32F10X_Lib/CMSIS
# Libraries
LIBDIR:=
LIBS:=-larm_cortexM3l_math
# Name of the linker script
LDSCRIPT:=$(SYSDIR)/gcc.ld
# Target objects and binaries directory
OBJDIR:=obj
BINDIR:=bin
# Port definition for programming via bootloader (using stm32flash)
BL_PORT:=ttyUSB0
# Internal Variables
ELF:=$(BINDIR)/$(TARGET).elf
HEX:=$(BINDIR)/$(TARGET).hex
DIS:=$(BINDIR)/$(TARGET).dis
MAP:=$(BINDIR)/$(TARGET).map
OBJ:=$(CSRC:%.c=$(OBJDIR)/%.o) $(CXXSRC:%.cpp=$(OBJDIR)/%.o)
OBJ+=$(SYSSRC:$(SYSDIR)/%.c=$(OBJDIR)/%.o) $(STARTUP:$(SYSDIR)/%.S=$(OBJDIR)/%.o)
# Replace standard build tools by arm tools
CC:=arm-none-eabi-gcc
CXX:=arm-none-eabi-g++
AS:=arm-none-eabi-gcc
LD:=arm-none-eabi-g++
OBJCOPY:=arm-none-eabi-objcopy
OBJDUMP:=arm-none-eabi-objdump
SIZE:=arm-none-eabi-size
# Common flags
COMMON_FLAGS =-mthumb -mlittle-endian -mcpu=$(MCPU)
COMMON_FLAGS+= -Wall
COMMON_FLAGS+= -I. -I$(CMSISDIR)/Include -I$(CMSISDIR)/Device/ST/STM32F1xx/Include -I$(SYSDIR)
COMMON_FLAGS+= $(addprefix -I,$(INCDIR))
COMMON_FLAGS+= -D$(MCU) -DMADEBYMAKEFILE -DSTM32F1
COMMON_FLAGS+= -Os -flto -ffunction-sections -fdata-sections
COMMON_FLAGS+= -g
# Assembler flags
ASFLAGS:=$(COMMON_FLAGS)
# C flags
CFLAGS:=$(COMMON_FLAGS) $(addprefix -D,$(CDEFS))
CFLAGS+= -std=gnu11 -nostdlib
# CXX flags
CXXFLAGS:=$(COMMON_FLAGS) $(addprefix -D,$(CXXDEFS))
CXXFLAGS+= -nostdlib -fno-exceptions -fno-rtti
# LD flags
LDFLAGS:=$(COMMON_FLAGS) -Wl,--gc-sections -Wl,-Map=$(MAP) -Wl,--no-wchar-size-warning
LDFLAGS+= --specs=nosys.specs --specs=nano.specs
LDFLAGS+= -L$(CMSISDIR)/Lib/GCC/ $(addprefix -L,$(LIBDIR))
LDLIBS:=-T$(LDSCRIPT) $(LIBS)
# Dependecies
DEPENDS:=$(CSRC:%.c=$(OBJDIR)/%.d) $(CXXSRC:%.cpp=$(OBJDIR)/%.d)
# Additional Suffixes
.SUFFIXES: .elf .hex
# Targets
.PHONY: all
all: GitVersion.h $(DIS) $(HEX)
$(SIZE) $(ELF)
.PHONY: program
program: $(HEX) $(ELF)
openocd -f openocd.cfg \
-c "program $(HEX) verify reset exit"
$(SIZE) $(ELF)
.PHONY: program_bl
program_bl: $(HEX) $(ELF)
stm32flash -w $(HEX) -v /dev/$(BL_PORT)
$(SIZE) $(ELF)
.PHONY: run
run: $(HEX) $(ELF)
openocd -f openocd.cfg \
-c "init" -c "reset" -c "exit"
.PHONY: debug
debug: $(ELF)
./debug.sh $(ELF)
.PHONY: clean
clean:
$(RM) $(OBJ) $(HEX) $(ELF) $(DIS) $(MAP) $(DEPENDS) GitVersion.h
# implicit rules
.elf.hex:
$(OBJCOPY) -O ihex $< $@
$(OBJDIR)/%.o: %.c
$(CC) -MMD $(CFLAGS) -c $< -o $@
$(OBJDIR)/%.o: %.cpp
$(CXX) -MMD $(CXXFLAGS) -c $< -o $@
$(OBJDIR)/%.o: $(SYSDIR)/%.c
$(CC) $(CFLAGS) -c $< -o $@
$(OBJDIR)/%.o: $(SYSDIR)/%.S
$(AS) $(ASFLAGS) -c $< -o $@
# explicit rules
$(OBJDIR):
mkdir -p $(OBJDIR)
$(BINDIR):
mkdir -p $(BINDIR)
$(ELF): $(OBJDIR) $(BINDIR) $(OBJ)
$(LD) $(OBJ) $(LDFLAGS) $(LDLIBS) -o $@
$(DIS): $(ELF)
$(OBJDUMP) -S $< > $@
# include dependecies
-include $(DEPENDS)
# Export the current git version if the index file exists, else 000...
GitVersion.h:
ifdef SYSTEMROOT
echo #define GITVERSION "0000000" > $@
else ifdef SystemRoot
echo #define GITVERSION "0000000" > $@
else
ifneq ("$(wildcard .git/index)","")
echo "#define GITVERSION \"$(shell git rev-parse --short HEAD)\"" > $@
else
echo "#define GITVERSION \"0000000\"" > $@
endif
endif
+1 -1
View File
@@ -175,7 +175,7 @@ void CNXDNTX::writeByte(uint8_t c)
void CNXDNTX::writeSilence() void CNXDNTX::writeSilence()
{ {
q15_t inBuffer[4U] = {0, 0, 0, 0}; q15_t inBuffer[4U] = {0x00U, 0x00U, 0x00U, 0x00U};
q15_t intBuffer[NXDN_RADIO_SYMBOL_LENGTH * 4U]; q15_t intBuffer[NXDN_RADIO_SYMBOL_LENGTH * 4U];
q15_t outBuffer[NXDN_RADIO_SYMBOL_LENGTH * 4U]; q15_t outBuffer[NXDN_RADIO_SYMBOL_LENGTH * 4U];
+1 -1
View File
@@ -173,7 +173,7 @@ void CP25TX::writeByte(uint8_t c)
void CP25TX::writeSilence() void CP25TX::writeSilence()
{ {
q15_t inBuffer[4U] = {0, 0, 0, 0}; q15_t inBuffer[4U] = {0x00U, 0x00U, 0x00U, 0x00U};
q15_t intBuffer[P25_RADIO_SYMBOL_LENGTH * 4U]; q15_t intBuffer[P25_RADIO_SYMBOL_LENGTH * 4U];
q15_t outBuffer[P25_RADIO_SYMBOL_LENGTH * 4U]; q15_t outBuffer[P25_RADIO_SYMBOL_LENGTH * 4U];
+14 -32
View File
@@ -1,35 +1,17 @@
This is the source code of the MMDVM firmware that supports D-Star, DMR, System Fusion, P25, NXDN, POCSAG, and FM modes. This is the source code of the MMDVM firmware that supports D-Star, DMR,
System Fusion, P25, NXDN, POCSAG, and FM modes.
It runs on the Arduino Due, the ST-Micro STM32F4xxx and STM32F7xxx processors, as well as the Teensy 3.5/3.6. What these platforms have in common is the use of an ARM Cortex-M3, M4, or M7 processors with a minimum clock speed greater of 80 MHz, and access to at least one analogue to digital converter, one digital to analogue converter, as well as a number of GPIO pins. It runs on the Arduino Due, the ST-Micro STM32F1xxx, STM32F4xxx and STM32F7xxx
processors, as well as the Teensy 3.1/3.2/3.5/3.6. What these platforms have in
common is the use of an ARM Cortex-M3, M4, or M7 processors with a clock speed
greater than 70 MHz, and access to at least one analogue to digital converter
and one digital to analogue converter.
In order to build this software for the Arduino Due, you will need to edit a file within the Arduino GUI and that is detailed in the BUILD.txt file. The STM32 support is supplied via the ARM GCC compiler. The Teensy support uses Teensyduino. In order to build this software for the Arduino Due, you will need to edit a
file within the Arduino GUI and that is detailed in the BUILD.txt file. The
STM32 support is being supplied via the ARM GCC compiler. The Teensy support
uses Teensyduino.
This software is licenced under the GPL v2 and is primarily intended for amateur and educational use. This software is licenced under the GPL v2 and is intended for amateur and
educational use only. Use of this software for commercial purposes is strictly
Portions of the ARM support code include the following copyright: forbidden.
Copyright (c) 2011 - 2013 ARM LIMITED
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of ARM nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
+47
View File
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2017 Wojciech Krutnik N0CALL
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
* FIFO ring buffer
* source:
* http://stackoverflow.com/questions/6822548/correct-way-of-implementing-a-uart-receive-buffer-in-a-small-arm-microcontroller
* (modified)
*
*/
#if !defined(RINGBUFF_H)
#define RINGBUFF_H
#define RINGBUFF_SIZE(ringBuff) (ringBuff.size) /* serial buffer in bytes (power 2) */
#define RINGBUFF_MASK(ringBuff) (ringBuff.size-1U) /* buffer size mask */
/* Buffer read / write macros */
#define RINGBUFF_RESET(ringBuff) (ringBuff).rdIdx = ringBuff.wrIdx = 0
#define RINGBUFF_WRITE(ringBuff, dataIn) (ringBuff).data[RINGBUFF_MASK(ringBuff) & ringBuff.wrIdx++] = (dataIn)
#define RINGBUFF_READ(ringBuff) ((ringBuff).data[RINGBUFF_MASK(ringBuff) & ((ringBuff).rdIdx++)])
#define RINGBUFF_EMPTY(ringBuff) ((ringBuff).rdIdx == (ringBuff).wrIdx)
#define RINGBUFF_FULL(ringBuff) ((RINGBUFF_MASK(ringBuff) & ringBuff.rdIdx) == (RINGBUFF_MASK(ringBuff) & ringBuff.wrIdx))
#define RINGBUFF_COUNT(ringBuff) (RINGBUFF_MASK(ringBuff) & ((ringBuff).wrIdx - (ringBuff).rdIdx))
/* Buffer type */
#define DECLARE_RINGBUFFER_TYPE(name, _size) \
typedef struct{ \
uint32_t size; \
uint32_t wrIdx; \
uint32_t rdIdx; \
uint8_t data[_size]; \
}name##_t
#endif
+7 -4
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2020,2026 by Jonathan Naylor G4KLX * Copyright (C) 2020 by Jonathan Naylor G4KLX
* Copyright (C) 2020 by Geoffrey Merck F4FXL - KC3FRA * 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
@@ -24,12 +24,15 @@
#include "stm32f4xx.h" #include "stm32f4xx.h"
#elif defined(STM32F7XX) #elif defined(STM32F7XX)
#include "stm32f7xx.h" #include "stm32f7xx.h"
#elif defined(STM32F105xC)
#include "stm32f1xx.h"
#include <cstddef>
#else #else
#include <Arduino.h> #include <Arduino.h>
#undef PI #undef PI
#endif #endif
#if defined(__SAM3X8E__) #if defined(__SAM3X8E__) || defined(STM32F105xC)
#define ARM_MATH_CM3 #define ARM_MATH_CM3
#elif defined(STM32F7XX) #elif defined(STM32F7XX)
#define ARM_MATH_CM7 #define ARM_MATH_CM7
@@ -50,7 +53,7 @@ public:
uint16_t getData() const; uint16_t getData() const;
bool put(const TDATATYPE& item) volatile; bool put(TDATATYPE item) volatile;
bool get(TDATATYPE& item) volatile; bool get(TDATATYPE& item) volatile;
@@ -71,4 +74,4 @@ private:
#include "RingBuffer.impl.h" #include "RingBuffer.impl.h"
#endif #endif
+2 -2
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2020,2026 by Jonathan Naylor G4KLX * Copyright (C) 2020 by Jonathan Naylor G4KLX
* Copyright (C) 2020 by Geoffrey Merck F4FXL - KC3FRA * 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
@@ -56,7 +56,7 @@ template <typename TDATATYPE> uint16_t CRingBuffer<TDATATYPE>::getData() const
return m_length - m_tail + m_head; return m_length - m_tail + m_head;
} }
template <typename TDATATYPE> bool CRingBuffer<TDATATYPE>::put(const TDATATYPE& item) volatile template <typename TDATATYPE> bool CRingBuffer<TDATATYPE>::put(TDATATYPE item) volatile
{ {
if (m_full) { if (m_full) {
m_overflow = true; m_overflow = true;
Submodule
+1
Submodule STM32F10X_Lib added at 417e0c2f4a
+1 -3
View File
@@ -1,7 +1,5 @@
/* /*
* Copyright (C) 2017 by Wojciech Krutnik N0CALL * source: http://mightydevices.com/?p=144
*
* Source: http://mightydevices.com/?p=144
* *
* 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
+3 -7
View File
@@ -61,7 +61,7 @@ void CSTMUART::handleIRQ()
if (USART_GetITStatus(m_usart, USART_IT_RXNE)) { if (USART_GetITStatus(m_usart, USART_IT_RXNE)) {
if(!m_rxFifo.isFull()) if(!m_rxFifo.isFull())
m_rxFifo.put((uint8_t) USART_ReceiveData(m_usart)); m_rxFifo.put((uint8_t) USART_ReceiveData(m_usart));
USART_ClearITPendingBit(m_usart, USART_IT_RXNE); USART_ClearITPendingBit(USART1, USART_IT_RXNE);
} }
if (USART_GetITStatus(m_usart, USART_IT_TXE)) { if (USART_GetITStatus(m_usart, USART_IT_TXE)) {
@@ -82,12 +82,8 @@ void CSTMUART::flush()
if(m_usart == NULL) if(m_usart == NULL)
return; return;
// wait until the TX FIFO has drained // wait until the TXE shows the shift register is empty
while (!m_txFifo.isEmpty()) while (USART_GetITStatus(m_usart, USART_FLAG_TXE))
;
// wait until the TC flag shows the shift register is empty
while (USART_GetFlagStatus(m_usart, USART_FLAG_TC) == RESET)
; ;
} }
+335 -150
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2013,2015-2021,2023,2025 by Jonathan Naylor G4KLX * Copyright (C) 2013,2015-2021 by Jonathan Naylor G4KLX
* Copyright (C) 2016 by Colin Durbridge G4EML * Copyright (C) 2016 by Colin Durbridge G4EML
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@@ -45,7 +45,6 @@ const uint8_t MMDVM_DSTAR_DATA = 0x11U;
const uint8_t MMDVM_DSTAR_LOST = 0x12U; const uint8_t MMDVM_DSTAR_LOST = 0x12U;
const uint8_t MMDVM_DSTAR_EOT = 0x13U; const uint8_t MMDVM_DSTAR_EOT = 0x13U;
const uint8_t MMDVM_DMR_ALOHA = 0x17U;
const uint8_t MMDVM_DMR_DATA1 = 0x18U; const uint8_t MMDVM_DMR_DATA1 = 0x18U;
const uint8_t MMDVM_DMR_LOST1 = 0x19U; const uint8_t MMDVM_DMR_LOST1 = 0x19U;
const uint8_t MMDVM_DMR_DATA2 = 0x1AU; const uint8_t MMDVM_DMR_DATA2 = 0x1AU;
@@ -64,8 +63,15 @@ const uint8_t MMDVM_P25_LOST = 0x32U;
const uint8_t MMDVM_NXDN_DATA = 0x40U; const uint8_t MMDVM_NXDN_DATA = 0x40U;
const uint8_t MMDVM_NXDN_LOST = 0x41U; const uint8_t MMDVM_NXDN_LOST = 0x41U;
const uint8_t MMDVM_M17_LINK_SETUP = 0x45U;
const uint8_t MMDVM_M17_STREAM = 0x46U;
const uint8_t MMDVM_M17_PACKET = 0x47U;
const uint8_t MMDVM_M17_LOST = 0x48U;
const uint8_t MMDVM_POCSAG_DATA = 0x50U; const uint8_t MMDVM_POCSAG_DATA = 0x50U;
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;
@@ -73,13 +79,11 @@ const uint8_t MMDVM_FM_PARAMS4 = 0x63U;
const uint8_t MMDVM_FM_DATA = 0x65U; const uint8_t MMDVM_FM_DATA = 0x65U;
const uint8_t MMDVM_FM_STATUS = 0x66U; const uint8_t MMDVM_FM_STATUS = 0x66U;
const uint8_t MMDVM_FM_EOT = 0x67U; const uint8_t MMDVM_FM_EOT = 0x67U;
const uint8_t MMDVM_FM_RSSI = 0x68U;
const uint8_t MMDVM_ACK = 0x70U; const uint8_t MMDVM_ACK = 0x70U;
const uint8_t MMDVM_NAK = 0x7FU; const uint8_t MMDVM_NAK = 0x7FU;
const uint8_t MMDVM_SERIAL_DATA = 0x80U; const uint8_t MMDVM_SERIAL_DATA = 0x80U;
const uint8_t MMDVM_I2C_DATA = 0x81U;
const uint8_t MMDVM_TRANSPARENT = 0x90U; const uint8_t MMDVM_TRANSPARENT = 0x90U;
const uint8_t MMDVM_QSO_INFO = 0x91U; const uint8_t MMDVM_QSO_INFO = 0x91U;
@@ -129,36 +133,38 @@ const uint8_t PROTOCOL_VERSION = 2U;
const int MAX_SERIAL_DATA = 250; const int MAX_SERIAL_DATA = 250;
const uint16_t MAX_SERIAL_COUNT = 100U; const uint16_t MAX_SERIAL_COUNT = 100U;
CSerialPort::CSerialPort() : CSerialPort::CSerialPort() :
m_buffer(), m_buffer(),
m_ptr(0U), m_ptr(0U),
m_len(0U), m_len(0U),
m_debug(false), m_debug(false),
m_serialData(),
m_lastSerialAvail(0), m_lastSerialAvail(0),
m_lastSerialAvailCount(0U) m_lastSerialAvailCount(0U)
{ {
} }
void CSerialPort::sendACK(uint8_t type) void CSerialPort::sendACK()
{ {
uint8_t reply[4U]; uint8_t reply[4U];
reply[0U] = MMDVM_FRAME_START; reply[0U] = MMDVM_FRAME_START;
reply[1U] = 4U; reply[1U] = 4U;
reply[2U] = MMDVM_ACK; reply[2U] = MMDVM_ACK;
reply[3U] = type; reply[3U] = m_buffer[2U];
writeInt(1U, reply, 4); writeInt(1U, reply, 4);
} }
void CSerialPort::sendNAK(uint8_t type, uint8_t err) void CSerialPort::sendNAK(uint8_t err)
{ {
uint8_t reply[5U]; uint8_t reply[5U];
reply[0U] = MMDVM_FRAME_START; reply[0U] = MMDVM_FRAME_START;
reply[1U] = 5U; reply[1U] = 5U;
reply[2U] = MMDVM_NAK; reply[2U] = MMDVM_NAK;
reply[3U] = type; reply[3U] = m_buffer[2U];
reply[4U] = err; reply[4U] = err;
writeInt(1U, reply, 5); writeInt(1U, reply, 5);
@@ -256,7 +262,14 @@ void CSerialPort::getStatus()
reply[11U] = 0U; reply[11U] = 0U;
#endif #endif
#if defined(MODE_M17)
if (m_m17Enable)
reply[12U] = m17TX.getSpace();
else
reply[12U] = 0U;
#else
reply[12U] = 0U; reply[12U] = 0U;
#endif
#if defined(MODE_FM) #if defined(MODE_FM)
if (m_fmEnable) if (m_fmEnable)
@@ -267,18 +280,27 @@ void CSerialPort::getStatus()
reply[13U] = 0U; reply[13U] = 0U;
#endif #endif
reply[14U] = 0x00U;
reply[15U] = 0x00U;
#if defined(MODE_POCSAG) #if defined(MODE_POCSAG)
if (m_pocsagEnable) if (m_pocsagEnable)
reply[14U] = pocsagTX.getSpace(); reply[16U] = pocsagTX.getSpace();
else else
reply[14U] = 0U; reply[16U] = 0U;
#else #else
reply[14U] = 0U; reply[16U] = 0U;
#endif
#if defined(MODE_AX25)
if (m_ax25Enable)
reply[17U] = ax25TX.getSpace();
else
reply[17U] = 0U;
#else
reply[17U] = 0U;
#endif #endif
reply[15U] = 0U;
reply[16U] = 0x00U;
reply[17U] = 0x00U;
reply[18U] = 0x00U; reply[18U] = 0x00U;
reply[19U] = 0x00U; reply[19U] = 0x00U;
@@ -312,6 +334,9 @@ void CSerialPort::getVersion()
#if defined(MODE_NXDN) #if defined(MODE_NXDN)
reply[4U] |= 0x10U; reply[4U] |= 0x10U;
#endif #endif
#if defined(MODE_M17)
reply[4U] |= 0x20U;
#endif
#if defined(MODE_FM) #if defined(MODE_FM)
reply[4U] |= 0x40U; reply[4U] |= 0x40U;
#endif #endif
@@ -320,6 +345,9 @@ void CSerialPort::getVersion()
#if defined(MODE_POCSAG) #if defined(MODE_POCSAG)
reply[5U] |= 0x01U; reply[5U] |= 0x01U;
#endif #endif
#if defined(MODE_AX25)
reply[5U] |= 0x02U;
#endif
// CPU type/manufacturer. 0=Atmel ARM, 1=NXP ARM, 2=St-Micro ARM // CPU type/manufacturer. 0=Atmel ARM, 1=NXP ARM, 2=St-Micro ARM
reply[6U] = io.getCPU(); reply[6U] = io.getCPU();
@@ -345,35 +373,22 @@ uint8_t CSerialPort::setConfig(const uint8_t* data, uint16_t length)
bool rxInvert = (data[0U] & 0x01U) == 0x01U; bool rxInvert = (data[0U] & 0x01U) == 0x01U;
bool txInvert = (data[0U] & 0x02U) == 0x02U; bool txInvert = (data[0U] & 0x02U) == 0x02U;
bool pttInvert = (data[0U] & 0x04U) == 0x04U; bool pttInvert = (data[0U] & 0x04U) == 0x04U;
#if defined(MODE_YSF)
bool ysfLoDev = (data[0U] & 0x08U) == 0x08U; bool ysfLoDev = (data[0U] & 0x08U) == 0x08U;
#endif
bool useCOSAsLockout = (data[0U] & 0x20U) == 0x20U; bool useCOSAsLockout = (data[0U] & 0x20U) == 0x20U;
bool simplex = (data[0U] & 0x80U) == 0x80U; bool simplex = (data[0U] & 0x80U) == 0x80U;
m_debug = (data[0U] & 0x10U) == 0x10U; m_debug = (data[0U] & 0x10U) == 0x10U;
#if defined(MODE_DSTAR)
bool dstarEnable = (data[1U] & 0x01U) == 0x01U; bool dstarEnable = (data[1U] & 0x01U) == 0x01U;
#endif
#if defined(MODE_DMR)
bool dmrEnable = (data[1U] & 0x02U) == 0x02U; bool dmrEnable = (data[1U] & 0x02U) == 0x02U;
#endif
#if defined(MODE_YSF)
bool ysfEnable = (data[1U] & 0x04U) == 0x04U; bool ysfEnable = (data[1U] & 0x04U) == 0x04U;
#endif
#if defined(MODE_P25)
bool p25Enable = (data[1U] & 0x08U) == 0x08U; bool p25Enable = (data[1U] & 0x08U) == 0x08U;
#endif
#if defined(MODE_NXDN)
bool nxdnEnable = (data[1U] & 0x10U) == 0x10U; bool nxdnEnable = (data[1U] & 0x10U) == 0x10U;
#endif
#if defined(MODE_FM)
bool fmEnable = (data[1U] & 0x20U) == 0x20U; bool fmEnable = (data[1U] & 0x20U) == 0x20U;
#endif bool m17Enable = (data[1U] & 0x40U) == 0x40U;
#if defined(MODE_POCSAG)
bool pocsagEnable = (data[2U] & 0x01U) == 0x01U; bool pocsagEnable = (data[2U] & 0x01U) == 0x01U;
#endif bool ax25Enable = (data[2U] & 0x02U) == 0x02U;
uint8_t txDelay = data[3U]; uint8_t txDelay = data[3U];
if (txDelay > 50U) if (txDelay > 50U)
@@ -381,9 +396,7 @@ uint8_t CSerialPort::setConfig(const uint8_t* data, uint16_t length)
MMDVM_STATE modemState = MMDVM_STATE(data[4U]); MMDVM_STATE modemState = MMDVM_STATE(data[4U]);
if (modemState != STATE_IDLE && modemState != STATE_DSTAR && modemState != STATE_DMR && modemState != STATE_YSF && modemState != STATE_P25 && modemState != STATE_NXDN && modemState != STATE_POCSAG && modemState != STATE_FM && if (modemState != STATE_IDLE && modemState != STATE_DSTAR && modemState != STATE_DMR && modemState != STATE_YSF && modemState != STATE_P25 && modemState != STATE_NXDN && modemState != STATE_M17 && modemState != STATE_POCSAG && modemState != STATE_FM && modemState != STATE_DSTARCAL && modemState != STATE_DMRCAL && modemState != STATE_RSSICAL && modemState != STATE_LFCAL && modemState != STATE_DMRCAL1K && modemState != STATE_P25CAL1K && modemState != STATE_DMRDMO1K && modemState != STATE_NXDNCAL1K && modemState != STATE_POCSAGCAL && modemState != STATE_FMCAL10K && modemState != STATE_FMCAL12K && modemState != STATE_FMCAL15K && modemState != STATE_FMCAL20K && modemState != STATE_FMCAL25K && modemState != STATE_FMCAL30K)
modemState != STATE_DSTARCAL && modemState != STATE_DMRCAL && modemState != STATE_RSSICAL && modemState != STATE_LFCAL && modemState != STATE_DMRCAL1K && modemState != STATE_P25CAL1K && modemState != STATE_DMRDMO1K && modemState != STATE_NXDNCAL1K && modemState != STATE_POCSAGCAL &&
modemState != STATE_FMCAL10K && modemState != STATE_FMCAL12K && modemState != STATE_FMCAL15K && modemState != STATE_FMCAL20K && modemState != STATE_FMCAL25K && modemState != STATE_FMCAL30K)
return 4U; return 4U;
#if defined(MODE_DSTAR) #if defined(MODE_DSTAR)
@@ -426,6 +439,14 @@ uint8_t CSerialPort::setConfig(const uint8_t* data, uint16_t length)
return 4U; return 4U;
#endif #endif
#if defined(MODE_M17)
if (modemState == STATE_M17 && !m17Enable)
return 4U;
#else
if (modemState == STATE_M17)
return 4U;
#endif
#if defined(MODE_POCSAG) #if defined(MODE_POCSAG)
if (modemState == STATE_POCSAG && !pocsagEnable) if (modemState == STATE_POCSAG && !pocsagEnable)
return 4U; return 4U;
@@ -453,27 +474,29 @@ uint8_t CSerialPort::setConfig(const uint8_t* data, uint16_t length)
uint8_t ysfTXLevel = data[11U]; uint8_t ysfTXLevel = data[11U];
uint8_t p25TXLevel = data[12U]; uint8_t p25TXLevel = data[12U];
uint8_t nxdnTXLevel = data[13U]; uint8_t nxdnTXLevel = data[13U];
uint8_t m17TXLevel = data[14U];
uint8_t pocsagTXLevel = data[15U]; uint8_t pocsagTXLevel = data[15U];
uint8_t fmTXLevel = data[16U]; uint8_t fmTXLevel = data[16U];
uint8_t ax25TXLevel = data[17U];
#if defined(MODE_YSF)
uint8_t ysfTXHang = data[20U]; uint8_t ysfTXHang = data[20U];
#endif
#if defined(MODE_P25)
uint8_t p25TXHang = data[21U]; uint8_t p25TXHang = data[21U];
#endif
#if defined(MODE_NXDN)
uint8_t nxdnTXHang = data[22U]; uint8_t nxdnTXHang = data[22U];
#endif uint8_t m17TXHang = data[23U];
#if defined(MODE_DMR)
bool trunking = (data[25U] & 128U) == 128U;
uint8_t colorCode = data[26U]; uint8_t colorCode = data[26U];
if (colorCode > 15U) if (colorCode > 15U)
return 4U; return 4U;
uint8_t dmrDelay = data[27U]; uint8_t dmrDelay = data[27U];
#endif
int8_t ax25RXTwist = int8_t(data[28U]) - 128;
if (ax25RXTwist < -4 || ax25RXTwist > 10)
return 4U;
uint8_t ax25TXDelay = data[29U];
uint8_t ax25SlotTime = data[30U];
uint8_t ax25PPersist = data[31U];
setMode(modemState); setMode(modemState);
@@ -486,7 +509,7 @@ uint8_t CSerialPort::setConfig(const uint8_t* data, uint16_t length)
#if defined(MODE_DMR) #if defined(MODE_DMR)
m_dmrEnable = dmrEnable; m_dmrEnable = dmrEnable;
dmrDMOTX.setTXDelay(txDelay); dmrDMOTX.setTXDelay(txDelay);
dmrTX.setTrunking(trunking);
dmrTX.setColorCode(colorCode); dmrTX.setColorCode(colorCode);
dmrRX.setColorCode(colorCode); dmrRX.setColorCode(colorCode);
dmrRX.setDelay(dmrDelay); dmrRX.setDelay(dmrDelay);
@@ -508,15 +531,25 @@ uint8_t CSerialPort::setConfig(const uint8_t* data, uint16_t length)
nxdnTX.setTXDelay(txDelay); nxdnTX.setTXDelay(txDelay);
nxdnTX.setParams(nxdnTXHang); nxdnTX.setParams(nxdnTXHang);
#endif #endif
#if defined(MODE_M17)
m_m17Enable = m17Enable;
m17TX.setTXDelay(txDelay);
m17TX.setParams(m17TXHang);
#endif
#if defined(MODE_POCSAG) #if defined(MODE_POCSAG)
m_pocsagEnable = pocsagEnable; m_pocsagEnable = pocsagEnable;
pocsagTX.setTXDelay(txDelay); pocsagTX.setTXDelay(txDelay);
#endif #endif
#if defined(MODE_AX25)
m_ax25Enable = ax25Enable;
ax25TX.setTXDelay(ax25TXDelay);
ax25RX.setParams(ax25RXTwist, ax25SlotTime, ax25PPersist);
#endif
#if defined(MODE_FM) #if defined(MODE_FM)
m_fmEnable = fmEnable; m_fmEnable = fmEnable;
#endif #endif
io.setParameters(rxInvert, txInvert, pttInvert, rxLevel, cwIdTXLevel, dstarTXLevel, dmrTXLevel, ysfTXLevel, p25TXLevel, nxdnTXLevel, pocsagTXLevel, fmTXLevel, txDCOffset, rxDCOffset, useCOSAsLockout); io.setParameters(rxInvert, txInvert, pttInvert, rxLevel, cwIdTXLevel, dstarTXLevel, dmrTXLevel, ysfTXLevel, p25TXLevel, nxdnTXLevel, m17TXLevel, pocsagTXLevel, fmTXLevel, ax25TXLevel, txDCOffset, rxDCOffset, useCOSAsLockout);
io.start(); io.start();
@@ -586,7 +619,6 @@ uint8_t CSerialPort::setFMParams3(const uint8_t* data, uint16_t length)
uint8_t hangTime = data[7U]; uint8_t hangTime = data[7U];
uint8_t accessMode = data[8U] & 0x0FU; uint8_t accessMode = data[8U] & 0x0FU;
bool linkMode = (data[8U] & 0x20U) == 0x20U;
bool noiseSquelch = (data[8U] & 0x40U) == 0x40U; bool noiseSquelch = (data[8U] & 0x40U) == 0x40U;
bool cosInvert = (data[8U] & 0x80U) == 0x80U; bool cosInvert = (data[8U] & 0x80U) == 0x80U;
@@ -597,7 +629,7 @@ uint8_t CSerialPort::setFMParams3(const uint8_t* data, uint16_t length)
uint8_t squelchHighThreshold = data[12U]; uint8_t squelchHighThreshold = data[12U];
uint8_t squelchLowThreshold = data[13U]; uint8_t squelchLowThreshold = data[13U];
return fm.setMisc(timeout, timeoutLevel, ctcssFrequency, ctcssHighThreshold, ctcssLowThreshold, ctcssLevel, kerchunkTime, hangTime, accessMode, linkMode, cosInvert, noiseSquelch, squelchHighThreshold, squelchLowThreshold, rfAudioBoost, maxDev, rxLevel); 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) uint8_t CSerialPort::setFMParams4(const uint8_t* data, uint16_t length)
@@ -630,9 +662,7 @@ uint8_t CSerialPort::setMode(const uint8_t* data, uint16_t length)
if (modemState == m_modemState) if (modemState == m_modemState)
return 0U; return 0U;
if (modemState != STATE_IDLE && modemState != STATE_DSTAR && modemState != STATE_DMR && modemState != STATE_YSF && modemState != STATE_P25 && modemState != STATE_NXDN && modemState != STATE_POCSAG && modemState != STATE_FM && if (modemState != STATE_IDLE && modemState != STATE_DSTAR && modemState != STATE_DMR && modemState != STATE_YSF && modemState != STATE_P25 && modemState != STATE_NXDN && modemState != STATE_M17 && modemState != STATE_POCSAG && modemState != STATE_FM && modemState != STATE_DSTARCAL && modemState != STATE_DMRCAL && modemState != STATE_RSSICAL && modemState != STATE_LFCAL && modemState != STATE_DMRCAL1K && modemState != STATE_P25CAL1K && modemState != STATE_DMRDMO1K && modemState != STATE_NXDNCAL1K && modemState != STATE_POCSAGCAL && modemState != STATE_FMCAL10K && modemState != STATE_FMCAL12K && modemState != STATE_FMCAL15K && modemState != STATE_FMCAL20K && modemState != STATE_FMCAL25K && modemState != STATE_FMCAL30K)
modemState != STATE_DSTARCAL && modemState != STATE_DMRCAL && modemState != STATE_RSSICAL && modemState != STATE_LFCAL && modemState != STATE_DMRCAL1K && modemState != STATE_P25CAL1K && modemState != STATE_DMRDMO1K && modemState != STATE_NXDNCAL1K && modemState != STATE_POCSAGCAL &&
modemState != STATE_FMCAL10K && modemState != STATE_FMCAL12K && modemState != STATE_FMCAL15K && modemState != STATE_FMCAL20K && modemState != STATE_FMCAL25K && modemState != STATE_FMCAL30K)
return 4U; return 4U;
#if defined(MODE_DSTAR) #if defined(MODE_DSTAR)
@@ -675,6 +705,14 @@ uint8_t CSerialPort::setMode(const uint8_t* data, uint16_t length)
return 4U; return 4U;
#endif #endif
#if defined(MODE_M17)
if (modemState == STATE_M17 && !m_m17Enable)
return 4U;
#else
if (modemState == STATE_M17)
return 4U;
#endif
#if defined(MODE_POCSAG) #if defined(MODE_POCSAG)
if (modemState == STATE_POCSAG && !m_pocsagEnable) if (modemState == STATE_POCSAG && !m_pocsagEnable)
return 4U; return 4U;
@@ -714,6 +752,9 @@ void CSerialPort::setMode(MMDVM_STATE modemState)
case STATE_NXDN: case STATE_NXDN:
DEBUG1("Mode set to NXDN"); DEBUG1("Mode set to NXDN");
break; break;
case STATE_M17:
DEBUG1("Mode set to M17");
break;
case STATE_POCSAG: case STATE_POCSAG:
DEBUG1("Mode set to POCSAG"); DEBUG1("Mode set to POCSAG");
break; break;
@@ -745,7 +786,7 @@ void CSerialPort::setMode(MMDVM_STATE modemState)
DEBUG1("Mode set to FM 20Khz Calibrate"); DEBUG1("Mode set to FM 20Khz Calibrate");
break; break;
case STATE_FMCAL25K: case STATE_FMCAL25K:
DEBUG1("Mode set to FM 25Khz Calibrate"); DEBUG1("Mode set to FM 10Khz Calibrate");
break; break;
case STATE_FMCAL30K: case STATE_FMCAL30K:
DEBUG1("Mode set to FM 30Khz Calibrate"); DEBUG1("Mode set to FM 30Khz Calibrate");
@@ -795,6 +836,11 @@ void CSerialPort::setMode(MMDVM_STATE modemState)
nxdnRX.reset(); nxdnRX.reset();
#endif #endif
#if defined(MODE_M17)
if (modemState != STATE_M17)
m17RX.reset();
#endif
#if defined(MODE_FM) #if defined(MODE_FM)
if (modemState != STATE_FM) if (modemState != STATE_FM)
fm.reset(); fm.reset();
@@ -810,14 +856,7 @@ void CSerialPort::start()
beginInt(1U, SERIAL_SPEED); beginInt(1U, SERIAL_SPEED);
#if defined(SERIAL_REPEATER) #if defined(SERIAL_REPEATER)
#if defined(SERIAL_REPEATER_BAUD_RATE) beginInt(3U, 9600);
beginInt(3U, SERIAL_REPEATER_BAUD_RATE);
#else
beginInt(3U, 9600);
#endif
#endif
#if defined(I2C_REPEATER)
beginInt(10U, 9600);
#endif #endif
} }
@@ -872,6 +911,20 @@ void CSerialPort::process()
} }
#if defined(SERIAL_REPEATER) #if defined(SERIAL_REPEATER)
// Write any outgoing serial data
uint16_t serialSpace = m_serialData.getData();
if (serialSpace > 0U) {
int avail = availableForWriteInt(3U);
if (avail < serialSpace)
serialSpace = avail;
for (uint16_t i = 0U; i < serialSpace; i++) {
uint8_t c = 0U;
m_serialData.get(c);
writeInt(3U, &c, 1U);
}
}
// Read any incoming serial data, and send out in batches // Read any incoming serial data, and send out in batches
int serialAvail = availableForReadInt(3U); int serialAvail = availableForReadInt(3U);
if ((serialAvail > 0 && serialAvail == m_lastSerialAvail && m_lastSerialAvailCount >= MAX_SERIAL_COUNT) || (serialAvail >= MAX_SERIAL_DATA)) { if ((serialAvail > 0 && serialAvail == m_lastSerialAvail && m_lastSerialAvailCount >= MAX_SERIAL_COUNT) || (serialAvail >= MAX_SERIAL_DATA)) {
@@ -882,7 +935,7 @@ void CSerialPort::process()
} }
writeSerialData(buffer, serialAvail - m_lastSerialAvail); writeSerialData(buffer, serialAvail - m_lastSerialAvail);
m_lastSerialAvailCount = 0U; m_lastSerialAvailCount = 0U;
} else if (serialAvail > 0 && serialAvail == m_lastSerialAvail) { } else if (serialAvail > 0U && serialAvail == m_lastSerialAvail) {
m_lastSerialAvailCount++; m_lastSerialAvailCount++;
} else { } else {
m_lastSerialAvail = serialAvail; m_lastSerialAvail = serialAvail;
@@ -907,61 +960,61 @@ void CSerialPort::processMessage(uint8_t type, const uint8_t* buffer, uint16_t l
case MMDVM_SET_CONFIG: case MMDVM_SET_CONFIG:
err = setConfig(buffer, length); err = setConfig(buffer, length);
if (err == 0U) if (err == 0U)
sendACK(type); sendACK();
else else
sendNAK(type, err); sendNAK(err);
break; break;
case MMDVM_SET_MODE: case MMDVM_SET_MODE:
err = setMode(buffer, length); err = setMode(buffer, length);
if (err == 0U) if (err == 0U)
sendACK(type); sendACK();
else else
sendNAK(type, err); sendNAK(err);
break; break;
case MMDVM_SET_FREQ: case MMDVM_SET_FREQ:
sendACK(type); sendACK();
break; break;
#if defined(MODE_FM) #if defined(MODE_FM)
case MMDVM_FM_PARAMS1: case MMDVM_FM_PARAMS1:
err = setFMParams1(buffer, length); err = setFMParams1(buffer, length);
if (err == 0U) { if (err == 0U) {
sendACK(type); sendACK();
} else { } else {
DEBUG2("Received invalid FM params 1", err); DEBUG2("Received invalid FM params 1", err);
sendNAK(type, err); sendNAK(err);
} }
break; break;
case MMDVM_FM_PARAMS2: case MMDVM_FM_PARAMS2:
err = setFMParams2(buffer, length); err = setFMParams2(buffer, length);
if (err == 0U) { if (err == 0U) {
sendACK(type); sendACK();
} else { } else {
DEBUG2("Received invalid FM params 2", err); DEBUG2("Received invalid FM params 2", err);
sendNAK(type, err); sendNAK(err);
} }
break; break;
case MMDVM_FM_PARAMS3: case MMDVM_FM_PARAMS3:
err = setFMParams3(buffer, length); err = setFMParams3(buffer, length);
if (err == 0U) { if (err == 0U) {
sendACK(type); sendACK();
} else { } else {
DEBUG2("Received invalid FM params 3", err); DEBUG2("Received invalid FM params 3", err);
sendNAK(type, err); sendNAK(err);
} }
break; break;
case MMDVM_FM_PARAMS4: case MMDVM_FM_PARAMS4:
err = setFMParams4(buffer, length); err = setFMParams4(buffer, length);
if (err == 0U) { if (err == 0U) {
sendACK(type); sendACK();
} else { } else {
DEBUG2("Received invalid FM params 4", err); DEBUG2("Received invalid FM params 4", err);
sendNAK(type, err); sendNAK(err);
} }
break; break;
#else #else
@@ -969,7 +1022,7 @@ void CSerialPort::processMessage(uint8_t type, const uint8_t* buffer, uint16_t l
case MMDVM_FM_PARAMS2: case MMDVM_FM_PARAMS2:
case MMDVM_FM_PARAMS3: case MMDVM_FM_PARAMS3:
case MMDVM_FM_PARAMS4: case MMDVM_FM_PARAMS4:
sendACK(type); sendACK();
break; break;
#endif #endif
@@ -999,10 +1052,10 @@ void CSerialPort::processMessage(uint8_t type, const uint8_t* buffer, uint16_t l
err = calPOCSAG.write(buffer, length); err = calPOCSAG.write(buffer, length);
#endif #endif
if (err == 0U) { if (err == 0U) {
sendACK(type); sendACK();
} else { } else {
DEBUG2("Received invalid calibration data", err); DEBUG2("Received invalid calibration data", err);
sendNAK(type, err); sendNAK(err);
} }
break; break;
@@ -1012,7 +1065,7 @@ void CSerialPort::processMessage(uint8_t type, const uint8_t* buffer, uint16_t l
err = cwIdTX.write(buffer, length); err = cwIdTX.write(buffer, length);
if (err != 0U) { if (err != 0U) {
DEBUG2("Invalid CW Id data", err); DEBUG2("Invalid CW Id data", err);
sendNAK(type, err); sendNAK(err);
} }
break; break;
@@ -1027,7 +1080,7 @@ void CSerialPort::processMessage(uint8_t type, const uint8_t* buffer, uint16_t l
setMode(STATE_DSTAR); setMode(STATE_DSTAR);
} else { } else {
DEBUG2("Received invalid D-Star header", err); DEBUG2("Received invalid D-Star header", err);
sendNAK(type, err); sendNAK(err);
} }
break; break;
@@ -1041,7 +1094,7 @@ void CSerialPort::processMessage(uint8_t type, const uint8_t* buffer, uint16_t l
setMode(STATE_DSTAR); setMode(STATE_DSTAR);
} else { } else {
DEBUG2("Received invalid D-Star data", err); DEBUG2("Received invalid D-Star data", err);
sendNAK(type, err); sendNAK(err);
} }
break; break;
@@ -1055,7 +1108,7 @@ void CSerialPort::processMessage(uint8_t type, const uint8_t* buffer, uint16_t l
setMode(STATE_DSTAR); setMode(STATE_DSTAR);
} else { } else {
DEBUG2("Received invalid D-Star EOT", err); DEBUG2("Received invalid D-Star EOT", err);
sendNAK(type, err); sendNAK(err);
} }
break; break;
#endif #endif
@@ -1073,7 +1126,7 @@ void CSerialPort::processMessage(uint8_t type, const uint8_t* buffer, uint16_t l
setMode(STATE_DMR); setMode(STATE_DMR);
} else { } else {
DEBUG2("Received invalid DMR data", err); DEBUG2("Received invalid DMR data", err);
sendNAK(type, err); sendNAK(err);
} }
break; break;
@@ -1091,7 +1144,7 @@ void CSerialPort::processMessage(uint8_t type, const uint8_t* buffer, uint16_t l
setMode(STATE_DMR); setMode(STATE_DMR);
} else { } else {
DEBUG2("Received invalid DMR data", err); DEBUG2("Received invalid DMR data", err);
sendNAK(type, err); sendNAK(err);
} }
break; break;
@@ -1112,7 +1165,7 @@ void CSerialPort::processMessage(uint8_t type, const uint8_t* buffer, uint16_t l
} }
if (err != 0U) { if (err != 0U) {
DEBUG2("Received invalid DMR start", err); DEBUG2("Received invalid DMR start", err);
sendNAK(type, err); sendNAK(err);
} }
break; break;
@@ -1121,16 +1174,7 @@ void CSerialPort::processMessage(uint8_t type, const uint8_t* buffer, uint16_t l
err = dmrTX.writeShortLC(buffer, length); err = dmrTX.writeShortLC(buffer, length);
if (err != 0U) { if (err != 0U) {
DEBUG2("Received invalid DMR Short LC", err); DEBUG2("Received invalid DMR Short LC", err);
sendNAK(type, err); sendNAK(err);
}
break;
case MMDVM_DMR_ALOHA:
if (m_dmrEnable)
err = dmrTX.writeAloha(buffer, length);
if (err != 0U) {
DEBUG2("Received invalid DMR ALOHA", err);
sendNAK(type, err);
} }
break; break;
@@ -1139,7 +1183,7 @@ void CSerialPort::processMessage(uint8_t type, const uint8_t* buffer, uint16_t l
err = dmrTX.writeAbort(buffer, length); err = dmrTX.writeAbort(buffer, length);
if (err != 0U) { if (err != 0U) {
DEBUG2("Received invalid DMR Abort", err); DEBUG2("Received invalid DMR Abort", err);
sendNAK(type, err); sendNAK(err);
} }
break; break;
#endif #endif
@@ -1155,7 +1199,7 @@ void CSerialPort::processMessage(uint8_t type, const uint8_t* buffer, uint16_t l
setMode(STATE_YSF); setMode(STATE_YSF);
} else { } else {
DEBUG2("Received invalid System Fusion data", err); DEBUG2("Received invalid System Fusion data", err);
sendNAK(type, err); sendNAK(err);
} }
break; break;
#endif #endif
@@ -1171,7 +1215,7 @@ void CSerialPort::processMessage(uint8_t type, const uint8_t* buffer, uint16_t l
setMode(STATE_P25); setMode(STATE_P25);
} else { } else {
DEBUG2("Received invalid P25 header", err); DEBUG2("Received invalid P25 header", err);
sendNAK(type, err); sendNAK(err);
} }
break; break;
@@ -1185,7 +1229,7 @@ void CSerialPort::processMessage(uint8_t type, const uint8_t* buffer, uint16_t l
setMode(STATE_P25); setMode(STATE_P25);
} else { } else {
DEBUG2("Received invalid P25 LDU", err); DEBUG2("Received invalid P25 LDU", err);
sendNAK(type, err); sendNAK(err);
} }
break; break;
#endif #endif
@@ -1201,7 +1245,51 @@ void CSerialPort::processMessage(uint8_t type, const uint8_t* buffer, uint16_t l
setMode(STATE_NXDN); setMode(STATE_NXDN);
} else { } else {
DEBUG2("Received invalid NXDN data", err); DEBUG2("Received invalid NXDN data", err);
sendNAK(type, err); sendNAK(err);
}
break;
#endif
#if defined(MODE_M17)
case MMDVM_M17_LINK_SETUP:
if (m_m17Enable) {
if (m_modemState == STATE_IDLE || m_modemState == STATE_M17)
err = m17TX.writeData(buffer, length);
}
if (err == 0U) {
if (m_modemState == STATE_IDLE)
setMode(STATE_M17);
} else {
DEBUG2("Received invalid M17 link setup data", err);
sendNAK(err);
}
break;
case MMDVM_M17_STREAM:
if (m_m17Enable) {
if (m_modemState == STATE_IDLE || m_modemState == STATE_M17)
err = m17TX.writeData(buffer, length);
}
if (err == 0U) {
if (m_modemState == STATE_IDLE)
setMode(STATE_M17);
} else {
DEBUG2("Received invalid M17 stream data", err);
sendNAK(err);
}
break;
case MMDVM_M17_PACKET:
if (m_m17Enable) {
if (m_modemState == STATE_IDLE || m_modemState == STATE_M17)
err = m17TX.writeData(buffer, length);
}
if (err == 0U) {
if (m_modemState == STATE_IDLE)
setMode(STATE_M17);
} else {
DEBUG2("Received invalid M17 packet data", err);
sendNAK(err);
} }
break; break;
#endif #endif
@@ -1217,7 +1305,7 @@ void CSerialPort::processMessage(uint8_t type, const uint8_t* buffer, uint16_t l
setMode(STATE_POCSAG); setMode(STATE_POCSAG);
} else { } else {
DEBUG2("Received invalid POCSAG data", err); DEBUG2("Received invalid POCSAG data", err);
sendNAK(type, err); sendNAK(err);
} }
break; break;
#endif #endif
@@ -1233,7 +1321,20 @@ void CSerialPort::processMessage(uint8_t type, const uint8_t* buffer, uint16_t l
setMode(STATE_FM); setMode(STATE_FM);
} else { } else {
DEBUG2("Received invalid FM data", err); DEBUG2("Received invalid FM data", err);
sendNAK(type, err); sendNAK(err);
}
break;
#endif
#if defined(MODE_AX25)
case MMDVM_AX25_DATA:
if (m_ax25Enable) {
if (m_modemState == STATE_IDLE || m_modemState == STATE_FM)
err = ax25TX.writeData(buffer, length);
}
if (err != 0U) {
DEBUG2("Received invalid AX.25 data", err);
sendNAK(err);
} }
break; break;
#endif #endif
@@ -1244,20 +1345,16 @@ void CSerialPort::processMessage(uint8_t type, const uint8_t* buffer, uint16_t l
break; break;
#if defined(SERIAL_REPEATER) #if defined(SERIAL_REPEATER)
case MMDVM_SERIAL_DATA: case MMDVM_SERIAL_DATA: {
writeInt(3U, buffer, length); for (uint16_t i = 0U; i < length; i++)
break; m_serialData.put(buffer[i]);
#endif }
#if defined(I2C_REPEATER)
case MMDVM_I2C_DATA:
writeInt(10U, buffer, length);
break; break;
#endif #endif
default: default:
// Handle this, send a NAK back // Handle this, send a NAK back
sendNAK(type, 1U); sendNAK(1U);
break; break;
} }
@@ -1537,6 +1634,94 @@ void CSerialPort::writeNXDNLost()
} }
#endif #endif
#if defined(MODE_M17)
void CSerialPort::writeM17LinkSetup(const uint8_t* data, uint8_t length)
{
if (m_modemState != STATE_M17 && m_modemState != STATE_IDLE)
return;
if (!m_m17Enable)
return;
uint8_t reply[130U];
reply[0U] = MMDVM_FRAME_START;
reply[1U] = 0U;
reply[2U] = MMDVM_M17_LINK_SETUP;
uint8_t count = 3U;
for (uint8_t i = 0U; i < length; i++, count++)
reply[count] = data[i];
reply[1U] = count;
writeInt(1U, reply, count);
}
void CSerialPort::writeM17Stream(const uint8_t* data, uint8_t length)
{
if (m_modemState != STATE_M17 && m_modemState != STATE_IDLE)
return;
if (!m_m17Enable)
return;
uint8_t reply[130U];
reply[0U] = MMDVM_FRAME_START;
reply[1U] = 0U;
reply[2U] = MMDVM_M17_STREAM;
uint8_t count = 3U;
for (uint8_t i = 0U; i < length; i++, count++)
reply[count] = data[i];
reply[1U] = count;
writeInt(1U, reply, count);
}
void CSerialPort::writeM17Packet(const uint8_t* data, uint8_t length)
{
if (m_modemState != STATE_M17 && m_modemState != STATE_IDLE)
return;
if (!m_m17Enable)
return;
uint8_t reply[130U];
reply[0U] = MMDVM_FRAME_START;
reply[1U] = 0U;
reply[2U] = MMDVM_M17_PACKET;
uint8_t count = 3U;
for (uint8_t i = 0U; i < length; i++, count++)
reply[count] = data[i];
reply[1U] = count;
writeInt(1U, reply, count);
}
void CSerialPort::writeM17Lost()
{
if (m_modemState != STATE_M17 && m_modemState != STATE_IDLE)
return;
if (!m_m17Enable)
return;
uint8_t reply[3U];
reply[0U] = MMDVM_FRAME_START;
reply[1U] = 3U;
reply[2U] = MMDVM_M17_LOST;
writeInt(1U, reply, 3);
}
#endif
#if defined(MODE_FM) #if defined(MODE_FM)
void CSerialPort::writeFMData(const uint8_t* data, uint16_t length) void CSerialPort::writeFMData(const uint8_t* data, uint16_t length)
{ {
@@ -1555,7 +1740,7 @@ void CSerialPort::writeFMData(const uint8_t* data, uint16_t length)
reply[2U] = (length + 4U) - 255U; reply[2U] = (length + 4U) - 255U;
reply[3U] = MMDVM_FM_DATA; reply[3U] = MMDVM_FM_DATA;
for (uint16_t i = 0U; i < length; i++) for (uint8_t i = 0U; i < length; i++)
reply[i + 4U] = data[i]; reply[i + 4U] = data[i];
writeInt(1U, reply, length + 4U); writeInt(1U, reply, length + 4U);
@@ -1563,7 +1748,7 @@ void CSerialPort::writeFMData(const uint8_t* data, uint16_t length)
reply[1U] = length + 3U; reply[1U] = length + 3U;
reply[2U] = MMDVM_FM_DATA; reply[2U] = MMDVM_FM_DATA;
for (uint16_t i = 0U; i < length; i++) for (uint8_t i = 0U; i < length; i++)
reply[i + 3U] = data[i]; reply[i + 3U] = data[i];
writeInt(1U, reply, length + 3U); writeInt(1U, reply, length + 3U);
@@ -1588,25 +1773,6 @@ void CSerialPort::writeFMStatus(uint8_t status)
writeInt(1U, reply, 4U); writeInt(1U, reply, 4U);
} }
void CSerialPort::writeFMRSSI(uint16_t rssi)
{
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] = 5U;
reply[2U] = MMDVM_FM_RSSI;
reply[3U] = (rssi >> 8) & 0xFFU;
reply[4U] = (rssi >> 0) & 0xFFU;
writeInt(1U, reply, 5U);
}
void CSerialPort::writeFMEOT() void CSerialPort::writeFMEOT()
{ {
if (m_modemState != STATE_FM && m_modemState != STATE_IDLE) if (m_modemState != STATE_FM && m_modemState != STATE_IDLE)
@@ -1625,6 +1791,40 @@ void CSerialPort::writeFMEOT()
} }
#endif #endif
#if defined(MODE_AX25)
void CSerialPort::writeAX25Data(const uint8_t* data, uint16_t length)
{
if (m_modemState != STATE_FM && m_modemState != STATE_IDLE)
return;
if (!m_ax25Enable)
return;
uint8_t reply[512U];
reply[0U] = MMDVM_FRAME_START;
if (length > 252U) {
reply[1U] = 0U;
reply[2U] = (length + 4U) - 255U;
reply[3U] = MMDVM_AX25_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_AX25_DATA;
for (uint8_t i = 0U; i < length; i++)
reply[i + 3U] = data[i];
writeInt(1U, reply, length + 3U);
}
}
#endif
#if defined(SERIAL_REPEATER) #if defined(SERIAL_REPEATER)
void CSerialPort::writeSerialData(const uint8_t* data, uint8_t length) void CSerialPort::writeSerialData(const uint8_t* data, uint8_t length)
{ {
@@ -1644,25 +1844,6 @@ void CSerialPort::writeSerialData(const uint8_t* data, uint8_t length)
} }
#endif #endif
#if defined(I2C_REPEATER)
void CSerialPort::writeI2CData(const uint8_t* data, uint8_t length)
{
uint8_t reply[255U];
reply[0U] = MMDVM_FRAME_START;
reply[1U] = 0U;
reply[2U] = MMDVM_I2C_DATA;
uint8_t count = 3U;
for (uint8_t i = 0U; i < length; i++, count++)
reply[count] = data[i];
reply[1U] = count;
writeInt(1U, reply, count);
}
#endif
void CSerialPort::writeCalData(const uint8_t* data, uint8_t length) void CSerialPort::writeCalData(const uint8_t* data, uint8_t length)
{ {
if (m_modemState != STATE_DSTARCAL) if (m_modemState != STATE_DSTARCAL)
@@ -1835,6 +2016,9 @@ void CSerialPort::writeDebug(const char* text, int16_t n1, int16_t n2, int16_t n
void CSerialPort::writeDebugDump(const uint8_t* data, uint16_t length) void CSerialPort::writeDebugDump(const uint8_t* data, uint16_t length)
{ {
if (length > 500U)
length = 500U;
uint8_t reply[512U]; uint8_t reply[512U];
reply[0U] = MMDVM_FRAME_START; reply[0U] = MMDVM_FRAME_START;
@@ -1844,7 +2028,7 @@ void CSerialPort::writeDebugDump(const uint8_t* data, uint16_t length)
reply[2U] = (length + 4U) - 255U; reply[2U] = (length + 4U) - 255U;
reply[3U] = MMDVM_DEBUG_DUMP; reply[3U] = MMDVM_DEBUG_DUMP;
for (uint16_t i = 0U; i < length; i++) for (uint8_t i = 0U; i < length; i++)
reply[i + 4U] = data[i]; reply[i + 4U] = data[i];
writeInt(1U, reply, length + 4U); writeInt(1U, reply, length + 4U);
@@ -1852,9 +2036,10 @@ void CSerialPort::writeDebugDump(const uint8_t* data, uint16_t length)
reply[1U] = length + 3U; reply[1U] = length + 3U;
reply[2U] = MMDVM_DEBUG_DUMP; reply[2U] = MMDVM_DEBUG_DUMP;
for (uint16_t i = 0U; i < length; i++) for (uint8_t i = 0U; i < length; i++)
reply[i + 3U] = data[i]; reply[i + 3U] = data[i];
writeInt(1U, reply, length + 3U); writeInt(1U, reply, length + 3U);
} }
} }
+15 -9
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2015,2016,2017,2018,2020,2021,2023,2025 by Jonathan Naylor G4KLX * Copyright (C) 2015,2016,2017,2018,2020,2021 by Jonathan Naylor G4KLX
* *
* 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
@@ -64,10 +64,20 @@ public:
void writeNXDNLost(); void writeNXDNLost();
#endif #endif
#if defined(MODE_M17)
void writeM17LinkSetup(const uint8_t* data, uint8_t length);
void writeM17Stream(const uint8_t* data, uint8_t length);
void writeM17Packet(const uint8_t* data, uint8_t length);
void writeM17Lost();
#endif
#if defined(MODE_AX25)
void writeAX25Data(const uint8_t* data, uint16_t length);
#endif
#if defined(MODE_FM) #if defined(MODE_FM)
void writeFMData(const uint8_t* data, uint16_t length); void writeFMData(const uint8_t* data, uint16_t length);
void writeFMStatus(uint8_t status); void writeFMStatus(uint8_t status);
void writeFMRSSI(uint16_t rssi);
void writeFMEOT(); void writeFMEOT();
#endif #endif
@@ -75,10 +85,6 @@ public:
void writeSerialData(const uint8_t* data, uint8_t length); void writeSerialData(const uint8_t* data, uint8_t length);
#endif #endif
#if defined(I2C_REPEATER)
void writeI2CData(const uint8_t* data, uint8_t length);
#endif
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);
@@ -94,11 +100,12 @@ private:
uint16_t m_ptr; uint16_t m_ptr;
uint16_t m_len; uint16_t m_len;
bool m_debug; bool m_debug;
CRingBuffer<uint8_t> m_serialData;
int m_lastSerialAvail; int m_lastSerialAvail;
uint16_t m_lastSerialAvailCount; uint16_t m_lastSerialAvailCount;
void sendACK(uint8_t type); void sendACK();
void sendNAK(uint8_t type, uint8_t err); void sendNAK(uint8_t err);
void getStatus(); void getStatus();
void getVersion(); void getVersion();
uint8_t setConfig(const uint8_t* data, uint16_t length); uint8_t setConfig(const uint8_t* data, uint16_t length);
@@ -122,4 +129,3 @@ private:
}; };
#endif #endif
+1 -1
View File
@@ -332,7 +332,7 @@ int CSerialPort::availableForReadInt(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 m_USART3.available();//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(STM32F7_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(STM32F7_DVM) || defined(STM32F4_EDA_405) || defined(STM32F4_EDA_446)
return m_USART1.available();//AvailUSART1(); return m_USART1.available();//AvailUSART1();
#elif defined(STM32F4_NUCLEO) || defined(STM32F4_RPT_HAT_TGO) #elif defined(STM32F4_NUCLEO) || defined(STM32F4_RPT_HAT_TGO)
+170
View File
@@ -0,0 +1,170 @@
/*
* Copyright (C) 2017 by Wojciech Krutnik N0CALL
*
* 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 "RingBuff.h"
#include "SerialPort.h"
/*
Pin definitions (configuration in IOSTM_CMSIS.c):
- Host communication:
USART1 - TXD PA9 - RXD PA10
*/
#if defined(STM32F1)
// BaudRate calculator macro
// source: STM32 HAL Library (stm32f1xx_hal_usart.h)
#define USART_DIV(__PCLK__, __BAUD__) (((__PCLK__)*25)/(4*(__BAUD__)))
#define USART_DIVMANT(__PCLK__, __BAUD__) (USART_DIV((__PCLK__), (__BAUD__))/100)
#define USART_DIVFRAQ(__PCLK__, __BAUD__) (((USART_DIV((__PCLK__), (__BAUD__)) - (USART_DIVMANT((__PCLK__), (__BAUD__)) * 100)) * 16 + 50) / 100)
#define USART_BRR(__PCLK__, __BAUD__) ((USART_DIVMANT((__PCLK__), (__BAUD__)) << 4)|(USART_DIVFRAQ((__PCLK__), (__BAUD__)) & 0x0F))
#define USART_BUFFER_SIZE 256U
DECLARE_RINGBUFFER_TYPE(USARTBuffer, USART_BUFFER_SIZE);
/* ************* USART1 ***************** */
static volatile USARTBuffer_t txBuffer1={.size=USART_BUFFER_SIZE};
static volatile USARTBuffer_t rxBuffer1={.size=USART_BUFFER_SIZE};
extern "C" {
bitband_t txe = (bitband_t)BITBAND_PERIPH(&USART1->SR, USART_SR_TXE_Pos);
bitband_t rxne = (bitband_t)BITBAND_PERIPH(&USART1->SR, USART_SR_RXNE_Pos);
bitband_t txeie = (bitband_t)BITBAND_PERIPH(&USART1->CR1, USART_CR1_TXEIE_Pos);
RAMFUNC void USART1_IRQHandler()
{
/* Transmitting data */
if(*txe){
if(!(RINGBUFF_EMPTY(txBuffer1))){
USART1->DR = RINGBUFF_READ(txBuffer1);
}else{ /* Buffer empty */
*txeie = 0; /* Don't send further data */
}
}
/* Receiving data */
if(*rxne){
RINGBUFF_WRITE(rxBuffer1, USART1->DR);
}
}
}
void USART1Init(int speed)
{
RCC->APB2ENR |= RCC_APB2ENR_USART1EN;
USART1->BRR = USART_BRR(72000000UL, speed);
USART1->CR1 = USART_CR1_UE | USART_CR1_TE |
USART_CR1_RE | USART_CR1_RXNEIE; // Enable USART and RX interrupt
NVIC_EnableIRQ(USART1_IRQn);
}
RAMFUNC void USART1TxData(const uint8_t* data, uint16_t length)
{
NVIC_DisableIRQ(USART1_IRQn);
/* Check remaining space in buffer */
if(RINGBUFF_COUNT(txBuffer1) + length > RINGBUFF_SIZE(txBuffer1)){
NVIC_EnableIRQ(USART1_IRQn);
return;
}
/* Append data to buffer */
while(length--){
RINGBUFF_WRITE(txBuffer1, *(data++));
}
/* Start sending data */
USART1->CR1 |= USART_CR1_TXEIE;
NVIC_EnableIRQ(USART1_IRQn);
}
/////////////////////////////////////////////////////////////////
void CSerialPort::beginInt(uint8_t n, int speed)
{
switch (n) {
case 1U:
USART1Init(speed);
break;
default:
break;
}
}
int CSerialPort::availableForReadInt(uint8_t n)
{
switch (n) {
case 1U:
return !RINGBUFF_EMPTY(rxBuffer1);
default:
return false;
}
}
int CSerialPort::availableForWriteInt(uint8_t n)
{
switch (n) {
case 1U:
return !RINGBUFF_FULL(txBuffer1);
default:
return false;
}
}
uint8_t CSerialPort::readInt(uint8_t n)
{
switch (n) {
case 1U:
return RINGBUFF_READ(rxBuffer1);
default:
return 0U;
}
}
void CSerialPort::writeInt(uint8_t n, const uint8_t* data, uint16_t length, bool flush)
{
bitband_t tc = (bitband_t)BITBAND_PERIPH(&USART1->SR, USART_SR_TC_Pos);
switch (n) {
case 1U:
USART1TxData(data, length);
*tc = 0;
if (flush) {
while (!RINGBUFF_EMPTY(txBuffer1) || !tc)
;
}
break;
default:
break;
}
}
#endif
-2
View File
@@ -1,6 +1,4 @@
/* /*
* Copyright (C) 2017 by Chris Huitema
*
* 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
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
+3
View File
@@ -23,6 +23,9 @@
#include "stm32f4xx.h" #include "stm32f4xx.h"
#elif defined(STM32F7XX) #elif defined(STM32F7XX)
#include "stm32f7xx.h" #include "stm32f7xx.h"
#elif defined(STM32F105xC)
#include "stm32f1xx.h"
#include <cstddef>
#else #else
#include <Arduino.h> #include <Arduino.h>
#endif #endif
+2 -2
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2020,2021,2022,2023,2025,2026 by Jonathan Naylor G4KLX * Copyright (C) 2020,2021 by Jonathan Naylor G4KLX
* *
* 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
@@ -19,6 +19,6 @@
#if !defined(VERSION_H) #if !defined(VERSION_H)
#define VERSION_H #define VERSION_H
#define VERSION "20260424" #define VERSION "20210508"
#endif #endif
+2 -2
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2009-2017,2020,2024 by Jonathan Naylor G4KLX * Copyright (C) 2009-2017,2020 by Jonathan Naylor G4KLX
* *
* 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
@@ -39,7 +39,7 @@ const uint8_t NOAVEPTR = 99U;
const uint16_t NOENDPTR = 9999U; const uint16_t NOENDPTR = 9999U;
const unsigned int MAX_SYNC_FRAMES = 4U + 1U; const unsigned int MAX_SYNC_FRAMES = 1U + 1U;
CYSFRX::CYSFRX() : CYSFRX::CYSFRX() :
m_state(YSFRXS_NONE), m_state(YSFRXS_NONE),
+1 -1
View File
@@ -166,7 +166,7 @@ void CYSFTX::writeByte(uint8_t c)
void CYSFTX::writeSilence() void CYSFTX::writeSilence()
{ {
q15_t inBuffer[4U] = {0, 0, 0, 0}; q15_t inBuffer[4U] = {0x00U, 0x00U, 0x00U, 0x00U};
q15_t outBuffer[YSF_RADIO_SYMBOL_LENGTH * 4U]; q15_t outBuffer[YSF_RADIO_SYMBOL_LENGTH * 4U];
::arm_fir_interpolate_q15(&m_modFilter, inBuffer, outBuffer, 4U); ::arm_fir_interpolate_q15(&m_modFilter, inBuffer, outBuffer, 4U);
+4 -4
View File
@@ -33,7 +33,7 @@ DSTAR PB6 output
DMR PB5 output DMR PB5 output
YSF PB7 output YSF PB7 output
POCSAG PC10 output POCSAG PC10 output
FM PB14 output FM PC11 output
RX PB0 analog input RX PB0 analog input
RSSI PB1 analog input RSSI PB1 analog input
@@ -83,9 +83,9 @@ EXT_CLK PA15 input
#define PORT_POCSAG GPIOC #define PORT_POCSAG GPIOC
#define RCC_Per_POCSAG RCC_AHB1Periph_GPIOC #define RCC_Per_POCSAG RCC_AHB1Periph_GPIOC
#define PIN_FM GPIO_Pin_14 #define PIN_FM GPIO_Pin_11
#define PORT_FM GPIOB #define PORT_FM GPIOC
#define RCC_Per_FM RCC_AHB1Periph_GPIOB #define RCC_Per_FM RCC_AHB1Periph_GPIOC
#define PIN_EXT_CLK GPIO_Pin_15 #define PIN_EXT_CLK GPIO_Pin_15
#define SRC_EXT_CLK GPIO_PinSource15 #define SRC_EXT_CLK GPIO_PinSource15
+2 -2
View File
@@ -20,7 +20,7 @@
#define _PINS_F7_STM32DVM_V5_H #define _PINS_F7_STM32DVM_V5_H
/* /*
Pin definitions for STM32F7 STM32-DVM rev 5 Board: Pin definitions for STM32F4 STM32-DVM rev 5 Board:
COS PB13 input COS PB13 input
PTT PB12 output PTT PB12 output
@@ -33,7 +33,6 @@ DSTAR PB6 output
DMR PB5 output DMR PB5 output
YSF PB7 output YSF PB7 output
POCSAG PC10 output (Not Valid) POCSAG PC10 output (Not Valid)
FM PB14 output
RX PB0 analog input RX PB0 analog input
RSSI PB1 analog input RSSI PB1 analog input
@@ -46,6 +45,7 @@ EXT_CLK PA15 input
#define PORT_COS GPIOB #define PORT_COS GPIOB
#define RCC_Per_COS RCC_AHB1Periph_GPIOB #define RCC_Per_COS RCC_AHB1Periph_GPIOB
#define PIN_PTT GPIO_Pin_12 #define PIN_PTT GPIO_Pin_12
#define PORT_PTT GPIOB #define PORT_PTT GPIOB
#define RCC_Per_PTT RCC_AHB1Periph_GPIOB #define RCC_Per_PTT RCC_AHB1Periph_GPIOB
+187
View File
@@ -0,0 +1,187 @@
/* Linker script to configure memory regions.
* STM32F105RB
*/
MEMORY
{
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 128K
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 64K
}
/* Linker script to place sections and symbol values. Should be used together
* with other linker script that defines memory regions FLASH and RAM.
* It references following symbols, which must be defined in code:
* Reset_Handler : Entry of reset handler
*
* It defines following symbols, which code can use without definition:
* __exidx_start
* __exidx_end
* __copy_table_start__
* __copy_table_end__
* __zero_table_start__
* __zero_table_end__
* __etext
* __data_start__
* __preinit_array_start
* __preinit_array_end
* __init_array_start
* __init_array_end
* __fini_array_start
* __fini_array_end
* __data_end__
* __bss_start__
* __bss_end__
* __end__
* end
* __HeapLimit
* __StackLimit
* __StackTop
* __stack
*/
ENTRY(Reset_Handler)
SECTIONS
{
.text :
{
KEEP(*(.isr_vector))
*(.text*)
KEEP(*(.init))
KEEP(*(.fini))
/* .ctors */
*crtbegin.o(.ctors)
*crtbegin?.o(.ctors)
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
*(SORT(.ctors.*))
*(.ctors)
/* .dtors */
*crtbegin.o(.dtors)
*crtbegin?.o(.dtors)
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
*(SORT(.dtors.*))
*(.dtors)
*(.rodata*)
KEEP(*(.eh_frame*))
} > FLASH
.ARM.extab :
{
*(.ARM.extab* .gnu.linkonce.armextab.*)
} > FLASH
__exidx_start = .;
.ARM.exidx :
{
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
} > FLASH
__exidx_end = .;
/* To copy multiple ROM to RAM sections,
* uncomment .copy.table section and,
* define __STARTUP_COPY_MULTIPLE in startup_ARMCMx.S */
/*
.copy.table :
{
. = ALIGN(4);
__copy_table_start__ = .;
LONG (__etext)
LONG (__data_start__)
LONG (__data_end__ - __data_start__)
LONG (__etext2)
LONG (__data2_start__)
LONG (__data2_end__ - __data2_start__)
__copy_table_end__ = .;
} > FLASH
*/
/* To clear multiple BSS sections,
* uncomment .zero.table section and,
* define __STARTUP_CLEAR_BSS_MULTIPLE in startup_ARMCMx.S */
/*
.zero.table :
{
. = ALIGN(4);
__zero_table_start__ = .;
LONG (__bss_start__)
LONG (__bss_end__ - __bss_start__)
LONG (__bss2_start__)
LONG (__bss2_end__ - __bss2_start__)
__zero_table_end__ = .;
} > FLASH
*/
__etext = .;
.data : AT (__etext)
{
__data_start__ = .;
*(vtable)
*(.data*)
. = ALIGN(4);
/* preinit data */
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP(*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
. = ALIGN(4);
/* init data */
PROVIDE_HIDDEN (__init_array_start = .);
KEEP(*(SORT(.init_array.*)))
KEEP(*(.init_array))
PROVIDE_HIDDEN (__init_array_end = .);
. = ALIGN(4);
/* finit data */
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP(*(SORT(.fini_array.*)))
KEEP(*(.fini_array))
PROVIDE_HIDDEN (__fini_array_end = .);
KEEP(*(.jcr*))
. = ALIGN(4);
/* All data end */
__data_end__ = .;
} > RAM
.bss :
{
. = ALIGN(4);
__bss_start__ = .;
*(.bss*)
*(COMMON)
. = ALIGN(4);
__bss_end__ = .;
} > RAM
.heap (COPY):
{
__end__ = .;
PROVIDE(end = .);
*(.heap*)
__HeapLimit = .;
} > RAM
/* .stack_dummy section doesn't contains any symbols. It is only
* used for linker to calculate size of stack sections, and assign
* values to stack symbols later */
.stack_dummy (COPY):
{
*(.stack*)
} > RAM
/* Set stack top to end of RAM, and stack limit move down by
* size of stack_dummy section */
__StackTop = ORIGIN(RAM) + LENGTH(RAM);
__StackLimit = __StackTop - SIZEOF(.stack_dummy);
PROVIDE(__stack = __StackTop);
/* Check if data + heap + stack exceeds RAM limit */
ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
}
+427
View File
@@ -0,0 +1,427 @@
/* File: startup_ARMCM3.S
* Purpose: startup file for Cortex-M3 devices. Should use with
* GCC for ARM Embedded Processors
* Version: V2.0
* Date: 16 August 2013
*/
/* Copyright (c) 2011 - 2013 ARM LIMITED
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name of ARM nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
*
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------*/
#if defined(STM32F105xC)
.syntax unified
.arch armv7-m
.section .stack
.align 3
#ifdef __STACK_SIZE
.equ Stack_Size, __STACK_SIZE
#else
.equ Stack_Size, 0xc00
#endif
.globl __StackTop
.globl __StackLimit
__StackLimit:
.space Stack_Size
.size __StackLimit, . - __StackLimit
__StackTop:
.size __StackTop, . - __StackTop
.section .heap
.align 3
#ifdef __HEAP_SIZE
.equ Heap_Size, __HEAP_SIZE
#else
.equ Heap_Size, 0
#endif
.globl __HeapBase
.globl __HeapLimit
__HeapBase:
.if Heap_Size
.space Heap_Size
.endif
.size __HeapBase, . - __HeapBase
__HeapLimit:
.size __HeapLimit, . - __HeapLimit
.equ BootRAM, 0xF1E0F85F
.section .isr_vector
.align 2
.globl __isr_vector
__isr_vector:
.long __StackTop /* Top of Stack */
.long Reset_Handler /* Reset Handler */
.long NMI_Handler /* NMI Handler */
.long HardFault_Handler /* Hard Fault Handler */
.long MemManage_Handler /* MPU Fault Handler */
.long BusFault_Handler /* Bus Fault Handler */
.long UsageFault_Handler /* Usage Fault Handler */
.long 0 /* Reserved */
.long 0 /* Reserved */
.long 0 /* Reserved */
.long 0 /* Reserved */
.long SVC_Handler /* SVCall Handler */
.long DebugMon_Handler /* Debug Monitor Handler */
.long 0 /* Reserved */
.long PendSV_Handler /* PendSV Handler */
.long SysTick_Handler /* SysTick Handler */
/* External interrupts */
.long WWDG_IRQHandler
.long PVD_IRQHandler
.long TAMPER_IRQHandler
.long RTC_IRQHandler
.long FLASH_IRQHandler
.long RCC_IRQHandler
.long EXTI0_IRQHandler
.long EXTI1_IRQHandler
.long EXTI2_IRQHandler
.long EXTI3_IRQHandler
.long EXTI4_IRQHandler
.long DMA1_Channel1_IRQHandler
.long DMA1_Channel2_IRQHandler
.long DMA1_Channel3_IRQHandler
.long DMA1_Channel4_IRQHandler
.long DMA1_Channel5_IRQHandler
.long DMA1_Channel6_IRQHandler
.long DMA1_Channel7_IRQHandler
.long ADC1_2_IRQHandler
.long CAN1_TX_IRQHandler
.long CAN1_RX0_IRQHandler
.long CAN1_RX1_IRQHandler
.long CAN1_SCE_IRQHandler
.long EXTI9_5_IRQHandler
.long TIM1_BRK_IRQHandler
.long TIM1_UP_IRQHandler
.long TIM1_TRG_COM_IRQHandler
.long TIM1_CC_IRQHandler
.long TIM2_IRQHandler
.long TIM3_IRQHandler
.long TIM4_IRQHandler
.long I2C1_EV_IRQHandler
.long I2C1_ER_IRQHandler
.long I2C2_EV_IRQHandler
.long I2C2_ER_IRQHandler
.long SPI1_IRQHandler
.long SPI2_IRQHandler
.long USART1_IRQHandler
.long USART2_IRQHandler
.long USART3_IRQHandler
.long EXTI15_10_IRQHandler
.long RTC_Alarm_IRQHandler
.long OTG_FS_WKUP_IRQHandler
.long 0
.long 0
.long 0
.long 0
.long 0
.long 0
.long 0
.long TIM5_IRQHandler
.long SPI3_IRQHandler
.long UART4_IRQHandler
.long UART5_IRQHandler
.long TIM6_IRQHandler
.long TIM7_IRQHandler
.long DMA2_Channel1_IRQHandler
.long DMA2_Channel2_IRQHandler
.long DMA2_Channel3_IRQHandler
.long DMA2_Channel4_IRQHandler
.long DMA2_Channel5_IRQHandler
.long 0
.long 0
.long CAN2_TX_IRQHandler
.long CAN2_RX0_IRQHandler
.long CAN2_RX1_IRQHandler
.long CAN2_SCE_IRQHandler
.long OTG_FS_IRQHandler
.long 0
.long 0
.long 0
.long 0
.long 0
.long 0
.long 0
.long 0
.long 0
.long 0
.long 0
.long 0
.long 0
.long 0
.long 0
.long 0
.long 0
.long 0
.long 0
.long 0
.long 0
.long 0
.long 0
.long 0
.long 0
.long 0
.long 0
.long 0
.long 0
.long 0
.long 0
.long 0
.long 0
.long 0
.long 0
.long 0
.long BootRAM /* @0x1E0. This is for boot in RAM mode for
STM32F10x Connectivity line Devices. */
.size __isr_vector, . - __isr_vector
.text
.thumb
.thumb_func
.align 2
.globl Reset_Handler
.type Reset_Handler, %function
Reset_Handler:
/* Firstly it copies data from read only memory to RAM. There are two schemes
* to copy. One can copy more than one sections. Another can only copy
* one section. The former scheme needs more instructions and read-only
* data to implement than the latter.
* Macro __STARTUP_COPY_MULTIPLE is used to choose between two schemes. */
#ifdef __STARTUP_COPY_MULTIPLE
/* Multiple sections scheme.
*
* Between symbol address __copy_table_start__ and __copy_table_end__,
* there are array of triplets, each of which specify:
* offset 0: LMA of start of a section to copy from
* offset 4: VMA of start of a section to copy to
* offset 8: size of the section to copy. Must be multiply of 4
*
* All addresses must be aligned to 4 bytes boundary.
*/
ldr r4, =__copy_table_start__
ldr r5, =__copy_table_end__
.L_loop0:
cmp r4, r5
bge .L_loop0_done
ldr r1, [r4]
ldr r2, [r4, #4]
ldr r3, [r4, #8]
.L_loop0_0:
subs r3, #4
ittt ge
ldrge r0, [r1, r3]
strge r0, [r2, r3]
bge .L_loop0_0
adds r4, #12
b .L_loop0
.L_loop0_done:
#else
/* Single section scheme.
*
* The ranges of copy from/to are specified by following symbols
* __etext: LMA of start of the section to copy from. Usually end of text
* __data_start__: VMA of start of the section to copy to
* __data_end__: VMA of end of the section to copy to
*
* All addresses must be aligned to 4 bytes boundary.
*/
ldr r1, =__etext
ldr r2, =__data_start__
ldr r3, =__data_end__
.L_loop1:
cmp r2, r3
ittt lt
ldrlt r0, [r1], #4
strlt r0, [r2], #4
blt .L_loop1
#endif /*__STARTUP_COPY_MULTIPLE */
/* This part of work usually is done in C library startup code. Otherwise,
* define this macro to enable it in this startup.
*
* There are two schemes too. One can clear multiple BSS sections. Another
* can only clear one section. The former is more size expensive than the
* latter.
*
* Define macro __STARTUP_CLEAR_BSS_MULTIPLE to choose the former.
* Otherwise efine macro __STARTUP_CLEAR_BSS to choose the later.
*/
#ifdef __STARTUP_CLEAR_BSS_MULTIPLE
/* Multiple sections scheme.
*
* Between symbol address __copy_table_start__ and __copy_table_end__,
* there are array of tuples specifying:
* offset 0: Start of a BSS section
* offset 4: Size of this BSS section. Must be multiply of 4
*/
ldr r3, =__zero_table_start__
ldr r4, =__zero_table_end__
.L_loop2:
cmp r3, r4
bge .L_loop2_done
ldr r1, [r3]
ldr r2, [r3, #4]
movs r0, 0
.L_loop2_0:
subs r2, #4
itt ge
strge r0, [r1, r2]
bge .L_loop2_0
adds r3, #8
b .L_loop2
.L_loop2_done:
#elif defined (__STARTUP_CLEAR_BSS)
/* Single BSS section scheme.
*
* The BSS section is specified by following symbols
* __bss_start__: start of the BSS section.
* __bss_end__: end of the BSS section.
*
* Both addresses must be aligned to 4 bytes boundary.
*/
ldr r1, =__bss_start__
ldr r2, =__bss_end__
movs r0, 0
.L_loop3:
cmp r1, r2
itt lt
strlt r0, [r1], #4
blt .L_loop3
#endif /* __STARTUP_CLEAR_BSS_MULTIPLE || __STARTUP_CLEAR_BSS */
#ifndef __NO_SYSTEM_INIT
bl SystemInit
#endif
#ifndef __START
#define __START _start
#endif
bl __START
.pool
.size Reset_Handler, . - Reset_Handler
.align 1
.thumb_func
.weak Default_Handler
.type Default_Handler, %function
Default_Handler:
b .
.size Default_Handler, . - Default_Handler
/* Macro to define default handlers. Default handler
* will be weak symbol and just dead loops. They can be
* overwritten by other handlers */
.macro def_irq_handler handler_name
.weak \handler_name
.set \handler_name, Default_Handler
.endm
def_irq_handler NMI_Handler
def_irq_handler HardFault_Handler
def_irq_handler MemManage_Handler
def_irq_handler BusFault_Handler
def_irq_handler UsageFault_Handler
def_irq_handler SVC_Handler
def_irq_handler DebugMon_Handler
def_irq_handler PendSV_Handler
def_irq_handler SysTick_Handler
def_irq_handler WWDG_IRQHandler
def_irq_handler PVD_IRQHandler
def_irq_handler TAMPER_IRQHandler
def_irq_handler RTC_IRQHandler
def_irq_handler FLASH_IRQHandler
def_irq_handler RCC_IRQHandler
def_irq_handler EXTI0_IRQHandler
def_irq_handler EXTI1_IRQHandler
def_irq_handler EXTI2_IRQHandler
def_irq_handler EXTI3_IRQHandler
def_irq_handler EXTI4_IRQHandler
def_irq_handler DMA1_Channel1_IRQHandler
def_irq_handler DMA1_Channel2_IRQHandler
def_irq_handler DMA1_Channel3_IRQHandler
def_irq_handler DMA1_Channel4_IRQHandler
def_irq_handler DMA1_Channel5_IRQHandler
def_irq_handler DMA1_Channel6_IRQHandler
def_irq_handler DMA1_Channel7_IRQHandler
def_irq_handler ADC1_2_IRQHandler
def_irq_handler CAN1_TX_IRQHandler
def_irq_handler CAN1_RX0_IRQHandler
def_irq_handler CAN1_RX1_IRQHandler
def_irq_handler CAN1_SCE_IRQHandler
def_irq_handler EXTI9_5_IRQHandler
def_irq_handler TIM1_BRK_IRQHandler
def_irq_handler TIM1_UP_IRQHandler
def_irq_handler TIM1_TRG_COM_IRQHandler
def_irq_handler TIM1_CC_IRQHandler
def_irq_handler TIM2_IRQHandler
def_irq_handler TIM3_IRQHandler
def_irq_handler TIM4_IRQHandler
def_irq_handler I2C1_EV_IRQHandler
def_irq_handler I2C1_ER_IRQHandler
def_irq_handler I2C2_EV_IRQHandler
def_irq_handler I2C2_ER_IRQHandler
def_irq_handler SPI1_IRQHandler
def_irq_handler SPI2_IRQHandler
def_irq_handler USART1_IRQHandler
def_irq_handler USART2_IRQHandler
def_irq_handler USART3_IRQHandler
def_irq_handler EXTI15_10_IRQHandler
def_irq_handler RTC_Alarm_IRQHandler
def_irq_handler OTG_FS_WKUP_IRQHandler
def_irq_handler TIM5_IRQHandler
def_irq_handler SPI3_IRQHandler
def_irq_handler UART4_IRQHandler
def_irq_handler UART5_IRQHandler
def_irq_handler TIM6_IRQHandler
def_irq_handler TIM7_IRQHandler
def_irq_handler DMA2_Channel1_IRQHandler
def_irq_handler DMA2_Channel2_IRQHandler
def_irq_handler DMA2_Channel3_IRQHandler
def_irq_handler DMA2_Channel4_IRQHandler
def_irq_handler DMA2_Channel5_IRQHandler
def_irq_handler CAN2_TX_IRQHandler
def_irq_handler CAN2_RX0_IRQHandler
def_irq_handler CAN2_RX1_IRQHandler
def_irq_handler CAN2_SCE_IRQHandler
def_irq_handler OTG_FS_IRQHandler
.end
#endif
+227
View File
@@ -0,0 +1,227 @@
/**
******************************************************************************
* @file system_stm32f1xx.c
* @author MCD Application Team, Wojciech Krutnik
* @version V2.2.2
* @date 26-June-2015
* @brief CMSIS Cortex-M0 Device Peripheral Access Layer System Source File.
*
* 1. This file provides two functions and one global variable to be called from
* user application:
* - SystemInit(): This function is called at startup just after reset and
* before branch to main program. This call is made inside
* the "startup_stm32f1xx.s" file.
*
* - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
* by the user application to setup the SysTick
* timer or configure other parameters.
*
* - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
* be called whenever the core clock is changed
* during program execution.
*
* 2. After each device reset the HSI (8 MHz) is used as system clock source.
* Then SystemInit() function is called, in "startup_stm32f1xx.s" file, to
* configure the system clock before to branch to main program.
*
* 3. This file configures the system clock and flash as follows:
*=============================================================================
* Supported STM32F1xx device
*-----------------------------------------------------------------------------
* System Clock source | PLL
*-----------------------------------------------------------------------------
* SYSCLK | 72MHz
*-----------------------------------------------------------------------------
* HCLK | 72Mhz
*-----------------------------------------------------------------------------
* PCLK1 | 36MHz
*-----------------------------------------------------------------------------
* PCLK2 | 72MHz
*-----------------------------------------------------------------------------
* AHB Prescaler | 1
*-----------------------------------------------------------------------------
* APB1 Prescaler | 2
*-----------------------------------------------------------------------------
* APB2 Prescaler | 1
*-----------------------------------------------------------------------------
* PLLSRC | HSE/1
*-----------------------------------------------------------------------------
* PLLMUL | 9
*-----------------------------------------------------------------------------
* HSE | 8MHz
*-----------------------------------------------------------------------------
* Flash Latency(WS) | 2
*-----------------------------------------------------------------------------
* Prefetch Buffer | ON
*-----------------------------------------------------------------------------
*=============================================================================
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
#if defined(STM32F105xC)
/** @addtogroup CMSIS
* @{
*/
/** @addtogroup stm32f1xx_system
* @{
*/
/** @addtogroup STM32F1xx_System_Private_Includes
* @{
*/
#include "stm32f1xx.h"
/**
* @}
*/
/** @addtogroup STM32F1xx_System_Private_TypesDefinitions
* @{
*/
/**
* @}
*/
/** @addtogroup STM32F1xx_System_Private_Defines
* @{
*/
#if !defined (HSE_VALUE)
#define HSE_VALUE ((uint32_t)8000000) /*!< Default value of the External oscillator in Hz.
This value can be provided and adapted by the user application. */
#endif /* HSE_VALUE */
#if !defined (HSI_VALUE)
#define HSI_VALUE ((uint32_t)8000000) /*!< Default value of the Internal oscillator in Hz.
This value can be provided and adapted by the user application. */
#endif /* HSI_VALUE */
/**
* @}
*/
/** @addtogroup STM32f1xx_System_Private_Macros
* @{
*/
/**
* @}
*/
/** @addtogroup STM32F1xx_System_Private_Variables
* @{
*/
uint32_t SystemCoreClock = 48000000;
/**
* @}
*/
/** @addtogroup STM32F1xx_System_Private_FunctionPrototypes
* @{
*/
static void SetSysClock(void);
/**
* @}
*/
/** @addtogroup STM32F1xx_System_Private_Functions
* @{
*/
/**
* @brief Setup the microcontroller system.
* Initialize the default HSI clock source, vector table location and the PLL configuration is reset.
* @param None
* @retval None
*/
void SystemInit(void)
{
/* Enable Prefetch Buffer, 2 wait states */
FLASH->ACR = FLASH_ACR_PRFTBE | FLASH_ACR_LATENCY_1;
/* Configure the System clock frequency, AHB/APBx prescalers */
SetSysClock();
}
/**
* @brief Configures the System clock frequency and AHB/APBx prescalers
* settings.
* @param None
* @retval None
*/
static void SetSysClock(void)
{
/* Enable HSE and Clock Security System */
RCC->CR |= RCC_CR_CSSON | RCC_CR_HSEON;
/* Wait for HSE startup */
while((RCC->CR & RCC_CR_HSERDY) == 0)
;
/* Enable PLL with 9x multiplier and HSE clock source
* APB1 prescaler /2 */
RCC->CFGR = (RCC->CFGR & (~RCC_CFGR_PLLMULL)) | RCC_CFGR_PLLMULL9
| RCC_CFGR_PLLSRC;
RCC->CR |= RCC_CR_PLLON;
while((RCC->CR & RCC_CR_PLLRDY) == 0)
;
/* HCLK = SYSCLK */
RCC->CFGR = (RCC->CFGR & ~RCC_CFGR_HPRE) | RCC_CFGR_HPRE_DIV1;
/* PCLK1 = HCLK/2; PCLK2 = HCLK */
RCC->CFGR = (RCC->CFGR & ~(RCC_CFGR_PPRE1|RCC_CFGR_PPRE2))
| RCC_CFGR_PPRE1_DIV2;
/* Switch SYSCLK to PLL */
RCC->CFGR |= RCC_CFGR_SW_PLL;
while((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_PLL)
;
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#endif
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/