-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft: Dynamic Clock Speed #5
base: master
Are you sure you want to change the base?
Conversation
- add gitignore - fix sleep_ms timing - write more/better comments
- adds a blink_dynamic_clocks example - rustfmt
@@ -42,6 +42,14 @@ enum OscSource { | |||
External = 2, | |||
} | |||
|
|||
pub enum CpuFreq { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm uncertain on how much I like the values of this enum, but it does well enough for now.
} | ||
} | ||
|
||
pub fn mode_to_fbe(&'static mut self) -> Fbe { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function feels... ehh? Maybe just the name is bad.
@@ -22,13 +22,13 @@ pub fn delay(n: u64) { | |||
/// not properly work at all with anything below 5 MHz | |||
#[inline] | |||
pub fn sleep_us(microseconds: u32) { | |||
(0..microseconds).for_each(|_| { | |||
(0..microseconds).for_each(|_| unsafe { | |||
let mut inner = crate::mcg::F_CPU / 5_000_000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reasoning: accessing static mut is always unsafe, so the only safe thing in here is the loop. I figure this is clearer 🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely needs docs and the API's not perfect, but otherwise looks fairly good.
This PR mostly focuses on supporting the
PEE
mode of the MCG.Previously we could enter
PEE
, but not escape it, and our code had no knowledge of its existence.Now, we can allow the k20dx256's clock speeds to dynamically change with a helper function
mcg.set_clocks(mcg::CpuFreq, sim)
. Additionally, static variables are now supported due to the addition of.bss
and.data
sections in the linker.In the future, more helper functions should be added for switching between MCG modes.
TODO: documentation and finalizing the API