Skip to content

Commit 7fbe44c

Browse files
committed
update debug facilities
1 parent 1196ba5 commit 7fbe44c

File tree

6 files changed

+222
-5
lines changed

6 files changed

+222
-5
lines changed

cores/nRF5/common_func.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,18 @@
8383
//--------------------------------------------------------------------+
8484
// DEBUG HELPER
8585
//--------------------------------------------------------------------+
86-
#if CFG_DEBUG == 3
86+
#if CFG_DEBUG == 2
8787
#define malloc_named( name, size ) ({ printf("[malloc] %s : %d\r\n", name, size); malloc(size); })
8888
#else
8989
#define malloc_named( name, size ) malloc ( size )
9090
#endif
9191

9292
int cprintf(const char * format, ...);
93+
94+
#if CFG_DEBUG
95+
9396
#define PRINT_LOCATION() cprintf("%s: %d:\n", __PRETTY_FUNCTION__, __LINE__)
94-
#define PRINT_MESS(x) cprintf("%s: %d: " x " \n" , __PRETTY_FUNCTION__, __LINE__)
97+
#define PRINT_MESS(x) cprintf("%s: %d: %s \n" , __PRETTY_FUNCTION__, __LINE__, (char*)(x))
9598
#define PRTNT_HEAP() if (CFG_DEBUG == 3) cprintf("\n%s: %d: Heap free: %d\n", __PRETTY_FUNCTION__, __LINE__, util_heap_get_free_size())
9699
#define PRINT_STR(x) cprintf("%s: %d: " #x " = %s\n" , __PRETTY_FUNCTION__, __LINE__, (char*)(x) )
97100
#define PRINT_INT(x) cprintf("%s: %d: " #x " = %ld\n" , __PRETTY_FUNCTION__, __LINE__, (uint32_t) (x) )
@@ -112,6 +115,18 @@ int cprintf(const char * format, ...);
112115
Serial.println();\
113116
}while(0)
114117

118+
#else
119+
120+
#define PRINT_LOCATION()
121+
#define PRINT_MESS(x)
122+
#define PRTNT_HEAP()
123+
#define PRINT_STR(x)
124+
#define PRINT_INT(x)
125+
#define PRINT_HEX(x)
126+
#define PRINT_BUFFER(buf, n)
127+
128+
#endif
129+
115130
//--------------------------------------------------------------------+
116131
// INLINE FUNCTION
117132
//--------------------------------------------------------------------+

cores/nRF5/debug.cpp

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,86 @@ void dbgMemInfo(void)
150150
Serial.println(buf);
151151
rtos_free(buf);
152152
}
153+
154+
155+
/*------------------------------------------------------------------*/
156+
/*
157+
*------------------------------------------------------------------*/
158+
159+
#if CFG_DEBUG
160+
161+
#include "ble.h"
162+
#include "ble_hci.h"
163+
164+
// Common BLE Event base
165+
static const char* _base_evt_str[] =
166+
{
167+
"BLE_EVT_TX_COMPLETE" ,
168+
"BLE_EVT_USER_MEM_REQUEST" ,
169+
"BLE_EVT_USER_MEM_RELEASE" ,
170+
};
171+
172+
static const char* _gap_evt_str[] =
173+
{
174+
"BLE_GAP_EVT_CONNECTED" ,
175+
"BLE_GAP_EVT_DISCONNECTED" ,
176+
"BLE_GAP_EVT_CONN_PARAM_UPDATE" ,
177+
"BLE_GAP_EVT_SEC_PARAMS_REQUEST" ,
178+
"BLE_GAP_EVT_SEC_INFO_REQUEST" ,
179+
"BLE_GAP_EVT_PASSKEY_DISPLAY" ,
180+
"BLE_GAP_EVT_KEY_PRESSED" ,
181+
"BLE_GAP_EVT_AUTH_KEY_REQUEST" ,
182+
"BLE_GAP_EVT_LESC_DHKEY_REQUEST" ,
183+
"BLE_GAP_EVT_AUTH_STATUS" ,
184+
"BLE_GAP_EVT_CONN_SEC_UPDATE" ,
185+
"BLE_GAP_EVT_TIMEOUT" ,
186+
"BLE_GAP_EVT_RSSI_CHANGED" ,
187+
"BLE_GAP_EVT_ADV_REPORT" ,
188+
"BLE_GAP_EVT_SEC_REQUEST" ,
189+
"BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST" ,
190+
"BLE_GAP_EVT_SCAN_REQ_REPORT" ,
191+
};
192+
193+
// GATTC Event
194+
static const char* _gattc_evt_str[] =
195+
{
196+
"BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP" ,
197+
"BLE_GATTC_EVT_REL_DISC_RSP" ,
198+
"BLE_GATTC_EVT_CHAR_DISC_RSP" ,
199+
"BLE_GATTC_EVT_DESC_DISC_RSP" ,
200+
"BLE_GATTC_EVT_ATTR_INFO_DISC_RSP" ,
201+
"BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP" ,
202+
"BLE_GATTC_EVT_READ_RSP" ,
203+
"BLE_GATTC_EVT_CHAR_VALS_READ_RSP" ,
204+
"BLE_GATTC_EVT_WRITE_RSP" ,
205+
"BLE_GATTC_EVT_HVX" ,
206+
"BLE_GATTC_EVT_TIMEOUT"
207+
};
208+
209+
// GATTS Event
210+
static const char* _gatts_evt_str[] =
211+
{
212+
"BLE_GATTS_EVT_WRITE" ,
213+
"BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST" ,
214+
"BLE_GATTS_EVT_SYS_ATTR_MISSING" ,
215+
"BLE_GATTS_EVT_HVC" ,
216+
"BLE_GATTS_EVT_SC_CONFIRM" ,
217+
"BLE_GATTS_EVT_TIMEOUT" ,
218+
};
219+
220+
const char* dbg_ble_event_str(uint16_t evt_id)
221+
{
222+
if ( is_within(BLE_EVT_BASE, evt_id, BLE_EVT_LAST) )
223+
return _base_evt_str[evt_id-BLE_EVT_BASE];
224+
else if ( is_within(BLE_GAP_EVT_BASE, evt_id, BLE_GAP_EVT_LAST) )
225+
return _gap_evt_str[evt_id-BLE_GAP_EVT_BASE];
226+
else if ( is_within(BLE_GATTC_EVT_BASE, evt_id, BLE_GATTC_EVT_LAST) )
227+
return _gattc_evt_str[evt_id-BLE_GATTC_EVT_BASE];
228+
else if ( is_within(BLE_GATTS_EVT_BASE, evt_id, BLE_GATTS_EVT_LAST) )
229+
return _gatts_evt_str[evt_id-BLE_GATTS_EVT_BASE];
230+
else
231+
return NULL;
232+
}
233+
234+
#endif
235+

