Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

xdata & function pointers

Help
robert
2008-12-09
2013-03-12
  • robert
    robert
    2008-12-09

    I have this array of function pointers which behaves properly until I try to store the array in xdata.  Can someone give me a tip on the syntax for making as much of this live in xdata as possible?  Or will all of this live in code?  Here is the code:

    ---Header file---------------------------------------
    typedef VOID (* QUEUE_SCREEN)(VOID);

    typedef struct {
    SCREEN_LIST    Index;
    QUEUE_SCREEN Display;
    QUEUE_SCREEN Invoke;
    }MENU_ENTRY;

    ---Data Init---(as global var)--------------------------------
    MENU_ENTRY MainMenu [] =
    {//Index, Display, Invoke
    {Me0gId,Me0Display,Me0Invoke},
    {Me1gId,Me1Display,Me1Invoke},
    {Me2gId,Me2Display,Me2Invoke}
    };

    ---Usage---------------------------------------
    MainMenu [Index].Display();

     
    • Maarten Brock
      Maarten Brock
      2008-12-10

      Doesn't this work?

      xdata MENU_ENTRY MainMenu [] = ...

       
    • robert
      robert
      2008-12-10

      It will compile, but the resulting code sends me into the weeds.

       
    • robert
      robert
      2008-12-11

      OK - sorry to be clear, the functionality is as expected with:
      MENU_ENTRY MainMenu []

      However

      xdata MENU_ENTRY MainMenu [];

      Makes junk code.  I am sure it is doing something reasonable from its point of view . . . Anyway, I assumed the problem was from improper type defing.  Humm now I am wondering if I should cast it as code when I use it e.g:
      (*code)MainMenu [Index].Display();

      Think that would help?

       
    • robert
      robert
      2008-12-11

      Well, OK, the problem is not solved, but I found the most efficient thing is to just keep it all in code.  This array is static after the build anyway.

      Working result:
      code MENU_ENTRY MainMenu []; 

      Has the smallest impact on code/data/xdata

       
    • robert
      robert
      2008-12-11

      Well, OK, the problem is not solved, but I found the most efficient thing is to just keep it all in code.  This array is static after the build anyway.

      Working result:
      code MENU_ENTRY MainMenu []; 

      Has the smallest impact on code/data/xdata

       
    • Maarten Brock
      Maarten Brock
      2008-12-12

      Does xdata initialization work at all? Does this work?

      xdata char MyXdataVar = 1;

      void test(void)
      {
          if (MyXdataVar == 1)
          {
              //turn on a led or something
          }
      }

      If it doesn't then you may need to look into the initialization. Is there an sfr like _XPAGE but not defined as such in your header file? Or does xdata need to be enabled first?

      Of course it's ok to put the array in code memory if it's const anyway. Saves you the memory too.

       
    • robert
      robert
      2008-12-17

      Yeah I am able to use xdata for a host of other things.