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>
17 std::is_invocable_v<FunctionType, void*, int32_t>;
18
23template <typename FunctionType>
25 std::is_invocable_v<FunctionType, volatile void*, int32_t>;
26
32template <typename FunctionType>
34inline void STM32_CallDCacheByAddr(FunctionType function, void* addr, int32_t dsize)
35{
36 function(addr, dsize);
37}
38
39template <typename FunctionType>
40requires(!DCacheFunctionAcceptsVoidPtr<FunctionType> &&
41 DCacheFunctionAcceptsVolatileVoidPtr<FunctionType>)
42inline void STM32_CallDCacheByAddr(FunctionType function, void* addr, int32_t dsize)
43{
44 function(reinterpret_cast<volatile void*>(addr), dsize);
45}
46
47template <typename FunctionType>
48requires(!DCacheFunctionAcceptsVoidPtr<FunctionType> &&
49 !DCacheFunctionAcceptsVolatileVoidPtr<FunctionType>)
50inline void STM32_CallDCacheByAddr(FunctionType function, void* addr, int32_t dsize)
51{
52 function(reinterpret_cast<uint32_t*>(addr), dsize);
53}
54
59inline void STM32_CleanDCacheByAddr(const void* addr, size_t size)
60{
61#if defined(__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U)
62 auto* raw = const_cast<void*>(addr);
63 const auto dsize = static_cast<int32_t>(size);
64 STM32_CallDCacheByAddr(&SCB_CleanDCache_by_Addr, raw, dsize);
65#else
66 (void)addr;
67 (void)size;
68#endif
69}
70
75inline void STM32_InvalidateDCacheByAddr(const void* addr, size_t size)
76{
77#if defined(__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U)
78 auto* raw = const_cast<void*>(addr);
79 const auto dsize = static_cast<int32_t>(size);
80 STM32_CallDCacheByAddr(&SCB_InvalidateDCache_by_Addr, raw, dsize);
81#else
82 (void)addr;
83 (void)size;
84#endif
85}
86} // 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.