3.2 __ext_io Keyword

The IAR __ext_io keyword specifies that the qualified object aliases memory-mapped SFRs, that is, the object is accessed from the AVR's IO registers. This is similar to the IAR __io attribute, except that it is meant for accessing SFRs above addresses 0x100.

Suggested Replacement

There is an MPLAB XC8 attributes that performs a similar tasks to this keyword, but there are some differences in its effect.

The MPLAB XC8 address attribute equates a symbol to an address, permitting the symbol to represent a register in the I/O space.

Caveats

The IAR __ext_io keyword ensures that memory is allocated to the object. That memory will be in the I/O space. When using the MPLAB XC8 address attribute, the compiler does not assign memory to the symbol; instead, it assumes that the symbol represents a peripheral register and merely equates the symbol to an address, which must be specified in the attribute.

Use of __ext_io implies the object is volatile. This is not the case when using the MPLAB XC8 address attribute.

Examples

Consider migrating IAR code such as:
__ext_io char TCB0_CTRLA;

int main(void) {
    volatile char x = TCB0_CTRLA;
}
to MPLAB XC8 code similar to:
volatile char TCB0_CTRLA __attribute__((address(0xB00)));
 
int main(void) {
    volatile char x = TCB0_CTRLA;
}
In this example, the compiler does not allocate memory at 0xB00; it merely assigns that address to the TCB0_CTRLA identifier.

Further Information

See the Attributes section in the MPLAB XC8 C Compiler User's Guide for AVR MCUs for more information on this attribute.