Mercurial > hg > beaglert
changeset 259:abd3657016ea prerelease
merged new aux tasks
author | Liam Donovan <l.b.donovan@qmul.ac.uk> |
---|---|
date | Mon, 16 May 2016 12:16:59 +0100 |
parents | 33e0e4831763 (diff) 88cf310417cd (current diff) |
children | afdddd5f189f |
files | core/PRU.cpp |
diffstat | 5 files changed, 39 insertions(+), 222 deletions(-) [+] |
line wrap: on
line diff
--- a/core/PRU.cpp Sat May 07 13:23:15 2016 +0100 +++ b/core/PRU.cpp Mon May 16 12:16:59 2016 +0100 @@ -38,7 +38,7 @@ using namespace std; #define PRU_MEM_MCASP_OFFSET 0x2000 // Offset within PRU-SHARED RAM -#define PRU_MEM_MCASP_LENGTH 0x2000 // Length of McASP memory, in bytes +#define PRU_MEM_MCASP_LENGTH 0x1000 // Length of McASP memory, in bytes #define PRU_MEM_DAC_OFFSET 0x0 // Offset within PRU0 RAM #define PRU_MEM_DAC_LENGTH 0x2000 // Length of ADC+DAC memory, in bytes #define PRU_MEM_COMM_OFFSET 0x0 // Offset within PRU-SHARED RAM @@ -51,12 +51,13 @@ #define PRU_SHOULD_SYNC 3 #define PRU_SYNC_ADDRESS 4 #define PRU_SYNC_PIN_MASK 5 -#define PRU_LED_ADDRESS 6 -#define PRU_LED_PIN_MASK 7 -#define PRU_FRAME_COUNT 8 -#define PRU_USE_SPI 9 +#define PRU_LED_ADDRESS 6 +#define PRU_LED_PIN_MASK 7 +#define PRU_FRAME_COUNT 8 +#define PRU_USE_SPI 9 #define PRU_SPI_NUM_CHANNELS 10 -#define PRU_USE_DIGITAL 11 +#define PRU_USE_DIGITAL 11 +#define PRU_PRU_NUMBER 12 short int digitalPins[NUM_DIGITALS]={ GPIO_NO_BIT_0, @@ -332,6 +333,7 @@ pru_buffer_comm[PRU_SHOULD_SYNC] = 0; pru_buffer_comm[PRU_SYNC_ADDRESS] = 0; pru_buffer_comm[PRU_SYNC_PIN_MASK] = 0; + pru_buffer_comm[PRU_PRU_NUMBER] = pru_number; if(led_enabled) { pru_buffer_comm[PRU_LED_ADDRESS] = USERLED3_GPIO_BASE; pru_buffer_comm[PRU_LED_PIN_MASK] = USERLED3_PIN_MASK;
--- a/include/pru_rtaudio_bin.h Sat May 07 13:23:15 2016 +0100 +++ b/include/pru_rtaudio_bin.h Mon May 16 12:16:59 2016 +0100 @@ -275,20 +275,24 @@ 0xe1006287, 0xe1006384, 0x209c0000, - 0x240002c3, - 0x24202083, - 0x240000e2, - 0xe1002382, - 0x240002c3, - 0x24202883, - 0x240120e2, - 0xe1002382, 0x240001d9, 0x24000099, 0x244803da, 0x2401009a, 0x244803dd, 0x2480009d, + 0x240002c0, + 0x24400080, + 0xf1303982, + 0x5101e203, + 0x240002c0, + 0x24200080, + 0x1320e0e3, + 0x240000e2, + 0xe1002382, + 0x1328e0e3, + 0x240120e2, + 0xe1002382, 0x91042480, 0x1d04e0e0, 0x81042480, @@ -630,7 +634,7 @@ 0x79000002, 0x0b10eee7, 0xf1c03d82, - 0xd500e29d, + 0xd500e299, 0xcf05e2fe, 0x10e7e7fb, 0x240208fc, @@ -693,7 +697,7 @@ 0x4902e904, 0x1101eafb, 0x6900fb08, - 0x2102b300, + 0x2102b700, 0x1103e1fb, 0x6900fb05, 0xf100269b,
--- a/projects/scope/main.cpp Sat May 07 13:23:15 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,97 +0,0 @@ -/* - * main.cpp - * - * Created on: Oct 24, 2014 - * Author: parallels - */ -#include <unistd.h> -#include <iostream> -#include <cstdlib> -#include <libgen.h> -#include <signal.h> -#include <getopt.h> -#include <BeagleRT.h> - -using namespace std; - -// Handle Ctrl-C by requesting that the audio rendering stop -void interrupt_handler(int var) -{ - gShouldStop = true; -} - -// Print usage information -void usage(const char * processName) -{ - cerr << "Usage: " << processName << " [options]" << endl; - - BeagleRT_usage(); - - cerr << " --frequency [-f] frequency: Set the frequency of the oscillator\n"; - cerr << " --help [-h]: Print this menu\n"; -} - -int main(int argc, char *argv[]) -{ - BeagleRTInitSettings settings; // Standard audio settings - float frequency = 440.0; // Frequency of oscillator - - struct option customOptions[] = - { - {"help", 0, NULL, 'h'}, - {"frequency", 1, NULL, 'f'}, - {NULL, 0, NULL, 0} - }; - - // Set default settings - BeagleRT_defaultSettings(&settings); - - // Parse command-line arguments - while (1) { - int c; - if ((c = BeagleRT_getopt_long(argc, argv, "hf:", customOptions, &settings)) < 0) - break; - switch (c) { - case 'h': - usage(basename(argv[0])); - exit(0); - case 'f': - frequency = atof(optarg); - break; - case '?': - default: - usage(basename(argv[0])); - exit(1); - } - } - - // Initialise the PRU audio device - if(BeagleRT_initAudio(&settings, &frequency) != 0) { - cout << "Error: unable to initialise audio" << endl; - return -1; - } - - // Start the audio device running - if(BeagleRT_startAudio()) { - cout << "Error: unable to start real-time audio" << endl; - return -1; - } - - // Set up interrupt handler to catch Control-C and SIGTERM - signal(SIGINT, interrupt_handler); - signal(SIGTERM, interrupt_handler); - - // Run until told to stop - while(!gShouldStop) { - usleep(100000); - } - - // Stop the audio device - BeagleRT_stopAudio(); - - // Clean up any resources allocated for audio - BeagleRT_cleanupAudio(); - - // All done! - return 0; -}
--- a/projects/scope/render.cpp Sat May 07 13:23:15 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,101 +0,0 @@ -#include <BeagleRT.h> -#include <NetworkSend.h> -#include <ReceiveAudioThread.h> -#include <cmath> - -float gPhase1, gPhase2; -float gFrequency1, gFrequency2; -float gInverseSampleRate; - -Scope scope(2); //create a scope object with 2 channels -NetworkSend networkSend; - -// initialise_render() is called once before the audio rendering starts. -// Use it to perform any initialisation and allocation which is dependent -// on the period size or sample rate. -// -// userData holds an opaque pointer to a data structure that was passed -// in from the call to initAudio(). -// -// Return true on success; returning false halts the program. -ReceiveAudioThread receiveAudio0; -ReceiveAudioThread receiveAudio1; -bool setup(BeagleRTContext *context, void *userData) -{ - receiveAudio0.init(9999, context->audioFrames, 0); - receiveAudio1.init(10000, context->audioFrames, 1); - - scope.setup(); //call this once in setup to initialise the scope - scope.setPort(0, 9999); - scope.setPort(1, 10000); -// networkSend.setup(context->audioSampleRate, 0, 9999, "192.168.7.1"); - - gInverseSampleRate = 1.0/context->audioSampleRate; - - gPhase1 = 0.0; - gPhase2 = 0.0; - - gFrequency1 = 200.0; - gFrequency2 = 201.0; - - return true; -} - -// render() is called regularly at the highest priority by the audio engine. -// Input and output are given from the audio hardware and the other -// ADCs and DACs (if available). If only audio is available, numMatrixFrames -// will be 0. - -void render(BeagleRTContext *context, void *userData) -{ - static int count=0; - if(count==0){ - printf("startHread\n"); - ReceiveAudioThread::startThread(); - } - for(unsigned int n = 0; n < context->audioFrames; n++) { - - float chn0 = sinf(gPhase1); - float chn1 = sinf(gPhase2); - - // float chn2 = context->audioIn[n*2 + 0]; - // float chn3 = context->audioIn[n*2 + 1]; - - // float chn4 = context->analogIn[(int)n/2*8 + 0]; - // float chn5 = context->analogIn[(int)n/2*8 + 1]; - scope.log(0, chn0); - scope.log(1, chn1); - // scope.log(2, chn2); - // scope.log(3, chn3); - // scope.log(4, chn4); - // scope.log(5, chn5); - -// scope.log(chn1, chn2, chn3, chn4, chn5, chn6); - //call this once every audio frame - //takes six or fewer floats as parameters - //first parameter becomes channel 1 etc - //to view, click the 'oscilloscope' button on the toolbar while BeagleRT is NOT running - //then click the big red button on the toolbar on this page - - gPhase1 += 2.0 * M_PI * gFrequency1 * gInverseSampleRate * ((count&4095)/4096.0+1); - gPhase2 += 2.0 * M_PI * gFrequency2 * gInverseSampleRate; - if(gPhase1 > 2.0 * M_PI) - gPhase1 -= 2.0 * M_PI; - if(gPhase2 > 2.0 * M_PI) - gPhase2 -= 2.0 * M_PI; - - } - if(count>0){ - int readPointer0=receiveAudio0.getSamplesSrc(context->audioOut, context->audioFrames, 1, 2, 0); - int readPointer1=receiveAudio1.getSamplesSrc(context->audioOut, context->audioFrames, 1, 2, 1); - } - count++; -} - -// cleanup_render() is called once at the end, after the audio has stopped. -// Release any resources that were allocated in initialise_render(). - -void cleanup(BeagleRTContext *context, void *userData) -{ - -}
--- a/pru_rtaudio.p Sat May 07 13:23:15 2016 +0100 +++ b/pru_rtaudio.p Mon May 16 12:16:59 2016 +0100 @@ -82,7 +82,8 @@ #define COMM_FRAME_COUNT 32 // How many frames have elapse since beginning #define COMM_USE_SPI 36 // Whether or not to use SPI ADC and DAC #define COMM_NUM_CHANNELS 40 // Low 2 bits indicate 8 [0x3], 4 [0x1] or 2 [0x0] channels -#define COMM_USE_DIGITAL 44 // Whether or not to use DIGITAL +#define COMM_USE_DIGITAL 44 // Whether or not to use DIGITAL +#define COMM_PRU_NUMBER 48 // Which PRU this code is running on #define MCASP0_BASE 0x48038000 #define MCASP1_BASE 0x4803C000 @@ -549,22 +550,30 @@ .endm START: + // Load useful registers for addressing SPI + MOV reg_comm_addr, SHARED_COMM_MEM_BASE + MOV reg_spi_addr, SPI_BASE + MOV reg_mcasp_addr, MCASP_BASE + + // Find out which PRU we are running on + // This affects the following offsets + MOV r0, 0x24000 // PRU1 control register offset + LBBO r2, reg_comm_addr, COMM_PRU_NUMBER, 4 + QBEQ PRU_NUMBER_CHECK_DONE, r2, 1 + MOV r0, 0x22000 // PRU0 control register offset +PRU_NUMBER_CHECK_DONE: + // Set up c24 and c25 offsets with CTBIR register // Thus C24 points to start of PRU0 RAM - MOV r3, 0x22020 // CTBIR0 + OR r3, r0, 0x20 // CTBIR0 MOV r2, 0 SBBO r2, r3, 0, 4 // Set up c28 pointer offset for shared PRU RAM - MOV r3, 0x22028 // CTPPR0 + OR r3, r0, 0x28 // CTPPR0 MOV r2, 0x00000120 // To get address 0x00012000 SBBO r2, r3, 0, 4 - // Load useful registers for addressing SPI - MOV reg_comm_addr, SHARED_COMM_MEM_BASE - MOV reg_spi_addr, SPI_BASE - MOV reg_mcasp_addr, MCASP_BASE - // Set ARM such that PRU can write to registers LBCO r0, C4, 4, 4 CLR r0, r0, 4