Add debug measurement fo max samplerate (200K on pi2)

This commit is contained in:
F5OEO 2018-08-06 09:28:40 +00:00
parent 7a199b0b8d
commit 8f2a63004f
3 changed files with 63 additions and 22 deletions

View file

@ -84,7 +84,7 @@ void dma::GetRpiInfo()
{ {
dram_phys_base = 0xc0000000; dram_phys_base = 0xc0000000;
mem_flag = MEM_FLAG_L1_NONALLOCATING/*MEM_FLAG_DIRECT*/|MEM_FLAG_HINT_PERMALOCK|MEM_FLAG_NO_INIT;//0x04; mem_flag = MEM_FLAG_DIRECT|MEM_FLAG_HINT_PERMALOCK|MEM_FLAG_NO_INIT;// 0x04;
} }
} }
else else

View file

@ -80,9 +80,11 @@ void iqdmasync::SetDmaAlgo()
for (uint32_t samplecnt = 0; samplecnt < buffersize; samplecnt++) for (uint32_t samplecnt = 0; samplecnt < buffersize; samplecnt++)
{ {
//@0 //@0
//Set Amplitude by writing to PADS //Set Amplitude by writing to PADS
cbp->info = 0;//BCM2708_DMA_NO_WIDE_BURSTS | BCM2708_DMA_WAIT_RESP ; cbp->info = BCM2708_DMA_NO_WIDE_BURSTS | BCM2708_DMA_WAIT_RESP ;
cbp->src = mem_virt_to_phys(&usermem[samplecnt*registerbysample+1]); cbp->src = mem_virt_to_phys(&usermem[samplecnt*registerbysample+1]);
cbp->dst = 0x7E000000+(PADS_GPIO_0<<2)+PADS_GPIO; cbp->dst = 0x7E000000+(PADS_GPIO_0<<2)+PADS_GPIO;
cbp->length = 4; cbp->length = 4;
@ -90,17 +92,7 @@ void iqdmasync::SetDmaAlgo()
cbp->next = mem_virt_to_phys(cbp + 1); cbp->next = mem_virt_to_phys(cbp + 1);
cbp++; cbp++;
//@1 //@2 Write a frequency sample : Order of DMA CS influence maximum rate : here 0,2,1 is the best : why !!!!!!
//Set Amplitude to FSEL for amplitude=0
cbp->info = 0;//BCM2708_DMA_NO_WIDE_BURSTS | BCM2708_DMA_WAIT_RESP ;
cbp->src = mem_virt_to_phys(&usermem[samplecnt*registerbysample+2]);
cbp->dst = 0x7E000000 + (GPFSEL0<<2)+GENERAL_BASE;
cbp->length = 4;
cbp->stride = 0;
cbp->next = mem_virt_to_phys(cbp + 1);
cbp++;
//@2 Write a frequency sample
cbp->info = BCM2708_DMA_NO_WIDE_BURSTS | BCM2708_DMA_WAIT_RESP ; cbp->info = BCM2708_DMA_NO_WIDE_BURSTS | BCM2708_DMA_WAIT_RESP ;
cbp->src = mem_virt_to_phys(&usermem[samplecnt*registerbysample]); cbp->src = mem_virt_to_phys(&usermem[samplecnt*registerbysample]);
@ -111,13 +103,25 @@ void iqdmasync::SetDmaAlgo()
//fprintf(stderr,"cbp : sample %x src %x dest %x next %x\n",samplecnt,cbp->src,cbp->dst,cbp->next); //fprintf(stderr,"cbp : sample %x src %x dest %x next %x\n",samplecnt,cbp->src,cbp->dst,cbp->next);
cbp++; cbp++;
//@1
//Set Amplitude to FSEL for amplitude=0
cbp->info = BCM2708_DMA_NO_WIDE_BURSTS | BCM2708_DMA_WAIT_RESP ;
cbp->src = mem_virt_to_phys(&usermem[samplecnt*registerbysample+2]);
cbp->dst = 0x7E000000 + (GPFSEL0<<2)+GENERAL_BASE;
cbp->length = 4;
cbp->stride = 0;
cbp->next = mem_virt_to_phys(cbp + 1);
cbp++;
//@3 Delay //@3 Delay
if(syncwithpwm) if(syncwithpwm)
cbp->info = BCM2708_DMA_NO_WIDE_BURSTS | BCM2708_DMA_WAIT_RESP |BCM2708_DMA_D_DREQ | BCM2708_DMA_PER_MAP(DREQ_PWM); cbp->info = BCM2708_DMA_NO_WIDE_BURSTS | BCM2708_DMA_WAIT_RESP |BCM2708_DMA_D_DREQ | BCM2708_DMA_PER_MAP(DREQ_PWM);
else else
cbp->info = BCM2708_DMA_NO_WIDE_BURSTS | BCM2708_DMA_WAIT_RESP |BCM2708_DMA_D_DREQ | BCM2708_DMA_PER_MAP(DREQ_PCM_TX); cbp->info =BCM2708_DMA_NO_WIDE_BURSTS | BCM2708_DMA_WAIT_RESP |BCM2708_DMA_D_DREQ | BCM2708_DMA_PER_MAP(DREQ_PCM_TX);
cbp->src = mem_virt_to_phys(cbarray); // Data is not important as we use it only to feed the PWM cbp->src = mem_virt_to_phys(&usermem[(samplecnt+1)*registerbysample]);//mem_virt_to_phys(cbarray); // Data is not important as we use it only to feed the PWM
if(syncwithpwm) if(syncwithpwm)
cbp->dst = 0x7E000000 + (PWM_FIFO<<2) + PWM_BASE ; cbp->dst = 0x7E000000 + (PWM_FIFO<<2) + PWM_BASE ;
else else
@ -143,7 +147,7 @@ void iqdmasync::SetIQSample(uint32_t Index,std::complex<float> sample,int Harmon
/*if(mydsp.frequency>2250) mydsp.frequency=2250; /*if(mydsp.frequency>2250) mydsp.frequency=2250;
if(mydsp.frequency<1000) mydsp.frequency=1000;*/ if(mydsp.frequency<1000) mydsp.frequency=1000;*/
sampletab[Index*registerbysample]=(0x5A<<24)|GetMasterFrac(mydsp.frequency/Harmonic); //Frequency sampletab[Index*registerbysample]=(0x5A<<24)|GetMasterFrac(mydsp.frequency/Harmonic); //Frequency
int IntAmplitude=(int)(mydsp.amplitude*1e4*8.0)-1; //Fixme 1e4 seems to work with SSB but should be an issue with classical IQ file int IntAmplitude=(int)(mydsp.amplitude*8.0)-1; //Fixme 1e4 seems to work with SSB but should be an issue with classical IQ file
int IntAmplitudePAD=0; int IntAmplitudePAD=0;
if(IntAmplitude>7) IntAmplitudePAD=7; if(IntAmplitude>7) IntAmplitudePAD=7;
@ -168,10 +172,25 @@ void iqdmasync::SetIQSamples(std::complex<float> *sample,size_t Size,int Harmoni
{ {
size_t NbWritten=0; size_t NbWritten=0;
int OSGranularity=100; int OSGranularity=100;
long int start_time;
long time_difference=0;
struct timespec gettime_now;
int debug=1;
while(NbWritten<Size) while(NbWritten<Size)
{ {
if(debug>0)
{
clock_gettime(CLOCK_REALTIME, &gettime_now);
start_time = gettime_now.tv_nsec;
}
int Available=GetBufferAvailable(); int Available=GetBufferAvailable();
int TimeToSleep=1e6*((int)buffersize*3/4-Available-OSGranularity)/SampleRate; // Sleep for theorically fill 3/4 of Fifo //printf("Available before=%d\n",Available);
int TimeToSleep=1e6*((int)buffersize*3/4-Available)/(float)SampleRate/*-OSGranularity*/; // Sleep for theorically fill 3/4 of Fifo
if(TimeToSleep>0) if(TimeToSleep>0)
{ {
//fprintf(stderr,"buffer size %d Available %d SampleRate %d Sleep %d\n",buffersize,Available,SampleRate,TimeToSleep); //fprintf(stderr,"buffer size %d Available %d SampleRate %d Sleep %d\n",buffersize,Available,SampleRate,TimeToSleep);
@ -179,15 +198,26 @@ void iqdmasync::SetIQSamples(std::complex<float> *sample,size_t Size,int Harmoni
} }
else else
{ {
//fprintf(stderr,"No Sleep %d\n",TimeToSleep); fprintf(stderr,"No Sleep %d\n",TimeToSleep);
sched_yield(); //sched_yield();
}
if(debug>0)
{
clock_gettime(CLOCK_REALTIME, &gettime_now);
time_difference = gettime_now.tv_nsec - start_time;
if(time_difference<0) time_difference+=1E9;
//fprintf(stderr,"Available %d Measure samplerate=%d\n",GetBufferAvailable(),(int)((GetBufferAvailable()-Available)*1e9/time_difference));
debug--;
} }
Available=GetBufferAvailable(); Available=GetBufferAvailable();
int Index=GetUserMemIndex(); int Index=GetUserMemIndex();
int ToWrite=((int)Size-(int)NbWritten)<Available?Size-NbWritten:Available; int ToWrite=((int)Size-(int)NbWritten)<Available?Size-NbWritten:Available;
//printf("Available after=%d Timetosleep %d To Write %d\n",Available,TimeToSleep,ToWrite);
for(int i=0;i<ToWrite;i++) for(int i=0;i<ToWrite;i++)
{ {
SetIQSample(Index+i,sample[NbWritten++],Harmonic); SetIQSample(Index+i,sample[NbWritten++],Harmonic);
} }

View file

@ -21,7 +21,7 @@ This program is free software: you can redistribute it and/or modify
#include "ngfmdmasync.h" #include "ngfmdmasync.h"
#include <unistd.h> #include <unistd.h>
#include <sched.h> #include <sched.h>
#include <time.h>
ngfmdmasync::ngfmdmasync(uint64_t TuneFrequency,uint32_t SR,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)
{ {
@ -120,10 +120,17 @@ void ngfmdmasync::SetFrequencySamples(float *sample,size_t Size)
{ {
size_t NbWritten=0; size_t NbWritten=0;
int OSGranularity=100; int OSGranularity=100;
long int start_time;
long time_difference=0;
struct timespec gettime_now;
while(NbWritten<Size) while(NbWritten<Size)
{ {
clock_gettime(CLOCK_REALTIME, &gettime_now);
start_time = gettime_now.tv_nsec;
int Available=GetBufferAvailable(); int Available=GetBufferAvailable();
int TimeToSleep=1e6*((int)buffersize*3/4-Available-OSGranularity)/SampleRate; // Sleep for theorically fill 3/4 of Fifo int TimeToSleep=1e6*((int)buffersize*3/4-Available)/SampleRate-OSGranularity; // Sleep for theorically fill 3/4 of Fifo
if(TimeToSleep>0) if(TimeToSleep>0)
{ {
//fprintf(stderr,"buffer size %d Available %d SampleRate %d Sleep %d\n",buffersize,Available,SampleRate,TimeToSleep); //fprintf(stderr,"buffer size %d Available %d SampleRate %d Sleep %d\n",buffersize,Available,SampleRate,TimeToSleep);
@ -134,6 +141,10 @@ void ngfmdmasync::SetFrequencySamples(float *sample,size_t Size)
//fprintf(stderr,"No Sleep %d\n",TimeToSleep); //fprintf(stderr,"No Sleep %d\n",TimeToSleep);
sched_yield(); sched_yield();
} }
clock_gettime(CLOCK_REALTIME, &gettime_now);
time_difference = gettime_now.tv_nsec - start_time;
if(time_difference<0) time_difference+=1E9;
//fprintf(stderr,"Measure samplerate=%d\n",(int)((GetBufferAvailable()-Available)*1e9/time_difference));
Available=GetBufferAvailable(); Available=GetBufferAvailable();
int Index=GetUserMemIndex(); int Index=GetUserMemIndex();
int ToWrite=((int)Size-(int)NbWritten)<Available?Size-NbWritten:Available; int ToWrite=((int)Size-(int)NbWritten)<Available?Size-NbWritten:Available;