comparison 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
comparison
equal deleted inserted replaced
302:b26e7c61e3b6 303:421a69d42943
62 #define PRU_USE_SPI 9 62 #define PRU_USE_SPI 9
63 #define PRU_SPI_NUM_CHANNELS 10 63 #define PRU_SPI_NUM_CHANNELS 10
64 #define PRU_USE_DIGITAL 11 64 #define PRU_USE_DIGITAL 11
65 #define PRU_PRU_NUMBER 12 65 #define PRU_PRU_NUMBER 12
66 #define PRU_MUX_CONFIG 13 66 #define PRU_MUX_CONFIG 13
67 #define PRU_MUX_END_CHANNEL 14
67 68
68 short int digitalPins[NUM_DIGITALS] = { 69 short int digitalPins[NUM_DIGITALS] = {
69 GPIO_NO_BIT_0, 70 GPIO_NO_BIT_0,
70 GPIO_NO_BIT_1, 71 GPIO_NO_BIT_1,
71 GPIO_NO_BIT_2, 72 GPIO_NO_BIT_2,
111 112
112 // Constructor: specify a PRU number (0 or 1) 113 // Constructor: specify a PRU number (0 or 1)
113 PRU::PRU(BelaContext *input_context) 114 PRU::PRU(BelaContext *input_context)
114 : context(input_context), pru_number(0), running(false), analog_enabled(false), 115 : context(input_context), pru_number(0), running(false), analog_enabled(false),
115 digital_enabled(false), gpio_enabled(false), led_enabled(false), 116 digital_enabled(false), gpio_enabled(false), led_enabled(false),
117 mux_channels(0),
116 gpio_test_pin_enabled(false), 118 gpio_test_pin_enabled(false),
117 pru_buffer_comm(0), pru_buffer_spi_dac(0), pru_buffer_spi_adc(0), 119 pru_buffer_comm(0), pru_buffer_spi_dac(0), pru_buffer_spi_adc(0),
118 pru_buffer_digital(0), pru_buffer_audio_dac(0), pru_buffer_audio_adc(0), 120 pru_buffer_digital(0), pru_buffer_audio_dac(0), pru_buffer_audio_adc(0),
119 xenomai_gpio_fd(-1), xenomai_gpio(0) 121 xenomai_gpio_fd(-1), xenomai_gpio(0)
120 { 122 {
288 rt_printf("initialise() called before GPIO enabled\n"); 290 rt_printf("initialise() called before GPIO enabled\n");
289 return 1; 291 return 1;
290 } 292 }
291 293
292 pru_number = pru_num; 294 pru_number = pru_num;
295 this->mux_channels = mux_channels;
293 296
294 /* Initialize structure used by prussdrv_pruintc_intc */ 297 /* Initialize structure used by prussdrv_pruintc_intc */
295 /* PRUSS_INTC_INITDATA is found in pruss_intc_mapping.h */ 298 /* PRUSS_INTC_INITDATA is found in pruss_intc_mapping.h */
296 tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA; 299 tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;
297 300
476 } 479 }
477 480
478 // Main loop to read and write data from/to PRU 481 // Main loop to read and write data from/to PRU
479 void PRU::loop(RT_INTR *pru_interrupt, void *userData) 482 void PRU::loop(RT_INTR *pru_interrupt, void *userData)
480 { 483 {
481 #ifdef BEAGLERT_USE_XENOMAI_INTERRUPTS 484 #ifdef BELA_USE_XENOMAI_INTERRUPTS
482 RTIME irqTimeout = PRU_SAMPLE_INTERVAL_NS * 1024; // Timeout for PRU interrupt: about 10ms, much longer than any expected period 485 RTIME irqTimeout = PRU_SAMPLE_INTERVAL_NS * 1024; // Timeout for PRU interrupt: about 10ms, much longer than any expected period
483 #else 486 #else
484 // Polling interval is 1/4 of the period 487 // Polling interval is 1/4 of the period
485 RTIME sleepTime = PRU_SAMPLE_INTERVAL_NS * (context->analogChannels / 2) * context->analogFrames / 4; 488 RTIME sleepTime = PRU_SAMPLE_INTERVAL_NS * (context->analogChannels / 2) * context->analogFrames / 4;
486 #endif 489 #endif
490 // Before starting, look at the last state of the analog and digital outputs which might 493 // Before starting, look at the last state of the analog and digital outputs which might
491 // have been changed by the user during the setup() function. This lets us start with pin 494 // have been changed by the user during the setup() function. This lets us start with pin
492 // directions and output values at something other than defaults. 495 // directions and output values at something other than defaults.
493 496
494 if(analog_enabled) { 497 if(analog_enabled) {
495 if(context->flags & BEAGLERT_FLAG_ANALOG_OUTPUTS_PERSIST) { 498 if(context->flags & BELA_FLAG_ANALOG_OUTPUTS_PERSIST) {
496 // Remember the content of the last_analog_out_frame 499 // Remember the content of the last_analog_out_frame
497 for(unsigned int ch = 0; ch < context->analogChannels; ch++){ 500 for(unsigned int ch = 0; ch < context->analogChannels; ch++){
498 last_analog_out_frame[ch] = context->analogOut[context->analogChannels * (context->analogFrames - 1) + ch]; 501 last_analog_out_frame[ch] = context->analogOut[context->analogChannels * (context->analogFrames - 1) + ch];
499 } 502 }
500 } 503 }
508 511
509 // TESTING 512 // TESTING
510 // uint32_t testCount = 0; 513 // uint32_t testCount = 0;
511 // RTIME startTime = rt_timer_read(); 514 // RTIME startTime = rt_timer_read();
512 515
513 #ifdef BEAGLERT_USE_XENOMAI_INTERRUPTS 516 #ifdef BELA_USE_XENOMAI_INTERRUPTS
514 int result; 517 int result;
515 #else 518 #else
516 // Which buffer the PRU was last processing 519 // Which buffer the PRU was last processing
517 uint32_t lastPRUBuffer = 0; 520 uint32_t lastPRUBuffer = 0;
518 #endif 521 #endif
519 522
520 while(!gShouldStop) { 523 while(!gShouldStop) {
521 #ifdef BEAGLERT_USE_XENOMAI_INTERRUPTS 524 #ifdef BELA_USE_XENOMAI_INTERRUPTS
522 // Wait for PRU to move to change buffers; 525 // Wait for PRU to move to change buffers;
523 // PRU will send an interrupts which we wait for 526 // PRU will send an interrupts which we wait for
524 rt_intr_enable(pru_interrupt); 527 rt_intr_enable(pru_interrupt);
525 while(!gShouldStop) { 528 while(!gShouldStop) {
526 result = rt_intr_wait(pru_interrupt, irqTimeout); 529 result = rt_intr_wait(pru_interrupt, irqTimeout);
580 // TODO: NEON 583 // TODO: NEON
581 for(unsigned int n = 0; n < 2 * context->audioFrames; n++) 584 for(unsigned int n = 0; n < 2 * context->audioFrames; n++)
582 context->audioIn[n] = (float)pru_buffer_audio_adc[n + pru_audio_offset] / 32768.0f; 585 context->audioIn[n] = (float)pru_buffer_audio_adc[n + pru_audio_offset] / 32768.0f;
583 586
584 if(analog_enabled) { 587 if(analog_enabled) {
588 if(mux_channels != 0) {
589 // If multiplexer is enabled, find out which channels we have by pulling out
590 // the place that it ended.
591 // int lastMuxChannel = pru_buffer_comm[PRU_MUX_END_CHANNEL];
592
593 // TODO
594 }
595
585 // TODO: NEON 596 // TODO: NEON
586 for(unsigned int n = 0; n < context->analogChannels * context->analogFrames; n++) 597 for(unsigned int n = 0; n < context->analogChannels * context->analogFrames; n++)
587 context->analogIn[n] = (float)pru_buffer_spi_adc[n + pru_spi_offset] / 65536.0f; 598 context->analogIn[n] = (float)pru_buffer_spi_adc[n + pru_spi_offset] / 65536.0f;
588 599
589 if(context->flags & BEAGLERT_FLAG_ANALOG_OUTPUTS_PERSIST) { 600 if(context->flags & BELA_FLAG_ANALOG_OUTPUTS_PERSIST) {
590 // Initialize the output buffer with the values that were in the last frame of the previous output 601 // Initialize the output buffer with the values that were in the last frame of the previous output
591 for(unsigned int ch = 0; ch < context->analogChannels; ch++){ 602 for(unsigned int ch = 0; ch < context->analogChannels; ch++){
592 for(unsigned int n = 0; n < context->analogFrames; n++){ 603 for(unsigned int n = 0; n < context->analogFrames; n++){
593 context->analogOut[n * context->analogChannels + ch] = last_analog_out_frame[ch]; 604 context->analogOut[n * context->analogChannels + ch] = last_analog_out_frame[ch];
594 } 605 }
621 // *********************** 632 // ***********************
622 render(context, userData); 633 render(context, userData);
623 // *********************** 634 // ***********************
624 635
625 if(analog_enabled) { 636 if(analog_enabled) {
626 if(context->flags & BEAGLERT_FLAG_ANALOG_OUTPUTS_PERSIST) { 637 if(context->flags & BELA_FLAG_ANALOG_OUTPUTS_PERSIST) {
627 // Remember the content of the last_analog_out_frame 638 // Remember the content of the last_analog_out_frame
628 for(unsigned int ch = 0; ch < context->analogChannels; ch++){ 639 for(unsigned int ch = 0; ch < context->analogChannels; ch++){
629 last_analog_out_frame[ch] = context->analogOut[context->analogChannels * (context->analogFrames - 1) + ch]; 640 last_analog_out_frame[ch] = context->analogOut[context->analogChannels * (context->analogFrames - 1) + ch];
630 } 641 }
631 } 642 }
667 // FIXME: TESTING!! 678 // FIXME: TESTING!!
668 // if(testCount > 100000) 679 // if(testCount > 100000)
669 // break; 680 // break;
670 } 681 }
671 682
672 #ifdef BEAGLERT_USE_XENOMAI_INTERRUPTS 683 #ifdef BELA_USE_XENOMAI_INTERRUPTS
673 // Turn off the interrupt for the PRU if it isn't already off 684 // Turn off the interrupt for the PRU if it isn't already off
674 rt_intr_disable(pru_interrupt); 685 rt_intr_disable(pru_interrupt);
675 #endif 686 #endif
676 687
677 // FIXME: TESTING 688 // FIXME: TESTING