18 January 2016, 13:17 | #1 |
NetBSD developer
Join Date: May 2012
Location: Warsaw, Poland
Posts: 411
|
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; 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 { ... } Code:
__amigainterrupt void pca9564_isr(pca9564_state_t *sp) { ... } 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 13:30. |
18 January 2016, 14:14 | #2 |
Unregistered User
Join Date: Sep 2012
Location: Copenhagen / DK
Age: 44
Posts: 4,190
|
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 } |
18 January 2016, 14:29 | #3 |
NetBSD developer
Join Date: May 2012
Location: Warsaw, Poland
Posts: 411
|
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) |
18 January 2016, 14:38 | #4 |
Unregistered User
Join Date: Sep 2012
Location: Copenhagen / DK
Age: 44
Posts: 4,190
|
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.
|
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 21:03 |
AmiCDrom v1.15 ( CDRom Handler Error HELP Plz ) | iowtheme | support.Hardware | 5 | 25 March 2010 11:03 |
Mount TCP: handler | amiga | support.Apps | 2 | 20 March 2009 13:13 |
CIA timer interrupt handler called twice during mod playback | absence | Coders. General | 5 | 16 March 2009 18:55 |
EXT2 file system handler: bugfix release 0.3 available | Paul | News | 0 | 29 November 2004 15:38 |
|
|