/* * The MIT License (MIT) * * Copyright (c) 2022, Ha Thach (tinyusb.org) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * This file is part of the TinyUSB stack. *//* ... */#ifndef_TUSB_DEBUG_H_#define_TUSB_DEBUG_H_#ifdef__cplusplusextern"C"{#endif//--------------------------------------------------------------------+// Debug//--------------------------------------------------------------------+// CFG_TUSB_DEBUG for debugging// 0 : no debug// 1 : print error// 2 : print warning// 3 : print info#ifCFG_TUSB_DEBUG// Enum to String for debugging purposes#ifCFG_TUSB_DEBUG>=CFG_TUH_LOG_LEVEL||CFG_TUSB_DEBUG>=CFG_TUD_LOG_LEVELexterncharconst*consttu_str_speed[];externcharconst*consttu_str_std_request[];externcharconst*consttu_str_xfer_result[];/* ... */#endifvoidtu_print_mem(voidconst*buf,uint32_tcount,uint8_tindent);#ifdefCFG_TUSB_DEBUG_PRINTFexternintCFG_TUSB_DEBUG_PRINTF(constchar*format,...);#definetu_printfCFG_TUSB_DEBUG_PRINTF/* ... */#else#definetu_printfprintf#endifstaticinlinevoidtu_print_buf(uint8_tconst*buf,uint32_tbufsize){for(uint32_ti=0;i<bufsize;i++)tu_printf("%02X ",buf[i]);tu_printf("\r\n");}tu_print_buf (uint8_t const* buf, uint32_t bufsize) { ... }// Log with Level#defineTU_LOG(n,...)TU_XSTRCAT(TU_LOG,n)(__VA_ARGS__)#defineTU_LOG_MEM(n,...)TU_XSTRCAT3(TU_LOG,n,_MEM)(__VA_ARGS__)#defineTU_LOG_BUF(n,...)TU_XSTRCAT3(TU_LOG,n,_BUF)(__VA_ARGS__)#defineTU_LOG_INT(n,...)TU_XSTRCAT3(TU_LOG,n,_INT)(__VA_ARGS__)#defineTU_LOG_HEX(n,...)TU_XSTRCAT3(TU_LOG,n,_HEX)(__VA_ARGS__)#defineTU_LOG_LOCATION()tu_printf("%s: %d:\r\n",__PRETTY_FUNCTION__,__LINE__)#defineTU_LOG_FAILED()tu_printf("%s: %d: Failed\r\n",__PRETTY_FUNCTION__,__LINE__)// Log Level 1: Error#defineTU_LOG1tu_printf#defineTU_LOG1_MEMtu_print_mem#defineTU_LOG1_BUF(_x,_n)tu_print_buf((uint8_tconst*)(_x),_n)#defineTU_LOG1_INT(_x)tu_printf(#_x" = %ld\r\n",(unsignedlong)(_x))#defineTU_LOG1_HEX(_x)tu_printf(#_x" = 0x%lX\r\n",(unsignedlong)(_x))12 defines// Log Level 2: Warn#ifCFG_TUSB_DEBUG>=2#defineTU_LOG2TU_LOG1#defineTU_LOG2_MEMTU_LOG1_MEM#defineTU_LOG2_BUFTU_LOG1_BUF#defineTU_LOG2_INTTU_LOG1_INT#defineTU_LOG2_HEXTU_LOG1_HEX/* ... */#endif// Log Level 3: Info#ifCFG_TUSB_DEBUG>=3#defineTU_LOG3TU_LOG1#defineTU_LOG3_MEMTU_LOG1_MEM#defineTU_LOG3_BUFTU_LOG1_BUF#defineTU_LOG3_INTTU_LOG1_INT#defineTU_LOG3_HEXTU_LOG1_HEX/* ... */#endiftypedefstruct{uint32_tkey;constchar*data;...}tu_lookup_entry_t;typedefstruct{uint16_tcount;tu_lookup_entry_tconst*items;...}tu_lookup_table_t;staticinlineconstchar*tu_lookup_find(tu_lookup_table_tconst*p_table,uint32_tkey){tu_staticcharnot_found[11];for(uint16_ti=0;i<p_table->count;i++){if(p_table->items[i].key==key)returnp_table->items[i].data;}for (uint16_t i=0; icount; i++) { ... }// not found return the key value in hexsnprintf(not_found,sizeof(not_found),"0x%08lX",(unsignedlong)key);returnnot_found;}tu_lookup_find (tu_lookup_table_t const* p_table, uint32_t key) { ... }/* ... */#endif// CFG_TUSB_DEBUG#ifndefTU_LOG#defineTU_LOG(n,...)#defineTU_LOG_MEM(n,...)#defineTU_LOG_BUF(n,...)#defineTU_LOG_INT(n,...)#defineTU_LOG_HEX(n,...)#defineTU_LOG_LOCATION()#defineTU_LOG_FAILED()/* ... */#endif// TODO replace all TU_LOGn with TU_LOG(n)#defineTU_LOG0(...)#defineTU_LOG0_MEM(...)#defineTU_LOG0_BUF(...)#defineTU_LOG0_INT(...)#defineTU_LOG0_HEX(...)5 defines#ifndefTU_LOG1#defineTU_LOG1(...)#defineTU_LOG1_MEM(...)#defineTU_LOG1_BUF(...)#defineTU_LOG1_INT(...)#defineTU_LOG1_HEX(...)/* ... */#endif#ifndefTU_LOG2#defineTU_LOG2(...)#defineTU_LOG2_MEM(...)#defineTU_LOG2_BUF(...)#defineTU_LOG2_INT(...)#defineTU_LOG2_HEX(...)/* ... */#endif#ifndefTU_LOG3#defineTU_LOG3(...)#defineTU_LOG3_MEM(...)#defineTU_LOG3_BUF(...)#defineTU_LOG3_INT(...)#defineTU_LOG3_HEX(...)/* ... */#endif#ifdef__cplusplus}extern "C" { ... }#endif/* ... */#endif/* _TUSB_DEBUG_H_ */
Details
Show: from
Types: Columns:
All items filtered out
All items filtered out
This file uses the notable symbols shown below. Click anywhere in the file to view more details.