Memory access error using interrupt handler with two args Topic is solved

Technical questions regarding the XTC tools and programming with XMOS.
babazaroni
Experienced Member
Posts: 94
Joined: Sun Feb 10, 2013 4:47 am

Memory access error using interrupt handler with two args

Post by babazaroni »

I am getting a memory access error when my interrupt handler is executed if I pass it two args, instead of the usual one.

In an XC file, Interrupt handler is declared as follows:

Code: Select all

void patch_board_handler(chanend c_audio,chanend c_host)
{
// memaccess error happens here when stack is prepared with the args
}
And I set the interrupt handler:

Code: Select all

set_interrupt_handler(patch_board_handler, 2, c_audio,c_host,0);
In a C file I declare:

Code: Select all

register_interrupt_handler(patch_board_handler, 2, 200)
The interrupt handler is triggered when I send a word on the c_audio channel. A memory access error occurs before the first statement in the handler is executed, presumably while the interrupt handler is setting up the stack.

I'm using xTimecomposer 14.1.2 and the device is an xcore-200.

Any ideas on how to fix this? Otherwise, I'll have to put the 2nd arg in a global and use asm statements to perform channel operations with it.


View Solution
robertxmos
XCore Addict
Posts: 169
Joined: Fri Oct 23, 2015 10:23 am

Post by robertxmos »

Hi
Unfortunately the interrupt.h is not abi compatible with regards to the stack (which must be 8byte aligned for xs2a).
If the code called by the interrupt can handle 4byte alignment, then you are fine - but I expect you are running C or XC code (or library code) which will be expecting 8byte alignment (and probably attempting a ldd or std from the misaligned stack).

Attached is a quick patch of interrupt.h (seems to work).
You may wish to add further improvements, such as the use of ldd and std.

robert
You do not have the required permissions to view the files attached to this post.