1 /*
2  * Copyright (c) 2001-2019, Arm Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 
8 
9 #ifndef _UTIL_LOG_H
10 #define _UTIL_LOG_H
11 
12 #include "stdio.h"
13 #include <stdint.h>
14 
15 
16 #define CC_COMMON_OK   0
17 #define WORD_BYTE_SIZE (sizeof(uint32_t))
18 
19 #define UTIL_LOG_ERR(format, args...) \
20         fprintf(stderr, "%s(): " format, __FUNCTION__, ##args)
21 
22 #ifdef UTIL_DEBUG
23 #define UTIL_LOG_INFO UTIL_LOG_ERR
24 #define UTIL_LOG_BYTE_BUFF(str, buff, size) {\
25     uint32_t i=0;\
26     unsigned long buff_addr = (unsigned long)buff;\
27     UTIL_LOG_ERR("\nprinting %s, %lu bytes", str, (unsigned long)size);\
28     for (i=0; i<size; i++){\
29         if (!(i%16)) {\
30             fprintf(stderr, "\n");\
31         }\
32         fprintf(stderr, " 0x%02X ", *((uint8_t *)buff_addr + i));\
33     }\
34     fprintf(stderr, "\n");\
35 }
36 #define UTIL_LOG_WORD_BUFF(str, buff, wordSize) {\
37     uint32_t i=0;\
38     unsigned long buff_addr = (unsigned long)buff;\
39     UTIL_LOG_ERR("\nprinting %s, %lu words", str, (unsigned long)wordSize);\
40     for (i=0; i<wordSize; i++){\
41         if (!(i%4)) {\
42             fprintf(stderr, "\n");\
43         }\
44         fprintf(stderr, " 0x%08lX ", *((unsigned long *)buff_addr + i));\
45     }\
46     fprintf(stderr, "\n");\
47 }
48 #else
49 #define UTIL_LOG_INFO(format...)  do{ }while(0)
50 #define UTIL_LOG_BYTE_BUFF(str, buff, size) do{ }while(0)
51 #define UTIL_LOG_WORD_BUFF(str, buff, size) do{ }while(0)
52 #endif
53 
54 
55 #define UTIL_REVERSE_WORD_ORDER(buff, buffSize) {\
56     uint32_t i = 0;\
57     uint8_t  tmpByte = 0;\
58     if (buffSize % WORD_BYTE_SIZE) {\
59         memset(buff, 0, buffSize);\
60     } else {\
61         while ((i+3)<buffSize) {\
62             tmpByte = buff[i+3];\
63             buff[i+3] = buff[i];\
64             buff[i] = tmpByte;\
65             tmpByte = buff[i+2];\
66             buff[i+2] = buff[i+1];\
67             buff[i+1] = tmpByte;\
68             i += 4;\
69         }\
70     }\
71 }
72 
73 #endif
74