avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] Array of pointers to functions revisited...


From: Royce & Sharal Pereira
Subject: [avr-gcc-list] Array of pointers to functions revisited...
Date: Mon, 19 Jul 2004 03:22:23 +0530

Hi, all,

I am repeating an earlier mail with some comments, as I had some problems with 
the solutions I
recieved from the list...

I'm trying to call a function from an array, like this..

char f_cnt;

void fun1(void)
    {
        //some code
    }
//---------------------
void fun2(void)
    {
        //some code
    }
//---------------------
void fun3(void)
    {
        //some code
    }
//---------------------

void (*call_fun[])() PROGMEM = { fun1, fun2, fun3};  //This puts the addresses 
in code memory(seems
so from the .lst file).
//----------------------
void main(void)
    {
        (*call_fun[f_cnt])();  //But here I get a 'ld' instruction. How to 
cause an LPM instruction
to get the function address before the 'icall' ?
    }
//---------------------

Now, as suggested by Martin  & E. Weddington I tried this:

void (*call_fun[])() PROGMEM= {................as above.

void main(void)
    {
        void *fun(void);

        fun= pgm_read_word(call_fun[f_cnt]);

        fun();
    }

Now when I looked at the .lss file it wasn't any fun() :)

The array call_fun had anything but the addresses of fun1, fun2 etc. !!
In the .lst file I see a   '.word pm(fun1)' instead of a '.word fun1' etc.(BTW 
What's this pm ?)

The second problem is- The line-

fun= pgm_read_word(call_fun[f_cnt]);

does not get the desired address correctly. There is a un-necessary 'ld' before 
'lpm' which destroys
the Z reg, so that the fetched address is wrong(I assume you will compile my 
code & see the result).

Many Thanks again,

--Royce.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]