annotate include/PRU.h @ 499:a15a116f6904 prerelease

Took some of the verbosity out of the Doxyfile
author Giulio Moro <giuliomoro@yahoo.it>
date Wed, 22 Jun 2016 00:04:04 +0100
parents 493a07f6ec09
children 5c8f46fcd4d0
rev   line source
andrewm@0 1 /*
andrewm@0 2 * PRU.h
andrewm@0 3 *
andrewm@0 4 * Created on: May 27, 2014
andrewm@0 5 * Author: andrewm
andrewm@0 6 */
andrewm@0 7
andrewm@0 8 #ifndef PRU_H_
andrewm@0 9 #define PRU_H_
andrewm@0 10
andrewm@0 11 #include <stdint.h>
andrewm@45 12 #include <native/intr.h>
giuliomoro@301 13 #include "../include/Bela.h"
andrewm@0 14
andrewm@307 15 /**
andrewm@307 16 * Internal version of the BelaContext struct which does not have const
andrewm@307 17 * elements, so it can be modified by the code. When it's passed to the user
andrewm@307 18 * code, it is typecast to the standard BelaContext.
andrewm@307 19 *
andrewm@307 20 * Important: make sure this retains the same structure as BelaContext!
andrewm@307 21 */
andrewm@307 22 typedef struct {
andrewm@307 23 /// \brief Buffer holding audio input samples
andrewm@307 24 ///
andrewm@307 25 /// This buffer may be in either interleaved or non-interleaved format,
andrewm@307 26 /// depending on the contents of the BelaInitSettings structure.
andrewm@307 27 /// \b Note: this element is available in render() only.
andrewm@307 28 float *audioIn;
andrewm@307 29
andrewm@307 30 /// \brief Buffer holding audio output samples
andrewm@307 31 ///
andrewm@307 32 /// This buffer may be in either interleaved or non-interleaved format,
andrewm@307 33 /// depending on the contents of the BelaInitSettings structure.
andrewm@307 34 /// \b Note: this element is available in render() only.
andrewm@307 35 float *audioOut;
andrewm@307 36
andrewm@307 37 /// \brief Buffer holding analog input samples
andrewm@307 38 ///
andrewm@307 39 /// This buffer may be in either interleaved or non-interleaved format,
andrewm@307 40 /// depending on the contents of the BelaInitSettings structure.
andrewm@307 41 /// \b Note: this element is available in render() only.
andrewm@307 42 float *analogIn;
andrewm@307 43
andrewm@307 44 /// \brief Buffer holding analog output samples
andrewm@307 45 ///
andrewm@307 46 /// This buffer may be in either interleaved or non-interleaved format,
andrewm@307 47 /// depending on the contents of the BelaInitSettings structure.
andrewm@307 48 /// \b Note: this element is available in render() only.
andrewm@307 49 float *analogOut;
andrewm@307 50
andrewm@307 51 /// \brief Buffer holding digital input/output samples
andrewm@307 52 ///
andrewm@307 53 /// \b Note: this element is available in render() only.
andrewm@307 54 uint32_t *digital;
andrewm@307 55
andrewm@307 56 /// Number of audio frames per period
andrewm@307 57 uint32_t audioFrames;
andrewm@307 58 /// Number of audio channels (currently always 2)
andrewm@307 59 uint32_t audioChannels;
andrewm@307 60 /// Audio sample rate in Hz (currently always 44100.0)
andrewm@307 61 float audioSampleRate;
andrewm@307 62
andrewm@307 63 /// \brief Number of analog frames per period
andrewm@307 64 ///
andrewm@307 65 /// This will be 0 if analog I/O is disabled.
andrewm@307 66 uint32_t analogFrames;
andrewm@307 67
andrewm@307 68 /// \brief Number of analog channels
andrewm@307 69 ///
andrewm@307 70 /// This could take a value of 8, 4 or 2. This will be 0 if analog I/O is disabled.
andrewm@307 71 uint32_t analogChannels;
andrewm@307 72
andrewm@307 73 /// \brief Analog sample rate in Hz
andrewm@307 74 ///
andrewm@307 75 /// The analog sample rate depends on the number of analog channels used. If
andrewm@307 76 /// 8 channels are used, the sample rate is 22050. If 4 channels are used, the sample
andrewm@307 77 /// rate is 44100. If 2 channels are used, the sample rate is 88200. If analog I/O
andrewm@307 78 /// is disabled, the sample rate is 0.
andrewm@307 79 float analogSampleRate;
andrewm@307 80
andrewm@307 81 /// Number of digital frames per period
andrewm@307 82 uint32_t digitalFrames;
andrewm@307 83 /// \brief Number of digital channels
andrewm@307 84 ///
andrewm@307 85 /// Currently this will always be 16, unless digital I/O is disabled, in which case it will be 0.
andrewm@307 86 uint32_t digitalChannels;
andrewm@307 87 /// Digital sample rate in Hz (currently always 44100.0)
andrewm@307 88 float digitalSampleRate;
andrewm@307 89
andrewm@311 90 /// \brief Number of elapsed audio frames since the start of rendering.
andrewm@307 91 ///
andrewm@311 92 /// This holds the total number of audio frames as of the beginning of the current period. To
andrewm@311 93 /// find the current number of analog or digital frames elapsed, multiply by the ratio of the
andrewm@311 94 /// sample rates (e.g. half the number of analog frames will have elapsed if the analog sample
andrewm@307 95 /// rate is 22050).
andrewm@311 96 uint64_t audioFramesElapsed;
andrewm@307 97
andrewm@307 98 /// \brief Other audio/sensor settings
andrewm@307 99 ///
andrewm@307 100 /// Binary combination of flags including:
andrewm@307 101 ///
andrewm@307 102 /// BELA_FLAG_INTERLEAVED: indicates the audio and analog buffers are interleaved
andrewm@307 103 ///
andrewm@307 104 /// BELA_FLAG_ANALOG_OUTPUTS_PERSIST: indicates that writes to the analog outputs will
andrewm@307 105 /// persist for future frames. If not set, writes affect one frame only.
andrewm@307 106 uint32_t flags;
andrewm@307 107 } InternalBelaContext;
andrewm@307 108
andrewm@307 109
andrewm@0 110 class PRU
andrewm@0 111 {
andrewm@0 112 private:
andrewm@0 113 static const unsigned int kPruGPIODACSyncPin;
andrewm@0 114 static const unsigned int kPruGPIOADCSyncPin;
andrewm@0 115 static const unsigned int kPruGPIOTestPin;
andrewm@0 116 static const unsigned int kPruGPIOTestPin2;
andrewm@0 117 static const unsigned int kPruGPIOTestPin3;
andrewm@0 118
andrewm@0 119 public:
andrewm@0 120 // Constructor
andrewm@307 121 PRU(InternalBelaContext *input_context);
andrewm@0 122
andrewm@0 123 // Destructor
andrewm@0 124 ~PRU();
andrewm@0 125
andrewm@0 126 // Prepare the GPIO pins needed for the PRU
andrewm@45 127 int prepareGPIO(int include_test_pin, int include_led);
andrewm@0 128
andrewm@0 129 // Clean up the GPIO at the end
andrewm@0 130 void cleanupGPIO();
andrewm@0 131
andrewm@0 132 // Initialise and open the PRU
andrewm@45 133 int initialise(int pru_num, int frames_per_buffer,
andrewm@280 134 int spi_channels, int mux_channels = 0,
andrewm@280 135 bool xenomai_test_pin = false);
andrewm@0 136
andrewm@15 137 // Run the code image in pru_rtaudio_bin.h
giuliomoro@16 138 int start(char * const filename);
andrewm@0 139
andrewm@0 140 // Loop: read and write data from the PRU
andrewm@45 141 void loop(RT_INTR *pru_interrupt, void *userData);
andrewm@0 142
andrewm@0 143 // Wait for an interrupt from the PRU indicate it is finished
andrewm@0 144 void waitForFinish();
andrewm@0 145
andrewm@0 146 // Turn off the PRU when done
andrewm@0 147 void disable();
andrewm@0 148
andrewm@0 149 // For debugging:
andrewm@0 150 void setGPIOTestPin();
andrewm@0 151 void clearGPIOTestPin();
andrewm@0 152
andrewm@0 153 private:
andrewm@307 154 InternalBelaContext *context; // Overall settings
andrewm@45 155
andrewm@0 156 int pru_number; // Which PRU we use
andrewm@0 157 bool running; // Whether the PRU is running
andrewm@45 158 bool analog_enabled; // Whether SPI ADC and DAC are used
giuliomoro@19 159 bool digital_enabled; // Whether digital is used
andrewm@0 160 bool gpio_enabled; // Whether GPIO has been prepared
andrewm@0 161 bool led_enabled; // Whether a user LED is enabled
andrewm@303 162 int mux_channels; // How many mux channels are used (if enabled)
andrewm@0 163 bool gpio_test_pin_enabled; // Whether the test pin was also enabled
andrewm@0 164
andrewm@303 165
andrewm@0 166 volatile uint32_t *pru_buffer_comm;
andrewm@0 167 uint16_t *pru_buffer_spi_dac;
andrewm@0 168 uint16_t *pru_buffer_spi_adc;
giuliomoro@19 169 uint32_t *pru_buffer_digital;
andrewm@0 170 int16_t *pru_buffer_audio_dac;
andrewm@0 171 int16_t *pru_buffer_audio_adc;
andrewm@0 172
andrewm@81 173 float *last_analog_out_frame;
andrewm@81 174 uint32_t *digital_buffer0, *digital_buffer1, *last_digital_buffer;
andrewm@81 175
andrewm@0 176 int xenomai_gpio_fd; // File descriptor for /dev/mem for fast GPIO
andrewm@0 177 uint32_t *xenomai_gpio; // Pointer to GPIO registers
andrewm@0 178 };
andrewm@0 179
andrewm@0 180
andrewm@0 181 #endif /* PRU_H_ */