mirror of https://github.com/g4klx/MMDVM.git
Lots of small tweaks.
This commit is contained in:
parent
11b18207ff
commit
8f9744c0ec
|
@ -33,6 +33,8 @@ const uint8_t BIT_MASK_TABLE[] = {0x80U, 0x40U, 0x20U, 0x10U, 0x08U, 0x04U, 0x02
|
||||||
|
|
||||||
#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])
|
#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 uint16_t NOENDPTR = 9999U;
|
||||||
|
|
||||||
CDMRSlotRX::CDMRSlotRX(bool slot) :
|
CDMRSlotRX::CDMRSlotRX(bool slot) :
|
||||||
m_slot(slot),
|
m_slot(slot),
|
||||||
m_bitBuffer(),
|
m_bitBuffer(),
|
||||||
|
@ -40,14 +42,13 @@ m_buffer(),
|
||||||
m_bitPtr(0U),
|
m_bitPtr(0U),
|
||||||
m_dataPtr(0U),
|
m_dataPtr(0U),
|
||||||
m_syncPtr(0U),
|
m_syncPtr(0U),
|
||||||
m_endPtr(999U),
|
m_endPtr(NOENDPTR),
|
||||||
m_maxCorr(0),
|
m_maxCorr(0),
|
||||||
m_centre(0),
|
m_centre(0),
|
||||||
m_threshold(0),
|
m_threshold(0),
|
||||||
m_control(0x00U),
|
m_control(0x00U),
|
||||||
m_syncCount(0U),
|
m_syncCount(0U),
|
||||||
m_colorCode(0U),
|
m_colorCode(0U),
|
||||||
m_receiving(false),
|
|
||||||
m_n(0U)
|
m_n(0U)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -62,7 +63,6 @@ void CDMRSlotRX::start()
|
||||||
|
|
||||||
void CDMRSlotRX::reset()
|
void CDMRSlotRX::reset()
|
||||||
{
|
{
|
||||||
m_receiving = false;
|
|
||||||
m_syncPtr = 0U;
|
m_syncPtr = 0U;
|
||||||
m_dataPtr = 0U;
|
m_dataPtr = 0U;
|
||||||
m_bitPtr = 0U;
|
m_bitPtr = 0U;
|
||||||
|
@ -71,14 +71,14 @@ void CDMRSlotRX::reset()
|
||||||
m_syncCount = 0U;
|
m_syncCount = 0U;
|
||||||
m_threshold = 0;
|
m_threshold = 0;
|
||||||
m_centre = 0;
|
m_centre = 0;
|
||||||
m_endPtr = 999U;
|
m_endPtr = NOENDPTR;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CDMRSlotRX::processSample(q15_t sample)
|
bool CDMRSlotRX::processSample(q15_t sample)
|
||||||
{
|
{
|
||||||
// Ensure that the buffer doesn't overflow
|
// Ensure that the buffer doesn't overflow
|
||||||
if (m_dataPtr > m_endPtr || m_dataPtr >= 900U)
|
if (m_dataPtr > m_endPtr || m_dataPtr >= 900U)
|
||||||
return m_receiving;
|
return m_endPtr != NOENDPTR;
|
||||||
|
|
||||||
m_buffer[m_dataPtr] = sample;
|
m_buffer[m_dataPtr] = sample;
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ bool CDMRSlotRX::processSample(q15_t sample)
|
||||||
m_bitBuffer[m_bitPtr] |= 0x01U;
|
m_bitBuffer[m_bitPtr] |= 0x01U;
|
||||||
|
|
||||||
// The approximate position of the sync samples
|
// The approximate position of the sync samples
|
||||||
if (m_receiving) {
|
if (m_endPtr != NOENDPTR) {
|
||||||
uint16_t min = m_syncPtr - 5U;
|
uint16_t min = m_syncPtr - 5U;
|
||||||
uint16_t max = m_syncPtr + 5U;
|
uint16_t max = m_syncPtr + 5U;
|
||||||
if (m_dataPtr >= min && m_dataPtr <= max)
|
if (m_dataPtr >= min && m_dataPtr <= max)
|
||||||
|
@ -111,7 +111,9 @@ bool CDMRSlotRX::processSample(q15_t sample)
|
||||||
CDMRSlotType slotType;
|
CDMRSlotType slotType;
|
||||||
slotType.decode(frame + 1U, colorCode, dataType);
|
slotType.decode(frame + 1U, colorCode, dataType);
|
||||||
|
|
||||||
|
if (colorCode == m_colorCode) {
|
||||||
m_syncCount = 0U;
|
m_syncCount = 0U;
|
||||||
|
m_n = 0U;
|
||||||
|
|
||||||
frame[0U] |= dataType;
|
frame[0U] |= dataType;
|
||||||
|
|
||||||
|
@ -120,14 +122,11 @@ bool CDMRSlotRX::processSample(q15_t sample)
|
||||||
case DT_VOICE_LC_HEADER:
|
case DT_VOICE_LC_HEADER:
|
||||||
case DT_VOICE_PI_HEADER:
|
case DT_VOICE_PI_HEADER:
|
||||||
DEBUG4("DMRSlotRX: header for slot/color code/data type", m_slot ? 2U : 1U, colorCode, dataType);
|
DEBUG4("DMRSlotRX: header for slot/color code/data type", m_slot ? 2U : 1U, colorCode, dataType);
|
||||||
m_receiving = true;
|
|
||||||
m_n = 0U;
|
|
||||||
serial.writeDMRData(m_slot, frame, DMR_FRAME_LENGTH_BYTES + 1U);
|
serial.writeDMRData(m_slot, frame, DMR_FRAME_LENGTH_BYTES + 1U);
|
||||||
break;
|
break;
|
||||||
case DT_TERMINATOR_WITH_LC:
|
case DT_TERMINATOR_WITH_LC:
|
||||||
DEBUG3("DMRSlotRX: terminator for slot/color code", m_slot ? 2U : 1U, colorCode);
|
DEBUG3("DMRSlotRX: terminator for slot/color code", m_slot ? 2U : 1U, colorCode);
|
||||||
m_receiving = false;
|
m_endPtr = NOENDPTR;
|
||||||
m_endPtr = 999U;
|
|
||||||
serial.writeDMRData(m_slot, frame, DMR_FRAME_LENGTH_BYTES + 1U);
|
serial.writeDMRData(m_slot, frame, DMR_FRAME_LENGTH_BYTES + 1U);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -135,11 +134,11 @@ bool CDMRSlotRX::processSample(q15_t sample)
|
||||||
serial.writeDMRData(m_slot, frame, DMR_FRAME_LENGTH_BYTES + 1U);
|
serial.writeDMRData(m_slot, frame, DMR_FRAME_LENGTH_BYTES + 1U);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if (m_control == 0x20U) {
|
} else if (m_control == 0x20U) {
|
||||||
// Voice sync
|
// Voice sync
|
||||||
DEBUG2("DMRSlotRX: voice sync for slot", m_slot ? 2U : 1U);
|
DEBUG2("DMRSlotRX: voice sync for slot", m_slot ? 2U : 1U);
|
||||||
serial.writeDMRData(m_slot, frame, DMR_FRAME_LENGTH_BYTES + 1U);
|
serial.writeDMRData(m_slot, frame, DMR_FRAME_LENGTH_BYTES + 1U);
|
||||||
m_receiving = true;
|
|
||||||
m_syncCount = 0U;
|
m_syncCount = 0U;
|
||||||
m_n = 0U;
|
m_n = 0U;
|
||||||
} else {
|
} else {
|
||||||
|
@ -147,18 +146,18 @@ bool CDMRSlotRX::processSample(q15_t sample)
|
||||||
if (m_syncCount >= MAX_SYNC_LOST_FRAMES) {
|
if (m_syncCount >= MAX_SYNC_LOST_FRAMES) {
|
||||||
DEBUG2("DMRSlotRX: lost for slot", m_slot ? 2U : 1U);
|
DEBUG2("DMRSlotRX: lost for slot", m_slot ? 2U : 1U);
|
||||||
serial.writeDMRLost(m_slot);
|
serial.writeDMRLost(m_slot);
|
||||||
m_receiving = false;
|
|
||||||
m_syncCount = 0U;
|
m_syncCount = 0U;
|
||||||
m_threshold = 0;
|
m_threshold = 0;
|
||||||
m_centre = 0;
|
m_centre = 0;
|
||||||
m_endPtr = 999U;
|
m_endPtr = NOENDPTR;
|
||||||
} else {
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Voice data
|
// Voice data
|
||||||
frame[0U] |= ++m_n;
|
frame[0U] |= ++m_n;
|
||||||
serial.writeDMRData(m_slot, frame, DMR_FRAME_LENGTH_BYTES + 1U);
|
serial.writeDMRData(m_slot, frame, DMR_FRAME_LENGTH_BYTES + 1U);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
m_dataPtr++;
|
m_dataPtr++;
|
||||||
|
|
||||||
|
@ -166,7 +165,7 @@ bool CDMRSlotRX::processSample(q15_t sample)
|
||||||
if (m_bitPtr >= DMR_RADIO_SYMBOL_LENGTH)
|
if (m_bitPtr >= DMR_RADIO_SYMBOL_LENGTH)
|
||||||
m_bitPtr = 0U;
|
m_bitPtr = 0U;
|
||||||
|
|
||||||
return m_receiving;
|
return m_endPtr != NOENDPTR;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDMRSlotRX::correlateSync(q15_t sample)
|
void CDMRSlotRX::correlateSync(q15_t sample)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2015 by Jonathan Naylor G4KLX
|
* Copyright (C) 2015,2016 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
|
||||||
|
@ -48,7 +48,6 @@ private:
|
||||||
uint8_t m_control;
|
uint8_t m_control;
|
||||||
uint8_t m_syncCount;
|
uint8_t m_syncCount;
|
||||||
uint8_t m_colorCode;
|
uint8_t m_colorCode;
|
||||||
bool m_receiving;
|
|
||||||
uint8_t m_n;
|
uint8_t m_n;
|
||||||
|
|
||||||
void correlateSync(q15_t sample);
|
void correlateSync(q15_t sample);
|
||||||
|
|
5
IO.cpp
5
IO.cpp
|
@ -32,8 +32,8 @@ const uint16_t GMSK_FILTER_LEN = 12U;
|
||||||
|
|
||||||
const uint16_t DC_OFFSET = 2048U;
|
const uint16_t DC_OFFSET = 2048U;
|
||||||
|
|
||||||
const uint16_t TX_BUFFER_SIZE = 1101U;
|
const uint16_t TX_BUFFER_SIZE = 1001U;
|
||||||
const uint16_t RX_BUFFER_SIZE = 501U;
|
const uint16_t RX_BUFFER_SIZE = 601U;
|
||||||
|
|
||||||
#if defined(__SAM3X8E__)
|
#if defined(__SAM3X8E__)
|
||||||
// An Arduino Due
|
// An Arduino Due
|
||||||
|
@ -64,6 +64,7 @@ const uint16_t RX_BUFFER_SIZE = 501U;
|
||||||
#define ADC_CDR_Chan 7
|
#define ADC_CDR_Chan 7
|
||||||
#define DACC_MR_USER_SEL_Chan DACC_MR_USER_SEL_CHANNEL0 // DAC on Due DAC0
|
#define DACC_MR_USER_SEL_Chan DACC_MR_USER_SEL_CHANNEL0 // DAC on Due DAC0
|
||||||
#define DACC_CHER_Chan DACC_CHER_CH0
|
#define DACC_CHER_Chan DACC_CHER_CH0
|
||||||
|
#else
|
||||||
#error "Either ARDUINO_DUE_PAPA, ARDUINO_DUE_ZUM, or ARDUINO_DUE_NTH need to be defined"
|
#error "Either ARDUINO_DUE_PAPA, ARDUINO_DUE_ZUM, or ARDUINO_DUE_NTH need to be defined"
|
||||||
#endif
|
#endif
|
||||||
#elif defined(__MK20DX256__)
|
#elif defined(__MK20DX256__)
|
||||||
|
|
21
SampleRB.cpp
21
SampleRB.cpp
|
@ -54,10 +54,12 @@ uint16_t CSampleRB::getData() const
|
||||||
return m_length - m_tail + m_head;
|
return m_length - m_tail + m_head;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSampleRB::put(uint16_t sample, uint8_t control)
|
bool CSampleRB::put(uint16_t sample, uint8_t control)
|
||||||
{
|
{
|
||||||
if (m_full)
|
if (m_full) {
|
||||||
return;
|
m_overflow = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
m_samples[m_head] = sample;
|
m_samples[m_head] = sample;
|
||||||
m_control[m_head] = control;
|
m_control[m_head] = control;
|
||||||
|
@ -66,14 +68,17 @@ void CSampleRB::put(uint16_t sample, uint8_t control)
|
||||||
if (m_head >= m_length)
|
if (m_head >= m_length)
|
||||||
m_head = 0U;
|
m_head = 0U;
|
||||||
|
|
||||||
if (m_head == m_tail) {
|
if (m_head == m_tail)
|
||||||
m_overflow = true;
|
|
||||||
m_full = true;
|
m_full = true;
|
||||||
}
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSampleRB::get(uint16_t& sample, uint8_t& control)
|
bool CSampleRB::get(uint16_t& sample, uint8_t& control)
|
||||||
{
|
{
|
||||||
|
if (m_head == m_tail && !m_full)
|
||||||
|
return false;
|
||||||
|
|
||||||
sample = m_samples[m_tail];
|
sample = m_samples[m_tail];
|
||||||
control = m_control[m_tail];
|
control = m_control[m_tail];
|
||||||
|
|
||||||
|
@ -82,6 +87,8 @@ void CSampleRB::get(uint16_t& sample, uint8_t& control)
|
||||||
m_tail++;
|
m_tail++;
|
||||||
if (m_tail >= m_length)
|
if (m_tail >= m_length)
|
||||||
m_tail = 0U;
|
m_tail = 0U;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CSampleRB::hasOverflowed()
|
bool CSampleRB::hasOverflowed()
|
||||||
|
|
|
@ -35,9 +35,9 @@ public:
|
||||||
|
|
||||||
uint16_t getData() const;
|
uint16_t getData() const;
|
||||||
|
|
||||||
void put(uint16_t sample, uint8_t control);
|
bool put(uint16_t sample, uint8_t control);
|
||||||
|
|
||||||
void get(uint16_t& sample, uint8_t& control);
|
bool get(uint16_t& sample, uint8_t& control);
|
||||||
|
|
||||||
bool hasOverflowed();
|
bool hasOverflowed();
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ const uint8_t MMDVM_DEBUG4 = 0xF4U;
|
||||||
const uint8_t MMDVM_DEBUG5 = 0xF5U;
|
const uint8_t MMDVM_DEBUG5 = 0xF5U;
|
||||||
const uint8_t MMDVM_SAMPLES = 0xF8U;
|
const uint8_t MMDVM_SAMPLES = 0xF8U;
|
||||||
|
|
||||||
const uint8_t HARDWARE[] = "MMDVM 20160116 (D-Star/DMR/System Fusion)";
|
const uint8_t HARDWARE[] = "MMDVM 20160118 (D-Star/DMR/System Fusion)";
|
||||||
|
|
||||||
const uint8_t PROTOCOL_VERSION = 1U;
|
const uint8_t PROTOCOL_VERSION = 1U;
|
||||||
|
|
||||||
|
|
|
@ -58,10 +58,10 @@ uint16_t CSerialRB::getData() const
|
||||||
return m_length - m_tail + m_head;
|
return m_length - m_tail + m_head;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSerialRB::put(uint8_t c)
|
bool CSerialRB::put(uint8_t c)
|
||||||
{
|
{
|
||||||
if (m_full)
|
if (m_full)
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
m_buffer[m_head] = c;
|
m_buffer[m_head] = c;
|
||||||
|
|
||||||
|
@ -71,6 +71,8 @@ void CSerialRB::put(uint8_t c)
|
||||||
|
|
||||||
if (m_head == m_tail)
|
if (m_head == m_tail)
|
||||||
m_full = true;
|
m_full = true;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t CSerialRB::peek() const
|
uint8_t CSerialRB::peek() const
|
||||||
|
|
|
@ -39,7 +39,7 @@ public:
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
void put(uint8_t c);
|
bool put(uint8_t c);
|
||||||
|
|
||||||
uint8_t peek() const;
|
uint8_t peek() const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue