Compare commits
17 commits
Author | SHA1 | Date | |
---|---|---|---|
|
dbb26b33c7 | ||
|
d514817b65 | ||
|
e0a4588df8 | ||
|
c9ea7cacb8 | ||
|
b0172f908b | ||
|
a7def5d4ba | ||
|
f6dfbeae03 | ||
|
b571c4a308 | ||
|
0aec0363e2 | ||
|
fd366412f7 | ||
|
d139ff56fb | ||
|
d318058a17 | ||
|
1cd126f230 | ||
|
5aabd38264 | ||
|
5c1613589d | ||
|
7c8849756d | ||
|
2d1bf3042b |
9 changed files with 88 additions and 22 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
*.o
|
||||
*.a
|
||||
*.gch
|
BIN
app/testrpitx
BIN
app/testrpitx
Binary file not shown.
44
src/Makefile
44
src/Makefile
|
@ -1,16 +1,36 @@
|
|||
CFLAGS = -Wall -O3 -Wno-unused-variable
|
||||
CXXFLAGS = -std=c++11 -Wall -O3 -Wno-unused-variable -I /opt/vc/include
|
||||
LDFLAGS = -lm -lrt -lpthread -L/opt/vc/lib -lbcm_host
|
||||
CCP = c++
|
||||
CC = cc
|
||||
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 -fPIC
|
||||
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
|
||||
#$(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
|
||||
all: librpitx.a librpitx.so
|
||||
|
||||
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:
|
||||
rm -f *.o *.a
|
||||
rm -f $(OBJS) *.a *.so
|
||||
|
|
|
@ -158,7 +158,7 @@ void atv::SetDmaAlgo()
|
|||
}
|
||||
cbp--;
|
||||
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)
|
||||
|
|
|
@ -19,7 +19,7 @@ This program is free software: you can redistribute it and/or modify
|
|||
#include "dma.h"
|
||||
#include "stdio.h"
|
||||
#include "util.h"
|
||||
#include <bcm_host.h>
|
||||
#include "rpi.h"
|
||||
|
||||
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)
|
||||
uint32_t BCM2708_PERI_BASE =bcm_host_get_peripheral_address();
|
||||
|
||||
channel=Channel;
|
||||
if(BCM2708_PERI_BASE==0xFE000000)
|
||||
{
|
||||
channel= 7; // Pi4
|
||||
dbg_printf(1,"dma PI4 using channel %d\n",channel);
|
||||
}
|
||||
else
|
||||
{
|
||||
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();
|
||||
if (mbox.handle < 0)
|
||||
|
|
18
src/gpio.cpp
18
src/gpio.cpp
|
@ -24,9 +24,9 @@ extern "C" {
|
|||
#include <unistd.h>
|
||||
#include <sys/timex.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include "util.h"
|
||||
#include <bcm_host.h>
|
||||
//#include "/opt/vc/include/bcm_host.h"
|
||||
#include "rpi.h"
|
||||
|
||||
gpio::gpio(uint32_t base, uint32_t len)
|
||||
{
|
||||
|
@ -94,15 +94,16 @@ uint32_t gpio::GetPeripheralBase()
|
|||
{
|
||||
RASPBERRY_PI_INFO_T info;
|
||||
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
|
||||
{
|
||||
dbg_printf(0,"RPi4 GPIO detected\n");
|
||||
pi_is_2711=true; //Rpi4
|
||||
XOSC_FREQUENCY=54000000;
|
||||
}
|
||||
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;
|
||||
XOSC_FREQUENCY=54000000;
|
||||
pi_is_2711=true;
|
||||
|
@ -135,7 +136,7 @@ clkgpio::~clkgpio()
|
|||
|
||||
int clkgpio::SetPllNumber(int PllNo, int MashType)
|
||||
{
|
||||
//print_clock_tree();
|
||||
print_clock_tree();
|
||||
if (PllNo < 8)
|
||||
pllnumber = PllNo;
|
||||
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_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);
|
||||
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;
|
||||
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) ;
|
||||
|
@ -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) ;
|
||||
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);
|
||||
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
31
src/rpi.c
Normal 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
3
src/rpi.h
Normal 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);
|
BIN
src/util.o
BIN
src/util.o
Binary file not shown.
Loading…
Reference in a new issue