Trial add of PDM code

This commit is contained in:
Ross Owen
2015-09-22 11:15:05 +01:00
parent 0205adaa1d
commit be0bf0d983
4 changed files with 135 additions and 17 deletions

View File

@@ -26,6 +26,9 @@ void audio(chanend c_in,
#if (XUD_TILE != 0)
, server interface i_dfu dfuInterface
#endif
#ifdef PDM_PCM_IN
, streaming chanend c_pdm_in
#endif
);
void SpdifTxWrapper(chanend c_spdif_tx);

View File

@@ -696,6 +696,15 @@ unsigned static deliver(chanend c_out, chanend ?c_spd_out,
unsigned sample = samplesOut[SPDIF_TX_INDEX + 1];
outuint(c_spd_out, sample); /* Forward sample to S/PDIF Tx thread */
#endif
#ifdef PDM_PCM_IN
c_pdm_in <: 1;
c_pdm_in :> samplesIn_0[0];
c_pdm_in :> samplesIn_0[1];
#endif
}
@@ -1171,6 +1180,7 @@ chanend ?c_config, chanend ?c
outuint(c_spdif_out, mClk);
#endif
#ifdef ADAT_TX
// Configure ADAT parameters ...
//

View File

@@ -43,6 +43,10 @@
#include "clocking.h"
#ifdef PDM_PCM_IN
void pcm_pdm_mic(streaming chanend c_pcm_out);
#endif
void genclock();
[[distributable]]
@@ -267,14 +271,6 @@ void xscope_user_init()
}
#endif
#ifdef PDM_PCM_IN
void dummy_pdm_code(streaming chanend c)
{
while(1)
c <: 0xff00ff00;
}
#endif
/* Core USB Audio functions - must be called on the Tile connected to the USB Phy */
void usb_audio_core(chanend c_mix_out
#ifdef MIDI
@@ -417,6 +413,9 @@ void usb_audio_io(chanend c_aud_in, chanend ?c_adc,
#if (XUD_TILE != 0)
, server interface i_dfu dfuInterface
#endif
#ifdef PDM_PCM_IN
, streaming chanend c_pdm_pcm
#endif
)
{
#ifdef MIXER
@@ -429,10 +428,6 @@ void usb_audio_io(chanend c_aud_in, chanend ?c_adc,
#define c_dig_rx null
#endif
#ifdef PDM_PCM_IN
streaming chan c_pdm_pcm
#endif
par
{
#ifdef MIXER
@@ -476,10 +471,6 @@ void usb_audio_io(chanend c_aud_in, chanend ?c_adc,
}
#endif
#ifdef PDM_PCM_IN
dummy_pdm_code(c_pdm_pcm);
#endif
//:
}
}
@@ -491,7 +482,6 @@ void usb_audio_io(chanend c_aud_in, chanend ?c_adc,
#ifndef USER_MAIN_CORES
#define USER_MAIN_CORES
#endif
//::
/* Main for USB Audio Applications */
int main()
@@ -553,6 +543,9 @@ int main()
#define dfuInterface null
#endif
#ifdef PDM_PCM_IN
streaming chan c_pdm_pcm;
#endif
USER_MAIN_DECLARATIONS
@@ -582,6 +575,7 @@ int main()
, c_mix_ctl
#endif
, c_clk_int, c_clk_ctl, dfuInterface
);
}
@@ -596,6 +590,9 @@ int main()
#if XUD_TILE != 0
, dfuInterface
#endif
#ifdef PDM_PCM_IN
, c_pdm_pcm
#endif
);
@@ -657,6 +654,11 @@ int main()
}
}
#endif
#ifdef PDM_PCM_IN
// TODO tile
on stdcore[0]: pcm_pdm_mic(c_pdm_pcm);
#endif
USER_MAIN_CORES
}

View File

@@ -0,0 +1,103 @@
#include <xscope.h>
#include <platform.h>
#include <xs1.h>
#include <stdlib.h>
#include "beam.h"
#include <print.h>
#include <stdio.h>
#include <string.h>
#include "static_constants.h"
#if 1
on tile[0]: in port p_pdm_clk = XS1_PORT_1E;
on tile[0]: in buffered port:8 p_pdm_mics = XS1_PORT_8B;
in port p_mclk = on tile[0]: XS1_PORT_1F;
clock mclk = on tile[0]: XS1_CLKBLK_1;
clock pdmclk = on tile[0]: XS1_CLKBLK_3;
in port p_buttons = on tile[0]: XS1_PORT_4C;
typedef struct {
unsigned ch_a;
unsigned ch_b;
} double_packed_audio;
typedef struct {
double_packed_audio data[4][1<<FRAME_SIZE_LOG2];
} synchronised_audio;
void example(streaming chanend c_ds_output_0, streaming chanend c_ds_output_1, streaming chanend c_pcm_out)
{
unsigned buffer = 1; //buffer index
synchronised_audio audio[2]; //double buffered
memset(audio, sizeof(synchronised_audio), 2);
unsafe
{
c_ds_output_0 <: (synchronised_audio * unsafe)audio[0].data[0];
c_ds_output_1 <: (synchronised_audio * unsafe)audio[0].data[2];
while(1)
{
schkct(c_ds_output_0, 8);
schkct(c_ds_output_1, 8);
c_ds_output_0 <: (synchronised_audio * unsafe)audio[buffer].data[0];
c_ds_output_1 <: (synchronised_audio * unsafe)audio[buffer].data[2];
buffer = 1 - buffer;
//The data has already been bit reversed in the downsampler
// audio[buffer] is good to go
//xscope_int(0, audio[buffer].data[0][0].ch_a);
//xscope_int(1, audio[buffer].data[0][0].ch_b);
c_pcm_out :> unsigned req;
c_pcm_out <: audio[buffer].data[0][0].ch_a;
c_pcm_out <: audio[buffer].data[0][0].ch_b;
printintln(audio[buffer].data[0][0].ch_b);
}
}
}
void pcm_pdm_mic(streaming chanend c_pcm_out)
{
streaming chan c_multi_channel_pdm, c_sync, c_4x_pdm_mic_0, c_4x_pdm_mic_1;
streaming chan c_ds_output_0, c_ds_output_1;
streaming chan c_buffer_mic0, c_buffer_mic1;
unsigned long long shared_memory[2] = {0};
configure_clock_src(mclk, p_mclk);
configure_clock_src_divide(pdmclk, p_mclk, 2);
configure_port_clock_output(p_pdm_clk, pdmclk);
configure_in_port(p_pdm_mics, pdmclk);
start_clock(mclk);
start_clock(pdmclk);
unsafe
{
unsigned long long * unsafe p_shared_memory = shared_memory;
par
{
//Input stage
pdm_first_stage(p_pdm_mics, p_shared_memory,
PDM_BUFFER_LENGTH_LOG2, c_sync,
c_4x_pdm_mic_0, c_4x_pdm_mic_1);
pdm_to_pcm_4x(c_4x_pdm_mic_0, c_ds_output_0);
pdm_to_pcm_4x(c_4x_pdm_mic_1, c_ds_output_1);
example(c_ds_output_0, c_ds_output_1, c_pcm_out);
}
}
}
#endif