hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (c) 2014, STMicroelectronics International N.V.
 */
 
#include "adbg_int.h"
 
#include <stdlib.h>
 
#include <ctype.h>
/*************************************************************************
 * 2. Definition of external constants and variables
 ************************************************************************/
 
/*************************************************************************
 * 3. File scope types, constants and variables
 ************************************************************************/
 
/*************************************************************************
 * 4. Declaration of file local functions
 ************************************************************************/
 
/*************************************************************************
 * 5. Definition of external functions
 ************************************************************************/
 
/******************************************************************************/
/*! @fn void Do_ADBG_Log( void* This_p, char* Format, ...)
 * @brief
 * @param [in] This_p
 * @param [in] Format
 * @param [in] ...
 * @return void
 */
/******************************************************************************/
void Do_ADBG_Log(const char *const Format, ...)
{
   va_list ap;
 
   va_start(ap, Format);
   vprintf(Format, ap);
   printf("\n");
   va_end(ap);
   fflush(stdout);
}
 
void Do_ADBG_HexLog(
   const void *const Buf_p,
   const size_t Size,
   const size_t Cols
   )
{
   const uint8_t *Data_p = Buf_p;
   size_t n = 0;
 
   for (n = 0; n < Size; n += Cols) {
       char HexBuffer[ADBG_STRING_LENGTH_MAX];
       char AsciiBuffer[ADBG_STRING_LENGTH_MAX / 3];
       size_t m, NumCols;
 
       (void)SecUtil_BufferToHex(Data_p + n, MIN(Cols, Size - n), NULL,
                     HexBuffer, sizeof(HexBuffer));
       NumCols = MIN(MIN(Cols, Size - n), sizeof(AsciiBuffer) - 1);
       for (m = 0; m < NumCols; m++) {
           int ch = Data_p[n + m];
 
           if (isprint(ch))
               AsciiBuffer[m] = (char)ch;
           else
               AsciiBuffer[m] = '.';
       }
       AsciiBuffer[m] = '\0';
 
       Do_ADBG_Log("  %-*s %s", (int)Cols * 3, HexBuffer, AsciiBuffer);
   }
}
 
/*************************************************************************
 * 6. Definitions of internal functions
 ************************************************************************/