S100 OpenExplorer

# #hbUCPMemFlush

`int32_t hbUCPMemFlush(hbUCPSysMem const *mem, int32_t flag);`

Refresh the cached system memory.

- Parameter

  - [in] `mem` Memory pointer.
  - [in] `flag` Refresh marker.

- Return Value

  - Return `0` means the API was successfully executed, otherwise the execution failed.

Notes

- `flag` optional values ​​and functions:

  - `HB_SYS_MEM_CACHE_INVALIDATE` uses the `Clean + Invalidate` combination operation to write the modified data in the cache back to the memory and invalidate the cache.

  - `HB_SYS_MEM_CACHE_CLEAN` uses the `Clean` operation to write the modified data in the cache back to the memory, but retains the cache copy.

- After the CPU finishes writing the data, `HB_SYS_MEM_CACHE_CLEAN` needs to be used to synchronize the modified data in the cache to the memory, otherwise the following situations may occur:

  - The block of memory is read by other devices, and the data read is the old data in the memory, while the data newly written by the CPU is in the cache.

  - The block of memory is written with new data by other devices later. After writing, when `HB_SYS_MEM_CACHE_INVALIDATE` is used to synchronize the data, the data in the cache will be synchronized to the memory, and the data written by other devices will be modified.

  - This block of memory is written with new data by other devices later. During the writing process, the data in the cache is synchronized to the memory, resulting in data confusion in the memory.

- After other devices have written data, `HB_SYS_MEM_CACHE_INVALIDATE` needs to be used to invalidate the cache, otherwise the CPU may read old data in the cache when reading data.

On This Page