Add block write method

This commit is contained in:
F5OEO 2018-03-21 09:44:43 +00:00
parent 3969c35268
commit 825d770993
4 changed files with 73 additions and 6 deletions

View file

@ -19,15 +19,17 @@ This program is free software: you can redistribute it and/or modify
#include "stdio.h" #include "stdio.h"
#include "iqdmasync.h" #include "iqdmasync.h"
#include <unistd.h>
#include <sched.h>
iqdmasync::iqdmasync(uint64_t TuneFrequency,uint32_t SampleRate,int Channel,uint32_t FifoSize):bufferdma(Channel,FifoSize,4,3) iqdmasync::iqdmasync(uint64_t TuneFrequency,uint32_t SR,int Channel,uint32_t FifoSize):bufferdma(Channel,FifoSize,4,3)
{ {
// Usermem : // Usermem :
// FRAC frequency // FRAC frequency
// PAD Amplitude // PAD Amplitude
// FSEL for amplitude 0 // FSEL for amplitude 0
SampleRate=SR;
tunefreq=TuneFrequency; tunefreq=TuneFrequency;
clkgpio::SetAdvancedPllMode(true); clkgpio::SetAdvancedPllMode(true);
clkgpio::SetCenterFrequency(TuneFrequency,SampleRate); // Write Mult Int and Frac : FixMe carrier is already there clkgpio::SetCenterFrequency(TuneFrequency,SampleRate); // Write Mult Int and Frac : FixMe carrier is already there
@ -162,4 +164,33 @@ void iqdmasync::SetIQSample(uint32_t Index,std::complex<float> sample)
PushSample(Index); PushSample(Index);
} }
void iqdmasync::SetIQSamples(std::complex<float> *sample,size_t Size)
{
size_t NbWritten=0;
int OSGranularity=100;
while(NbWritten<Size)
{
int Available=GetBufferAvailable();
int TimeToSleep=1e6*((int)buffersize*3/4-Available-OSGranularity)/SampleRate; // Sleep for theorically fill 3/4 of Fifo
if(TimeToSleep>0)
{
//fprintf(stderr,"buffer size %d Available %d SampleRate %d Sleep %d\n",buffersize,Available,SampleRate,TimeToSleep);
usleep(TimeToSleep);
}
else
{
//fprintf(stderr,"No Sleep %d\n",TimeToSleep);
sched_yield();
}
Available=GetBufferAvailable();
int Index=GetUserMemIndex();
int ToWrite=((int)Size-(int)NbWritten)<Available?Size-NbWritten:Available;
for(int i=0;i<ToWrite;i++)
{
SetIQSample(Index+i,sample[NbWritten++]);
}
}
}

View file

@ -14,13 +14,15 @@ class iqdmasync:public bufferdma,public clkgpio,public pwmgpio,public pcmgpio
bool syncwithpwm; bool syncwithpwm;
dsp mydsp; dsp mydsp;
uint32_t Originfsel; //Save the original FSEL GPIO uint32_t Originfsel; //Save the original FSEL GPIO
uint32_t SampleRate;
public: public:
iqdmasync(uint64_t TuneFrequency,uint32_t SampleRate,int Channel,uint32_t FifoSize); iqdmasync(uint64_t TuneFrequency,uint32_t SR,int Channel,uint32_t FifoSize);
~iqdmasync(); ~iqdmasync();
void SetDmaAlgo(); void SetDmaAlgo();
void SetPhase(bool inversed); void SetPhase(bool inversed);
void SetIQSample(uint32_t Index,std::complex<float> sample); void SetIQSample(uint32_t Index,std::complex<float> sample);
void SetIQSamples(std::complex<float> *sample,size_t Size);
}; };
#endif #endif

View file

@ -19,12 +19,14 @@ This program is free software: you can redistribute it and/or modify
#include "stdio.h" #include "stdio.h"
#include "ngfmdmasync.h" #include "ngfmdmasync.h"
#include <unistd.h>
#include <sched.h>
ngfmdmasync::ngfmdmasync(uint64_t TuneFrequency,uint32_t SampleRate,int Channel,uint32_t FifoSize):bufferdma(Channel,FifoSize,2,1) ngfmdmasync::ngfmdmasync(uint64_t TuneFrequency,uint32_t SR,int Channel,uint32_t FifoSize):bufferdma(Channel,FifoSize,2,1)
{ {
SampleRate=SR;
tunefreq=TuneFrequency; tunefreq=TuneFrequency;
clkgpio::SetAdvancedPllMode(true); clkgpio::SetAdvancedPllMode(true);
clkgpio::SetCenterFrequency(TuneFrequency,SampleRate); // Write Mult Int and Frac : FixMe carrier is already there clkgpio::SetCenterFrequency(TuneFrequency,SampleRate); // Write Mult Int and Frac : FixMe carrier is already there
@ -114,4 +116,34 @@ void ngfmdmasync::SetFrequencySample(uint32_t Index,double Frequency)
PushSample(Index); PushSample(Index);
} }
void ngfmdmasync::SetFrequencySamples(double *sample,size_t Size)
{
size_t NbWritten=0;
int OSGranularity=100;
while(NbWritten<Size)
{
int Available=GetBufferAvailable();
int TimeToSleep=1e6*((int)buffersize*3/4-Available-OSGranularity)/SampleRate; // Sleep for theorically fill 3/4 of Fifo
if(TimeToSleep>0)
{
//fprintf(stderr,"buffer size %d Available %d SampleRate %d Sleep %d\n",buffersize,Available,SampleRate,TimeToSleep);
usleep(TimeToSleep);
}
else
{
//fprintf(stderr,"No Sleep %d\n",TimeToSleep);
sched_yield();
}
Available=GetBufferAvailable();
int Index=GetUserMemIndex();
int ToWrite=((int)Size-(int)NbWritten)<Available?Size-NbWritten:Available;
for(int i=0;i<ToWrite;i++)
{
SetFrequencySample(Index+i,sample[NbWritten++]);
}
}
}

View file

@ -10,13 +10,15 @@ class ngfmdmasync:public bufferdma,public clkgpio,public pwmgpio,public pcmgpio
protected: protected:
uint64_t tunefreq; uint64_t tunefreq;
bool syncwithpwm; bool syncwithpwm;
uint32_t SampleRate;
public: public:
ngfmdmasync(uint64_t TuneFrequency,uint32_t SampleRate,int Channel,uint32_t FifoSize); ngfmdmasync(uint64_t TuneFrequency,uint32_t SR,int Channel,uint32_t FifoSize);
~ngfmdmasync(); ~ngfmdmasync();
void SetDmaAlgo(); void SetDmaAlgo();
void SetPhase(bool inversed); void SetPhase(bool inversed);
void SetFrequencySample(uint32_t Index,double Frequency); void SetFrequencySample(uint32_t Index,double Frequency);
void SetFrequencySamples(double *sample,size_t Size);
}; };
#endif #endif