From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web09.9382.1632988134434100838 for ; Thu, 30 Sep 2021 00:48:54 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: pierre.gondois@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4C071106F; Thu, 30 Sep 2021 00:48:49 -0700 (PDT) Received: from e120189.home (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 28F633F70D; Thu, 30 Sep 2021 00:48:47 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io, Sami Mujawar , Alexei.Fedorov@arm.com, Joey Gouly Subject: [PATCH v2 04/10] DynamicTablesPkg: Add HexFromAscii() to AcpiHelperLib Date: Thu, 30 Sep 2021 08:48:15 +0100 Message-Id: <20210930074821.12546-5-Pierre.Gondois@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210930074821.12546-1-Pierre.Gondois@arm.com> References: <20210930074821.12546-1-Pierre.Gondois@arm.com> From: Pierre Gondois Add HexFromAscii(), converting an hexadecimal ascii char to an integer. Reviewed-by: Sami Mujawar Signed-off-by: Pierre Gondois --- Notes: v2: -Document returned error code. [Sami] .../Include/Library/AcpiHelperLib.h | 15 +++++++++ .../Library/Common/AcpiHelperLib/AcpiHelper.c | 31 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/DynamicTablesPkg/Include/Library/AcpiHelperLib.h b/DynamicTablesPkg/Include/Library/AcpiHelperLib.h index 53ab19b1d139..094392a1a6d0 100644 --- a/DynamicTablesPkg/Include/Library/AcpiHelperLib.h +++ b/DynamicTablesPkg/Include/Library/AcpiHelperLib.h @@ -34,6 +34,21 @@ AsciiFromHex ( IN UINT8 Hex ); +/** Convert an ASCII char representing an hexadecimal number + to its integer value. + + @param [in] Char Char to convert. + Must be between '0'-'9' or 'A'-'F' or 'a'-'f'. + + @return The corresponding integer (between 0-16). + -1 if error. +**/ +UINT8 +EFIAPI +HexFromAscii ( + IN CHAR8 Char + ); + /** Check if a HID is a valid PNP ID. @param [in] Hid The Hid to validate. diff --git a/DynamicTablesPkg/Library/Common/AcpiHelperLib/AcpiHelper.c b/DynamicTablesPkg/Library/Common/AcpiHelperLib/AcpiHelper.c index 434b472cbb14..0b566f0502ac 100644 --- a/DynamicTablesPkg/Library/Common/AcpiHelperLib/AcpiHelper.c +++ b/DynamicTablesPkg/Library/Common/AcpiHelperLib/AcpiHelper.c @@ -38,6 +38,37 @@ AsciiFromHex ( return (UINT8)-1; } +/** Convert an ASCII char representing an hexadecimal number + to its integer value. + + @param [in] Char Char to convert. + Must be between '0'-'9' or 'A'-'F' or 'a'-'f'. + + @return The corresponding integer (between 0-16). + -1 if error. +**/ +UINT8 +EFIAPI +HexFromAscii ( + IN CHAR8 Char + ) +{ + if ((Char >= '0') && (Char <= '9')) { + return (UINT8)(Char - '0'); + } + + if ((Char >= 'A') && (Char <= 'F')) { + return (UINT8)(Char - 'A' + 10); + } + + if ((Char >= 'a') && (Char <= 'f')) { + return (UINT8)(Char - 'a' + 10); + } + + ASSERT (FALSE); + return (UINT8)-1; +} + /** Check if a HID is a valid PNP ID. @param [in] Hid The Hid to validate. -- 2.17.1