generated from Embedded_Projects/N32WB031_Template
Initial BLE demo project.
Signed-off-by: Yilin Sun <imi415@imi.moe>
This commit is contained in:
parent
c2a068af3b
commit
8b4ce08d0f
|
@ -1,6 +1,6 @@
|
|||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
project(n32wb03x_template)
|
||||
project(n32wb03x_ble_demo)
|
||||
|
||||
enable_language(CXX)
|
||||
enable_language(ASM)
|
||||
|
@ -8,6 +8,8 @@ enable_language(ASM)
|
|||
# Different linker scripts
|
||||
set(TARGET_LDSCRIPT_FLASH "${CMAKE_SOURCE_DIR}/SDK/gcc/n32wb03x_FLASH.ld")
|
||||
|
||||
set(TARGET_SYMBOL_LIST "${CMAKE_CURRENT_SOURCE_DIR}/SDK/middlewares/Nationstech/ble_library/ns_ble_stack/symdef/symbol_g15.txt")
|
||||
|
||||
set(TARGET_SOURCES
|
||||
"SDK/firmware/n32wb03x_std_periph_driver/src/misc.c"
|
||||
"SDK/firmware/n32wb03x_std_periph_driver/src/n32wb03x_adc.c"
|
||||
|
@ -27,9 +29,32 @@ set(TARGET_SOURCES
|
|||
"SDK/firmware/n32wb03x_std_periph_driver/src/n32wb03x_tim.c"
|
||||
"SDK/firmware/n32wb03x_std_periph_driver/src/n32wb03x_usart.c"
|
||||
"SDK/firmware/n32wb03x_std_periph_driver/src/n32wb03x_wwdg.c"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_profile/dis/diss/src/diss.c"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_profile/dis/diss/src/diss_task.c"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrps/src/hrps.c"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrps/src/hrps_task.c"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_profile/prf.c"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_stack/stack_common/rwip.c"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_stack/stack_common/rwip_driver.c"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_library/ble/ns_ble.c"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_library/ble/ns_ble_task.c"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_library/ecc/ns_ecc.c"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_library/ecc/sha256.c"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_library/ecc/uECC.c"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_library/error/ns_error.c"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_library/log/ns_log_lpuart.c"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_library/log/ns_log_usart.c"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_library/scheduler/ns_scheduler.c"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_library/sec/ns_sec.c"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_library/sleep/ns_sleep.c"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_library/timer/ns_timer.c"
|
||||
"board/n32wb03x_it.c"
|
||||
"board/system_n32wb03x.c"
|
||||
"SDK/gcc/startup_n32wb03x.S"
|
||||
"src/app_profile/app_dis.c"
|
||||
"src/app_profile/app_hrps.c"
|
||||
"src/app_ble.c"
|
||||
"src/app_gpio.c"
|
||||
"src/main.c"
|
||||
)
|
||||
|
||||
|
@ -42,8 +67,53 @@ set(TARGET_C_INCLUDES
|
|||
"SDK/firmware/CMSIS/core"
|
||||
"SDK/firmware/CMSIS/device"
|
||||
"SDK/firmware/n32wb03x_std_periph_driver/inc"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_profile/bas/bass/api"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_profile/custom"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_profile/custom/custs/api"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_profile/dis/diss/api"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_profile/hogp"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogpd/api"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_profile/hogp/hogpd/src"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_profile/hrp"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrps/api"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_profile/hrp/hrps/src"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_stack/arch"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_stack/arch"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ahi/api"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/api"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/inc"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/gap"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/gatt"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/hl/src/l2c"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/api"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/src"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/src/llc"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/src/lld"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_stack/ip/ble/ll/src/llm"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_stack/ip/em/api"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_stack/ip/hci/api"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_stack/ip/sch/api"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_stack/modules/aes/api"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_stack/modules/common/api"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_stack/modules/common/api"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_stack/modules/common/src"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_stack/modules/dbg/api"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_stack/modules/ecc_p256/api"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_stack/modules/h4tl/api"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_stack/modules/ke/api"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_stack/modules/rwip/api"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_stack/rfinit/api"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_ble_stack/stack_common"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_library/adv"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_library/ble"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_library/delay"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_library/log"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_library/sec"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_library/sleep"
|
||||
"SDK/middlewares/Nationstech/ble_library/ns_library/timer"
|
||||
"board"
|
||||
"include"
|
||||
"include/app_profile"
|
||||
)
|
||||
|
||||
# Shared libraries linked with application
|
||||
|
@ -64,16 +134,16 @@ set(CMAKE_CXX_FLAGS_DEBUG "-DDEBUG -O0 -g")
|
|||
set(CMAKE_ASM_FLAGS_DEBUG "-DDEBUG -O0 -g")
|
||||
|
||||
# RELEASE
|
||||
set(CMAKE_C_FLAGS_RELEASE "-DNDEBUG -O2 -flto")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG -O2 -flto")
|
||||
set(CMAKE_ASM_FLAGS_RELEASE "-DNDEBUG -O2 -flto")
|
||||
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-flto")
|
||||
set(CMAKE_C_FLAGS_RELEASE "-DNDEBUG -O2")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG -O2")
|
||||
set(CMAKE_ASM_FLAGS_RELEASE "-DNDEBUG -O2")
|
||||
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "")
|
||||
|
||||
# Final compiler flags
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -fno-common -fno-builtin -ffreestanding -fdata-sections -ffunction-sections")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-common -fno-builtin -ffreestanding -fdata-sections -ffunction-sections")
|
||||
set(CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS} -x assembler-with-cpp")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--just-symbols=${TARGET_SYMBOL_LIST} -Wl,--gc-sections")
|
||||
|
||||
# Shared sources, includes and definitions
|
||||
add_compile_definitions(${TARGET_C_DEFINES})
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 21b2bbc22399e2c3a0b44aa4829ca2d27ac95f80
|
|
@ -9,8 +9,8 @@ set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
|
|||
# Optionally set size binary name, for elf section size reporting.
|
||||
set(TARGET_TOOLCHAIN_SIZE arm-none-eabi-size)
|
||||
|
||||
set(CMAKE_C_FLAGS_INIT "-mcpu=cortex-m0plus -mthumb -mfloat-abi=soft")
|
||||
set(CMAKE_CXX_FLAGS_INIT "-mcpu=cortex-m0plus -mthumb -mfloat-abi=soft")
|
||||
set(CMAKE_C_FLAGS_INIT "-mcpu=cortex-m0 -mthumb -mfloat-abi=soft")
|
||||
set(CMAKE_CXX_FLAGS_INIT "-mcpu=cortex-m0 -mthumb -mfloat-abi=soft")
|
||||
set(CMAKE_EXE_LINKER_FLAGS_INIT "-specs=nano.specs -specs=nosys.specs -Wl,--print-memory-usage -Wl,--no-warn-rwx-segments")
|
||||
|
||||
# Make CMake happy about those compilers
|
||||
|
|
|
@ -55,116 +55,98 @@
|
|||
the Bluetooth stack only.
|
||||
*/
|
||||
|
||||
#define SYSCLK_USE_HSI 1
|
||||
#define SYSCLK_USE_HSE 0
|
||||
#define SYSCLK_USE_HSI 1
|
||||
#define SYSCLK_USE_HSE 0
|
||||
|
||||
#ifndef SYSCLK_FREQ
|
||||
#define SYSCLK_FREQ HSI_VALUE
|
||||
#endif
|
||||
|
||||
/*
|
||||
* SYSCLK_SRC *
|
||||
** SYSCLK_USE_HSI **
|
||||
** SYSCLK_USE_HSE **
|
||||
*/
|
||||
* SYSCLK_SRC *
|
||||
** SYSCLK_USE_HSI **
|
||||
** SYSCLK_USE_HSE **
|
||||
*/
|
||||
#ifndef SYSCLK_SRC
|
||||
#define SYSCLK_SRC SYSCLK_USE_HSI
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define TRIM_STORE_ADDR 0x1000
|
||||
#define TRIM_READ_CMD_CODE_LEN 0x140
|
||||
#define TRIM_READ_CMD_CODE_CRC 0x3aa0
|
||||
const unsigned char TRIM_READ_CMD_CODE[] ={
|
||||
0x40,0xba,0x70,0x47,0xc0,0xba,0x70,0x47,0x01,0x38,0xfd,0xd1,0x70,0x47,0x00,0x00,
|
||||
0xf7,0xb5,0x03,0x25,0xad,0x06,0x28,0x6a,0x82,0xb0,0x16,0x46,0x0c,0x46,0x40,0x08,
|
||||
0x40,0x00,0x28,0x62,0x28,0x6a,0x02,0x21,0x08,0x43,0x28,0x62,0x28,0x6a,0x80,0x07,
|
||||
0xfc,0xd4,0x66,0x20,0x68,0x60,0x01,0x27,0x2f,0x61,0xa8,0x6a,0xc0,0x05,0xfc,0xd5,
|
||||
0x99,0x20,0x68,0x60,0x2f,0x61,0xa8,0x6a,0xc0,0x05,0xfc,0xd5,0xff,0x20,0x91,0x30,
|
||||
0xff,0xf7,0xda,0xff,0xff,0x23,0x01,0x33,0xab,0x62,0x68,0x46,0xef,0x60,0x35,0x21,
|
||||
0x69,0x60,0x2f,0x61,0xa9,0x6a,0xc9,0x05,0xfc,0xd5,0xab,0x62,0xa9,0x69,0xef,0x60,
|
||||
0xc9,0xb2,0x05,0x22,0x6a,0x60,0x2f,0x61,0xaa,0x6a,0xd2,0x05,0xfc,0xd5,0xab,0x62,
|
||||
0xaa,0x69,0x09,0x02,0xd2,0xb2,0x11,0x43,0x01,0x80,0xc8,0x07,0x02,0xd0,0x03,0x20,
|
||||
0x05,0xb0,0xf0,0xbd,0xab,0x62,0x68,0x69,0xff,0x21,0x08,0x31,0x88,0x43,0x68,0x61,
|
||||
0x68,0x69,0xc9,0x1e,0x08,0x43,0x68,0x61,0x02,0x98,0x00,0x02,0x48,0x30,0x68,0x60,
|
||||
0x08,0x20,0xa8,0x60,0xee,0x60,0x2f,0x61,0xa8,0x6a,0xc0,0x05,0xfc,0xd5,0xff,0x20,
|
||||
0x01,0x30,0xa8,0x62,0x00,0x23,0xf6,0x1c,0xb0,0x08,0x0e,0xd0,0xb2,0x08,0x11,0x48,
|
||||
0x00,0x68,0x99,0x00,0x60,0x54,0x06,0x0a,0x09,0x19,0x4e,0x70,0x06,0x0c,0x00,0x0e,
|
||||
0x8e,0x70,0x5b,0x1c,0xc8,0x70,0x9a,0x42,0xf1,0xd8,0xff,0x20,0x01,0x30,0xa8,0x62,
|
||||
0x68,0x69,0xff,0x21,0x08,0x31,0x88,0x43,0x68,0x61,0x68,0x69,0x38,0x43,0x68,0x61,
|
||||
0x28,0x6a,0x80,0x08,0x80,0x00,0x28,0x62,0x28,0x6a,0x38,0x43,0x28,0x62,0x00,0x20,
|
||||
0x05,0xb0,0xf0,0xbd,0x80,0x00,0x00,0x0c,0x03,0x20,0x80,0x06,0x41,0x69,0xff,0x22,
|
||||
0x08,0x32,0x91,0x43,0x41,0x61,0x42,0x69,0x01,0x21,0x0a,0x43,0x42,0x61,0x02,0x6a,
|
||||
0x92,0x08,0x92,0x00,0x02,0x62,0x02,0x6a,0x0a,0x43,0x02,0x62,0x70,0x47,0x00,0x00,
|
||||
#define TRIM_STORE_ADDR 0x1000
|
||||
#define TRIM_READ_CMD_CODE_LEN 0x140
|
||||
#define TRIM_READ_CMD_CODE_CRC 0x3aa0
|
||||
const unsigned char TRIM_READ_CMD_CODE[] = {
|
||||
0x40, 0xba, 0x70, 0x47, 0xc0, 0xba, 0x70, 0x47, 0x01, 0x38, 0xfd, 0xd1, 0x70, 0x47, 0x00, 0x00, 0xf7, 0xb5, 0x03,
|
||||
0x25, 0xad, 0x06, 0x28, 0x6a, 0x82, 0xb0, 0x16, 0x46, 0x0c, 0x46, 0x40, 0x08, 0x40, 0x00, 0x28, 0x62, 0x28, 0x6a,
|
||||
0x02, 0x21, 0x08, 0x43, 0x28, 0x62, 0x28, 0x6a, 0x80, 0x07, 0xfc, 0xd4, 0x66, 0x20, 0x68, 0x60, 0x01, 0x27, 0x2f,
|
||||
0x61, 0xa8, 0x6a, 0xc0, 0x05, 0xfc, 0xd5, 0x99, 0x20, 0x68, 0x60, 0x2f, 0x61, 0xa8, 0x6a, 0xc0, 0x05, 0xfc, 0xd5,
|
||||
0xff, 0x20, 0x91, 0x30, 0xff, 0xf7, 0xda, 0xff, 0xff, 0x23, 0x01, 0x33, 0xab, 0x62, 0x68, 0x46, 0xef, 0x60, 0x35,
|
||||
0x21, 0x69, 0x60, 0x2f, 0x61, 0xa9, 0x6a, 0xc9, 0x05, 0xfc, 0xd5, 0xab, 0x62, 0xa9, 0x69, 0xef, 0x60, 0xc9, 0xb2,
|
||||
0x05, 0x22, 0x6a, 0x60, 0x2f, 0x61, 0xaa, 0x6a, 0xd2, 0x05, 0xfc, 0xd5, 0xab, 0x62, 0xaa, 0x69, 0x09, 0x02, 0xd2,
|
||||
0xb2, 0x11, 0x43, 0x01, 0x80, 0xc8, 0x07, 0x02, 0xd0, 0x03, 0x20, 0x05, 0xb0, 0xf0, 0xbd, 0xab, 0x62, 0x68, 0x69,
|
||||
0xff, 0x21, 0x08, 0x31, 0x88, 0x43, 0x68, 0x61, 0x68, 0x69, 0xc9, 0x1e, 0x08, 0x43, 0x68, 0x61, 0x02, 0x98, 0x00,
|
||||
0x02, 0x48, 0x30, 0x68, 0x60, 0x08, 0x20, 0xa8, 0x60, 0xee, 0x60, 0x2f, 0x61, 0xa8, 0x6a, 0xc0, 0x05, 0xfc, 0xd5,
|
||||
0xff, 0x20, 0x01, 0x30, 0xa8, 0x62, 0x00, 0x23, 0xf6, 0x1c, 0xb0, 0x08, 0x0e, 0xd0, 0xb2, 0x08, 0x11, 0x48, 0x00,
|
||||
0x68, 0x99, 0x00, 0x60, 0x54, 0x06, 0x0a, 0x09, 0x19, 0x4e, 0x70, 0x06, 0x0c, 0x00, 0x0e, 0x8e, 0x70, 0x5b, 0x1c,
|
||||
0xc8, 0x70, 0x9a, 0x42, 0xf1, 0xd8, 0xff, 0x20, 0x01, 0x30, 0xa8, 0x62, 0x68, 0x69, 0xff, 0x21, 0x08, 0x31, 0x88,
|
||||
0x43, 0x68, 0x61, 0x68, 0x69, 0x38, 0x43, 0x68, 0x61, 0x28, 0x6a, 0x80, 0x08, 0x80, 0x00, 0x28, 0x62, 0x28, 0x6a,
|
||||
0x38, 0x43, 0x28, 0x62, 0x00, 0x20, 0x05, 0xb0, 0xf0, 0xbd, 0x80, 0x00, 0x00, 0x0c, 0x03, 0x20, 0x80, 0x06, 0x41,
|
||||
0x69, 0xff, 0x22, 0x08, 0x32, 0x91, 0x43, 0x41, 0x61, 0x42, 0x69, 0x01, 0x21, 0x0a, 0x43, 0x42, 0x61, 0x02, 0x6a,
|
||||
0x92, 0x08, 0x92, 0x00, 0x02, 0x62, 0x02, 0x6a, 0x0a, 0x43, 0x02, 0x62, 0x70, 0x47, 0x00, 0x00,
|
||||
};
|
||||
typedef uint32_t (*trim_read_cmd_func_t)(uint32_t,uint8_t*,uint32_t);
|
||||
typedef uint32_t (*trim_read_cmd_func_t)(uint32_t, uint8_t*, uint32_t);
|
||||
trim_stored_t trim_stored;
|
||||
|
||||
/*******************************************************************************
|
||||
* Clock Definitions
|
||||
*******************************************************************************/
|
||||
uint32_t SystemCoreClock = SYSCLK_FREQ; /*!< System Clock Frequency (Core Clock) */
|
||||
uint32_t SystemCoreClock = SYSCLK_FREQ; /*!< System Clock Frequency (Core Clock) */
|
||||
static void RCC_HsiCalib(uint32_t systemfreq);
|
||||
|
||||
void SystemTrimValueRead(uint8_t* p_data,uint32_t byte_length)
|
||||
{
|
||||
uint32_t ramcode[TRIM_READ_CMD_CODE_LEN/4 +1 ];
|
||||
|
||||
void SystemTrimValueRead(uint8_t* p_data, uint32_t byte_length) {
|
||||
uint32_t ramcode[TRIM_READ_CMD_CODE_LEN / 4 + 1];
|
||||
trim_read_cmd_func_t trim_read_cmd_func = (trim_read_cmd_func_t)((uint8_t*)&ramcode[0] + 0x11);
|
||||
memcpy((void*)ramcode,(const void*)TRIM_READ_CMD_CODE,TRIM_READ_CMD_CODE_LEN);
|
||||
memcpy((void*)ramcode, (const void*)TRIM_READ_CMD_CODE, TRIM_READ_CMD_CODE_LEN);
|
||||
(*trim_read_cmd_func)(TRIM_STORE_ADDR, p_data, byte_length);
|
||||
}
|
||||
|
||||
trim_stored_t* SystemTrimValueGet(void)
|
||||
{
|
||||
//read the trim value if not in RAM yet
|
||||
if(trim_stored.stote_rc64m_trim_value == 0xFFFFFFFF || trim_stored.stote_rc64m_trim_value == 0)
|
||||
{
|
||||
SystemTrimValueRead((uint8_t*)&trim_stored,sizeof(trim_stored));
|
||||
trim_stored_t* SystemTrimValueGet(void) {
|
||||
// read the trim value if not in RAM yet
|
||||
if (trim_stored.stote_rc64m_trim_value == 0xFFFFFFFF || trim_stored.stote_rc64m_trim_value == 0) {
|
||||
SystemTrimValueRead((uint8_t*)&trim_stored, sizeof(trim_stored));
|
||||
}
|
||||
//check again if read trim value sucessful
|
||||
if(trim_stored.stote_rc64m_trim_value == 0xFFFFFFFF || trim_stored.stote_rc64m_trim_value == 0)
|
||||
{
|
||||
// check again if read trim value sucessful
|
||||
if (trim_stored.stote_rc64m_trim_value == 0xFFFFFFFF || trim_stored.stote_rc64m_trim_value == 0) {
|
||||
return NULL;
|
||||
}else{
|
||||
} else {
|
||||
return &trim_stored;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t* SystemGetUUID(void)
|
||||
{
|
||||
//read the trim value if not in RAM yet
|
||||
if(trim_stored.stote_rc64m_trim_value == 0xFFFFFFFF || trim_stored.stote_rc64m_trim_value == 0)
|
||||
{
|
||||
SystemTrimValueRead((uint8_t*)&trim_stored,sizeof(trim_stored));
|
||||
uint8_t* SystemGetUUID(void) {
|
||||
// read the trim value if not in RAM yet
|
||||
if (trim_stored.stote_rc64m_trim_value == 0xFFFFFFFF || trim_stored.stote_rc64m_trim_value == 0) {
|
||||
SystemTrimValueRead((uint8_t*)&trim_stored, sizeof(trim_stored));
|
||||
}
|
||||
//check again if read trim value sucessful
|
||||
if(trim_stored.stote_rc64m_trim_value == 0xFFFFFFFF || trim_stored.stote_rc64m_trim_value == 0)
|
||||
{
|
||||
// check again if read trim value sucessful
|
||||
if (trim_stored.stote_rc64m_trim_value == 0xFFFFFFFF || trim_stored.stote_rc64m_trim_value == 0) {
|
||||
return NULL;
|
||||
}else{
|
||||
} else {
|
||||
return trim_stored.flash_uuid;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
uint8_t* SystemGetMacAddr(void)
|
||||
{
|
||||
//read the trim value if not in RAM yet
|
||||
if(trim_stored.stote_rc64m_trim_value == 0xFFFFFFFF || trim_stored.stote_rc64m_trim_value == 0)
|
||||
{
|
||||
SystemTrimValueRead((uint8_t*)&trim_stored,sizeof(trim_stored));
|
||||
uint8_t* SystemGetMacAddr(void) {
|
||||
// read the trim value if not in RAM yet
|
||||
if (trim_stored.stote_rc64m_trim_value == 0xFFFFFFFF || trim_stored.stote_rc64m_trim_value == 0) {
|
||||
SystemTrimValueRead((uint8_t*)&trim_stored, sizeof(trim_stored));
|
||||
}
|
||||
//check again if read trim value sucessful
|
||||
if(trim_stored.stote_rc64m_trim_value == 0xFFFFFFFF || trim_stored.stote_rc64m_trim_value == 0)
|
||||
{
|
||||
// check again if read trim value sucessful
|
||||
if (trim_stored.stote_rc64m_trim_value == 0xFFFFFFFF || trim_stored.stote_rc64m_trim_value == 0) {
|
||||
return NULL;
|
||||
}else{
|
||||
} else {
|
||||
return &trim_stored.flash_uuid[5];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Setup the microcontroller system
|
||||
|
@ -172,63 +154,56 @@ uint8_t* SystemGetMacAddr(void)
|
|||
* SystemCoreClock variable.
|
||||
* @note This function should be used only after reset.
|
||||
*/
|
||||
void SystemInit(void)
|
||||
{
|
||||
uint32_t tmp;
|
||||
RCC->APB1PCLKEN |= RCC_APB1_PERIPH_PWR; // PWR enable
|
||||
PWR->VTOR_REG = 0x81000000; //set irq vtor to flash address
|
||||
void SystemInit(void) {
|
||||
uint32_t tmp;
|
||||
RCC->APB1PCLKEN |= RCC_APB1_PERIPH_PWR; // PWR enable
|
||||
PWR->VTOR_REG = 0x81000000; // set irq vtor to flash address
|
||||
|
||||
*(uint32_t*)0x40007014 = 0x0000080F;
|
||||
*(uint32_t*)0x40007020 = 0x00020018;
|
||||
*(uint32_t*)0x40007014 = 0x0000080F;
|
||||
*(uint32_t*)0x40007020 = 0x00020018;
|
||||
*(uint32_t*)0x40011000 &= ~0xC000;
|
||||
|
||||
SystemTrimValueRead((uint8_t*)&trim_stored,sizeof(trim_stored));
|
||||
SystemTrimValueRead((uint8_t*)&trim_stored, sizeof(trim_stored));
|
||||
/* check otp has been write */
|
||||
if(trim_stored.stote_rc64m_trim_value == 0xFFFFFFFF || trim_stored.stote_rc64m_trim_value == 0)
|
||||
{
|
||||
RCC->CFG |= RCC_CFG_HSISRC_DIV1; // USE HSI as system clock
|
||||
if (trim_stored.stote_rc64m_trim_value == 0xFFFFFFFF || trim_stored.stote_rc64m_trim_value == 0) {
|
||||
RCC->CFG |= RCC_CFG_HSISRC_DIV1; // USE HSI as system clock
|
||||
RCC->CFG &= ~RCC_CFG_APB1PRES;
|
||||
RCC->CFG |= RCC_HCLK_DIV2; //APB1 = HCLK/2, APB1 max is 32M
|
||||
RCC->CFG |= RCC_HCLK_DIV2; // APB1 = HCLK/2, APB1 max is 32M
|
||||
/* Calib from HSE */
|
||||
RCC_HsiCalib(SYSCLK_FREQ);
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = (PWR->reserved4)&(~0X1F);
|
||||
tmp |= (trim_stored.stote_bg_vtrim_value)&0X1F;
|
||||
} else {
|
||||
tmp = (PWR->reserved4) & (~0X1F);
|
||||
tmp |= (trim_stored.stote_bg_vtrim_value) & 0X1F;
|
||||
PWR->reserved4 = tmp;
|
||||
if(SYSCLK_FREQ == 64000000)
|
||||
{
|
||||
RCC->CTRL &= ~0x8000;// Set HSI as 64M
|
||||
if (SYSCLK_FREQ == 64000000) {
|
||||
RCC->CTRL &= ~0x8000; // Set HSI as 64M
|
||||
/* Configures LSI trim */
|
||||
tmp = RCC->CTRL & ~(0x7F << 8); // TRIM 8-14 bit
|
||||
RCC->CTRL = tmp|(trim_stored.stote_rc64m_trim_value << 8);// clear and set TRIM value
|
||||
|
||||
RCC->CFG |= RCC_CFG_HSISRC_DIV1; // USE HSI as system clock
|
||||
|
||||
tmp = RCC->CTRL & ~(0x7F << 8); // TRIM 8-14 bit
|
||||
RCC->CTRL = tmp | (trim_stored.stote_rc64m_trim_value << 8); // clear and set TRIM value
|
||||
|
||||
RCC->CFG |= RCC_CFG_HSISRC_DIV1; // USE HSI as system clock
|
||||
|
||||
RCC->CFG &= ~RCC_CFG_APB1PRES;
|
||||
RCC->CFG |= RCC_HCLK_DIV2; //APB1 = HCLK/2, APB1 max is 32M
|
||||
}
|
||||
// else if(SYSCLK_FREQ == 96000000)
|
||||
// {
|
||||
// RCC->CTRL |= 0x8000; // Set HSI as 96M
|
||||
// /* Configures LSI trim */
|
||||
// tmp = RCC->CTRL & ~(0x7F << 8); // TRIM 8-14 bit
|
||||
// RCC->CTRL = tmp|(trim_stored.stote_rc96m_trim_value << 8);// clear and set TRIM value
|
||||
//
|
||||
// RCC->CFG |= RCC_CFG_HSISRC_DIV1; // USE HSI as system clock
|
||||
// tmp = RCC->CFG & ~RCC_CFG_APB1PRES;
|
||||
// RCC->CFG |= RCC_HCLK_DIV4; //APB1 = HCLK/4, APB1 max is 32M
|
||||
//
|
||||
// tmp = RCC->CFG & ~RCC_CFG_APB2PRES;
|
||||
// RCC->CFG |= RCC_HCLK_DIV4<<3; //APB2 = HCLK/2, APB1 max is 64M
|
||||
// }
|
||||
RCC->CFG |= RCC_HCLK_DIV2; // APB1 = HCLK/2, APB1 max is 32M
|
||||
}
|
||||
// else if(SYSCLK_FREQ == 96000000)
|
||||
// {
|
||||
// RCC->CTRL |= 0x8000; // Set HSI as 96M
|
||||
// /* Configures LSI trim */
|
||||
// tmp = RCC->CTRL & ~(0x7F << 8); // TRIM 8-14 bit
|
||||
// RCC->CTRL = tmp|(trim_stored.stote_rc96m_trim_value << 8);// clear and set TRIM value
|
||||
//
|
||||
// RCC->CFG |= RCC_CFG_HSISRC_DIV1; // USE HSI as system clock
|
||||
// tmp = RCC->CFG & ~RCC_CFG_APB1PRES;
|
||||
// RCC->CFG |= RCC_HCLK_DIV4; //APB1 = HCLK/4, APB1 max is 32M
|
||||
//
|
||||
// tmp = RCC->CFG & ~RCC_CFG_APB2PRES;
|
||||
// RCC->CFG |= RCC_HCLK_DIV4<<3; //APB2 = HCLK/2, APB1 max is 64M
|
||||
// }
|
||||
/* Configures LSI trim */
|
||||
RCC->LSCTRL &= ~RCC_LSCTRL_LSTTRIM;
|
||||
RCC->LSCTRL |= trim_stored.stote_rc32768_trim_value << 8;
|
||||
|
||||
RCC->LSCTRL |= trim_stored.stote_rc32768_trim_value << 8;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -245,103 +220,84 @@ void SystemInit(void)
|
|||
* frequency in the chip. It is calculated based on the predefined
|
||||
* constant and the selected clock source:
|
||||
*/
|
||||
void SystemCoreClockUpdate(void)
|
||||
{
|
||||
void SystemCoreClockUpdate(void) {
|
||||
SystemCoreClock = HSI_VALUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief dealy cycles.
|
||||
*/
|
||||
__attribute__((naked)) void system_delay_cycles(uint32_t i)
|
||||
{
|
||||
asm volatile(
|
||||
"sub r0, #1\n"
|
||||
"bne system_delay_cycles\n"
|
||||
"bx lr"
|
||||
);
|
||||
void system_delay_cycles(uint32_t i) {
|
||||
for (volatile uint32_t j = i; j > 0; j--) {
|
||||
j = j;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Dealy 10 us
|
||||
*/
|
||||
void system_delay_n_10us(uint32_t value)
|
||||
{
|
||||
system_delay_cycles(107*value);
|
||||
void system_delay_n_10us(uint32_t value) {
|
||||
system_delay_cycles(107 * value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable the HSI and calibration it.
|
||||
*/
|
||||
static void RCC_HsiCalib(uint32_t systemfreq)
|
||||
{
|
||||
|
||||
uint32_t g_hsi_accuracy = 0;
|
||||
uint32_t g_timeoutcnt = 1000;
|
||||
static void RCC_HsiCalib(uint32_t systemfreq) {
|
||||
uint32_t g_hsi_accuracy = 0;
|
||||
uint32_t g_timeoutcnt = 1000;
|
||||
uint32_t g_cal_hsi_cnt_value = 1024;
|
||||
|
||||
uint32_t delta =0;
|
||||
uint32_t min = 0;
|
||||
uint32_t max = 127; //32M TRIM 8-14 bit
|
||||
uint32_t mid = (RCC->CTRL >> 8) & 0x7F;
|
||||
uint16_t count_value = 0;
|
||||
uint32_t hsi_timeoutcnt = 0;
|
||||
uint8_t tmp_trim;
|
||||
uint32_t delta = 0;
|
||||
uint32_t min = 0;
|
||||
uint32_t max = 127; // 32M TRIM 8-14 bit
|
||||
uint32_t mid = (RCC->CTRL >> 8) & 0x7F;
|
||||
uint16_t count_value = 0;
|
||||
uint32_t hsi_timeoutcnt = 0;
|
||||
uint8_t tmp_trim;
|
||||
|
||||
if(systemfreq == 64000000)
|
||||
{
|
||||
if (systemfreq == 64000000) {
|
||||
RCC->CTRL &= ~0x8000;
|
||||
g_cal_hsi_cnt_value = 2048; //for 64M
|
||||
}
|
||||
else
|
||||
{
|
||||
g_cal_hsi_cnt_value = 2048; // for 64M
|
||||
} else {
|
||||
RCC->CTRL |= 0x8000;
|
||||
g_cal_hsi_cnt_value = 3072; //for 96M
|
||||
g_cal_hsi_cnt_value = 3072; // for 96M
|
||||
}
|
||||
|
||||
do{
|
||||
uint32_t tmp = RCC->CTRL & ~(0x7F << 8); //32M TRIM 8-14 bit
|
||||
RCC->CTRL = tmp| (mid << 8); // clear and set TRIM value //and start to cnt
|
||||
system_delay_cycles(5); // delay scape
|
||||
while(1)
|
||||
{
|
||||
system_delay_cycles(1);
|
||||
if((RCC->OSCFCSR & 0x02))
|
||||
{
|
||||
|
||||
do {
|
||||
uint32_t tmp = RCC->CTRL & ~(0x7F << 8); // 32M TRIM 8-14 bit
|
||||
RCC->CTRL = tmp | (mid << 8); // clear and set TRIM value //and start to cnt
|
||||
system_delay_cycles(5); // delay scape
|
||||
while (1) {
|
||||
system_delay_cycles(1);
|
||||
if ((RCC->OSCFCSR & 0x02)) {
|
||||
break;
|
||||
}
|
||||
if(hsi_timeoutcnt++ > g_timeoutcnt)
|
||||
{
|
||||
}
|
||||
if (hsi_timeoutcnt++ > g_timeoutcnt) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
count_value = RCC->OSCFCHSICNT; //ready cnt value
|
||||
if(count_value > g_cal_hsi_cnt_value)
|
||||
{
|
||||
delta = count_value - g_cal_hsi_cnt_value;
|
||||
}
|
||||
else
|
||||
{
|
||||
delta = g_cal_hsi_cnt_value - count_value;
|
||||
}
|
||||
|
||||
if(count_value >= g_cal_hsi_cnt_value)
|
||||
{
|
||||
max = mid;
|
||||
count_value = RCC->OSCFCHSICNT; // ready cnt value
|
||||
if (count_value > g_cal_hsi_cnt_value) {
|
||||
delta = count_value - g_cal_hsi_cnt_value;
|
||||
} else {
|
||||
delta = g_cal_hsi_cnt_value - count_value;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (count_value >= g_cal_hsi_cnt_value) {
|
||||
max = mid;
|
||||
} else {
|
||||
min = mid;
|
||||
}
|
||||
|
||||
tmp_trim = (min + max)/2;
|
||||
if(tmp_trim == mid ) //0 and 127 if not used
|
||||
|
||||
tmp_trim = (min + max) / 2;
|
||||
if (tmp_trim == mid) // 0 and 127 if not used
|
||||
{
|
||||
break;
|
||||
}
|
||||
mid = tmp_trim;
|
||||
}while(delta > g_hsi_accuracy);
|
||||
} while (delta > g_hsi_accuracy);
|
||||
RCC->CFG &= ~1;
|
||||
while((RCC->CFG & (1<<2)));
|
||||
while ((RCC->CFG & (1 << 2)))
|
||||
;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
/*****************************************************************************
|
||||
* Copyright (c) 2019, Nations Technologies Inc.
|
||||
*
|
||||
* All rights reserved.
|
||||
* ****************************************************************************
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Nations' name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAYS OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file ns_ble.h
|
||||
* @author Nations Firmware Team
|
||||
* @version v1.0.1
|
||||
*
|
||||
* @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
|
||||
*/
|
||||
#ifndef __APP_BLE_H__
|
||||
#define __APP_BLE_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "ns_ble.h"
|
||||
#include "ns_ble_task.h"
|
||||
|
||||
/// User Task messages
|
||||
enum user_msg_id
|
||||
{
|
||||
APP_USER_DEMO_EVE = APP_FREE_EVE_FOR_USER,
|
||||
APP_CUSTS_TEST_EVT,
|
||||
|
||||
};
|
||||
|
||||
/* ble application initialization */
|
||||
void app_ble_init(void);
|
||||
void app_ble_gap_params_init(void);
|
||||
void app_ble_adv_init(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __APP_BLE_H__ */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
|
@ -0,0 +1,70 @@
|
|||
/*****************************************************************************
|
||||
* Copyright (c) 2019, Nations Technologies Inc.
|
||||
*
|
||||
* All rights reserved.
|
||||
* ****************************************************************************
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Nations' name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAYS OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file app_gpio.h
|
||||
* @author Nations Firmware Team
|
||||
* @version v1.0.0
|
||||
*
|
||||
* @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
|
||||
*/
|
||||
#ifndef __APP_GPIO_H__
|
||||
#define __APP_GPIO_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "n32wb03x.h"
|
||||
|
||||
#define LED1_PORT GPIOB
|
||||
#define LED1_PIN GPIO_PIN_0
|
||||
#define LED2_PORT GPIOA
|
||||
#define LED2_PIN GPIO_PIN_6
|
||||
|
||||
|
||||
void LedInit(GPIO_Module* GPIOx, uint16_t Pin);
|
||||
void LedOn(GPIO_Module* GPIOx, uint16_t Pin);
|
||||
void LedOff(GPIO_Module* GPIOx, uint16_t Pin);
|
||||
void LedBlink(GPIO_Module* GPIOx, uint16_t Pin);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __APP_GPIO_H__ */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
|
@ -0,0 +1,137 @@
|
|||
/*****************************************************************************
|
||||
* Copyright (c) 2019, Nations Technologies Inc.
|
||||
*
|
||||
* All rights reserved.
|
||||
* ****************************************************************************
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Nations' name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file app_dis.h
|
||||
* @author Nations Firmware Team
|
||||
* @version v1.0.0
|
||||
*
|
||||
* @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef APP_DIS_H_
|
||||
#define APP_DIS_H_
|
||||
|
||||
/**
|
||||
* @addtogroup APP
|
||||
*
|
||||
* @brief Device Information Application Module Entry point.
|
||||
*
|
||||
* @{
|
||||
**/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
#include "rwip_config.h" // SW Configuration
|
||||
|
||||
#if (BLE_APP_DIS)
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* Define ------------------------------------------------------------*/
|
||||
|
||||
/// Manufacturer Name Value
|
||||
#define APP_DIS_MANUFACTURER_NAME ("Nations")
|
||||
#define APP_DIS_MANUFACTURER_NAME_LEN (7)
|
||||
|
||||
/// Model Number String Value
|
||||
#define APP_DIS_MODEL_NB_STR ("NS-BLE-1.0")
|
||||
#define APP_DIS_MODEL_NB_STR_LEN (10)
|
||||
|
||||
/// Serial Number
|
||||
#define APP_DIS_SERIAL_NB_STR ("1.0.0.0-LE")
|
||||
#define APP_DIS_SERIAL_NB_STR_LEN (10)
|
||||
|
||||
/// Firmware Revision
|
||||
#define APP_DIS_FIRM_REV_STR ("1.0.0")
|
||||
#define APP_DIS_FIRM_REV_STR_LEN (5)
|
||||
|
||||
/// System ID Value - LSB -> MSB
|
||||
#define APP_DIS_SYSTEM_ID ("\x12\x34\x56\xFF\xFE\x9A\xBC\xDE")
|
||||
#define APP_DIS_SYSTEM_ID_LEN (8)
|
||||
|
||||
/// Hardware Revision String
|
||||
#define APP_DIS_HARD_REV_STR ("1.0.0")
|
||||
#define APP_DIS_HARD_REV_STR_LEN (5)
|
||||
|
||||
/// Software Revision String
|
||||
#define APP_DIS_SW_REV_STR ("1.0.0")
|
||||
#define APP_DIS_SW_REV_STR_LEN (5)
|
||||
|
||||
/// IEEE
|
||||
#define APP_DIS_IEEE ("\xFF\xEE\xDD\xCC\xBB\xAA")
|
||||
#define APP_DIS_IEEE_LEN (6)
|
||||
|
||||
/**
|
||||
* PNP ID Value - LSB -> MSB
|
||||
* Vendor ID Source : 0x02 (USB Implementer’s Forum assigned Vendor ID value)
|
||||
* Vendor ID : 0x045E (Microsoft Corp)
|
||||
* Product ID : 0x0040
|
||||
* Product Version : 0x0300
|
||||
*/
|
||||
#define APP_DIS_PNP_ID ("\x02\x5E\x04\x40\x00\x00\x03")
|
||||
#define APP_DIS_PNP_ID_LEN (7)
|
||||
|
||||
#if (BLE_APP_HID)
|
||||
#define APP_DIS_FEATURES (DIS_MANUFACTURER_NAME_CHAR_SUP_BIT |\
|
||||
DIS_MODEL_NB_STR_CHAR_SUP_BIT |\
|
||||
DIS_SYSTEM_ID_CHAR_SUP_BIT |\
|
||||
DIS_PNP_ID_CHAR_SUP_BIT)
|
||||
|
||||
#else
|
||||
#define APP_DIS_FEATURES (DIS_ALL_FEAT_SUP)
|
||||
#endif //(BLE_APP_HID)
|
||||
|
||||
|
||||
/* Public variables ---------------------------------------------------------*/
|
||||
|
||||
/// Table of message handlers
|
||||
extern const struct app_subtask_handlers app_dis_handlers;
|
||||
|
||||
/* Public function prototypes -----------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief Initialize Device Information Service Application
|
||||
**/
|
||||
void app_dis_init(void);
|
||||
|
||||
/**
|
||||
* @brief Add a Device Information Service instance in the DB
|
||||
**/
|
||||
void app_dis_add_dis(void);
|
||||
|
||||
/**
|
||||
* @brief Enable the Device Information Service
|
||||
**/
|
||||
void app_dis_enable_prf(uint16_t conhdl);
|
||||
|
||||
#endif //BLE_APP_DIS
|
||||
|
||||
/// @} APP
|
||||
|
||||
#endif //APP_DIS_H_
|
|
@ -0,0 +1,118 @@
|
|||
/*****************************************************************************
|
||||
* Copyright (c) 2019, Nations Technologies Inc.
|
||||
*
|
||||
* All rights reserved.
|
||||
* ****************************************************************************
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Nations' name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file app_hrps.h
|
||||
* @author Nations Firmware Team
|
||||
* @version v1.0.0
|
||||
*
|
||||
* @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef APP_HRPS_H_
|
||||
#define APP_HRPS_H_
|
||||
|
||||
/**
|
||||
* @addtogroup APP
|
||||
*
|
||||
* @brief Heart Rate Application Module Entry point.
|
||||
*
|
||||
* @{
|
||||
**/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
#include "rwip_config.h" // SW Configuration
|
||||
|
||||
#if (BLE_APP_HRPS)
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* Define ------------------------------------------------------------*/
|
||||
|
||||
#define APP_HRPS_FEATURES (0x04) //HRPS ALL FEATURES 0x07
|
||||
|
||||
#define HEART_RATE_SEND_DELAY 1000
|
||||
|
||||
enum hrps_cfg
|
||||
{
|
||||
HRPS_CFG_NTF_EN = 1,
|
||||
};
|
||||
|
||||
/// Heart Rate Application Module Environment Structure
|
||||
struct app_hrps_env_tag
|
||||
{
|
||||
/// Connection handle
|
||||
uint8_t conidx;
|
||||
/// Heart Rate Value
|
||||
uint8_t hrps_value;
|
||||
};
|
||||
|
||||
/// Heart Rate Application environment
|
||||
extern struct app_hrps_env_tag app_hrps_env;
|
||||
|
||||
extern uint16_t heart_rate_timer_id;
|
||||
|
||||
/* Public variables ---------------------------------------------------------*/
|
||||
|
||||
/// Table of message handlers
|
||||
extern const struct app_subtask_handlers app_hrps_handlers;
|
||||
|
||||
/* Public function prototypes -----------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief Initialize Heart Rate Service Application
|
||||
**/
|
||||
void app_hrps_init(void);
|
||||
|
||||
/**
|
||||
* @brief Add a Heart Rate Service in the DB
|
||||
**/
|
||||
void app_hrps_add_hrps(void);
|
||||
|
||||
/**
|
||||
* @brief Enable the Heart Rate profile
|
||||
**/
|
||||
void app_hrps_enable_prf(uint8_t conidx, uint8_t cfg);
|
||||
|
||||
/**
|
||||
* @brief Send heart rate value
|
||||
*/
|
||||
void app_heart_rate_send(uint16_t heart_rate);
|
||||
|
||||
/**
|
||||
* @brief Send heart rate value periodically
|
||||
*/
|
||||
void app_heart_rate_timeout_handler(void);
|
||||
|
||||
#endif //BLE_APP_HRPS
|
||||
|
||||
/// @} APP
|
||||
|
||||
#endif //APP_HRPS_H_
|
||||
|
|
@ -0,0 +1,110 @@
|
|||
/*****************************************************************************
|
||||
* Copyright (c) 2019, Nations Technologies Inc.
|
||||
*
|
||||
* All rights reserved.
|
||||
* ****************************************************************************
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Nations' name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file rwapp_config.h
|
||||
* @author Nations Firmware Team
|
||||
* @version v1.0.0
|
||||
*
|
||||
* @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _RWAPP_CONFIG_H_
|
||||
#define _RWAPP_CONFIG_H_
|
||||
|
||||
/**
|
||||
* @addtogroup app
|
||||
* @brief Application configuration definition
|
||||
*
|
||||
* @{
|
||||
**/
|
||||
|
||||
#include "app_user_config.h"
|
||||
#include "rwip_config.h"
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
/* Define ------------------------------------------------------------*/
|
||||
|
||||
|
||||
/// Application Profile
|
||||
#if defined(CFG_APP_PRF)
|
||||
#define BLE_APP_PRF 1
|
||||
#else // defined(CFG_APP_PRF)
|
||||
#define BLE_APP_PRF 0
|
||||
#endif // defined(CFG_APP_PRF)
|
||||
|
||||
|
||||
/// Health Thermometer Application
|
||||
#if defined(CFG_APP_HT)
|
||||
#define BLE_APP_HT 1
|
||||
#else // defined(CFG_APP_HT)
|
||||
#define BLE_APP_HT 0
|
||||
#endif // defined(CFG_APP_HT)
|
||||
|
||||
/// HID Application
|
||||
#if defined(CFG_APP_HID)
|
||||
#define BLE_APP_HID 1
|
||||
#else // defined(CFG_APP_HID)
|
||||
#define BLE_APP_HID 0
|
||||
#endif // defined(CFG_APP_HID)
|
||||
|
||||
/// DIS Application
|
||||
#if defined(CFG_APP_DIS)
|
||||
#define BLE_APP_DIS 1
|
||||
#else // defined(CFG_APP_DIS)
|
||||
#define BLE_APP_DIS 0
|
||||
#endif // defined(CFG_APP_DIS)
|
||||
|
||||
|
||||
|
||||
/// Battery Service Application
|
||||
#if (CFG_APP_BATT)
|
||||
#define BLE_APP_BATT 1
|
||||
#else
|
||||
#define BLE_APP_BATT 0
|
||||
#endif //(CFG_APP_BATT)
|
||||
|
||||
/// Security Application
|
||||
#if (defined(CFG_APP_SEC) || BLE_APP_HID)
|
||||
#define BLE_APP_SEC 1
|
||||
#else //(defined(CFG_APP_SEC) || BLE_APP_HID)
|
||||
#define BLE_APP_SEC 0
|
||||
#endif //(defined(CFG_APP_SEC) || BLE_APP_HID)
|
||||
|
||||
|
||||
#define AM0_APP_OPTIONAL_CHARACTERISTICS 0
|
||||
|
||||
#if defined(CFG_APP_NS_IUS)
|
||||
#define BLE_APP_NS_IUS 1
|
||||
#else // defined(CFG_APP_NS_IUS)
|
||||
#define BLE_APP_NS_IUS 0
|
||||
#endif // defined(CFG_APP_NS_IUS)
|
||||
|
||||
/// @} rwapp_config
|
||||
|
||||
#endif /* _RWAPP_CONFIG_H_ */
|
|
@ -0,0 +1,118 @@
|
|||
/*****************************************************************************
|
||||
* Copyright (c) 2019, Nations Technologies Inc.
|
||||
*
|
||||
* All rights reserved.
|
||||
* ****************************************************************************
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Nations' name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file app_user_config.h
|
||||
* @author Nations Firmware Team
|
||||
* @version v1.0.1
|
||||
*
|
||||
* @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
#ifndef _APP_USER_CONFIG_H_
|
||||
#define _APP_USER_CONFIG_H_
|
||||
|
||||
#include "ns_adv_data_def.h"
|
||||
|
||||
/* Device name */
|
||||
#define CUSTOM_DEVICE_NAME "NS_Heart_Rate"
|
||||
|
||||
/* adv configer*/
|
||||
#define CUSTOM_ADV_FAST_INTERVAL 160 /**< Fast advertising interval (in units of 0.625 ms. This value corresponds to 100 ms.). */
|
||||
#define CUSTOM_ADV_SLOW_INTERVAL 3200 /**< Slow advertising interval (in units of 0.625 ms. This value corresponds to 2 seconds). */
|
||||
|
||||
#define CUSTOM_ADV_FAST_DURATION 0 /**< The advertising duration of fast advertising in units of 1 seconds. maximum is 655 seconds */
|
||||
#define CUSTOM_ADV_SLOW_DURATION 180 /**< The advertising duration of slow advertising in units of 1 seconds. maximum is 655 seconds */
|
||||
|
||||
// Advertise data
|
||||
#define CUSTOM_USER_ADVERTISE_DATA \
|
||||
"\x03"\
|
||||
ADV_TYPE_SERVICE_DATA_16BIT_UUID\
|
||||
ADV_UUID_HEART_RATE_SERVICE\
|
||||
|
||||
|
||||
#define CUSTOM_USER_ADVERTISE_DATA_LEN (sizeof(CUSTOM_USER_ADVERTISE_DATA)-1)
|
||||
|
||||
// Scan response data
|
||||
#define CUSTOM_USER_ADV_SCNRSP_DATA \
|
||||
"\x0a"\
|
||||
ADV_TYPE_MANUFACTURER_SPECIFIC_DATA\
|
||||
"\xff\xffNations"
|
||||
|
||||
// Scan response data length- maximum 31 bytes
|
||||
#define CUSTOM_USER_ADV_SCNRSP_DATA_LEN (sizeof(CUSTOM_USER_ADV_SCNRSP_DATA)-1)
|
||||
|
||||
|
||||
/* connection config */
|
||||
#define MIN_CONN_INTERVAL 15 /**< Minimum connection interval (15 ms) */
|
||||
#define MAX_CONN_INTERVAL 30 /**< Maximum connection interval (30 ms). */
|
||||
#define SLAVE_LATENCY 0 /**< Slave latency. */
|
||||
#define CONN_SUP_TIMEOUT 5000 /**< Connection supervisory timeout (5000ms). */
|
||||
|
||||
#define FIRST_CONN_PARAMS_UPDATE_DELAY (5000) /**< Time of initiating event to update connection params (5 seconds). */
|
||||
|
||||
//sec config
|
||||
#define SEC_PARAM_IO_CAPABILITIES GAP_IO_CAP_NO_INPUT_NO_OUTPUT /**< No I/O capabilities. (@enum gap_io_cap) */
|
||||
#define SEC_PARAM_OOB 0 /**< Out Of Band data not available. */
|
||||
#define SEC_PARAM_KEY_SIZE 16 /**< Minimum encryption key size. 7 to 16 */
|
||||
#define SEC_PARAM_BOND 1 /**< Perform bonding. */
|
||||
#define SEC_PARAM_MITM 1 /**< Man In The Middle protection not required. */
|
||||
#define SEC_PARAM_LESC 0 /**< LE Secure Connections not enabled. */
|
||||
#define SEC_PARAM_KEYPRESS 0 /**< Keypress notifications not enabled. */
|
||||
#define SEC_PARAM_IKEY GAP_KDIST_NONE /**< Initiator Key Distribution. (@enum gap_kdist) */
|
||||
#define SEC_PARAM_RKEY GAP_KDIST_ENCKEY /**< Responder Key Distribution. (@enum gap_kdist) */
|
||||
#define SEC_PARAM_SEC_MODE_LEVEL GAP_NO_SEC /**< Device security requirements (minimum security level). (@enum see gap_sec_req) */
|
||||
|
||||
//bond conifg
|
||||
#define MAX_BOND_PEER 5
|
||||
#define BOND_STORE_ENABLE 0
|
||||
#define BOND_DATA_BASE_ADDR 0x0103B000
|
||||
|
||||
/* profiles config */
|
||||
#define CFG_APP_DIS 1
|
||||
#define CFG_PRF_DISS 1
|
||||
#define CFG_PRF_HRPS 1
|
||||
#define BLE_APP_HRPS 1
|
||||
|
||||
/* User config */
|
||||
|
||||
#define NS_LOG_ERROR_ENABLE 1
|
||||
#define NS_LOG_WARNING_ENABLE 1
|
||||
#define NS_LOG_INFO_ENABLE 1
|
||||
#define NS_LOG_DEBUG_ENABLE 0
|
||||
|
||||
#define NS_LOG_LPUART_ENABLE 1
|
||||
|
||||
#define NS_TIMER_ENABLE 1
|
||||
|
||||
#define FIRMWARE_VERSION "1.0.0"
|
||||
#define HARDWARE_VERSION "1.0.0"
|
||||
|
||||
|
||||
|
||||
#endif // _APP_USER_CONFIG_H_
|
||||
|
|
@ -0,0 +1,306 @@
|
|||
/*****************************************************************************
|
||||
* Copyright (c) 2019, Nations Technologies Inc.
|
||||
*
|
||||
* All rights reserved.
|
||||
* ****************************************************************************
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Nations' name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file app_ble.c
|
||||
* @author Nations Firmware Team
|
||||
* @version v1.0.2
|
||||
*
|
||||
* @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include "n32wb03x.h"
|
||||
#include "gapm_task.h" // GAP Manager Task API
|
||||
#include "app_ble.h"
|
||||
#include "app_gpio.h"
|
||||
#include "ns_sec.h"
|
||||
#include "app_hrps.h"
|
||||
#include "app_dis.h"
|
||||
#include "app_user_config.h"
|
||||
/** @addtogroup
|
||||
* @{
|
||||
*/
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
void app_ble_connected(void);
|
||||
void app_ble_disconnected(void);
|
||||
|
||||
/**
|
||||
* @brief user message handler
|
||||
* @param
|
||||
* @return
|
||||
* @note
|
||||
*/
|
||||
void app_user_msg_handler(ke_msg_id_t const msgid, void const *p_param)
|
||||
{
|
||||
|
||||
switch (msgid)
|
||||
{
|
||||
case APP_CUSTS_TEST_EVT:
|
||||
|
||||
break;
|
||||
// case :
|
||||
// break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ble message handler
|
||||
* @param
|
||||
* @return
|
||||
* @note
|
||||
*/
|
||||
void app_ble_msg_handler(struct ble_msg_t const *p_ble_msg)
|
||||
{
|
||||
switch (p_ble_msg->msg_id)
|
||||
{
|
||||
case APP_BLE_OS_READY:
|
||||
NS_LOG_INFO("APP_BLE_OS_READY\r\n");
|
||||
break;
|
||||
case APP_BLE_GAP_CONNECTED:
|
||||
app_ble_connected();
|
||||
break;
|
||||
case APP_BLE_GAP_DISCONNECTED:
|
||||
app_ble_disconnected();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief advertising message handler
|
||||
* @param
|
||||
* @return
|
||||
* @note
|
||||
*/
|
||||
void app_ble_adv_msg_handler(enum app_adv_mode adv_mode)
|
||||
{
|
||||
switch (adv_mode)
|
||||
{
|
||||
case APP_ADV_MODE_DIRECTED:
|
||||
|
||||
break;
|
||||
case APP_ADV_MODE_FAST:
|
||||
|
||||
break;
|
||||
case APP_ADV_MODE_SLOW:
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief ble GAP initialization
|
||||
* @param
|
||||
* @return
|
||||
* @note
|
||||
*/
|
||||
void app_ble_gap_params_init(void)
|
||||
{
|
||||
struct ns_gap_params_t dev_info = {0};
|
||||
uint8_t *p_mac = SystemGetMacAddr();
|
||||
//get UUID from trim stored
|
||||
if(p_mac != NULL)
|
||||
{
|
||||
//set the uuid as mac address
|
||||
memcpy(dev_info.mac_addr.addr, p_mac , BD_ADDR_LEN);
|
||||
}
|
||||
else{
|
||||
memcpy(dev_info.mac_addr.addr, "\x01\x02\x03\x04\x05\x06" , BD_ADDR_LEN);
|
||||
}
|
||||
|
||||
|
||||
/* init params*/
|
||||
dev_info.mac_addr_type = GAPM_STATIC_ADDR;
|
||||
dev_info.appearance = 0;
|
||||
dev_info.dev_role = GAP_ROLE_PERIPHERAL;
|
||||
|
||||
dev_info.dev_name_len = sizeof(CUSTOM_DEVICE_NAME)-1;
|
||||
memcpy(dev_info.dev_name, CUSTOM_DEVICE_NAME, dev_info.dev_name_len);
|
||||
|
||||
dev_info.dev_conn_param.intv_min = MSECS_TO_UNIT(MIN_CONN_INTERVAL,MSECS_UNIT_1_25_MS);
|
||||
dev_info.dev_conn_param.intv_max = MSECS_TO_UNIT(MAX_CONN_INTERVAL,MSECS_UNIT_1_25_MS);
|
||||
dev_info.dev_conn_param.latency = SLAVE_LATENCY;
|
||||
dev_info.dev_conn_param.time_out = MSECS_TO_UNIT(CONN_SUP_TIMEOUT,MSECS_UNIT_10_MS);
|
||||
dev_info.conn_param_update_delay = FIRST_CONN_PARAMS_UPDATE_DELAY;
|
||||
|
||||
ns_ble_gap_init(&dev_info);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief ble advertising initialization
|
||||
* @param
|
||||
* @return
|
||||
* @note
|
||||
*/
|
||||
void app_ble_adv_init(void)
|
||||
{
|
||||
struct ns_adv_params_t user_adv = {0};
|
||||
|
||||
//init advertising data
|
||||
user_adv.adv_data_len = CUSTOM_USER_ADVERTISE_DATA_LEN;
|
||||
memcpy(user_adv.adv_data,CUSTOM_USER_ADVERTISE_DATA,CUSTOM_USER_ADVERTISE_DATA_LEN);
|
||||
user_adv.scan_rsp_data_len = CUSTOM_USER_ADV_SCNRSP_DATA_LEN;
|
||||
memcpy(user_adv.scan_rsp_data,CUSTOM_USER_ADV_SCNRSP_DATA,CUSTOM_USER_ADV_SCNRSP_DATA_LEN);
|
||||
|
||||
user_adv.attach_appearance = false;
|
||||
user_adv.attach_name = true;
|
||||
user_adv.ex_adv_enable = false;
|
||||
user_adv.adv_phy = PHY_1MBPS_VALUE;
|
||||
|
||||
//init advertising params
|
||||
user_adv.directed_adv.enable = false;
|
||||
|
||||
user_adv.fast_adv.enable = true;
|
||||
user_adv.fast_adv.duration = CUSTOM_ADV_FAST_DURATION;
|
||||
user_adv.fast_adv.adv_intv = CUSTOM_ADV_FAST_INTERVAL;
|
||||
|
||||
user_adv.slow_adv.enable = true;
|
||||
user_adv.slow_adv.duration = CUSTOM_ADV_SLOW_DURATION;
|
||||
user_adv.slow_adv.adv_intv = CUSTOM_ADV_SLOW_INTERVAL;
|
||||
|
||||
user_adv.ble_adv_msg_handler = app_ble_adv_msg_handler;
|
||||
|
||||
ns_ble_adv_init(&user_adv);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void app_ble_sec_init(void)
|
||||
{
|
||||
struct ns_sec_init_t sec_init = {0};
|
||||
|
||||
sec_init.rand_pin_enable = false;
|
||||
sec_init.pin_code = 123456;
|
||||
|
||||
sec_init.pairing_feat.auth = ( SEC_PARAM_BOND | (SEC_PARAM_MITM<<2) | (SEC_PARAM_LESC<<3) | (SEC_PARAM_KEYPRESS<<4) );
|
||||
sec_init.pairing_feat.iocap = SEC_PARAM_IO_CAPABILITIES;
|
||||
sec_init.pairing_feat.key_size = SEC_PARAM_KEY_SIZE;
|
||||
sec_init.pairing_feat.oob = SEC_PARAM_OOB;
|
||||
sec_init.pairing_feat.ikey_dist = SEC_PARAM_IKEY;
|
||||
sec_init.pairing_feat.rkey_dist = SEC_PARAM_RKEY;
|
||||
sec_init.pairing_feat.sec_req = SEC_PARAM_SEC_MODE_LEVEL;
|
||||
|
||||
sec_init.bond_enable = BOND_STORE_ENABLE;
|
||||
sec_init.bond_db_addr = BOND_DATA_BASE_ADDR;
|
||||
sec_init.bond_max_peer = MAX_BOND_PEER;
|
||||
sec_init.bond_sync_delay = 2000;
|
||||
|
||||
sec_init.ns_sec_msg_handler = NULL;
|
||||
|
||||
ns_sec_init(&sec_init);
|
||||
}
|
||||
|
||||
void app_ble_prf_init(void)
|
||||
{
|
||||
//add device informaiton server
|
||||
ns_ble_add_prf_func_register(app_dis_add_dis);
|
||||
|
||||
//add heart rate server(hrps)
|
||||
ns_ble_add_prf_func_register(app_hrps_add_hrps);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief ble initialization
|
||||
* @param
|
||||
* @return
|
||||
* @note
|
||||
*/
|
||||
void app_ble_init(void)
|
||||
{
|
||||
struct ns_stack_cfg_t app_handler = {0};
|
||||
app_handler.ble_msg_handler = app_ble_msg_handler;
|
||||
app_handler.user_msg_handler = app_user_msg_handler;
|
||||
app_handler.lsc_cfg = BLE_LSC_LSI_32768HZ;
|
||||
//initialization ble stack
|
||||
ns_ble_stack_init(&app_handler);
|
||||
|
||||
app_ble_gap_params_init();
|
||||
app_ble_sec_init();
|
||||
app_ble_adv_init();
|
||||
app_ble_prf_init();
|
||||
//start adv
|
||||
ns_ble_adv_start();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ble connected
|
||||
* @param
|
||||
* @return
|
||||
* @note
|
||||
*/
|
||||
void app_ble_connected(void)
|
||||
{
|
||||
LedOn(LED2_PORT,LED2_PIN);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ble disconnected
|
||||
* @param
|
||||
* @return
|
||||
* @note
|
||||
*/
|
||||
void app_ble_disconnected(void)
|
||||
{
|
||||
// Restart Advertising
|
||||
ns_ble_adv_start();
|
||||
|
||||
LedOff(LED2_PORT,LED2_PIN);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
|
@ -0,0 +1,119 @@
|
|||
/*****************************************************************************
|
||||
* Copyright (c) 2019, Nations Technologies Inc.
|
||||
*
|
||||
* All rights reserved.
|
||||
* ****************************************************************************
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Nations' name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file app_gpio.c
|
||||
* @author Nations Firmware Team
|
||||
* @version v1.0.0
|
||||
*
|
||||
* @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
|
||||
*/
|
||||
#include "app_gpio.h"
|
||||
|
||||
/** @addtogroup
|
||||
* @{
|
||||
*/
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Configures LED GPIO.
|
||||
* @param Led Specifies the Led to be configured.
|
||||
* This parameter can be GPIO_PIN_0~GPIO_PIN_13.
|
||||
*/
|
||||
void LedInit(GPIO_Module* GPIOx, uint16_t Pin)
|
||||
{
|
||||
GPIO_InitType GPIO_InitStructure;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
||||
|
||||
/* Enable the GPIO Clock */
|
||||
if (GPIOx == GPIOA)
|
||||
{
|
||||
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE);
|
||||
}
|
||||
else if (GPIOx == GPIOB)
|
||||
{
|
||||
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE);
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* Configure the GPIO pin as output push-pull */
|
||||
if (Pin <= GPIO_PIN_ALL)
|
||||
{
|
||||
GPIO_InitStruct(&GPIO_InitStructure);
|
||||
GPIO_InitStructure.Pin = Pin;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @brief Turns selected Led on.
|
||||
* @param GPIOx x can be A to B to select the GPIO port.
|
||||
* @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13.
|
||||
*/
|
||||
void LedOn(GPIO_Module* GPIOx, uint16_t Pin)
|
||||
{
|
||||
GPIO_SetBits(GPIOx, Pin);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Turns selected Led Off.
|
||||
* @param GPIOx x can be A to B to select the GPIO port.
|
||||
* @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13.
|
||||
*/
|
||||
void LedOff(GPIO_Module* GPIOx, uint16_t Pin)
|
||||
{
|
||||
GPIO_ResetBits(GPIOx, Pin);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Toggles the selected Led.
|
||||
* @param GPIOx x can be A to B to select the GPIO port.
|
||||
* @param Pin This parameter can be GPIO_PIN_0~GPIO_PIN_13.
|
||||
*/
|
||||
void LedBlink(GPIO_Module* GPIOx, uint16_t Pin)
|
||||
{
|
||||
GPIO_TogglePin(GPIOx, Pin);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
|
@ -0,0 +1,234 @@
|
|||
/*****************************************************************************
|
||||
* Copyright (c) 2019, Nations Technologies Inc.
|
||||
*
|
||||
* All rights reserved.
|
||||
* ****************************************************************************
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Nations' name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file app_dis.c
|
||||
* @author Nations Firmware Team
|
||||
* @version v1.0.1
|
||||
*
|
||||
* @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup APP
|
||||
* @{
|
||||
**/
|
||||
|
||||
#include "rwip_config.h" // SW configuration
|
||||
|
||||
#if (BLE_APP_DIS)
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "ns_ble.h" // Application Manager Definitions
|
||||
#include "app_dis.h" // Device Information Service Application Definitions
|
||||
#include "diss_task.h" // Device Information Profile Functions
|
||||
#include "prf_types.h" // Profile Common Types Definitions
|
||||
#include "ke_task.h" // Kernel
|
||||
#include "gapm_task.h" // GAP Manager Task API
|
||||
#include "diss.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief dis server value require indicate handler
|
||||
* @param
|
||||
* @return
|
||||
* @note
|
||||
*/
|
||||
static int diss_value_req_ind_handler(ke_msg_id_t const msgid,
|
||||
struct diss_value_req_ind const *param,
|
||||
ke_task_id_t const dest_id,
|
||||
ke_task_id_t const src_id)
|
||||
{
|
||||
NS_LOG_DEBUG("%s\r\n", __func__);
|
||||
// Initialize length
|
||||
uint8_t len = 0;
|
||||
// Pointer to the data
|
||||
uint8_t *data = NULL;
|
||||
|
||||
// Check requested value
|
||||
switch (param->value)
|
||||
{
|
||||
case DIS_MANUFACTURER_NAME_CHAR:
|
||||
{
|
||||
// Set information
|
||||
len = APP_DIS_MANUFACTURER_NAME_LEN;
|
||||
data = (uint8_t *)APP_DIS_MANUFACTURER_NAME;
|
||||
} break;
|
||||
|
||||
case DIS_MODEL_NB_STR_CHAR:
|
||||
{
|
||||
// Set information
|
||||
len = APP_DIS_MODEL_NB_STR_LEN;
|
||||
data = (uint8_t *)APP_DIS_MODEL_NB_STR;
|
||||
} break;
|
||||
|
||||
case DIS_SYSTEM_ID_CHAR:
|
||||
{
|
||||
// Set information
|
||||
len = APP_DIS_SYSTEM_ID_LEN;
|
||||
data = (uint8_t *)APP_DIS_SYSTEM_ID;
|
||||
} break;
|
||||
|
||||
case DIS_PNP_ID_CHAR:
|
||||
{
|
||||
// Set information
|
||||
len = APP_DIS_PNP_ID_LEN;
|
||||
data = (uint8_t *)APP_DIS_PNP_ID;
|
||||
} break;
|
||||
|
||||
case DIS_SERIAL_NB_STR_CHAR:
|
||||
{
|
||||
// Set information
|
||||
len = APP_DIS_SERIAL_NB_STR_LEN;
|
||||
data = (uint8_t *)APP_DIS_SERIAL_NB_STR;
|
||||
} break;
|
||||
|
||||
case DIS_HARD_REV_STR_CHAR:
|
||||
{
|
||||
// Set information
|
||||
len = APP_DIS_HARD_REV_STR_LEN;
|
||||
data = (uint8_t *)APP_DIS_HARD_REV_STR;
|
||||
} break;
|
||||
|
||||
case DIS_FIRM_REV_STR_CHAR:
|
||||
{
|
||||
// Set information
|
||||
len = APP_DIS_FIRM_REV_STR_LEN;
|
||||
data = (uint8_t *)APP_DIS_FIRM_REV_STR;
|
||||
} break;
|
||||
|
||||
case DIS_SW_REV_STR_CHAR:
|
||||
{
|
||||
// Set information
|
||||
len = APP_DIS_SW_REV_STR_LEN;
|
||||
data = (uint8_t *)APP_DIS_SW_REV_STR;
|
||||
} break;
|
||||
|
||||
case DIS_IEEE_CHAR:
|
||||
{
|
||||
// Set information
|
||||
len = APP_DIS_IEEE_LEN;
|
||||
data = (uint8_t *)APP_DIS_IEEE;
|
||||
} break;
|
||||
|
||||
default:
|
||||
ASSERT_ERR(0);
|
||||
break;
|
||||
}
|
||||
|
||||
// Allocate confirmation to send the value
|
||||
struct diss_value_cfm *cfm_value = KE_MSG_ALLOC_DYN(DISS_VALUE_CFM,
|
||||
src_id, dest_id,
|
||||
diss_value_cfm,
|
||||
len);
|
||||
|
||||
// Set parameters
|
||||
cfm_value->value = param->value;
|
||||
cfm_value->length = len;
|
||||
if (len)
|
||||
{
|
||||
// Copy data
|
||||
memcpy(&cfm_value->data[0], data, len);
|
||||
}
|
||||
// Send message
|
||||
ke_msg_send(cfm_value);
|
||||
|
||||
return (KE_MSG_CONSUMED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief dis server Initialize
|
||||
* @param
|
||||
* @return
|
||||
* @note
|
||||
*/
|
||||
void app_dis_init(void)
|
||||
{
|
||||
//register application subtask to app task
|
||||
struct prf_task_t prf;
|
||||
prf.prf_task_id = TASK_ID_DISS;
|
||||
prf.prf_task_handler = &app_dis_handlers;
|
||||
ns_ble_prf_task_register(&prf);
|
||||
|
||||
//register get itf function to prf.c
|
||||
struct prf_get_func_t get_func;
|
||||
get_func.task_id = TASK_ID_DISS;
|
||||
get_func.prf_itf_get_func = diss_prf_itf_get;
|
||||
prf_get_itf_func_register(&get_func);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief add dis server
|
||||
* @param
|
||||
* @return
|
||||
* @note
|
||||
*/
|
||||
void app_dis_add_dis(void)
|
||||
{
|
||||
struct diss_db_cfg* db_cfg;
|
||||
// Allocate the DISS_CREATE_DB_REQ
|
||||
struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD,
|
||||
TASK_GAPM, TASK_APP,
|
||||
gapm_profile_task_add_cmd, sizeof(struct diss_db_cfg));
|
||||
// Fill message
|
||||
req->operation = GAPM_PROFILE_TASK_ADD;
|
||||
req->sec_lvl = PERM(SVC_AUTH, NO_AUTH);
|
||||
req->prf_task_id = TASK_ID_DISS;
|
||||
req->app_task = TASK_APP;
|
||||
req->start_hdl = 0;
|
||||
|
||||
// Set parameters
|
||||
db_cfg = (struct diss_db_cfg* ) req->param;
|
||||
db_cfg->features = APP_DIS_FEATURES;
|
||||
|
||||
// Send the message
|
||||
ke_msg_send(req);
|
||||
|
||||
app_dis_init();
|
||||
}
|
||||
|
||||
/* Public variables ---------------------------------------------------------*/
|
||||
|
||||
/// Default State handlers definition
|
||||
const struct ke_msg_handler app_dis_msg_handler_list[] =
|
||||
{
|
||||
{DISS_VALUE_REQ_IND, (ke_msg_func_t)diss_value_req_ind_handler},
|
||||
};
|
||||
|
||||
const struct app_subtask_handlers app_dis_handlers = APP_HANDLERS(app_dis);
|
||||
|
||||
|
||||
#endif //BLE_APP_DIS
|
||||
|
||||
/// @} APP
|
|
@ -0,0 +1,230 @@
|
|||
/*****************************************************************************
|
||||
* Copyright (c) 2019, Nations Technologies Inc.
|
||||
*
|
||||
* All rights reserved.
|
||||
* ****************************************************************************
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Nations' name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file app_hrps.c
|
||||
* @author Nations Firmware Team
|
||||
* @version v1.0.2
|
||||
*
|
||||
* @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup APP
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include "rwip_config.h" // SW configuration
|
||||
|
||||
#if (BLE_APP_HRPS)
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "ns_ble.h" // Application Manager Definitions
|
||||
#include "app_hrps.h" // Device Information Service Application Definitions
|
||||
#include "hrps_task.h" // Device Information Profile Functions
|
||||
#include "prf_types.h" // Profile Common Types Definitions
|
||||
#include "ke_task.h" // Kernel
|
||||
#include "gapm_task.h" // GAP Manager Task API
|
||||
#include <string.h>
|
||||
#include "co_utils.h"
|
||||
#include "hrps.h"
|
||||
#include "stdio.h"
|
||||
#include "ns_timer.h"
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/// Heart Rate Application environment
|
||||
struct app_hrps_env_tag app_hrps_env;
|
||||
|
||||
uint16_t heart_rate_timer_id;
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief hrps server Initialize
|
||||
* @param
|
||||
* @return
|
||||
* @note
|
||||
*/
|
||||
void app_hrps_init(void)
|
||||
{
|
||||
app_hrps_env.hrps_value = 35;
|
||||
|
||||
//register application subtask to app task
|
||||
struct prf_task_t prf;
|
||||
prf.prf_task_id = TASK_ID_HRPS;
|
||||
prf.prf_task_handler = &app_hrps_handlers;
|
||||
ns_ble_prf_task_register(&prf);
|
||||
|
||||
//register get itf function to prf.c
|
||||
struct prf_get_func_t get_func;
|
||||
get_func.task_id = TASK_ID_HRPS;
|
||||
get_func.prf_itf_get_func = hrps_prf_itf_get;
|
||||
prf_get_itf_func_register(&get_func);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief add hrps server
|
||||
* @param
|
||||
* @return
|
||||
* @note
|
||||
*/
|
||||
void app_hrps_add_hrps(void)
|
||||
{
|
||||
struct hrps_db_cfg* db_cfg;
|
||||
// Allocate the DISS_CREATE_DB_REQ
|
||||
struct gapm_profile_task_add_cmd *req = KE_MSG_ALLOC_DYN(GAPM_PROFILE_TASK_ADD_CMD,
|
||||
TASK_GAPM, TASK_APP,
|
||||
gapm_profile_task_add_cmd, sizeof(struct hrps_db_cfg));
|
||||
// Fill message
|
||||
req->operation = GAPM_PROFILE_TASK_ADD;
|
||||
req->sec_lvl = PERM(SVC_AUTH, NO_AUTH);
|
||||
|
||||
req->prf_task_id = TASK_ID_HRPS;
|
||||
req->app_task = TASK_APP;
|
||||
req->start_hdl = 0;
|
||||
|
||||
// Set parameters
|
||||
db_cfg = (struct hrps_db_cfg* ) req->param;
|
||||
db_cfg->features = APP_HRPS_FEATURES;
|
||||
|
||||
// Send the message
|
||||
ke_msg_send(req);
|
||||
|
||||
app_hrps_init();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief enable heart rate profile
|
||||
* @param
|
||||
* @return
|
||||
* @note
|
||||
*/
|
||||
void app_hrps_enable_prf(uint8_t conidx, uint8_t cfg)
|
||||
{
|
||||
app_hrps_env.conidx = conidx;
|
||||
|
||||
// Allocate the message
|
||||
struct hrps_enable_req * req = KE_MSG_ALLOC(HRPS_ENABLE_REQ,
|
||||
prf_get_task_from_id(TASK_ID_HRPS),
|
||||
TASK_APP,
|
||||
hrps_enable_req);
|
||||
|
||||
// Fill in the parameter structure
|
||||
req->conidx = conidx;
|
||||
|
||||
// NTF status
|
||||
req->hr_meas_ntf = cfg;
|
||||
|
||||
// Send the message
|
||||
ke_msg_send(req);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief send heart rate value
|
||||
* @param
|
||||
* @return
|
||||
* @note
|
||||
*/
|
||||
void app_heart_rate_send(uint16_t heart_rate)
|
||||
{
|
||||
// Allocate the message
|
||||
struct hrps_meas_send_cmd * cmd = KE_MSG_ALLOC(HRPS_MEAS_SEND_CMD,
|
||||
prf_get_task_from_id(TASK_ID_HRPS),
|
||||
TASK_APP,
|
||||
hrps_meas_send_cmd);
|
||||
|
||||
// Fill in the parameter structure
|
||||
cmd->meas_val.heart_rate = heart_rate;
|
||||
|
||||
// Send the message
|
||||
ke_msg_send(cmd);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief heart rate send timeout handler
|
||||
* @param
|
||||
* @return
|
||||
* @note
|
||||
*/
|
||||
void app_heart_rate_timeout_handler(void)
|
||||
{
|
||||
app_hrps_env.hrps_value ++;
|
||||
|
||||
if(app_hrps_env.hrps_value >= 180)
|
||||
{
|
||||
app_hrps_env.hrps_value = 35;
|
||||
}
|
||||
|
||||
app_heart_rate_send(app_hrps_env.hrps_value);
|
||||
|
||||
ns_timer_cancel(heart_rate_timer_id);
|
||||
|
||||
heart_rate_timer_id = ns_timer_create(HEART_RATE_SEND_DELAY,app_heart_rate_timeout_handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief HRPS config indicate handler
|
||||
* @param
|
||||
* @return
|
||||
* @note
|
||||
*/
|
||||
static int hrps_cfg_indntf_ind_handler(ke_msg_id_t const msgid,
|
||||
struct hrps_cfg_indntf_ind const *param,
|
||||
ke_task_id_t const dest_id,
|
||||
ke_task_id_t const src_id)
|
||||
{
|
||||
if( (param->cfg_val & HRPS_CFG_NTF_EN) != 0)
|
||||
{
|
||||
app_hrps_enable_prf(0, PRF_CLI_START_NTF);
|
||||
heart_rate_timer_id = ns_timer_create(HEART_RATE_SEND_DELAY,app_heart_rate_timeout_handler);
|
||||
}
|
||||
else
|
||||
{
|
||||
app_hrps_enable_prf(0, PRF_CLI_STOP_NTFIND);
|
||||
ns_timer_cancel(heart_rate_timer_id);
|
||||
}
|
||||
|
||||
return KE_MSG_CONSUMED;
|
||||
}
|
||||
|
||||
|
||||
/* Public variables ---------------------------------------------------------*/
|
||||
|
||||
/// Default State handlers definition
|
||||
const struct ke_msg_handler app_hrps_msg_handler_list[] =
|
||||
{
|
||||
{HRPS_CFG_INDNTF_IND, (ke_msg_func_t)hrps_cfg_indntf_ind_handler},
|
||||
};
|
||||
|
||||
const struct app_subtask_handlers app_hrps_handlers = APP_HANDLERS(app_hrps);
|
||||
|
||||
|
||||
#endif //BLE_APP_HRPS
|
||||
|
||||
/// @} APP
|
170
src/main.c
170
src/main.c
|
@ -1,47 +1,123 @@
|
|||
#include "n32wb03x.h"
|
||||
#include "n32wb03x_gpio.h"
|
||||
|
||||
static volatile uint32_t uwTick = 0U;
|
||||
|
||||
static void HAL_Delay(uint32_t msec);
|
||||
|
||||
int main(void) {
|
||||
SysTick_Config(SystemCoreClock / 1000);
|
||||
|
||||
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE);
|
||||
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE);
|
||||
|
||||
GPIO_InitType led;
|
||||
|
||||
led.Pin = GPIO_PIN_0;
|
||||
led.GPIO_Mode = GPIO_MODE_OUTPUT_PP;
|
||||
led.GPIO_Speed = GPIO_SPEED_LOW;
|
||||
led.GPIO_Current = GPIO_DC_12MA;
|
||||
led.GPIO_Pull = GPIO_NO_PULL;
|
||||
led.GPIO_Alternate = GPIO_AF0;
|
||||
|
||||
GPIO_InitPeripheral(GPIOB, &led);
|
||||
|
||||
led.Pin = GPIO_PIN_6;
|
||||
GPIO_InitPeripheral(GPIOA, &led);
|
||||
|
||||
GPIO_TogglePin(GPIOB, GPIO_PIN_0);
|
||||
|
||||
for (;;) {
|
||||
GPIO_TogglePin(GPIOB, GPIO_PIN_0);
|
||||
GPIO_TogglePin(GPIOA, GPIO_PIN_6);
|
||||
HAL_Delay(500);
|
||||
}
|
||||
}
|
||||
|
||||
static void HAL_Delay(uint32_t msec) {
|
||||
uint32_t t_start = uwTick;
|
||||
|
||||
while (uwTick - t_start < msec) {
|
||||
__WFI();
|
||||
}
|
||||
}
|
||||
|
||||
void SysTick_Handler(void) {
|
||||
uwTick++;
|
||||
}
|
||||
/*****************************************************************************
|
||||
* Copyright (c) 2019, Nations Technologies Inc.
|
||||
*
|
||||
* All rights reserved.
|
||||
* ****************************************************************************
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Nations' name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||||
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* ****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file main.c
|
||||
* @author Nations Firmware Team
|
||||
* @version v1.0.1
|
||||
*
|
||||
* @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
/** @addtogroup
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "n32wb03x.h"
|
||||
#include "rwip.h"
|
||||
#include "ns_ble.h"
|
||||
#include "ns_sleep.h"
|
||||
#include "ns_delay.h"
|
||||
#include "ns_log.h"
|
||||
#include "app_gpio.h"
|
||||
#include "app_ble.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
#define DEMO_STRING "\r\n Nations Heart Rate Demo \r\n"
|
||||
|
||||
/* Private constants ---------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief main function
|
||||
* @param
|
||||
* @return
|
||||
* @note Note
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
//for hold the SWD before sleep
|
||||
delay_n_10us(200*1000);
|
||||
|
||||
|
||||
NS_LOG_INIT();
|
||||
|
||||
app_ble_init();
|
||||
|
||||
NS_LOG_INFO(DEMO_STRING);
|
||||
|
||||
// periph init
|
||||
LedInit(LED1_PORT,LED1_PIN); // power led
|
||||
LedInit(LED2_PORT,LED2_PIN); //connection state
|
||||
LedOn(LED1_PORT,LED1_PIN);
|
||||
|
||||
while (1)
|
||||
{
|
||||
/*schedule all pending events*/
|
||||
rwip_schedule();
|
||||
|
||||
#ifdef NDEBUG
|
||||
ns_sleep();
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief user handle before enter sleep mode
|
||||
* @param
|
||||
* @return
|
||||
* @note
|
||||
*/
|
||||
void app_sleep_prepare_proc(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief user handle after wake up from sleep mode
|
||||
* @param
|
||||
* @return
|
||||
* @note
|
||||
*/
|
||||
void app_sleep_resume_proc(void)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
|
Loading…
Reference in New Issue