1 /** 2 * @file lv_debug.c 3 * 4 */ 5 6 /********************* 7 * INCLUDES 8 *********************/ 9 #include "lv_debug.h" 10 11 #if LV_USE_DEBUG 12 13 #include "lv_mem.h" 14 #include <string.h> 15 16 /********************* 17 * DEFINES 18 *********************/ 19 #ifndef LV_DEBUG_STR_MAX_LENGTH 20 #define LV_DEBUG_STR_MAX_LENGTH (1024 * 8) 21 #endif 22 23 #ifndef LV_DEBUG_STR_MAX_REPEAT 24 #define LV_DEBUG_STR_MAX_REPEAT 8 25 #endif 26 /********************** 27 * TYPEDEFS 28 **********************/ 29 30 /********************** 31 * STATIC PROTOTYPES 32 **********************/ 33 34 /********************** 35 * STATIC VARIABLES 36 **********************/ 37 38 /********************** 39 * MACROS 40 **********************/ 41 42 /********************** 43 * GLOBAL FUNCTIONS 44 **********************/ 45 lv_debug_check_null(const void * p)46bool lv_debug_check_null(const void * p) 47 { 48 if(p) return true; 49 50 return false; 51 } 52 lv_debug_check_mem_integrity(void)53bool lv_debug_check_mem_integrity(void) 54 { 55 return lv_mem_test() == LV_RES_OK ? true : false; 56 } 57 lv_debug_check_str(const void * str)58bool lv_debug_check_str(const void * str) 59 { 60 const uint8_t * s = (const uint8_t *)str; 61 uint8_t last_byte = 0; 62 uint32_t rep = 0; 63 uint32_t i; 64 65 for(i = 0; i < LV_DEBUG_STR_MAX_LENGTH && s[i] != '\0'; i++) { 66 if(s[i] != last_byte) { 67 last_byte = s[i]; 68 rep = 1; 69 } 70 else if(s[i] > 0x7F) { 71 rep++; 72 if(rep > LV_DEBUG_STR_MAX_REPEAT) { 73 LV_LOG_WARN("lv_debug_check_str: a non-ASCII char has repeated more than LV_DEBUG_STR_MAX_REPEAT times)"); 74 return false; 75 } 76 } 77 78 if(s[i] < 10) { 79 LV_LOG_WARN("lv_debug_check_str: invalid char in the string (< 10 value)"); 80 return false; /*Shouldn't occur in strings*/ 81 } 82 } 83 84 if(s[i] == '\0') return true; 85 86 LV_LOG_WARN("lv_debug_check_str: string is longer than LV_DEBUG_STR_MAX_LENGTH"); 87 return false; 88 } 89 lv_debug_log_error(const char * msg,uint64_t value)90void lv_debug_log_error(const char * msg, uint64_t value) 91 { 92 static const char hex[] = "0123456789ABCDEF"; 93 94 size_t msg_len = strlen(msg); 95 uint32_t value_len = sizeof(unsigned long int); 96 97 if(msg_len < 230) { 98 char buf[255]; 99 char * bufp = buf; 100 101 /*Add the function name*/ 102 _lv_memcpy(bufp, msg, msg_len); 103 bufp += msg_len; 104 105 /*Add value in hey*/ 106 *bufp = ' '; 107 bufp ++; 108 *bufp = '('; 109 bufp ++; 110 *bufp = '0'; 111 bufp ++; 112 *bufp = 'x'; 113 bufp ++; 114 115 int8_t i; 116 for(i = value_len * 2 - 1; i >= 0; i--) { 117 uint8_t x = (unsigned long int)((unsigned long int)value >> (i * 4)) & 0xF; 118 119 *bufp = hex[x]; 120 bufp++; 121 } 122 123 *bufp = ')'; 124 bufp ++; 125 126 *bufp = '\0'; 127 LV_LOG_ERROR(buf); 128 } 129 else { 130 LV_LOG_ERROR(msg); 131 } 132 } 133 134 /********************** 135 * STATIC FUNCTIONS 136 **********************/ 137 138 139 #endif /*LV_USE_DEBUG*/ 140 141