Omdat de C18-compiler niet meer door Microchip wordt ondersteund en de rest van de VSCP-groep zijn code al naar XC8 heeft gemigreerd, moest ik mijn Mespelare-firmware ook migreren. Dit artikel beschrijft hoe ik dat aanpak.
Dit artikel is een ruwe versie. Gebruik op eigen risico.
Migratiehandleiding#
Microchip heeft het proces beschreven in de MPLAB C18 to XC8 C Compiler Migration Guide . Die is aan te raden als leesvoer.
In dit artikel volg ik de handleiding om mijn code te migreren, dus als je wilt kun je meedoen.
We slaan de C18-compatibiliteitsmodus over en doen een degelijke code-upgrade naar de XC8-compiler.
Integer promotion#
Ik had eerder al een probleem met het gedrag van integer promotion in C18 en moest de optie instellen om bewerkingen automatisch naar integer te promoveren. In XC8 is die optie niet meer beschikbaar en is integer promotion het standaardgedrag van de compiler.
Section 3.4 Integer Promotions zegt hierover: The MPLAB XC8 compiler cannot mimic this non-standard behavior. The results obtained from this compiler will always be consistent with the smaller data types (i.e. short, char and structure bit-fields) being promoted to either signed int or unsigned int. This means that the result of expressions using the smaller types can be different to those obtained from the same code compiled with MPLAB C18.
Mooi zo, laten we het hopen!
3.5.1 Header Files#
MPLAB XC8 uses the header file _ <xc.h> for all device specific information and it is likely you will need to include this header in all your C source modules. Separate assembly modules should include the header < xc.inc> to access SFRs by name._
Dit betekent dat we in main.c en in can18F66K80.c de regel #include <p18cxxx.h> verwijderen en in de plaats daarvan #include <xc.h> toevoegen. XC8 neemt nu automatisch de juiste header op voor ons doelapparaat, op basis van het apparaat dat we in de projectopties hebben ingesteld. 
3.6 DATA TYPES AND LIMITS#
The type of a plain char is signed char on MPLAB C18 (unless the -k option is used), but unsigned char on MPLAB XC8. It is always good practice to explicitly state the signedness of char types when you define them.
Betekent dit dat we alle initialisaties van onze char-variabelen moeten aanpassen naar signed char? Dat slaan we voorlopig over en we houden het in gedachten voor als onze code zich raar gedraagt.
3.13 INTERRUPTS#
The definitions of interrupt vectors and service routines when using MPLAB XC8 is dif- ferent to those applicable for MPLAB C18. Encoding of the service routines also differs between the two compilers.
Dit betekent dat we onze code voor de hoge en lage interrupt in main.c moeten aanpassen.
De oude code:
#ifdef RELOCATE
#pragma code low_vector = 0x818
#else
#pragma code low_vector = 0x18
#endif
void interrupt_at_low_vector( void ) {
_asm GOTO isr_low _endasm
}
#pragma code
#pragma interruptlow isr_low
void isr_low( void ) // called every 10ms
{
moet worden aangepast naar:
void interrupt low_priority isr_low( void )
{
Heel wat eenvoudiger. Hetzelfde geldt voor de hoge interrupt:
void interrupt isr_high (void)
{
Hier hoeven we high_priority niet op te geven, maar als we dat willen kan het wel. For the high priority (default) interrupt, omit the low_priority keyword when defining the function; or you can use the high_priority keyword instead.
3.14.1 Variables and Functions#
The MPLAB C18 #pragma sectiontype is used to allocate variables and code to an alternate section with the name specified. This is usually done so that this section can be explicitly linked in memory at a specific address or in an address range. If the aim is purely to locate a variable or function at a specific address, then the easiest way of performing this in MPLAB XC8 is to make the variable or function absolute, using the @ address construct.
Mogelijk nodig voor de pragma’s in het bestand c018_reloc.c. //TODO
3.19.2 Assembly Language Differences#
Mogelijk nodig voor de inline assembly in het bestand c018_reloc.c. //TODO
De C18-code in can18F66K80.c vraagt werk. Deze code:
#if defined(MCHP_C18)
_asm
BCF COMSTAT, 6, 0
_endasm
#endif
moet worden aangevuld met deze code:
#if defined(__XC8)
#asm
BCF COMSTAT, 6, 0
#endasm
#endif
Deze code:
#if defined(MCHP_C18)
_asm
BCF COMSTAT, 7, 0
_endasm
#endif
moet worden aangevuld met deze code:
#if defined(__XC8)
#asm
BCF COMSTAT, 7, 0
#endasm
#endif
1.3.3 Options and Linker scripts#
Is dit een probleem voor de relocatiebestanden? //TODO
1.3.4 Assembly Code#
Die moeten we aanpassen //TODO
Wordt vervolgd…
