libxr
Embedded C++ framework for bare-metal, RTOS and Linux
Loading...
Searching...
No Matches
stm32_dcache.hpp
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5#include <type_traits>
6
7#include "main.h"
8
9namespace LibXR
10{
14template <typename FunctionType>
15concept DCacheFunctionAcceptsVoidPtr = std::is_invocable_v<FunctionType, void*, int32_t>;
16
20template <typename FunctionType>
22 std::is_invocable_v<FunctionType, volatile void*, int32_t>;
23
29template <typename FunctionType>
31inline void STM32_CallDCacheByAddr(FunctionType function, void* addr, int32_t dsize)
32{
33 function(addr, dsize);
34}
35
36template <typename FunctionType>
37 requires(!DCacheFunctionAcceptsVoidPtr<FunctionType> &&
38 DCacheFunctionAcceptsVolatileVoidPtr<FunctionType>)
39inline void STM32_CallDCacheByAddr(FunctionType function, void* addr, int32_t dsize)
40{
41 function(reinterpret_cast<volatile void*>(addr), dsize);
42}
43
44template <typename FunctionType>
45 requires(!DCacheFunctionAcceptsVoidPtr<FunctionType> &&
46 !DCacheFunctionAcceptsVolatileVoidPtr<FunctionType>)
47inline void STM32_CallDCacheByAddr(FunctionType function, void* addr, int32_t dsize)
48{
49 function(reinterpret_cast<uint32_t*>(addr), dsize);
50}
51
56inline void STM32_CleanDCacheByAddr(const void* addr, size_t size)
57{
58#if defined(__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U)
59 auto* raw = const_cast<void*>(addr);
60 const auto dsize = static_cast<int32_t>(size);
61 STM32_CallDCacheByAddr(&SCB_CleanDCache_by_Addr, raw, dsize);
62#else
63 (void)addr;
64 (void)size;
65#endif
66}
67
72inline void STM32_InvalidateDCacheByAddr(const void* addr, size_t size)
73{
74#if defined(__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U)
75 auto* raw = const_cast<void*>(addr);
76 const auto dsize = static_cast<int32_t>(size);
77 STM32_CallDCacheByAddr(&SCB_InvalidateDCache_by_Addr, raw, dsize);
78#else
79 (void)addr;
80 (void)size;
81#endif
82}
83} // namespace LibXR
D-Cache API 可直接接受 void* / D-Cache API accepts void*
D-Cache API 可直接接受 volatile void* / D-Cache API accepts volatile void*
LibXR 命名空间 / LibXR namespace.
Definition ch32_can.hpp:14
void STM32_InvalidateDCacheByAddr(const void *addr, size_t size)
失效指定内存范围覆盖的 D-Cache cache line Invalidates D-Cache lines covering the specified memory range
void STM32_CallDCacheByAddr(FunctionType function, void *addr, int32_t dsize)
按当前工具链接受的指针类型调用 CMSIS D-Cache 接口 Calls the CMSIS D-Cache helper with the pointer type accepted by the...
void STM32_CleanDCacheByAddr(const void *addr, size_t size)
清理指定内存范围覆盖的 D-Cache cache line Cleans D-Cache lines covering the specified memory range