#1223 Interrupt function has to be in separate source file

closed-fixed
nobody
5
2013-05-25
2006-10-26
No

SDCC : pic16/pic14 2.6.1 #4408 (Oct 15 2006) (UNIX)

It seems that the interrupt code breaks the assumption
that all code in a single file resides in a single code
page, because despite the code page used for the rest
of the file, an interrupt function will be located at
the interrupt address 4.

So, the following code:

----------------------------------
main()
{
while (1);
}

void func(void)
{}

void int_func(void) interrupt 0
{
func();
}
----------------------------------

when compiled with:

sdcc -mpic14 -p16f88 test.c

breaks, because the non-interrupt code ends up in code
page 1, but the interrupt code in page 0. However, the
call to func() from the handler assumes that it resides
in the same code page and thus doesn't set PCLATH
correctly.

The following extracts from the lst file show this:

First the function func():

----------------------------------
_func
;Function start
; 2 exit points
; .line
7; "test.c" {}
000802 0008 return RETURN
; exit point
of _func
----------------------------------

This shows the function located at address 0x802 in
page 1. Now the call from the interrupt handler:

----------------------------------
00000c 018a clrf 0xa CLRF
PCLATH
; .line
11; "test.c" func();
00000d 2002 call 0x2 CALL
_func
----------------------------------

Which shows the clearing of PCLATH, followed by a call
to address 0x2, in page 0.

The simple workaround is to put the interrupt function
in its own source file, which then causes the pagesel
code to be generated.

This could be as designed, but if so, the
processor-specific section should be updated in the
docs to warn against this.

simon -AT- brydens.net

Discussion

  • Raphael Neider

    Raphael Neider - 2006-10-28
    • milestone: --> fixed
    • status: open --> closed-fixed
     
  • Raphael Neider

    Raphael Neider - 2006-10-28

    Logged In: YES
    user_id=1115835

    Fixed in r4440, thanks for the report.
    Interrupt routines now drop all assumptions regarding their
    (or their callees') code banks and always emit appropriate
    PAGESELs around CALLs.

    Regards,
    Raphael

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks