development check in, now compiles

master
Steve Lascos 7 years ago
parent 19baaa34be
commit c5383595c1
  1. 6
      src/BASpiMemory.cpp
  2. 1
      src/BASpiMemory.h
  3. 2
      src/BATypes.h
  4. 10
      src/LibBasicFunctions.cpp
  5. 2
      src/LibBasicFunctions.h
  6. 24
      src/LibMemoryManagement.cpp
  7. 8
      src/LibMemoryManagement.h

@ -293,6 +293,8 @@ BASpiMemoryDMA::BASpiMemoryDMA(SpiDeviceId memDeviceId, uint32_t speedHz, size_t
case SpiDeviceId::SPI_DEVICE1 : case SpiDeviceId::SPI_DEVICE1 :
cs = SPI_CS_MEM1; cs = SPI_CS_MEM1;
break; break;
default :
cs = SPI_CS_MEM0;
} }
m_cs = new ActiveLowChipSelect(cs, m_settings); m_cs = new ActiveLowChipSelect(cs, m_settings);
m_txBuffer = new uint8_t[bufferSizeBytes+4]; m_txBuffer = new uint8_t[bufferSizeBytes+4];
@ -396,7 +398,7 @@ void BASpiMemoryDMA::zero16(size_t address, size_t numWords)
void BASpiMemoryDMA::read(size_t address, uint8_t *dest, size_t numBytes) void BASpiMemoryDMA::read(size_t address, uint8_t *dest, size_t numBytes)
{ {
UNUSED(dest) UNUSED(dest);
while ( m_rxTransfer->busy()) {} while ( m_rxTransfer->busy()) {}
uint16_t transferCount = numBytes + 4; uint16_t transferCount = numBytes + 4;
m_setSpiCmdAddr(SPI_READ_CMD, address, m_rxBuffer); m_setSpiCmdAddr(SPI_READ_CMD, address, m_rxBuffer);
@ -406,7 +408,7 @@ void BASpiMemoryDMA::read(size_t address, uint8_t *dest, size_t numBytes)
void BASpiMemoryDMA::read16(size_t address, uint16_t *dest, size_t numWords) void BASpiMemoryDMA::read16(size_t address, uint16_t *dest, size_t numWords)
{ {
UNUSED(dest) UNUSED(dest);
while ( m_rxTransfer->busy()) {} while ( m_rxTransfer->busy()) {}
m_setSpiCmdAddr(SPI_READ_CMD, address, m_rxBuffer); m_setSpiCmdAddr(SPI_READ_CMD, address, m_rxBuffer);
size_t numBytes = sizeof(uint16_t)*numWords; size_t numBytes = sizeof(uint16_t)*numWords;

@ -94,6 +94,7 @@ protected:
//constexpr int MAX_DMA_XFERS = 4; //constexpr int MAX_DMA_XFERS = 4;
class BASpiMemoryDMA : public BASpiMemory { class BASpiMemoryDMA : public BASpiMemory {
public:
BASpiMemoryDMA() = delete; BASpiMemoryDMA() = delete;
/// Create an object to control either MEM0 (via SPI1) or MEM1 (via SPI2). /// Create an object to control either MEM0 (via SPI1) or MEM1 (via SPI2).
/// @details default is 20 Mhz /// @details default is 20 Mhz

@ -10,6 +10,8 @@
namespace BAGuitar { namespace BAGuitar {
#define UNUSED(x) (void)(x)
/**************************************************************************//** /**************************************************************************//**
* Customer RingBuffer with random access * Customer RingBuffer with random access
*****************************************************************************/ *****************************************************************************/

@ -213,7 +213,7 @@ bool AudioDelay::getSamples(audio_block_t *dest, size_t offset, size_t numSample
// destPtr--; // destPtr--;
// } // }
m_slot->readAdvance16(AUDIO_BLOCK_SAMPLES); m_slot->readAdvance16(dest->data, AUDIO_BLOCK_SAMPLES);
// // Code below worked // // Code below worked
// int16_t *destPtr = dest->data; // int16_t *destPtr = dest->data;
@ -268,13 +268,13 @@ bool IirBiQuadFilter::process(int16_t *output, int16_t *input, size_t numSamples
// create convertion buffers on teh stack // create convertion buffers on teh stack
int32_t input32[numSamples]; int32_t input32[numSamples];
int32_t output32[numSamples]; int32_t output32[numSamples];
for (int i=0; i<numSamples; i++) { for (size_t i=0; i<numSamples; i++) {
input32[i] = (int32_t)(input[i]); input32[i] = (int32_t)(input[i]);
} }
arm_biquad_cascade_df1_fast_q31(&m_iirCfg, input32, output32, numSamples); arm_biquad_cascade_df1_fast_q31(&m_iirCfg, input32, output32, numSamples);
for (int i=0; i<numSamples; i++) { for (size_t i=0; i<numSamples; i++) {
output[i] = (int16_t)(output32[i] & 0xffff); output[i] = (int16_t)(output32[i] & 0xffff);
} }
} }
@ -310,13 +310,13 @@ bool IirBiQuadFilterHQ::process(int16_t *output, int16_t *input, size_t numSampl
// create convertion buffers on teh stack // create convertion buffers on teh stack
int32_t input32[numSamples]; int32_t input32[numSamples];
int32_t output32[numSamples]; int32_t output32[numSamples];
for (int i=0; i<numSamples; i++) { for (size_t i=0; i<numSamples; i++) {
input32[i] = (int32_t)(input[i]); input32[i] = (int32_t)(input[i]);
} }
arm_biquad_cas_df1_32x64_q31(&m_iirCfg, input32, output32, numSamples); arm_biquad_cas_df1_32x64_q31(&m_iirCfg, input32, output32, numSamples);
for (int i=0; i<numSamples; i++) { for (size_t i=0; i<numSamples; i++) {
output[i] = (int16_t)(output32[i] & 0xffff); output[i] = (int16_t)(output32[i] & 0xffff);
} }
} }

@ -109,7 +109,7 @@ public:
/// Construct an audio buffer using a slot configured with the BAGuitar::ExternalSramManager /// Construct an audio buffer using a slot configured with the BAGuitar::ExternalSramManager
/// @param slot a pointer to the slot representing the memory you wish to use for the buffer. /// @param slot a pointer to the slot representing the memory you wish to use for the buffer.
AudioDelay(ExtMemSlot *slot, bool useDma=true); AudioDelay(ExtMemSlot *slot);
~AudioDelay(); ~AudioDelay();

@ -108,7 +108,7 @@ uint16_t ExtMemSlot::readAdvance16()
return val; return val;
} }
bool ExtMemSlot::readAdvance16(int16_t *dest=nullptr, size_t numWords) bool ExtMemSlot::readAdvance16(int16_t *dest, size_t numWords)
{ {
if (!m_valid) { return false; } if (!m_valid) { return false; }
size_t numBytes = sizeof(int16_t)*numWords; size_t numBytes = sizeof(int16_t)*numWords;
@ -175,9 +175,14 @@ bool ExtMemSlot::zeroAdvance16(size_t numWords)
return true; return true;
} }
void ExtMemSlot::readDmaBufferContents(uint8_t *dest, size_t numBytes, size_t bufferOffset = 0) void ExtMemSlot::readDmaBufferContents(uint8_t *dest, size_t numBytes, size_t bufferOffset)
{ {
m_spi->readBufferContents(dest, numBytes, bufferOffset); if (m_useDma) {
(static_cast<BASpiMemoryDMA*>(m_spi))->readBufferContents(dest, numBytes, bufferOffset);
// BASpiMemoryDMA *spi = nullptr;
// spi = static_cast<BASpiMemoryDMA>(m_spi);
// spi->readBufferContents(dest, numBytes, bufferOffset);
}
} }
@ -256,14 +261,14 @@ size_t ExternalSramManager::availableMemory(BAGuitar::MemSelect mem)
return m_memConfig[mem].totalAvailable; return m_memConfig[mem].totalAvailable;
} }
bool ExternalSramManager::requestMemory(ExtMemSlot *slot, float delayMilliseconds, BAGuitar::MemSelect mem, bool useDma) bool ExternalSramManager::requestMemory(ExtMemSlot *slot, float delayMilliseconds, BAGuitar::MemSelect mem, size_t dmaBufferSize)
{ {
// convert the time to numer of samples // convert the time to numer of samples
size_t delayLengthInt = (size_t)((delayMilliseconds*(AUDIO_SAMPLE_RATE_EXACT/1000.0f))+0.5f); size_t delayLengthInt = (size_t)((delayMilliseconds*(AUDIO_SAMPLE_RATE_EXACT/1000.0f))+0.5f);
return requestMemory(slot, delayLengthInt * sizeof(int16_t), mem, useDma); return requestMemory(slot, delayLengthInt * sizeof(int16_t), mem, dmaBufferSize);
} }
bool ExternalSramManager::requestMemory(ExtMemSlot *slot, size_t sizeBytes, BAGuitar::MemSelect mem, bool useDma) bool ExternalSramManager::requestMemory(ExtMemSlot *slot, size_t sizeBytes, BAGuitar::MemSelect mem, size_t dmaBufferSize)
{ {
if (m_memConfig[mem].totalAvailable >= sizeBytes) { if (m_memConfig[mem].totalAvailable >= sizeBytes) {
@ -276,10 +281,12 @@ bool ExternalSramManager::requestMemory(ExtMemSlot *slot, size_t sizeBytes, BAGu
slot->m_size = sizeBytes; slot->m_size = sizeBytes;
if (!m_memConfig[mem].m_spi) { if (!m_memConfig[mem].m_spi) {
if (useDma) { if (dmaBufferSize > 0) {
m_memConfig[mem].m_spi = new BAGuitar::BASpiMemoryDma(static_cast<BAGuitar::SpiDeviceId>(mem)); m_memConfig[mem].m_spi = new BAGuitar::BASpiMemoryDMA(static_cast<BAGuitar::SpiDeviceId>(mem), dmaBufferSize);
slot->m_useDma = true;
} else { } else {
m_memConfig[mem].m_spi = new BAGuitar::BASpiMemory(static_cast<BAGuitar::SpiDeviceId>(mem)); m_memConfig[mem].m_spi = new BAGuitar::BASpiMemory(static_cast<BAGuitar::SpiDeviceId>(mem));
slot->m_useDma = false;
} }
if (!m_memConfig[mem].m_spi) { if (!m_memConfig[mem].m_spi) {
Serial.println("requestMemory: new failed! m_spi is a nullptr"); Serial.println("requestMemory: new failed! m_spi is a nullptr");
@ -295,7 +302,6 @@ bool ExternalSramManager::requestMemory(ExtMemSlot *slot, size_t sizeBytes, BAGu
slot->m_valid = true; slot->m_valid = true;
if (!slot->isEnabled()) { slot->enable(); } if (!slot->isEnabled()) { slot->enable(); }
slot->clear(); slot->clear();
slot->m_useDma = useDma;
return true; return true;
} else { } else {
// there is not enough memory available for the request // there is not enough memory available for the request

@ -110,7 +110,7 @@ public:
/// @param dest pointer to the destination of the read. /// @param dest pointer to the destination of the read.
/// @param numWords number of 16-bit words to transfer /// @param numWords number of 16-bit words to transfer
/// @returns true on success, else false on error /// @returns true on success, else false on error
bool readAdvance16(int16_t *dest=nullptr, size_t numWords); bool readAdvance16(int16_t *dest, size_t numWords);
/// Write a block of 16-bit data from the specified location in circular operation /// Write a block of 16-bit data from the specified location in circular operation
/// @param src pointer to the start of the block of data to write to memory /// @param src pointer to the start of the block of data to write to memory
@ -186,15 +186,17 @@ public:
/// @param slot a pointer to the global slot object to which memory will be allocated /// @param slot a pointer to the global slot object to which memory will be allocated
/// @param delayMilliseconds request the amount of memory based on required time for audio samples, rather than number of bytes. /// @param delayMilliseconds request the amount of memory based on required time for audio samples, rather than number of bytes.
/// @param mem specify which external memory to allocate from /// @param mem specify which external memory to allocate from
/// @param dmaBufferSize When > 0, DMA mode is used with the specified DMA buffer size
/// @returns true on success, otherwise false on error /// @returns true on success, otherwise false on error
bool requestMemory(ExtMemSlot *slot, float delayMilliseconds, BAGuitar::MemSelect mem = BAGuitar::MemSelect::MEM0, bool useDma = true); bool requestMemory(ExtMemSlot *slot, float delayMilliseconds, BAGuitar::MemSelect mem = BAGuitar::MemSelect::MEM0, size_t dmaBufferSize = 0);
/// Request memory be allocated for the provided slot /// Request memory be allocated for the provided slot
/// @param slot a pointer to the global slot object to which memory will be allocated /// @param slot a pointer to the global slot object to which memory will be allocated
/// @param sizeBytes request the amount of memory in bytes to request /// @param sizeBytes request the amount of memory in bytes to request
/// @param mem specify which external memory to allocate from /// @param mem specify which external memory to allocate from
/// @param dmaBufferSize When > 0, DMA mode is used with the specified DMA buffer size
/// @returns true on success, otherwise false on error /// @returns true on success, otherwise false on error
bool requestMemory(ExtMemSlot *slot, size_t sizeBytes, BAGuitar::MemSelect mem = BAGuitar::MemSelect::MEM0, bool useDma = true); bool requestMemory(ExtMemSlot *slot, size_t sizeBytes, BAGuitar::MemSelect mem = BAGuitar::MemSelect::MEM0, size_t dmaBufferSize = 0);
private: private:
static bool m_configured; ///< there should only be one instance of ExternalSramManager in the whole project static bool m_configured; ///< there should only be one instance of ExternalSramManager in the whole project

Loading…
Cancel
Save