libyggdrasil  v1.0.0
cache.hpp
Go to the documentation of this file.
1  /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * _____.___. .___ .__.__ *
3  * \__ | | ____ ____ __| _/___________ _____|__| | *
4  * / | |/ ___\ / ___\ / __ |\_ __ \__ \ / ___/ | | *
5  * \____ / /_/ > /_/ > /_/ | | | \// __ \_\___ \| | |__ *
6  * / ______\___ /\___ /\____ | |__| (____ /____ >__|____/ *
7  * \/ /_____//_____/ \/ \/ \/ *
8  * - Midgard - *
9  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
10  * This software can be used by students and other personal of the *
11  * Bern University of Applied Sciences under the terms of the MIT *
12  * license. *
13  * For other persons this software is under the terms of the GNU *
14  * General Public License version 2. *
15  * *
16  * Copyright © 2021, Bern University of Applied Sciences. *
17  * All rights reserved. *
18  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
26 #pragma once
27 
28 #include <cpp/common/types.hpp>
30 
32 
33 #include <core_cm7.h>
34 
35 namespace bsp::core {
36 
37  constexpr auto DCacheLineSize = 32;
38  constexpr auto ICacheLineSize = 32;
39 
44  DSB();
45  ISB();
46 
47  SCB->ICIALLU = 0UL;
48 
49  DSB();
50  ISB();
51  }
52 
59  ALWAYS_INLINE void invalidateICache(void *address, size_t size) {
60  if (size > 0) {
61  addr_t invalidateAddress = reinterpret_cast<addr_t>(address);
62  ssize_t invalidateSize = size + (invalidateAddress & (ICacheLineSize - 1));
63 
64  DSB();
65 
66  do {
67  SCB->ICIMVAU = invalidateAddress;
68 
69  invalidateAddress += ICacheLineSize;
70  invalidateSize -= ICacheLineSize;
71  } while (invalidateSize > 0);
72 
73  DSB();
74  ISB();
75  }
76  }
77 
78 }
instructions.hpp
Assembly instruction wrapper functions for Midgard.
types.hpp
Commonly used type definitions and helper templates.
ALWAYS_INLINE
#define ALWAYS_INLINE
Definition: attributes.h:34
bsp::core::DCacheLineSize
constexpr auto DCacheLineSize
Size of one Data Cache Line.
Definition: cache.hpp:37
bsp::core::ICacheLineSize
constexpr auto ICacheLineSize
Size of one Instruction Cache Line.
Definition: cache.hpp:38
bsp::core::invalidateICache
ALWAYS_INLINE void invalidateICache()
Invalidates the entire ICache.
Definition: cache.hpp:43
bsp::core
Definition: cortex.hpp:33
attributes.hpp
Commonly used C++ and GNU attributes.
bsp::addr_t
std::uint32_t addr_t
ARM32 specific types.
Definition: types.hpp:90