XCORE SDK
XCORE Software Development Kit
|
PDM rx service which uses a streaming channel to send a block of data by pointer. More...
#include <PdmRx.hpp>
Public Member Functions | |
uint32_t | ReadPort () |
Read a word of PDM data from the port. More... | |
void | SendBlock (uint32_t block[CHANNELS_IN *SUBBLOCKS]) |
Send a block of PDM data to a listener. More... | |
void | Init (port_t p_pdm_mics) |
Initialize this object with a channel and port. More... | |
void | MapChannels (unsigned map[CHANNELS_OUT]) |
Set the input-output mapping for all output channels. More... | |
void | MapChannel (unsigned out_channel, unsigned in_channel) |
Set the input-output mapping for a single output channel. More... | |
void | InstallISR () |
Install ISR for PDM reception on the current core. More... | |
void | UnmaskISR () |
Unmask interrupts on the current core. | |
uint32_t * | GetPdmBlock () |
Get a block of PDM data. More... | |
![]() | |
void | SetPort (port_t p_pdm_mics) |
Set the port from which to collect PDM samples. | |
void | ProcessNext () |
Perform a port read and if a new block has completed, signal. | |
void | ThreadEntry () |
Entry point for PDM processing thread. More... | |
Additional Inherited Members | |
![]() | |
static constexpr unsigned | BlockSize |
Number of words of PDM data per block. | |
![]() | |
port_t | p_pdm_mics |
Port from which to collect PDM data. | |
unsigned | phase |
Number of words left to capture for the current block. | |
uint32_t | block_data [2][BLOCK_SIZE] |
Buffers for PDM data blocks. | |
uint32_t * | blocks [2] |
PDM block redirection pointers. More... | |
PDM rx service which uses a streaming channel to send a block of data by pointer.
This class can run the PDM rx service either as a stand-alone thread or through an interrupt.
A streaming channel is used to transfer control of the PDM data block between contexts (i.e. thread->thread or ISR->thread).
The MicArray
unit receives blocks of PDM data from an instance of this class by calling GetPdmBlock()
, which blocks until a new PDM block is available.
The buffer transferred by SendBlock()
contains CHANNELS_IN*
SUBBLOCKS words of PDM data for
CHANNELS_INmicrophone channels. The words are stored in reverse order of arrival. See
deinterleave_pdm_samples<>()` for additional details on this format.
Within GetPdmBlock()
(i.e. mic array thread) the PDM data block is deinterleaved and copied to another buffer in the format required by the decimator component, which is returned by GetPdmBlock()
. This buffer contains samples for CHANNELS_OUT
microphone channels.
In some cases an application may be required to capture more microphone channels than should actually be processed by subsequent processing stages (including the decimator component). For example, this may be the case if 4 microphone channels are desired but only an 8 bit wide port is physically available to capture the samples.
This class template has a parameter both for the number of channels to be captured by the port (CHANNELS_IN
), as well as for the number of channels that are to be output for consumption by the MicArray
's decimator component (CHANNELS_OUT
).
When the PDM microphones are in an SDR configuration, CHANNELS_IN
must be the width (in bits) of the xCore port to which the microphones are physically connected. When in a DDR configuration, CHANNELS_IN
must be twice the width (in bits) of the xCore port to which the microphones are physically connected.
CHANNELS_OUT
is the number of microphone channels to be consumed by the decimator unit (i.e. must be the same as the MIC_COUNT
template parameter of the decimator component). If all port pins are connected to microphones, this parameter will generally be the same as CHANNELS_IN
.
The input channel index of a microphone depends on the pin to which it is connected. Each pin connected to a port has a bit index for that port, given in the 'Signal Description and GPIO' section of your package's datasheet.
Suppose an N
-bit port is used to capture microphone data, and a microphone is connected to bit B
of that port. In an SDR microphone configuration, the input channel index of that microphone is B
– the same as the port bit index.
In a DDR configuration, that microphone will be on either input channel index B
or B+N
, depending on whether that microphone is configured for in-phase capture or out-of-phase capture.
Sometimes it may be desirable to re-order the microphone channel indices. This is likely the case, for example, when CHANNELS_IN > CHANNELS_OUT
.
By default output channels are mapped from the input channels with the same index. If CHANNELS_IN > CHANNELS_OUT
, this means that the input channels with the highest CHANNELS_IN-CHANNELS_OUT
indices are dropped by default.
The MapChannel()
and MapChannels()
methods can be used to specify a non-default mapping from input channel indices to output channel indices. It takes a pointer to a CHANNELS_OUT
-element array specifying the input channel index for each output channel.
CHANNELS_IN | The number of microphone channels to be captured by the port. |
CHANNELS_OUT | The number of microphone channels to be delivered by this StandardPdmRxService instance. |
SUBBLOCKS | The number of 32-sample sub-blocks to be captured for each microphone channel. |
uint32_t * mic_array::StandardPdmRxService< CHANNELS_IN, CHANNELS_OUT, SUBBLOCKS >::GetPdmBlock |
Get a block of PDM data.
Because blocks of PDM samples are delivered by pointer, the caller must either copy the samples or finish processing them before the next block of samples is ready, or the data will be clobbered.
void mic_array::StandardPdmRxService< CHANNELS_IN, CHANNELS_OUT, SUBBLOCKS >::Init | ( | port_t | p_pdm_mics | ) |
Initialize this object with a channel and port.
p_pdm_mics | Port to receive PDM data on. |
void mic_array::StandardPdmRxService< CHANNELS_IN, CHANNELS_OUT, SUBBLOCKS >::InstallISR |
Install ISR for PDM reception on the current core.
void mic_array::StandardPdmRxService< CHANNELS_IN, CHANNELS_OUT, SUBBLOCKS >::MapChannel | ( | unsigned | out_channel, |
unsigned | in_channel | ||
) |
Set the input-output mapping for a single output channel.
By default, input channel index k
maps to output channel index k
.
This method overrides that behavior for a single output channel, configuring output channel out_channel
to be derived from input channel in_channel
.
out_channel | Output channel index to be re-mapped. |
in_channel | New source channel index for out_channel . |
void mic_array::StandardPdmRxService< CHANNELS_IN, CHANNELS_OUT, SUBBLOCKS >::MapChannels | ( | unsigned | map[CHANNELS_OUT] | ) |
Set the input-output mapping for all output channels.
By default, input channel index k
maps to output channel index k
.
This method overrides that behavior for all channels, re-mapping each output channel such that output channel k
is derived from input channel map[k]
.
map | Array containing new channel map. |
uint32_t mic_array::StandardPdmRxService< CHANNELS_IN, CHANNELS_OUT, SUBBLOCKS >::ReadPort |
Read a word of PDM data from the port.
uint32_t
containing 32 PDM samples. If MIC_COUNT >= 2
the samples from each port will be interleaved together. void mic_array::StandardPdmRxService< CHANNELS_IN, CHANNELS_OUT, SUBBLOCKS >::SendBlock | ( | uint32_t | block[CHANNELS_IN *SUBBLOCKS] | ) |
Send a block of PDM data to a listener.
block | PDM data to send. |