changeset 280:c55c6f6c233c prerelease

Added support for multiplexer capelet and command-line support for choosing PRU
author andrewm
date Tue, 17 May 2016 17:49:23 +0100
parents 3c3d042dad12
children 5f17da990d1b
files core/PRU.cpp core/RTAudio.cpp core/RTAudioCommandLine.cpp include/BeagleRT.h include/PRU.h
diffstat 5 files changed, 51 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/core/PRU.cpp	Tue May 17 16:07:45 2016 +0100
+++ b/core/PRU.cpp	Tue May 17 17:49:23 2016 +0100
@@ -48,6 +48,8 @@
 #define PRU_MEM_DIGITAL_OFFSET 0x1000 //Offset within PRU-SHARED RAM
 #define MEM_DIGITAL_BUFFER1_OFFSET 0x400 //Start pointer to DIGITAL_BUFFER1, which is 256 words.
 											// 256 is the maximum number of frames allowed
+
+// Offsets within CPU <-> PRU communication memory (4 byte slots)
 #define PRU_SHOULD_STOP 	0
 #define PRU_CURRENT_BUFFER  1
 #define PRU_BUFFER_FRAMES   2
@@ -61,8 +63,9 @@
 #define PRU_SPI_NUM_CHANNELS 10
 #define PRU_USE_DIGITAL      11
 #define PRU_PRU_NUMBER       12
+#define PRU_MUX_CONFIG       13
 
