Skip to content

Commit afbd996

Browse files
committed
add print message for debug
define DEBUG to output information define PRINT_HCI_DATA to trace the exact content of the TX packet Signed-off-by: Francois Ramu <[email protected]>
1 parent 98f2414 commit afbd996

File tree

1 file changed

+50
-30
lines changed

1 file changed

+50
-30
lines changed

src/utility/HCISharedMemTransport.cpp

Lines changed: 50 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ volatile bool sys_resp;
2626
volatile bool acl_data; /* true : data acknowledged by the BLE */
2727
volatile bool data_available;
2828

29-
/* this one is for printing
30-
#define DEBUG */
29+
/* this one is for printing */
30+
#define DEBUG
31+
#define PRINT_HCI_DATA
32+
3133
/* this must be defined */
3234
#define CONFIG_DEBUG
3335

@@ -83,6 +85,20 @@ static void evt_received(TL_EvtPacket_t *hcievt)
8385
switch (hcievt->evtserial.type) {
8486
case TL_BLEEVT_PKT_TYPE:
8587

88+
#if defined(DEBUG)
89+
#if defined(PRINT_HCI_DATA)
90+
printf("RX<< BLE EVT : ");
91+
printf(" Type %#x", hcievt->evtserial.type);
92+
printf(" evt %#x", hcievt->evtserial.evt.evtcode);
93+
printf(" Len %#d", hcievt->evtserial.evt.plen);
94+
printf(" :");
95+
for (uint8_t i = 0; i < hcievt->evtserial.evt.plen; i++) {
96+
printf(" %02X", hcievt->evtserial.evt.payload[i]);
97+
}
98+
printf("\r\n");
99+
#endif /* PRINT_HCI_DATA */
100+
#endif /* DEBUG */
101+
86102
/* check the Rx event of complete the previous bd_addr opcode 0xfc0c */
87103
if ((hcievt->evtserial.evt.evtcode == TL_BLEEVT_CC_OPCODE) &&
88104
(hcievt->evtserial.evt.payload[0] == 0x01) &&
@@ -141,19 +157,18 @@ __enable_irq();
141157
default:
142158
// should not happen - let's block to check
143159
#if defined(DEBUG)
144-
printf("BLE TL evt_received, wrong type:%d", hcievt->evtserial.type);
160+
printf("BLE TL evt_received, wrong type:%d\r\n", hcievt->evtserial.type);
145161
#endif /* DEBUG */
146162
break;
147163
}
148164

149165
if (_write_index > BLE_MODULE_SHARED_MEM_BUFFER_SIZE) {
150166
#if defined(DEBUG)
151-
printf("Error: data read overflow");
167+
printf("Error: data read overflow\r\n");
152168
#endif /* DEBUG */
153169
data_available = true;
154170
}
155171

156-
157172
/* In case Event belongs to the Evt Pool we need to inform */
158173
if (((uint8_t *)hcievt >= EvtPool) && ((uint8_t *)hcievt < (EvtPool + POOL_SIZE))) {
159174
/* Free the message from shared memory */
@@ -661,10 +676,11 @@ static int bt_ipm_set_power(void)
661676
/* if event is a command complete event */
662677
if (*pMsg == HCI_CMD_CMPL_EVT) {
663678
/* "Command Complete Event Command" */
664-
#if (PRINT_HCI_DATA)
679+
#if defined(PRINT_HCI_DATA)
665680
for (uint8_t i = 0; i < 20; i++) {
666-
tr_debug(" %02X", *((uint8_t *)pMsg + i));
681+
printf(" %02X", *((uint8_t *)pMsg + i));
667682
}
683+
printf("\r\n");
668684
#endif
669685
/* parse parameters */
670686
pMsg += HCI_EVT_HDR_LEN;
@@ -839,7 +855,7 @@ static int bt_ipm_set_power(void)
839855
840856
default:
841857
#if defined(DEBUG)
842-
printf("Complete Event in reset seq with unknown opcode =0x%4X", opcode);
858+
printf("Complete Event in reset seq with unknown opcode =0x%4X\r\n", opcode);
843859
#endif /* DEBUG */
844860
break;
845861
}
@@ -853,7 +869,7 @@ static int bt_ipm_set_power(void)
853869
pMsg++; /* skip num packets */
854870
BSTREAM_TO_UINT16(opcode, pMsg);
855871
#if defined(DEBUG)
856-
printf("Command Status event, status:%d, opcode=0x%4X", status, opcode);
872+
printf("Command Status event, status:%d, opcode=0x%4X\r\n", status, opcode);
857873
#endif /* DEBUG */
858874
} else {
859875
/**
@@ -864,11 +880,11 @@ static int bt_ipm_set_power(void)
864880
pMsg += HCI_EVT_HDR_LEN;
865881
BSTREAM_TO_UINT16(opcode, pMsg);
866882
#if defined(DEBUG)
867-
printf("Vendor specific event, opcode=0x%4X", opcode);
883+
printf("Vendor specific event, opcode=0x%4X\r\n", opcode);
868884
#endif /* DEBUG */
869885
} else {
870886
#if defined(DEBUG)
871-
printf("Unknown event %d!", pMsg[0]);
887+
printf("Unknown event %d!\r\n", pMsg[0]);
872888
#endif /* DEBUG */
873889
}
874890
}
@@ -886,9 +902,7 @@ static int bt_ipm_set_power(void)
886902
// type 02 ACL DATA
887903
// type 03 SCO Voice (not supported)
888904
// type 04 event - uplink (not suported)
889-
#if defined(DEBUG)
890-
printf("mbox_write type:%d, len:%d", type, len);
891-
#endif /* DEBUG */
905+
892906
/* TO DO : MANAGE ACL DATA CASE in separate buffer */
893907
switch (type) {
894908
case 1://BLE command
@@ -898,23 +912,26 @@ static int bt_ipm_set_power(void)
898912
/* We're tracing here the command, after copy in shared mem but before
899913
* * M0 trigger. */
900914
#if defined(DEBUG)
901-
printf("TX>> BLE CMD");
902-
#endif /* DEBUG */
903-
#if (PRINT_HCI_DATA)
904-
/* Trace the buffer including Type (+1 on lngth) */
905-
tr_debug(" Type %#x", bleCmdBuf->cmdserial.type);
906-
tr_debug(" Cmd %#x", bleCmdBuf->cmdserial.cmd.cmdcode);
907-
tr_debug(" Len %#x", bleCmdBuf->cmdserial.cmd.plen);
915+
#if !defined(PRINT_HCI_DATA)
916+
printf("mbox_write type:%d, len:%d\r\n", type, len);
917+
#else /* Trace the buffer including Type (+1 on lngth) */
918+
printf("TX>> BLE CMD : ");
919+
printf(" Type %#x", bleCmdBuf->cmdserial.type);
920+
printf(" Cmd %#x", bleCmdBuf->cmdserial.cmd.cmdcode);
921+
printf(" Len %#d", bleCmdBuf->cmdserial.cmd.plen);
922+
printf(" :");
908923
for (uint8_t i = 0; i < bleCmdBuf->cmdserial.cmd.plen; i++) {
909-
tr_debug(" %02X", *(((uint8_t *)&bleCmdBuf->cmdserial.cmd.payload) + i));
924+
printf(" %02X", *(((uint8_t *)&bleCmdBuf->cmdserial.cmd.payload) + i));
910925
}
926+
printf("\r\n");
911927
#endif /* PRINT_HCI_DATA */
928+
#endif /* DEBUG */
912929
TL_BLE_SendCmd(NULL, 0); // unused parameters for now
913930
break;
914931
case 2://ACL DATA
915932
if (!acl_data) {
916933
#if defined(DEBUG)
917-
printf("ERROR: previous ACL message not ACK'd");
934+
printf("ERROR: previous ACL message not ACK'd\r\n");
918935
#endif /* DEBUG */
919936
/* return number of bytes sent, 0 in this error case */
920937
return 0;
@@ -923,13 +940,16 @@ static int bt_ipm_set_power(void)
923940
&((TL_AclDataPacket_t *)HciAclDataBuffer)->AclDataSerial, pData, len);
924941
TL_BLE_SendAclData(NULL, 0); // unused parameters for now
925942
#if defined(DEBUG)
926-
printf("TX>> BLE ACL");
927-
#endif /* DEBUG */
928-
#if PRINT_HCI_DATA
943+
#if !defined(PRINT_HCI_DATA)
944+
printf("mbox_write type:%d, len:%d \r\n", type, len);
945+
#else
946+
printf("TX>> BLE ACL : ");
929947
for (uint8_t i = 0; i < len + 1 + 8; i++) {
930-
tr_debug(" %02x", *(((uint8_t *) aclDataBuffer) + i));
948+
printf("%02x ", *(((uint8_t *) HciAclDataBuffer) + i));
931949
}
932-
#endif
950+
printf("\r\n");
951+
#endif /* PRINT_HCI_DATA */
952+
#endif /* DEBUG */
933953
break;
934954
}
935955
return len;
@@ -946,7 +966,7 @@ static void init_debug(void)
946966

947967
#if defined(CONFIG_DEBUG)
948968
#if defined(DEBUG)
949-
printf("init_debug ENABLED");
969+
printf("init_debug ENABLED\r\n");
950970
#endif /* DEBUG */
951971
/**
952972
* Keep debugger enabled while in any low power mode
@@ -961,7 +981,7 @@ static void init_debug(void)
961981

962982
#else
963983
#if defined(DEBUG)
964-
printf("init_debug DISABLED");
984+
printf("init_debug DISABLED\n\r");
965985
#endif /* DEBUG */
966986
GPIO_InitTypeDef gpio_config = {0};
967987

0 commit comments

Comments
 (0)