Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
 All Classes Files Functions Variables Typedefs Macros Groups
PRU.h
1 /*
2  * PRU.h
3  *
4  * Created on: May 27, 2014
5  * Author: andrewm
6  */
7 
8 #ifndef PRU_H_
9 #define PRU_H_
10 
11 #include <stdint.h>
12 #include "Bela.h"
13 #include "Gpio.h"
14 #include "AudioCodec.h"
15 
23 typedef struct {
29  float *audioIn;
30 
36  float *audioOut;
37 
43  float *analogIn;
44 
50  float *analogOut;
51 
55  uint32_t *digital;
56 
58  uint32_t audioFrames;
60  uint32_t audioInChannels;
62  uint32_t audioOutChannels;
65 
69  uint32_t analogFrames;
70 
74  uint32_t analogInChannels;
75 
80 
88 
90  uint32_t digitalFrames;
94  uint32_t digitalChannels;
97 
105 
111 
117 
124 
130 
139  uint32_t flags;
141 
142 class PruMemory;
143 class PRU
144 {
145 private:
146  static const unsigned int kPruGPIODACSyncPin;
147  static const unsigned int kPruGPIOADCSyncPin;
148 
149 public:
150  // Constructor
151  PRU(InternalBelaContext *input_context, AudioCodec *audio_codec);
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  bool capeButtonMonitoring, bool enableLed);
166 
167  // Run the code image in pru_rtaudio_bin.h
168  int start(char * const filename);
169 
170  // Loop: read and write data from the PRU and call the user-defined audio callback
171  void loop(void *userData, void(*render)(BelaContext*, void*), bool highPerformanceMode);
172 
173  // Wait for an interrupt from the PRU indicate it is finished
174  void waitForFinish();
175 
176  // Turn off the PRU when done
177  void disable();
178 
179  // Exit the whole PRU subsystem
180  void exitPRUSS();
181 
182 private:
183  void initialisePruCommon();
184  int testPruError();
185  InternalBelaContext *context; // Overall settings
186 
187  int pru_number; // Which PRU we use
188  bool initialised; // Whether the prussdrv system is initialised
189  bool running; // Whether the PRU is running
190  bool analog_enabled; // Whether SPI ADC and DAC are used
191  bool digital_enabled; // Whether digital is used
192  float analogs_per_audio; // How many analog frames per each audio frame
193  bool uniform_sample_rate; // Should the sampling rate of the analog and audio forced to be the same, as far as ARM is concerned
194  int hardware_analog_frames; // The actual number of frames for the analog channels, as far as the PRU is concerned
195  bool gpio_enabled; // Whether GPIO has been prepared
196  bool led_enabled; // Whether a user LED is enabled
197 
198  PruMemory* pruMemory;
199  volatile uint32_t *pru_buffer_comm;
200  uint32_t pruBufferMcaspFrames;
201 
202  float *last_analog_out_frame;
203  uint32_t *last_digital_buffer;
204  float *audio_expander_input_history;
205  float *audio_expander_output_history;
206  float audio_expander_filter_coeff;
207  bool pruUsesMcaspIrq;
208  BelaHw belaHw;
209 
210  Gpio belaCapeButton; // Monitoring the bela cape button
211  Gpio underrunLed; // Flashing an LED upon underrun
212  AudioCodec *codec; // Required to hard reset audio codec from loop
213 };
214 
215 
216 #endif /* PRU_H_ */
uint32_t audioOutChannels
Number of output audio channels.
Definition: PRU.h:62
uint32_t analogOutChannels
Number of output analog channels.
Definition: PRU.h:79
Definition: AudioCodec.h:4
float digitalSampleRate
Digital sample rate in Hz (currently always 44100.0)
Definition: PRU.h:96
uint32_t digitalFrames
Number of digital frames per period.
Definition: PRU.h:90
float * audioIn
Buffer holding audio input samples.
Definition: PRU.h:29
uint32_t audioInChannels
Number of input audio channels.
Definition: PRU.h:60
uint32_t audioFrames
Number of audio frames per period.
Definition: PRU.h:58
float * multiplexerAnalogIn
Buffer which holds multiplexed analog inputs, when multiplexer capelet is enabled.
Definition: PRU.h:123
uint32_t digitalChannels
Number of digital channels.
Definition: PRU.h:94
uint32_t * digital
Buffer holding digital input/output samples.
Definition: PRU.h:55
uint32_t analogFrames
Number of analog frames per period.
Definition: PRU.h:69
Definition: PRU.h:143
Definition: Gpio.h:32
uint32_t analogInChannels
Number of input analog channels.
Definition: PRU.h:74
float * analogIn
Buffer holding analog input samples.
Definition: PRU.h:43
Structure holding audio and sensor settings and pointers to I/O data buffers.
Definition: Bela.h:148
uint32_t flags
Other audio/sensor settings.
Definition: PRU.h:139
float * analogOut
Buffer holding analog output samples.
Definition: PRU.h:50
float * audioOut
Buffer holding audio output samples.
Definition: PRU.h:36
uint32_t audioExpanderEnabled
Flags for whether audio expander is enabled on given analog channels.
Definition: PRU.h:129
void render(BelaContext *context, void *userData)
User-defined callback function to process audio and sensor data.
Definition: render.cpp:40
float audioSampleRate
Audio sample rate in Hz (currently always 44100.0)
Definition: PRU.h:64
uint32_t multiplexerStartingChannel
Multiplexer channel corresponding to the first analog frame.
Definition: PRU.h:116
Main Bela public API.
uint32_t multiplexerChannels
Number of multiplexer channels for each analog input.
Definition: PRU.h:110
uint64_t audioFramesElapsed
Number of elapsed audio frames since the start of rendering.
Definition: PRU.h:104
float analogSampleRate
Analog sample rate in Hz.
Definition: PRU.h:87
Definition: PRU.h:23