I wanted to know what the proper use of PSRAM is in relation to data cache
I use PSRAM as huge databuffer in my recorder
for this I plan to use the following (simple) Queue object where buffer may be initializes using EXTMEM
So there are four questions
- are the arm_dcache* functions really necessary (program seemed to work without them).
- are changing the write/read addresses not sufficient to invalidate the cache?
- if not, is it correct to call 'arm_dcache_flush_delete' after writing to EXTMEM and 'arm_dcache_delete' before read?
- is 'arm_dcache_delete' really needed?
I use PSRAM as huge databuffer in my recorder
for this I plan to use the following (simple) Queue object where buffer may be initializes using EXTMEM
Code:
class Data
{
public:
Data(uint32_t * buffer) { data_buffer=buffer; front_=rear_=0;}
uint16_t push(uint32_t * src)
{
uint16_t f =front_ + 1;
if(f >= MAXBUF) f=0;
if(f == rear_) return 0;
uint32_t *ptr= data_buffer+f*NBUF_ACQ;
memcpy(ptr,src,NBUF_ACQ*4);
#if defined(USE_EXT_MEM)
arm_dcache_flush_delete((void *)ptr,NBUF_ACQ*4);
#endif
front_ = f;
return 1;
}
uint16_t pull(uint32_t * dst, uint32_t ndbl)
{
uint16_t r = (rear_/ndbl) ;
if(r == (front_/ndbl)) return 0;
uint32_t *ptr= data_buffer + r*ndbl*NBUF_ACQ;
#if defined(USE_EXT_MEM)
arm_dcache_delete((void *)ptr,NBUF_ACQ*4);
#endif
memcpy(dst,ptr,ndbl*NBUF_ACQ*4);
if(++r >= (MAXBUF/ndbl)) r=0;
rear_ = r*ndbl;
return 1;
}
uint16_t getCount () { if(front_ >= rear_) return front_ - rear_; return front_+ MAXBUF -rear_; }
private:
uint16_t front_, rear_;
uint32_t *data_buffer;
};
So there are four questions
- are the arm_dcache* functions really necessary (program seemed to work without them).
- are changing the write/read addresses not sufficient to invalidate the cache?
- if not, is it correct to call 'arm_dcache_flush_delete' after writing to EXTMEM and 'arm_dcache_delete' before read?
- is 'arm_dcache_delete' really needed?