diff core/PRU.cpp @ 303:421a69d42943 prerelease

Changed BeagleRT -> Bela in defines and thread names; some preliminary mux capelet stuff
author andrewm
date Fri, 27 May 2016 17:40:44 +0100
parents e4392164b458
children ff5f346a293e
line wrap: on
line diff
--- a/core/PRU.cpp	Fri May 27 17:28:24 2016 +0100
+++ b/core/PRU.cpp	Fri May 27 17:40:44 2016 +0100
@@ -64,6 +64,7 @@
 #define PRU_USE_DIGITAL      11
 #define PRU_PRU_NUMBER       12
 #define PRU_MUX_CONFIG       13
+#define PRU_MUX_END_CHANNEL  14
 
 short int digitalPins[NUM_DIGITALS] = {
 		GPIO_NO_BIT_0,
@@ -113,6 +114,7 @@
 PRU::PRU(BelaContext *input_context)
 : context(input_context), pru_number(0), running(false), analog_enabled(false),
   digital_enabled(false), gpio_enabled(false), led_enabled(false),
+  mux_channels(0),
   gpio_test_pin_enabled(false),
   pru_buffer_comm(0), pru_buffer_spi_dac(0), pru_buffer_spi_adc(0),
   pru_buffer_digital(0), pru_buffer_audio_dac(0), pru_buffer_audio_adc(0),
@@ -290,6 +292,7 @@
 	}
 
 	pru_number = pru_num;
+	this->mux_channels = mux_channels;
 
     /* Initialize structure used by prussdrv_pruintc_intc   */
     /* PRUSS_INTC_INITDATA is found in pruss_intc_mapping.h */
@@ -478,7 +481,7 @@
 // Main loop to read and write data from/to PRU
 void PRU::loop(RT_INTR *pru_interrupt, void *userData)
 {
-#ifdef BEAGLERT_USE_XENOMAI_INTERRUPTS
+#ifdef BELA_USE_XENOMAI_INTERRUPTS
 	RTIME irqTimeout = PRU_SAMPLE_INTERVAL_NS * 1024;	// Timeout for PRU interrupt: about 10ms, much longer than any expected period
 #else
 	// Polling interval is 1/4 of the period
@@ -492,7 +495,7 @@
 	// directions and output values at something other than defaults.
 
 	if(analog_enabled) {
-		if(context->flags & BEAGLERT_FLAG_ANALOG_OUTPUTS_PERSIST) {
+		if(context->flags & BELA_FLAG_ANALOG_OUTPUTS_PERSIST) {
 			// Remember the content of the last_analog_out_frame
 			for(unsigned int ch = 0; ch < context->analogChannels; ch++){
 				last_analog_out_frame[ch] = context->analogOut[context->analogChannels * (context->analogFrames - 1) + ch];
@@ -510,7 +513,7 @@
 	// uint32_t testCount = 0;
 	// RTIME startTime = rt_timer_read();
 
-#ifdef BEAGLERT_USE_XENOMAI_INTERRUPTS
+#ifdef BELA_USE_XENOMAI_INTERRUPTS
 	int result;
 #else
 	// Which buffer the PRU was last processing
@@ -518,7 +521,7 @@
 #endif
 
 	while(!gShouldStop) {
-#ifdef BEAGLERT_USE_XENOMAI_INTERRUPTS
+#ifdef BELA_USE_XENOMAI_INTERRUPTS
 		// Wait for PRU to move to change buffers;
 		// PRU will send an interrupts which we wait for
 		rt_intr_enable(pru_interrupt);
@@ -582,11 +585,19 @@
 			context->audioIn[n] = (float)pru_buffer_audio_adc[n + pru_audio_offset] / 32768.0f;
 
 		if(analog_enabled) {
+			if(mux_channels != 0) {
+				// If multiplexer is enabled, find out which channels we have by pulling out
+				// the place that it ended. 
+				// int lastMuxChannel = pru_buffer_comm[PRU_MUX_END_CHANNEL];
+				
+				// TODO
+			}
+			
 			// TODO: NEON
 			for(unsigned int n = 0; n < context->analogChannels * context->analogFrames; n++)
 				context->analogIn[n] = (float)pru_buffer_spi_adc[n + pru_spi_offset] / 65536.0f;
 
-			if(context->flags & BEAGLERT_FLAG_ANALOG_OUTPUTS_PERSIST) {
+			if(context->flags & BELA_FLAG_ANALOG_OUTPUTS_PERSIST) {
 				// Initialize the output buffer with the values that were in the last frame of the previous output
 				for(unsigned int ch = 0; ch < context->analogChannels; ch++){
 					for(unsigned int n = 0; n < context->analogFrames; n++){
@@ -623,7 +634,7 @@
 		// ***********************
 
 		if(analog_enabled) {
-			if(context->flags & BEAGLERT_FLAG_ANALOG_OUTPUTS_PERSIST) {
+			if(context->flags & BELA_FLAG_ANALOG_OUTPUTS_PERSIST) {
 				// Remember the content of the last_analog_out_frame
 				for(unsigned int ch = 0; ch < context->analogChannels; ch++){
 					last_analog_out_frame[ch] = context->analogOut[context->analogChannels * (context->analogFrames - 1) + ch];
@@ -669,7 +680,7 @@
 		//	break;
 	}
 
-#ifdef BEAGLERT_USE_XENOMAI_INTERRUPTS
+#ifdef BELA_USE_XENOMAI_INTERRUPTS
 	// Turn off the interrupt for the PRU if it isn't already off
 	rt_intr_disable(pru_interrupt);
 #endif