For devices that contain a data cache (DCACHE), the HAL supports cache management in select drivers that can potentially be affected by it. The impacted drivers are:
The implementation of the cache management is based on the following cache policy and configuration:
When working with DCACHE, cache coherency issues can be encountered when multiple bus masters access the same region of memory. There are two main scenarios to consider in the case where one of these is the CPU with DCACHE enabled, and the other is a peripheral such as a DMA. Suppose that both access the same memory region located in SRAM. Cache coherency issues can occur depending on the ordering in which the bus masters access that memory and which operations are performed on it.
To avoid running into these issues, the HAL (and the application) must perform the following operations.
In a scenario where multiple bus masters have DCACHE enabled, such as in multi-core (CPU) devices, the application must ensure that memory access is co-ordinated between the cores, such as by using an IPC (Inter-processor commnication) channel.
Cache clean and invalidate operations are performed at a granularity of the cache line size (i.e. 32 bytes). Therefore, all affected memory regions must also be aligned to 32 bytes and suitably padded to be a multiple of 32 bytes. Without proper alignment and padding, adjacent data will become corrupted during these operations.
The HAL is responsible for managing the memory internally within the drivers. The affected memory regions are aligned to the cache line and padded. However, the drivers cannot manage all the memory, such as data buffers passed in by the application. It is the responsibility of the application to properly align and pad the data. Refer to the individual driver API documentation on where these operations should be applied.