DSPRelated.com
Forums

Call 'C' Routine from 'ISR' in assembly

Started by Krieger,Alex March 18, 2005

In addition to the very informative discussion in the VisualDSP++ documentation (on line help and PDF's) on the C/C++ run time environment, it is also very illuminating to actually see the code executed upon interrupt. After setting up a simple isr to respond to, say int 4, a simple statement like:

sysreg_write (sysreg_IRPTL, 0x0010); // Force Int no. 4

will force an interrupt, allowing to single step and follow the executed code. The first interesting thing is that at the int. vector address, the following is placed by the compiler:

jump ___lib_int_determiner

This code, ___lib_int_determiner, can be found in the source code provided in the VisualDSP++ installation, and it reveals just all that the compiler must do and save before actually jumping to the user provided isr. All registers must be saved, and some must be re-initialized to provide "C-level" continuity, for a call to a C function to work correctly. Therefore, to place a vector to jump directly to a isr written in assembly language, from which to call a C function, without first duplicating the compiler provided register saves etc., seems at the very least, questionable. Perhaps the solution is simply to copy all that VisualDSP++ provided code into one' own isr template to ensure all the proper C run time framework is maintained, but my approach has simply been to work within the C runtime framework, while being well informed of what is actually happening, courtesy of the compiler.

It may well be worth re-considering whether it is really so necessary to call a C function from a isr in assembly language, as opposed to, say, as has already been suggested, to have the isr just set a flag, which is monitored by the main program, which then actually calls the required C function. Then, the isr code can be kept minimally small and efficient, and the interrupt can be vectored directly to the isr. Lots of fun.

All the best,

AK -----Original Message-----
From: Brett George [mailto:]
Sent: March 18, 2005 8:34 AM
To:
Subject: RE: [adsp] 'C' Routine from 'ISR' in assembly

> -----Original Message-----
> From: lsborba [mailto:]
>
> Hello,
>
> At first i wish to thank all people who help on my first problem.
> Im writing this mail because i finally compile my program, but it
> i found another problem.
> Im working with an assembly program and calling a subroutine
> in 'C'. When i call the 'C' routine it works fine, but when i return
> to the assembly program, something strange happens.
> As i use a "isr", after the first execution of my "isr" the
> interruption does not work right. I looked at the disassembly window
> and i note that the code of INT1_ADDR was changed!! It used to jump
> to "PWMSync_ISR" (address 0x0000A1), but after the first execution
> the line was changed for "simidle" (address 0x0000A1). Some one know
> what is it?
> Evereything says the 'C' routine is modifying the stack somewhere.
> But, how could i prevent that? There is a way to save that stack
> before and restore it after de 'C' routine?
> Im using a ADSP 21992. I foud some olds messages saying thats
> not recommendable work with 'C' from a isr in assembly, but i really
> need to do this.
>
> Thanks,
> Leandro Borba

Calling C functions from asm ISRs is not difficult. Just make sure that you
preserve the scratch registers across the c-call. The compiler will handle
all the other registers.

Brett.

============
Brett George -
Software Engineering Manager
DEQX Pty/Ltd - www.deqx.com