Skip to content
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

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

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
@@ -42,6 +42,14 @@ enum OscSource {
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.

@@ -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;
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