MPLAB C Compiler for PIC24 MCUs and dsPIC DSCs ... - Microchip
MPLAB C Compiler for PIC24 MCUs and dsPIC DSCs ... - Microchip
MPLAB C Compiler for PIC24 MCUs and dsPIC DSCs ... - Microchip
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
6.4 EXTERNAL POINTERS<br />
6.3.3 Define Variables within PMP Space<br />
Additional C Pointer Types<br />
The pmp space attribute is also used to assign individual variables to the space. This<br />
requires that the memory space declaration to be present. Given the declarations in the<br />
previous subsection, the following variable declarations can be made:<br />
__pmp__ int external_array[256]<br />
__attribute__((space(pmp(external_PMP_memory))));<br />
external_array will be allocated in the previous declared memory<br />
external_PMP_memory. If there is only one PMP memory, <strong>and</strong> chip-selects are not<br />
being used, it is possible to leave out the explicit reference to the memory. It is good<br />
practice, however, to always make the memory explicit which would lead to code that<br />
is more easily maintained.<br />
Note that, like managed PSV pointers, we have qualified the variable with a new type<br />
qualifier __pmp__. When attached to a variable or pointer it instructs the compiler to<br />
generate the correct sequence <strong>for</strong> accessing via the PMP peripheral.<br />
Now that a variable has been declared it may be accessed using normal C syntax. The<br />
compiler will generate code to correctly communicate with the PMP peripheral.<br />
Not all of <strong>Microchip</strong>’s 16-bit devices have a PMP peripheral, or not all memories are<br />
suitable <strong>for</strong> attaching to a parallel port (serial memories sold by <strong>Microchip</strong>, <strong>for</strong> example).<br />
The toolsuite provides a more general interface to any external memory, although, as<br />
will be seen, the memory does not have to be external.<br />
Like PMP memory space, the tool-chain needs to learn about external memories that<br />
are being attached. Unlike PMP, however, the compiler does not know how to access<br />
these memories. A mechanism is provided by which an application can specify how to<br />
access such memories.<br />
External pointers (<strong>and</strong> their addresses) consume 32 bits. The largest attachable memory<br />
is 64K (16 bits); the other 16 bits is used to uniquely identify the memory. A total of<br />
64K (16 bits) of these may be (theoretically) attached.<br />
To use this feature:<br />
• Declare a New Memory Space<br />
• Define Variables within an External Space<br />
• Define How to Access Memory Spaces<br />
As an example:<br />
• An External Example<br />
6.4.1 Declare a New Memory Space<br />
This is very similar to declaring a new memory space <strong>for</strong> PMP access.<br />
The 16-bit toolsuite requires in<strong>for</strong>mation about each external memory. In order <strong>for</strong><br />
16-bit device linker to be able to properly assign memory, in<strong>for</strong>mation about the size of<br />
memory available <strong>and</strong>, optionally the origin of the memory, needs to be provided.<br />
In Chapter 2. “Differences Between 16-Bit Device C <strong>and</strong> ANSI C” the new external<br />
memory space was introduced. This attribute serves two purposes: declaring<br />
extended memory spaces <strong>and</strong> assigning C variable declarations to external memory<br />
(this will be covered in the next subsection).<br />
Declaring an extended memory requires providing the size of the memory. You may<br />
optionally specify an origin <strong>for</strong> this memory; if none is specified 0x0000 will be<br />
assumed.<br />
© 2008 <strong>Microchip</strong> Technology Inc. DS51284H-page 85