Nios II Classic Software Developer’s Handbook

ID 683282
Date 5/14/2015
Public
Document Table of Contents

9.6.2. HAL Behavior for Managing Cache in Multi-Master and Multi-Processor Systems

The HAL provides the C-language IORD_*DIRECT macros that expand to the ldio family of instructions and the IOWR_*DIRECT macros that expand to the stio family of instructions.

For more information, refer to the "HAL I/O Macros to Bypass the Data Cache" table (Table 9–1 on page 9–4).

These macros are provided to access noncacheable memory regions.

The HAL provides the alt_uncached_malloc(), alt_uncached_free(), alt_remap_uncached(), and alt_remap_cached() routines to allocate and manipulate regions of uncached memory. These routines are available on Nios II cores with or without a data cache—code written for a Nios II core with a data cache is completely compatible with a Nios II core without a data cache.

The alt_uncached_malloc() routine guarantees that the allocated memory region is not in the data cache and that all subsequent accesses to the allocated memory regions bypass the data cache. In the case there is no data cache implemented the alt_uncached_malloc() routine simply calls malloc(). If data cache is implemented, but bit 31 is not set to be used as a cache bypass then the following link error will result when building the code:ALT_LINK_ERROR("alt_uncached_malloc() is not available because CPU is not configured to use bit 31 of address to bypass data cache");.

The alt_remap_uncached() routine is not available with Nios II Gen2 cores with data caches because mixing cacheable and uncacheable data on the same line is not supported. This function will result in a link error when used with Nios Gen2 cores.

In the case there is no data cache implemented the alt_uncached_free() routine simply calls free(). If data cache is implemented, but bit 31 is not set to be used as a cache bypass then a link error will result when building the code.