Skip to content

Commit

Permalink
Use bcm_host functions to runtime support of Pi 4.
Browse files Browse the repository at this point in the history
Close #10 and #8
  • Loading branch information
mill1000 committed Mar 10, 2023
1 parent 8508b59 commit c0d93de
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ static void raspdifInit(dma_channel_t dmaChannel, double sampleRate_Hz)

// Save DMA channel
raspdif.dmaChannel = dmaChannel;
LOGD(TAG, "Initializing with DMA channel %d.", dmaChannel);

// Allocate buffers and control blocks in physical memory
memory_physical_t memory = memoryAllocatePhysical(sizeof(raspdif_control_t));
Expand Down Expand Up @@ -199,7 +200,8 @@ static void raspdifInit(dma_channel_t dmaChannel, double sampleRate_Hz)
double spdif_clock = sampleRate_Hz * 64.0 * 2.0;
LOGD(TAG, "Calculated SPDIF clock of %g Hz for sample rate of %g Hz.", spdif_clock, sampleRate_Hz);

double divisor = (500e6 / spdif_clock);
double pllFreq_Hz = bcm_host_is_model_pi4() ? 750e6 : 500e6;
double divisor = (pllFreq_Hz / spdif_clock);

double divi = 0;
double divf = round(4096 * modf(divisor, &divi));
Expand Down Expand Up @@ -431,7 +433,8 @@ int main(int argc, char* argv[])
logSetLevel(LOG_LEVEL_DEBUG);

// Initialize hardware and buffers
raspdifInit(dma_channel_13, arguments.sample_rate);
dma_channel_t dmaChannel = bcm_host_is_model_pi4() ? dma_channel_5 : dma_channel_13;
raspdifInit(dmaChannel, arguments.sample_rate);

// Allocate storage for a SPDIF block
spdif_block_t block;
Expand Down

0 comments on commit c0d93de

Please sign in to comment.