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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

6.1 INTRODUCTION<br />

<strong>MPLAB</strong> ® C COMPILER FOR<br />

<strong>PIC24</strong> <strong>MCUs</strong> AND <strong>dsPIC</strong> ® <strong>DSCs</strong><br />

USER’S GUIDE<br />

Chapter 6. Additional C Pointer Types<br />

<strong>MPLAB</strong> C <strong>Compiler</strong> <strong>for</strong> <strong>PIC24</strong> <strong>MCUs</strong> <strong>and</strong> <strong>dsPIC</strong> ® <strong>DSCs</strong> (<strong>for</strong>merly <strong>MPLAB</strong> C30) offers<br />

some extended pointer modes to help access more of the unique features of<br />

<strong>Microchip</strong>’s 16-bit product architecture. Extended pointers <strong>and</strong> their use will be covered<br />

in this chapter.<br />

• Managed PSV Pointers - <strong>for</strong> reading more data through the PSV<br />

• PMP Pointers - <strong>for</strong> accessing data via the PMP peripheral (where available)<br />

• External Pointers - <strong>for</strong> accessing external memory in a user-defined fashion<br />

Although the concentration will be on pointer access, defining variables <strong>and</strong> ensuring<br />

that the data is allocated in the correct region of the 16-bit architectures (bi-polar) memory<br />

is also covered.<br />

This chapter will make use of concepts introduced in Chapter 2. “Differences<br />

Between 16-Bit Device C <strong>and</strong> ANSI C”.<br />

6.2 MANAGED PSV POINTERS<br />

The <strong>dsPIC</strong>30F/33F <strong>and</strong> <strong>PIC24</strong>F/H families of processors contain hardware support <strong>for</strong><br />

accessing data from within program Flash using a hardware feature that is commonly<br />

called Program Space Visibility (PSV). More detail about how PSV works can be found<br />

in device data sheets or family reference manuals. Also, see Section 4.14 “Program<br />

Space Visibility (PSV) Usage” <strong>and</strong> Section 8.10 “PSV Usage with Interrupt Service<br />

Routines”.<br />

Briefly, the architecture allows the mapping of one 32K page of Flash into the upper<br />

32K of the data address space via the Special Function Register (SFR) PSVPAG. By<br />

default the compiler only supports direct access to one single PSV page, referred to as<br />

the auto_psv space. In this model, 16-bit data pointers can be used. However, on<br />

larger devices, this can make it difficult to manage large amounts of constant data<br />

stored in Flash.<br />

The extensions presented here allow the definition of a variable as being a ‘managed’<br />

PSV variable. This means that the compiler will manipulate both the offset (within a<br />

PSV page) <strong>and</strong> the page itself. As a consequence, data pointers must be 32 bits. The<br />

compiler will probably generate more instructions than the single PSV page model, but<br />

that is the price being paid to buy more flexibility <strong>and</strong> shorter coding time to access<br />

larger amounts of data in Flash.<br />

6.2.1 Defining Data <strong>for</strong> Managed PSV Access<br />

Chapter 2. “Differences Between 16-Bit Device C <strong>and</strong> ANSI C” introduces C extensions<br />

which allows the identification of extra in<strong>for</strong>mation <strong>for</strong> a variable or function. The<br />

compiler provides the space attribute to help place variables into different areas<br />

(spaces) of memory.<br />

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

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

Saved successfully!

Ooh no, something went wrong!