디버깅을 위해 다음 프로그램 코드가 헤더 파일에 있습니다. 내 의도는 프로그램이 디버그 모드로 컴파일되지 않은 경우 어떤 메시지를 콘솔 포트에 출력할지 또는 인쇄하지 않을지를 컴파일 시간 중에 결정하는 것입니다. DBG 수준 또는 모듈 중 하나 BLE 디버깅을 사용하는 경우"비트와"를 사용할 때 C 전처리 컴파일 예외가 발생합니다.
DebugMsg(ERROR| BLE ,"[ERROR-BLE]This should be seen",..);
DebugMsg(DBG | BLE ,"[DBG-BLE]This should not been logged",..);
마지막 메시지는 기록되어야한다
#define ALL 0xffffffff
#define ENABLED (ERROR | WARNING | INFO) //Enabled error messages which needs to be printed out.
//Error msg types
#define ERROR 0x1ul
#define WARNING 0x2ul
#define INFO 0x4ul
#define DBG 0x10ul
#define ENTER 0x20ul
#define STORAGE 0x40ul
#define BOND_MANAGER 0x80ul
#define ANCS_EVENT 0x100ul
#define NOTIF_EVENT 0x200ul
#define BLE_EVENT 0x400ul
#define ANCS_APP 0x800ul
#define BLE 0x1000ul
#define PERIPHERALS 0x2000ul
#define PWM 0x4000ul
#define LEDS 0x8000ul
#define DebugMsgStr(a,b) do { \
if (a & ENABLED) \
simple_uart_putstring(b); \ //print to console port
}while(0)
#define DebugMsg(a,...) do { \
if (a & ENABLED) {\
uint8_t data[100]; \
snprintf(data,100,"%x - %x - %x",a,ENABLED,a&ENABLED); \ //These two lines only used for debugging the debug_printf
simple_uart_putstring(data); \ //These two lines only used for debugging the debug_printf
snprintf(data,100,__VA_ARGS__); \
simple_uart_putstring(data); }\ //print to console port
}while(0)
내가 좋아하는 코드에서 메시지를 인쇄 할 수 있습니다. DBG 수준이 현재 사용할 수 없습니다에도 불구하고, 나는 다음과 같은 로그를 참조하십시오
이8010 - 7 - 8000[LEDS-DBG] effect_counter:2
1010 - 7 - 10[BLE-DBG] Timer Tick: 0x0000745d
그래서
0x8010 & 0x7 == 0x8000.
0x1010 & 0x7 == 0x10
이 일어날 수 있습니까? 나는 cortex-m0 nrf51822 Nordic 칩으로 컴파일하기 위해 arm-gcc를 사용하고있다. 또한 약간의 발췌 문장이 있지만, (& ENABLED)가 컴파일되지 않은 경우에는 특별한 것을 보지 못했습니다.
DebugMsg(DBG | BLE,"[BLE-DBG] Timer Tick: 0x%08x\r\n",currentTime);
R7 --> this probably contains a pointer to currentTime variable
0001587a: adds r1, r7, #0 -->r1 = r7
0001587c: adds r1, #12 -->r1 = r1+12
0001587e: ldr r2, [pc, #248] ; (0x15978 <ble_ancs_c_connection_moretriage_timer+272>)
00015880: ldr r3, [pc, #248] ; (0x1597c <ble_ancs_c_connection_moretriage_timer+276>)
00015882: movs r0, #7 --> r0 -ba 0x7
00015884: str r0, [sp, #0] --> save to stack
00015886: movs r0, #16 -->r0 ->ba 0x10
00015888: str r0, [sp, #4] --> save to stack
0001588a: adds r0, r1, #0 --> r0 = r1
0001588c: movs r1, #100 ; 0x64 --> r1 = 100
0001588e: bl 0x22c74 <snprintf>
00015892: adds r3, r7, #0
00015894: adds r3, #12
00015896: adds r0, r3, #0
00015898: bl 0x21a08 <simple_uart_putstring>
0001589c: ldr r3, [r7, #112] ; 0x70
0001589e: adds r1, r7, #0
000158a0: adds r1, #12
000158a2: ldr r2, [pc, #220] ; (0x15980 <ble_ancs_c_connection_moretriage_timer+280>)
000158a4: adds r0, r1, #0
000158a6: movs r1, #100 ; 0x64
000158a8: bl 0x22c74 <snprintf>
000158ac: adds r3, r7, #0
000158ae: adds r3, #12
000158b0: adds r0, r3, #0
000158b2: bl 0x21a08 <simple_uart_putstring>
미리 감사드립니다.
에 마르코을 변경해야합니다 '당신은 따라서, 0x8000ull & 0x7ull' 형'부호 long'입니다하지만 당신은 서명되지 않은 int''입니다'%의 x', 그것을 인쇄하고 여기에 정의되지 않은 동작이 있습니다. –
오랫동안 C를하지 못했지만,'Error','Warning' 또는'Info'를 #define하기 전에'Enabled' *를 정의 할 수 있습니까? –
@PeterM : 이것들은 단순히 텍스트로 대체 한 것입니다. 'Enabled'가 _used_가되기 전에'Error','Warning','Info'가 정의되어있는 한 아무런 문제가 없습니다. – TonyK