Initial ook support

This commit is contained in:
F5OEO 2018-12-17 12:46:17 +00:00
parent aa02b85060
commit 887470a7be
5 changed files with 175 additions and 36 deletions

View file

@ -155,7 +155,7 @@ void SimpleTestFileIQ(uint64_t Freq)
bool stereo=true; bool stereo=true;
int SR=48000; int SR=48000;
int FifoSize=512; int FifoSize=512;
iqdmasync iqtest(Freq,SR,14,FifoSize); iqdmasync iqtest(Freq,SR,14,FifoSize,MODE_IQ);
short IQBuffer[IQBURST*2]; short IQBuffer[IQBURST*2];
std::complex<float> CIQBuffer[IQBURST]; std::complex<float> CIQBuffer[IQBURST];
while(running) while(running)
@ -303,36 +303,23 @@ void SimpleTestOOK(uint64_t Freq)
{ {
int SR=2000; int SR=2000;
int FifoSize=512; int FifoSize=2000;
amdmasync amtest(Freq,SR,14,FifoSize); ookburst ook(Freq,SR,14,FifoSize);
unsigned char TabSymbol[FifoSize];
for(size_t i=0;i<FifoSize/2;i++)
int count=0; {
int Every=SR/100; TabSymbol[i]=i%2;
float x=0.0; }
for(size_t i=0;i<FifoSize/2;i++)
{
TabSymbol[i+FifoSize/2]=0;
}
while(running) while(running)
{ {
//usleep(FifoSize*1000000.0*1.0/(8.0*SR)); ook.SetSymbols(TabSymbol,FifoSize);
usleep(1); // sleep(2);
int Available=amtest.GetBufferAvailable();
if(Available>256)
{
int Index=amtest.GetUserMemIndex();
for(int i=0;i<Available;i++)
{
if(count<1000)
x=0;
else
x=1.0;
amtest.SetAmSample(Index+i,x);
count++;
if(count>2000) count=0;
}
}
} }
amtest.stop();
} }
void SimpleTestBurstFsk(uint64_t Freq) void SimpleTestBurstFsk(uint64_t Freq)
@ -382,7 +369,7 @@ int main(int argc, char* argv[])
uint64_t Freq=144200000; uint64_t Freq=144200000;
if(argc>1) if(argc>1)
Freq=atol(argv[1]); Freq=atof(argv[1]);
for (int i = 0; i < 64; i++) { for (int i = 0; i < 64; i++) {
struct sigaction sa; struct sigaction sa;
@ -393,11 +380,11 @@ int main(int argc, char* argv[])
} }
//SimpleTest(Freq); //SimpleTest(Freq);
SimpleTestbpsk(Freq); //SimpleTestbpsk(Freq);
//SimpleTestFileIQ(Freq); //SimpleTestFileIQ(Freq);
//SimpleTestDMA(Freq); //SimpleTestDMA(Freq);
//SimpleTestAm(Freq); //SimpleTestAm(Freq);
//SimpleTestOOK(Freq); SimpleTestOOK(Freq);
//SimpleTestBurstFsk(Freq); //SimpleTestBurstFsk(Freq);
} }

View file

@ -4,11 +4,11 @@ LDFLAGS = -lm -lrt -lpthread
CCP = c++ CCP = c++
CC = cc 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 mailbox.o mailbox.c
$(CC) $(CFLAGS) -c -o raspberry_pi_revision.o raspberry_pi_revision.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 $(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 $(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 install: librpitx

View file

@ -25,4 +25,4 @@ This program is free software: you can redistribute it and/or modify
#include "amdmasync.h" #include "amdmasync.h"
#include "fskburst.h" #include "fskburst.h"
#include "dsp.h" #include "dsp.h"
#include "ookburst.h"

129
src/ookburst.cpp Normal file
View file

@ -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 <http://www.gnu.org/licenses/>.
*/
#include "stdio.h"
#include <unistd.h>
#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;i<Size;i++)
{
sampletab[i]=(Symbols[i]==0)?((Originfsel & ~(7 << 12)) | (0 << 12)):((Originfsel & ~(7 << 12)) | (4 << 12));
cbp = &cbarray[i*cbbysample];
cbp->next = 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);
}
}

23
src/ookburst.h Normal file
View file

@ -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