Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
portapack-mayhem
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mcules
portapack-mayhem
Commits
88afee26
Commit
88afee26
authored
6 years ago
by
Jared Boone
Browse files
Options
Downloads
Patches
Plain Diff
Clock Manager: Detect Si5351 CLKIN present, measure frequency, and use if approximately 10MHz.
parent
30f2bc41
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
firmware/application/clock_manager.cpp
+24
-4
24 additions, 4 deletions
firmware/application/clock_manager.cpp
firmware/application/clock_manager.hpp
+2
-0
2 additions, 0 deletions
firmware/application/clock_manager.hpp
firmware/application/si5351.hpp
+9
-0
9 additions, 0 deletions
firmware/application/si5351.hpp
with
35 additions
and
4 deletions
firmware/application/clock_manager.cpp
+
24
−
4
View file @
88afee26
...
@@ -269,11 +269,23 @@ void ClockManager::init() {
...
@@ -269,11 +269,23 @@ void ClockManager::init() {
clock_generator
.
enable_fanout
();
clock_generator
.
enable_fanout
();
clock_generator
.
set_pll_input_sources
(
si5351_pll_input_sources
);
clock_generator
.
set_pll_input_sources
(
si5351_pll_input_sources
);
const
bool
use_clkin
=
false
;
const
auto
clkin_present
=
!
clock_generator
.
clkin_loss_of_signal
();
auto
clkin_valid
=
false
;
if
(
clkin_present
)
{
// Measure Si5351B CLKIN frequency against LPC43xx IRC oscillator
set_gp_clkin_to_clkin_direct
();
start_frequency_monitor_measurement
(
cgu
::
CLK_SEL
::
GP_CLKIN
);
wait_For_frequency_monitor_measurement_done
();
const
auto
clkin_frequency
=
get_frequency_monitor_measurement_in_hertz
();
// CLKIN is required to be 10MHz. FREQ_MON measurement is accurate to 1.5%
// due to LPC43xx IRC oscillator precision.
clkin_valid
=
(
clkin_frequency
>=
9850000
)
&&
(
clkin_frequency
<=
10150000
);
}
clock_generator
.
set_clock_control
(
clock_generator
.
set_clock_control
(
use_clkin
?
clkin_valid
?
si5351_clock_control_clkin
:
si5351_clock_control_xtal
si5351_clock_control_clkin
:
si5351_clock_control_xtal
);
);
clock_generator
.
write
(
si5351_pll_a_xtal_reg
);
clock_generator
.
write
(
si5351_pll_a_xtal_reg
);
...
@@ -422,6 +434,14 @@ void ClockManager::disable_gp_clkin_source() {
...
@@ -422,6 +434,14 @@ void ClockManager::disable_gp_clkin_source() {
clock_generator
.
disable_output
(
clock_generator_output_mcu_clkin
);
clock_generator
.
disable_output
(
clock_generator_output_mcu_clkin
);
}
}
void
ClockManager
::
set_gp_clkin_to_clkin_direct
()
{
clock_generator
.
set_clock_control
(
clock_generator_output_mcu_clkin
,
{
ClockControl
::
CLK_IDRV_2mA
|
ClockControl
::
CLK_SRC_CLKIN
|
ClockControl
::
CLK_INV_Normal
|
ClockControl
::
MS_INT_Integer
|
ClockControl
::
CLK_PDN_Power_On
}
);
enable_gp_clkin_source
();
}
void
ClockManager
::
start_frequency_monitor_measurement
(
const
cgu
::
CLK_SEL
clk_sel
)
{
void
ClockManager
::
start_frequency_monitor_measurement
(
const
cgu
::
CLK_SEL
clk_sel
)
{
// Measure a clock input for 480 cycles of the LPC43xx IRC.
// Measure a clock input for 480 cycles of the LPC43xx IRC.
LPC_CGU
->
FREQ_MON
=
LPC_CGU_FREQ_MON_Type
{
LPC_CGU
->
FREQ_MON
=
LPC_CGU_FREQ_MON_Type
{
...
...
This diff is collapsed.
Click to expand it.
firmware/application/clock_manager.hpp
+
2
−
0
View file @
88afee26
...
@@ -77,6 +77,8 @@ private:
...
@@ -77,6 +77,8 @@ private:
void
enable_gp_clkin_source
();
void
enable_gp_clkin_source
();
void
disable_gp_clkin_source
();
void
disable_gp_clkin_source
();
void
set_gp_clkin_to_clkin_direct
();
void
start_frequency_monitor_measurement
(
const
cgu
::
CLK_SEL
clk_sel
);
void
start_frequency_monitor_measurement
(
const
cgu
::
CLK_SEL
clk_sel
);
void
wait_For_frequency_monitor_measurement_done
();
void
wait_For_frequency_monitor_measurement_done
();
...
...
This diff is collapsed.
Click to expand it.
firmware/application/si5351.hpp
+
9
−
0
View file @
88afee26
...
@@ -310,6 +310,10 @@ public:
...
@@ -310,6 +310,10 @@ public:
while
(
device_status
()
&
0x80
);
while
(
device_status
()
&
0x80
);
}
}
bool
clkin_loss_of_signal
()
{
return
(
device_status
()
>>
4
)
&
1
;
}
void
enable_fanout
()
{
void
enable_fanout
()
{
write_register
(
Register
::
FanoutEnable
,
0b11010000
);
write_register
(
Register
::
FanoutEnable
,
0b11010000
);
}
}
...
@@ -373,6 +377,11 @@ public:
...
@@ -373,6 +377,11 @@ public:
update_all_clock_control
();
update_all_clock_control
();
}
}
void
set_clock_control
(
const
size_t
n
,
const
ClockControl
::
Type
clock_control
)
{
_clock_control
[
n
]
=
clock_control
;
write_register
(
Register
::
CLKControl_Base
+
n
,
_clock_control
[
n
]);
}
void
enable_clock
(
const
size_t
n
)
{
void
enable_clock
(
const
size_t
n
)
{
_clock_control
[
n
]
&=
~
ClockControl
::
CLK_PDN_Mask
;
_clock_control
[
n
]
&=
~
ClockControl
::
CLK_PDN_Mask
;
write_register
(
Register
::
CLKControl_Base
+
n
,
_clock_control
[
n
]);
write_register
(
Register
::
CLKControl_Base
+
n
,
_clock_control
[
n
]);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment