Skip to content

Draft: Dynamic Clock Speed#5

Draft
dwbrite wants to merge 3 commits intoirevoire:masterfrom
dwbrite:feat/dynamic-mcg-modes
Draft

Draft: Dynamic Clock Speed#5
dwbrite wants to merge 3 commits intoirevoire:masterfrom
dwbrite:feat/dynamic-mcg-modes

Conversation

@dwbrite
Copy link
Contributor

@dwbrite dwbrite commented Feb 20, 2020

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

Devin Brite added 3 commits February 19, 2020 21:29
- add gitignore
- fix sleep_ms timing
- write more/better comments
- adds a blink_dynamic_clocks example
- rustfmt
External = 2,
}

pub enum CpuFreq {
Copy link
Contributor Author

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 {
Copy link
Contributor Author

@dwbrite dwbrite Feb 20, 2020

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.

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;
Copy link
Contributor Author

@dwbrite dwbrite Feb 20, 2020

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 🤷‍♂️

Copy link
Contributor Author

@dwbrite dwbrite left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant