diff options
author | Pierre Gondois <Pierre.Gondois@arm.com> | 2021-09-30 08:48:15 +0100 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2021-10-01 10:57:43 +0000 |
commit | 653113412fe1099bc80bc128f6501ea77631cc0e (patch) | |
tree | d1c6c3e86cc689e494a1bdc948404efdfc8dd8ae /DynamicTablesPkg | |
parent | 1ad5182500ed8760076ea359ecd8e28edd5d5f53 (diff) | |
download | edk2-653113412fe1099bc80bc128f6501ea77631cc0e.tar.gz |
DynamicTablesPkg: Add HexFromAscii() to AcpiHelperLib
Add HexFromAscii(), converting an hexadecimal ascii char
to an integer.
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
Diffstat (limited to 'DynamicTablesPkg')
-rw-r--r-- | DynamicTablesPkg/Include/Library/AcpiHelperLib.h | 15 | ||||
-rw-r--r-- | DynamicTablesPkg/Library/Common/AcpiHelperLib/AcpiHelper.c | 31 |
2 files changed, 46 insertions, 0 deletions
diff --git a/DynamicTablesPkg/Include/Library/AcpiHelperLib.h b/DynamicTablesPkg/Include/Library/AcpiHelperLib.h index 53ab19b1d1..094392a1a6 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 434b472cbb..0b566f0502 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.
|