Compare commits

...

17 commits
pi4 ... master

Author SHA1 Message Date
f5oeo
dbb26b33c7 Try to fix some weird null registry 2023-01-29 17:35:45 +00:00
F5OEO
d514817b65 Misspelling dependancy 2021-02-25 09:36:11 +01:00
F5OEO
e0a4588df8
Merge pull request #17 from jmfriedt/master
Makefile: explicit rules to generale static and dynamic libraries
2021-02-23 11:46:33 +01:00
Jean-Michel Friedt
c9ea7cacb8 Makefile: explicit rules to generale static and dynamic libraries 2021-02-23 11:24:22 +01:00
Your Name
b0172f908b Remove rpi warning 2021-01-13 10:40:16 +00:00
F5OEO
a7def5d4ba
Merge pull request #16 from jmfriedt/master
remove bcm_host dependency + Makefile constants CC/CXX overwritable from command line
2021-01-13 09:38:33 +01:00
jfriedt
f6dfbeae03 Makefile: add install rule 2021-01-12 15:13:17 +01:00
jfriedt
b571c4a308 remove bcm_host dependency + Makefile constants CC/CXX overwritable from command line 2021-01-12 14:37:14 +01:00
f5oeo
0aec0363e2 Compliant to 64bit 2020-11-03 13:50:48 +00:00
f5oeo
fd366412f7 Remove object from git 2020-11-03 13:50:25 +00:00
F5OEO
d139ff56fb Fix PLL rate for non PI4 2020-11-03 10:52:37 +00:00
f5oeo
d318058a17 Move optparse used by ook to rpitx 2020-11-02 13:20:25 +00:00
f5oeo
1cd126f230 Merge branch 'master' of https://github.com/F5OEO/librpitx 2020-11-02 13:16:32 +00:00
f5oeo
5aabd38264 Remove testapp binary 2020-11-02 13:15:45 +00:00
F5OEO
5c1613589d
Merge pull request #15 from psa-jforestier/libsendook
Improve logging and command line parser
2020-09-09 10:35:20 +02:00
psa-jforestier
7c8849756d add new function to parse command line (got it from rtl_433) 2020-09-08 18:21:24 +02:00
psa-jforestier
2d1bf3042b improve logging function 2020-09-08 18:20:50 +02:00
9 changed files with 88 additions and 22 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
*.o
*.a
*.gch

Binary file not shown.

View file

@ -1,16 +1,36 @@
CFLAGS = -Wall -O3 -Wno-unused-variable CFLAGS ?= -Wall -O3 -Wno-unused-variable
CXXFLAGS = -std=c++11 -Wall -O3 -Wno-unused-variable -I /opt/vc/include CFLAGS += -std=c++11 -fPIC
LDFLAGS = -lm -lrt -lpthread -L/opt/vc/lib -lbcm_host CXXFLAGS ?= -std=c++11 -Wall -O3 -Wno-unused-variable -I /opt/vc/include
CCP = c++ CXXFLAGS += -std=c++11 -Wall -O3 -Wno-unused-variable -fPIC
CC = cc LDFLAGS ?= -lm -lrt -lpthread -L/opt/vc/lib -lbcm_host
LDFLAGS += -fPIC
CXX ?= c++
CC ?= cc
PREFIX ?= /usr/local/
SRCCC=$(wildcard *.c)
SRCXX=$(wildcard *.cpp)
OBJS=$(SRCCC:.c=.o)
OBJS+=$(SRCXX:.cpp=.o)
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 atv.h atv.cpp util.h all: librpitx.a librpitx.so
#$(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 ookburst.cpp atv.cpp util.cpp mailbox.c
$(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 atv.o util.o mailbox.o
install: librpitx %.o: %.c
$(CXX) $(CFLAGS) -c $^
%.o: %.cpp
$(CXX) $(CXXFLAGS) -c $^
librpitx.a: $(OBJS)
$(AR) rc $@ $^
librpitx.so: $(OBJS)
$(CXX) -fPIC -shared -o $@ $^ $(LDFLAGS)
install: librpitx.a
mkdir -p $(PREFIX)/include/librpitx
install *.h $(PREFIX)/include/librpitx
mkdir -p $(PREFIX)/lib
install librpitx.a $(PREFIX)/lib
clean: clean:
rm -f *.o *.a rm -f $(OBJS) *.a *.so

View file

@ -158,7 +158,7 @@ void atv::SetDmaAlgo()
} }
cbp--; cbp--;
cbp->next = mem_virt_to_phys(cbarray); // We loop to the first CB cbp->next = mem_virt_to_phys(cbarray); // We loop to the first CB
dbg_printf(1, "Last cbp : %d \n", ((unsigned int)(cbp) - (unsigned int)(cbarray)) / sizeof(dma_cb_t)); dbg_printf(1, "Last cbp : %d \n", ((uintptr_t)(cbp) - (uintptr_t)(cbarray)) / sizeof(dma_cb_t));
} }
void atv::SetFrame(unsigned char *Luminance, size_t Lines) void atv::SetFrame(unsigned char *Luminance, size_t Lines)

View file

