9.10.21 space (space)

Normally, the compiler allocates variables in general data space. The 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 - dsPIC33C/E/F and dsPIC30 DSCs only – Allocate the variable in dataflash. For dsPIC33A, the argument is not supported so an error message is produced.
  • xmemory – Allocate the variable in X data space. Variables in X data space can be accessed using ordinary C statements. An example of xmemory space 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.5 eds and 9.10.2 aligned (alignment).

  • ymemory – Allocate the variable in Y data space. Variables in Y data space can be accessed using ordinary C statements. An example of ymemory space 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.5 eds and 9.10.2 aligned (alignment).

  • prog – Allocate the variable in program space in a section designated for executable code.

    For dsPIC33C/E/F and dsPIC30F devices, variables in program space cannot 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.4 Access of Objects in Program Memory

    For dsPIC33A devices, this area of memory can be accessed with normal C statements.

  • auto_psv – For dsPIC33C/E/F and dsPIC30, allocate the variable in program space, in a compiler-managed section designated for automatic Program Space Visibility (PSV) window access. Variables in auto_psv space can be read (but not written) using ordinary C statements, and are subject to a maximum of 32K total space allocated. When specifying space(auto_psv), it is not possible to assign a section name using the section attribute; any section name will be ignored with a warning. A variable in the auto_psv space cannot be placed at a specific address or given a reverse alignment.
    Note: Variables placed in the auto_psv section are not loaded into data memory at startup. This attribute may be useful for reducing RAM usage.

    For dsPIC33A, the argument is treated as if prog was specified and a warning message is produced.

  • 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 – For dsPIC33C/E/F and dsPIC30, 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.

    For dsPIC33A, the argument is treated as if prog was specified and a warning message is produced.

  • 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 - dsPIC33C/E/F and dsPIC30 DSCs only– Allocate the variable in off chip memory associated with the PMP peripheral. For complete details please see the 11.4 Parallel Master Port Access [DD] section.

    For dsPIC33A, the argument is not supported so an error message is produced.

  • external – Allocate the variable in a user defined memory space. For complete details please see the11.5 External Memory Access section.