English Amiga Board

English Amiga Board (http://eab.abime.net/index.php)
-   Coders. System (http://eab.abime.net/forumdisplay.php?f=113)
-   -   How to pass data to interrupt handler with VBCC? (http://eab.abime.net/showthread.php?t=81206)

strim 18 January 2016 13:17

How to pass data to interrupt handler with VBCC?

I'm writing a simple program that will be used to the hardware I am developing (I2C controller). I generally got it working, but didn't like the fact that I was using way too many globals. So I decided to replace globals with... God struct/object. Anyway, I have trouble passing data to interrupt handler.

I know there's some magic with __amigainterrupt required, but I couldn't find any examples.

I have my God object/struct:

typedef struct {
} pca9564_state_t;

It is instantiated in the main function, where interrupt is also defined:

int main(void)
        pca9564_state_t sc;
        struct Interrupt *int6;

        if (int6 = AllocMem(sizeof(struct Interrupt), MEMF_PUBLIC|MEMF_CLEAR)) {
                int6->is_Node.ln_Type = NT_INTERRUPT;
                int6->is_Node.ln_Pri = -60;
                int6->is_Node.ln_Name = "PCA9564";
                int6->is_Data = (APTR)≻
                int6->is_Code = pca9564_isr;

                AddIntServer(INTB_EXTER, int6);
        } else {

Now, the question is, how do I access the struct inside of interrupt server? I have my server defined like this:


__amigainterrupt void
pca9564_isr(pca9564_state_t *sp)

But sp seems to contain garbage, or at least not what I expect.

Whole code of my program is here:

Previous version, which worked correctly but used globals is here:

demolition 18 January 2016 14:14

Now I have absolutely no experience with Amiga C/C++ coding, but normally I would expect an interrupt function to receive a void pointer as argument which would then have to be cast to the correct type. Since your compiler accepts your code, it might just perform the pointer type conversion by itself without warnings.

I would normally expect it to work like this:

__amigainterrupt void pca9564_isr(void *sp)
  pca9564_state_t *pData = (pca9564_state_t*)sp;
  // use pData here

How is __amigainterrupt defined in the header file?

strim 18 January 2016 14:29

Turns out, interrupt routines have a bit different register conventions than everything else. Whoever came up this shitty design, probably though he is smart. Smart-ass.

Anyway, I fixed the code and now it works:

__amigainterrupt void
pca9564_isr(__reg("a1") pca9564_state_t *sp)

demolition 18 January 2016 14:38

Good to know - at least now some specific experience is documented here on this issue, so maybe it will be useful for someone else struggling with the same problem. :)

All times are GMT +2. The time now is 10:56.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.

Page generated in 0.07063 seconds with 11 queries