View previous topic :: View next topic |
Author |
Message |
Bart Diricx
Joined: 16 Sep 2010 Posts: 5
|
#org usage |
Posted: Thu Sep 16, 2010 8:49 am |
|
|
Hi,
I'm making firmware for a PIC16F88 µC which needs to have a I2C bootloader. I want all functions which might get executed prior to finishing the bootloader to be put in address range 0x0E40 - 0x0FFF.
If I do the following:
Code: |
-> main.h:
------------------
void bootloader (void);
void init (void);
-> main.c:
------------------
#ORG 0x0E40 0x0FFF // define bootloader segment
void main()
{
init();
bootloader();
}
#ORG 0x0E40 // located in bootloader segment
void init (void)
{
...
}
#ORG 0x0E40 // located in bootloader segment
void bootloader (void)
{
...
} |
I get "Error 166 "main.c" Line 150(1,2): Invalid overload function bootloader
If I don't place the function prototypes in main.h, and declare the functions prior to void main (void) then it builds correctly. Also when I don't put the #org statements, it builds correctly, but isn't placed in the correct memory segments.
Why can't it handle function prototypes when using #org statements? Is there a workaround / solution for this?
I'm using PCWH 4.0.69.
Best regards,
Diricx Bart |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Sep 16, 2010 2:51 pm |
|
|
I was able to make it compile by putting #separate above each prototype.
Quote: |
// main.h
#separate
void bootloader(void);
#separate
void init(void);
|
|
|
|
Bart Diricx
Joined: 16 Sep 2010 Posts: 5
|
|
Posted: Fri Sep 17, 2010 1:03 am |
|
|
Thanks, this works indeed ! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19553
|
|
Posted: Sat Sep 18, 2010 8:01 am |
|
|
It makes a lot of sense if you think about it.
If you remember that for 'single call' functions, the default is always to put them 'inline', the original prototype for the function, effectively becomes:
Code: |
#inline
void bootloader(void);
|
You then when you come to the 'real' definition, tell the compiler to put this function as a distinct entity, somewhere else, which then clashes with the original definition.
By using #separate, you are telling the compiler to treat this as an entity that is _not_ going to be put inline, which then agrees with the latter definition.
Makes total sense, just a pity it is not documented!.
Best Wishes |
|
|
|