libDaisy
Hardware Library for Daisy
system.h
Go to the documentation of this file.
1#ifndef DSY_SYSTEM_H
2#define DSY_SYSTEM_H
3
4#ifndef UNIT_TEST // for unit tests, a dummy implementation is provided below
5
6#include <cstdint>
7#include "per/tim.h"
8
9namespace daisy
10{
18class System
19{
20 public:
22 struct Config
23 {
25 enum class SysClkFreq
26 {
27 FREQ_400MHZ,
28 FREQ_480MHZ,
29 };
30
35 void Defaults()
36 {
38 use_dcache = true;
39 use_icache = true;
40 skip_clocks = false;
41 }
42
47 void Boost()
48 {
50 use_dcache = true;
51 use_icache = true;
52 skip_clocks = false;
53 }
54
59 };
60
65 {
75 };
76
77 System() {}
79
83 void Init();
84
89 void Init(const Config& config);
90
95 void DeInit();
96
102
105 static uint32_t GetNow();
106
108 static uint32_t GetUs();
109
114 static uint32_t GetTick();
115
119 static void Delay(uint32_t delay_ms);
120
123 static void DelayUs(uint32_t delay_us);
124
125
128 static void DelayTicks(uint32_t delay_ticks);
129
132 static void ResetToBootloader();
133
135 static uint32_t GetTickFreq();
136
140 static uint32_t GetSysClkFreq();
141
146 static uint32_t GetHClkFreq();
147
154 static uint32_t GetPClk1Freq();
155
162 static uint32_t GetPClk2Freq();
163
167 const Config& GetConfig() const { return cfg_; }
168
173
178 static MemoryRegion GetMemoryRegion(uint32_t address);
179
185 static constexpr uint32_t kQspiBootloaderOffset = 0x40000U;
186
187 private:
188 void ConfigureClocks();
189 void ConfigureMpu();
190 Config cfg_;
191
194 static TimerHandle tim_;
195};
196} // namespace daisy
197
198#else // ifndef UNIT_TEST
199
200#include <cstdint>
201#include "../tests/TestIsolator.h"
202namespace daisy
203{
214class System
215{
216 public:
217 static uint32_t GetNow()
218 {
219 return testIsolator_.GetStateForCurrentTest()->currentUs_ / 1000;
220 }
221 static uint32_t GetUs()
222 {
223 return testIsolator_.GetStateForCurrentTest()->currentUs_;
224 }
225 static uint32_t GetTick()
226 {
227 return testIsolator_.GetStateForCurrentTest()->currentTick_;
228 }
229 static uint32_t GetTickFreq()
230 {
231 return testIsolator_.GetStateForCurrentTest()->tickFreqHz_;
232 }
233
235 static void SetTickForUnitTest(uint32_t tick)
236 {
237 testIsolator_.GetStateForCurrentTest()->currentTick_ = tick;
238 }
240 static void SetUsForUnitTest(uint32_t us)
241 {
242 testIsolator_.GetStateForCurrentTest()->currentUs_ = us;
243 }
245 static void SetTickFreqForUnitTest(uint32_t freqInHz)
246 {
247 testIsolator_.GetStateForCurrentTest()->tickFreqHz_ = freqInHz;
248 }
249
250 private:
251 struct SystemState
252 {
253 uint32_t currentTick_ = 0;
254 uint32_t currentUs_ = 0;
255 uint32_t tickFreqHz_ = 0;
256 };
257 static TestIsolator<SystemState> testIsolator_;
258};
259
260} // namespace daisy
261
262#endif // ifndef UNIT_TEST
263#endif
Definition: system.h:19
static uint32_t GetNow()
System()
Definition: system.h:77
void Init(const Config &config)
static uint32_t GetPClk1Freq()
static uint32_t GetTick()
static uint32_t GetSysClkFreq()
const Config & GetConfig() const
Definition: system.h:167
static uint32_t GetTickFreq()
static uint32_t GetHClkFreq()
static void DelayUs(uint32_t delay_us)
static void Delay(uint32_t delay_ms)
static MemoryRegion GetMemoryRegion(uint32_t address)
static uint32_t GetPClk2Freq()
~System()
Definition: system.h:78
static void DelayTicks(uint32_t delay_ticks)
void JumpToQspi()
MemoryRegion
Definition: system.h:65
@ SRAM_D1
Definition: system.h:69
@ SRAM_D2
Definition: system.h:70
@ QSPI
Definition: system.h:73
@ SRAM_D3
Definition: system.h:71
@ ITCMRAM
Definition: system.h:67
@ SDRAM
Definition: system.h:72
@ DTCMRAM
Definition: system.h:68
@ INTERNAL_FLASH
Definition: system.h:66
@ INVALID_ADDRESS
Definition: system.h:74
static MemoryRegion GetProgramMemoryRegion()
static uint32_t GetUs()
static void ResetToBootloader()
static constexpr uint32_t kQspiBootloaderOffset
Definition: system.h:185
Hardare timer peripheral support.
Definition: tim.h:38
Hardware defines and helpers for daisy field platform.
Definition: index.h:2
Definition: system.h:23
SysClkFreq cpu_freq
Definition: system.h:55
SysClkFreq
Definition: system.h:26
bool use_icache
Definition: system.h:57
bool skip_clocks
Definition: system.h:58
void Boost()
Definition: system.h:47
bool use_dcache
Definition: system.h:56
void Defaults()
Definition: system.h:35