Integration of nimble, work in progress.

Advertising is working.
This commit is contained in:
JF 2020-04-19 20:44:59 +02:00
parent 6e1bd118c5
commit dd6aecbf6b
10 changed files with 401 additions and 106 deletions

View File

@ -70,22 +70,23 @@ macro(nRF5x_setup)
endif()
set(CPU_FLAGS "-mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16")
add_definitions(-DNRF52 -DNRF52832 -DNRF52832_XXAA -DNRF52_PAN_74 -DNRF52_PAN_64 -DNRF52_PAN_12 -DNRF52_PAN_58 -DNRF52_PAN_54 -DNRF52_PAN_31 -DNRF52_PAN_51 -DNRF52_PAN_36 -DNRF52_PAN_15 -DNRF52_PAN_20 -DNRF52_PAN_55 -DBOARD_PCA10040)
add_definitions(-DSOFTDEVICE_PRESENT -DS132 -DSWI_DISABLE0 -DBLE_STACK_SUPPORT_REQD -DNRF_SD_BLE_API_VERSION=6)
# add_definitions(-DSOFTDEVICE_PRESENT -DS132 -DSWI_DISABLE0 -DBLE_STACK_SUPPORT_REQD -DNRF_SD_BLE_API_VERSION=6)
add_definitions(-DFREERTOS)
add_definitions(-DDEBUG_NRF_USER)
add_definitions(-D__STARTUP_CLEAR_BSS)
add_definitions(-D__HEAP_SIZE=8192)
add_definitions(-D__STACK_SIZE=2048)
# add_definitions(-D__STARTUP_CLEAR_BSS)
# add_definitions(-D__HEAP_SIZE=8192)
# add_definitions(-D__STACK_SIZE=2048)
include_directories(
"${NRF5_SDK_PATH}/components/softdevice/s132/headers"
"${NRF5_SDK_PATH}/components/softdevice/s132/headers/nrf52"
# "${NRF5_SDK_PATH}/components/softdevice/s132/headers"
# "${NRF5_SDK_PATH}/components/softdevice/s132/headers/nrf52"
"${NRF5_SDK_PATH}/components/drivers_nrf/nrf_soc_nosd"
)
list(APPEND SDK_SOURCE_FILES
"${NRF5_SDK_PATH}/modules/nrfx/mdk/system_nrf52.c"
"${NRF5_SDK_PATH}/modules/nrfx/mdk/gcc_startup_nrf52.S"
)
set(SOFTDEVICE_PATH "${NRF5_SDK_PATH}/components/softdevice/s132/hex/s132_nrf52_6.1.1_softdevice.hex")
# set(SOFTDEVICE_PATH "${NRF5_SDK_PATH}/components/softdevice/s132/hex/s132_nrf52_6.1.1_softdevice.hex")
endif ()
set(COMMON_FLAGS "-MP -MD -mthumb -mabi=aapcs -Wall -g3 -ffunction-sections -fdata-sections -fno-strict-aliasing -fno-builtin --short-enums ${CPU_FLAGS} -Wreturn-type -Werror=return-type")
@ -254,69 +255,69 @@ macro(nRF5x_setup)
# LCD/GFX
include_directories(
"${NRF5_SDK_PATH}/external/thedotfactory_fonts"
"${NRF5_SDK_PATH}/components/ble/ble_db_discovery"
# "${NRF5_SDK_PATH}/components/ble/ble_db_discovery"
)
list(APPEND SDK_SOURCE_FILES
"${NRF5_SDK_PATH}/components/ble/ble_db_discovery/ble_db_discovery.c"
"${NRF5_SDK_PATH}/components/ble/ble_services/ble_cts_c/ble_cts_c.c"
"${NRF5_SDK_PATH}/components/ble/ble_services/ble_ans_c/ble_ans_c.c"
# "${NRF5_SDK_PATH}/components/ble/ble_db_discovery/ble_db_discovery.c"
# "${NRF5_SDK_PATH}/components/ble/ble_services/ble_cts_c/ble_cts_c.c"
# "${NRF5_SDK_PATH}/components/ble/ble_services/ble_ans_c/ble_ans_c.c"
# "${NRF5_SDK_PATH}/external/thedotfactory_fonts/orkney24pts.c"
)
#BLE S132
include_directories(
"${NRF5_SDK_PATH}/components/ble/common"
"${NRF5_SDK_PATH}/components/ble/ble_advertising"
"${NRF5_SDK_PATH}/components/ble/ble_services/ble_bas"
"${NRF5_SDK_PATH}/components/ble/ble_services/ble_hrs"
"${NRF5_SDK_PATH}/components/ble/ble_services/ble_dis"
"${NRF5_SDK_PATH}/components/ble/nrf_ble_gatt"
"${NRF5_SDK_PATH}/components/libraries/sensorsim"
"${NRF5_SDK_PATH}/components/ble/peer_manager"
"${NRF5_SDK_PATH}/components/ble/nrf_ble_qwr"
)
# include_directories(
# "${NRF5_SDK_PATH}/components/ble/common"
# "${NRF5_SDK_PATH}/components/ble/ble_advertising"
# "${NRF5_SDK_PATH}/components/ble/ble_services/ble_bas"
# "${NRF5_SDK_PATH}/components/ble/ble_services/ble_hrs"
# "${NRF5_SDK_PATH}/components/ble/ble_services/ble_dis"
# "${NRF5_SDK_PATH}/components/ble/nrf_ble_gatt"
# "${NRF5_SDK_PATH}/components/libraries/sensorsim"
# "${NRF5_SDK_PATH}/components/ble/peer_manager"
# "${NRF5_SDK_PATH}/components/ble/nrf_ble_qwr"
# )
LIST(APPEND SDK_SOURCE_FILES
"${NRF5_SDK_PATH}//components/ble/common/ble_srv_common.c"
"${NRF5_SDK_PATH}/components/ble/ble_advertising/ble_advertising.c"
"${NRF5_SDK_PATH}/components/ble/common/ble_advdata.c"
"${NRF5_SDK_PATH}/components/ble/ble_services/ble_bas/ble_bas.c"
"${NRF5_SDK_PATH}/components/ble/ble_services/ble_hrs/ble_hrs.c"
"${NRF5_SDK_PATH}/components/ble/ble_services/ble_dis/ble_dis.c"
"${NRF5_SDK_PATH}/components/ble/nrf_ble_gatt/nrf_ble_gatt.c"
"${NRF5_SDK_PATH}/components/libraries/sensorsim/sensorsim.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/peer_manager.c"
"${NRF5_SDK_PATH}/components/ble/nrf_ble_qwr/nrf_ble_qwr.c"
"${NRF5_SDK_PATH}/components/ble/common/ble_conn_state.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/auth_status_tracker.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/gatt_cache_manager.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/gatts_cache_manager.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/id_manager.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/peer_data_storage.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/peer_database.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/peer_id.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/peer_manager.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/peer_manager_handler.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/pm_buffer.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/security_dispatcher.c"
"${NRF5_SDK_PATH}/components/ble/peer_manager/security_manager.c"
"${NRF5_SDK_PATH}/components/ble/common/ble_conn_state.c"
"${NRF5_SDK_PATH}/components/ble/common/ble_conn_params.c"
"${NRF5_SDK_PATH}/components/ble/common/ble_conn_state.c"
"${NRF5_SDK_PATH}/components/libraries/atomic_flags/nrf_atflags.c"
"${NRF5_SDK_PATH}/components/libraries/fds/fds.c"
"${NRF5_SDK_PATH}/components/libraries/fstorage/nrf_fstorage.c"
"${NRF5_SDK_PATH}/components/libraries/fstorage/nrf_fstorage_sd.c"
"${NRF5_SDK_PATH}/components/libraries/atomic_fifo/nrf_atfifo.c"
"${NRF5_SDK_PATH}/components/softdevice/common/nrf_sdh.c"
"${NRF5_SDK_PATH}/components/softdevice/common/nrf_sdh_ble.c"
"${NRF5_SDK_PATH}/components/softdevice/common/nrf_sdh_freertos.c"
"${NRF5_SDK_PATH}/components/softdevice/common/nrf_sdh_soc.c"
"${NRF5_SDK_PATH}/components/libraries/experimental_section_vars/nrf_section_iter.c"
"${NRF5_SDK_PATH}/components/libraries/bsp/bsp_btn_ble.c"
"${NRF5_SDK_PATH}/components/libraries/hardfault/hardfault_implementation.c"
"${NRF5_SDK_PATH}/components/libraries/hardfault/nrf52/handler/hardfault_handler_gcc.c"
# "${NRF5_SDK_PATH}//components/ble/common/ble_srv_common.c"
# "${NRF5_SDK_PATH}/components/ble/ble_advertising/ble_advertising.c"
# "${NRF5_SDK_PATH}/components/ble/common/ble_advdata.c"
# "${NRF5_SDK_PATH}/components/ble/ble_services/ble_bas/ble_bas.c"
# "${NRF5_SDK_PATH}/components/ble/ble_services/ble_hrs/ble_hrs.c"
# "${NRF5_SDK_PATH}/components/ble/ble_services/ble_dis/ble_dis.c"
# "${NRF5_SDK_PATH}/components/ble/nrf_ble_gatt/nrf_ble_gatt.c"
# "${NRF5_SDK_PATH}/components/libraries/sensorsim/sensorsim.c"
# "${NRF5_SDK_PATH}/components/ble/peer_manager/peer_manager.c"
# "${NRF5_SDK_PATH}/components/ble/nrf_ble_qwr/nrf_ble_qwr.c"
# "${NRF5_SDK_PATH}/components/ble/common/ble_conn_state.c"
# "${NRF5_SDK_PATH}/components/ble/peer_manager/auth_status_tracker.c"
# "${NRF5_SDK_PATH}/components/ble/peer_manager/gatt_cache_manager.c"
# "${NRF5_SDK_PATH}/components/ble/peer_manager/gatts_cache_manager.c"
# "${NRF5_SDK_PATH}/components/ble/peer_manager/id_manager.c"
# "${NRF5_SDK_PATH}/components/ble/peer_manager/peer_data_storage.c"
# "${NRF5_SDK_PATH}/components/ble/peer_manager/peer_database.c"
# "${NRF5_SDK_PATH}/components/ble/peer_manager/peer_id.c"
# "${NRF5_SDK_PATH}/components/ble/peer_manager/peer_manager.c"
# "${NRF5_SDK_PATH}/components/ble/peer_manager/peer_manager_handler.c"
# "${NRF5_SDK_PATH}/components/ble/peer_manager/pm_buffer.c"
# "${NRF5_SDK_PATH}/components/ble/peer_manager/security_dispatcher.c"
# "${NRF5_SDK_PATH}/components/ble/peer_manager/security_manager.c"
# "${NRF5_SDK_PATH}/components/ble/common/ble_conn_state.c"
# "${NRF5_SDK_PATH}/components/ble/common/ble_conn_params.c"
# "${NRF5_SDK_PATH}/components/ble/common/ble_conn_state.c"
# "${NRF5_SDK_PATH}/components/libraries/atomic_flags/nrf_atflags.c"
# "${NRF5_SDK_PATH}/components/libraries/fds/fds.c"
# "${NRF5_SDK_PATH}/components/libraries/fstorage/nrf_fstorage.c"
# "${NRF5_SDK_PATH}/components/libraries/fstorage/nrf_fstorage_sd.c"
# "${NRF5_SDK_PATH}/components/libraries/atomic_fifo/nrf_atfifo.c"
# "${NRF5_SDK_PATH}/components/softdevice/common/nrf_sdh.c"
# "${NRF5_SDK_PATH}/components/softdevice/common/nrf_sdh_ble.c"
# "${NRF5_SDK_PATH}/components/softdevice/common/nrf_sdh_freertos.c"
# "${NRF5_SDK_PATH}/components/softdevice/common/nrf_sdh_soc.c"
# "${NRF5_SDK_PATH}/components/libraries/experimental_section_vars/nrf_section_iter.c"
# "${NRF5_SDK_PATH}/components/libraries/bsp/bsp_btn_ble.c"
# "${NRF5_SDK_PATH}/components/libraries/hardfault/hardfault_implementation.c"
# "${NRF5_SDK_PATH}/components/libraries/hardfault/nrf52/handler/hardfault_handler_gcc.c"
)
LIST(APPEND SDK_SOURCE_FILES

View File

@ -5,8 +5,8 @@ GROUP(-lgcc -lc -lnosys)
MEMORY
{
FLASH (rx) : ORIGIN = 0x26000, LENGTH = 0x5a000
RAM (rwx) : ORIGIN = 0x200057b8, LENGTH = 0xa848
FLASH (rx) : ORIGIN = 0x00000, LENGTH = 0x80000
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x10000
}
SECTIONS

View File

@ -1,3 +1,5 @@
#if 0
#include <libraries/util/sdk_errors.h>
#include <softdevice/common/nrf_sdh.h>
#include <libraries/util/app_error.h>
@ -778,3 +780,4 @@ void ble_manager_delete_bonds() {
err_code = pm_peers_delete();
APP_ERROR_CHECK(err_code);
}
#endif

View File

@ -1,5 +1,5 @@
#pragma once
#include <ble/ble_services/ble_cts_c/ble_cts_c.h>
//#include <ble/ble_services/ble_cts_c/ble_cts_c.h>
#ifdef __cplusplus
extern "C" {
@ -39,7 +39,7 @@ void ble_manager_start_advertising(void *p_erase_bonds);
void ble_manager_init_peer_manager();
// TODO use signals from RTOS to notify new time
void ble_manager_set_new_time_callback(void (*OnNewTime)(current_time_char_t* currentTime));
//void ble_manager_set_new_time_callback(void (*OnNewTime)(current_time_char_t* currentTime));
void ble_manager_set_ble_disconnection_callback(void (*OnBleDisconnection)());
void ble_manager_set_ble_connection_callback(void (*OnBleConnection)());

View File

@ -23,11 +23,100 @@ nRF5x_addAppGpiote()
add_definitions(-DCONFIG_GPIO_AS_PINRESET)
add_definitions(-DDEBUG)
add_definitions(-DNIMBLE_CFG_CONTROLLER)
add_definitions(-DOS_CPUTIME_FREQ)
include_directories(.)
include_directories(libs/)
set(TINYCRYPT_SRC
libs/mynewt-nimble/ext/tinycrypt/src/aes_encrypt.c
libs/mynewt-nimble/ext/tinycrypt/src/utils.c
)
set(NIMBLE_SRC
libs/mynewt-nimble/porting/npl/freertos/src/nimble_port_freertos.c
libs/mynewt-nimble/porting/npl/freertos/src/npl_os_freertos.c
libs/mynewt-nimble/nimble/host/src/ble_hs.c
libs/mynewt-nimble/nimble/host/src/ble_hs_hci_evt.c
libs/mynewt-nimble/nimble/host/src/ble_l2cap_sig_cmd.c
libs/mynewt-nimble/nimble/host/src/ble_l2cap_sig.c
libs/mynewt-nimble/nimble/host/src/ble_l2cap.c
libs/mynewt-nimble/nimble/host/src/ble_hs_mbuf.c
libs/mynewt-nimble/nimble/host/src/ble_sm.c
libs/mynewt-nimble/nimble/host/src/ble_gap.c
libs/mynewt-nimble/nimble/host/src/ble_gatts.c
libs/mynewt-nimble/nimble/host/src/ble_gattc.c
libs/mynewt-nimble/nimble/host/src/ble_hs_conn.c
libs/mynewt-nimble/nimble/host/src/ble_att_svr.c
libs/mynewt-nimble/nimble/host/src/ble_store.c
libs/mynewt-nimble/nimble/host/src/ble_hs_pvcy.c
libs/mynewt-nimble/nimble/host/src/ble_hs_hci.c
libs/mynewt-nimble/nimble/host/src/ble_hs_log.c
libs/mynewt-nimble/nimble/host/src/ble_hs_hci_util.c
libs/mynewt-nimble/nimble/host/src/ble_hs_hci_cmd.c
libs/mynewt-nimble/nimble/host/src/ble_hs_cfg.c
libs/mynewt-nimble/nimble/host/src/ble_uuid.c
libs/mynewt-nimble/nimble/host/src/ble_hs_id.c
libs/mynewt-nimble/nimble/host/src/ble_hs_misc.c
libs/mynewt-nimble/nimble/host/src/ble_att.c
libs/mynewt-nimble/nimble/host/src/ble_att_clt.c
libs/mynewt-nimble/nimble/host/src/ble_att_svr.c
libs/mynewt-nimble/nimble/host/src/ble_att_cmd.c
libs/mynewt-nimble/nimble/host/src/ble_hs_atomic.c
libs/mynewt-nimble/nimble/host/src/ble_hs_adv.c
libs/mynewt-nimble/nimble/host/src/ble_hs_flow.c
libs/mynewt-nimble/nimble/host/src/ble_sm.c
libs/mynewt-nimble/nimble/host/src/ble_sm_cmd.c
libs/mynewt-nimble/nimble/host/src/ble_sm_lgcy.c
libs/mynewt-nimble/nimble/host/src/ble_sm_alg.c
libs/mynewt-nimble/nimble/host/src/ble_hs_mqueue.c
libs/mynewt-nimble/nimble/host/src/ble_hs_stop.c
libs/mynewt-nimble/nimble/host/src/ble_hs_startup.c
libs/mynewt-nimble/nimble/host/store/ram/src/ble_store_ram.c
libs/mynewt-nimble/nimble/transport/ram/src/ble_hci_ram.c
libs/mynewt-nimble/nimble/controller/src/ble_ll.c
libs/mynewt-nimble/nimble/controller/src/ble_ll_rand.c
libs/mynewt-nimble/nimble/controller/src/ble_ll_conn.c
libs/mynewt-nimble/nimble/controller/src/ble_ll_ctrl.c
libs/mynewt-nimble/nimble/controller/src/ble_ll_hci.c
libs/mynewt-nimble/nimble/controller/src/ble_ll_conn_hci.c
libs/mynewt-nimble/nimble/controller/src/ble_ll_utils.c
libs/mynewt-nimble/nimble/controller/src/ble_ll_scan.c
libs/mynewt-nimble/nimble/controller/src/ble_ll_whitelist.c
libs/mynewt-nimble/nimble/controller/src/ble_ll_adv.c
libs/mynewt-nimble/nimble/controller/src/ble_ll_sched.c
libs/mynewt-nimble/nimble/controller/src/ble_ll_supp_cmd.c
libs/mynewt-nimble/nimble/controller/src/ble_ll_hci_ev.c
libs/mynewt-nimble/nimble/controller/src/ble_ll_rfmgmt.c
libs/mynewt-nimble/porting/nimble/src/os_cputime.c
libs/mynewt-nimble/porting/nimble/src/os_cputime_pwr2.c
libs/mynewt-nimble/porting/nimble/src/os_mbuf.c
libs/mynewt-nimble/porting/nimble/src/os_mempool.c
libs/mynewt-nimble/porting/nimble/src/hal_timer.c
libs/mynewt-nimble/porting/nimble/src/mem.c
libs/mynewt-nimble/porting/nimble/src/endian.c
libs/mynewt-nimble/porting/nimble/src/os_msys_init.c
libs/mynewt-nimble/nimble/drivers/nrf52/src/ble_hw.c
libs/mynewt-nimble/nimble/drivers/nrf52/src/ble_phy.c
libs/mynewt-nimble/nimble/host/services/gap/src/ble_svc_gap.c
libs/mynewt-nimble/nimble/host/services/gatt/src/ble_svc_gatt.c
libs/mynewt-nimble/nimble/host/util/src/addr.c
)
set(LVGL_SRC
libs/lv_conf.h
libs/lvgl/lvgl.h
@ -230,6 +319,8 @@ list(APPEND SOURCE_FILES
FreeRTOS/port.c
FreeRTOS/port_cmsis_systick.c
FreeRTOS/port_cmsis.c
${TINYCRYPT_SRC}
${NIMBLE_SRC}
${LVGL_SRC}
${IMAGE_FILES}
@ -288,6 +379,18 @@ set(INCLUDE_FILES
include_directories(
FreeRTOS/
libs/date/includes
libs/mynewt-nimble/porting/npl/freertos/include
libs/mynewt-nimble/nimble/include
libs/mynewt-nimble/porting/nimble/include
libs/mynewt-nimble/nimble/host/include
libs/mynewt-nimble/nimble/controller/include
libs/mynewt-nimble/nimble/transport/ram/include
libs/mynewt-nimble/nimble/drivers/nrf52/include
libs/mynewt-nimble/ext/tinycrypt/include
libs/mynewt-nimble/nimble/host/services/gap/include
libs/mynewt-nimble/nimble/host/services/gatt/include
libs/mynewt-nimble/nimble/host/util/include
libs/mynewt-nimble/nimble/host/store/ram/include
)
link_directories(

View File

@ -63,7 +63,7 @@
#define configTICK_RATE_HZ 1024
#define configMAX_PRIORITIES ( 3 )
#define configMINIMAL_STACK_SIZE ( 120 )
#define configTOTAL_HEAP_SIZE ( 1024*10 )
#define configTOTAL_HEAP_SIZE ( 1024*20 )
#define configMAX_TASK_NAME_LEN ( 4 )
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1

View File

@ -4,9 +4,14 @@
#include <DisplayApp/LittleVgl.h>
#include <hal/nrf_rtc.h>
#include <BLE/BleManager.h>
#include <softdevice/common/nrf_sdh_freertos.h>
#include <Components/Ble/NotificationManager.h>
#include <services/gap/ble_svc_gap.h>
#include <host/ble_gatt.h>
#include <host/ble_hs_adv.h>
#include "SystemTask.h"
#include <nimble/hci_common.h>
#include <host/ble_gap.h>
#include <host/util/util.h>
#include "../main.h"
using namespace Pinetime::System;
@ -32,14 +37,87 @@ void SystemTask::Process(void *instance) {
app->Work();
}
static int _gap_event_cb(struct ble_gap_event *event, void *arg)
{
return 0;
}
static int
adv_event(struct ble_gap_event *event, void *arg)
{
switch (event->type) {
case BLE_GAP_EVENT_ADV_COMPLETE:
return 0;
case BLE_GAP_EVENT_CONNECT:
return 0;
case BLE_GAP_EVENT_DISCONNECT:
return 0;
default:
return 0;
}
}
void SystemTask::Work() {
watchdog.Setup(7);
watchdog.Start();
// watchdog.Setup(7);
// watchdog.Start();
NRF_LOG_INFO("Last reset reason : %s", Pinetime::Drivers::Watchdog::ResetReasonToString(watchdog.ResetReason()));
APP_GPIOTE_INIT(2);
bool erase_bonds=true;
ble_manager_init_peer_manager();
nrf_sdh_freertos_init(ble_manager_start_advertising, &erase_bonds);
// bool erase_bonds=true;
// ble_manager_init_peer_manager();
// nrf_sdh_freertos_init(ble_manager_start_advertising, &erase_bonds);
/* BLE */
while (!ble_hs_synced()) {}
int res;
res = ble_hs_util_ensure_addr(0);
assert(res == 0);
uint8_t addrType;
res = ble_hs_id_infer_auto(0, &addrType);
assert(res == 0);
res = ble_svc_gap_device_name_set("Pinetime-JF");
assert(res == 0);
/* set adv parameters */
struct ble_gap_adv_params adv_params;
struct ble_hs_adv_fields fields;
/* advertising payload is split into advertising data and advertising
response, because all data cannot fit into single packet; name of device
is sent as response to scan request */
struct ble_hs_adv_fields rsp_fields;
/* fill all fields and parameters with zeros */
memset(&adv_params, 0, sizeof(adv_params));
memset(&fields, 0, sizeof(fields));
memset(&rsp_fields, 0, sizeof(rsp_fields));
adv_params.conn_mode = BLE_GAP_CONN_MODE_UND;
adv_params.disc_mode = BLE_GAP_DISC_MODE_GEN;
fields.flags = BLE_HS_ADV_F_DISC_GEN |
BLE_HS_ADV_F_BREDR_UNSUP;
// fields.uuids128 = BLE_UUID128(BLE_UUID128_DECLARE(
// 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
// 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff));
fields.num_uuids128 = 0;
fields.uuids128_is_complete = 0;;
fields.tx_pwr_lvl = BLE_HS_ADV_TX_PWR_LVL_AUTO;
rsp_fields.name = (uint8_t *)"Pinetime-JF";
rsp_fields.name_len = strlen("Pinetime-JF");
rsp_fields.name_is_complete = 1;
res = ble_gap_adv_set_fields(&fields);
assert(res == 0);
res = ble_gap_adv_rsp_set_fields(&rsp_fields);
res = ble_gap_adv_start(addrType, NULL, 36000,
&adv_params, adv_event, NULL);
assert(res == 0);
/* /BLE*/
spi.Init();
lcd.Init();

View File

@ -33,16 +33,16 @@ void Watchdog::Kick() {
Watchdog::ResetReasons Watchdog::ActualResetReason() const {
uint32_t resetReason;
sd_power_reset_reason_get(&resetReason);
sd_power_reset_reason_clr(0xFFFFFFFF);
if(resetReason & 0x01u) return ResetReasons::ResetPin;
if((resetReason >> 1u) & 0x01u) return ResetReasons::Watchdog;
if((resetReason >> 2u) & 0x01u) return ResetReasons::SoftReset;
if((resetReason >> 3u) & 0x01u) return ResetReasons::CpuLockup;
if((resetReason >> 16u) & 0x01u) return ResetReasons::SystemOff;
if((resetReason >> 17u) & 0x01u) return ResetReasons::LpComp;
if((resetReason >> 18u) & 0x01u) return ResetReasons::DebugInterface;
if((resetReason >> 19u) & 0x01u) return ResetReasons::NFC;
// sd_power_reset_reason_get(&resetReason);
// sd_power_reset_reason_clr(0xFFFFFFFF);
// if(resetReason & 0x01u) return ResetReasons::ResetPin;
// if((resetReason >> 1u) & 0x01u) return ResetReasons::Watchdog;
// if((resetReason >> 2u) & 0x01u) return ResetReasons::SoftReset;
// if((resetReason >> 3u) & 0x01u) return ResetReasons::CpuLockup;
// if((resetReason >> 16u) & 0x01u) return ResetReasons::SystemOff;
// if((resetReason >> 17u) & 0x01u) return ResetReasons::LpComp;
// if((resetReason >> 18u) & 0x01u) return ResetReasons::DebugInterface;
// if((resetReason >> 19u) & 0x01u) return ResetReasons::NFC;
return ResetReasons::HardReset;
}

View File

@ -7,7 +7,7 @@
#include <softdevice/common/nrf_sdh.h>
#include <hal/nrf_rtc.h>
#include <timers.h>
#include <ble/ble_services/ble_cts_c/ble_cts_c.h>
//#include <ble/ble_services/ble_cts_c/ble_cts_c.h>
#include <Components/DateTime/DateTimeController.h>
#include "BLE/BleManager.h"
#include "Components/Battery/BatteryController.h"
@ -17,6 +17,18 @@
#include <DisplayApp/LittleVgl.h>
#include <SystemTask/SystemTask.h>
#include <Components/Ble/NotificationManager.h>
#include <nimble/nimble_port_freertos.h>
#include <nimble/npl_freertos.h>
#include <nimble/nimble_port.h>
#include <host/ble_hs.h>
#include <controller/ble_ll.h>
#include <os/os_cputime.h>
#include <transport/ram/ble_hci_ram.h>
#include <hal/nrf_wdt.h>
#include <host/util/util.h>
#include <services/gap/ble_svc_gap.h>
#include <services/gatt/ble_svc_gatt.h>
#if NRF_LOG_ENABLED
#include "Logging/NrfLogger.h"
@ -93,20 +105,20 @@ void OnNewNotification(const char* message, uint8_t size) {
systemTask->PushMessage(Pinetime::System::SystemTask::Messages::OnNewNotification);
}
void OnNewTime(current_time_char_t* currentTime) {
auto dayOfWeek = currentTime->exact_time_256.day_date_time.day_of_week;
auto year = currentTime->exact_time_256.day_date_time.date_time.year;
auto month = currentTime->exact_time_256.day_date_time.date_time.month;
auto day = currentTime->exact_time_256.day_date_time.date_time.day;
auto hour = currentTime->exact_time_256.day_date_time.date_time.hours;
auto minute = currentTime->exact_time_256.day_date_time.date_time.minutes;
auto second = currentTime->exact_time_256.day_date_time.date_time.seconds;
dateTimeController.SetTime(year, month, day,
dayOfWeek, hour, minute, second, nrf_rtc_counter_get(portNRF_RTC_REG));
systemTask->PushMessage(Pinetime::System::SystemTask::Messages::OnNewTime);
}
//void OnNewTime(current_time_char_t* currentTime) {
// auto dayOfWeek = currentTime->exact_time_256.day_date_time.day_of_week;
// auto year = currentTime->exact_time_256.day_date_time.date_time.year;
// auto month = currentTime->exact_time_256.day_date_time.date_time.month;
// auto day = currentTime->exact_time_256.day_date_time.date_time.day;
// auto hour = currentTime->exact_time_256.day_date_time.date_time.hours;
// auto minute = currentTime->exact_time_256.day_date_time.date_time.minutes;
// auto second = currentTime->exact_time_256.day_date_time.date_time.seconds;
//
// dateTimeController.SetTime(year, month, day,
// dayOfWeek, hour, minute, second, nrf_rtc_counter_get(portNRF_RTC_REG));
//
// systemTask->PushMessage(Pinetime::System::SystemTask::Messages::OnNewTime);
//}
void SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler(void) {
if(((NRF_SPIM0->INTENSET & (1<<6)) != 0) && NRF_SPIM0->EVENTS_END == 1) {
@ -124,6 +136,100 @@ void SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler(void) {
}
}
static void (*radio_isr_addr)(void) ;
static void (*rng_isr_addr)(void) ;
static void (*rtc0_isr_addr)(void) ;
/* Some interrupt handlers required for NimBLE radio driver */
extern "C" {
void RADIO_IRQHandler(void) {
((void (*)(void)) radio_isr_addr)();
}
void RNG_IRQHandler(void) {
((void (*)(void)) rng_isr_addr)();
}
void RTC0_IRQHandler(void) {
((void (*)(void)) rtc0_isr_addr)();
}
void WDT_IRQHandler(void) {
nrf_wdt_event_clear(NRF_WDT_EVENT_TIMEOUT);
}
void npl_freertos_hw_set_isr(int irqn, void (*addr)(void)) {
switch (irqn) {
case RADIO_IRQn:
radio_isr_addr = addr;
break;
case RNG_IRQn:
rng_isr_addr = addr;
break;
case RTC0_IRQn:
rtc0_isr_addr = addr;
break;
}
}
uint32_t
npl_freertos_hw_enter_critical(void) {
uint32_t ctx = __get_PRIMASK();
__disable_irq();
return (ctx & 0x01);
}
void npl_freertos_hw_exit_critical(uint32_t ctx) {
if (!ctx) {
__enable_irq();
}
}
static struct ble_npl_eventq g_eventq_dflt;
struct ble_npl_eventq *
nimble_port_get_dflt_eventq(void) {
return &g_eventq_dflt;
}
void nimble_port_run(void) {
struct ble_npl_event *ev;
while (1) {
ev = ble_npl_eventq_get(&g_eventq_dflt, BLE_NPL_TIME_FOREVER);
ble_npl_event_run(ev);
}
}
void BleHost(void *) {
nimble_port_run();
}
void nimble_port_init(void) {
void os_msys_init(void);
void ble_store_ram_init(void);
ble_npl_eventq_init(&g_eventq_dflt);
os_msys_init();
ble_hs_init();
ble_store_ram_init();
hal_timer_init(5, NULL);
os_cputime_init(32768);
ble_ll_init();
ble_hci_ram_init();
nimble_port_freertos_init(BleHost);
}
void nimble_port_ll_task_func(void *args) {
// extern void ble_ll_task(void *arg);
ble_ll_task(args);
}
}
int main(void) {
logger.Init();
@ -135,11 +241,15 @@ int main(void) {
dateTimeController, notificationManager));
systemTask->Start();
ble_manager_init();
ble_manager_set_new_time_callback(OnNewTime);
ble_manager_set_ble_connection_callback(OnBleConnection);
ble_manager_set_ble_disconnection_callback(OnBleDisconnection);
ble_manager_set_new_notification_callback(OnNewNotification);
nimble_port_init();
ble_svc_gap_init();
ble_svc_gatt_init();
// ble_manager_init();
// ble_manager_set_new_time_callback(OnNewTime);
// ble_manager_set_ble_connection_callback(OnBleConnection);
// ble_manager_set_ble_disconnection_callback(OnBleDisconnection);
// ble_manager_set_new_notification_callback(OnNewNotification);
vTaskStartScheduler();

View File

@ -8460,15 +8460,15 @@
// <e> NRF_LOG_ENABLED - nrf_log - Logger
//==========================================================
#ifndef NRF_LOG_ENABLED
#define NRF_LOG_ENABLED 0
#define NRF_LOG_ENABLED 1
#endif
#ifndef NRF_LOG_BACKEND_RTT_ENABLED
#define NRF_LOG_BACKEND_RTT_ENABLED 0
#define NRF_LOG_BACKEND_RTT_ENABLED 1
#endif
#ifndef NRF_LOG_BACKEND_SERIAL_USES_RTT
#define NRF_LOG_BACKEND_SERIAL_USES_RTT 0
#define NRF_LOG_BACKEND_SERIAL_USES_RTT 1
#endif
// <h> Log message pool - Configuration of log message pool