Merge pull request #45 from adafruit/develop

increase buffer depth to fix OTA issue with nrfConnect on iOS
This commit is contained in:
hathach 2019-02-15 23:04:38 +07:00 committed by GitHub
commit 2aefebaf00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 165 additions and 5 deletions

View File

@ -154,7 +154,7 @@ static void dfu_prepare_func_app_erase(uint32_t image_size)
nrf_nvmc_page_erase(DFU_BANK_0_REGION_START + i * CODE_PAGE_SIZE);
}
// simulate complete call
// invoke complete callback
pstorage_callback_handler(&m_storage_handle_app, PSTORAGE_CLEAR_OP_CODE, NRF_SUCCESS, NULL, 0);
}
}

View File

@ -736,6 +736,11 @@ static void on_ble_evt(ble_evt_t * p_ble_evt)
uint32_t err_code;
ble_gatts_rw_authorize_reply_params_t auth_reply;
#ifdef CFG_DEBUG
extern const char* dbg_ble_event_str(uint16_t evt_id);
ADALOG("BLE", dbg_ble_event_str(p_ble_evt->header.evt_id));
#endif
switch (p_ble_evt->header.evt_id)
{
case BLE_GAP_EVT_CONNECTED:
@ -896,6 +901,7 @@ static void on_ble_evt(ble_evt_t * p_ble_evt)
case BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST:
{
uint16_t att_mtu = MIN(p_ble_evt->evt.gatts_evt.params.exchange_mtu_request.client_rx_mtu, BLEGATT_ATT_MTU_MAX);
ADALOG("GAP", "ATT MTU is changed to %d", att_mtu);
APP_ERROR_CHECK( sd_ble_gatts_exchange_mtu_reply(m_conn_handle, att_mtu) );
}
break;
@ -1088,3 +1094,109 @@ uint32_t dfu_transport_ble_close()
return NRF_SUCCESS;
}
#ifdef CFG_DEBUG
typedef struct
{
uint32_t key;
void const * data;
}lookup_entry_t;
typedef struct
{
uint16_t count;
lookup_entry_t const* items;
} lookup_table_t;
void const * lookup_find(lookup_table_t const* p_table, uint32_t key)
{
for(uint16_t i=0; i<p_table->count; i++)
{
if (p_table->items[i].key == key) return p_table->items[i].data;
}
return NULL;
}
/*------------------------------------------------------------------*/
/* BLE Event String
*------------------------------------------------------------------*/
static lookup_entry_t const _strevt_lookup[] =
{
// BLE common: 0x01
{ .key = BLE_EVT_USER_MEM_REQUEST , .data= "BLE_EVT_USER_MEM_REQUEST" },
{ .key = BLE_EVT_USER_MEM_RELEASE , .data= "BLE_EVT_USER_MEM_RELEASE" },
// BLE Gap: 0x10
{ .key = BLE_GAP_EVT_CONNECTED , .data= "BLE_GAP_EVT_CONNECTED" },
{ .key = BLE_GAP_EVT_DISCONNECTED , .data= "BLE_GAP_EVT_DISCONNECTED" },
{ .key = BLE_GAP_EVT_CONN_PARAM_UPDATE , .data= "BLE_GAP_EVT_CONN_PARAM_UPDATE" },
{ .key = BLE_GAP_EVT_SEC_PARAMS_REQUEST , .data= "BLE_GAP_EVT_SEC_PARAMS_REQUEST" },
{ .key = BLE_GAP_EVT_SEC_INFO_REQUEST , .data= "BLE_GAP_EVT_SEC_INFO_REQUEST" },
{ .key = BLE_GAP_EVT_PASSKEY_DISPLAY , .data= "BLE_GAP_EVT_PASSKEY_DISPLAY" },
{ .key = BLE_GAP_EVT_KEY_PRESSED , .data= "BLE_GAP_EVT_KEY_PRESSED" },
{ .key = BLE_GAP_EVT_AUTH_KEY_REQUEST , .data= "BLE_GAP_EVT_AUTH_KEY_REQUEST" },
{ .key = BLE_GAP_EVT_LESC_DHKEY_REQUEST , .data= "BLE_GAP_EVT_LESC_DHKEY_REQUEST" },
{ .key = BLE_GAP_EVT_AUTH_STATUS , .data= "BLE_GAP_EVT_AUTH_STATUS" },
{ .key = BLE_GAP_EVT_CONN_SEC_UPDATE , .data= "BLE_GAP_EVT_CONN_SEC_UPDATE" },
{ .key = BLE_GAP_EVT_TIMEOUT , .data= "BLE_GAP_EVT_TIMEOUT" },
{ .key = BLE_GAP_EVT_RSSI_CHANGED , .data= "BLE_GAP_EVT_RSSI_CHANGED" },
{ .key = BLE_GAP_EVT_ADV_REPORT , .data= "BLE_GAP_EVT_ADV_REPORT" },
{ .key = BLE_GAP_EVT_SEC_REQUEST , .data= "BLE_GAP_EVT_SEC_REQUEST" },
{ .key = BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST , .data= "BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST" },
{ .key = BLE_GAP_EVT_SCAN_REQ_REPORT , .data= "BLE_GAP_EVT_SCAN_REQ_REPORT" },
{ .key = BLE_GAP_EVT_PHY_UPDATE_REQUEST , .data= "BLE_GAP_EVT_PHY_UPDATE_REQUEST" },
{ .key = BLE_GAP_EVT_PHY_UPDATE , .data= "BLE_GAP_EVT_PHY_UPDATE" },
{ .key = BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST , .data= "BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST" },
{ .key = BLE_GAP_EVT_DATA_LENGTH_UPDATE , .data= "BLE_GAP_EVT_DATA_LENGTH_UPDATE" },
{ .key = BLE_GAP_EVT_QOS_CHANNEL_SURVEY_REPORT , .data= "BLE_GAP_EVT_QOS_CHANNEL_SURVEY_REPORT" },
{ .key = BLE_GAP_EVT_ADV_SET_TERMINATED , .data= "BLE_GAP_EVT_ADV_SET_TERMINATED" },
// BLE Gattc: 0x30
{ .key = BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP , .data= "BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP" },
{ .key = BLE_GATTC_EVT_REL_DISC_RSP , .data= "BLE_GATTC_EVT_REL_DISC_RSP" },
{ .key = BLE_GATTC_EVT_CHAR_DISC_RSP , .data= "BLE_GATTC_EVT_CHAR_DISC_RSP" },
{ .key = BLE_GATTC_EVT_DESC_DISC_RSP , .data= "BLE_GATTC_EVT_DESC_DISC_RSP" },
{ .key = BLE_GATTC_EVT_ATTR_INFO_DISC_RSP , .data= "BLE_GATTC_EVT_ATTR_INFO_DISC_RSP" },
{ .key = BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP , .data= "BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP" },
{ .key = BLE_GATTC_EVT_READ_RSP , .data= "BLE_GATTC_EVT_READ_RSP" },
{ .key = BLE_GATTC_EVT_CHAR_VALS_READ_RSP , .data= "BLE_GATTC_EVT_CHAR_VALS_READ_RSP" },
{ .key = BLE_GATTC_EVT_WRITE_RSP , .data= "BLE_GATTC_EVT_WRITE_RSP" },
{ .key = BLE_GATTC_EVT_HVX , .data= "BLE_GATTC_EVT_HVX" },
{ .key = BLE_GATTC_EVT_EXCHANGE_MTU_RSP , .data= "BLE_GATTC_EVT_EXCHANGE_MTU_RSP" },
{ .key = BLE_GATTC_EVT_TIMEOUT , .data= "BLE_GATTC_EVT_TIMEOUT" },
{ .key = BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE , .data= "BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE" },
// BLE Gatts: 0x50
{ .key = BLE_GATTS_EVT_WRITE , .data= "BLE_GATTS_EVT_WRITE" },
{ .key = BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST , .data= "BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST" },
{ .key = BLE_GATTS_EVT_SYS_ATTR_MISSING , .data= "BLE_GATTS_EVT_SYS_ATTR_MISSING" },
{ .key = BLE_GATTS_EVT_HVC , .data= "BLE_GATTS_EVT_HVC" },
{ .key = BLE_GATTS_EVT_SC_CONFIRM , .data= "BLE_GATTS_EVT_SC_CONFIRM" },
{ .key = BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST , .data= "BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST" },
{ .key = BLE_GATTS_EVT_TIMEOUT , .data= "BLE_GATTS_EVT_TIMEOUT" },
{ .key = BLE_GATTS_EVT_HVN_TX_COMPLETE , .data= "BLE_GATTS_EVT_HVN_TX_COMPLETE" },
};
lookup_table_t const _strevt_table =
{
.count = arrcount(_strevt_lookup),
.items = _strevt_lookup
};
const char* dbg_ble_event_str(uint16_t evt_id)
{
const char * str = (const char *) lookup_find(&_strevt_table, evt_id);
static char unknown_str[7] = {0};
if ( str == NULL )
{
sprintf(unknown_str, "0x%04X", evt_id);
str = unknown_str;
}
return str;
}
#endif

