![]() |
|
|||
0001 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 0002 /****************************************************************************** 0003 * 0004 * Module Name: uthex -- Hex/ASCII support functions 0005 * 0006 * Copyright (C) 2000 - 2022, Intel Corp. 0007 * 0008 *****************************************************************************/ 0009 0010 #include <acpi/acpi.h> 0011 #include "accommon.h" 0012 0013 #define _COMPONENT ACPI_COMPILER 0014 ACPI_MODULE_NAME("uthex") 0015 0016 /* Hex to ASCII conversion table */ 0017 static const char acpi_gbl_hex_to_ascii[] = { 0018 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 0019 'E', 'F' 0020 }; 0021 0022 /******************************************************************************* 0023 * 0024 * FUNCTION: acpi_ut_hex_to_ascii_char 0025 * 0026 * PARAMETERS: integer - Contains the hex digit 0027 * position - bit position of the digit within the 0028 * integer (multiple of 4) 0029 * 0030 * RETURN: The converted Ascii character 0031 * 0032 * DESCRIPTION: Convert a hex digit to an Ascii character 0033 * 0034 ******************************************************************************/ 0035 0036 char acpi_ut_hex_to_ascii_char(u64 integer, u32 position) 0037 { 0038 u64 index; 0039 0040 acpi_ut_short_shift_right(integer, position, &index); 0041 return (acpi_gbl_hex_to_ascii[index & 0xF]); 0042 } 0043 0044 /******************************************************************************* 0045 * 0046 * FUNCTION: acpi_ut_ascii_to_hex_byte 0047 * 0048 * PARAMETERS: two_ascii_chars - Pointer to two ASCII characters 0049 * return_byte - Where converted byte is returned 0050 * 0051 * RETURN: Status and converted hex byte 0052 * 0053 * DESCRIPTION: Perform ascii-to-hex translation, exactly two ASCII characters 0054 * to a single converted byte value. 0055 * 0056 ******************************************************************************/ 0057 0058 acpi_status acpi_ut_ascii_to_hex_byte(char *two_ascii_chars, u8 *return_byte) 0059 { 0060 0061 /* Both ASCII characters must be valid hex digits */ 0062 0063 if (!isxdigit((int)two_ascii_chars[0]) || 0064 !isxdigit((int)two_ascii_chars[1])) { 0065 return (AE_BAD_HEX_CONSTANT); 0066 } 0067 0068 *return_byte = 0069 acpi_ut_ascii_char_to_hex(two_ascii_chars[1]) | 0070 (acpi_ut_ascii_char_to_hex(two_ascii_chars[0]) << 4); 0071 0072 return (AE_OK); 0073 } 0074 0075 /******************************************************************************* 0076 * 0077 * FUNCTION: acpi_ut_ascii_char_to_hex 0078 * 0079 * PARAMETERS: hex_char - Hex character in Ascii. Must be: 0080 * 0-9 or A-F or a-f 0081 * 0082 * RETURN: The binary value of the ascii/hex character 0083 * 0084 * DESCRIPTION: Perform ascii-to-hex translation 0085 * 0086 ******************************************************************************/ 0087 0088 u8 acpi_ut_ascii_char_to_hex(int hex_char) 0089 { 0090 0091 /* Values 0-9 */ 0092 0093 if (hex_char <= '9') { 0094 return ((u8)(hex_char - '0')); 0095 } 0096 0097 /* Upper case A-F */ 0098 0099 if (hex_char <= 'F') { 0100 return ((u8)(hex_char - 0x37)); 0101 } 0102 0103 /* Lower case a-f */ 0104 0105 return ((u8)(hex_char - 0x57)); 0106 }
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |