6 www.xilinx.com UG647 October 23, 2013
MicroBlaze Processor API
void Xil_DCacheInvalidate()
Invalidate the data cache.
If the L2 cache system is present in the hardware, this function invalidates the L2 cache first,
before invalidating the L1 cache.
Note:
For MicroBlaze processors prior to version v7.20.a:
The cache and interrupts are disabled before invalidation starts and restored to their previous state after
invalidation.
void Xil_DCacheInvalidateRange(unsigned int cache_addr,
unsigned int cache_size
Invalidate the data cache. This function can be used for invalidating all or part of the data cache.
The parameter
cache_addr indicates the beginning of the cache location and cache_size
represents the size from
cache_addr to invalidate.
Note that cache lines will be invalidated starting from the cache line to which cache_addr
belongs and ending at the cache line containing the address (
cache_addr +
cache_size - 1).
If the L2 cache system is present in the hardware, this function invalidates the relevant L2
cache range first, before invalidating the L1 cache range.
Note:
For MicroBlaze processors prior to version v7.20.a:
The cache and interrupts are disabled before invalidation starts and restored to their previous state after
invalidation.
For example, Xil_DCacheInvalidateRange (0x00000300, 0x100) invalidates the data
cache region from 0x300 to 0x3ff (0x100 bytes of cache memory is cleared starting from
0x300).
Software Sequence for Initializing Instruction and Data Caches
Typically, before using the cache, your program must perform a particular sequence of cache
operations to ensure that invalid/dirty data in the cache is not being used by the processor. This
would typically happen during repeated program downloads and executions.
The following example snippets show the necessary software sequence for initializing
instruction and data caches in your program.
/* Initialize ICache *//
Xil_ICacheInvalidate ();
Xil_ICacheEnable ();
/* Initialize DCache */
Xil_DCacheInvalidate ();
Xil_DCacheEnable ();
At the end of your program, you should also put in a sequence similar to the example snippet
below. This ensures that the cache and external memory are left in a valid and clean state.
/* Clean up DCache. For writeback caches, the disable_dcache routine
internally does the flush and invalidate. For write through caches,
an explicit invalidation must be performed on the entire cache. */
#if XPAR_MICROBLAZE_DCACHE_USE_WRITEBACK == 0
Xil_DCacheInvalidate ();
#endif
Xil_DCacheDisable ();