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

stm32-multi: rtc: add functionality for subseconds #302

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pskiers
Copy link

@pskiers pskiers commented Sep 29, 2022

Adds functionality for rtc for subseconds

Description

Motivation and Context

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

How Has This Been Tested?

  • Already covered by automatic testing.
  • New test added: (add PR link here).
  • Tested by hand on: (list targets here).

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing linter checks and tests passed.
  • My changes generate no new compilation warnings for any of the targets.

Special treatment

  • This PR needs additional PRs to work (list the PRs, preferably in merge-order).
  • I will merge this PR by myself when appropriate.

Comment on lines 145 to 147
const unsigned int month_days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

timestamp->usecs = ((uint64_t) (rtc_common.prediv_s - (ssec & 0xffff)) * 1000 * 1000) / (rtc_common.prediv_s + 1);

Choose a reason for hiding this comment

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

[clang-format-pr] reported by reviewdog 🐶
suggested fix

Suggested change
const unsigned int month_days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
timestamp->usecs = ((uint64_t) (rtc_common.prediv_s - (ssec & 0xffff)) * 1000 * 1000) / (rtc_common.prediv_s + 1);
const unsigned int month_days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
timestamp->usecs = ((uint64_t)(rtc_common.prediv_s - (ssec & 0xffff)) * 1000 * 1000) / (rtc_common.prediv_s + 1);

timestamp->usecs = ((uint64_t) (rtc_common.prediv_s - (ssec & 0xffff)) * 1000 * 1000) / (rtc_common.prediv_s + 1);

if (ssec > rtc_common.prediv_s) {
timestamp->usecs = ((uint64_t) (2 * rtc_common.prediv_s - (ssec & 0xffff)) * 1000 * 1000) / (rtc_common.prediv_s + 1);

Choose a reason for hiding this comment

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

[clang-format-pr] reported by reviewdog 🐶
suggested fix

Suggested change
timestamp->usecs = ((uint64_t) (2 * rtc_common.prediv_s - (ssec & 0xffff)) * 1000 * 1000) / (rtc_common.prediv_s + 1);
timestamp->usecs = ((uint64_t)(2 * rtc_common.prediv_s - (ssec & 0xffff)) * 1000 * 1000) / (rtc_common.prediv_s + 1);

else {
timestamp->hours = (24 + timestamp->hours - carry) % 24;
}

Choose a reason for hiding this comment

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

[clang-format-pr] reported by reviewdog 🐶
suggested fix

Suggested change

prev_month = (11 + timestamp->month) % 12;
prev_month_days = month_days[prev_month];
if (prev_month == 2 && ((timestamp->year % 4 == 0 && timestamp->year % 100 != 0) || timestamp->year % 400 == 0)) {
prev_month_days ++;

Choose a reason for hiding this comment

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

[clang-format-pr] reported by reviewdog 🐶
suggested fix

Suggested change
prev_month_days ++;
prev_month_days++;

}
else {
timestamp->month = (12 + timestamp->month - carry) % 12;
}

Choose a reason for hiding this comment

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

[clang-format-pr] reported by reviewdog 🐶
suggested fix

Suggested change
}
}

Comment on lines 251 to 252
ssec = *(rtc_common.base + ssr) & 0xffff;
ssec = ((uint64_t) (rtc_common.prediv_s - ssec) * 1000 * 1000) / (rtc_common.prediv_s + 1);

Choose a reason for hiding this comment

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

[clang-format-pr] reported by reviewdog 🐶
suggested fix

Suggested change
ssec = *(rtc_common.base + ssr) & 0xffff;
ssec = ((uint64_t) (rtc_common.prediv_s - ssec) * 1000 * 1000) / (rtc_common.prediv_s + 1);
ssec = *(rtc_common.base + ssr) & 0xffff;
ssec = ((uint64_t)(rtc_common.prediv_s - ssec) * 1000 * 1000) / (rtc_common.prediv_s + 1);

ssec = *(rtc_common.base + ssr) & 0xffff;
ssec = ((uint64_t) (rtc_common.prediv_s - ssec) * 1000 * 1000) / (rtc_common.prediv_s + 1);
/*Setting TR has a side effect of changing SSR value to prediv_s*/
*(rtc_common.base + tr) = time;

Choose a reason for hiding this comment

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

[clang-format-pr] reported by reviewdog 🐶
suggested fix

Suggested change
*(rtc_common.base + tr) = time;
*(rtc_common.base + tr) = time;

*(rtc_common.base + isr) &= ~(1 << 7);
while ((*(rtc_common.base + isr) & (1 << 3)));

Choose a reason for hiding this comment

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

[clang-format-pr] reported by reviewdog 🐶
suggested fix

Suggested change
while ((*(rtc_common.base + isr) & (1 << 3)));
while ((*(rtc_common.base + isr) & (1 << 3)))
;

*(rtc_common.base + isr) &= ~(1 << 7);
while ((*(rtc_common.base + isr) & (1 << 3)));
*(rtc_common.base + shiftr) = ((1000 * 1000 - timestamp->usecs) * (rtc_common.prediv_s + 1) / (1000 * 1000)) | (1 << 31);
while ((*(rtc_common.base + isr) & (1 << 3)));

Choose a reason for hiding this comment

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

[clang-format-pr] reported by reviewdog 🐶
suggested fix

Suggested change
while ((*(rtc_common.base + isr) & (1 << 3)));
while ((*(rtc_common.base + isr) & (1 << 3)))
;

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