libxr  1.0
Want to be the best embedded framework
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{
15template <typename FunctionType>
16concept DCacheFunctionAcceptsVoidPtr = std::is_invocable_v<FunctionType, void*, int32_t>;
17
22template <typename FunctionType>
24 std::is_invocable_v<FunctionType, volatile void*, int32_t>;
25
31template <typename FunctionType>
33inline void STM32_CallDCacheByAddr(FunctionType function, void* addr, int32_t dsize)
34{
35 function(addr, dsize);
36}
37
38template <typename FunctionType>
39 requires(!DCacheFunctionAcceptsVoidPtr<FunctionType> &&
40 DCacheFunctionAcceptsVolatileVoidPtr<FunctionType>)
41inline void STM32_CallDCacheByAddr(FunctionType function, void* addr, int32_t dsize)
42{
43 function(reinterpret_cast<volatile void*>(addr), dsize);
44}
45
46template <typename FunctionType>
47 requires(!DCacheFunctionAcceptsVoidPtr<FunctionType> &&
48 !DCacheFunctionAcceptsVolatileVoidPtr<FunctionType>)
49inline void STM32_CallDCacheByAddr(FunctionType function, void* addr, int32_t dsize)
50{
51 function(reinterpret_cast<uint32_t*>(addr), dsize);
52}
53
58inline void STM32_CleanDCacheByAddr(const void* addr, size_t size)
59{
60#if defined(__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U)
61 auto* raw = const_cast<void*>(addr);
62 const auto dsize = static_cast<int32_t>(size);
63 STM32_CallDCacheByAddr(&SCB_CleanDCache_by_Addr, raw, dsize);
64#else
65 (void)addr;
66 (void)size;
67#endif
68}
69
74inline void STM32_InvalidateDCacheByAddr(const void* addr, size_t size)
75{
76#if defined(__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U)
77 auto* raw = const_cast<void*>(addr);
78 const auto dsize = static_cast<int32_t>(size);
79 STM32_CallDCacheByAddr(&SCB_InvalidateDCache_by_Addr, raw, dsize);
80#else
81 (void)addr;
82 (void)size;
83#endif
84}
85} // namespace LibXR
D-Cache API accepts void*
D-Cache API accepts volatile void*
LibXR 命名空间
Definition ch32_can.hpp:14
void STM32_InvalidateDCacheByAddr(const void *addr, size_t size)
Invalidates D-Cache lines covering the specified memory range.
void STM32_CallDCacheByAddr(FunctionType function, void *addr, int32_t dsize)
Calls the CMSIS D-Cache helper with the pointer type accepted by the current toolchain.
void STM32_CleanDCacheByAddr(const void *addr, size_t size)
Cleans D-Cache lines covering the specified memory range.