kopia lustrzana https://github.com/F5OEO/rpitx
Dma issue
rodzic
11af187182
commit
d0d2fd9aff
|
@ -1,5 +1,5 @@
|
|||
#all: ../rpitx ../pissb ../pisstv ../pifsq ../pifm ../piam ../pidcf77 ../piopera
|
||||
all: ../rpitx v2rpitx
|
||||
all: v2rpitx
|
||||
|
||||
#CFLAGS = -Wall -g -O2 -D DIGITHIN
|
||||
CFLAGS = -Wall -g -O2 -Wno-unused-variable
|
||||
|
@ -10,7 +10,7 @@ LDFLAGS = -lm -lrt -lpthread
|
|||
$(CC) $(CFLAGS) -o ../rpitx RpiTx.c RpiGpio.c mailbox.c RpiDma.c raspberry_pi_revision.c $(LDFLAGS)
|
||||
|
||||
|
||||
CFLAGS = -Wall -g -O2 -Wno-unused-variable
|
||||
CFLAGS = -Wall -g -O0 -Wno-unused-variable
|
||||
LDFLAGS = -lm -lrt -lpthread
|
||||
CCP = g++
|
||||
CC = gcc
|
||||
|
@ -60,7 +60,7 @@ LDFLAGS_Piopera = -lm
|
|||
|
||||
clean:
|
||||
|
||||
rm -f ../rpitx ../pissb ../pisstv ../pifsq ../pifm ../piam ../pidcf77 RpiTx.o mailbox.o RpiGpio.o RpiDma.o
|
||||
rm -f ../rpitx ../pissb ../pisstv ../pifsq ../pifm ../piam ../pidcf77 v2rpitx RpiTx.o mailbox.o RpiGpio.o RpiDma.o
|
||||
|
||||
install: all
|
||||
install -m 0755 ../pisstv /usr/bin
|
||||
|
|
46
src/dma.cpp
46
src/dma.cpp
|
@ -122,10 +122,14 @@ int dma::stop()
|
|||
return 0;
|
||||
}
|
||||
|
||||
uint32_t dma::getcbposition()
|
||||
int dma::getcbposition()
|
||||
{
|
||||
|
||||
return mem_phys_to_virt((uint32_t)(dma_reg.gpioreg[DMA_CONBLK_AD+channel*0x40]))-(uint32_t)virtbase;
|
||||
volatile uint32_t dmacb=(uint32_t)(dma_reg.gpioreg[DMA_CONBLK_AD+channel*0x40]);
|
||||
//fprintf(stderr,"cb=%x\n",dmacb);
|
||||
if(dmacb>0)
|
||||
return mem_phys_to_virt(dmacb)-(uint32_t)virtbase;
|
||||
else
|
||||
return -1;
|
||||
// dma_reg.gpioreg[DMA_CONBLK_AD+channel*0x40]-mem_virt_to_phys((void *)cbarray );
|
||||
}
|
||||
|
||||
|
@ -140,7 +144,7 @@ bufferdma::bufferdma(int Channel,uint32_t tbuffersize,uint32_t tcbbysample,uint3
|
|||
buffersize=tbuffersize;
|
||||
cbbysample=tcbbysample;
|
||||
registerbysample=tregisterbysample;
|
||||
fprintf(stderr,"BufferSize %d , cb %d user %d\n",tbuffersize,tbuffersize*cbbysample,tbuffersize*registerbysample);
|
||||
fprintf(stderr,"BufferSize %d , cb %d user %d\n",buffersize,buffersize*cbbysample,buffersize*registerbysample);
|
||||
|
||||
|
||||
|
||||
|
@ -157,24 +161,37 @@ void bufferdma::SetDmaAlgo()
|
|||
|
||||
|
||||
|
||||
uint32_t bufferdma::GetBufferAvailable()
|
||||
int bufferdma::GetBufferAvailable()
|
||||
{
|
||||
int diffsample=0;
|
||||
if(isrunning())
|
||||
{
|
||||
current_sample=getcbposition()/cbbysample;
|
||||
int diffsample=current_sample-last_sample;
|
||||
if(diffsample<0)
|
||||
diffsample+=buffersize;
|
||||
int CurrenCbPos=getcbposition();
|
||||
if(CurrenCbPos!=-1)
|
||||
{
|
||||
current_sample=CurrenCbPos/(sizeof(dma_cb_t)*cbbysample);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr,"DMA Stopped\n");
|
||||
current_sample=0;
|
||||
}
|
||||
//fprintf(stderr,"CurrentCB=%d\n",current_sample);
|
||||
diffsample=current_sample-last_sample;
|
||||
if(diffsample<=0) diffsample+=buffersize;
|
||||
|
||||
fprintf(stderr,"cur %d last %d diff%d\n",current_sample,last_sample,diffsample);
|
||||
}
|
||||
else
|
||||
{
|
||||
last_sample=(buffersize-1)*cbbysample;
|
||||
last_sample=buffersize-1;
|
||||
diffsample=buffersize;
|
||||
current_sample=0;
|
||||
fprintf(stderr,"Warning DMA stopped\n");
|
||||
fprintf(stderr,"Warning DMA stopped \n");
|
||||
fprintf(stderr,"cur %d last %d diff%d\n",current_sample,last_sample,diffsample);
|
||||
}
|
||||
return (uint32_t)diffsample;
|
||||
|
||||
return diffsample;
|
||||
|
||||
}
|
||||
|
||||
|
@ -182,10 +199,11 @@ int bufferdma::GetUserMemIndex()
|
|||
{
|
||||
|
||||
int IndexAvailable=-1;
|
||||
//fprintf(stderr,"Avail=%d\n",GetBufferAvailable());
|
||||
if(GetBufferAvailable()>0)
|
||||
{
|
||||
IndexAvailable=last_sample+1;
|
||||
if(IndexAvailable==(int)buffersize) IndexAvailable=0;
|
||||
if(IndexAvailable>=(int)buffersize-1) IndexAvailable=0;
|
||||
}
|
||||
return IndexAvailable;
|
||||
}
|
||||
|
@ -205,7 +223,7 @@ int bufferdma::PushSample(int Index)
|
|||
*/
|
||||
if(isrunning()==false)
|
||||
{
|
||||
//start();
|
||||
start();
|
||||
}
|
||||
return 0;
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ class dma
|
|||
void GetRpiInfo();
|
||||
int start();
|
||||
int stop();
|
||||
uint32_t getcbposition();
|
||||
int getcbposition();
|
||||
bool isrunning();
|
||||
|
||||
};
|
||||
|
@ -112,7 +112,7 @@ class bufferdma:public dma
|
|||
public:
|
||||
bufferdma(int Channel,uint32_t tbuffersize,uint32_t tcbbysample,uint32_t tregisterbysample);
|
||||
void SetDmaAlgo();
|
||||
uint32_t GetBufferAvailable();
|
||||
int GetBufferAvailable();
|
||||
int GetUserMemIndex();
|
||||
int PushSample(int Index);
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ ngfmdmasync::ngfmdmasync(uint64_t TuneFrequency,uint32_t SampleRate,int Channel,
|
|||
|
||||
|
||||
|
||||
//SetDmaAlgo();
|
||||
SetDmaAlgo();
|
||||
|
||||
//FillMemory(IntMultiply,FracMultiply);
|
||||
|
||||
|
@ -61,7 +61,7 @@ void ngfmdmasync::SetDmaAlgo()
|
|||
// Write INT Mult
|
||||
/*
|
||||
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+1]);
|
||||
cbp->dst = 0x7E000000 + (PLLA_CTRL<<2) + CLK_BASE ;
|
||||
cbp->length = 4;
|
||||
cbp->stride = 0;
|
||||
|
@ -78,7 +78,7 @@ void ngfmdmasync::SetDmaAlgo()
|
|||
cbp->length = 4;
|
||||
cbp->stride = 0;
|
||||
cbp->next = mem_virt_to_phys(cbp + 1);
|
||||
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++;
|
||||
|
||||
|
||||
|
@ -90,7 +90,7 @@ void ngfmdmasync::SetDmaAlgo()
|
|||
cbp->length = 4;
|
||||
cbp->stride = 0;
|
||||
cbp->next = mem_virt_to_phys(cbp + 1);
|
||||
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++;
|
||||
}
|
||||
|
||||
|
@ -102,6 +102,7 @@ void ngfmdmasync::SetDmaAlgo()
|
|||
void ngfmdmasync::SetFrequencySample(uint32_t Index,int Frequency)
|
||||
{
|
||||
sampletab[Index]=(0x5A<<24)|GetMasterFrac(Frequency);
|
||||
//fprintf(stderr,"Frac=%d\n",GetMasterFrac(Frequency));
|
||||
PushSample(Index);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,8 +10,8 @@ int main(int argc, char* argv[])
|
|||
|
||||
generalgpio generalio;
|
||||
generalio.enableclk();
|
||||
|
||||
/*clkgpio clk;
|
||||
/*
|
||||
clkgpio clk;
|
||||
clk.SetPllNumber(clk_plld,1);
|
||||
clk.SetAdvancedPllMode(true);
|
||||
clk.SetCenterFrequency(144100000);
|
||||
|
@ -20,29 +20,31 @@ int main(int argc, char* argv[])
|
|||
clk.SetFrequency(i);
|
||||
usleep(10);
|
||||
}
|
||||
sleep(5);*/
|
||||
sleep(5);
|
||||
*/
|
||||
|
||||
//dma mydma(14,32,16);
|
||||
//bufferdma mydma(14,16,2,1);
|
||||
|
||||
ngfmdmasync ngfmtest(144100000,5000,14,16);
|
||||
ngfmdmasync ngfmtest(144100000,5000,14,128);
|
||||
|
||||
for(int i=0;i<10;i++)
|
||||
for(int i=0;i<256;i++)
|
||||
{
|
||||
int Index=ngfmtest.GetUserMemIndex();
|
||||
//printf("GetIndex=%d\n",Index);
|
||||
if(Index>=0)
|
||||
{
|
||||
ngfmtest.SetFrequencySample(Index,i);
|
||||
ngfmtest.SetFrequencySample(Index,i*10);
|
||||
|
||||
}
|
||||
else
|
||||
usleep(100);
|
||||
usleep(10);
|
||||
}
|
||||
fprintf(stderr,"End\n");
|
||||
sleep(10);
|
||||
ngfmtest.stop();
|
||||
|
||||
|
||||
|
||||
|
||||
// Test Fmdmasync
|
||||
/*
|
||||
|
|
Ładowanie…
Reference in New Issue