11.4.3 Define Variables within PMP Space
The pmp
space attribute is also used to assign
individual variables to the space. This requires that the memory space declaration to be
present. Given the declarations in the previous subsection, the following variable
declarations can be made:
__pmp__ int external_array[256]
__attribute__((space(pmp(external_PMP_memory))));
external_array
will be allocated in the previously
declared memory external_PMP_memory
. If there is only one PMP memory,
and chip-selects are not being used, it is possible to leave out the explicit reference
to the memory. It is good practice, however, to always make the memory explicit which
would lead to code that is more easily maintained.
Note that, like managed PSV pointers, we have qualified the variable
with a new type qualifier __pmp__
. When attached to a variable or
pointer it instructs the compiler to generate the correct sequence for access via the
PMP peripheral.
Now that a variable has been declared it may be accessed using normal C syntax. The compiler will generate code to correctly communicate with the PMP peripheral.