From 954df3d6bf60c750a4f4aaa0f4297260755a234e Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Tue, 10 Aug 2021 17:10:14 -0700 Subject: include/bcd: move bcd code to commonlib/bsd/include Move bcd2bin() / bin2bcd() functions to commonlib/bsd/include/ Also, the license is changed from GPL to BSD. This is because it is needed from "utils" (see CL in the chain). For reference bin2bcd() & bcd2bin() are very simple functions. There are already BSD implementations, like these ones (just to name a few): https://chromium.googlesource.com/chromiumos/platform/mosys/+/refs/heads/main/include/lib/math.h#67 http://web.mit.edu/freebsd/head/sys/contrib/octeon-sdk/cvmx-cn3010-evb-hs5.c BUG=b:172210863 TEST=make (everything compiled Ok). Change-Id: If2eba82da35838799bcbcf38303de6bd53f7eb72 Signed-off-by: Ricardo Quesada Reviewed-on: https://review.coreboot.org/c/coreboot/+/56904 Reviewed-by: Furquan Shaikh Reviewed-by: Paul Menzel Reviewed-by: Jack Rosenthal Tested-by: build bot (Jenkins) --- src/commonlib/bsd/include/commonlib/bsd/bcd.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/commonlib/bsd/include/commonlib/bsd/bcd.h (limited to 'src/commonlib') diff --git a/src/commonlib/bsd/include/commonlib/bsd/bcd.h b/src/commonlib/bsd/include/commonlib/bsd/bcd.h new file mode 100644 index 0000000000..6346b5f72f --- /dev/null +++ b/src/commonlib/bsd/include/commonlib/bsd/bcd.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ + +#ifndef _BCD_H_ +#define _BCD_H_ + +#include + +static inline uint8_t bcd2bin(uint8_t val) +{ + return ((val >> 4) & 0xf) * 10 + (val & 0xf); +} + +static inline uint8_t bin2bcd(uint8_t val) +{ + return ((val / 10) << 4) | (val % 10); +} + +#endif /* _BCD_H_ */ -- cgit v1.2.3