AsciiFromHex is a function converts a hex number to an ASCII character. This function is used across multiple generators, so add it to the TableHelperLib.
Signed-off-by: Pierre Gondois <pierre.gond...@arm.com> Signed-off-by: Sami Mujawar <sami.muja...@arm.com> --- DynamicTablesPkg/Include/Library/TableHelperLib.h | 15 +++++++++- DynamicTablesPkg/Library/Common/TableHelperLib/TableHelper.c | 30 ++++++++++++++++++-- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/DynamicTablesPkg/Include/Library/TableHelperLib.h b/DynamicTablesPkg/Include/Library/TableHelperLib.h index e4a8dfa046bd97d89f0297ccad521f317bed5c36..099a0a4544e3d1f746d4be8533cb006786f11611 100644 --- a/DynamicTablesPkg/Include/Library/TableHelperLib.h +++ b/DynamicTablesPkg/Include/Library/TableHelperLib.h @@ -1,6 +1,6 @@ /** @file - Copyright (c) 2017 - 2019, ARM Limited. All rights reserved. + Copyright (c) 2017 - 2020, Arm Limited. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent @@ -107,4 +107,17 @@ FindDuplicateValue ( IN PFN_IS_EQUAL EqualTestFunction ); +/** Convert a hex number to its ASCII code. + + @param [in] x Hex number to convert. + Must be 0 <= x < 16. + + @return The ASCII code corresponding to x. +**/ +UINT8 +EFIAPI +AsciiFromHex ( + IN UINT8 x + ); + #endif // TABLE_HELPER_LIB_H_ diff --git a/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelper.c b/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelper.c index fc6cf3b088da1f7ad89dd4356b414bede9e80575..0d9daad3b05b6e82089f92afb6de4eeee5af9a28 100644 --- a/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelper.c +++ b/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelper.c @@ -1,8 +1,9 @@ /** @file Table Helper -Copyright (c) 2017 - 2019, ARM Limited. All rights reserved. -SPDX-License-Identifier: BSD-2-Clause-Patent + Copyright (c) 2017 - 2020, Arm Limited. All rights reserved.<BR> + + SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include <Protocol/AcpiTable.h> @@ -244,3 +245,28 @@ FindDuplicateValue ( } return FALSE; } + +/** Convert a hex number to its ASCII code. + + @param [in] x Hex number to convert. + Must be 0 <= x < 16. + + @return The ASCII code corresponding to x. +**/ +UINT8 +EFIAPI +AsciiFromHex ( + IN UINT8 x + ) +{ + if (x < 10) { + return (UINT8)(x + '0'); + } + + if (x < 16) { + return (UINT8)(x - 10 + 'A'); + } + + ASSERT (FALSE); + return (UINT8)0; +} -- 'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)' -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#64100): https://edk2.groups.io/g/devel/message/64100 Mute This Topic: https://groups.io/mt/76149185/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-