11.5.6 Cache Load and Lock
It is possible to lock a specific way for code optimization by writing the Lock Way register (LCKWAY.LCKWAY). The locked way will not be updated by the CMCC as part of cache operations.
The load and lock mechanism can be implemented to use cache memory in a
deterministic way. Follow these steps to load and lock a way:
- Disable cache controller by clearing the CTRL.CEN bit.
- Invalidate the desired WAY line by line. This will reset the round robin algorithm of the invalidated line, that will become eligible for the next load operation.
- Disable the Instruction cache, but keep the Data cache enabled.
- Enable the cache by setting the CTRL.CEN bit.
- Place the respective piece of code and/or data to the corresponding WAY due to simple LOAD operations. Loading the piece of code and/or data will force the cache to refill the previous invalidated line in the right way. No need to load all the bytes of the line, only the first byte. The cache will automatically refill the complete line.
- Lock the specific WAY by setting LCKWAY.LCKWAY[3:0].
- Re-enable the instruction cache. The locked WAY is now loaded and ready to operate. The remaining WAYS can be used as I-cache or D-cache as required.