Skip to content

Commit

Permalink
add support for a CMD_SET_BUFFERS, this will allow the host to contro…
Browse files Browse the repository at this point in the history
…l the size of the transmit FIFO buffers; reduce the size of FIFO buffers;
  • Loading branch information
gatekeep committed Jun 16, 2023
1 parent 7b20b3c commit c728dab
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 3 deletions.
41 changes: 41 additions & 0 deletions SerialPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,17 @@ void SerialPort::process()
}
break;

case CMD_SET_BUFFERS:
err = setBuffers(m_buffer + 3U, m_len - 3U);
if (err == RSN_OK) {
sendACK();
}
else {
DEBUG2("SerialPort: process(): received invalid data to set buffers", err);
sendNAK(err);
}
break;

/** CW */
case CMD_SEND_CWID:
err = RSN_RINGBUFF_FULL;
Expand Down Expand Up @@ -1274,3 +1285,33 @@ uint8_t SerialPort::setRFParams(const uint8_t* data, uint8_t length)
// unused on dedicated modem -- see firmware_hs for implementation
return RSN_OK;
}

/// <summary>
/// Sets the protocol ring buffer sizes.
/// </summary>
/// <param name="data"></param>
/// <param name="length"></param>
/// <returns></returns>
uint8_t SerialPort::setBuffers(const uint8_t* data, uint8_t length)
{
if (length < 1U)
return RSN_ILLEGAL_LENGTH;
if (m_modemState != STATE_IDLE)
return RSN_INVALID_MODE;

uint16_t dmrBufSize = dmr::DMR_TX_BUFFER_LEN;
uint16_t p25BufSize = p25::P25_TX_BUFFER_LEN;
uint16_t nxdnBufSize = nxdn::NXDN_TX_BUFFER_LEN;

dmrBufSize = (data[0U] << 8) + (data[1U]);
p25BufSize = (data[2U] << 8) + (data[3U]);
nxdnBufSize = (data[4U] << 8) + (data[5U]);

p25TX.resizeBuffer(p25BufSize);
nxdnTX.resizeBuffer(nxdnBufSize);

dmrTX.resizeBuffer(dmrBufSize);
dmrDMOTX.resizeBuffer(dmrBufSize);

return RSN_OK;
}
4 changes: 4 additions & 0 deletions SerialPort.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ enum DVM_COMMANDS {

CMD_SEND_CWID = 0x0AU,

CMD_SET_BUFFERS = 0x0FU,

CMD_DMR_DATA1 = 0x18U,
CMD_DMR_LOST1 = 0x19U,
CMD_DMR_DATA2 = 0x1AU,
Expand Down Expand Up @@ -227,6 +229,8 @@ class DSP_FW_API SerialPort {
uint8_t setRXLevel(const uint8_t* data, uint8_t length);
/// <summary>Sets the RF parameters.</summary>
uint8_t setRFParams(const uint8_t* data, uint8_t length);
/// <summary>Sets the protocol ring buffer sizes.</summary>
uint8_t setBuffers(const uint8_t* data, uint8_t length);

/// <summary></summary>
void flashRead();
Expand Down
10 changes: 10 additions & 0 deletions dmr/DMRDMOTX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,16 @@ void DMRDMOTX::setSymbolLvlAdj(int8_t level3Adj, int8_t level1Adj)
m_symLevel1Adj = 0;
}

/// <summary>
/// Helper to resize the FIFO buffer.
/// </summary>
/// <param name="size"></param>
void DMRDMOTX::resizeBuffer(uint16_t size)
{
m_fifo.reset();
m_fifo.reinitialize(size);
}

/// <summary>
/// Helper to get how much space the ring buffer has for samples.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions dmr/DMRDMOTX.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ namespace dmr
/// <summary>Sets the fine adjust 4FSK symbol levels.</summary>
void setSymbolLvlAdj(int8_t level3Adj, int8_t level1Adj);

/// <summary>Helper to resize the FIFO buffer.</summary>
void resizeBuffer(uint16_t size);

/// <summary>Helper to get how much space the ring buffer has for samples.</summary>
uint8_t getSpace() const;

Expand Down
3 changes: 2 additions & 1 deletion dmr/DMRDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ namespace dmr

const int8_t DMR_MS_VOICE_SYNC_SYMBOLS_VALUES[] = { +3, -3, -3, -3, +3, -3, -3, +3, +3, +3, -3, +3, -3, +3, +3, +3, +3, -3, -3, +3, -3, -3, -3, +3 };

const uint32_t DMR_TX_BUFFER_LEN = 1033U; // 1033 = DMR_FRAME_LENGTH_BYTES * 31 + 10 (BUFFER_LEN = DMR_FRAME_LENGTH_BYTES * NO_OF_FRAMES + 10)
// 505 = DMR_FRAME_LENGTH_BYTES * 15 + 10 (BUFFER_LEN = DMR_FRAME_LENGTH_BYTES * NO_OF_FRAMES + 10)
const uint32_t DMR_TX_BUFFER_LEN = 505U; // 15 frames + pad

// Data Type(s)
const uint8_t DT_VOICE_PI_HEADER = 0U;
Expand Down
12 changes: 12 additions & 0 deletions dmr/DMRTX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,18 @@ void DMRTX::resetFifo2()
m_fifo[1U].reset();
}

