andrewm@0: /* andrewm@0: * PRU.h andrewm@0: * andrewm@0: * Created on: May 27, 2014 andrewm@0: * Author: andrewm andrewm@0: */ andrewm@0: andrewm@0: #ifndef PRU_H_ andrewm@0: #define PRU_H_ andrewm@0: andrewm@0: #include andrewm@0: andrewm@0: class PRU andrewm@0: { andrewm@0: private: andrewm@0: static const unsigned int kPruGPIODACSyncPin; andrewm@0: static const unsigned int kPruGPIOADCSyncPin; andrewm@0: static const unsigned int kPruGPIOTestPin; andrewm@0: static const unsigned int kPruGPIOTestPin2; andrewm@0: static const unsigned int kPruGPIOTestPin3; andrewm@0: andrewm@0: public: andrewm@0: // Constructor andrewm@0: PRU(); andrewm@0: andrewm@0: // Destructor andrewm@0: ~PRU(); andrewm@0: andrewm@0: // Prepare the GPIO pins needed for the PRU andrewm@0: int prepareGPIO(int use_spi, int include_test_pin, int include_led); andrewm@0: andrewm@0: // Clean up the GPIO at the end andrewm@0: void cleanupGPIO(); andrewm@0: andrewm@0: // Initialise and open the PRU andrewm@12: int initialise(int pru_num, int frames_per_buffer, int spi_channels, andrewm@12: bool xenomai_test_pin = false); andrewm@0: andrewm@15: // Run the code image in pru_rtaudio_bin.h andrewm@15: int start(); andrewm@0: andrewm@0: // Loop: read and write data from the PRU andrewm@0: void loop(); andrewm@0: andrewm@0: // Wait for an interrupt from the PRU indicate it is finished andrewm@0: void waitForFinish(); andrewm@0: andrewm@0: // Turn off the PRU when done andrewm@0: void disable(); andrewm@0: andrewm@0: // For debugging: andrewm@0: void setGPIOTestPin(); andrewm@0: void clearGPIOTestPin(); andrewm@0: andrewm@0: private: andrewm@0: int pru_number; // Which PRU we use andrewm@0: bool running; // Whether the PRU is running andrewm@0: bool spi_enabled; // Whether SPI ADC and DAC are used andrewm@0: bool gpio_enabled; // Whether GPIO has been prepared andrewm@0: bool led_enabled; // Whether a user LED is enabled andrewm@0: bool gpio_test_pin_enabled; // Whether the test pin was also enabled andrewm@12: int spi_num_channels; // How many channels to use for SPI ADC/DAC andrewm@0: andrewm@0: volatile uint32_t *pru_buffer_comm; andrewm@0: uint16_t *pru_buffer_spi_dac; andrewm@0: uint16_t *pru_buffer_spi_adc; andrewm@0: int16_t *pru_buffer_audio_dac; andrewm@0: int16_t *pru_buffer_audio_adc; andrewm@0: unsigned int spi_buffer_frames; andrewm@0: unsigned int audio_buffer_frames; andrewm@0: andrewm@0: int xenomai_gpio_fd; // File descriptor for /dev/mem for fast GPIO andrewm@0: uint32_t *xenomai_gpio; // Pointer to GPIO registers andrewm@0: }; andrewm@0: andrewm@0: andrewm@0: #endif /* PRU_H_ */