Page MenuHomeFreeBSD

Add RTC clock conversions for BCD values, with non-panic validation.
AbandonedPublic

Authored by ian on Jan 1 2018, 11:45 PM.
Tags
None
Referenced Files
F103573341: D13730.diff
Tue, Nov 26, 4:04 PM
F103549444: D13730.diff
Tue, Nov 26, 9:50 AM
Unknown Object (File)
Mon, Nov 25, 12:07 AM
Unknown Object (File)
Thu, Nov 21, 12:40 AM
Unknown Object (File)
Tue, Oct 29, 6:24 AM
Unknown Object (File)
Tue, Oct 29, 6:24 AM
Unknown Object (File)
Oct 4 2024, 6:30 AM
Unknown Object (File)
Sep 23 2024, 11:17 PM
Subscribers

Details

Reviewers
None
Summary

RTC clock hardware frequently uses BCD numbers. Currently the low-level bcd2bin() and bin2bcd() functions will KASSERT if given out-of-range BCD values. Every RTC driver must implement its own code for validating the unreliable data coming from the hardware to avoid a potential kernel panic.

This change introduces two new functions, clock_bcd_to_ts() and clock_ts_to_bcd(). The former validates its inputs and returns EINVAL if any values are out of range. The latter guarantees the returned data will be valid BCD in a known format (4-digit years, etc).

A new bcd_clocktime structure is used with the new functions. It is identical to the original clocktime structure, but has a new unique type to help avoid errors such as passing binary clocktime data to the bcd flavor of conversions.

Changes to existing drivers to use the new code will be committed separately, once this new stuff makes it through review.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 14048

Event Timeline

Add support for handling AM/PM mode (12 vs 24 hour clock) to the conversion routines. Many RTC chips/drivers support an AM/PM mode, and it turns out to be difficult to do the math on BCD values in each individual driver. It's much easier to commonize the support and do the math while the numbers are in binary form during conversion.

Also, change the types of the fields holding BCD data in the bcd_clocktime struct to be uint8_t rather than plain int.