-short int digitalPins[NUM_DIGITALS]={
+short int digitalPins[NUM_DIGITALS] = {
 		GPIO_NO_BIT_0,
 		GPIO_NO_BIT_1,
 		GPIO_NO_BIT_2,
@@ -277,7 +280,7 @@
 }
 
 // Initialise and open the PRU
-int PRU::initialise(int pru_num, int frames_per_buffer, int spi_channels, bool xenomai_test_pin)
+int PRU::initialise(int pru_num, int frames_per_buffer, int spi_channels, int mux_channels, bool xenomai_test_pin)
 {
 	uint32_t *pruMem = 0;
 
@@ -337,6 +340,16 @@
     pru_buffer_comm[PRU_SYNC_ADDRESS] = 0;
     pru_buffer_comm[PRU_SYNC_PIN_MASK] = 0;
     pru_buffer_comm[PRU_PRU_NUMBER] = pru_number;
+	
+	if(mux_channels == 2) 
+		pru_buffer_comm[PRU_MUX_CONFIG] = 1;
+	else if(mux_channels == 4)
+		pru_buffer_comm[PRU_MUX_CONFIG] = 2;
+	else if(mux_channels == 8)
+		pru_buffer_comm[PRU_MUX_CONFIG] = 3;
+	else
+		pru_buffer_comm[PRU_MUX_CONFIG] = 0;
+	
     if(led_enabled) {
     	pru_buffer_comm[PRU_LED_ADDRESS] = USERLED3_GPIO_BASE;
     	pru_buffer_comm[PRU_LED_PIN_MASK] = USERLED3_PIN_MASK;
--- a/core/RTAudio.cpp	Tue May 17 16:07:45 2016 +0100
+++ b/core/RTAudio.cpp	Tue May 17 17:49:23 2016 +0100
@@ -98,6 +98,16 @@
 
 int BeagleRT_initAudio(BeagleRTInitSettings *settings, void *userData)
 {
+	// Sanity checks
+	if(settings->pruNumber < 0 || settings->pruNumber > 1) {
+		cout << "Invalid PRU number " << settings->pruNumber << endl;
+		return -1;
+	}
+	if(settings->pruNumber != 1 && settings->numMuxChannels != 0) {
+		cout << "Incompatible settings: multiplexer can only be run using PRU 1\n";
+		return -1;
+	}
+	
 	rt_print_auto_init(1);
 
 	BeagleRT_setVerboseLevel(settings->verbose);
@@ -202,9 +212,10 @@
 		cout << "Error: unable to prepare GPIO for PRU audio\n";
 		return 1;
 	}
-
+	
 	// Get the PRU memory buffers ready to go
-	if(gPRU->initialise(0, gContext.analogFrames, gContext.analogChannels, true)) {
+	if(gPRU->initialise(settings->pruNumber, gContext.analogFrames, gContext.analogChannels,
+		 				settings->numMuxChannels, true)) {
 		cout << "Error: unable to initialise PRU\n";
 		return 1;
 	}
--- a/core/RTAudioCommandLine.cpp	Tue May 17 16:07:45 2016 +0100
+++ b/core/RTAudioCommandLine.cpp	Tue May 17 17:49:23 2016 +0100
@@ -14,6 +14,7 @@
 #define OPT_PRU_FILE 1000
 #define OPT_PGA_GAIN_LEFT 1001
 #define OPT_PGA_GAIN_RIGHT 1002
+#define OPT_PRU_NUMBER 1003
 
 
 enum {
@@ -39,6 +40,7 @@
 	{"transmit-port", 1, NULL, 'T'},
 	{"server-name", 1, NULL, 'S'},
 	{"pru-file", 1, NULL, OPT_PRU_FILE},
+	{"pru-number", 1, NULL, OPT_PRU_NUMBER},
 	{NULL, 0, NULL, 0}
 };
 
@@ -60,8 +62,10 @@
 	for(int n = 0; n < 2; n++)
 		settings->pgaGain[n] = DEFAULT_PGA_GAIN;
 	settings->headphoneLevel = DEFAULT_HP_LEVEL;
+	settings->numMuxChannels = 0;
 
 	settings->verbose = 0;
+	settings->pruNumber = 0;
 	settings->pruFilename[0] = '\0';
 
 	// These two deliberately have no command-line flags by default.
@@ -166,8 +170,16 @@
 			break;
 		case 'C':
 			settings->numAnalogChannels = atoi(optarg);
-			if(settings->numAnalogChannels >= 8)
+			if(settings->numAnalogChannels >= 8) {
+				// Use multiplexer capelet to run larger numbers of channels
+				if(settings->numAnalogChannels >= 64)
+					settings->numMuxChannels = 8;
+				else if(settings->numAnalogChannels >= 32)
+					settings->numMuxChannels = 4;
+				else if(settings->numAnalogChannels >= 16)
+					settings->numMuxChannels = 2;
 				settings->numAnalogChannels = 8;
+			}
 			else if(settings->numAnalogChannels >= 4)
 				settings->numAnalogChannels = 4;
 			else
@@ -220,6 +232,9 @@
 		case OPT_PGA_GAIN_RIGHT:
 			settings->pgaGain[1] = atof(optarg);
 			break;
+		case OPT_PRU_NUMBER:
+			settings->pruNumber = atoi(optarg);
+			break;
 		case '?':
 		default:
 			return c;
@@ -246,6 +261,7 @@
 	std::cerr << "   --transmit-port [-T] val:        Set the transmit port (default: 9999)\n";
 	std::cerr << "   --server-name [-S] val:          Set the destination server name (default: '127.0.0.1')\n";
 	std::cerr << "   --pru-file val:                  Set an optional external file to use for the PRU binary code\n";
+	std::cerr << "   --pru-number val:                Set the PRU to use for I/O (options: 0 or 1, default: 0)\n";
 	std::cerr << "   --verbose [-v]:                  Enable verbose logging information\n";
 }
 
--- a/include/BeagleRT.h	Tue May 17 16:07:45 2016 +0100
+++ b/include/BeagleRT.h	Tue May 17 17:49:23 2016 +0100
@@ -132,7 +132,11 @@
 	float pgaGain[2];
 	/// Level for the headphone output
 	float headphoneLevel;
+	/// How many channels to use on the multiplexer capelet, if enabled
+	int numMuxChannels;
 
+	/// Which PRU (0 or 1) the code should run on
+	int pruNumber; 
 	/// The external .bin file to load. If empty will use PRU code from pru_rtaudio_bin.h
 	char pruFilename[MAX_PRU_FILENAME_LENGTH];
 	/// Whether to use verbose logging
--- a/include/PRU.h	Tue May 17 16:07:45 2016 +0100
+++ b/include/PRU.h	Tue May 17 17:49:23 2016 +0100
@@ -36,7 +36,8 @@
 
 	// Initialise and open the PRU
 	int initialise(int pru_num, int frames_per_buffer,
-				   int spi_channels, bool xenomai_test_pin = false);
+				   int spi_channels, int mux_channels = 0, 
+				   bool xenomai_test_pin = false);
 
 	// Run the code image in pru_rtaudio_bin.h
 	int start(char * const filename);