Vault 7: Projects
This publication series is about specific projects related to the Vault 7 main publication.
MPLAB
®
XC16 C Compiler Users Guide
DS50002071C-page 158 2012-2013 Microchip Technology Inc.
10.6 EXTERNAL MEMORY ACCESS
Not all of Microchips 16-bit devices have a parallel master port peripheral (see
Section 10.5 Parallel Master Port Access), and not all memories are suitable for
attaching to the PMP (serial memories sold by Microchip, for example). The toolsuite
provides a more general interface to, what is known as, external memory, although, as
will be seen, the memory does not have to be external.
Like PMP access, the tool-chain needs to learn about external memories that are being
attached. Unlike PMP access, however, the compiler does not know how to access
these memories. A mechanism is provided by which an application can specify how
such memories should be accessed.
Addresses of external objects are all 32 bits in size. The largest attachable memory is
64K (16 bits); the other 16 bits in the address is used to uniquely identify the memory.
A total of 64K (16 bits) of these may be (theoretically) attached.
To use this feature, work through the following sections.
10.6.1 Declare a New Memory Space
This is very similar to declaring a new memory space for PMP access.
The 16-bit toolsuite requires information about each external memory. In order for
16-bit device linker to be able to properly assign memory, information about the size of
memory available and, optionally the origin of the memory, needs to be provided.
In Chapter 7. Differences Between MPLAB XC16 and ANSI C the external
memory space was introduced. This attribute serves two purposes: declaring extended
memory spaces and assigning C variable declarations to external memory (this will be
covered in the next subsection).
Declaring an extended memory requires providing the size of the memory. You may
optionally specify an origin for this memory; if none is specified 0x0000 will be
assumed.
extern int external_memory
__attribute__((space(external(size(1024)))));
Above an external memory of size 1024 bytes is defined. This memory can be uniquely
identified by its given name of external_memory.
10.6.2 Define Variables Within an External Space
The external space attribute is also used to assign individual variables to the space.
This requires that the memory space declaration to be present. Given the declarations
in the previous subsection, the following variable declarations can be made:
__external__ int external_array[256]
__attribute__((space(external(external_memory))));
external_array will be allocated in the previous declared memory
external_memory.
Note that, like managed PSV objects, we have qualified the variable with a new type
qualifier __external__. When attached to a variable or pointer target, it instructs the
compiler to generate the correct sequence to access these objects.
Once an external memory variable has been declared, it may be accessed using nor-
mal C syntax. The compiler will generate code to access the variable via special helper
functions that the programmer must define. These are covered in the next subsection.
Protego_Release_01_05-Related-OEM-Documentation-MPLAB-XC16-C-Compiler.pdf