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.

Variable pointer in HWI

I would like to run a different ISR  for the same HWI depending on an initialization parameter.  I found the HWI_dispatchPlug that shows it has a pointer to a HWI function as an argument.  But I don't understand the documentation of it's description or if I'm even on the right path.   I've got a C6745 under DSP/BIOS.

The ISR already requires an argument, so I can't use that.  Basically what I want to do is run ISR1 for Mode1 and ISR2 for Mode2 when a certain HWI is active.

 

  • Yes, HWI_dispatchPlug is the right path. The arguments to HWI_dispatchPlug are similar to what is supplied to the TCF in the GUI when you assign the ISR statically.

    What part of the documentation is causing confusion for you? I assume you are looking at spru403q page 217-218. If not, which document & page are you looking at?

  • To setup a HWI, I edit the .tcf file using the configuration tool.  Within the scheduling folder I pull up the properties of one of the HWIs and add my ISR function and interrupt selection number.  Then I write my ISR as needed.  Do I call HWI_dispatchPlug()  anytime before the interrupt occurs?  I'm not sure of the syntax specifically of the fxn argument. An example would help.  Do I leave the function call blank in the HWI properties?  For the vecid parameter, do I use vecid = 5 for HWI_INT5, for example?

    This is my guess at it

    // Initialization

    HWI_Attrs    *my_attrs;

    my_attrs.intrMask = 1;  HWI_Attrs.ccask = 1; HWI_Attrs.arg = 0;

    void myisr(int arg1)  {   do my isr stuff  }

    void myotherisr(int arg1)  {  do my other isr stuff  }|

    if (mode1)

               HWI_dispatchPlug(5, &myisr, 0, my_attrs);

    else   HWI_dispatchPlug(5, &myotherisr, 0, my_attrs);

  • You pseudo code looks good to me.

    The GUI or build process may require some value in the fxn field, but either address will work, or maybe even something like 0. I would probably put _myisr and then only plug for the !mode1 case.

    I recommend that you do the HWI_dispatchPlug before enabling the interrupts with the C64_enableIER call in main.

    If this has to be done dynamically, you should wrap it in an HWI_disable/enable block. This may likely be handled by the HWI_dispatchPlug function, but without knowing for sure it is always good to be safe.

    Regards,
    RandyP

  • I'm still having problems with the syntax.  How exactly do I implement this?  My latest attempt is

    void   myisr(int arg1) {   /* my isr stuff */ }

    void  myotherisr(int arg1) { /*my other isr stuff */ }

    void   init_isrs(int mode){

    HWI_Attrs    myattrs = { 1,1,0};

    switch(mode){

          case MODE1:    HWI_dispatchPlug( 5, &myisr(), 0, myattrs); break;

          case MODE2:    HWI_dispatchPlug(5, &myotherisr(), 0, myattrs); break;

      }

    }

    This code gives me errors such as:  1.  argument of type "HWI_Attrs" is incompatible with paramter of type "HWI_Attrs*"

    2. expression must be an lvalue or a function desginator    ( on call to HWI_dispatchPlug)

    3. too few arguments in function call      ( on call to HWI_dispatchPlug)

    Thanks,   jamp

  • Where are the ^ arrows of the error messages? They will usually give more granularity toward the source of the error. If that is not helpful, in my cases like this I will break the line up into many lines with just one token per line, such as

    HWI_dispatchPlug(
    5,
    &myisr(),

    and so on. This way you may get better indications of exactly which argument fails.

    When I get error messages that I do not understand, I change something about the line or symbol or such to see if the error changes.

    Please let me know if you find anything of interest from these comments.

    Regards,
    RandyP

  • Thanks for the tip.  I'm not sure what you mean about the ^arrow? line number? Using your trick I discovered that the errors are associated with the function pointer  "&myisr()"   and the "myattrs" argument.

    Error -> expression must be an lvalue or a function designator:     &myisr(1)    ( including an argument "1" cleared  the "too few arguments"  error)

    Error ->argument of type "HWI_Attrs" is incompatible with parameter of type "HWI_Attrs*" :  myattrs

    But I'm not clear on what I need to change to fix this.

           thanks,       jamp

  • Okay I finally got it.  This is what worked for me:

    HWI_dispatchPlug(5, (Fxn)myisr, 0, &myattrs);  

     I do appreciate your help Randy, because it kept me with ideas when I was out of them.

       Thanks for the support and quick responses,

                jamp