Aviate Audio Multiverse Library
SramManager.h
Go to the documentation of this file.
1 /**************************************************************************/
16 #ifndef AVIATE_SRAMMANAGER_H_
17 #define AVIATE_SRAMMANAGER_H_
18 
19 #include <memory>
20 #include "Aviate/Aviate.h"
21 #include "Aviate/ForwardDeclares.h"
22 
23 namespace Aviate {
24 
25 class SramManager;
26 
29 public:
31  virtual ~SramMemSlot();
32 
35  bool clear();
36 
39  bool isUseDma() const;
40 
43  bool isWriteBusy() const;
44 
47  bool isReadBusy() const;
48 
51  size_t size();
52 
56  bool setWritePosition(size_t offsetBytes);
57 
60  size_t getWritePosition() const;
61 
65  bool setReadPosition(size_t offsetBytes);
66 
69  size_t getReadPosition() const;
70 
71  /* Byte-based transfers */
72 
77  bool zero(size_t offsetBytes, size_t numBytes);
78 
84  bool write(size_t offsetBytes, uint8_t *src, size_t numBytes);
85 
91  bool read(size_t offsetBytes, uint8_t *dest, size_t numBytes);
92 
96  bool zeroAdvance(size_t numBytes);
97 
101  bool writeAdvance(uint8_t data); // write just one data
102 
107  bool writeAdvance(uint8_t *src, size_t numBytes);
108 
111  uint8_t readAdvance();
112 
118  bool readAdvance(uint8_t *dest, size_t numBytes);
119 
120 
121  /* 16-bit data transfers */
122 
127  bool zero16(size_t offsetWords, size_t numWords);
128 
134  bool write16(size_t offsetWords, int16_t *src, size_t numWords);
135 
141  bool read16(size_t offsetWords, int16_t *dest, size_t numWords);
142 
146  bool zeroAdvance16(size_t numWords);
147 
152  bool writeAdvance16(int16_t *src, size_t numWords);
153 
157  bool writeAdvance16(int16_t data); // write just one data
158 
161  uint16_t readAdvance16();
162 
168  bool readAdvance16(int16_t *dest, size_t numWords);
169 
172  bool enable() const;
173 
176  bool isEnabled() const;
177 
178  friend SramManager;
179  friend AudioDelay;
180 
181 private:
182  class Impl;
183  std::unique_ptr<Impl> _pimpl;
184 };
185 
186 /**************************************************************************/
192 class AVIATE_API SramManager final {
193 public:
196  SramManager(bool useDma);
197  virtual ~SramManager();
198 
200  void begin();
201 
204  size_t availableMemory();
205 
210  SramMemSlot* requestMemory(float delayMilliseconds, bool clearMemory = false);
211 
216  SramMemSlot* requestMemory(size_t sizeBytes, bool clearMemory = false);
217 
220  SysPlatform::SysSpi* getSpiMemoryPtr();
221 
224  SysPlatform::SysSpi* getSpiDmaMemoryPtr();
225 
228  bool isUsingDma();
229 
232  void stop(bool waitForStop = false);
233 
236  void start(bool waitForStart = false);
237 
240  bool isStopped();
241 
244  bool isStarted();
245 
246  bool runSramTest();
247 
248 
249 private:
250  struct Impl;
251  std::unique_ptr<Impl> _pimpl;
252 };
253 
254 extern volatile SramManager* sramManagerPtr;
255 
256 }
257 
258 #endif // LIBAVALON_FLASHMANAGER_H_
#define AVIATE_API
enable default visibility. This is used for public API functions and classes.
Definition: Aviate.h:19
SramManager provides a class to handle dividing an external SPI RAM into independent slots for genera...
Definition: SramManager.h:192
SysPlatform::SysSpi * getSpiDmaMemoryPtr()
get the raw pointer to the underlying DMA-mode SPI memory
SramMemSlot * requestMemory(float delayMilliseconds, bool clearMemory=false)
Request memory be allocated for the provided slot.
void begin()
Starts the SRAM manager and gets it ready for use.
bool isStopped()
check if SRAM manager is stopped
void stop(bool waitForStop=false)
Halt the SRAM manager, no further transactions will be processed.
size_t availableMemory()
Query the amount of available (unallocated) memory.
virtual ~SramManager()
destructor
bool isUsingDma()
Check if SRAM manager is using DMA for transfers.
SramManager(bool useDma)
This object is created automatically by the framework. Do not instantiate directly.
SramMemSlot * requestMemory(size_t sizeBytes, bool clearMemory=false)
Request memory be allocated for the provided slot.
void start(bool waitForStart=false)
Start the SRAM manager.
bool isStarted()
check if SRAM manager is started
SysPlatform::SysSpi * getSpiMemoryPtr()
get the raw pointers to the underlying SPI memory
This object is used for data transfers to/from the external SPI SRAM.
Definition: SramManager.h:28
bool clear()
clear the entire contents of the slot by writing zeros
bool isReadBusy() const
Check if a DMA read is complete and data is available.
bool isWriteBusy() const
Check if a DMA write is still pending or in progress.
bool writeAdvance16(int16_t *src, size_t numWords)
Write a block of 16-bit data from the specified location in circular operation.
bool writeAdvance(uint8_t data)
Write a single 16-bit data to the next location in circular operation.
bool isUseDma() const
check if SRAM is using DMA for transfers
friend SramManager
SramManager is a friend of this class.
Definition: SramManager.h:178
bool zeroAdvance16(size_t numWords)
Write a block of 16-bit data zeros in circular operation.
bool write16(size_t offsetWords, int16_t *src, size_t numWords)
Write a block of 16-bit data to the memory at the specified offset.
bool readAdvance16(int16_t *dest, size_t numWords)
Read the next block of numWords during circular operation.
bool setReadPosition(size_t offsetBytes)
set a new read position (in bytes) for circular operation
bool read16(size_t offsetWords, int16_t *dest, size_t numWords)
Read a block of 16-bit data from the memory at the specified location.
size_t getWritePosition() const
returns the currently set write pointer pointer
uint16_t readAdvance16()
Read the next in memory during circular operation.
bool zero16(size_t offsetWords, size_t numWords)
Write a block of zeros (16-bit) to the memory at the specified offset.
bool read(size_t offsetBytes, uint8_t *dest, size_t numBytes)
Read a block of 8-bit data from the memory at the specified location.
bool writeAdvance(uint8_t *src, size_t numBytes)
Write a block of 16-bit data from the specified location in circular operation.
bool readAdvance(uint8_t *dest, size_t numBytes)
Read the next block of numWords during circular operation.
bool zeroAdvance(size_t numBytes)
Write a block of 16-bit data zeros in circular operation.
bool zero(size_t offsetBytes, size_t numBytes)
Write a block of zeros (8-bit) to the memory at the specified offset.
size_t size()
Get the size of the memory slot in bytes.
bool enable() const
Ensures the underlying SPI interface is enabled.
bool setWritePosition(size_t offsetBytes)
set a new write position (in bytes) for circular operation
friend AudioDelay
AudioDelay is a friend of this class.
Definition: SramManager.h:179
bool writeAdvance16(int16_t data)
Write a single 16-bit data to the next location in circular operation.
uint8_t readAdvance()
Read the next byte in memory during circular operation.
SramMemSlot()
constructor
bool write(size_t offsetBytes, uint8_t *src, size_t numBytes)
Write a block of 8-bit data to the memory at the specified offset.
size_t getReadPosition() const
returns the currently set read pointer pointer
bool isEnabled() const
Checks whether underlying SPI interface is enabled.
The Aviate library/namespace provides the primary API for working with Multiverse.
Definition: AudioEffectWrapper.h:24
volatile SramManager * sramManagerPtr
pointer to global SramManager pointer