This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Error: Intrinsic function parameter must be literal

Hi All!

I get an error: Intrinsic function parameter must be literal

unsigned int ir_buf[50];

unsigned char level[50];

unsigned int counter;

unsigned char idx,last_idx;

# define F_CPU  8000000UL

void send_ir_packet(void)

{

    while(1)

    {

        for(idx = 1; idx < last_idx; idx++)

       {

            if(level[idx] == 0)

            {

                IR_OUT = 0;

            }

           else

          {

               IR_OUT = 1;

         }

        __delay_cycles((F_CPU / 1000000UL) * ir_buf[idx]);  //here i get an error

        }

    }

}


Is there any workaround of this problem?

  • Intrinsics are compile-time instructions that cause the compiler to generate a certain special code that cannot be described in C language.
    So the parameters for them need to be known at compile-time. While FCPU/1000000UL can be calculated at compile-time, ir_buf[idx] is unknown.

    The only way to get what you want is to build a loop around the intrinsic that loops for ir_buf[idx] times. But then you have to take the execution overhead for the loop into account.

    It is better to set up a timer for delays. Once the timer runs with a known speed (e.g. F_CPU/1000000UL = 1MHz), all delays that rely on the timer will work without any code change, whether they are dynamic (ir_buf[idx]) or fixed.

**Attention** This is a public forum