Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#36 PIC16 reset vector

closed
None
5
2008-04-18
2005-05-28
Richard G
No

Hello,
I am finding an annoying feature of the reset vector
for the pic16 architecture in the latest sdcc build.
I am using the 2.5.0 with the
sdcc-snapshot-i386-unknown-linux2.2-20050522.tar.gz
(may 22)
nightly build.
sdcc -v gives:
SDCC :
mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08
2.5.1 #1031 (May 22 2005) (UNIX)

there are 3 points:

1. simply declare main as interrupt 0 :
void main(void) interrupt 0
{
.
.
.
}
- problem: although the goto is used (in the asm)(thus
allowing interrupt vector at 00008) it saves the wreg,
bsr etc as the first instructions in the asm file (when
the chip has just switch on), why???. If using the
shadow regs keyword this only removes some of the
problem - some reg's are still saved. (main also ends
with a RETFIE - no need)

2. declaring the function as '_naked' stops the saving
of the regs but removes the 'goto' thereby writing main
code over the ISR at 00008. - in an earlier version :
SDCC :
mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08
0.0.0 #959 (Feb 13 2005) (UNIX)
this dosnt happen (the goto appears with the _naked
keyword)

3. I have worked around this by using some inline asm,
the chip _seems_ to run ok (but it may be executing the
isr on start, i havnt checked):

void main(void) interrupt 0 _naked
{
_asm
ORG 000
GOTO _mainloop
_endasm;
}

I renamed my original main to (mainloop) and made that
_naked also.

It just seems strange that this problem didnt exist in
the earleir version.

It's of course possible that I have missed something
basic here, please let me know and thanks for your
time. Your SDCC compiler is a commendable undertaking
and I have been using it for part of my third year
degree project developing an ultrasonic and bump-sensor
interface to a CAN bus.

If you want to see the code, I have attached a tar file.
I thought that would be better than copying and pasting
all the code in here.

Thanks Again

Richard Gardiner
richARDg@mail.com << remove the CAPTIALS

Discussion

  • Richard G
    Richard G
    2005-05-28

    makefile, source code and asm output

     
    Attachments
  • Raphael Neider
    Raphael Neider
    2005-05-30

    Logged In: YES
    user_id=1115835

    From your Makefile I take that you do not link against
    crt0i.o/crt0iz.o/crt0.o. You SHOULD link against crt0i.o (or
    crt0iz.o) to have your static globals initialized (the "i"
    means initialize, "z" is for zero complete RAM (except
    initialized locations...)).

    Doing this will automatically have SDCC...
    (i) define the initializer routine as interrupt 0-handler,
    (ii) CALL main after initialization is complete and thus
    (iii) solve (most of) your problems (I believe).

    There should be no need to declare main() _naked nor will it
    be possible to declare it as interrupt 0-handler (as then
    two handlers would exists, which is a bad thing...). The
    only potential problem left is that SDCC will happily save
    all locals used in main (that's r0x?? in the .asm file) on
    the stack without need, but I might try to prevent that from
    happening (or you still use void main (void) _naked { /*
    code */ } )...

    Let me know if this solved your problem.

     
  • Raphael Neider
    Raphael Neider
    2005-05-30

    • milestone: --> 100455
    • assigned_to: nobody --> tecodev
     
  • Raphael Neider
    Raphael Neider
    2005-05-30

    • labels: 608414 -->
    • milestone: 100455 -->
     
  • Raphael Neider
    Raphael Neider
    2005-05-30

    Logged In: YES
    user_id=1115835

    Just realized that your globals only pretend (by
    non-indentation) to be globals. So the initializer argument
    can be dropped.
    But you need to set up the stack!!! Use
    #pragma stack 0x300 0xff
    to declare the call-stack at 0x300..0x3FF and link against
    crt0/crt0i/crt0iz to setup FSR1 and FSR2 accordingly.
    I bet this is mentioned in the docs somewhere... ;-)

    Regards, Raphael

     
  • Maarten Brock
    Maarten Brock
    2008-04-18

    • status: open --> closed
     
  • Maarten Brock
    Maarten Brock
    2008-04-18

    Logged In: YES
    user_id=888171
    Originator: NO

    I assume that the comments by Raphael solved this issue.