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
from

Conversation

@dwbrite
Copy link
Contributor

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 Feb 18, 2020
- 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 {

This comment has been minimized.

Copy link
@dwbrite

dwbrite Feb 20, 2020

Author Contributor

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 {

This comment has been minimized.

Copy link
@dwbrite

dwbrite Feb 20, 2020

Author Contributor

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;

This comment has been minimized.

Copy link
@dwbrite

dwbrite Feb 20, 2020

Author Contributor

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 left a comment

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
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

1 participant
You can’t perform that action at this time.