CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Remapping the Reset Vector and Interrupt Vectors

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
MCW
Guest







Remapping the Reset Vector and Interrupt Vectors
PostPosted: Tue Aug 12, 2003 7:58 am     Reply with quote

Hello,

Iīve got a serious problem with my PIC18F258. I must remap the Reset Vector and the Interrupt Vectors out of the boot sector (0x00 - 0x01FF). I have written the following code. There is no error message during the compilation with the PCH compiler, but the program donīt work !

Can anybody help me ?

Best Regards MCW

#define new_reset_adress 0x0200
#define new_high_interrupt_adress 0x0208
#define new_low_interrupt_adress 0x0218

#build (reset = new_reset_adress)
#build (interrupt = new_high_interrupt_adress)
#build (interrupt = new_low_interrupt_adress)

#rom 0x00 = {new_reset_adress}
#rom 0x08 = {new_high_interrupt_adress}
#rom 0x18 = {new_low_interrupt_adress}


#org 0x00, 0x01FF
Loader ()
{
// space for the bootloader
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516924
R.J.Hamlett
Guest







Re: Remapping the Reset Vector and Interrupt Vectors
PostPosted: Tue Aug 12, 2003 2:56 pm     Reply with quote

:=Hello,
:=
:=Iīve got a serious problem with my PIC18F258. I must remap the Reset Vector and the Interrupt Vectors out of the boot sector (0x00 - 0x01FF). I have written the following code. There is no error message during the compilation with the PCH compiler, but the program donīt work !
:=
:=Can anybody help me ?
:=
:=Best Regards MCW
:=
:=#define new_reset_adress 0x0200
:=#define new_high_interrupt_adress 0x0208
:=#define new_low_interrupt_adress 0x0218
:=
:=#build (reset = new_reset_adress)
:=#build (interrupt = new_high_interrupt_adress)
:=#build (interrupt = new_low_interrupt_adress)
:=
:=#rom 0x00 = {new_reset_adress}
:=#rom 0x08 = {new_high_interrupt_adress}
:=#rom 0x18 = {new_low_interrupt_adress}
:=
:=
:=#org 0x00, 0x01FF
:=Loader ()
:={
:= // space for the bootloader
:=}

Do a search on this group, for '#build'. Search in the message text, and look for the last 100 days or so.
It is a marvelously 'undocumented' CCS instruction, which allows you to tell the compiler to relocate the boot vector, and the location for interrupt handler code.
Without this, #org will not allow you to put code at 0, since the compiler knows this is reserved for the boot vector.

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516930
Jerry.I
Guest







Re: Remapping the Reset Vector and Interrupt Vectors
PostPosted: Tue Aug 12, 2003 3:38 pm     Reply with quote

Try This


How to Relocate User Code
CCS
Add the following directives in you .c file:

#build(reset=0x200)
#build(interrupt=0x208)
#org 0x0000,0x01ff
void bootloader() {
#asm
nop
#endasm
} // Reserve space for the bootloader





:=Hello,
:=
:=Iīve got a serious problem with my PIC18F258. I must remap the Reset Vector and the Interrupt Vectors out of the boot sector (0x00 - 0x01FF). I have written the following code. There is no error message during the compilation with the PCH compiler, but the program donīt work !
:=
:=Can anybody help me ?
:=
:=Best Regards MCW
:=
:=#define new_reset_adress 0x0200
:=#define new_high_interrupt_adress 0x0208
:=#define new_low_interrupt_adress 0x0218
:=
:=#build (reset = new_reset_adress)
:=#build (interrupt = new_high_interrupt_adress)
:=#build (interrupt = new_low_interrupt_adress)
:=
:=#rom 0x00 = {new_reset_adress}
:=#rom 0x08 = {new_high_interrupt_adress}
:=#rom 0x18 = {new_low_interrupt_adress}
:=
:=
:=#org 0x00, 0x01FF
:=Loader ()
:={
:= // space for the bootloader
:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516933
MCW
Guest







Re: Remapping the Reset Vector and Interrupt Vectors
PostPosted: Wed Aug 13, 2003 11:26 pm     Reply with quote

I still doesnīt work ? any other ideas ?

:=Try This
:=
:=
:=How to Relocate User Code
:=CCS
:=Add the following directives in you .c file:
:=
:=#build(reset=0x200)
:=#build(interrupt=0x208)
:=#org 0x0000,0x01ff
:=void bootloader() {
:=#asm
:=nop
:=#endasm
:=} // Reserve space for the bootloader
:=
:=
:=
:=
:=
:=:=Hello,
:=:=
:=:=Iīve got a serious problem with my PIC18F258. I must remap the Reset Vector and the Interrupt Vectors out of the boot sector (0x00 - 0x01FF). I have written the following code. There is no error message during the compilation with the PCH compiler, but the program donīt work !
:=:=
:=:=Can anybody help me ?
:=:=
:=:=Best Regards MCW
:=:=
:=:=#define new_reset_adress 0x0200
:=:=#define new_high_interrupt_adress 0x0208
:=:=#define new_low_interrupt_adress 0x0218
:=:=
:=:=#build (reset = new_reset_adress)
:=:=#build (interrupt = new_high_interrupt_adress)
:=:=#build (interrupt = new_low_interrupt_adress)
:=:=
:=:=#rom 0x00 = {new_reset_adress}
:=:=#rom 0x08 = {new_high_interrupt_adress}
:=:=#rom 0x18 = {new_low_interrupt_adress}
:=:=
:=:=
:=:=#org 0x00, 0x01FF
:=:=Loader ()
:=:={
:=:= // space for the bootloader
:=:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516952
R.J.Hamlett
Guest







Re: Remapping the Reset Vector and Interrupt Vectors
PostPosted: Thu Aug 14, 2003 1:57 am     Reply with quote

:=I still doesnīt work ? any other ideas ?
Do what I said, and read the threads about this. There is a 'caveat', in that some instructions deal in bytes, and others deal in words. I suspect it is actually 'working', but the code is not being put where you expect (a careful look at the .hex file will show how the location takes place...).

Best Wishes

:=:=Try This
:=:=
:=:=
:=:=How to Relocate User Code
:=:=CCS
:=:=Add the following directives in you .c file:
:=:=
:=:=#build(reset=0x200)
:=:=#build(interrupt=0x208)
:=:=#org 0x0000,0x01ff
:=:=void bootloader() {
:=:=#asm
:=:=nop
:=:=#endasm
:=:=} // Reserve space for the bootloader
:=:=
:=:=
:=:=
:=:=
:=:=
:=:=:=Hello,
:=:=:=
:=:=:=Iīve got a serious problem with my PIC18F258. I must remap the Reset Vector and the Interrupt Vectors out of the boot sector (0x00 - 0x01FF). I have written the following code. There is no error message during the compilation with the PCH compiler, but the program donīt work !
:=:=:=
:=:=:=Can anybody help me ?
:=:=:=
:=:=:=Best Regards MCW
:=:=:=
:=:=:=#define new_reset_adress 0x0200
:=:=:=#define new_high_interrupt_adress 0x0208
:=:=:=#define new_low_interrupt_adress 0x0218
:=:=:=
:=:=:=#build (reset = new_reset_adress)
:=:=:=#build (interrupt = new_high_interrupt_adress)
:=:=:=#build (interrupt = new_low_interrupt_adress)
:=:=:=
:=:=:=#rom 0x00 = {new_reset_adress}
:=:=:=#rom 0x08 = {new_high_interrupt_adress}
:=:=:=#rom 0x18 = {new_low_interrupt_adress}
:=:=:=
:=:=:=
:=:=:=#org 0x00, 0x01FF
:=:=:=Loader ()
:=:=:={
:=:=:= // space for the bootloader
:=:=:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516954
MCW
Guest







Re: Remapping the Reset Vector and Interrupt Vectors
PostPosted: Thu Aug 14, 2003 2:19 am     Reply with quote

Hello,

Iīve done what youīve said. Iīve lookes at the .hex file and there I could see, that the reset vector is now placed at 0x0200 (as I excepted it). The jump to main is correct, too. But there is NO jump from 0x0000 to the new reset adress 0x0200 !

So, what can I do ?

Thanks for your help

#define new_reset_adress 0x0200
#define new_high_interrupt_adress 0x0208
#define new_low_interrupt_adress 0x0218



#build(reset=0x0200)
#build(interrupt=0x0208)
#build(interrupt=0x0218)


#org 0x00, 0x07
Jump()
{
#asm
goto 0x0200
#endasm
}

#org 0x0020, 0x01FF DEFAULT // reserve space for a boot block
bootloader ()
{
#asm
nop
#endasm
}
#org DEFAULT



:=:=I still doesnīt work ? any other ideas ?
:=Do what I said, and read the threads about this. There is a 'caveat', in that some instructions deal in bytes, and others deal in words. I suspect it is actually 'working', but the code is not being put where you expect (a careful look at the .hex file will show how the location takes place...).
:=
:=Best Wishes
:=
:=:=:=Try This
:=:=:=
:=:=:=
:=:=:=How to Relocate User Code
:=:=:=CCS
:=:=:=Add the following directives in you .c file:
:=:=:=
:=:=:=#build(reset=0x200)
:=:=:=#build(interrupt=0x208)
:=:=:=#org 0x0000,0x01ff
:=:=:=void bootloader() {
:=:=:=#asm
:=:=:=nop
:=:=:=#endasm
:=:=:=} // Reserve space for the bootloader
:=:=:=
:=:=:=
:=:=:=
:=:=:=
:=:=:=
:=:=:=:=Hello,
:=:=:=:=
:=:=:=:=Iīve got a serious problem with my PIC18F258. I must remap the Reset Vector and the Interrupt Vectors out of the boot sector (0x00 - 0x01FF). I have written the following code. There is no error message during the compilation with the PCH compiler, but the program donīt work !
:=:=:=:=
:=:=:=:=Can anybody help me ?
:=:=:=:=
:=:=:=:=Best Regards MCW
:=:=:=:=
:=:=:=:=#define new_reset_adress 0x0200
:=:=:=:=#define new_high_interrupt_adress 0x0208
:=:=:=:=#define new_low_interrupt_adress 0x0218
:=:=:=:=
:=:=:=:=#build (reset = new_reset_adress)
:=:=:=:=#build (interrupt = new_high_interrupt_adress)
:=:=:=:=#build (interrupt = new_low_interrupt_adress)
:=:=:=:=
:=:=:=:=#rom 0x00 = {new_reset_adress}
:=:=:=:=#rom 0x08 = {new_high_interrupt_adress}
:=:=:=:=#rom 0x18 = {new_low_interrupt_adress}
:=:=:=:=
:=:=:=:=
:=:=:=:=#org 0x00, 0x01FF
:=:=:=:=Loader ()
:=:=:=:={
:=:=:=:= // space for the bootloader
:=:=:=:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516956
R.J.Hamlett
Guest







Re: Remapping the Reset Vector and Interrupt Vectors
PostPosted: Thu Aug 14, 2003 6:58 am     Reply with quote

:=Hello,
:=
:=Iīve done what youīve said. Iīve lookes at the .hex file and there I could see, that the reset vector is now placed at 0x0200 (as I excepted it). The jump to main is correct, too. But there is NO jump from 0x0000 to the new reset adress 0x0200 !
:=
:=So, what can I do ?
Two seperate things.
The first is that the compiler seems persistently to have an 'oddity', not allowing any actual code to be put at address 0, even when the vectors have been moved. Fortunately the #ROM statement allows this to be bypassed. So:
#define MAIN_ADDRESS (0x200l)
#build(reset=MAIN_ADDRESS)
#build(interrupt=0x208)
#org 0x0,0x07 {}
#ROM 0x0 = {
0xEF00+((MAIN_ADDRESS>>1) & 0xFF),
0xF000+(MAIN_ADDRESS>>9)
}

Will put the required code where you want it. Alternatively, if you just move your assembler origin to '2', the assembler routine will load there fine...

The other point is a 'comment'.
If you look at the assembler generated from the 'jump' code at address 2, it will end with a 'retlw' instruction, rather than a normal return. This is because you don't declare the return type in either case as a 'void'. Generally when coding routines like this, it is well worth using the syntax:

void routine(void) {

}

Which then results in the code not assuming there is any data to arrive, or return from the routine. You have done this on the 'bootloader', but not the other routine. It doesn't really 'matter', but results in slightly tidier assembler, and is especially useful if you are calling routines using 'C' branches, inside assembler, where the 'double void' version, will result in the code either being put 'inline', or a simple 'goto' for the routine in many cases :-).

Best Wishes

:=Thanks for your help
:=
:=#define new_reset_adress 0x0200
:=#define new_high_interrupt_adress 0x0208
:=#define new_low_interrupt_adress 0x0218
:=
:=
:=
:=#build(reset=0x0200)
:=#build(interrupt=0x0208)
:=#build(interrupt=0x0218)
:=
:=
:=#org 0x00, 0x07
:=Jump()
:={
:=#asm
:= goto 0x0200
:=#endasm
:=}
:=
:=#org 0x0020, 0x01FF DEFAULT // reserve space for a boot block
:=bootloader ()
:={
:= #asm
:= nop
:= #endasm
:=}
:=#org DEFAULT
:=
:=
:=
:=:=:=I still doesnīt work ? any other ideas ?
:=:=Do what I said, and read the threads about this. There is a 'caveat', in that some instructions deal in bytes, and others deal in words. I suspect it is actually 'working', but the code is not being put where you expect (a careful look at the .hex file will show how the location takes place...).
:=:=
:=:=Best Wishes
:=:=
:=:=:=:=Try This
:=:=:=:=
:=:=:=:=
:=:=:=:=How to Relocate User Code
:=:=:=:=CCS
:=:=:=:=Add the following directives in you .c file:
:=:=:=:=
:=:=:=:=#build(reset=0x200)
:=:=:=:=#build(interrupt=0x208)
:=:=:=:=#org 0x0000,0x01ff
:=:=:=:=void bootloader() {
:=:=:=:=#asm
:=:=:=:=nop
:=:=:=:=#endasm
:=:=:=:=} // Reserve space for the bootloader
:=:=:=:=
:=:=:=:=
:=:=:=:=
:=:=:=:=
:=:=:=:=
:=:=:=:=:=Hello,
:=:=:=:=:=
:=:=:=:=:=Iīve got a serious problem with my PIC18F258. I must remap the Reset Vector and the Interrupt Vectors out of the boot sector (0x00 - 0x01FF). I have written the following code. There is no error message during the compilation with the PCH compiler, but the program donīt work !
:=:=:=:=:=
:=:=:=:=:=Can anybody help me ?
:=:=:=:=:=
:=:=:=:=:=Best Regards MCW
:=:=:=:=:=
:=:=:=:=:=#define new_reset_adress 0x0200
:=:=:=:=:=#define new_high_interrupt_adress 0x0208
:=:=:=:=:=#define new_low_interrupt_adress 0x0218
:=:=:=:=:=
:=:=:=:=:=#build (reset = new_reset_adress)
:=:=:=:=:=#build (interrupt = new_high_interrupt_adress)
:=:=:=:=:=#build (interrupt = new_low_interrupt_adress)
:=:=:=:=:=
:=:=:=:=:=#rom 0x00 = {new_reset_adress}
:=:=:=:=:=#rom 0x08 = {new_high_interrupt_adress}
:=:=:=:=:=#rom 0x18 = {new_low_interrupt_adress}
:=:=:=:=:=
:=:=:=:=:=
:=:=:=:=:=#org 0x00, 0x01FF
:=:=:=:=:=Loader ()
:=:=:=:=:={
:=:=:=:=:= // space for the bootloader
:=:=:=:=:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516961
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group