View File

@ -253,9 +253,9 @@ void led_state(uint32_t state)
case STATE_BLE_CONNECTED:
new_rgb_color = 0x0000ff;
#ifdef LED_SECONDARY_PIN
secondary_cycle_length = 500;
secondary_cycle_length = 3000;
#else
primary_cycle_length = 500;
primary_cycle_length = 3000;
#endif
break;

View File

@ -96,4 +96,50 @@ static inline bool button_pressed(uint32_t pin)
bool is_ota(void);
//--------------------------------------------------------------------+
// DEBUG
//--------------------------------------------------------------------+
//#define CFG_DEBUG
#ifdef CFG_DEBUG
#include <stdio.h>
#define PRINT_LOCATION() printf("%s: %d:\n", __PRETTY_FUNCTION__, __LINE__)
#define PRINT_MESS(x) printf("%s: %d: %s \n" , __FUNCTION__, __LINE__, (char*)(x))
#define PRTNT_HEAP() if (CFG_DEBUG == 3) printf("\n%s: %d: Heap free: %d\n", __FUNCTION__, __LINE__, util_heap_get_free_size())
#define PRINT_STR(x) printf("%s: %d: " #x " = %s\n" , __FUNCTION__, __LINE__, (char*)(x) )
#define PRINT_INT(x) printf("%s: %d: " #x " = %ld\n" , __FUNCTION__, __LINE__, (uint32_t) (x) )
#define PRINT_HEX(x) printf("%s: %d: " #x " = 0x%X\n" , __FUNCTION__, __LINE__, (uint32_t) (x) )
#define PRINT_BUFFER(buf, n) \
do {\
uint8_t const* p8 = (uint8_t const*) (buf);\
printf(#buf ": ");\
for(uint32_t i=0; i<(n); i++) printf("%x ", p8[i]);\
printf("\n");\
}while(0)
#define ADALOG(tag, ...) \
do { \
if ( tag ) printf("[%s] ", tag);\
printf(__VA_ARGS__);\
printf("\n");\
}while(0)
#else
#define PRINT_LOCATION()
#define PRINT_MESS(x)
#define PRTNT_HEAP()
#define PRINT_STR(x)
#define PRINT_INT(x)
#define PRINT_HEX(x)
#define PRINT_BUFFER(buf, n)
#define ADALOG(...)
#endif
#endif

View File

@ -64,9 +64,9 @@
// <e> HCI_MEM_POOL_ENABLED - hci_mem_pool - memory pool implementation used by HCI
//==========================================================
#define HCI_MEM_POOL_ENABLED 1
#define HCI_TX_BUF_SIZE 600
#define HCI_TX_BUF_SIZE 600 // not used
#define HCI_RX_BUF_SIZE 600
#define HCI_RX_BUF_QUEUE_SIZE 4
#define HCI_RX_BUF_QUEUE_SIZE 8 // must be power of 2
//==========================================================
// <e> UART_ENABLED - nrf_drv_uart - UART/UARTE peripheral driver

View File

@ -375,10 +375,12 @@
<configuration
Name="Feather52840"
c_preprocessor_definitions="NRF52840_XXAA;MK_DIS_FIRMWARE=&quot;s140 6.1.1 r0&quot;;S140;BOARD_FEATHER_NRF52840_EXPRESS;BOARD_HEADER_FILE=&quot;feather_nrf52840_express.h&quot;"
gcc_optimization_level="Debug"
linker_memory_map_file="nRF52840_xxAA_MemoryMap.xml" />
<configuration
Name="Feather52832"
c_preprocessor_definitions="NRF52832_XXAA;MK_DIS_FIRMWARE=&quot;s132 6.1.1 r0&quot;;S132;BOARD_FEATHER_NRF52832;BOARD_HEADER_FILE=&quot;feather_nrf52832.h&quot;"
gcc_optimization_level="Debug"
linker_memory_map_file="nRF52832_xxAA_MemoryMap.xml" />
<configuration
Name="PCA10056"