Electronics > Microcontrollers

Referencing but not emitting ROM constants in C18

(1/1)

gxti:
I've been working on some simple firmware for the PIC18F66J60 based on the Microchip Internet bootloader and TCP/IP stack. I've gotten everything working great, but I need a way to easily program MAC addresses. What I've done is set aside a spot in the bootloader's program space at 0xFBF0, and altered the bootloader to use that instead of the #defines it came with. No problem.


--- Code: ---#pragma romdata BOOTMAC=0xFBF0
static far rom BYTE BootMAC[6] = {0xBE, 0xEF, 0xCA, 0xDE, 0x00, 0x00};
#pragma romdata
// ...
memcpypgm2ram((void*)MyAddress.vMAC, (far rom void*)BootMAC, sizeof(MyAddress.vMAC));

--- End code ---

But now I want to use this same config value to set up registers in the actual application. The gist is that by having the MAC burned into the bootloader's area, I can use the bootloader to update the firmware "in the field" without overwriting the pre-programmed MAC. So first I tried using the same declaration as above, but now the .hex file contains a value for 0xFBF0 which I don't want because it belongs to the bootloader and the bootloader (rightly) refuses to program it and fails the upload. Then I tried using "extern" instead of "static", but the linker doesn't find a definition for the variable and fails. Third I tried not referencing the program memory directly and instead just reading the MAC back out of the SFR, but for some reason that came out as all zeroes. Finally I worked around the problem by having the bootloader skip over the 0xFBF0 chunk. But it's kind of ugly, and I'm curious if there's a way to solve this properly using C18. Other possibilities that I don't especially like include using assembly to copy it out, and passing it from the bootloader to the application through RAM. Any ideas?

Short Circuit:

--- Code: ---#define BOOTMAC 0xFBF0

memcpypgm2ram((void*)MyAddress.vMAC, (far rom void*)BOOTMAC, sizeof(MyAddress.vMAC));

--- End code ---

gxti:
Now I feel incredibly silly. Thank you, kind sir.

Navigation

[0] Message Index

There was an error while thanking
Thanking...
Go to full version