forked from wirtz/BALibrary
Added bulk transfer functions to BASpiMemory, and start work on some library routines for external SRAM management and. NOT WORKING YET
parent
f3104753fc
commit
ecb0ba0aa8
@ -0,0 +1,35 @@ |
||||
/*
|
||||
* LibBasicFunctions.cpp |
||||
* |
||||
* Created on: Dec 23, 2017 |
||||
* Author: slascos |
||||
*/ |
||||
|
||||
#include "LibBasicFunctions.h" |
||||
|
||||
namespace BAGuitar { |
||||
|
||||
void updateAudioMemorySlot(BASpiMemory *mem, MemSlot slot, audio_block_t *block) |
||||
{ |
||||
if (block) { |
||||
if (slot.currentPosition + AUDIO_BLOCK_SAMPLES-1 <= slot.end) { |
||||
// entire block fits in memory slot without wrapping
|
||||
mem->write16(slot.currentPosition, (uint16_t *)block->data, AUDIO_BLOCK_SAMPLES); // cast audio data to uint.
|
||||
} else { |
||||
// this write will wrap the memory slot
|
||||
size_t numBytes = slot.end - slot.currentPosition + 1; |
||||
mem->write16(slot.currentPosition, (uint16_t *)block->data, numBytes); |
||||
size_t remainingBytes = AUDIO_BLOCK_SAMPLES - numBytes; // calculate the remaining bytes
|
||||
mem->write16(slot.start, (uint16_t *)block->data + numBytes, remainingBytes); // write remaining bytes are start
|
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
void zeroMemorySlot(BASpiMemory *mem, MemSlot slot) |
||||
{ |
||||
mem->zero16(slot.start, slot.end-slot.start+1); |
||||
} |
||||
|
||||
} |
||||
|
@ -0,0 +1,23 @@ |
||||
/*
|
||||
* LibBasicFunctions.h |
||||
* |
||||
* Created on: Dec 23, 2017 |
||||
* Author: slascos |
||||
*/ |
||||
|
||||
#ifndef SRC_LIBBASICFUNCTIONS_H_ |
||||
#define SRC_LIBBASICFUNCTIONS_H_ |
||||
|
||||
#include "Audio.h" |
||||
#include "LibExtMemoryManagement.h" |
||||
#include "BASpiMemory.h" |
||||
|
||||
namespace BAGuitar { |
||||
|
||||
void updateAudioMemorySlot(BAGuitar::BASpiMemory *mem, MemSlot slot, audio_block_t *block); |
||||
void zeroMemorySlot(BAGuitar::BASpiMemory *mem, MemSlot slot); |
||||
|
||||
} |
||||
|
||||
|
||||
#endif /* SRC_LIBBASICFUNCTIONS_H_ */ |
@ -0,0 +1,66 @@ |
||||
/*
|
||||
* ExtMemoryManagement.h |
||||
* |
||||
* Created on: Dec 23, 2017 |
||||
* Author: slascos |
||||
*/ |
||||
|
||||
#ifndef SRC_LIBEXTMEMORYMANAGEMENT_H_ |
||||
#define SRC_LIBEXTMEMORYMANAGEMENT_H_ |
||||
|
||||
#include <cstddef> |
||||
|
||||
#include "BAHardware.h" |
||||
|
||||
namespace BAGuitar { |
||||
|
||||
struct MemConfig { |
||||
size_t size; |
||||
size_t totalAvailable; |
||||
size_t nextAvailable; |
||||
}; |
||||
|
||||
struct MemSlot { |
||||
size_t start; |
||||
size_t end; |
||||
size_t currentPosition; |
||||
}; |
||||
|
||||
class ExternalSramManager { |
||||
public: |
||||
ExternalSramManager() = delete; |
||||
ExternalSramManager(BAGuitar::MemSelect mem) { |
||||
|
||||
// Initialize the static memory configuration structs
|
||||
m_memConfig[MEM0].size = MEM0_MAX_ADDR; |
||||
m_memConfig[MEM0].totalAvailable = MEM0_MAX_ADDR; |
||||
m_memConfig[MEM0].nextAvailable = 0; |
||||
|
||||
m_memConfig[MEM0].size = MEM0_MAX_ADDR; |
||||
m_memConfig[MEM0].totalAvailable = MEM0_MAX_ADDR; |
||||
m_memConfig[MEM0].nextAvailable = 0; |
||||
} |
||||
|
||||
|
||||
bool getMemory(BAGuitar::MemSelect mem, size_t size, MemSlot &slot) { |
||||
if (m_memConfig[mem].totalAvailable >= size) { |
||||
slot.start = m_memConfig[mem].nextAvailable; |
||||
slot.end = slot.start + size -1; |
||||
slot.currentPosition = slot.start; |
||||
|
||||
// Update the mem config
|
||||
m_memConfig[mem].nextAvailable = slot.end+1; |
||||
m_memConfig[mem].totalAvailable -= size; |
||||
return true; |
||||
} else { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
static MemConfig m_memConfig[BAGuitar::NUM_MEM_SLOTS]; |
||||
|
||||
}; |
||||
|
||||
} |
||||
|
||||
#endif /* SRC_LIBEXTMEMORYMANAGEMENT_H_ */ |
Loading…
Reference in new issue