/// <summary>
/// Helper to resize the FIFO buffer.
/// </summary>
/// <param name="size"></param>
void DMRTX::resizeBuffer(uint16_t size)
{
m_fifo[0U].reset();
m_fifo[1U].reset();
m_fifo[0U].reinitialize(size);
m_fifo[1U].reinitialize(size);
}

/// <summary>
///
/// </summary>
Expand Down
4 changes: 4 additions & 0 deletions dmr/DMRTX.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ namespace dmr
void resetFifo1();
/// <summary>Helper to reset data values to defaults for slot 2 FIFO.</summary>
void resetFifo2();

/// <summary>Helper to resize the FIFO buffer.</summary>
void resizeBuffer(uint16_t size);

/// <summary></summary>
uint32_t getFrameCount();

Expand Down
3 changes: 2 additions & 1 deletion nxdn/NXDNDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ namespace nxdn
const uint16_t NXDN_FSW_SYMBOLS = 0x014DU;
const uint16_t NXDN_FSW_SYMBOLS_MASK = 0x03FFU;

const uint32_t NXDN_TX_BUFFER_LEN = 2026U; // 2026 = NXDN_FRAME_LENGTH_BYTES * 42 + 10 (BUFFER_LEN = NXDN_FRAME_LENGTH_BYTES * NO_OF_FRAMES + 10)
// 538 = NXDN_FRAME_LENGTH_BYTES * 11 + 10 (BUFFER_LEN = NXDN_FRAME_LENGTH_BYTES * NO_OF_FRAMES)
const uint32_t NXDN_TX_BUFFER_LEN = 538U; // 11 frames + pad
} // namespace nxdn

#endif // __NXDN_DEFINES_H__
10 changes: 10 additions & 0 deletions nxdn/NXDNTX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,16 @@ void NXDNTX::setCal(bool start)
m_state = start ? NXDNTXSTATE_CAL : NXDNTXSTATE_NORMAL;
}

/// <summary>
/// Helper to resize the FIFO buffer.
/// </summary>
/// <param name="size"></param>
void NXDNTX::resizeBuffer(uint16_t size)
{
m_fifo.reset();
m_fifo.reinitialize(size);
}

/// <summary>
/// Helper to get how much space the ring buffer has for samples.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions nxdn/NXDNTX.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ namespace nxdn
/// <summary>Helper to set the calibration state for Tx.</summary>
void setCal(bool start);

/// <summary>Helper to resize the FIFO buffer.</summary>
void resizeBuffer(uint16_t size);

/// <summary>Helper to get how much space the ring buffer has for samples.</summary>
uint8_t getSpace() const;

Expand Down
3 changes: 2 additions & 1 deletion p25/P25Defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ namespace p25
const uint32_t P25_SYNC_SYMBOLS = 0x00FB30A0U;
const uint32_t P25_SYNC_SYMBOLS_MASK = 0x00FFFFFFU;

const uint32_t P25_TX_BUFFER_LEN = 2602U; // 2602 = P25_LDU_FRAME_LENGTH_BYTES * 12 + 10 (BUFFER_LEN = P25_LDU_FRAME_LENGTH_BYTES * NO_OF_FRAMES + 10)
// 442 = P25_LDU_FRAME_LENGTH_BYTES * 2 + 10 (BUFFER_LEN = P25_LDU_FRAME_LENGTH_BYTES * NO_OF_FRAMES + 10)
const uint32_t P25_TX_BUFFER_LEN = 442U; // 2 frames + pad

// Data Unit ID(s)
const uint8_t P25_DUID_HDU = 0x00U; // Header Data Unit
Expand Down
10 changes: 10 additions & 0 deletions p25/P25TX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,16 @@ void P25TX::setCal(bool start)
m_state = start ? P25TXSTATE_CAL : P25TXSTATE_NORMAL;
}

/// <summary>
/// Helper to resize the FIFO buffer.
/// </summary>
/// <param name="size"></param>
void P25TX::resizeBuffer(uint16_t size)
{
m_fifo.reset();
m_fifo.reinitialize(size);
}

/// <summary>
/// Helper to get how much space the ring buffer has for samples.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions p25/P25TX.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ namespace p25
/// <summary>Helper to set the calibration state for Tx.</summary>
void setCal(bool start);

/// <summary>Helper to resize the FIFO buffer.</summary>
void resizeBuffer(uint16_t size);

/// <summary>Helper to get how much space the ring buffer has for samples.</summary>
uint8_t getSpace() const;

Expand Down

0 comments on commit c728dab

Please sign in to comment.