Microchip Technology SW006022-1N Scheda Tecnica
Memory Allocation and Access
2012 Microchip Technology Inc.
DS52071B-page 125
7.4
VARIABLES IN PROGRAM SPACE
The 16-bit core families of processors contain hardware support for accessing data
from within program Flash using a hardware feature that is commonly called Program
Space Visibility (PSV). More detail about how PSV works can be found in device data
sheets or family reference manuals. Also, see Section 7.4.1 “Allocation and Access
of Program Memory Objects” and Section 11.8.2 “PSV Usage with Interrupt Ser-
vice Routines”.
from within program Flash using a hardware feature that is commonly called Program
Space Visibility (PSV). More detail about how PSV works can be found in device data
sheets or family reference manuals. Also, see Section 7.4.1 “Allocation and Access
of Program Memory Objects” and Section 11.8.2 “PSV Usage with Interrupt Ser-
vice Routines”.
Briefly, the architecture allows the mapping of one 32K page of Flash into the upper
32K of the data address space via the Special Function Register (SFR) PSVPAG or
DSRPAG. By default the compiler only supports direct access to one single PSV page,
referred to as the auto_psv space. In this model, 16-bit data pointers can be used.
However, this can make it difficult to manage large amounts of constant data stored in
Flash on larger devices.
32K of the data address space via the Special Function Register (SFR) PSVPAG or
DSRPAG. By default the compiler only supports direct access to one single PSV page,
referred to as the auto_psv space. In this model, 16-bit data pointers can be used.
However, this can make it difficult to manage large amounts of constant data stored in
Flash on larger devices.
When the option -mconst-in-code is enabled, const-qualified variables that are
not auto are placed in program memory. Any auto variables qualified const are
placed on the stack along with other auto variables.
not auto are placed in program memory. Any auto variables qualified const are
placed on the stack along with other auto variables.
Any const-qualified (auto or non-auto) variable will always be read-only and any
attempt to write to these in your source code will result in an error being issued by the
compiler.
attempt to write to these in your source code will result in an error being issued by the
compiler.
A const object is usually defined with initial values, as the program cannot write to
these objects at runtime. However this is not a requirement. An uninitialized const
object is allocated space along with other uninitialized RAM variables, but is still
read-only. Here are examples of const object definitions.
these objects at runtime. However this is not a requirement. An uninitialized const
object is allocated space along with other uninitialized RAM variables, but is still
read-only. Here are examples of const object definitions.
const char IOtype = ’A’; // initialized const object
const char buffer[10]; // I reserve memory in RAM
See Chapter 13. “Mixing C and Assembly Code” for the equivalent assembly sym-
bols that are used to represent const-qualified variables in program memory.
bols that are used to represent const-qualified variables in program memory.
7.4.1
Allocation and Access of Program Memory Objects
There are many objects that are allocated to program memory by the compiler. The fol-
lowing sections indicate those objects and how they are allocated to their final memory
location by the compiler and how they are accessed.
lowing sections indicate those objects and how they are allocated to their final memory
location by the compiler and how they are accessed.
7.4.1.1
STRING AND CONST OBJECTS
By default, the compiler will automatically arrange for strings and const-qualified
initialized variables to be allocated in the auto_psv section, which is mapped into the
PSV window. Specify the -mconst-in-data option to direct the compiler not to use
the PSV window and these objects will be allocated along with other RAM-based vari-
ables.
initialized variables to be allocated in the auto_psv section, which is mapped into the
PSV window. Specify the -mconst-in-data option to direct the compiler not to use
the PSV window and these objects will be allocated along with other RAM-based vari-
ables.
In the default memory model, the PSV page is fixed to one page which is represented
by the auto_psv memory space. Accessing the single auto PSV page is efficient as
no page manipulation is required. Additional FLASH may be accessed using the tech-
niques introduced in section Section 7.4.2.1 “Managed PSV Access”.
by the auto_psv memory space. Accessing the single auto PSV page is efficient as
no page manipulation is required. Additional FLASH may be accessed using the tech-
niques introduced in section Section 7.4.2.1 “Managed PSV Access”.