9.10.21 space
(space)
space attribute can be used to direct the compiler to allocate a
variable in specific memory spaces. Memory spaces are discussed further in 11.1 Address Spaces The following
arguments to the space attribute are accepted:data– Allocate the variable in general data space. Variables in general data space can be accessed using ordinary C statements. This is the default allocation.dataflash– Allocate the variable in dataflash.xmemory - dsPIC30F, dsPIC33EP/F DSCs only– Allocate the variable in X data space. Variables in X data space can be accessed using ordinary C statements. An example ofxmemoryspace allocation is:int x[32] __attribute__ ((space(xmemory)));Depending on the device, other attributes may need to be used with
space()for xmemory, such as 9.10.5edsand 9.10.2aligned (alignment).ymemory - dsPIC30F, dsPIC33EP/F DSCs only– Allocate the variable in Y data space. Variables in Y data space can be accessed using ordinary C statements. An example ofymemoryspace allocation is:int y[32] __attribute__ ((space(ymemory)));Depending on the device, other attributes may need to be used with
space()for ymemory, such as 9.10.5edsand 9.10.2aligned (alignment).prog– Allocate the variable in program space, in a section designated for executable code. Variables in program space can not be accessed using ordinary C statements. They must be explicitly accessed by the programmer, usually using table-access inline assembly instructions, the Program Space Visibility (PSV) window, or by the methods described in 11.3.2 Access of Objects in Program Memoryauto_psvAllocate the variable in program space, in a compiler-managed section designated for automatic Program Space Visibility (PSV) window access. Variables in
auto_psvspace can be read (but not written) using ordinary C statements, and are subject to a maximum of 32K total space allocated. When specifyingspace(auto_psv), it is not possible to assign a section name using thesectionattribute; any section name will be ignored with a warning. A variable in theauto_psvspace cannot be placed at a specific address or given a reverse alignment.Note: Variables placed in theauto_psvsection are not loaded into data memory at startup. This attribute may be useful for reducing RAM usage.dma - dsPIC33E/F DSCs only– Allocate the variable in DMA memory. Variables in DMA memory can be accessed using ordinary C statements and by the DMA peripheral.__builtin_dmaoffset()and__builtin_dmapage()can be used to find the correct offset for configuring the DMA peripheral. See 28 Built-in Functions for details.#include <xc.h> unsigned int BufferA[8] __attribute__((space(dma))); unsigned int BufferB[8] __attribute__((space(dma))); int main() { DMA1STA = __builtin_dmaoffset(BufferA); DMA1STB = __builtin_dmaoffset(BufferB); /* ... */ }psv– Allocate the variable in program space, in a section designated for Program Space Visibility (PSV) window access. The linker will locate the section so that the entire variable can be accessed using a single setting of the PSVPAG register. Variables in PSV space are not managed by the compiler and can not be accessed using ordinary C statements. They must be explicitly accessed by the programmer, usually using table-access inline assembly instructions, or using the PSV window.eedata - dsPIC30F/33F DSCs only– Allocate the variable in EEPROM Data (EEData) space. Variables in EEData space can not be accessed using ordinary C statements. They must be explicitly accessed by the programmer, usually using table-access inline assembly instructions, or using the Program Space Visibility (PSV) window.pmp– Allocate the variable in off chip memory associated with the PMP peripheral. For complete details please see the 11.4 Parallel Master Port Access section.external– Allocate the variable in a user defined memory space. For complete details please see the11.5 External Memory Access section.
