libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
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 {
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
74
76 struct BootInfo
77 {
78 enum class Type : uint32_t
79 {
80 INVALID = 0x00000000,
81 JUMP = 0xDEADBEEF,
82 SKIP_TIMEOUT = 0x5AFEB007,
83 INF_TIMEOUT = 0xB0074EFA,
86 enum class Version : uint32_t
87 {
88 LT_v6_0 = 0, // Less than v6.0
89 NONE, // No bootloader present
90 v6_0, // v6.0
91 v6_1, // v6.1 or greater
92 LAST
94 };
95
96 System() {}
98
102 void Init();
103
108 void Init(const Config& config);
109
114 void DeInit();
115
121
124 static uint32_t GetNow();
125
127 static uint32_t GetUs();
128
134
138 static void Delay(uint32_t delay_ms);
139
143
144
148
165
169
171 static void InitBackupSram();
172
175
178
183
189
197
205
209 const Config& GetConfig() const { return cfg_; }
210
215
221
227 static constexpr uint32_t kQspiBootloaderOffset = 0x40000U;
228
229 private:
230 void ConfigureClocks();
231 void ConfigureMpu();
232 Config cfg_;
233
236 static TimerHandle tim_;
237};
238
239extern volatile daisy::System::BootInfo boot_info;
240
241} // namespace daisy
242
243#else // ifndef UNIT_TEST
244
245#include <cstdint>
246#include "../tests/TestIsolator.h"
247namespace daisy
248{
259class System
260{
261 public:
262 static uint32_t GetNow()
263 {
264 return testIsolator_.GetStateForCurrentTest()->currentUs_ / 1000;
265 }
266 static uint32_t GetUs()
267 {
268 return testIsolator_.GetStateForCurrentTest()->currentUs_;
269 }
270 static uint32_t GetTick()
271 {
272 return testIsolator_.GetStateForCurrentTest()->currentTick_;
273 }
274 static uint32_t GetTickFreq()
275 {
276 return testIsolator_.GetStateForCurrentTest()->tickFreqHz_;
277 }
278
280 static void SetTickForUnitTest(uint32_t tick)
281 {
282 testIsolator_.GetStateForCurrentTest()->currentTick_ = tick;
283 }
285 static void SetUsForUnitTest(uint32_t us)
286 {
287 testIsolator_.GetStateForCurrentTest()->currentUs_ = us;
288 }
290 static void SetTickFreqForUnitTest(uint32_t freqInHz)
291 {
292 testIsolator_.GetStateForCurrentTest()->tickFreqHz_ = freqInHz;
293 }
294
295 private:
296 struct SystemState
297 {
298 uint32_t currentTick_ = 0;
299 uint32_t currentUs_ = 0;
300 uint32_t tickFreqHz_ = 0;
301 };
302 static TestIsolator<SystemState> testIsolator_;
303};
304
305} // namespace daisy
306
307#endif // ifndef UNIT_TEST
308#endif
Definition leddriver.h:33
Definition system.h:19
static uint32_t GetNow()
System()
Definition system.h:96
void Init(const Config &config)
static uint32_t GetPClk1Freq()
static uint32_t GetTick()
static uint32_t GetSysClkFreq()
const Config & GetConfig() const
Definition system.h:209
BootloaderMode
Definition system.h:159
@ DAISY
Definition system.h:161
@ DAISY_SKIP_TIMEOUT
Definition system.h:162
@ STM
Definition system.h:160
@ DAISY_INFINITE_TIMEOUT
Definition system.h:163
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:97
static void DelayTicks(uint32_t delay_ticks)
void JumpToQspi()
MemoryRegion
Definition system.h:63
@ SRAM_D1
Definition system.h:67
@ SRAM_D2
Definition system.h:68
@ QSPI
Definition system.h:71
@ SRAM_D3
Definition system.h:69
@ ITCMRAM
Definition system.h:65
@ SDRAM
Definition system.h:70
@ DTCMRAM
Definition system.h:66
@ INTERNAL_FLASH
Definition system.h:64
@ INVALID_ADDRESS
Definition system.h:72
static MemoryRegion GetProgramMemoryRegion()
static void InitBackupSram()
static uint32_t GetUs()
static BootInfo::Version GetBootloaderVersion()
static constexpr uint32_t kQspiBootloaderOffset
Definition system.h:227
static void ResetToBootloader(BootloaderMode mode=BootloaderMode::STM)
Hardare timer peripheral support.
Definition tim.h:38
Hardware defines and helpers for daisy field platform.
Definition index.h:2
volatile daisy::System::BootInfo boot_info
Definition system.h:77
Type
Definition system.h:79
Version
Definition system.h:87
enum daisy::System::BootInfo::Type status
uint32_t data
Definition system.h:85
enum daisy::System::BootInfo::Version version
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