The near and far Keywords

The PRU can load a 16-bit address into a register with a single instruction. However, pointers are 32 bits and load/store instructions can load from the full 32-bit address space. The near and far keywords allow more efficient loading of data.

The near and far keywords can be applied to any data symbol. The __near and __far keywords are also accepted and are available even when --strict_ansi is specified. The __near and __far keywords are guaranteed to not conflict with any user symbols named "near" and "far".

The near keyword asserts that a symbol will be in the lower 16 bits of memory. By default all symbols are near. The PRU local memory is always in the lower 16 bits; most accesses to the upper memory range will be for peripheral accesses.

The far keyword asserts that a symbol may be in the upper 16 bits of memory. It is legal to place far data in the lower 16 bits of memory. All symbols that will reside in the upper 16 bits of memory must be declared using far, even if they have the cregister attribute.

A cregister symbol can have a far qualifier and be a near cregister access. See Section 5.14.4 for information about type attributes, including cregister. For example:

__far int peripheral __attribute__((cregister("PERIPH", near)));

This means that relative to the cregister access peripheral, this is a near access. However, if accessed using an absolute address, this is a far access. This is important because the compiler may choose to not access a peripheral using a cregister access.