Embedded Design Handbook

ID 683689
Date 8/28/2023
Public
Document Table of Contents

4.2.3.4.3. Sharing Uncached Memory

If your application must allocate some memory, operate on that memory, and then share the memory region with another peripheral (or processor), use the HAL-supplied alt_uncached_malloc() and alt_uncached_free() functions. Both of these functions operate on pointers to bypass cached memory.

To share uncached memory between a Nios® II processor and a peripheral, perform the following steps:

  1. malloc memory—Run the alt_uncached_malloc() function to claim a block of memory from the heap. If this operation is successful, the function returns a pointer that bypasses the data cache.
  2. Operate on memory—Have the Nios® II processor read or write the memory using the pointer. Your application can perform normal pointer-arithmetic operations on this pointer.
  3. Convert pointer—Run the alt_remap_cached() function to convert the pointer to a memory address that is understood by external peripherals.
  4. Pass pointer—Pass the converted pointer to the external peripheral to enable it to perform operations on the memory region.