developer | 02e6591 | 2023-08-17 16:33:10 +0800 | [diff] [blame] | 1 | /* log.c |
| 2 | * |
| 3 | * Log implementation for specific environment |
| 4 | */ |
| 5 | |
| 6 | /***************************************************************************** |
| 7 | * Copyright (c) 2008-2020 by Rambus, Inc. and/or its subsidiaries. |
| 8 | * |
| 9 | * This program is free software: you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation, either version 2 of the License, or |
| 12 | * any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | *****************************************************************************/ |
| 22 | |
| 23 | #define LOG_SEVERITY_MAX LOG_SEVERITY_NO_OUTPUT |
| 24 | |
| 25 | // Logging API |
| 26 | #include "log.h" // the API to implement |
| 27 | |
| 28 | |
| 29 | /*---------------------------------------------------------------------------- |
| 30 | * Log_HexDump |
| 31 | * |
| 32 | * This function logs Hex Dump of a Buffer |
| 33 | * |
| 34 | * szPrefix |
| 35 | * Prefix to be printed on every row. |
| 36 | * |
| 37 | * PrintOffset |
| 38 | * Offset value that is printed at the start of every row. Can be used |
| 39 | * when the byte printed are located at some offset in another buffer. |
| 40 | * |
| 41 | * Buffer_p |
| 42 | * Pointer to the start of the array of bytes to hex dump. |
| 43 | * |
| 44 | * ByteCount |
| 45 | * Number of bytes to include in the hex dump from Buffer_p. |
| 46 | * |
| 47 | * Return Value |
| 48 | * None. |
| 49 | */ |
| 50 | void |
| 51 | Log_HexDump( |
| 52 | const char * szPrefix_p, |
| 53 | const unsigned int PrintOffset, |
| 54 | const uint8_t * Buffer_p, |
| 55 | const unsigned int ByteCount) |
| 56 | { |
| 57 | unsigned int i; |
| 58 | |
| 59 | for(i = 0; i < ByteCount; i += 16) |
| 60 | { |
| 61 | unsigned int j, Limit; |
| 62 | |
| 63 | // if we do not have enough data for a full line |
| 64 | if (i + 16 > ByteCount) |
| 65 | Limit = ByteCount - i; |
| 66 | else |
| 67 | Limit = 16; |
| 68 | |
| 69 | Log_FormattedMessage("%s %08d:", szPrefix_p, PrintOffset + i); |
| 70 | |
| 71 | for (j = 0; j < Limit; j++) |
| 72 | Log_FormattedMessage(" %02X", Buffer_p[i+j]); |
| 73 | |
| 74 | Log_FormattedMessage("\n"); |
| 75 | } // for |
| 76 | } |
| 77 | |
| 78 | |
| 79 | /*---------------------------------------------------------------------------- |
| 80 | * Log_HexDump32 |
| 81 | * |
| 82 | * This function logs Hex Dump of an array of 32-bit words |
| 83 | * |
| 84 | * szPrefix |
| 85 | * Prefix to be printed on every row. |
| 86 | * |
| 87 | * PrintOffset |
| 88 | * Offset value that is printed at the start of every row. Can be used |
| 89 | * when the byte printed are located at some offset in another buffer. |
| 90 | * |
| 91 | * Buffer_p |
| 92 | * Pointer to the start of the array of 32-bit words to hex dump. |
| 93 | * |
| 94 | * Word32Count |
| 95 | * Number of 32-bit words to include in the hex dump from Buffer_p. |
| 96 | * |
| 97 | * Return Value |
| 98 | * None. |
| 99 | */ |
| 100 | void |
| 101 | Log_HexDump32( |
| 102 | const char * szPrefix_p, |
| 103 | const unsigned int PrintOffset, |
| 104 | const uint32_t * Buffer_p, |
| 105 | const unsigned int Word32Count) |
| 106 | { |
| 107 | unsigned int i; |
| 108 | |
| 109 | for(i = 0; i < Word32Count; i += 4) |
| 110 | { |
| 111 | unsigned int j, Limit; |
| 112 | |
| 113 | // if we do not have enough data for a full line |
| 114 | if (i + 4 > Word32Count) |
| 115 | Limit = Word32Count - i; |
| 116 | else |
| 117 | Limit = 4; |
| 118 | |
| 119 | Log_FormattedMessage("%s %08d:", szPrefix_p, PrintOffset + i*4); |
| 120 | |
| 121 | for (j = 0; j < Limit; j++) |
| 122 | Log_FormattedMessage(" %08X", Buffer_p[i+j]); |
| 123 | |
| 124 | Log_FormattedMessage("\n"); |
| 125 | } // for |
| 126 | } |
| 127 | |
| 128 | /* end of file log.c */ |