07.04.2013 Views

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

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

16-Bit C <strong>Compiler</strong> User’s Guide<br />

extern int external_memory<br />

__attribute__((space(external(size(1024)))));<br />

Above an external memory of size 1024 bytes is defined. This memory can be uniquely<br />

identified by its given name of external_memory.<br />

6.4.2 Define Variables within an External Space<br />

The external space attribute is also used to assign individual variables to the space.<br />

This requires that the memory space declaration to be present. Given the declarations<br />

in the previous subsection, the following variable declarations can be made:<br />

__external__ int external_array[256]<br />

__attribute__((space(external(external_memory))));<br />

external_array will be allocated in the previous declared memory<br />

external_memory.<br />

Note that, like managed PSV pointers, we have qualified the variable with a new type<br />

qualifier __external__. When attached to a variable or pointer it instructs the compiler<br />

to generate the correct sequence <strong>for</strong> accessing.<br />

Now that a variable has been declared it may be accessed using normal C syntax. The<br />

compiler will generate code to access the variable via special helper functions that the<br />

programmer must define. These are covered in the next subsection.<br />

6.4.3 Define How to Access Memory Spaces<br />

References to variables placed in external memories are controlled via the use of several<br />

helper functions. Up to five (5) functions may be defined <strong>for</strong> reading <strong>and</strong> five (5) <strong>for</strong><br />

writing. One each of these is a generic function <strong>and</strong> will be called if any of the other four<br />

is not defined but is required. If none of the functions are defined, the compiler will generate<br />

an error message. A brief example will be presented in the next subsection. Generally<br />

defining the individual functions will result in more efficient code generation.<br />

6.4.3.1 FUNCTIONS FOR READING<br />

read_external<br />

void __read_external(unsigned int address,<br />

unsigned int memory_space,<br />

void *buffer,<br />

unsigned int len)<br />

This function is a generic Read function <strong>and</strong> will be called if one of the next functions<br />

are required but not defined. This function should per<strong>for</strong>m the steps necessary to fill<br />

len bytes of memory in the buffer from the external memory named memory_space<br />

starting at address address.<br />

read_external8<br />

unsigned char __read_external8(unsigned int address,<br />

unsigned int memory_space)<br />

Read 8 bits from external memory space memory_space starting from address<br />

address. The compiler would like to call this function if trying to access an 8-bit sized<br />

object.<br />

DS51284H-page 86 © 2008 <strong>Microchip</strong> Technology Inc.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!