comparison core/PRU.cpp @ 50:be427da6fb9c newapi

Removed old testing code that stopped audio after 10 seconds; command line parameter updates; D-Box updates (not fully working yet)
author andrewm
date Sat, 30 May 2015 12:34:32 -0500
parents 579c86316008
children a6d223473ea2
comparison
equal deleted inserted replaced
49:bb40e7e06b8c 50:be427da6fb9c
418 } 418 }
419 419
420 // Main loop to read and write data from/to PRU 420 // Main loop to read and write data from/to PRU
421 void PRU::loop(RT_INTR *pru_interrupt, void *userData) 421 void PRU::loop(RT_INTR *pru_interrupt, void *userData)
422 { 422 {
423 #ifdef BEAGLERT_USE_XENOMAI_INTERRUPTS
424 RTIME irqTimeout = PRU_SAMPLE_INTERVAL_NS * 1024; // Timeout for PRU interrupt: about 10ms, much longer than any expected period
425 #else
423 // Polling interval is 1/4 of the period 426 // Polling interval is 1/4 of the period
424 //RTIME sleepTime = PRU_SAMPLE_INTERVAL_NS * (context->analogChannels / 2) * context->analogFrames / 4; 427 RTIME sleepTime = PRU_SAMPLE_INTERVAL_NS * (context->analogChannels / 2) * context->analogFrames / 4;
425 428 #endif
426 RTIME irqTimeout = PRU_SAMPLE_INTERVAL_NS * 1024; // Timeout for PRU interrupt: about 10ms, much longer than any expected period 429
427 float *lastAnalogOutFrame; 430 float *lastAnalogOutFrame;
428 uint32_t *digitalBuffer0, *digitalBuffer1, *lastDigitalBuffer; 431 uint32_t *digitalBuffer0, *digitalBuffer1, *lastDigitalBuffer;
429 uint32_t pru_audio_offset, pru_spi_offset; 432 uint32_t pru_audio_offset, pru_spi_offset;
430 int result; 433 int result;
431 434
466 lastDigitalBuffer[n] = 0x0000ffff; 469 lastDigitalBuffer[n] = 0x0000ffff;
467 } 470 }
468 } 471 }
469 472
470 // TESTING 473 // TESTING
471 uint32_t testCount = 0; 474 // uint32_t testCount = 0;
472 // RTIME startTime = rt_timer_read(); 475 // RTIME startTime = rt_timer_read();
473 476
477 #ifndef BEAGLERT_USE_XENOMAI_INTERRUPTS
478 // Which buffer the PRU was last processing
479 uint32_t lastPRUBuffer = 0;
480 #endif
481
474 while(!gShouldStop) { 482 while(!gShouldStop) {
483 #ifdef BEAGLERT_USE_XENOMAI_INTERRUPTS
475 // Wait for PRU to move to change buffers; 484 // Wait for PRU to move to change buffers;
476 // PRU will send an interrupts which we wait for 485 // PRU will send an interrupts which we wait for
477 rt_intr_enable(pru_interrupt); 486 rt_intr_enable(pru_interrupt);
478 while(!gShouldStop) { 487 while(!gShouldStop) {
479 result = rt_intr_wait(pru_interrupt, irqTimeout); 488 result = rt_intr_wait(pru_interrupt, irqTimeout);
487 } 496 }
488 } 497 }
489 498
490 // Clear pending PRU interrupt 499 // Clear pending PRU interrupt
491 prussdrv_pru_clear_event(PRU_EVTOUT_1, PRU1_ARM_INTERRUPT); 500 prussdrv_pru_clear_event(PRU_EVTOUT_1, PRU1_ARM_INTERRUPT);
501 #else
502 // Poll
503 while(pru_buffer_comm[PRU_CURRENT_BUFFER] == lastPRUBuffer && !gShouldStop) {
504 rt_task_sleep(sleepTime);
505 }
506
507 lastPRUBuffer = pru_buffer_comm[PRU_CURRENT_BUFFER];
508 #endif
492 509
493 if(gShouldStop) 510 if(gShouldStop)
494 break; 511 break;
495 512
496 // Check which buffer we're on-- will have been set right 513 // Check which buffer we're on-- will have been set right
510 context->digital = digitalBuffer1; 527 context->digital = digitalBuffer1;
511 } 528 }
512 529
513 // FIXME: some sort of margin is needed here to prevent the audio 530 // FIXME: some sort of margin is needed here to prevent the audio
514 // code from completely eating the Linux system 531 // code from completely eating the Linux system
515 testCount++; 532 // testCount++;
516 //rt_task_sleep(sleepTime*4); 533 //rt_task_sleep(sleepTime*4);
517 //rt_task_sleep(sleepTime/4); 534 //rt_task_sleep(sleepTime/4);
518 535
519 if(xenomai_gpio != 0) { 536 if(xenomai_gpio != 0) {
520 // Set the test pin high 537 // Set the test pin high
603 // Set the test pin high 620 // Set the test pin high
604 xenomai_gpio[GPIO_CLEARDATAOUT] = TEST_PIN_MASK; 621 xenomai_gpio[GPIO_CLEARDATAOUT] = TEST_PIN_MASK;
605 } 622 }
606 623
607 // FIXME: TESTING!! 624 // FIXME: TESTING!!
608 if(testCount > 100000) 625 // if(testCount > 100000)
609 break; 626 // break;
610 } 627 }
611 628
629 #ifdef BEAGLERT_USE_XENOMAI_INTERRUPTS
612 // Turn off the interrupt for the PRU if it isn't already off 630 // Turn off the interrupt for the PRU if it isn't already off
613 rt_intr_disable(pru_interrupt); 631 rt_intr_disable(pru_interrupt);
632 #endif
614 633
615 // FIXME: TESTING 634 // FIXME: TESTING
616 // RTIME endTime = rt_timer_read(); 635 // RTIME endTime = rt_timer_read();
617 // RTIME diffTime = endTime - startTime; 636 // RTIME diffTime = endTime - startTime;
618 // rt_printf("%d blocks elapsed in %f seconds, %f Hz block rate\n", testCount, ((float)diffTime / 1.0e9), (float)testCount / ((float)diffTime / 1.0e9)); 637 // rt_printf("%d blocks elapsed in %f seconds, %f Hz block rate\n", testCount, ((float)diffTime / 1.0e9), (float)testCount / ((float)diffTime / 1.0e9));