From 887470a7be267580109bda8e90f9776cfd110e59 Mon Sep 17 00:00:00 2001 From: F5OEO Date: Mon, 17 Dec 2018 12:46:17 +0000 Subject: [PATCH] Initial ook support --- app/testrpitx.cpp | 51 +++++++----------- src/Makefile | 6 +-- src/librpitx.h | 2 +- src/ookburst.cpp | 129 ++++++++++++++++++++++++++++++++++++++++++++++ src/ookburst.h | 23 +++++++++ 5 files changed, 175 insertions(+), 36 deletions(-) create mode 100644 src/ookburst.cpp create mode 100644 src/ookburst.h diff --git a/app/testrpitx.cpp b/app/testrpitx.cpp index 1cbf101..43c5f9a 100644 --- a/app/testrpitx.cpp +++ b/app/testrpitx.cpp @@ -155,7 +155,7 @@ void SimpleTestFileIQ(uint64_t Freq) bool stereo=true; int SR=48000; int FifoSize=512; - iqdmasync iqtest(Freq,SR,14,FifoSize); + iqdmasync iqtest(Freq,SR,14,FifoSize,MODE_IQ); short IQBuffer[IQBURST*2]; std::complex CIQBuffer[IQBURST]; while(running) @@ -303,36 +303,23 @@ void SimpleTestOOK(uint64_t Freq) { int SR=2000; - int FifoSize=512; - amdmasync amtest(Freq,SR,14,FifoSize); - - - int count=0; - int Every=SR/100; - float x=0.0; - + int FifoSize=2000; + ookburst ook(Freq,SR,14,FifoSize); + unsigned char TabSymbol[FifoSize]; + for(size_t i=0;i256) - { - int Index=amtest.GetUserMemIndex(); - for(int i=0;i2000) count=0; - } - } - } - amtest.stop(); + ook.SetSymbols(TabSymbol,FifoSize); + // sleep(2); + } + } void SimpleTestBurstFsk(uint64_t Freq) @@ -382,7 +369,7 @@ int main(int argc, char* argv[]) uint64_t Freq=144200000; if(argc>1) - Freq=atol(argv[1]); + Freq=atof(argv[1]); for (int i = 0; i < 64; i++) { struct sigaction sa; @@ -393,11 +380,11 @@ int main(int argc, char* argv[]) } //SimpleTest(Freq); - SimpleTestbpsk(Freq); + //SimpleTestbpsk(Freq); //SimpleTestFileIQ(Freq); //SimpleTestDMA(Freq); //SimpleTestAm(Freq); - //SimpleTestOOK(Freq); + SimpleTestOOK(Freq); //SimpleTestBurstFsk(Freq); } diff --git a/src/Makefile b/src/Makefile index c6132e0..c6113bf 100644 --- a/src/Makefile +++ b/src/Makefile @@ -4,11 +4,11 @@ LDFLAGS = -lm -lrt -lpthread CCP = c++ CC = cc -librpitx: librpitx.h gpio.h gpio.cpp dma.h dma.cpp mailbox.c raspberry_pi_revision.c fmdmasync.h fmdmasync.cpp ngfmdmasync.h ngfmdmasync.cpp dsp.h dsp.cpp iqdmasync.h iqdmasync.cpp serialdmasync.h serialdmasync.cpp phasedmasync.h phasedmasync.cpp fskburst.h fskburst.cpp +librpitx: librpitx.h gpio.h gpio.cpp dma.h dma.cpp mailbox.c raspberry_pi_revision.c fmdmasync.h fmdmasync.cpp ngfmdmasync.h ngfmdmasync.cpp dsp.h dsp.cpp iqdmasync.h iqdmasync.cpp serialdmasync.h serialdmasync.cpp phasedmasync.h phasedmasync.cpp fskburst.h fskburst.cpp ookburst.cpp ookburst.h $(CC) $(CFLAGS) -c -o mailbox.o mailbox.c $(CC) $(CFLAGS) -c -o raspberry_pi_revision.o raspberry_pi_revision.c - $(CCP) $(CXXFLAGS) -c dsp.cpp iqdmasync.cpp ngfmdmasync.cpp fmdmasync.cpp dma.cpp gpio.cpp serialdmasync.cpp phasedmasync.cpp amdmasync.h amdmasync.cpp fskburst.cpp - $(AR) rc librpitx.a dsp.o iqdmasync.o ngfmdmasync.o fmdmasync.o dma.o gpio.o mailbox.o raspberry_pi_revision.o serialdmasync.o phasedmasync.o amdmasync.o fskburst.o + $(CCP) $(CXXFLAGS) -c dsp.cpp iqdmasync.cpp ngfmdmasync.cpp fmdmasync.cpp dma.cpp gpio.cpp serialdmasync.cpp phasedmasync.cpp amdmasync.h amdmasync.cpp fskburst.cpp ookburst.cpp + $(AR) rc librpitx.a dsp.o iqdmasync.o ngfmdmasync.o fmdmasync.o dma.o gpio.o mailbox.o raspberry_pi_revision.o serialdmasync.o phasedmasync.o amdmasync.o fskburst.o ookburst.o install: librpitx diff --git a/src/librpitx.h b/src/librpitx.h index 8ad35cb..5aaebb3 100644 --- a/src/librpitx.h +++ b/src/librpitx.h @@ -25,4 +25,4 @@ This program is free software: you can redistribute it and/or modify #include "amdmasync.h" #include "fskburst.h" #include "dsp.h" - \ No newline at end of file +#include "ookburst.h" \ No newline at end of file diff --git a/src/ookburst.cpp b/src/ookburst.cpp new file mode 100644 index 0000000..2ec6de2 --- /dev/null +++ b/src/ookburst.cpp @@ -0,0 +1,129 @@ +/* +Copyright (C) 2018 Evariste COURJAUD F5OEO + +This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "stdio.h" +#include +#include "ookburst.h" + + + ookburst::ookburst(uint64_t TuneFrequency,uint32_t SymbolRate,int Channel,uint32_t FifoSize):bufferdma(Channel,FifoSize+1,2,1) + { + + clkgpio::SetAdvancedPllMode(true); + + clkgpio::SetCenterFrequency(TuneFrequency,SymbolRate); // Write Mult Int and Frac : FixMe carrier is already there + clkgpio::SetFrequency(0); + + syncwithpwm=false; + + if(syncwithpwm) + { + pwmgpio::SetPllNumber(clk_plld,1); + pwmgpio::SetFrequency(SymbolRate); + } + else + { + pcmgpio::SetPllNumber(clk_plld,1); + pcmgpio::SetFrequency(SymbolRate); + } + + + + SetDmaAlgo(); + + padgpio pad; + Originfsel=pad.gpioreg[PADS_GPIO_0]; + } + + ookburst::~ookburst() + { + } + + void ookburst::SetDmaAlgo() +{ + dma_cb_t *cbp=cbarray; + for (uint32_t samplecnt = 0; samplecnt < buffersize-1; samplecnt++) + { + + + //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]); + cbp->dst = 0x7E000000 + (GPFSEL0<<2)+GENERAL_BASE; + cbp->length = 4; + cbp->stride = 0; + cbp->next = mem_virt_to_phys(cbp + 1); + cbp++; + + + // Delay + if(syncwithpwm) + cbp->info = BCM2708_DMA_NO_WIDE_BURSTS | BCM2708_DMA_WAIT_RESP |BCM2708_DMA_D_DREQ | BCM2708_DMA_PER_MAP(DREQ_PWM); + 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 the PWM + if(syncwithpwm) + cbp->dst = 0x7E000000 + (PWM_FIFO<<2) + PWM_BASE ; + else + cbp->dst = 0x7E000000 + (PCM_FIFO_A<<2) + PCM_BASE ; + 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); + cbp++; + + } + lastcbp=cbp; + + // Last CBP before stopping : disable output + sampletab[buffersize*registerbysample-1]=(Originfsel & ~(7 << 12)) | (0 << 12); //Disable Clk + cbp->info = BCM2708_DMA_NO_WIDE_BURSTS | BCM2708_DMA_WAIT_RESP ; + cbp->src = mem_virt_to_phys(&usermem[(buffersize*registerbysample-1)]); + cbp->dst = 0x7E000000 + (GPFSEL0<<2)+GENERAL_BASE; + cbp->length = 4; + cbp->stride = 0; + cbp->next = 0; // Stop DMA + + //fprintf(stderr,"Last cbp %p: src %x dest %x next %x\n",cbp,cbp->src,cbp->dst,cbp->next); +} + void ookburst::SetSymbols(unsigned char *Symbols,uint32_t Size) + { + if(Size>buffersize-1) {fprintf(stderr,"Buffer overflow\n");return;} + + dma_cb_t *cbp=cbarray; + for(unsigned int i=0;inext = mem_virt_to_phys(cbp + 1); + + } + cbp->next = mem_virt_to_phys(lastcbp); + + + dma::start(); + + while(isrunning()) //Block function : return until sent completely signal + { + usleep(100); + + } + + } + diff --git a/src/ookburst.h b/src/ookburst.h new file mode 100644 index 0000000..438f3c2 --- /dev/null +++ b/src/ookburst.h @@ -0,0 +1,23 @@ +#ifndef DEF_OOKBURST +#define DEF_OOKBURST + +#include "stdint.h" +#include "dma.h" +#include "gpio.h" + +class ookburst:public bufferdma,public clkgpio,public pwmgpio,public pcmgpio +{ + protected: + float timegranularity; //ns + uint32_t Originfsel; + bool syncwithpwm; + dma_cb_t *lastcbp; + public: + ookburst(uint64_t TuneFrequency,uint32_t SymbolRate,int Channel,uint32_t FifoSize); + ~ookburst(); + void SetDmaAlgo(); + + void SetSymbols(unsigned char *Symbols,uint32_t Size); +}; + +#endif