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 CCS Technical Support

Bootloader: problem with #org directive!

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







Bootloader: problem with #org directive!
PostPosted: Tue Jun 20, 2006 3:34 am     Reply with quote

Hi,
I am trying to write a bootloader for PIC18F6680.
I have started with an example from this forum but I have a problem.
I post the code and the error.

Note: if I comment the #int routine it compiles correctly!
Thank you in advance...

It follows the code.

"myboot.h":

#define RESET_VECTOR 0x0000
#define HIGH_INT_VECTOR 0x0008
#define NORMAL_INT_VECTOR 0x0018
#define INTERRUPT_REMAP_END HIGH_INT_VECTOR + 0x1B

#define LOADER_START INTERRUPT_REMAP_END+1
#define LOADER_END 0x07ff
#define LOADER_SIZE 0x1ff
#define LOADER_RESET RESET_VECTOR
#define LOADER_HIGH_INT LOADER_START + RESET_VECTOR
#define LOADER_NORMAL_INT LOADER_HIGH_INT + 0x10
#define LOADER_INT_REMAP_END LOADER_HIGH_INT + 0x1B

#define APPLICATION_START LOADER_END
#define APPLICATION_RESET APPLICATION_START + RESET_VECTOR
#define APPLICATION_HIGH_INT APPLICATION_START + HIGH_INT_VECTOR
#define APPLICATION_NORMAL_INT APPLICATION_START + NORMAL_INT_VECTOR
#define APPLICATION_INT_REMAP_END APPLICATION_HIGH_INT + 0x1B


#ifdef MY_BOOTLOADER
#build(reset=LOADER_RESET)
#build(interrupt=LOADER_HIGH_INT)
#else
#build(reset=APPLICATION_RESET, interrupt=APPLICATION_HIGH_INT)
#org 0, LOADER_END {}
#endif



"main.c":

#include <18f6680.h>
#fuses H4,NOWDT,NOLVP,NOPUT,BROWNOUT
#use Delay(Clock=40000000)
#use RS232(BAUD=9600,XMIT=PIN_C6,RCV=PIN_C7,BRGH1OK,ERRORS) //ok

#define MY_BOOTLOADER
#include <myboot.h>

#org HIGH_INT_VECTOR, INTERRUPT_REMAP_END
void isr_relocate(void) {
#asm
// Address 0x0008 is the hardware High priority interrupt
TSTFSZ BootloaderActive // if bootloader active
GOTO LOADER_HIGH_INT // then jump to bootloader ISR
GOTO APPLICATION_HIGH_INT // else jump to application ISR

NOP // Just filling memory
NOP
NOP

// Address 0x0018 is the hardware Low priority interrupt
TSTFSZ BootloaderActive // if bootloader active
GOTO LOADER_NORMAL_INT // then jump to bootloader ISR
GOTO APPLICATION_NORMAL_INT // else jump to application ISR
#endasm
}

#int_rtcc
void foo()
{
int i=0;
i=i+1;
}

#org LOADER_START, LOADER_END default

#define BUFFER_LEN_LOD 64
int buffidx;
char buffer[BUFFER_LEN_LOD];

#define ACKLOD 0x06
#define XON 0x11
#define XOFF 0x13

unsigned int atoi_b16(char *s);
void load_program(void);

void main(void)
{
if(!input(PIN_B1))
{
load_program();
}
goto_address(APPLICATION_START);
}

#org default

errors:
Executing: "C:\Programmi\PICC\Ccsc.exe" "main.c" +FH +DF +LN +T -A +M +Z +Y=9 +EA
--- Info 300 "C:\Documents and Settings\Dino\Documenti\Microlab\Bootloader18F\main.c" Line 168(0,7): More info: Segment at 00000-00006 (0004 used) Priv
--- Info 300 "C:\Documents and Settings\Dino\Documenti\Microlab\Bootloader18F\main.c" Line 168(0,7): More info: Segment at 00008-00022 (0000 used) Priv
--- Info 300 "C:\Documents and Settings\Dino\Documenti\Microlab\Bootloader18F\main.c" Line 168(0,7): More info: Segment at 00024-007FE (0000 used) Priv
--- Info 300 "C:\Documents and Settings\Dino\Documenti\Microlab\Bootloader18F\main.c" Line 168(0,7): More info: Segment at 00800-0FFFE (0000 used)
--- Info 300 "C:\Documents and Settings\Dino\Documenti\Microlab\Bootloader18F\main.c" Line 168(0,7): More info: Attempted to create: 00024-000B6 for ISR
*** Error 126 "C:\Documents and Settings\Dino\Documenti\Microlab\Bootloader18F\main.c" Line 168(0,7): Invalid ORG range
1 Errors, 0 Warnings.
Ttelmah
Guest







PostPosted: Tue Jun 20, 2006 3:54 am     Reply with quote

The problem is in understanding what the build options 'do'. When you specify an address in 'build', this is where the system will put the 'int_global' handler. Now you then try to locate your 'isr_relocate' code here, and hence there is a clash...
You need to write your own 'int_global' routine. This will then automatically be put directly at the address specified in the build, and it can execute the jump to the real handler routine.

Best Wishes
Guest








PostPosted: Tue Jun 20, 2006 4:41 am     Reply with quote

Quote:

The problem is in understanding what the build options 'do'. When you specify an address in 'build', this is where the system will put the 'int_global' handler. Now you then try to locate your 'isr_relocate' code here, and hence there is a clash...
You need to write your own 'int_global' routine. This will then automatically be put directly at the address specified in the build, and it can execute the jump to the real handler routine.


In my section "#define", I wrote this line:

#build(interrupt=LOADER_HIGH_INT)

In this way I mean to locate area for my bootloader interrupts (I want to use them in the bootloader).

In my code I placed isr_relocate in the system defined area for interrupts.
In this way the program jumps to the interrupt handler code.

Now, when you tell me to write my interrupt handler "int_global", do you mean for my bootloader or unique interrupt handler (to use it with bootloader and application too)?

Thank you.[/quote]
Ttelmah
Guest







PostPosted: Tue Jun 20, 2006 5:08 am     Reply with quote

If you declare:
Code:

#int_global
void isr_relocate(void) {

}

Then this routine will be put at the address speified as the 'interrupt' address in the build. If you don't declare an int_global, then the compilers default int_global routine _will_be put at this location, and will therefore immediately clash with the routine you are trying to locate there.
Look at the declaration in 'bootloader.c', for how CCS declare the interrupt relocation.

Best Wishes
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Jun 20, 2006 5:02 pm     Reply with quote

The original code as posted in http://www.ccsinfo.com/forum/viewtopic.php?p=62993#62993 didn't compile when an interrupt handler was added to bootload.c. It seems like the compiler wants to create a section for the interrupts in an area that is already reserved. I suspect this is related to a compiler bug in v3.245 but couldn't get a grip at it. The easiest workaround is to remove the line
Code:
#org LOADER_START, LOADER_END default
Guest
Guest







PostPosted: Wed Jun 21, 2006 2:13 am     Reply with quote

I am using the compiler version 3.249, I believe, looking assembly code generated, the compiler ignores some pre-compiler rules!

Thank you.
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