↓ Ir al contenido
  1. Entradas/

Actualizar el firmware de Mespelare a XC8

·774 palabras·4 mins
David Steeman
Autor
David Steeman

Como Microchip ya no da soporte al compilador C18 y el resto del grupo VSCP ha migrado su código a XC8, yo también necesitaba migrar el firmware de Mespelare. Este artículo describe el proceso.

Este artículo es un borrador. Sigue adelante bajo tu propia responsabilidad.

Guía de migración
#

Microchip ha descrito el proceso en su MPLAB C18 to XC8 C Compiler Migration Guide . Es una lectura recomendable.

A lo largo de este artículo seguiré la guía de migración para migrar mi código, así que, si quieres, puedes seguirla conmigo.

Nos saltaremos el modo de compatibilidad con C18 y haremos una actualización de código como es debido al compilador XC8.

Promoción de enteros
#

Ya tuve antes un problema con el comportamiento de la promoción de enteros en C18, y tuve que activar la opción que promociona automáticamente las operaciones a entero. En XC8 esta opción ya no existe, y la promoción de enteros se ha convertido en el comportamiento estándar del compilador.

La sección 3.4 Integer Promotions dice lo siguiente: 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.

¡Bien, ojalá sea así!

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._

Esto significa que en main.c y en can18F66K80.c quitaremos la línea #include <p18cxxx.h> y añadiremos en su lugar #include <xc.h>. XC8 incluirá ahora automáticamente la cabecera correcta para nuestro dispositivo, según el dispositivo que hayamos indicado en las opciones del proyecto.

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.

¿Significa esto que tenemos que cambiar todas las declaraciones de variables char a signed char? Lo dejaremos para más adelante y lo tendremos presente por si nuestro código se comporta de forma errática.

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.

Esto significa que tendremos que cambiar el código de las interrupciones de alta y de baja prioridad en main.c.

El código antiguo:

#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
{

habrá que cambiarlo por:

void interrupt low_priority isr_low( void )
{

Bastante más sencillo. Lo mismo vale para la interrupción de alta prioridad:

void interrupt isr_high (void) 
{

Aquí no hace falta indicar high_priority, pero podemos hacerlo si queremos. 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.

Puede que haga falta para los pragma del archivo c018_reloc.c. //TODO

3.19.2 Assembly Language Differences
#

Puede que haga falta para el ensamblador en línea del archivo c018_reloc.c. //TODO

El código C18 de can18F66K80.c necesita trabajo. Este código:

#if defined(MCHP_C18)
	 _asm
	 BCF COMSTAT, 6, 0
	_endasm
#endif

necesita que se añada este código:

#if defined(__XC8)
	 #asm
	 BCF COMSTAT, 6, 0
	 #endasm
#endif

Este código:

#if defined(MCHP_C18)
	_asm
	BCF COMSTAT, 7, 0
	_endasm
#endif

necesita que se añada este código:

#if defined(__XC8)
	#asm
	BCF COMSTAT, 7, 0
	#endasm
#endif

1.3.3 Options and Linker scripts
#

¿Es esto un problema para los archivos de reubicación? //TODO

1.3.4 Assembly Code
#

Habrá que cambiarlos //TODO

Continuará…

Recursos
#