English Amiga Board


Go Back   English Amiga Board > Coders > Coders. System

 
 
Thread Tools
Old 18 January 2016, 14:17   #1
strim
NetBSD developer
 
Join Date: May 2012
Location: Warsaw, Poland
Posts: 410
How to pass data to interrupt handler with VBCC?

Hello.

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:
Code:
typedef struct { 
...
} pca9564_state_t;
It is instantiated in the main function, where interrupt is also defined:
Code:
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:

Code:
__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:
https://gist.github.com/1a4d13513df1874883d3

Previous version, which worked correctly but used globals is here:
https://github.com/Sakura-IT/akuhei-.../src/akutest.c

Last edited by strim; 18 January 2016 at 14:30.
strim is offline  
Old 18 January 2016, 15:14   #2
demolition
Unregistered User
demolition's Avatar
 
Join Date: Sep 2012
Location: Copenhagen / DK
Age: 39
Posts: 3,976
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:
Code:
__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?
demolition is offline  
Old 18 January 2016, 15:29   #3
strim
NetBSD developer
 
Join Date: May 2012
Location: Warsaw, Poland
Posts: 410
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:
Code:
__amigainterrupt void
pca9564_isr(__reg("a1") pca9564_state_t *sp)
strim is offline  
Old 18 January 2016, 15:38   #4
demolition
Unregistered User
demolition's Avatar
 
Join Date: Sep 2012
Location: Copenhagen / DK
Age: 39
Posts: 3,976
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.
demolition is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
AmigaOS 3.9 BB ROM Update Error & Ram-Handler Not Updating 44.24 crazyegg support.Apps 23 10 November 2010 22:03
AmiCDrom v1.15 ( CDRom Handler Error HELP Plz ) iowtheme support.Hardware 5 25 March 2010 12:03
Mount TCP: handler amiga support.Apps 2 20 March 2009 14:13
CIA timer interrupt handler called twice during mod playback absence Coders. General 5 16 March 2009 19:55
EXT2 file system handler: bugfix release 0.3 available Paul News 0 29 November 2004 16:38

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 09:33.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.
Page generated in 0.06721 seconds with 13 queries