First test of fm dma - Not tested

v2beta
F5OEO 2018-02-27 12:17:02 +00:00
rodzic 5c2deb23e1
commit 61afc7962e
4 zmienionych plików z 67 dodań i 6 usunięć

Wyświetl plik

@ -1,12 +1,56 @@
#include "stdio.h"
#include "fmdmasync.h"
#include "gpio.h" //for definition of registers
fmdmasync::fmdmasync(int Channel,uint32_t FifoSize):dma(Channel,FifoSize*2,FifoSize)
{
SetDmaAlgo();
FillMemory(12,1472);
}
fmdmasync::~fmdmasync()
{
}
void fmdmasync::SetDmaAlgo()
{
dma_cb_t *cbp = cbarray;
for (uint32_t samplecnt = 0; samplecnt < cbsize/2; samplecnt++) { //cbsize/2 because we have 2 CB by sample
// Write a frequency sample
cbp->info = BCM2708_DMA_NO_WIDE_BURSTS /* BCM2708_DMA_WAIT_RESP |BCM2708_DMA_D_DREQ | BCM2708_DMA_PER_MAP(5)*/;
cbp->src = mem_virt_to_phys(&usermem[samplecnt]);
cbp->dst = 0x7E000000 | GPCLK_DIV | CLK_BASE ;
cbp->length = 4;
cbp->stride = 0;
cbp->next = mem_virt_to_phys(cbp + 1);
//printf("cbp : sample %x src %x dest %x next %x\n",ctl->sample + i,cbp->src,cbp->dst,cbp->next);
cbp++;
// Delay
cbp->info = BCM2708_DMA_SRC_IGNOR |/* BCM2708_DMA_NO_WIDE_BURSTS | BCM2708_DMA_WAIT_RESP |*/ BCM2708_DMA_D_DREQ | BCM2708_DMA_PER_MAP(2);
cbp->src = mem_virt_to_phys(usermem); // Data is not important as we use it only to feed the PWM
cbp->dst = 0x7E000000 | PWM_FIFO | PWM_BASE ;
cbp->length = 4;
cbp->stride = 0;
cbp->next = mem_virt_to_phys(cbp + 1);
cbp++;
}
cbp--;
cbp->next = mem_virt_to_phys(cbarray); // We loop to the first CB
}
void fmdmasync::FillMemory(uint32_t FreqDivider,uint32_t FreqFractionnal)
{
for (uint32_t samplecnt = 0; samplecnt < usermemsize; samplecnt++)
{
usermem[samplecnt]=0x5A000000 | ((FreqDivider)<<12) | FreqFractionnal;
FreqFractionnal=(FreqFractionnal+1)%4096;
}
}

Wyświetl plik

@ -9,6 +9,8 @@ class fmdmasync:public dma
public:
fmdmasync(int Channel,uint32_t FifoSize);
~fmdmasync();
void SetDmaAlgo();
void FillMemory(uint32_t FreqDivider,uint32_t FreqFractionnal);
};
#endif

Wyświetl plik

@ -100,7 +100,7 @@ int clkgpio::SetFrequency(uint64_t Frequency)
uint32_t FreqDivider=(uint32_t)Freqresult;
uint32_t FreqFractionnal=(uint32_t) (4096*(Freqresult-(double)FreqDivider));
if((FreqDivider>4096)||(FreqDivider<2)) fprintf(stderr,"Frequency out of range\n");
//printf("DIV/FRAC %u/%u \n",FreqDivider,FreqFractionnal);
printf("DIV/FRAC %u/%u \n",FreqDivider,FreqFractionnal);
gpioreg[GPCLK_DIV] = 0x5A000000 | ((FreqDivider)<<12) | FreqFractionnal;
//gpioreg[GPCLK_CNTL]= 0x5A000000 | (Mash << 9) | pllnumber |4 ; //4 is START CLK

Wyświetl plik

@ -1,6 +1,7 @@
#include <unistd.h>
#include "dma.h"
#include "gpio.h"
#include "fmdmasync.h"
int main(int argc, char* argv[])
{
@ -10,9 +11,23 @@ int main(int argc, char* argv[])
generalgpio generalio;
generalio.enableclk();
for(int i=0;i<100;i++)
pwmgpio pwm;
pwm.SetPllNumber(clk_plld,1);
pwm.SetFrequency(1000000);
pwm.SetMode(0);
clk.SetFrequency(89000000);
fmdmasync fmtest(14,4000);
fmtest.start();
sleep(20);
fmtest.stop();
/*
{
usleep(40000);
clk.SetFrequency(89000000+i*40);
}
for(int i=0;i<10000;i++)
{
usleep(50);
clk.SetFrequency(89000000+(i%2)*200000);
}
}*/
}