@web-font-path: "roboto-debian.css";
Loading...
Searching...
No Matches
hardware_xip_cache

Low-level cache maintenance operations for the XIP cache. More...

Functions

void xip_cache_invalidate_all (void)
 Invalidate the cache for the entire XIP address space.
 
void xip_cache_invalidate_range (uintptr_t start_offset, uintptr_t size_bytes)
 Invalidate a range of offsets within the XIP address space.
 

Detailed Description

Low-level cache maintenance operations for the XIP cache.

These functions apply some maintenance operation to either the entire cache contents, or a range of offsets within the downstream address space. Offsets start from 0 (indicating the first byte of flash), so pointers should have XIP_BASE subtracted before passing into one of these functions.

The only valid cache maintenance operation on RP2040 is "invalidate", which tells the cache to forget everything it knows about some address. This is necessary after a programming operation, because the cache does not automatically know about any serial programming operations performed on the external flash device, and could return stale data.

Function Documentation

◆ xip_cache_invalidate_all()

void xip_cache_invalidate_all ( void  )

Invalidate the cache for the entire XIP address space.

Invalidation ensures that subsequent reads will fetch data from the downstream memory, rather than using (potentially stale) cached data.

This function is faster than calling xip_cache_invalidate_range() for the entire address space, because it iterates over cachelines instead of addresses.

Note
Any pending write data held in the cache is lost: you can force the cache to commit these writes first, by calling xip_cache_clean_all()
Unlike flash_flush_cache(), this function affects only the cache line state. flash_flush_cache() calls a ROM API which can have other effects on some platforms, like cleaning up the bootrom's QSPI GPIO setup on RP2040. Prefer this function for general cache maintenance use, and prefer flash_flush_cache in sequences of ROM flash API calls.

◆ xip_cache_invalidate_range()

void xip_cache_invalidate_range ( uintptr_t  start_offset,
uintptr_t  size_bytes 
)

Invalidate a range of offsets within the XIP address space.

Parameters
start_offsetThe first offset to be invalidated. Offset 0 means the first byte of XIP memory (e.g. flash). Pointers must have XIP_BASE subtracted before passing into this function. Must be 4-byte-aligned on RP2040. Must be a aligned to the start of a cache line (XIP_CACHE_LINE_SIZE) on other platforms.
size_bytesThe number of bytes to invalidate. Must be a multiple of 4 bytes on RP2040. Must be a multiple of XIP_CACHE_LINE_SIZE on other platforms.

Invalidation ensures that subsequent reads will fetch data from the downstream memory, rather than using (potentially stale) cached data.

Note
Any pending write data held in the cache is lost: you can force the cache to commit these writes first, by calling xip_cache_clean_range() with the same parameters. Generally this is not necessary because invalidation is used with flash (write-behind via programming), and cleaning is used with PSRAM (writing through the cache).