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

Fixup rosc_set_div function #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/rp2_common/hardware_rosc/rosc.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ uint rosc_find_freq(uint32_t low_mhz, uint32_t high_mhz) {
}

void rosc_set_div(uint32_t div) {
assert(div <= 31 && div >= 1);
rosc_write(&rosc_hw->div, ROSC_DIV_VALUE_PASS + div);
assert(div <= 31);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like this should actually be a valid_params_if

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I'll update it this evening.

rosc_clear_bad_write();
assert(rosc_write_okay());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

under what circumstances can this fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well that's a good question - it's so long since I wrote this PR that I can't remember now! I'll have to dig through my emails this evening....... (and hope that the answer exists in an email and isn't lost somewhere in the google chat history)

// don't use rosc_write here because setting a valid DIV is incorrectly flagged as a bad write
rosc_hw->div = ROSC_DIV_VALUE_PASS + div;
rosc_clear_bad_write();
assert(rosc_write_okay());
}

void rosc_set_freq(uint32_t code) {
Expand All @@ -58,4 +63,4 @@ void rosc_set_dormant(void) {
rosc_write(&rosc_hw->dormant, ROSC_DORMANT_VALUE_DORMANT);
// Wait for it to become stable once woken up
while(!(rosc_hw->status & ROSC_STATUS_STABLE_BITS));
}
}