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 <native/intr.h>
13 #include "../include/Bela.h"
14 
22 typedef struct {
28  float *audioIn;
29 
35  float *audioOut;
36 
42  float *analogIn;
43 
49  float *analogOut;
50 
54  uint32_t *digital;
55 
57  uint32_t audioFrames;
59  uint32_t audioInChannels;
61  uint32_t audioOutChannels;
64 
68  uint32_t analogFrames;
69 
73  uint32_t analogInChannels;
74 
79 
87 
89  uint32_t digitalFrames;
93  uint32_t digitalChannels;
96 
104 
113  uint32_t flags;
115 
116 
117 class PRU
118 {
119 private:
120  static const unsigned int kPruGPIODACSyncPin;
121  static const unsigned int kPruGPIOADCSyncPin;
122  static const unsigned int kPruGPIOTestPin;
123  static const unsigned int kPruGPIOTestPin2;
124  static const unsigned int kPruGPIOTestPin3;
125 
126 public:
127  // Constructor
128  PRU(InternalBelaContext *input_context);
129 
130  // Destructor
131  ~PRU();
132 
133  // Prepare the GPIO pins needed for the PRU
134  int prepareGPIO(int include_test_pin, int include_led);
135 
136  // Clean up the GPIO at the end
137  void cleanupGPIO();
138 
139  // Initialise and open the PRU
140  int initialise(int pru_num, int frames_per_buffer,
141  int spi_channels, int mux_channels = 0,
142  bool xenomai_test_pin = false);
143 
144  // Run the code image in pru_rtaudio_bin.h
145  int start(char * const filename);
146 
147  // Loop: read and write data from the PRU
148  void loop(RT_INTR *pru_interrupt, void *userData);
149 
150  // Wait for an interrupt from the PRU indicate it is finished
151  void waitForFinish();
152 
153  // Turn off the PRU when done
154  void disable();
155 
156  // For debugging:
157  void setGPIOTestPin();
158  void clearGPIOTestPin();
159 
160 private:
161  InternalBelaContext *context; // Overall settings
162 
163  int pru_number; // Which PRU we use
164  bool running; // Whether the PRU is running
165  bool analog_enabled; // Whether SPI ADC and DAC are used
166  bool digital_enabled; // Whether digital is used
167  bool gpio_enabled; // Whether GPIO has been prepared
168  bool led_enabled; // Whether a user LED is enabled
169  int mux_channels; // How many mux channels are used (if enabled)
170  bool gpio_test_pin_enabled; // Whether the test pin was also enabled
171 
172 
173  volatile uint32_t *pru_buffer_comm;
174  uint16_t *pru_buffer_spi_dac;
175  uint16_t *pru_buffer_spi_adc;
176  uint32_t *pru_buffer_digital;
177  int16_t *pru_buffer_audio_dac;
178  int16_t *pru_buffer_audio_adc;
179 
180  float *last_analog_out_frame;
181  uint32_t *digital_buffer0, *digital_buffer1, *last_digital_buffer;
182 
183  int xenomai_gpio_fd; // File descriptor for /dev/mem for fast GPIO
184  uint32_t *xenomai_gpio; // Pointer to GPIO registers
185 };
186 
187 
188 #endif /* PRU_H_ */
uint32_t audioOutChannels
Number of output audio channels.
Definition: PRU.h:61
uint32_t analogOutChannels
Number of output analog channels.
Definition: PRU.h:78
float digitalSampleRate
Digital sample rate in Hz (currently always 44100.0)
Definition: PRU.h:95
uint32_t digitalFrames
Number of digital frames per period.
Definition: PRU.h:89
float * audioIn
Buffer holding audio input samples.
Definition: PRU.h:28
uint32_t audioInChannels
Number of input audio channels.
Definition: PRU.h:59
uint32_t audioFrames
Number of audio frames per period.
Definition: PRU.h:57
uint32_t digitalChannels
Number of digital channels.
Definition: PRU.h:93
uint32_t * digital
Buffer holding digital input/output samples.
Definition: PRU.h:54
uint32_t analogFrames
Number of analog frames per period.
Definition: PRU.h:68
Definition: PRU.h:117
uint32_t analogInChannels
Number of input analog channels.
Definition: PRU.h:73
float * analogIn
Buffer holding analog input samples.
Definition: PRU.h:42
uint32_t flags
Other audio/sensor settings.
Definition: PRU.h:113
float * analogOut
Buffer holding analog output samples.
Definition: PRU.h:49
float * audioOut
Buffer holding audio output samples.
Definition: PRU.h:35
float audioSampleRate
Audio sample rate in Hz (currently always 44100.0)
Definition: PRU.h:63
uint64_t audioFramesElapsed
Number of elapsed audio frames since the start of rendering.
Definition: PRU.h:103
float analogSampleRate
Analog sample rate in Hz.
Definition: PRU.h:86
Definition: PRU.h:22