mFrame
載入中...
搜尋中...
無符合項目
Clock.h
1
7#ifndef CHIP_008A1453_A242_4775_9606_2ED0FF5092CA
8#define CHIP_008A1453_A242_4775_9606_2ED0FF5092CA
9
10/* ***************************************************************************************
11 * Include
12 */
13
14//----------------------------------------------------------------------------------------
15#include "mframe.h"
16
17//----------------------------------------------------------------------------------------
18#include "./../Status.h"
19#include "./../mrcc/MRCC.h"
20#include "./../syscon/SYSCON.h"
21#include "./AttachID.h"
22#include "./Div.h"
23#include "./FircTrimConfig.h"
24#include "./GateName.h"
25#include "./MonitorMode.h"
26#include "./Name.h"
27#include "./SelectName.h"
28#include "./SircTrimConfig.h"
29#include "./SircTrimMode.h"
30#include "./SircTrimSource.h"
31/* ***************************************************************************************
32 * Namespace
33 */
34namespace chip::clock {
35 class Clock;
36}
37
38/* ***************************************************************************************
39 * Class/Interface/Struct/Enum
40 */
42 /* *************************************************************************************
43 * Variable
44 */
45
46 /* *************************************************************************************
47 * Abstract Method
48 */
49
50 /* *************************************************************************************
51 * Construct Method
52 */
53 private:
58 Clock(void);
59
60 public:
65 virtual ~Clock(void) override;
66
67 /* *************************************************************************************
68 * Operator Method
69 */
70
71 /* *************************************************************************************
72 * Public Method <Override>
73 */
74
75 /* *************************************************************************************
76 * Public Method
77 */
78
79 /* *************************************************************************************
80 * Protected Method
81 */
82
83 /* *************************************************************************************
84 * Private Method
85 */
86
87 /* *************************************************************************************
88 * Static Variable
89 */
90 public:
91 /* *************************************************************************************
92 * Static Method
93 */
94 public:
95 static inline constexpr uint32 ATTACH_REG_OFFSET(AttachID attachID) {
96 return (+attachID >> 16U);
97 }
98
99 static inline bool getClockStatus(GateName clk) {
100 uint32 reg_offset = chip::clock::getGateNameOffset(clk);
101 uint32 bit_shift = chip::clock::getGateNameShift(clk);
102 volatile uint32 *pClkCtrl = reinterpret_cast<volatile uint32 *>(
103 reinterpret_cast<uint32>(&(chip::mrcc::MRCC0.mrcc_glb_cc0_set)) + reg_offset);
104
105 if (clk == GateName::NOT_AVAIL)
106 return false;
107
108 if (reg_offset == REG_PWM0SUBCTL)
109 return (chip::mrcc::MRCC0.mrcc_glb_cc0_set & +chip::mrcc::Mask::GLB_CC0_FLEXPWM0);
110
111 else
112 return (*pClkCtrl & (1UL << bit_shift));
113 }
114
120 static inline void enableClock(GateName clk) {
121 uint32 reg_offset = chip::clock::getGateNameOffset(clk);
122 uint32 bit_shift = chip::clock::getGateNameShift(clk);
123 volatile uint32 *pClkCtrl = reinterpret_cast<volatile uint32 *>(
124 reinterpret_cast<uint32>(&(chip::mrcc::MRCC0.mrcc_glb_cc0_set)) + reg_offset);
125
126 if (clk == GateName::NOT_AVAIL) {
127 return;
128 }
129
130 /* Unlock clock configuration */
131 chip::syscon::SYSCON0.clkunlock &= ~+chip::syscon::Mask::CLKUNLOCK_UNLOCK;
132
133 if (reg_offset == REG_PWM0SUBCTL) {
134 chip::syscon::SYSCON0.pwm0subctl |= (1UL << bit_shift);
136 } else {
137 *pClkCtrl = (1UL << bit_shift);
138 }
139
140 /* Freeze clock configuration */
141 chip::syscon::SYSCON0.clkunlock |= +chip::syscon::Mask::CLKUNLOCK_UNLOCK;
142 }
143
149 static inline void disableClock(GateName clk) {
150 uint32 reg_offset = getGateNameOffset(clk);
151 uint32 bit_shift = getGateNameShift(clk);
152 volatile uint32 *pClkCtrl = reinterpret_cast<volatile uint32 *>(
153 reinterpret_cast<uint32>(&(chip::mrcc::MRCC0.mrcc_glb_cc0_clr)) + reg_offset);
154
155 if (clk == GateName::NOT_AVAIL) {
156 return;
157 }
158
159 /* Unlock clock configuration */
160 chip::syscon::SYSCON0.clkunlock &= ~+chip::syscon::Mask::CLKUNLOCK_UNLOCK;
161
162 if (reg_offset == REG_PWM0SUBCTL) {
163 chip::syscon::SYSCON0.pwm0subctl &= ~(1UL << bit_shift);
164
165 if (0U == (chip::syscon::SYSCON0.pwm0subctl & 0xFU)) {
167 }
168 } else {
169 *pClkCtrl = (1UL << bit_shift);
170 }
171
172 /* Freeze clock configuration */
173 chip::syscon::SYSCON0.clkunlock |= +chip::syscon::Mask::CLKUNLOCK_UNLOCK;
174 }
175
181 static void attachClock(AttachID connection);
182
191
198 static void setClockSelect(SelectName sel_name, uint32 value);
199
206 static uint32 getClockSelect(SelectName sel_name);
207
214 static void setClockDiv(Div div_name, uint32 value);
215
221 static uint32 getClockDiv(Div div_name);
222
228 static void haltClockDiv(Div div_name);
229
238 static chip::Status setupFROHFClocking(unsigned int iFreq);
239
248
261 static chip::Status setupFRO16KClocking(uint8 clk_16k_enable_mask);
262
268 static chip::Status setupExtClocking(uint32 iFreq);
269
275 static chip::Status setupExtRefClocking(uint32 iFreq);
276
281 static uint32 getFreq(Name clockName);
282
287 static uint32 getCoreSysClkFreq(void);
288
293 static uint32 getI3CFClkFreq(void);
294
299 static uint32 getCTimerClkFreq(uint32 id);
300
305 static uint32 getLpi2cClkFreq(void);
306
311 static uint32 getLpspiClkFreq(uint32 id);
312
317 static uint32 getLpuartClkFreq(uint32 id);
318
323 static uint32 getLptmrClkFreq(void);
324
329 static uint32 getOstimerClkFreq(void);
330
335 static uint32 getAdcClkFreq(void);
336
341 static uint32 getCmpFClkFreq(uint32 id);
342
347 static uint32 getCmpRRClkFreq(uint32 id);
348
353 static uint32 getTraceClkFreq(void);
354
359 static uint32 getClkoutClkFreq(void);
360
365 static uint32 getSystickClkFreq(void);
366
371 static uint32 getWwdtClkFreq(void);
372
379
386
396
402 static bool enableUsbfsClock(void);
403};
404
405/* ***************************************************************************************
406 * End of file
407 */
408
409#endif /* CHIP_008A1453_A242_4775_9606_2ED0FF5092CA */
Definition Clock.h:41
static void setClockDiv(Div div_name, uint32 value)
Setup peripheral clock dividers.
static uint32 getCoreSysClkFreq(void)
Return Frequency of core.
static void disableClock(GateName clk)
Disable the clock for specific IP.
Definition Clock.h:149
static chip::Status setupFRO16KClocking(uint8 clk_16k_enable_mask)
Initialize the FRO16K.
static uint32 getLptmrClkFreq(void)
Return Frequency of LPTMR functional Clock.
static uint32 getClockSelect(SelectName sel_name)
Get the clock select value. This fuction get the peripheral clock select value.
static chip::Status setupFRO12MClocking(void)
Initialize the FRO12M.
static bool enableUsbfsClock(void)
Enable USB FS clock.
static uint32 getWwdtClkFreq(void)
Return Frequency of Systick Clock.
static uint32 getSystickClkFreq(void)
Return Frequency of Systick Clock.
static uint32 getI3CFClkFreq(void)
Return Frequency of I3C FCLK.
static void setClockSelect(SelectName sel_name, uint32 value)
Set the clock select value. This fuction set the peripheral clock select value.
static void enableClock(GateName clk)
Enable the clock for specific IP.
Definition Clock.h:120
virtual ~Clock(void) override
Destroy the object.
static uint32 getTraceClkFreq(void)
Return Frequency of Trace Clock.
static uint32 getLpi2cClkFreq(void)
Return Frequency of LPI2C0 functional Clock.
static chip::Status setupExtClocking(uint32 iFreq)
Initialize the external osc clock to given frequency.
static void setSysOscMonitorMode(MonitorMode mode)
Sets the system OSC monitor mode.
static uint32 getCmpRRClkFreq(uint32 id)
Return Frequency of CMP Round Robin Clock.
static chip::Status setupExtRefClocking(uint32 iFreq)
Initialize the external reference clock to given frequency.
static uint32 getLpuartClkFreq(uint32 id)
Return Frequency of LPUART functional Clock.
static uint32 getCmpFClkFreq(uint32 id)
Return Frequency of CMP Function Clock.
static void attachClock(AttachID connection)
Configure the clock selection muxes.
static chip::Status frohfTrimConfig(FircTrimConfig config)
Setup FROHF trim.
static chip::Status setupFROHFClocking(unsigned int iFreq)
Initialize the FROHF to given frequency (48,64,96,192).
static uint32 getClockDiv(Div div_name)
Get peripheral clock dividers.
static uint32 getClkoutClkFreq(void)
Return Frequency of CLKOUT Clock.
static chip::Status fro12MTrimConfig(SircTrimConfig config)
Setup FRO 12M trim.
static void haltClockDiv(Div div_name)
Halt peripheral clock dividers.
static uint32 getFreq(Name clockName)
Return Frequency of selected clock.
static uint32 getOstimerClkFreq(void)
Return Frequency of OSTIMER.
static AttachID getClockAttachId(AttachID connection)
Get the actual clock attach id. This fuction uses the offset in input attach id, then it reads the ac...
static uint32 getLpspiClkFreq(uint32 id)
Return Frequency of LPSPI functional Clock.
static uint32 getAdcClkFreq(void)
Return Frequency of Adc Clock.
static uint32 getCTimerClkFreq(uint32 id)
Return Frequency of CTimer functional Clock.
Definition Object.h:34
Definition AttachID.h:23
SelectName
Definition SelectName.h:33
Name
Definition Name.h:33
MonitorMode
Definition MonitorMode.h:34
AttachID
Definition AttachID.h:46
Div
Definition Div.h:33
GateName
Definition GateName.h:39
@ GLB_CC0_FLEXPWM0
MRCC_GLB_CC0 - FLEXPWM0.
@ CLKUNLOCK_UNLOCK
CLKUNLOCK - UNLOCK.
Status
Definition Status.h:34
Definition FircTrimConfig.h:31
Definition SircTrimConfig.h:31
__O uint32 mrcc_glb_cc0_set
Definition mrcc/Register.h:39
__O uint32 mrcc_glb_cc0_clr
Definition mrcc/Register.h:40
__IO uint32 clkunlock
CLKUNLOCK[0x3FC] <RW>
Definition syscon/Register.h:119
__IO uint32 pwm0subctl
Definition syscon/Register.h:269