@ -19,7 +19,7 @@ This program is free software: you can redistribute it and/or modify
#include "dma.h" #include "dma.h"
#include "stdio.h" #include "stdio.h"
#include "util.h" #include "util.h"
#include <bcm_host.h> #include "rpi.h"
extern "C" extern "C"
{ {
@ -36,15 +36,20 @@ dma::dma(int Channel,uint32_t CBSize,uint32_t UserMemSize) // Fixme! Need to che
//Channel DMA is now hardcoded according to Raspi Model (DMA 7 for Pi4, DMA 14 for others) //Channel DMA is now hardcoded according to Raspi Model (DMA 7 for Pi4, DMA 14 for others)
uint32_t BCM2708_PERI_BASE =bcm_host_get_peripheral_address(); uint32_t BCM2708_PERI_BASE =bcm_host_get_peripheral_address();
channel=Channel;
if(BCM2708_PERI_BASE==0xFE000000) if(BCM2708_PERI_BASE==0xFE000000)
{ {
channel= 7; // Pi4 channel= 7; // Pi4
dbg_printf(1,"dma PI4 using channel %d\n",channel);
} }
else else
{ {
channel = 14; // Other Pi channel = 14; // Other Pi
dbg_printf(1,"dma (NOT a PI4) using channel %d\n",channel);
} }
dbg_printf(1,"Channel %d CBSize %u UsermemSize %u\n",Channel,CBSize,UserMemSize);
dbg_printf(1,"channel %d CBSize %u UsermemSize %u\n",channel,CBSize,UserMemSize);
mbox.handle = mbox_open(); mbox.handle = mbox_open();
if (mbox.handle < 0) if (mbox.handle < 0)

View file

@ -24,9 +24,9 @@ extern "C" {
#include <unistd.h> #include <unistd.h>
#include <sys/timex.h> #include <sys/timex.h>
#include <math.h> #include <math.h>
#include <string.h>
#include "util.h" #include "util.h"
#include <bcm_host.h> #include "rpi.h"
//#include "/opt/vc/include/bcm_host.h"
gpio::gpio(uint32_t base, uint32_t len) gpio::gpio(uint32_t base, uint32_t len)
{ {
@ -94,15 +94,16 @@ uint32_t gpio::GetPeripheralBase()
{ {
RASPBERRY_PI_INFO_T info; RASPBERRY_PI_INFO_T info;
uint32_t BCM2708_PERI_BASE =bcm_host_get_peripheral_address(); uint32_t BCM2708_PERI_BASE =bcm_host_get_peripheral_address();
dbg_printf(1,"Peri Base = %x SDRAM %x\n",/*get_hwbase()*/bcm_host_get_peripheral_address(),bcm_host_get_sdram_address()); dbg_printf(0,"Peri Base = %x SDRAM %x\n",/*get_hwbase()*/bcm_host_get_peripheral_address(),bcm_host_get_sdram_address());
if(BCM2708_PERI_BASE==0xFE000000) // Fixme , could be inspect without this hardcoded value if(BCM2708_PERI_BASE==0xFE000000) // Fixme , could be inspect without this hardcoded value
{ {
dbg_printf(0,"RPi4 GPIO detected\n");
pi_is_2711=true; //Rpi4 pi_is_2711=true; //Rpi4
XOSC_FREQUENCY=54000000; XOSC_FREQUENCY=54000000;
} }
if(BCM2708_PERI_BASE==0) if(BCM2708_PERI_BASE==0)
{ {
dbg_printf(0,"Unknown peripheral base, swith to PI4 \n"); dbg_printf(0,"Unknown peripheral base, switch to PI4 \n");
BCM2708_PERI_BASE=0xfe000000; BCM2708_PERI_BASE=0xfe000000;
XOSC_FREQUENCY=54000000; XOSC_FREQUENCY=54000000;
pi_is_2711=true; pi_is_2711=true;
@ -135,7 +136,7 @@ clkgpio::~clkgpio()
int clkgpio::SetPllNumber(int PllNo, int MashType) int clkgpio::SetPllNumber(int PllNo, int MashType)
{ {
//print_clock_tree(); print_clock_tree();
if (PllNo < 8) if (PllNo < 8)
pllnumber = PllNo; pllnumber = PllNo;
else else
@ -168,7 +169,9 @@ uint64_t clkgpio::GetPllFrequency(int PllNo)
//case clk_pllb:Freq=XOSC_FREQUENCY*((uint64_t)gpioreg[PLLB_CTRL]&0x3ff) +XOSC_FREQUENCY*(uint64_t)gpioreg[PLLB_FRAC]/(1<<20);break; //case clk_pllb:Freq=XOSC_FREQUENCY*((uint64_t)gpioreg[PLLB_CTRL]&0x3ff) +XOSC_FREQUENCY*(uint64_t)gpioreg[PLLB_FRAC]/(1<<20);break;
case clk_pllc: case clk_pllc:
//Freq = (XOSC_FREQUENCY * ((uint64_t)gpioreg[PLLC_CTRL] & 0x3ff) + (XOSC_FREQUENCY * (uint64_t)gpioreg[PLLC_FRAC]) / (1 << 20)) / (2*gpioreg[PLLC_PER] >> 1)) /((gpioreg[PLLC_CTRL] >> 12)&0x7) ; //Freq = (XOSC_FREQUENCY * ((uint64_t)gpioreg[PLLC_CTRL] & 0x3ff) + (XOSC_FREQUENCY * (uint64_t)gpioreg[PLLC_FRAC]) / (1 << 20)) / (2*gpioreg[PLLC_PER] >> 1)) /((gpioreg[PLLC_CTRL] >> 12)&0x7) ;
Freq =( (XOSC_FREQUENCY * ((uint64_t)gpioreg[PLLC_CTRL] & 0x3ff) + (XOSC_FREQUENCY * (uint64_t)gpioreg[PLLC_FRAC]) / (1 << 20)) / (2*gpioreg[PLLC_PER] >> 1))/((gpioreg[PLLC_CTRL] >> 12)&0x7) ; //dbg_printf(1, "Gpio reg %x %x\n",gpioreg[PLLC_PER],gpioreg[PLLC_CTRL] >> 12);
if((gpioreg[PLLC_PER]!=0)&&(gpioreg[PLLC_CTRL] >> 12 != 0))
Freq =( (XOSC_FREQUENCY * ((uint64_t)gpioreg[PLLC_CTRL] & 0x3ff) + (XOSC_FREQUENCY * (uint64_t)gpioreg[PLLC_FRAC]) / (1 << 20)) / (2*gpioreg[PLLC_PER] >> 1))/((gpioreg[PLLC_CTRL] >> 12)&0x7) ;
break; break;
case clk_plld: case clk_plld:
Freq =( (XOSC_FREQUENCY * ((uint64_t)gpioreg[PLLD_CTRL] & 0x3ff) + (XOSC_FREQUENCY * (uint64_t)gpioreg[PLLD_FRAC]) / (1 << 20)) / (2*gpioreg[PLLD_PER] >> 1))/((gpioreg[PLLD_CTRL] >> 12)&0x7) ; Freq =( (XOSC_FREQUENCY * ((uint64_t)gpioreg[PLLD_CTRL] & 0x3ff) + (XOSC_FREQUENCY * (uint64_t)gpioreg[PLLD_FRAC]) / (1 << 20)) / (2*gpioreg[PLLD_PER] >> 1))/((gpioreg[PLLD_CTRL] >> 12)&0x7) ;
@ -177,7 +180,8 @@ uint64_t clkgpio::GetPllFrequency(int PllNo)
Freq =( XOSC_FREQUENCY * ((uint64_t)gpioreg[PLLH_CTRL] & 0x3ff) + XOSC_FREQUENCY * (uint64_t)gpioreg[PLLH_FRAC] / (1 << 20))/(2*(gpioreg[PLLH_CTRL] >> 12)&0x7) ; Freq =( XOSC_FREQUENCY * ((uint64_t)gpioreg[PLLH_CTRL] & 0x3ff) + XOSC_FREQUENCY * (uint64_t)gpioreg[PLLH_FRAC] / (1 << 20))/(2*(gpioreg[PLLH_CTRL] >> 12)&0x7) ;
break; break;
} }
//if(pi_is_2711) Freq*=2LL; if(!pi_is_2711) // FixMe : Surely a register which say it is a 2x
Freq*=2LL;
Freq=Freq*(1.0-clk_ppm*1e-6); Freq=Freq*(1.0-clk_ppm*1e-6);
dbg_printf(1, "Pi4=%d Xosc = %llu Freq PLL no %d= %llu\n",pi_is_2711,XOSC_FREQUENCY,PllNo, Freq); dbg_printf(1, "Pi4=%d Xosc = %llu Freq PLL no %d= %llu\n",pi_is_2711,XOSC_FREQUENCY,PllNo, Freq);

31
src/rpi.c Normal file
View file

@ -0,0 +1,31 @@
#include "stdint.h"
#include <cstdio>
static unsigned get_dt_ranges(const char *filename, unsigned offset)
{
unsigned address = ~0;
FILE *fp = fopen(filename, "rb");
if (fp)
{
unsigned char buf[4];
fseek(fp, offset, SEEK_SET);
if (fread(buf, 1, sizeof buf, fp) == sizeof buf)
address = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3] << 0;
fclose(fp);
}
return address;
}
unsigned bcm_host_get_peripheral_address(void)
{
unsigned address = get_dt_ranges("/proc/device-tree/soc/ranges", 4);
if (address == 0)
address = get_dt_ranges("/proc/device-tree/soc/ranges", 8);
return address == ~0u ? 0x20000000 : address;
}
unsigned bcm_host_get_sdram_address(void)
{
unsigned address = get_dt_ranges("/proc/device-tree/axi/vc_mem/reg", 8);
return address == ~0u ? 0x40000000 : address;
}

3
src/rpi.h Normal file
View file

@ -0,0 +1,3 @@
unsigned get_dt_ranges(const char *filename, unsigned offset);
unsigned bcm_host_get_peripheral_address(void);
unsigned bcm_host_get_sdram_address(void);

Binary file not shown.