cores/nRF5/debug.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939

4040
#include <Arduino.h>
4141

42+
#if CFG_DEBUG
43+
const char* dbg_ble_event_str(uint16_t evt_id);
44+
#endif
45+
4246
int dbgHeapTotal(void);
4347
int dbgHeapUsed(void);
4448

cores/nRF5/utility/utilities.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**************************************************************************/
2+
/*!
3+
@file utilities.c
4+
@author hathach
5+
6+
@section LICENSE
7+
8+
Software License Agreement (BSD License)
9+
10+
Copyright (c) 2017, Adafruit Industries (adafruit.com)
11+
All rights reserved.
12+
13+
Redistribution and use in source and binary forms, with or without
14+
modification, are permitted provided that the following conditions are met:
15+
1. Redistributions of source code must retain the above copyright
16+
notice, this list of conditions and the following disclaimer.
17+
2. Redistributions in binary form must reproduce the above copyright
18+
notice, this list of conditions and the following disclaimer in the
19+
documentation and/or other materials provided with the distribution.
20+
3. Neither the name of the copyright holders nor the
21+
names of its contributors may be used to endorse or promote products
22+
derived from this software without specific prior written permission.
23+
24+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
25+
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
28+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34+
*/
35+
/**************************************************************************/
36+
37+
#include "utilities.h"
38+
39+
/******************************************************************************/
40+
/*!
41+
@brief Find the corresponding data from the key
42+
@param
43+
*/
44+
/******************************************************************************/
45+
void const * lookup_find(lookup_table_t const* p_table, uint32_t key)
46+
{
47+
for(uint16_t i=0; i<p_table->count; i++)
48+
{
49+
if (p_table->items[i].key == key) return p_table->items[i].data;
50+
}
51+
52+
return NULL;
53+
}

cores/nRF5/utility/utilities.h

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**************************************************************************/
2+
/*!
3+
@file utilities.h
4+
@author hathach
5+
6+
@section LICENSE
7+
8+
Software License Agreement (BSD License)
9+
10+
Copyright (c) 2017, Adafruit Industries (adafruit.com)
11+
All rights reserved.
12+
13+
Redistribution and use in source and binary forms, with or without
14+
modification, are permitted provided that the following conditions are met:
15+
1. Redistributions of source code must retain the above copyright
16+
notice, this list of conditions and the following disclaimer.
17+
2. Redistributions in binary form must reproduce the above copyright
18+
notice, this list of conditions and the following disclaimer in the
19+
documentation and/or other materials provided with the distribution.
20+
3. Neither the name of the copyright holders nor the
21+
names of its contributors may be used to endorse or promote products
22+
derived from this software without specific prior written permission.
23+
24+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
25+
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
28+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34+
*/
35+
/**************************************************************************/
36+
#ifndef UTILITIES_H_
37+
#define UTILITIES_H_
38+
39+
#include <Arduino.h>
40+
41+
typedef struct
42+
{
43+
uint32_t key;
44+
void const * data;
45+
}lookup_entry_t;
46+
47+
typedef struct
48+
{
49+
uint16_t count;
50+
uint16_t data_size;
51+
52+
lookup_entry_t const* items;
53+
} lookup_table_t;
54+
55+
void const * lookup_find(lookup_table_t const* p_table, uint32_t key);
56+
57+
#endif /* UTILITIES_H_ */

libraries/Bluefruit52Lib/src/bluefruit.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,13 @@ void AdafruitBluefruit::_poll(void)
600600
}
601601
else if( ERROR_NONE == err)
602602
{
603+
#if CFG_DEBUG
604+
Serial.print("[BLE]: ");
605+
if ( dbg_ble_event_str(evt->header.evt_id) ) Serial.print(dbg_ble_event_str(evt->header.evt_id));
606+
else Serial.printf("0x04X", evt->header.evt_id);
607+
Serial.println();
608+
#endif
609+
603610
switch ( evt->header.evt_id )
604611
{
605612
case BLE_GAP_EVT_CONNECTED:
@@ -770,9 +777,7 @@ void AdafruitBluefruit::_poll(void)
770777
break;
771778

772779

773-
default:
774-
//PRINT_HEX(evt->header.evt_id);
775-
break;
780+
default: break;
776781
}
777782

778783
// Central Event Handler

0 commit comments

Comments
 (0)