Compare commits
No commits in common. "master" and "pi4" have entirely different histories.
9 changed files with 22 additions and 88 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,3 +0,0 @@
|
||||||
*.o
|
|
||||||
*.a
|
|
||||||
*.gch
|
|
BIN
app/testrpitx
Executable file
BIN
app/testrpitx
Executable file
Binary file not shown.
44
src/Makefile
44
src/Makefile
|
@ -1,36 +1,16 @@
|
||||||
CFLAGS ?= -Wall -O3 -Wno-unused-variable
|
CFLAGS = -Wall -O3 -Wno-unused-variable
|
||||||
CFLAGS += -std=c++11 -fPIC
|
CXXFLAGS = -std=c++11 -Wall -O3 -Wno-unused-variable -I /opt/vc/include
|
||||||
CXXFLAGS ?= -std=c++11 -Wall -O3 -Wno-unused-variable -I /opt/vc/include
|
LDFLAGS = -lm -lrt -lpthread -L/opt/vc/lib -lbcm_host
|
||||||
CXXFLAGS += -std=c++11 -Wall -O3 -Wno-unused-variable -fPIC
|
CCP = c++
|
||||||
LDFLAGS ?= -lm -lrt -lpthread -L/opt/vc/lib -lbcm_host
|
CC = cc
|
||||||
LDFLAGS += -fPIC
|
|
||||||
CXX ?= c++
|
|
||||||
CC ?= cc
|
|
||||||
PREFIX ?= /usr/local/
|
|
||||||
SRCCC=$(wildcard *.c)
|
|
||||||
SRCXX=$(wildcard *.cpp)
|
|
||||||
OBJS=$(SRCCC:.c=.o)
|
|
||||||
OBJS+=$(SRCXX:.cpp=.o)
|
|
||||||
|
|
||||||
all: librpitx.a librpitx.so
|
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
|
||||||
|
#$(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
|
||||||
|
|
||||||
%.o: %.c
|
install: librpitx
|
||||||
$(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 $(OBJS) *.a *.so
|
rm -f *.o *.a
|
||||||
|
|
|
@ -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", ((uintptr_t)(cbp) - (uintptr_t)(cbarray)) / sizeof(dma_cb_t));
|
dbg_printf(1, "Last cbp : %d \n", ((unsigned int)(cbp) - (unsigned int)(cbarray)) / sizeof(dma_cb_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
void atv::SetFrame(unsigned char *Luminance, size_t Lines)
|
void atv::SetFrame(unsigned char *Luminance, size_t Lines)
|
||||||
|
|
|
@ -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 "rpi.h"
|
#include <bcm_host.h>
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
|
@ -36,20 +36,15 @@ 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)
|
||||||
|
|
18
src/gpio.cpp
18
src/gpio.cpp
|
@ -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 "rpi.h"
|
#include <bcm_host.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,16 +94,15 @@ 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(0,"Peri Base = %x SDRAM %x\n",/*get_hwbase()*/bcm_host_get_peripheral_address(),bcm_host_get_sdram_address());
|
dbg_printf(1,"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, switch to PI4 \n");
|
dbg_printf(0,"Unknown peripheral base, swith 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;
|
||||||
|
@ -136,7 +135,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
|
||||||
|
@ -169,9 +168,7 @@ 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) ;
|
||||||
//dbg_printf(1, "Gpio reg %x %x\n",gpioreg[PLLC_PER],gpioreg[PLLC_CTRL] >> 12);
|
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) ;
|
||||||
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) ;
|
||||||
|
@ -180,8 +177,7 @@ 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) // FixMe : Surely a register which say it is a 2x
|
//if(pi_is_2711) Freq*=2LL;
|
||||||
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
31
src/rpi.c
|
@ -1,31 +0,0 @@
|
||||||
#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;
|
|
||||||
}
|
|
|
@ -1,3 +0,0 @@
|
||||||
unsigned get_dt_ranges(const char *filename, unsigned offset);
|
|
||||||
unsigned bcm_host_get_peripheral_address(void);
|
|
||||||
unsigned bcm_host_get_sdram_address(void);
|
|
BIN
src/util.o
Normal file
BIN
src/util.o
Normal file
Binary file not shown.
Loading…
Reference in a new issue