From 1be11a70e3491d04006a3003a835ccaed0858940 Mon Sep 17 00:00:00 2001 From: F5OEO Date: Wed, 19 Dec 2018 10:16:40 +0000 Subject: [PATCH] Wokring ook , fixe fskburst --- app/testrpitx.cpp | 55 ++++++++++++++++++----------------------------- src/fskburst.cpp | 50 ++++++++++++++++++++++++++++++++++-------- src/ookburst.cpp | 55 ++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 107 insertions(+), 53 deletions(-) diff --git a/app/testrpitx.cpp b/app/testrpitx.cpp index 43c5f9a..b6a406a 100644 --- a/app/testrpitx.cpp +++ b/app/testrpitx.cpp @@ -302,22 +302,21 @@ void SimpleTestAm(uint64_t Freq) void SimpleTestOOK(uint64_t Freq) { - int SR=2000; - int FifoSize=2000; + int SR=1000; + int FifoSize=21; //24 ookburst ook(Freq,SR,14,FifoSize); - unsigned char TabSymbol[FifoSize]; - for(size_t i=0;i - - fskburst::fskburst(uint64_t TuneFrequency,uint32_t SymbolRate,float Deviation,int Channel,uint32_t FifoSize):bufferdma(Channel,FifoSize+2,2,1),freqdeviation(Deviation) + fskburst::fskburst(uint64_t TuneFrequency,uint32_t SymbolRate,float Deviation,int Channel,uint32_t FifoSize):bufferdma(Channel,FifoSize+3,2,1),freqdeviation(Deviation) { clkgpio::SetAdvancedPllMode(true); clkgpio::SetCenterFrequency(TuneFrequency,SymbolRate); // Write Mult Int and Frac : FixMe carrier is already there clkgpio::SetFrequency(0); - //clkgpio::enableclk(4); // GPIO 4 CLK by default + syncwithpwm=false; if(syncwithpwm) @@ -57,6 +57,31 @@ This program is free software: you can redistribute it and/or modify sampletab[buffersize*registerbysample-1]=(Originfsel & ~(7 << 12)) | (0 << 12); //Disable Clk dma_cb_t *cbp = cbarray; + // We must fill the FIFO (PWM or PCM) to be Synchronized from start + // PWM FIFO = 16 + // PCM FIFO = 64 + if(syncwithpwm) + { + cbp->info = BCM2708_DMA_NO_WIDE_BURSTS | BCM2708_DMA_WAIT_RESP |BCM2708_DMA_D_DREQ | BCM2708_DMA_PER_MAP(DREQ_PWM); + cbp->src = mem_virt_to_phys(cbarray); // Data is not important as we use it only to feed the PWM + cbp->dst = 0x7E000000 + (PWM_FIFO<<2) + PWM_BASE ; + cbp->length = 4*(16+1); + cbp->stride = 0; + cbp->next = mem_virt_to_phys(cbp + 1); + cbp++; + } + else + { + 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 PCM + cbp->dst = 0x7E000000 + (PCM_FIFO_A<<2) + PCM_BASE ; + cbp->length = 4*(64+1); + 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); + cbp++; + } + cbp->info = BCM2708_DMA_NO_WIDE_BURSTS | BCM2708_DMA_WAIT_RESP ; cbp->src = mem_virt_to_phys(&usermem[buffersize*registerbysample-2]); cbp->dst = 0x7E000000 + (GPFSEL0<<2)+GENERAL_BASE; @@ -110,21 +135,28 @@ This program is free software: you can redistribute it and/or modify } void fskburst::SetSymbols(unsigned char *Symbols,uint32_t Size) { - if(Size>buffersize-2) {fprintf(stderr,"Buffer overflow\n");return;} + if(Size>buffersize-3) {fprintf(stderr,"Buffer overflow\n");return;} - dma_cb_t *cbp=cbarray+1+1; + dma_cb_t *cbp=cbarray; + cbp+=2; // Skip the first 2 CB (initialisation) for(unsigned int i=0;inext = mem_virt_to_phys(cbp + 1); + cbp++; } + cbp--; cbp->next = mem_virt_to_phys(lastcbp); dma::start(); - - + while(isrunning()) //Block function : return until sent completely signal + { + usleep(100); + + } + usleep(100);//To be sure last symbol Tx ? + } diff --git a/src/ookburst.cpp b/src/ookburst.cpp index 2ec6de2..3cfce82 100644 --- a/src/ookburst.cpp +++ b/src/ookburst.cpp @@ -20,12 +20,12 @@ This program is free software: you can redistribute it and/or modify #include "ookburst.h" - ookburst::ookburst(uint64_t TuneFrequency,uint32_t SymbolRate,int Channel,uint32_t FifoSize):bufferdma(Channel,FifoSize+1,2,1) + ookburst::ookburst(uint64_t TuneFrequency,uint32_t SymbolRate,int Channel,uint32_t FifoSize):bufferdma(Channel,FifoSize+2,2,1) { clkgpio::SetAdvancedPllMode(true); - clkgpio::SetCenterFrequency(TuneFrequency,SymbolRate); // Write Mult Int and Frac : FixMe carrier is already there + clkgpio::SetCenterFrequency(TuneFrequency,0); // Bandwidth is 0 because frequency always the same clkgpio::SetFrequency(0); syncwithpwm=false; @@ -56,7 +56,32 @@ This program is free software: you can redistribute it and/or modify void ookburst::SetDmaAlgo() { dma_cb_t *cbp=cbarray; - for (uint32_t samplecnt = 0; samplecnt < buffersize-1; samplecnt++) + // We must fill the FIFO (PWM or PCM) to be Synchronized from start + // PWM FIFO = 16 + // PCM FIFO = 64 + if(syncwithpwm) + { + cbp->info = BCM2708_DMA_NO_WIDE_BURSTS | BCM2708_DMA_WAIT_RESP |BCM2708_DMA_D_DREQ | BCM2708_DMA_PER_MAP(DREQ_PWM); + cbp->src = mem_virt_to_phys(cbarray); // Data is not important as we use it only to feed the PWM + cbp->dst = 0x7E000000 + (PWM_FIFO<<2) + PWM_BASE ; + cbp->length = 4*(16+1); + cbp->stride = 0; + cbp->next = mem_virt_to_phys(cbp + 1); + cbp++; + } + else + { + 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 PCM + cbp->dst = 0x7E000000 + (PCM_FIFO_A<<2) + PCM_BASE ; + cbp->length = 4*(64+1); + 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); + cbp++; + } + + for (uint32_t samplecnt = 0; samplecnt < buffersize-2; samplecnt++) { @@ -83,7 +108,7 @@ This program is free software: you can redistribute it and/or modify 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 %d pointer %p src %x dest %x next %x\n",samplecnt,cbp,cbp->src,cbp->dst,cbp->next); cbp++; } @@ -102,28 +127,38 @@ This program is free software: you can redistribute it and/or modify } void ookburst::SetSymbols(unsigned char *Symbols,uint32_t Size) { - if(Size>buffersize-1) {fprintf(stderr,"Buffer overflow\n");return;} + if(Size>buffersize-2) {fprintf(stderr,"Buffer overflow\n");return;} dma_cb_t *cbp=cbarray; - for(unsigned int i=0;inext = mem_virt_to_phys(cbp + 1); + //fprintf(stderr,"cbp : sample %d pointer %p src %x dest %x next %x\n",i,cbp,cbp->src,cbp->dst,cbp->next); + cbp++; + } - cbp->next = mem_virt_to_phys(lastcbp); - + cbp--; + cbp->next = mem_virt_to_phys(lastcbp); + + dma::start(); + while(isrunning()) //Block function : return until sent completely signal { usleep(100); } + usleep(100);//To be sure last symbol Tx ? }