add le_gap.c / le_adv.c
This commit is contained in:
@@ -98,6 +98,14 @@ extern "C"
|
||||
// This setting configures how Stack events are dispatched to the application.
|
||||
#define NRF_SDH_DISPATCH_MODEL 2 /* SoftDevice events are to be fetched manually. */
|
||||
|
||||
// BLE Observers priorities - Invididual priorities
|
||||
#define BLE_ADV_BLE_OBSERVER_PRIO 1
|
||||
#define BLE_CONN_PARAMS_BLE_OBSERVER_PRIO 1
|
||||
#define BLE_CONN_STATE_BLE_OBSERVER_PRIO 0
|
||||
|
||||
// Enable Advertising module
|
||||
#define BLE_ADVERTISING_ENABLED 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|VisualGDB'">
|
||||
<ClCompile>
|
||||
<CLanguageStandard>GNU99</CLanguageStandard>
|
||||
<AdditionalIncludeDirectories>.;../bmd380_sdk/components/softdevice/s140/headers;../bmd380_sdk/components/softdevice/s140/headers/nrf52;../bmd380_sdk/external/segger_rtt;../bmd380_sdk/components/libraries/log;../bmd380_sdk/components/libraries/log/src;../bmd380_sdk/components/libraries/memobj;../bmd380_sdk/components/libraries/ringbuf;../bmd380_sdk/components/libraries/atomic;../bmd380_sdk/components/libraries/balloc;../bmd380_sdk/external/freertos/portable/CMSIS/nrf52;../bmd380_sdk/external/freertos/portable/GCC/nrf52;../bmd380_sdk/integration/nrfx;../bmd380_sdk/integration/nrfx/legacy;../bmd380_sdk/components/libraries/experimental_section_vars;../bmd380_sdk/components/libraries/strerror;../bmd380_sdk/external/freertos/source/include;../bmd380_sdk/components/softdevice/common;%(ClCompile.AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>.;../bmd380_sdk/components/softdevice/s140/headers;../bmd380_sdk/components/softdevice/s140/headers/nrf52;../bmd380_sdk/external/segger_rtt;../bmd380_sdk/components/libraries/log;../bmd380_sdk/components/libraries/log/src;../bmd380_sdk/components/libraries/memobj;../bmd380_sdk/components/libraries/ringbuf;../bmd380_sdk/components/libraries/atomic;../bmd380_sdk/components/libraries/balloc;../bmd380_sdk/external/freertos/portable/CMSIS/nrf52;../bmd380_sdk/external/freertos/portable/GCC/nrf52;../bmd380_sdk/integration/nrfx;../bmd380_sdk/integration/nrfx/legacy;../bmd380_sdk/components/libraries/experimental_section_vars;../bmd380_sdk/components/libraries/strerror;../bmd380_sdk/external/freertos/source/include;../bmd380_sdk/components/softdevice/common;../bmd380_sdk/components/ble/common;../bmd380_sdk/components/ble/ble_advertising;../bmd380_sdk/components/libraries/atomic_flags;../bmd380_sdk/components/ble/ble_db_discovery;../bmd380_sdk/components/ble/ble_dtm;../bmd380_sdk/components/ble/ble_link_ctx_manager;../bmd380_sdk/components/ble/ble_racp;../bmd380_sdk/components/ble/ble_radio_notification;../bmd380_sdk/components/ble/ble_services/ble_ancs_c;../bmd380_sdk/components/ble/ble_services/ble_ans_c;../bmd380_sdk/components/ble/ble_services/ble_bas;../bmd380_sdk/components/ble/ble_services/ble_bas_c;../bmd380_sdk/components/ble/ble_services/ble_bps;../bmd380_sdk/components/ble/ble_services/ble_cscs;../bmd380_sdk/components/ble/ble_services/ble_cts_c;../bmd380_sdk/components/ble/ble_services/ble_dfu;../bmd380_sdk/components/ble/ble_services/ble_dis;../bmd380_sdk/components/ble/ble_services/ble_dis_c;../bmd380_sdk/components/ble/ble_services/ble_escs;../bmd380_sdk/components/ble/ble_services/ble_gls;../bmd380_sdk/components/ble/ble_services/ble_hids;../bmd380_sdk/components/ble/ble_services/ble_hrs;../bmd380_sdk/components/ble/ble_services/ble_hrs_c;../bmd380_sdk/components/ble/ble_services/ble_hts;../bmd380_sdk/components/ble/ble_services/ble_ias;../bmd380_sdk/components/ble/ble_services/ble_ias_c;../bmd380_sdk/components/ble/ble_services/ble_ipsp;../bmd380_sdk/components/ble/ble_services/ble_lbs;../bmd380_sdk/components/ble/ble_services/ble_lbs_c;../bmd380_sdk/components/ble/ble_services/ble_lls;../bmd380_sdk/components/ble/ble_services/ble_nus;../bmd380_sdk/components/ble/ble_services/ble_nus_c;../bmd380_sdk/components/ble/ble_services/ble_rscs;../bmd380_sdk/components/ble/ble_services/ble_rscs_c;../bmd380_sdk/components/ble/ble_services/ble_tps;../bmd380_sdk/components/ble/ble_services/eddystone;../bmd380_sdk/components/ble/ble_services/experimental_ble_lns;../bmd380_sdk/components/ble/ble_services/experimental_ble_ots;../bmd380_sdk/components/ble/ble_services/experimental_gatts_c;../bmd380_sdk/components/ble/ble_services/experimental_nrf_ble_cgms;../bmd380_sdk/components/ble/ble_services/experimental_nrf_ble_ots_c;../bmd380_sdk/components/ble/ble_services/nrf_ble_bms;../bmd380_sdk/components/ble/nrf_ble_gatt;../bmd380_sdk/components/ble/nrf_ble_gq;../bmd380_sdk/components/ble/nrf_ble_qwr;../bmd380_sdk/components/ble/nrf_ble_scan;../bmd380_sdk/components/ble/peer_manager;%(ClCompile.AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>DEBUG=1;USE_APP_CONFIG=1;%(ClCompile.PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalOptions />
|
||||
<CPPLanguageStandard />
|
||||
@@ -75,6 +75,7 @@
|
||||
</ImportGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\bmd380_sdk\components\libraries\atomic\nrf_atomic.c" />
|
||||
<ClCompile Include="..\bmd380_sdk\components\libraries\atomic_flags\nrf_atflags.c" />
|
||||
<ClCompile Include="..\bmd380_sdk\components\libraries\balloc\nrf_balloc.c" />
|
||||
<ClCompile Include="..\bmd380_sdk\components\libraries\experimental_section_vars\nrf_section_iter.c" />
|
||||
<ClCompile Include="..\bmd380_sdk\components\libraries\log\src\nrf_log_backend_flash.c" />
|
||||
@@ -158,6 +159,8 @@
|
||||
<ClCompile Include="..\bmd380_sdk\integration\nrfx\legacy\nrf_drv_uart.c">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|VisualGDB'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="le_adv.c" />
|
||||
<ClCompile Include="le_gap.c" />
|
||||
<ClCompile Include="main.c" />
|
||||
<None Include="nRF52811_XXAA_s140.lds" />
|
||||
<None Include="nRF52840_XXAA_S140_reserve.lds" />
|
||||
@@ -221,6 +224,7 @@
|
||||
<ClInclude Include="..\bmd380_sdk\components\libraries\atomic\nrf_atomic.h" />
|
||||
<ClInclude Include="..\bmd380_sdk\components\libraries\atomic\nrf_atomic_internal.h" />
|
||||
<ClInclude Include="..\bmd380_sdk\components\libraries\atomic\nrf_atomic_sanity_check.h" />
|
||||
<ClInclude Include="..\bmd380_sdk\components\libraries\atomic_flags\nrf_atflags.h" />
|
||||
<ClInclude Include="..\bmd380_sdk\components\libraries\balloc\nrf_balloc.h" />
|
||||
<ClInclude Include="..\bmd380_sdk\components\libraries\experimental_section_vars\nrf_section.h" />
|
||||
<ClInclude Include="..\bmd380_sdk\components\libraries\experimental_section_vars\nrf_section_iter.h" />
|
||||
@@ -541,5 +545,18 @@
|
||||
<None Include="bmd380_peripheral-Debug.vgdbsettings" />
|
||||
<None Include="bmd380_peripheral-Release.vgdbsettings" />
|
||||
<None Include="nrf5x.xml" />
|
||||
<ClCompile Include="..\bmd380_sdk\components\ble\ble_advertising\ble_advertising.c" />
|
||||
<ClCompile Include="..\bmd380_sdk\components\ble\common\ble_advdata.c" />
|
||||
<ClCompile Include="..\bmd380_sdk\components\ble\common\ble_conn_params.c" />
|
||||
<ClCompile Include="..\bmd380_sdk\components\ble\common\ble_conn_state.c" />
|
||||
<ClCompile Include="..\bmd380_sdk\components\ble\common\ble_srv_common.c" />
|
||||
<ClInclude Include="..\bmd380_sdk\components\ble\ble_advertising\ble_advertising.h" />
|
||||
<ClInclude Include="..\bmd380_sdk\components\ble\common\ble_advdata.h" />
|
||||
<ClInclude Include="..\bmd380_sdk\components\ble\common\ble_conn_params.h" />
|
||||
<ClInclude Include="..\bmd380_sdk\components\ble\common\ble_conn_state.h" />
|
||||
<ClInclude Include="..\bmd380_sdk\components\ble\common\ble_date_time.h" />
|
||||
<ClInclude Include="..\bmd380_sdk\components\ble\common\ble_gatt_db.h" />
|
||||
<ClInclude Include="..\bmd380_sdk\components\ble\common\ble_sensor_location.h" />
|
||||
<ClInclude Include="..\bmd380_sdk\components\ble\common\ble_srv_common.h" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -214,6 +214,24 @@
|
||||
<Filter Include="Header files\softdevice\common">
|
||||
<UniqueIdentifier>{c7ac68a2-299c-474c-885e-d429e8e5a452}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source files\ble">
|
||||
<UniqueIdentifier>{bc9e84c6-e1eb-4f92-a953-156157313736}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source files\ble\ble_advertising">
|
||||
<UniqueIdentifier>{e343d3fa-a2ab-4468-a86f-85ab5bf8691f}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source files\ble\common">
|
||||
<UniqueIdentifier>{6796de8c-d113-49ae-b410-1ba146602aaa}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Header files\ble">
|
||||
<UniqueIdentifier>{e35e5681-0697-4cac-a093-e56c06a1b735}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Header files\ble\ble_advertising">
|
||||
<UniqueIdentifier>{7f288a24-1e47-49e6-9a8a-907e9c84ca1d}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Header files\ble\common">
|
||||
<UniqueIdentifier>{defffc43-551c-4791-967b-7d0aee507516}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.c">
|
||||
@@ -1257,6 +1275,54 @@
|
||||
<ClCompile Include="..\bmd380_sdk\components\softdevice\common\nrf_sdh_soc.c">
|
||||
<Filter>Source files\softdevice\common</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="le_adv.c">
|
||||
<Filter>Source files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="le_gap.c">
|
||||
<Filter>Source files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\bmd380_sdk\components\ble\ble_advertising\ble_advertising.c">
|
||||
<Filter>Source files\ble\ble_advertising</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\bmd380_sdk\components\ble\common\ble_advdata.c">
|
||||
<Filter>Source files\ble\common</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\bmd380_sdk\components\ble\common\ble_conn_params.c">
|
||||
<Filter>Source files\ble\common</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\bmd380_sdk\components\ble\common\ble_conn_state.c">
|
||||
<Filter>Source files\ble\common</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\bmd380_sdk\components\ble\common\ble_srv_common.c">
|
||||
<Filter>Source files\ble\common</Filter>
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\bmd380_sdk\components\ble\ble_advertising\ble_advertising.h">
|
||||
<Filter>Header files\ble\ble_advertising</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\bmd380_sdk\components\ble\common\ble_advdata.h">
|
||||
<Filter>Header files\ble\common</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\bmd380_sdk\components\ble\common\ble_conn_params.h">
|
||||
<Filter>Header files\ble\common</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\bmd380_sdk\components\ble\common\ble_conn_state.h">
|
||||
<Filter>Header files\ble\common</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\bmd380_sdk\components\ble\common\ble_date_time.h">
|
||||
<Filter>Header files\ble\common</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\bmd380_sdk\components\ble\common\ble_gatt_db.h">
|
||||
<Filter>Header files\ble\common</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\bmd380_sdk\components\ble\common\ble_sensor_location.h">
|
||||
<Filter>Header files\ble\common</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\bmd380_sdk\components\ble\common\ble_srv_common.h">
|
||||
<Filter>Header files\ble\common</Filter>
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\bmd380_sdk\components\libraries\atomic_flags\nrf_atflags.c">
|
||||
<Filter>Source files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="nRF52840_XXAA_S140_reserve.lds">
|
||||
@@ -1507,6 +1573,9 @@
|
||||
<ClInclude Include="..\bmd380_sdk\components\softdevice\common\nrf_sdh_soc.h">
|
||||
<Filter>Header files\softdevice\common</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\bmd380_sdk\components\libraries\atomic_flags\nrf_atflags.h">
|
||||
<Filter>Header files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="..\bmd380_sdk\external\segger_rtt\license\license.txt">
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "app_config.h"
|
||||
#include "apply_old_config.h"
|
||||
#include "sdk_config.h"
|
||||
|
||||
#include "nrf_log.h"
|
||||
#include "nrf_log_ctrl.h"
|
||||
#include "nrf_log_default_backends.h"
|
||||
|
||||
#include "nrf_delay.h"
|
||||
#include "nrf_gpio.h"
|
||||
|
||||
#include "nrf_sdh.h"
|
||||
#include "nrf_sdh_ble.h"
|
||||
#include "nrf_sdh_freertos.h"
|
||||
|
||||
#include "ble_advdata.h"
|
||||
#include "ble_advertising.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
BLE_ADVERTISING_DEF(m_advertising); /**< Advertising module instance. */
|
||||
|
||||
static void le_adv_evt_handler(ble_adv_evt_t const adv_evt)
|
||||
{
|
||||
switch (adv_evt)
|
||||
{
|
||||
case BLE_ADV_EVT_IDLE:
|
||||
case BLE_ADV_EVT_DIRECTED_HIGH_DUTY:
|
||||
case BLE_ADV_EVT_DIRECTED:
|
||||
case BLE_ADV_EVT_FAST:
|
||||
case BLE_ADV_EVT_SLOW:
|
||||
case BLE_ADV_EVT_FAST_WHITELIST:
|
||||
case BLE_ADV_EVT_SLOW_WHITELIST:
|
||||
case BLE_ADV_EVT_WHITELIST_REQUEST:
|
||||
case BLE_ADV_EVT_PEER_ADDR_REQUEST:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void le_adv_error_handler(uint32_t nrf_error)
|
||||
{
|
||||
// TODO...
|
||||
__BKPT(255);
|
||||
}
|
||||
|
||||
void le_adv_init(uint8_t ble_conn_cfg_tag)
|
||||
{
|
||||
uint32_t err_code;
|
||||
uint8_t adv_flags;
|
||||
ble_advertising_init_t init;
|
||||
|
||||
memset(&init, 0, sizeof(init));
|
||||
|
||||
adv_flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
|
||||
init.advdata.name_type = BLE_ADVDATA_FULL_NAME;
|
||||
init.advdata.include_appearance = true;
|
||||
init.advdata.flags = adv_flags;
|
||||
|
||||
init.config.ble_adv_whitelist_enabled = false;
|
||||
init.config.ble_adv_directed_high_duty_enabled = true;
|
||||
init.config.ble_adv_directed_enabled = true;
|
||||
init.config.ble_adv_directed_interval = MSEC_TO_UNITS(20, UNIT_0_625_MS);
|
||||
init.config.ble_adv_directed_timeout = MSEC_TO_UNITS(1000, UNIT_10_MS);
|
||||
init.config.ble_adv_fast_enabled = true;
|
||||
init.config.ble_adv_fast_interval = MSEC_TO_UNITS(40, UNIT_0_625_MS);
|
||||
init.config.ble_adv_fast_timeout = MSEC_TO_UNITS(3000, UNIT_10_MS);
|
||||
init.config.ble_adv_slow_enabled = true;
|
||||
init.config.ble_adv_slow_interval = MSEC_TO_UNITS(500, UNIT_0_625_MS);
|
||||
init.config.ble_adv_slow_timeout = MSEC_TO_UNITS(0, UNIT_10_MS);
|
||||
init.config.ble_adv_primary_phy = BLE_GAP_PHY_1MBPS;
|
||||
init.config.ble_adv_secondary_phy = BLE_GAP_PHY_1MBPS;
|
||||
|
||||
init.evt_handler = le_adv_evt_handler;
|
||||
init.error_handler = le_adv_error_handler;
|
||||
|
||||
err_code = ble_advertising_init(&m_advertising, &init);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
ble_advertising_conn_cfg_tag_set(&m_advertising, ble_conn_cfg_tag);
|
||||
|
||||
ret_code_t ret = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
|
||||
APP_ERROR_CHECK(ret);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "app_config.h"
|
||||
#include "apply_old_config.h"
|
||||
#include "sdk_config.h"
|
||||
|
||||
#include "nrf_sdh.h"
|
||||
#include "nrf_sdh_ble.h"
|
||||
|
||||
#include "app_error.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
void le_gap_init(const char *device_name, uint16_t usAppearance)
|
||||
{
|
||||
ret_code_t err_code;
|
||||
|
||||
ble_gap_conn_sec_mode_t sec_mode;
|
||||
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
|
||||
if (device_name != NULL)
|
||||
{
|
||||
// Set GAP device name
|
||||
err_code = sd_ble_gap_device_name_set(&sec_mode, (const uint8_t *)device_name, strlen(device_name));
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
|
||||
// Set GAP Appearance value
|
||||
err_code = sd_ble_gap_appearance_set(usAppearance);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
// Set GAP Peripheral Preferred Connection Parameters.
|
||||
ble_gap_conn_params_t gap_conn_params;
|
||||
memset(&gap_conn_params, 0, sizeof(gap_conn_params));
|
||||
gap_conn_params.min_conn_interval = MSEC_TO_UNITS(8, UNIT_1_25_MS); /**< Minimum connection interval (7.5 ms) */
|
||||
gap_conn_params.max_conn_interval = MSEC_TO_UNITS(40, UNIT_1_25_MS); /**< Maximum connection interval (40 ms). */
|
||||
gap_conn_params.slave_latency = 16; /**< Slave latency. */
|
||||
gap_conn_params.conn_sup_timeout = MSEC_TO_UNITS(5000, UNIT_10_MS); /**< Connection supervisory timeout (5000 ms). */
|
||||
|
||||
err_code = sd_ble_gap_ppcp_set(&gap_conn_params);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
@@ -103,6 +103,13 @@ int main(void)
|
||||
NRF_LOG_INFO("%s Build: %s %s", DEVICE_NAME, __TIME__, __DATE__);
|
||||
|
||||
le_stack_Init();
|
||||
|
||||
extern void le_gap_init(const char *device_name, uint16_t usAppearance);
|
||||
le_gap_init("memchip", BLE_APPEARANCE_UNKNOWN);
|
||||
|
||||
extern void le_adv_init(uint8_t ble_conn_cfg_tag);
|
||||
le_adv_init(APP_BLE_CONN_CFG_TAG);
|
||||
|
||||
nrf_sdh_freertos_init(NULL, NULL);
|
||||
|
||||
xTaskCreate(led1_task, "led1_task", 160, NULL, 3, NULL);
|
||||
|
||||
Reference in New Issue
Block a user