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

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

Re: [avr-gcc-list] pointer to functions


From: Lorne Gutz
Subject: Re: [avr-gcc-list] pointer to functions
Date: Tue, 15 Apr 2003 09:34:54 -0400

Hi
     Being a chap who hates 'case' statements with a passion,
I usually find a way to use jump tables.  Below you will find
the initialization of an array of pointers to functions.  All you
need is:
   FN[x] = some_function_name;
not
   FN[x] = some_function_name();
or
   FN[x] = &some_function_name;

    I have used this skeem on several of the AVR chips.  If
you are interested in how to do the indexing into the array
or actually jumping to a function,  ask,   I cand help you
out there as will.

cheers
Lorne


On Tuesday 15 April 2003 05:25, Rune Christensen wrote:
> Hello
>
> I need to make a struct with two pointers called init and done.
>
> typedef struct
> {
>   init
>   done
> } sblock;
>
> In the main there should be something like this
> sblock sb;
>
> sb.init = &(loginit());
> sb.done = &(logdone());
>
> It should be possible to write
> init()
> done()
>
> But can that be done in a AT90s8515 ??
> And how is the syntax ??
>
> Best regards
> Rune Christensen
> Student at www.dtu.dk
>
> address@hidden
>

typedef     void  (*func)(void);
static    func    fn[NumOfCmds];


volatile uint8_t    Buff;
volatile uint8_t    RxBuff;
volatile uint8_t    Cmd;

int main (void)
{
    uint8_t     tmp, dd;
 DDRB  = 0x07;

    fn[0]  = Status;
    fn[1]  = Sos_SeaKey_Ack_ON;
    fn[2]  = Sos_SeaKey_Ack_OFF;
    fn[3]  = GPS_ACK_ON;
    fn[4]  = GPS_ACK_OFF;
    fn[5]  = SeaKey_Send_ON;
    fn[6]  = SeaKey_Send_OFF;
    fn[7]  = SOS_Send_ON;
    fn[8]  = SOS_Send_OFF;
    fn[9]  = GPS_Send_ON;
    fn[10] = GPS_Send_OFF;
    fn[11] = An0_Zero;
    fn[12] = An0_One;
    fn[13] = An0_Two;
    fn[14] = GPS_OUT_MT2_Hi;
    fn[15] = GPS_OUT_MT2_Lo;
    fn[16] = SOS_OUT_MT2_Hi;
    fn[17] = SOS_OUT_MT2_Lo;
    fn[18] = MT2_ON;
    fn[19] = MT2_OFF;
    fn[20] = EN_MT2_sw;
    fn[21] = DIS_MT2_sw;
>
> _______________________________________________
> avr-gcc-list mailing list
> address@hidden
> http://www.avr1.org/mailman/listinfo/avr-gcc-list



reply via email to

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