From 4bcc1e88c41bfbfb79396dbe2f7dc5833fd46bdb Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Mon, 11 May 2020 07:52:27 +0200 Subject: [PATCH 1/9] Update to SAM 1.6.12 --- Makefile.Arduino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile.Arduino b/Makefile.Arduino index 6046810..0afa96a 100644 --- a/Makefile.Arduino +++ b/Makefile.Arduino @@ -1,5 +1,5 @@ #!/usr/bin/make -# makefile for the arduino due (works with arduino IDE 1.6.11) +# makefile for the arduino due (works with arduino IDE 1.6.12) # # The original file can be found at https://github.com/pauldreik/arduino-due-makefile # @@ -34,7 +34,7 @@ OBJCOPY:=$(ADIR)/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-n C:=$(CC) #SAM:=arduino/sam/ -SAM:=$(ADIR)/packages/arduino/hardware/sam/1.6.11 +SAM:=$(ADIR)/packages/arduino/hardware/sam/1.6.12 #CMSIS:=arduino/sam/system/CMSIS/ #LIBSAM:=arduino/sam/system/libsam TMPDIR:=$(PWD)/build From 8cbd52aa726c43e5248d13ced9c05e0928cb5c26 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Mon, 11 May 2020 07:52:27 +0200 Subject: [PATCH 2/9] Update to SAM 1.6.12 --- Makefile.Arduino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile.Arduino b/Makefile.Arduino index 6046810..0afa96a 100644 --- a/Makefile.Arduino +++ b/Makefile.Arduino @@ -1,5 +1,5 @@ #!/usr/bin/make -# makefile for the arduino due (works with arduino IDE 1.6.11) +# makefile for the arduino due (works with arduino IDE 1.6.12) # # The original file can be found at https://github.com/pauldreik/arduino-due-makefile # @@ -34,7 +34,7 @@ OBJCOPY:=$(ADIR)/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-n C:=$(CC) #SAM:=arduino/sam/ -SAM:=$(ADIR)/packages/arduino/hardware/sam/1.6.11 +SAM:=$(ADIR)/packages/arduino/hardware/sam/1.6.12 #CMSIS:=arduino/sam/system/CMSIS/ #LIBSAM:=arduino/sam/system/libsam TMPDIR:=$(PWD)/build From eac2aa4ac194205a284d1bc8e0613f7bc1677724 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Mon, 11 May 2020 14:36:30 +0200 Subject: [PATCH 3/9] Write larger chunks of FM audio to the serial port --- FM.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/FM.cpp b/FM.cpp index 4c8b45b..9913863 100644 --- a/FM.cpp +++ b/FM.cpp @@ -158,10 +158,20 @@ void CFM::process() while (io.getSpace() >= 3U && m_outputRFRB.get(sample)) io.write(STATE_FM, &sample, 1U); - uint8_t serialSample; - //write data to serial port - while (m_downsampler.getPackedData(serialSample)) - serial.writeFMData(&serialSample, 1U); + if(m_downsampler.getData() >= 127) { + uint8_t length = uint8_t(m_downsampler.getData()); + + if(length > 127U)//max message size on serial is 127 + length = 127U; + + uint8_t serialSamples[length]; + + for(uint8_t i = 0U; i < length; i++) { + uint8_t serialSample = 0U; + m_downsampler.getPackedData(serialSample); + } + serial.writeFMData(serialSamples, length); + } } void CFM::reset() From 5d4df6ffd975dc7afbd2a06b7e1578bdf16bfa18 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Mon, 11 May 2020 16:04:58 +0200 Subject: [PATCH 4/9] Write larger chunks of data to IO --- FM.cpp | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/FM.cpp b/FM.cpp index 9913863..6fb513a 100644 --- a/FM.cpp +++ b/FM.cpp @@ -154,21 +154,36 @@ void CFM::samples(bool cos, const q15_t* samples, uint8_t length) void CFM::process() { - q15_t sample; - while (io.getSpace() >= 3U && m_outputRFRB.get(sample)) - io.write(STATE_FM, &sample, 1U); + if (io.getSpace() > 2 && (m_outputRFRB.getData() >= 250 || m_state != STATE_FM)) {//if we just left FM mode, so write all what is left in buffer, regardless of the amoutn of data + uint16_t length = m_outputRFRB.getData(); + uint16_t space = io.getSpace() - 2; - if(m_downsampler.getData() >= 127) { - uint8_t length = uint8_t(m_downsampler.getData()); + if(length > space) + length = space; + + q15_t samples[length]; + for(uint16_t i = 0; i < length; i++) { + q15_t sample = 0; + m_outputRFRB.get(sample); + samples[i] = sample; + } + + io.write(STATE_FM, samples, length); + } + + //Write audio to serial + if (m_downsampler.getData() >= 127 || m_state != STATE_FM) {//if we just left FM mode, so write all what is left in buffer, regardless of the amoutn of data + uint16_t length = m_downsampler.getData(); if(length > 127U)//max message size on serial is 127 length = 127U; uint8_t serialSamples[length]; - for(uint8_t i = 0U; i < length; i++) { + for(uint16_t i = 0U; i < length; i++) { uint8_t serialSample = 0U; m_downsampler.getPackedData(serialSample); + serialSamples[i] = serialSample; } serial.writeFMData(serialSamples, length); } From 86ffc69b3088bd9b1d11aca0ddd8ade6ec58e851 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Mon, 11 May 2020 19:01:05 +0200 Subject: [PATCH 5/9] Add getData --- FMDownsampler.cpp | 9 +++++++-- FMDownsampler.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/FMDownsampler.cpp b/FMDownsampler.cpp index c2c3635..3209778 100644 --- a/FMDownsampler.cpp +++ b/FMDownsampler.cpp @@ -28,7 +28,7 @@ m_samplePackPointer(NULL), m_packIndex(0U), m_downSampleIndex(0U) { - m_samplePackPointer = &m_samplePack; + m_samplePackPointer = &m_samplePack; } void CFMDownsampler::addSample(q15_t sample) @@ -55,7 +55,7 @@ void CFMDownsampler::addSample(q15_t sample) break; } m_packIndex++; - if(m_packIndex >= 2U)//did we pack to samples ? + if(m_packIndex >= 2U)//did we pack two samples ? m_packIndex = 0U; } @@ -69,6 +69,11 @@ bool CFMDownsampler::getPackedData(uint8_t& data) return m_ringBuffer.get(data); } +uint16_t CFMDownsampler::getData() +{ + return m_ringBuffer.getData(); +} + void CFMDownsampler::reset() { m_downSampleIndex = 0; diff --git a/FMDownsampler.h b/FMDownsampler.h index 9b576c4..179493f 100644 --- a/FMDownsampler.h +++ b/FMDownsampler.h @@ -28,6 +28,7 @@ public: CFMDownsampler(uint16_t length); void addSample(q15_t sample); bool getPackedData(uint8_t& data); + uint16_t getData(); void reset(); private: From 6786b9b6b12bf827d981fa75e959b8f71f712464 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Mon, 11 May 2020 19:01:50 +0200 Subject: [PATCH 6/9] Temporary revert to previous code --- FM.cpp | 70 +++++++++++++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 30 deletions(-) diff --git a/FM.cpp b/FM.cpp index 6fb513a..9c25d83 100644 --- a/FM.cpp +++ b/FM.cpp @@ -20,10 +20,8 @@ #include "Globals.h" #include "FM.h" -const uint8_t BIT_MASK_TABLE[] = {0x80U, 0x40U, 0x20U, 0x10U, 0x08U, 0x04U, 0x02U, 0x01U}; - -#define WRITE_BIT_AUDIO(p,i,b) p[(i)>>3] = (b) ? (p[(i)>>3] | BIT_MASK_TABLE[(i)&7]) : (p[(i)>>3] & ~BIT_MASK_TABLE[(i)&7]) -#define READ_BIT_AUDIO(p,i) (p[(i)>>3] & BIT_MASK_TABLE[(i)&7]) +const uint16_t FM_TX_BLOCK_SIZE = 250U; +const uint16_t FM_SERIAL_BLOCK_SIZE = 127U; CFM::CFM() : m_callsign(), @@ -154,39 +152,51 @@ void CFM::samples(bool cos, const q15_t* samples, uint8_t length) void CFM::process() { - if (io.getSpace() > 2 && (m_outputRFRB.getData() >= 250 || m_state != STATE_FM)) {//if we just left FM mode, so write all what is left in buffer, regardless of the amoutn of data - uint16_t length = m_outputRFRB.getData(); - uint16_t space = io.getSpace() - 2; + q15_t sample; + while (io.getSpace() >= 3U && m_outputRFRB.get(sample)) + io.write(STATE_FM, &sample, 1U); - if(length > space) - length = space; + // if (io.getSpace() > 2 && (m_outputRFRB.getData() >= FM_TX_BLOCK_SIZE || m_state != STATE_FM)) {//if we just left FM mode, so write all what is left in buffer, regardless of the amoutn of data + // uint16_t length = m_outputRFRB.getData(); + // uint16_t space = io.getSpace() - 2; - q15_t samples[length]; - for(uint16_t i = 0; i < length; i++) { - q15_t sample = 0; - m_outputRFRB.get(sample); - samples[i] = sample; - } + // if(length > FM_TX_BLOCK_SIZE) + // length = FM_TX_BLOCK_SIZE; + // if(space > FM_TX_BLOCK_SIZE) + // space = FM_TX_BLOCK_SIZE; + // if(length > space) + // length = space; - io.write(STATE_FM, samples, length); - } + // q15_t samples[FM_TX_BLOCK_SIZE]; + // for(uint16_t i = 0; i < length; i++) { + // q15_t sample = 0; + // m_outputRFRB.get(sample); + // samples[i] = sample; + // } - //Write audio to serial - if (m_downsampler.getData() >= 127 || m_state != STATE_FM) {//if we just left FM mode, so write all what is left in buffer, regardless of the amoutn of data - uint16_t length = m_downsampler.getData(); + // io.write(STATE_FM, samples, length); + // } - if(length > 127U)//max message size on serial is 127 - length = 127U; + // //Write audio to serial + // if (m_downsampler.getData() >= 127 || m_state != STATE_FM) {//if we just left FM mode, so write all what is left in buffer, regardless of the amoutn of data + // uint16_t length = m_downsampler.getData(); - uint8_t serialSamples[length]; + // if(length > FM_SERIAL_BLOCK_SIZE)//max message size on serial is 127 + // length = FM_SERIAL_BLOCK_SIZE; - for(uint16_t i = 0U; i < length; i++) { - uint8_t serialSample = 0U; - m_downsampler.getPackedData(serialSample); - serialSamples[i] = serialSample; - } - serial.writeFMData(serialSamples, length); - } + // if(length > FM_SERIAL_BLOCK_SIZE) + // length = FM_SERIAL_BLOCK_SIZE; + + // uint8_t serialSamples[FM_SERIAL_BLOCK_SIZE]; + + // for(uint16_t i = 0U; i < length; i++) { + // uint8_t serialSample = 0U; + // m_downsampler.getPackedData(serialSample); + // serialSamples[i] = serialSample; + // } + + // serial.writeFMData(serialSamples, length); + // } } void CFM::reset() From b4a125a75997bb09783f0e4f28cad77728d39197 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Mon, 11 May 2020 22:31:50 +0200 Subject: [PATCH 7/9] Add debug info TX switching --- IO.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/IO.cpp b/IO.cpp index 7b000fb..c668f1f 100644 --- a/IO.cpp +++ b/IO.cpp @@ -264,6 +264,7 @@ void CIO::process() if (m_txBuffer.getData() == 0U && m_tx) { m_tx = false; setPTTInt(m_pttInvert ? true : false); + DEBUG1("Process TX OFF"); } if (m_rxBuffer.getData() >= RX_BLOCK_SIZE) { @@ -453,6 +454,7 @@ void CIO::write(MMDVM_STATE mode, q15_t* samples, uint16_t length, const uint8_t if (!m_tx) { m_tx = true; setPTTInt(m_pttInvert ? false : true); + DEBUG1("Write TX ON"); } q15_t txLevel = 0; From 042c26b3bb29ab7b353594899f0a7b4a33717ea3 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Mon, 11 May 2020 22:32:24 +0200 Subject: [PATCH 8/9] Trying to fix no tx, WIP --- FM.cpp | 51 +++++++++++++++++++++++++++++---------------------- FM.h | 3 ++- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/FM.cpp b/FM.cpp index 9c25d83..1e1f5aa 100644 --- a/FM.cpp +++ b/FM.cpp @@ -62,7 +62,7 @@ m_inputExtRB(2400U) // 100ms of Audio insertDelay(100U); } -void CFM::samples(bool cos, const q15_t* samples, uint8_t length) +void CFM::samples(bool cos, q15_t* samples, uint8_t length) { if (m_useCOS) { if (m_cosInvert) @@ -147,35 +147,37 @@ void CFM::samples(bool cos, const q15_t* samples, uint8_t length) currentSample += m_ctcssTX.getAudio(); m_outputRFRB.put(currentSample); + //samples[i] = currentSample; } + + // XXX This relays audio correctly, no t, process need to be commented + // if (m_state == FS_RELAYING_RF || m_state == FS_KERCHUNK_RF || m_state == FS_RELAYING_EXT || m_state == FS_KERCHUNK_EXT) + // io.write(STATE_FM, samples, i); + } void CFM::process() { - q15_t sample; - while (io.getSpace() >= 3U && m_outputRFRB.get(sample)) - io.write(STATE_FM, &sample, 1U); + uint16_t space = io.getSpace() - 2U; + uint16_t length = m_outputRFRB.getData(); + if (space > 2 && length >= FM_TX_BLOCK_SIZE ) { - // if (io.getSpace() > 2 && (m_outputRFRB.getData() >= FM_TX_BLOCK_SIZE || m_state != STATE_FM)) {//if we just left FM mode, so write all what is left in buffer, regardless of the amoutn of data - // uint16_t length = m_outputRFRB.getData(); - // uint16_t space = io.getSpace() - 2; + if(length > FM_TX_BLOCK_SIZE) + length = FM_TX_BLOCK_SIZE; + if(space > FM_TX_BLOCK_SIZE) + space = FM_TX_BLOCK_SIZE; + if(length > space) + length = space; - // if(length > FM_TX_BLOCK_SIZE) - // length = FM_TX_BLOCK_SIZE; - // if(space > FM_TX_BLOCK_SIZE) - // space = FM_TX_BLOCK_SIZE; - // if(length > space) - // length = space; + q15_t samples[FM_TX_BLOCK_SIZE]; + for(uint16_t i = 0U; i < length; i++) { + q15_t sample = 0; + m_outputRFRB.get(sample); + samples[i] = sample; + } - // q15_t samples[FM_TX_BLOCK_SIZE]; - // for(uint16_t i = 0; i < length; i++) { - // q15_t sample = 0; - // m_outputRFRB.get(sample); - // samples[i] = sample; - // } - - // io.write(STATE_FM, samples, length); - // } + io.write(STATE_FM, samples, length); + } // //Write audio to serial // if (m_downsampler.getData() >= 127 || m_state != STATE_FM) {//if we just left FM mode, so write all what is left in buffer, regardless of the amoutn of data @@ -325,6 +327,11 @@ void CFM::stateMachine(bool validRFSignal, bool validExtSignal) default: break; } + + if (m_state == FS_LISTENING) { + m_outputRFRB.reset(); + m_downsampler.reset(); + } } void CFM::clock(uint8_t length) diff --git a/FM.h b/FM.h index daef1b1..a4c82f9 100644 --- a/FM.h +++ b/FM.h @@ -51,7 +51,7 @@ class CFM { public: CFM(); - void samples(bool cos, const q15_t* samples, uint8_t length); + void samples(bool cos, q15_t* samples, uint8_t length); void process(); @@ -117,6 +117,7 @@ private: void clock(uint8_t length); void sendCallsign(); + void sendBeeps(); void beginRelaying(); void insertDelay(uint16_t ms); From 1d04c1e90388e5e53d5081a60e614160497d3fda Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Mon, 11 May 2020 22:35:46 +0200 Subject: [PATCH 9/9] Typo --- FM.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FM.cpp b/FM.cpp index 1e1f5aa..7eb7261 100644 --- a/FM.cpp +++ b/FM.cpp @@ -150,7 +150,7 @@ void CFM::samples(bool cos, q15_t* samples, uint8_t length) //samples[i] = currentSample; } - // XXX This relays audio correctly, no t, process need to be commented + // XXX This relays audio correctly, no tones yet, process need to be commented // if (m_state == FS_RELAYING_RF || m_state == FS_KERCHUNK_RF || m_state == FS_RELAYING_EXT || m_state == FS_KERCHUNK_EXT) // io.write(STATE_FM, samples, i);