Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
Loading...
Searching...
No Matches
PRU.h
1#pragma once
2
3#include <stdint.h>
4#include "Bela.h"
5#include "Gpio.h"
6#include "PruManager.h"
7struct McaspRegisters;
8
16typedef struct _InternalBelaContext {
22 float *audioIn;
23
29 float *audioOut;
30
36 float *analogIn;
37
43 float *analogOut;
44
48 uint32_t *digital;
49
51 uint32_t audioFrames;
58
62 uint32_t analogFrames;
63
68
73
81
83 uint32_t digitalFrames;
90
98
104
110
117
123
132 uint32_t flags;
133
135 char projectName[MAX_PROJECTNAME_LENGTH];
136
138 unsigned int underrunCount;
139 operator BelaContext () {return *(BelaContext*)this;}
140} InternalBelaContext;
141
142class PruMemory;
143class PRU
144{
145private:
146 static const unsigned int kPruGPIODACSyncPin;
147 static const unsigned int kPruGPIOADCSyncPin;
148
149public:
150 // Constructor
151 PRU(InternalBelaContext *input_context);
152
153 // Destructor
154 ~PRU();
155
156 // Prepare the GPIO pins needed for the PRU
157 int prepareGPIO(int include_led);
158
159 // Clean up the GPIO at the end
160 void cleanupGPIO();
161
162 // Initialise and open the PRU
163 int initialise(BelaHw newBelaHw, int pru_num, bool uniformSampleRate,
164 int mux_channels,
165 int stopButtonPin, bool enableLed,
166 uint32_t disabledBelaDigitalChannels);
167
168 // Run the code image in pru_rtaudio_bin.h
169 int start(char * const filename, const McaspRegisters& mcaspRegisters);
170
171 // Loop: read and write data from the PRU and call the user-defined audio callback
172 void loop(void *userData, void(*render)(BelaContext*, void*), bool highPerformanceMode, BelaCpuData* cpuData);
173
174 // Wait for an interrupt from the PRU indicate it is finished
175 void waitForFinish();
176
177 // Turn off the PRU when done
178 void disable();
179
180 // Exit the whole PRU subsystem
181 void exitPRUSS();
182 PruManager *pruManager;
183
184private:
185 void initialisePruCommon(const McaspRegisters& mcaspRegisters);
186 int testPruError();
187 InternalBelaContext *context; // Overall settings
188
189 int pru_number; // Which PRU we use
190 bool initialised; // Whether the prussdrv system is initialised
191 bool running; // Whether the PRU is running
192 bool analog_enabled; // Whether SPI ADC and DAC are used
193 bool digital_enabled; // Whether digital is used
194 float analogs_per_audio; // How many analog frames per each audio frame
195 bool uniform_sample_rate; // Should the sampling rate of the analog and audio forced to be the same, as far as ARM is concerned
196 int hardware_analog_frames; // The actual number of frames for the analog channels, as far as the PRU is concerned
197 bool gpio_enabled; // Whether GPIO has been prepared
198 bool led_enabled; // Whether a user LED is enabled
199 bool analog_out_is_audio;
200 size_t pru_audio_out_channels;
201
202 PruMemory* pruMemory;
203 volatile uint32_t *pru_buffer_comm;
204 uint32_t pruBufferMcaspFrames;
205
206 float *last_analog_out_frame;
207 uint32_t *last_digital_buffer;
208 float *audio_expander_input_history;
209 float *audio_expander_output_history;
210 float audio_expander_filter_coeff;
211 bool pruUsesMcaspIrq;
212 BelaHw belaHw;
213
214 Gpio stopButton; // Monitoring the bela cape button
215 Gpio underrunLed; // Flashing an LED upon underrun
216 Gpio adcNrstPin; // Resetting the ADC on Bela Mini Rev C
217 uint32_t disabledDigitalChannels;
218};
Main Bela public API.
BelaHw
Definition Bela.h:108
Definition Gpio.h:5
Definition PruManager.h:21
void render(BelaContext *context, void *userData)
User-defined callback function to process audio and sensor data.
Definition render.cpp:68
Structure holding audio and sensor settings and pointers to I/O data buffers.
Definition Bela.h:231
Definition Bela.h:872
Definition Mcasp.h:10
Definition PRU.h:16
uint32_t flags
Other audio/sensor settings.
Definition PRU.h:132
uint32_t analogFrames
Number of analog frames per period.
Definition PRU.h:62
float * analogIn
Buffer holding analog input samples.
Definition PRU.h:36
float * audioIn
Buffer holding audio input samples.
Definition PRU.h:22
uint32_t digitalChannels
Number of digital channels.
Definition PRU.h:87
uint32_t audioInChannels
Number of input audio channels.
Definition PRU.h:53
float analogSampleRate
Analog sample rate in Hz.
Definition PRU.h:80
uint32_t * digital
Buffer holding digital input/output samples.
Definition PRU.h:48
uint64_t audioFramesElapsed
Number of elapsed audio frames since the start of rendering.
Definition PRU.h:97
unsigned int underrunCount
Number of detected underruns.
Definition PRU.h:138
uint32_t analogOutChannels
Number of output analog channels.
Definition PRU.h:72
float * analogOut
Buffer holding analog output samples.
Definition PRU.h:43
uint32_t audioFrames
Number of audio frames per period.
Definition PRU.h:51
float * audioOut
Buffer holding audio output samples.
Definition PRU.h:29
float digitalSampleRate
Digital sample rate in Hz (currently always 44100.0).
Definition PRU.h:89
uint32_t audioOutChannels
Number of output audio channels.
Definition PRU.h:55
float * multiplexerAnalogIn
Buffer which holds multiplexed analog inputs, when multiplexer capelet is enabled.
Definition PRU.h:116
float audioSampleRate
Audio sample rate in Hz (currently always 44100.0).
Definition PRU.h:57
uint32_t analogInChannels
Number of input analog channels.
Definition PRU.h:67
uint32_t multiplexerChannels
Number of multiplexer channels for each analog input.
Definition PRU.h:103
uint32_t multiplexerStartingChannel
Multiplexer channel corresponding to the first analog frame.
Definition PRU.h:109
char projectName[MAX_PROJECTNAME_LENGTH]
Name of running project.
Definition PRU.h:135
uint32_t audioExpanderEnabled
Flags for whether audio expander is enabled on given analog channels.
Definition PRU.h:122
uint32_t digitalFrames
Number of digital frames per period.
Definition PRU.h:83