1

I'm testing a project on a signal processing processor (ADSP 21489). I'm using as a development software VisualDSP++ 5.0 from Analog Devices. I use the DMA buffers to send data to a CODEC.

The problem is that in Debug mode everything is fine, but in Release mode it's not working. The compiler optimizes something that shouldn't be optimized. I tried making the variables volatile and adding #pragma optimize_off, but still didn't work. Any tips how this can be resolved?

extern volatile int inputReady;
extern volatile int buffer_cntr;

static void fixData (int *output, float *input, unsigned int outstep, unsigned int length)
{
    int i;

    for(i = 0; i < length; i++)
    {
        output[outstep*i] = __builtin_conv_FtoR(input[i]);
    }
}

#pragma optimize_off
volatile int sine_cnt = 0;

static void process_audioBlocks(void)
{
    memcpy(fBlockA.Tx_L1, &sine[sine_cnt], DAC_NUM_SAMPLES);
    memcpy(fBlockA.Tx_R1, &sine[sine_cnt], DAC_NUM_SAMPLES);
    memcpy(fBlockA.Tx_L2, &sine[sine_cnt], DAC_NUM_SAMPLES);
    memcpy(fBlockA.Tx_R2, &sine[sine_cnt], DAC_NUM_SAMPLES);
    memcpy(fBlockA.Tx_R3, &sine[sine_cnt], DAC_NUM_SAMPLES);
    memcpy(fBlockA.Tx_L3, &sine[sine_cnt], DAC_NUM_SAMPLES);
    memcpy(fBlockA.Tx_L4, &sine[sine_cnt], DAC_NUM_SAMPLES);
    memcpy(fBlockA.Tx_R4, &sine[sine_cnt], DAC_NUM_SAMPLES);
    
    if (sine_cnt < ARRAY_SIZE(sine) - DAC_NUM_SAMPLES)
    {
        sine_cnt += DAC_NUM_SAMPLES;
    }
    else
    {
        sine_cnt = 0;
    }
}
#pragma optimize_as_cmd_line

#pragma optimize_off
void AD1938_ISR(int sig_int)
{
    int i;
       
    if(isProcessing)
    {
        ProcessingTooLong();
    }
    else
    {
        //Increment the block pointer
        buffer_cntr++;
        buffer_cntr %= 2;
        inputReady = 1;
    }
}
#pragma optimize_as_cmd_line

#pragma optimize_off
void AD1938_Handle_Codec_Data(volatile int buffer_cntr)
{
    // Clear the Block Ready Semaphore
    inputReady = 0;

    // Set the Processing Active Semaphore before starting processing
    isProcessing = 1;

    // Place the audio processing algorithm here. 
    process_audioBlocks();

    // Fix DAC data for AD1938
    fixData(tx_block_pointer[buffer_cntr]+0, fBlockA.Tx_L1, NUM_TX_SLOTS, DAC_NUM_SAMPLES);
    fixData(tx_block_pointer[buffer_cntr]+1, fBlockA.Tx_R1, NUM_TX_SLOTS, DAC_NUM_SAMPLES);
    fixData(tx_block_pointer[buffer_cntr]+2, fBlockA.Tx_L2, NUM_TX_SLOTS, DAC_NUM_SAMPLES);
    fixData(tx_block_pointer[buffer_cntr]+3, fBlockA.Tx_R2, NUM_TX_SLOTS, DAC_NUM_SAMPLES);
    fixData(tx_block_pointer[buffer_cntr]+4, fBlockA.Tx_L3, NUM_TX_SLOTS, DAC_NUM_SAMPLES);
    fixData(tx_block_pointer[buffer_cntr]+5, fBlockA.Tx_R3, NUM_TX_SLOTS, DAC_NUM_SAMPLES);
    fixData(tx_block_pointer[buffer_cntr]+6, fBlockA.Tx_L4, NUM_TX_SLOTS, DAC_NUM_SAMPLES);
    fixData(tx_block_pointer[buffer_cntr]+7, fBlockA.Tx_R4, NUM_TX_SLOTS, DAC_NUM_SAMPLES);
    
    // Clear the Processing Active Semaphore after processing is complete
    isProcessing = 0;
}
#pragma optimize_as_cmd_line 

This is part of my code. The AD1938_ISR is a interrupt handler which initiates the transfer. The tx_block_pointer contains pointers to the dma buffer (ping-pong transfer mode).

4
  • hello , no need to put everything volatile , but i was wondering could you post the definition of the isProcessing variable ? This is typically the kind of usage where the optimisation would change the intended behaviour. Commented Oct 18, 2016 at 11:25
  • isProcessing variable is defined globaly as a volatile integer (volatile int isProcessing = 0). If isProcessing == 1 when the interrupt arrives (the processing takes too long) the program will be stuck in a infinite loop ( the function void ProcessingTooLong(void) { printf("\nError: Audio processing too long"); while(1); }) Commented Oct 19, 2016 at 11:20
  • isProcessing is a semaphore to indicate to the isr that the processing has not completed before the buffer will be overwritten. Commented Oct 19, 2016 at 11:24
  • It looks like some modifications from an exemple code from installation package of VisualDSP++... can you tell what was the initial example (before you change anything)? Commented Nov 25, 2016 at 15:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.