Skip to content
Snippets Groups Projects
Commit ffce77e1 authored by schneider's avatar schneider Committed by rahix
Browse files

fix(sdk): Plug in pre-release with BTLE support

Plug in a new SDK with improved BLE support (more source files
available)

Does not yet actually us BLE.
parent ca3aaa55
No related branches found
No related tags found
1 merge request!43fix(sdk): Plug in pre-release with BTLE support
Pipeline #1472 passed
Showing
with 1479 additions and 1088 deletions
......@@ -29,10 +29,15 @@
# property whatsoever. Maxim Integrated Products, Inc. retains all
# ownership rights.
#
# $Id: Makefile 41870 2019-03-26 14:20:03Z nathan.goldstick $
# $Id: Makefile 44505 2019-07-09 20:32:03Z nathan.goldstick $
#
################################################################################
# Include project configuration.
ifneq "$(wildcard config.mk)" ""
include config.mk
endif
# This is the name of the build output file
ifeq "$(PROJECT)" ""
PROJECT=max32665
......@@ -55,29 +60,6 @@ endif
TARGET_UC:=$(shell echo $(TARGET) | tr a-z A-Z)
TARGET_LC:=$(shell echo $(TARGET) | tr A-Z a-z)
# Beacon App Defines
ifneq "$(BEACON_APP_BEACON_APP_ADV_TYPE)" ""
PROJ_CFLAGS+=-DBEACON_APP_BEACON_APP_ADV_TYPE
endif
ifneq "$(BEACON_APP_MODE)" ""
PROJ_CFLAGS+=-DBEACON_APP_MODE
endif
ifneq "$(BEACON_APP_PEER_ADDR)" ""
PROJ_CFLAGS+=-DBEACON_APP_PEER_ADDR
endif
ifneq "$(BEACON_APP_USE_LEGACY_PDU)" ""
PROJ_CFLAGS+=-DBEACON_APP_USE_LEGACY_PDU
endif
ifneq "$(BEACON_APP_USE_ANON_ADV)" ""
PROJ_CFLAGS+=-DBEACON_APP_USE_ANON_ADV
endif
ifneq "$(BEACON_APP_USE_FRAG_PREF)" ""
PROJ_CFLAGS+=-DBEACON_APP_USE_FRAG_PREF
endif
ifneq "$(BEACON_APP_USE_PER_ADV)" ""
PROJ_CFLAGS+=-DBEACON_APP_USE_PER_ADV
endif
# Last octet address modifier
ifneq "$(BLE_ADDR_LSB)" ""
PROJ_CFLAGS+=-DBLE_ADDR_LSB=$(BLE_ADDR_LSB)
......@@ -90,10 +72,8 @@ endif
# This is the path to the CMSIS root directory
ifeq "$(MAXIM_PATH)" ""
LIBS_DIR=../../../Libraries
NDALIBS_DIR=../../../NDALibraries
else
LIBS_DIR=/$(subst \,/,$(subst :,,$(MAXIM_PATH))/Firmware/$(TARGET_UC)/Libraries)
NDALIBS_DIR=/$(subst \,/,$(subst :,,$(MAXIM_PATH))/Firmware/$(TARGET_UC)/NDALibraries)
endif
CMSIS_ROOT=$(LIBS_DIR)/CMSIS
......@@ -101,23 +81,105 @@ CMSIS_ROOT=$(LIBS_DIR)/CMSIS
SRCS = main.c
SRCS += stack_beacon.c
SRCS += beacon_main.c
# Where to find source files for this test
VPATH = .
VPATH += fcl/src
# Where to find header files for this test
IPATH = .
################################################################################
# Project build configuration.
#-------------------------------------------------------------------------------
# Configuration passed via environment vars.
ifdef BTLE_APP_USE_LEGACY_API
ifeq "$(BTLE_APP_USE_LEGACY_API)" ""
PROJ_CFLAGS+=-DBTLE_APP_USE_LEGACY_API=TRUE
else
ifeq "$(BTLE_APP_USE_LEGACY_API)" "0"
else
ifeq "$(BTLE_APP_USE_LEGACY_API)" "FALSE"
else
PROJ_CFLAGS+=-DBTLE_APP_USE_LEGACY_API=TRUE
endif
endif
endif
endif
ifdef CONSOLE_UART
ifneq "$(CONSOLE_UART)" ""
PROJ_CFLAGS+=-DCONSOLE_UART=$(CONSOLE_UART)
endif
endif
ifdef ENABLE_SDMA
ifneq "$(ENABLE_SDMA)" ""
ifeq "$(ENABLE_SDMA)" "0"
undefine ENABLE_SDMA
else
ifeq "$(ENABLE_SDMA)" "FALSE"
undefine ENABLE_SDMA
else
ENABLE_SDMA=1
endif
endif
endif
endif
ifneq "$(ENABLE_SDMA)" ""
ifdef BTLE_APP_USE_LEGACY_API
ifneq "$(BTLE_APP_USE_LEGACY_API)" ""
ifeq "$(BTLE_APP_USE_LEGACY_API)" "0"
$(error SDMA currently requires BTLE_APP_USE_LEGACY_API)
endif
ifeq "$(BTLE_APP_USE_LEGACY_API)" "FALSE"
$(error SDMA currently requires BTLE_APP_USE_LEGACY_API)
endif
endif
endif
endif
#-------------------------------------------------------------------------------
# Configuration specified here.
#--------------------
# Stack configuration
# Enable assertion checking for development
PROJ_CFLAGS+=-DMXC_ASSERT_ENABLE
PROJ_CFLAGS+=-DASYMMETRIC -DWORD32
PROJ_CFLAGS+=-DMXC_ASSERT_ENABLE=TRUE
PROJ_CFLAGS+=-DWSF_TRACE_ENABLED=TRUE
PROJ_CFLAGS+=-DWSF_ASSERT_ENABLED=TRUE
# PROJ_CFLAGS+=-DLL_TRACE_ENABLED=TRUE
# PROJ_CFLAGS+=-DLL_DBG_PIN_ENABLED=TRUE
PROJ_CFLAGS+=-DWSF_MS_PER_TICK=1
#--------------------
# Application CFLAGS configuration
#--------------------
# Stack CFLAGS configuration
PROJ_CFLAGS+=-DINIT_BROADCASTER
# PROJ_CFLAGS+=-DINIT_OBSERVER
# PROJ_CFLAGS+=-DINIT_CENTRAL
PROJ_CFLAGS+=-DINIT_PERIPHERAL
PROJ_CFLAGS+=-DINIT_ENCRYPTED
ENABLE_LL_TESTER?=#1
# Use this variable to override default compilier optimization.
#MXC_OPTIMIZE_CFLAGS=-Os
#MXC_OPTIMIZE_CFLAGS=-O0 -fomit-frame-pointer
# Point this variable to a linker file to override the default file
#LINKERFILE=$(CMSIS_ROOT)/Device/Maxim/$(TARGET_UC)/Source/GCC/$(TARGET_LC).ld
################################################################################
# Include external library makefiles here
DEBUG=1
# Include the BSP
BOARD_DIR=$(LIBS_DIR)/Boards/$(BOARD)
......@@ -128,7 +190,7 @@ PERIPH_DRIVER_DIR=$(LIBS_DIR)/$(TARGET)PeriphDriver
include ${PERIPH_DRIVER_DIR}/periphdriver.mk
# Include Cordio BTLE Library
CORDIO_DIR=$(NDALIBS_DIR)/BTLE
CORDIO_DIR=$(LIBS_DIR)/BTLE
include ${CORDIO_DIR}/btle.mk
# Include MAXUSB library
......
# Specifies whether the legacy 4.2 api should be used.
# 1 by default.
# Set to 1 to use 4.2 advertisements.
# Set to 0 to use 5.0 extended advertisements.
BTLE_APP_USE_LEGACY_API?=1
# UART used for console output.
# 1 by default.
CONSOLE_UART?=1
# Run link layer using SDMA.
ENABLE_SDMA?=0
......@@ -29,48 +29,47 @@
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2019-03-26 14:20:03 +0000 (Tue, 26 Mar 2019) $
* $Revision: 41870 $
* $Date: 2019-07-12 10:56:57 -0500 (Fri, 12 Jul 2019) $
* $Revision: 44598 $
*
******************************************************************************/
#include <stdio.h>
#include <string.h>
#include "mxc_config.h"
#include "wsf_types.h"
#include "wsf_os.h"
#include "wsf_buf.h"
#include "wsf_timer.h"
#include "wsf_trace.h"
#include "app_ui.h"
#include "ll_api.h"
#include "sch_api.h"
#include "beacon_api.h"
#include "mxc_config.h"
#include "gcr_regs.h"
#include "mcr_regs.h"
#include "app_ui.h"
#include "hci_vs.h"
#include "hci_core.h"
/**************************************************************************************************
Macros
**************************************************************************************************/
/* Number of WSF buffer pools */
#define WSF_BUF_POOLS 6
/* Size of buffer for stdio functions */
#define WSF_BUF_POOLS 6
#define WSF_BUF_SIZE 0x1048
/* Size of buffer for stdio functions */
#define PRINTF_BUF_SIZE 128
#define PRINTF_BUF_SIZE 128
/**************************************************************************************************
Local Variables
**************************************************************************************************/
uint32_t SystemHeapSize=WSF_BUF_SIZE;
uint32_t SystemHeap[WSF_BUF_SIZE/4];
uint32_t SystemHeapStart;
/*! Buffer for stdio functions */
char printf_buffer[PRINTF_BUF_SIZE];
/*! Free memory for pool buffers (use word elements for word alignment). */
static uint32_t mainBufMem[3584/sizeof(uint32_t)+96];
/*! Default pool descriptor. */
static wsfBufPoolDesc_t mainPoolDesc[WSF_BUF_POOLS] =
{
......@@ -79,7 +78,7 @@ static wsfBufPoolDesc_t mainPoolDesc[WSF_BUF_POOLS] =
{ 64, 4 },
{ 128, 4 },
{ 256, 4 },
{ 384, 4 }
{ 512, 4 }
};
/**************************************************************************************************
......@@ -89,6 +88,12 @@ static wsfBufPoolDesc_t mainPoolDesc[WSF_BUF_POOLS] =
/*! \brief Stack initialization for app. */
extern void StackInitBeacon(void);
/*************************************************************************************************/
void PalSysAssertTrap(void)
{
while(1) {}
}
/*************************************************************************************************/
void SysTick_Handler(void)
{
......@@ -96,15 +101,17 @@ void SysTick_Handler(void)
}
/*************************************************************************************************/
static void myTrace(const char *pStr, va_list args)
static bool_t myTrace(const uint8_t *pBuf, uint32_t len)
{
extern uint8_t wsfCsNesting;
if (wsfCsNesting == 0)
{
vprintf(pStr, args);
printf("\r\n");
fwrite(pBuf, len, 1, stdout);
return TRUE;
}
return FALSE;
}
/*************************************************************************************************/
......@@ -116,47 +123,23 @@ static void myTrace(const char *pStr, va_list args)
/*************************************************************************************************/
static void WsfInit(void)
{
WsfTimerInit();
WsfBufInit(sizeof(mainBufMem), (uint8_t*)mainBufMem, WSF_BUF_POOLS, mainPoolDesc);
WsfTraceRegister(myTrace);
}
/*************************************************************************************************/
/*!
* \brief Initialize platform.
*
* \param msPerTick Milliseconds per timer tick.
*
* \return None.
*/
/*************************************************************************************************/
void PlatformInit(void)
{
/* Change the pullup on the RST pin to 25K */
MXC_MCR->ctrl = 0x202;
/* Set VREGO_D to 1.3V */
*((volatile uint32_t*)0x40004410) = 0x50;
/* Set TX LDO to 1.1V and enable LDO. Set RX LDO to 0.9V and enable LDO */
MXC_GCR->btleldocn = 0xD9; // TX 1.1V RX 0.9V
/* Power up the 32MHz XO */
MXC_GCR->clkcn |= MXC_F_GCR_CLKCN_X32M_EN;
/* Enable peripheral clocks */
MXC_GCR->perckcn0 &= ~(MXC_F_GCR_PERCKCN0_GPIO0D | MXC_F_GCR_PERCKCN0_GPIO1D); // Clear GPIO0 and GPIO1 Disable
MXC_GCR->perckcn1 &= ~(MXC_F_GCR_PERCKCN1_BTLED | MXC_F_GCR_PERCKCN1_TRNGD ); // Clear BTLE and ICACHE0 disable
/* setup the systick */
uint32_t bytesUsed;
/* setup the systick for 1MS timer*/
SysTick->LOAD = (SystemCoreClock / 1000) * WSF_MS_PER_TICK;
SysTick->VAL = 0;
SysTick->CTRL |= (SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk | SysTick_CTRL_TICKINT_Msk);
#ifndef __IAR_SYSTEMS_ICC__
/* Added to prevent printf() and friends from using malloc() */
setvbuf(stdout, printf_buffer, _IOLBF, PRINTF_BUF_SIZE);
#endif
WsfTimerInit();
SystemHeapStart = (uint32_t)&SystemHeap;
memset(SystemHeap, 0, sizeof(SystemHeap));
printf("SystemHeapStart = 0x%x\n", SystemHeapStart);
printf("SystemHeapSize = 0x%x\n", SystemHeapSize);
bytesUsed = WsfBufInit(WSF_BUF_POOLS, mainPoolDesc);
printf("bytesUsed = 0x%x\n", bytesUsed);
WsfTraceRegisterHandler(myTrace);
WsfTraceEnable(TRUE);
}
/*
......@@ -167,42 +150,18 @@ void PlatformInit(void)
*/
void SetAddress(uint8_t event)
{
uint8_t bdAddr[6] = {0x20, 0x05, 0x44, 0x8B, 0x05, 0x00};
uint8_t bdAddr[6] = {0x02, 0x00, 0x44, 0x8B, 0x05, 0x00};
switch (event) {
case APP_UI_RESET_CMPL:
printf("Setting address -- MAC %02X:%02X:%02X:%02X:%02X:%02X\n", bdAddr[5], bdAddr[4], bdAddr[3], bdAddr[2], bdAddr[1], bdAddr[0]);
LlSetBdAddr((uint8_t*)&bdAddr);
LlGetBdAddr(hciCoreCb.bdAddr);
break;
default:
break;
case APP_UI_RESET_CMPL:
printf("Setting address -- MAC %02X:%02X:%02X:%02X:%02X:%02X\n", bdAddr[5], bdAddr[4], bdAddr[3], bdAddr[2], bdAddr[1], bdAddr[0]);
HciVsSetBdAddr(bdAddr);
break;
default:
break;
}
}
/*************************************************************************************************/
/*!
* \brief Initialize MAC layer.
*
* \param None.
*
* \return None.
*/
/*************************************************************************************************/
void MacInit(void)
{
wsfHandlerId_t handlerId;
/* Initialize link layer. */
BbInit();
handlerId = WsfOsSetNextHandler(SchHandler);
SchInit(handlerId);
LlAdvSlaveInit();
LlConnSlaveInit();
handlerId = WsfOsSetNextHandler(LlHandler);
LlHandlerInit(handlerId);
}
/*************************************************************************************************/
/*!
* \fn main
......@@ -216,11 +175,15 @@ void MacInit(void)
/*************************************************************************************************/
int main(void)
{
#ifndef __IAR_SYSTEMS_ICC__
setvbuf(stdout, printf_buffer, _IOLBF, PRINTF_BUF_SIZE);
#endif
printf("\n\n***** MAX32665 BLE Beacon *****\n");
PlatformInit();
/* Initialize Radio */
WsfInit();
MacInit();
StackInitBeacon();
BeaconStart();
......
......@@ -17,13 +17,14 @@
*/
/*************************************************************************************************/
#include <stdio.h>
#include <string.h>
#include "wsf_types.h"
#include "wsf_os.h"
#include "util/bstream.h"
#include "beacon_api.h"
#include "wdxs/wdxs_api.h"
#include "hci_handler.h"
#include "hci_api.h"
#include "dm_handler.h"
#include "l2c_handler.h"
#include "att_handler.h"
......@@ -35,6 +36,56 @@
#include "svc_dis.h"
#include "svc_core.h"
#include "sec_api.h"
#include "ll_init_api.h"
#define LL_IMPL_REV 0x2303
#define LL_MEMORY_FOOTPRINT 0xc152
uint8_t LlMem[LL_MEMORY_FOOTPRINT];
const LlRtCfg_t _ll_cfg = {
/* Device */
/*compId*/ LL_COMP_ID_ARM,
/*implRev*/ LL_IMPL_REV,
/*btVer*/ LL_VER_BT_CORE_SPEC_5_0,
/*_align32 */ 0, // padding for alignment
/* Advertiser */
/*maxAdvSets*/ 4, // 4 Extended Advertising Sets
/*maxAdvReports*/ 8,
/*maxExtAdvDataLen*/ LL_MAX_ADV_DATA_LEN,
/*defExtAdvDataFrag*/ 64,
/*auxDelayUsec*/ 0,
/* Scanner */
/*maxScanReqRcvdEvt*/ 4,
/*maxExtScanDataLen*/ LL_MAX_ADV_DATA_LEN,
/* Connection */
/*maxConn*/ 2,
/*numTxBufs*/ 16,
/*numRxBufs*/ 16,
/*maxAclLen*/ 512,
/*defTxPwrLvl*/ 0,
/*ceJitterUsec*/ 0,
/* DTM */
/*dtmRxSyncMs*/ 10000,
/* PHY */
/*phy2mSup*/ TRUE,
/*phyCodedSup*/ TRUE,
/*stableModIdxTxSup*/ FALSE,
/*stableModIdxRxSup*/ FALSE
};
const BbRtCfg_t _bb_cfg = {
/*clkPpm*/ 20,
/*rfSetupDelayUsec*/ BB_RF_SETUP_DELAY_US,
/*maxScanPeriodMsec*/ BB_MAX_SCAN_PERIOD_MS,
/*schSetupDelayUsec*/ BB_SCH_SETUP_DELAY_US
};
/*************************************************************************************************/
/*!
......@@ -47,21 +98,51 @@ void StackInitBeacon(void)
{
wsfHandlerId_t handlerId;
#ifndef ENABLE_SDMA
uint32_t memUsed;
/* Initialize link layer. */
LlInitRtCfg_t ll_init_cfg =
{
.pBbRtCfg = &_bb_cfg,
.wlSizeCfg = 4,
.rlSizeCfg = 4,
.plSizeCfg = 4,
.pLlRtCfg = &_ll_cfg,
.pFreeMem = LlMem,
.freeMemAvail = LL_MEMORY_FOOTPRINT
};
memUsed = LlInitControllerExtInit(&ll_init_cfg);
if(memUsed != LL_MEMORY_FOOTPRINT)
{
printf("mem_used: 0x%x LL_MEMORY_FOOTPRINT: 0x%x\n", memUsed,
LL_MEMORY_FOOTPRINT);
}
#endif
handlerId = WsfOsSetNextHandler(HciHandler);
HciHandlerInit(handlerId);
SecInit();
SecAesInit();
SecCmacInit();
SecEccInit();
handlerId = WsfOsSetNextHandler(HciHandler);
HciHandlerInit(handlerId);
HciLeReadMaxAdvDataLen();
HciLeReadNumSupAdvSets();
handlerId = WsfOsSetNextHandler(DmHandler);
DmDevVsInit(0);
#ifdef BTLE_APP_USE_LEGACY_API
DmAdvInit();
//DmConnInit();
//DmConnSlaveInit();
#else /* BTLE_APP_USE_LEGACY_API */
DmExtAdvInit();
DmConnInit();
DmExtConnSlaveInit();
//DmConnInit();
//DmExtConnSlaveInit();
#endif /* BTLE_APP_USE_LEGACY_API */
DmSecInit();
DmSecLescInit();
DmPrivInit();
DmHandlerInit(handlerId);
handlerId = WsfOsSetNextHandler(L2cSlaveHandler);
......@@ -90,4 +171,5 @@ void StackInitBeacon(void)
handlerId = WsfOsSetNextHandler(WdxsHandler);
WdxsHandlerInit(handlerId);
#endif
}
......@@ -29,10 +29,15 @@
# property whatsoever. Maxim Integrated Products, Inc. retains all
# ownership rights.
#
# $Id: Makefile 38151 2018-09-27 21:32:49Z zach.metzinger $
# $Id: Makefile 44515 2019-07-09 23:06:13Z nathan.goldstick $
#
################################################################################
# Include project configuration.
ifneq "$(wildcard config.mk)" ""
include config.mk
endif
# This is the name of the build output file
ifeq "$(PROJECT)" ""
PROJECT=max32665
......@@ -67,10 +72,8 @@ endif
# This is the path to the CMSIS root directory
ifeq "$(MAXIM_PATH)" ""
LIBS_DIR=../../../Libraries
NDALIBS_DIR=../../../NDALibraries
else
LIBS_DIR=/$(subst \,/,$(subst :,,$(MAXIM_PATH))/Firmware/$(TARGET_UC)/Libraries)
NDALIBS_DIR=/$(subst \,/,$(subst :,,$(MAXIM_PATH))/Firmware/$(TARGET_UC)/NDALibraries)
endif
CMSIS_ROOT=$(LIBS_DIR)/CMSIS
......@@ -78,23 +81,119 @@ CMSIS_ROOT=$(LIBS_DIR)/CMSIS
SRCS = main.c
SRCS += stack_datc.c
SRCS += datc_main.c
# Where to find source files for this test
VPATH = .
VPATH += fcl/src
# Where to find header files for this test
IPATH = .
################################################################################
# Project build configuration.
#-------------------------------------------------------------------------------
# Configuration passed via environment vars.
ifdef BTLE_APP_USE_LEGACY_API
ifeq "$(BTLE_APP_USE_LEGACY_API)" ""
PROJ_CFLAGS+=-DBTLE_APP_USE_LEGACY_API=TRUE
else
ifeq "$(BTLE_APP_USE_LEGACY_API)" "0"
else
ifeq "$(BTLE_APP_USE_LEGACY_API)" "FALSE"
else
PROJ_CFLAGS+=-DBTLE_APP_USE_LEGACY_API=TRUE
endif
endif
endif
endif
ifdef BTLE_APP_USE_ACTIVE_SCANNING
ifeq "$(BTLE_APP_USE_ACTIVE_SCANNING)" ""
PROJ_CFLAGS+=-DBTLE_APP_USE_ACTIVE_SCANNING=TRUE
else
ifeq "$(BTLE_APP_USE_ACTIVE_SCANNING)" "0"
else
ifeq "$(BTLE_APP_USE_ACTIVE_SCANNING)" "FALSE"
else
PROJ_CFLAGS+=-DBTLE_APP_USE_ACTIVE_SCANNING=TRUE
endif
endif
endif
endif
ifdef CONSOLE_UART
ifneq "$(CONSOLE_UART)" ""
PROJ_CFLAGS+=-DCONSOLE_UART=$(CONSOLE_UART)
endif
endif
ifdef ENABLE_SDMA
ifneq "$(ENABLE_SDMA)" ""
ifeq "$(ENABLE_SDMA)" "0"
undefine ENABLE_SDMA
else
ifeq "$(ENABLE_SDMA)" "FALSE"
undefine ENABLE_SDMA
else
ENABLE_SDMA=1
endif
endif
endif
endif
ifneq "$(ENABLE_SDMA)" ""
ifdef BTLE_APP_USE_LEGACY_API
ifneq "$(BTLE_APP_USE_LEGACY_API)" ""
ifeq "$(BTLE_APP_USE_LEGACY_API)" "0"
$(error SDMA currently requires BTLE_APP_USE_LEGACY_API)
endif
ifeq "$(BTLE_APP_USE_LEGACY_API)" "FALSE"
$(error SDMA currently requires BTLE_APP_USE_LEGACY_API)
endif
endif
endif
endif
#-------------------------------------------------------------------------------
# Configuration specified here.
#--------------------
# Stack configuration
# Enable assertion checking for development
PROJ_CFLAGS+=-DMXC_ASSERT_ENABLE
PROJ_CFLAGS+=-DASYMMETRIC -DWORD32
PROJ_CFLAGS+=-DMXC_ASSERT_ENABLE=TRUE
# PROJ_CFLAGS+=-DWSF_TRACE_ENABLED=TRUE
PROJ_CFLAGS+=-DWSF_ASSERT_ENABLED=TRUE
# PROJ_CFLAGS+=-DLL_TRACE_ENABLED=TRUE
# PROJ_CFLAGS+=-DLL_DBG_PIN_ENABLED=TRUE
PROJ_CFLAGS+=-DWSF_MS_PER_TICK=1
#--------------------
# Application CFLAGS configuration
#--------------------
# Stack CFLAGS configuration
# PROJ_CFLAGS+=-DINIT_BROADCASTER
PROJ_CFLAGS+=-DINIT_OBSERVER
PROJ_CFLAGS+=-DINIT_CENTRAL
# PROJ_CFLAGS+=-DINIT_PERIPHERAL
PROJ_CFLAGS+=-DINIT_ENCRYPTED
ENABLE_LL_TESTER?=#1
# Use this variable to override default compilier optimization.
#MXC_OPTIMIZE_CFLAGS=-Os
#MXC_OPTIMIZE_CFLAGS=-O0 -fomit-frame-pointer
# Point this variable to a linker file to override the default file
#LINKERFILE=$(CMSIS_ROOT)/Device/Maxim/$(TARGET_UC)/Source/GCC/$(TARGET_LC).ld
################################################################################
# Include external library makefiles here
DEBUG=1
# Include the BSP
BOARD_DIR=$(LIBS_DIR)/Boards/$(BOARD)
......@@ -105,7 +204,7 @@ PERIPH_DRIVER_DIR=$(LIBS_DIR)/$(TARGET)PeriphDriver
include ${PERIPH_DRIVER_DIR}/periphdriver.mk
# Include Cordio BTLE Library
CORDIO_DIR=$(NDALIBS_DIR)/BTLE
CORDIO_DIR=$(LIBS_DIR)/BTLE
include ${CORDIO_DIR}/btle.mk
# Include MAXUSB library
......
# Specifies whether the legacy 4.2 api should be used.
# 1 by default.
# Set to 1 to use 4.2 advertisements.
# Set to 0 to use 5.0 extended advertisements.
BTLE_APP_USE_LEGACY_API?=1
# Specifies whether scan requests should be transmitted.
BTLE_APP_USE_ACTIVE_SCANNING?=1
# UART used for console output.
# 1 by default.
CONSOLE_UART?=1
# Run link layer using SDMA.
ENABLE_SDMA?=0
......@@ -86,6 +86,7 @@ struct
Configurable Parameters
**************************************************************************************************/
#ifdef BTLE_APP_USE_LEGACY_API
/*! configurable parameters for master */
static const appMasterCfg_t datcMasterCfg =
{
......@@ -93,9 +94,46 @@ static const appMasterCfg_t datcMasterCfg =
420, /*! The scan window, in 0.625 ms units */
0, /*! The scan duration in ms */
DM_DISC_MODE_NONE, /*! The GAP discovery mode */
DM_SCAN_TYPE_ACTIVE /*! The scan type (active or passive) */
#ifdef BTLE_APP_USE_ACTIVE_SCANNING
DM_SCAN_TYPE_ACTIVE
#else /* BTLE_APP_USE_ACTIVE_SCANNING */
DM_SCAN_TYPE_PASSIVE
#endif /* BTLE_APP_USE_ACTIVE_SCANNING */
/*!< The scan type (active or passive) */
};
#else /* BTLE_APP_USE_LEGACY_API */
/*! configurable parameters for extended master */
static const uint8_t datcExtMasterScanPhysCfg =
HCI_SCAN_PHY_LE_1M_BIT |
//HCI_SCAN_PHY_LE_2M_BIT |
//HCI_SCAN_PHY_LE_CODED_BIT |
0;
static const appExtMasterCfg_t datcExtMasterCfg =
{
{ 420, 420, 420 }, /*! \brief The scan interval, in 0.625 ms units */
{ 420, 420, 420 }, /*! \brief The scan window, in 0.625 ms units. Must be less than or equal to scan interval. */
0, /*! \brief The scan duration in ms. Set to zero or both duration and period to non-zero to scan until stopped. */
0, /*! \brief The scan period, in 1.28 sec units. Set to zero to disable periodic scanning. */
DM_DISC_MODE_NONE, /*! \brief The GAP discovery mode (general, limited, or none) */
#ifdef BTLE_APP_USE_ACTIVE_SCANNING
{
DM_SCAN_TYPE_ACTIVE,
DM_SCAN_TYPE_ACTIVE,
DM_SCAN_TYPE_ACTIVE
}
#else /* BTLE_APP_USE_ACTIVE_SCANNING */
{
DM_SCAN_TYPE_PASSIVE,
DM_SCAN_TYPE_PASSIVE,
DM_SCAN_TYPE_PASSIVE
}
#endif /* BTLE_APP_USE_ACTIVE_SCANNING */
/*!< \brief The scan type (active or passive) */
};
#endif /* BTLE_APP_USE_LEGACY_API */
/*! configurable parameters for security */
static const appSecCfg_t datcSecCfg =
{
......@@ -123,8 +161,8 @@ static const smpCfg_t datcSmpCfg =
/*! Connection parameters */
static const hciConnSpec_t datcConnCfg =
{
40, /*! Minimum connection interval in 1.25ms units */
40, /*! Maximum connection interval in 1.25ms units */
6, /*! Minimum connection interval in 1.25ms units */
6, /*! Maximum connection interval in 1.25ms units */
0, /*! Connection latency */
600, /*! Supervision timeout in 10ms units */
0, /*! Minimum CE length, in 0.625 ms units */
......@@ -355,7 +393,11 @@ static void datcScanStop(dmEvt_t *pMsg)
/* Open connection */
if (datcConnInfo.doConnect)
{
#ifdef BTLE_APP_USE_LEGACY_API
testCb.connId = AppConnOpen(datcConnInfo.addrType, datcConnInfo.addr, datcConnInfo.dbHdl);
#else
testCb.connId = AppExtConnOpen(datcExtMasterScanPhysCfg, datcConnInfo.addrType, datcConnInfo.addr, datcConnInfo.dbHdl);
#endif
datcConnInfo.doConnect = FALSE;
}
}
......@@ -453,6 +495,119 @@ static void datcScanReport(dmEvt_t *pMsg)
}
}
#ifndef BTLE_APP_IGNORE_EXT_EVENTS
/*************************************************************************************************/
/*!
* \brief Handle a scan report.
*
* \param pMsg Pointer to DM callback event message.
*
* \return None.
*/
/*************************************************************************************************/
static void datcExtScanReport(dmEvt_t *pMsg)
{
uint8_t *pData;
appDbHdl_t dbHdl;
bool_t connect = FALSE;
/* disregard if not scanning or autoconnecting */
if (!datcCb.scanning || !datcCb.autoConnect)
{
return;
}
printf("datcExtScanReport() %x : %02x:%02x:%02x:%02x:%02x:%02x\n",
pMsg->extScanReport.addrType,
pMsg->extScanReport.addr[5],
pMsg->extScanReport.addr[4],
pMsg->extScanReport.addr[3],
pMsg->extScanReport.addr[2],
pMsg->extScanReport.addr[1],
pMsg->extScanReport.addr[0]);
printf(" directedAddr ( %x : %02x:%02x:%02x:%02x:%02x:%02x )\n",
pMsg->extScanReport.directAddrType,
pMsg->extScanReport.directAddr[5],
pMsg->extScanReport.directAddr[4],
pMsg->extScanReport.directAddr[3],
pMsg->extScanReport.directAddr[2],
pMsg->extScanReport.directAddr[1],
pMsg->extScanReport.directAddr[0]);
printf(" evtType %x,\n", pMsg->extScanReport.eventType);
printf(" addrType %x,\n", pMsg->extScanReport.addrType);
printf(" priPhy %u,\n", pMsg->extScanReport.priPhy);
printf(" secPhy %u,\n", pMsg->extScanReport.secPhy);
printf(" advSid 0x%02x,\n", pMsg->extScanReport.advSid);
printf(" txPower %i,\n", pMsg->extScanReport.txPower);
printf(" rssi %d,\n", pMsg->extScanReport.rssi);
printf(" perAdvInter %i,\n", pMsg->extScanReport.perAdvInter);
printf(" directAddrType %x,\n", pMsg->extScanReport.directAddrType);
printf(" len %u,\n", pMsg->extScanReport.len);
if (pMsg->extScanReport.pData[1] == DM_ADV_TYPE_LOCAL_NAME)
{
uint8_t name[32];
memset(name, 0, sizeof(name));
memcpy(name, &pMsg->extScanReport.pData[2], pMsg->extScanReport.pData[0]);
printf(" | %s\n", name);
}
else {
printf(", data");
int i;
for (i = 0; i < pMsg->extScanReport.len; i++) {
printf(" %02x", pMsg->extScanReport.pData[i]);
}
printf("\n");
}
/* if we already have a bond with this device then connect to it */
if ((dbHdl = AppDbFindByAddr(pMsg->extScanReport.addrType, pMsg->extScanReport.addr)) != APP_DB_HDL_NONE)
{
/* if this is a directed advertisement where the initiator address is an RPA */
if (DM_RAND_ADDR_RPA(pMsg->extScanReport.directAddr, pMsg->extScanReport.directAddrType))
{
/* resolve direct address to see if it's addressed to us */
AppMasterResolveAddr(pMsg, dbHdl, APP_RESOLVE_DIRECT_RPA);
}
else
{
connect = TRUE;
}
}
/* if the peer device uses an RPA */
else if (DM_RAND_ADDR_RPA(pMsg->extScanReport.addr, pMsg->extScanReport.addrType))
{
/* resolve advertiser's RPA to see if we already have a bond with this device */
AppMasterResolveAddr(pMsg, APP_DB_HDL_NONE, APP_RESOLVE_ADV_RPA);
}
/* find vendor-specific advertising data */
else if ((pData = DmFindAdType(DM_ADV_TYPE_MANUFACTURER, pMsg->extScanReport.len,
pMsg->extScanReport.pData)) != NULL)
{
/* check length and vendor ID */
if (pData[DM_AD_LEN_IDX] >= 3 && BYTES_UINT16_CMP(&pData[DM_AD_DATA_IDX], HCI_ID_ARM))
{
connect = TRUE;
}
}
if (connect)
{
/* stop scanning and connect */
datcCb.autoConnect = FALSE;
AppExtScanStop();
/* Store peer information for connect on scan stop */
datcConnInfo.addrType = DmHostAddrType(pMsg->extScanReport.addrType);
memcpy(datcConnInfo.addr, pMsg->extScanReport.addr, sizeof(bdAddr_t));
datcConnInfo.dbHdl = dbHdl;
datcConnInfo.doConnect = TRUE;
}
}
#endif /* BTLE_APP_IGNORE_EXT_EVENTS */
/*************************************************************************************************/
/*!
* \brief Perform UI actions on connection open.
......@@ -483,7 +638,16 @@ static void datcClose(dmEvt_t *pMsg)
if (!datcCb.scanning)
{
datcCb.autoConnect = TRUE;
#ifdef BTLE_APP_USE_LEGACY_API
AppScanStart(datcMasterCfg.discMode, datcMasterCfg.scanType, datcMasterCfg.scanDuration);
#else /* BTLE_APP_USE_LEGACY_API */
AppExtScanStart(
datcExtMasterScanPhysCfg,
datcExtMasterCfg.discMode,
datcExtMasterCfg.scanType,
datcExtMasterCfg.scanDuration,
datcExtMasterCfg.scanPeriod);
#endif /* BTLE_APP_USE_LEGACY_API */
}
}
......@@ -522,16 +686,13 @@ static void datcSetup(dmEvt_t *pMsg)
WsfTimerStartMs(&testCb.timer, 1000);
testCb.connectCount = 0x80000000;
/* If this is defined to one, scanning will be limited to the EvKit dats peer */
#if 0
/* Scanning will be limited to the EvKit dats peer */
DmDevWhiteListAdd(DM_ADDR_PUBLIC, (bdAddr_t){0x02, 0x00, 0x44, 0x8B, 0x05, 0x00});
DmDevSetFilterPolicy(DM_FILT_POLICY_MODE_SCAN, HCI_FILT_WHITE_LIST);
DmDevSetFilterPolicy(DM_FILT_POLICY_MODE_INIT, HCI_FILT_WHITE_LIST);
#endif
/* 0x3 : 1M and 2M PHYs */
DmSetDefaultPhy(0, 0x3, 0x3);
testCb.phy = 0x1;
DmSetDefaultPhy(0, HCI_PHY_LE_1M_BIT | HCI_PHY_LE_2M_BIT, HCI_PHY_LE_1M_BIT | HCI_PHY_LE_2M_BIT);
testCb.phy = HCI_PHY_LE_1M_BIT;
DmConnSetConnSpec((hciConnSpec_t *) &datcConnCfg);
}
......@@ -676,7 +837,16 @@ static void testTimerHandler(void)
if (testCb.counter == 2)
{
datcCb.autoConnect = TRUE;
#ifdef BTLE_APP_USE_LEGACY_API
AppScanStart(datcMasterCfg.discMode, datcMasterCfg.scanType, datcMasterCfg.scanDuration);
#else /* BTLE_APP_USE_LEGACY_API */
AppExtScanStart(
datcExtMasterScanPhysCfg,
datcExtMasterCfg.discMode,
datcExtMasterCfg.scanType,
datcExtMasterCfg.scanDuration,
datcExtMasterCfg.scanPeriod);
#endif /* BTLE_APP_USE_LEGACY_API */
}
if ((((testCb.counter - testCb.connectCount) % 5) == 0) &&
......@@ -684,18 +854,19 @@ static void testTimerHandler(void)
(datcCb.discState[testCb.connId-1] == DATC_DISC_SVC_MAX))
{
datcSendData(testCb.connId);
DmConnReadRssi(testCb.connId);
}
if ((((testCb.counter - testCb.connectCount) % 10) == 0) &&
(testCb.connId != DM_CONN_ID_NONE) &&
(datcCb.discState[testCb.connId-1] == DATC_DISC_SVC_MAX))
{
if(testCb.phy == 0x1) {
if(testCb.phy == HCI_PHY_LE_1M_BIT) {
/* Change from 1M to 2M PHY */
testCb.phy = 0x2;
testCb.phy = HCI_PHY_LE_2M_BIT;
} else {
/* Change from Coded to 1M PHY */
testCb.phy = 0x1;
testCb.phy = HCI_PHY_LE_1M_BIT;
}
DmSetPhy(testCb.connId, 0, testCb.phy, testCb.phy, 0);
......@@ -723,6 +894,9 @@ static void datcProcMsg(dmEvt_t *pMsg)
datcValueNtf((attEvt_t *) pMsg);
break;
case ATTC_WRITE_CMD_RSP:
break;
case DM_RESET_CMPL_IND:
DmSecGenerateEccKeyReq();
datcSetup(pMsg);
......@@ -734,20 +908,44 @@ static void datcProcMsg(dmEvt_t *pMsg)
uiEvent = APP_UI_SCAN_START;
break;
#ifndef BTLE_APP_IGNORE_EXT_EVENTS
case DM_EXT_SCAN_START_IND:
datcScanStart(pMsg);
uiEvent = APP_UI_EXT_SCAN_START_IND;
break;
#endif /* BTLE_APP_IGNORE_EXT_EVENTS */
case DM_SCAN_STOP_IND:
datcScanStop(pMsg);
uiEvent = APP_UI_SCAN_STOP;
break;
#ifndef BTLE_APP_IGNORE_EXT_EVENTS
case DM_EXT_SCAN_STOP_IND:
datcScanStop(pMsg);
uiEvent = APP_UI_EXT_SCAN_STOP_IND;
break;
#endif /* BTLE_APP_IGNORE_EXT_EVENTS */
case DM_SCAN_REPORT_IND:
datcScanReport(pMsg);
break;
#ifndef BTLE_APP_IGNORE_EXT_EVENTS
case DM_EXT_SCAN_REPORT_IND:
datcExtScanReport(pMsg);
break;
#endif /* BTLE_APP_IGNORE_EXT_EVENTS */
case DM_CONN_OPEN_IND:
datcOpen(pMsg);
uiEvent = APP_UI_CONN_OPEN;
break;
case DM_CONN_READ_RSSI_IND:
printf("Connection 0x%x RSSI: %d\n", pMsg->readRssi.handle, pMsg->readRssi.rssi);
break;
case DM_CONN_CLOSE_IND:
printf("Connection closed status 0x%x, reason 0x%x", pMsg->connClose.status, pMsg->connClose.reason);
switch (pMsg->connClose.reason)
......@@ -758,9 +956,6 @@ static void datcProcMsg(dmEvt_t *pMsg)
case HCI_ERR_CONN_FAIL: printf(" FAIL ESTABLISH\n"); break;
case HCI_ERR_MIC_FAILURE: printf(" MIC FAILURE\n"); break;
}
#if 0
WSF_ASSERT(0);
#endif
datcClose(pMsg);
uiEvent = APP_UI_CONN_CLOSE;
break;
......@@ -816,6 +1011,13 @@ static void datcProcMsg(dmEvt_t *pMsg)
testTimerHandler();
break;
case DM_VENDOR_SPEC_IND:
break;
case DM_PHY_UPDATE_IND:
APP_TRACE_INFO2("DM_PHY_UPDATE_IND - RX: %d, TX: %d", pMsg->phyUpdate.rxPhy, pMsg->phyUpdate.txPhy);
break;
default:
break;
}
......@@ -846,7 +1048,11 @@ void DatcHandlerInit(wsfHandlerId_t handlerId)
datcCb.hdlListLen = DATC_DISC_HDL_LIST_LEN;
/* Set configuration pointers */
#ifdef BTLE_APP_USE_LEGACY_API
pAppMasterCfg = (appMasterCfg_t *) &datcMasterCfg;
#else /* BTLE_APP_USE_LEGACY_API */
pAppExtMasterCfg = (appExtMasterCfg_t *) &datcExtMasterCfg;
#endif /* BTLE_APP_USE_LEGACY_API */
pAppSecCfg = (appSecCfg_t *) &datcSecCfg;
pAppDiscCfg = (appDiscCfg_t *) &datcDiscCfg;
pAppCfg = (appCfg_t *)&datcAppCfg;
......
......@@ -29,47 +29,48 @@
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2019-02-11 23:36:35 +0000 (Mon, 11 Feb 2019) $
* $Revision: 40967 $
* $Date: 2019-07-11 13:33:24 -0500 (Thu, 11 Jul 2019) $
* $Revision: 44549 $
*
******************************************************************************/
#include <stdio.h>
#include <string.h>
#include "mxc_config.h"
#include "wsf_types.h"
#include "wsf_os.h"
#include "wsf_buf.h"
#include "wsf_timer.h"
#include "wsf_trace.h"
#include "app_ui.h"
#include "ll_api.h"
#include "sch_api.h"
#include "datc/datc_api.h"
#include "mxc_config.h"
#include "gcr_regs.h"
#include "mcr_regs.h"
#include "app_ui.h"
#include "radio_drv.h"
#include "hci_core.h"
#include "hci_vs.h"
/**************************************************************************************************
Macros
**************************************************************************************************/
/* Number of WSF buffer pools */
#define WSF_BUF_POOLS 6
#define WSF_BUF_POOLS 6
#define WSF_BUF_SIZE 0x1048
/* Size of buffer for stdio functions */
#define PRINTF_BUF_SIZE 128
#define PRINTF_BUF_SIZE 128
/**************************************************************************************************
Local Variables
**************************************************************************************************/
uint32_t SystemHeapSize=WSF_BUF_SIZE;
uint32_t SystemHeap[WSF_BUF_SIZE/4];
uint32_t SystemHeapStart;
/*! Buffer for stdio functions */
char printf_buffer[PRINTF_BUF_SIZE];
/*! Free memory for pool buffers (use word elements for word alignment). */
static uint32_t mainBufMem[3584/sizeof(uint32_t)+96];
/*! Default pool descriptor. */
static wsfBufPoolDesc_t mainPoolDesc[WSF_BUF_POOLS] =
{
......@@ -78,7 +79,7 @@ static wsfBufPoolDesc_t mainPoolDesc[WSF_BUF_POOLS] =
{ 64, 4 },
{ 128, 4 },
{ 256, 4 },
{ 384, 4 }
{ 512, 4 }
};
/**************************************************************************************************
......@@ -95,67 +96,53 @@ void SysTick_Handler(void)
}
/*************************************************************************************************/
static void myTrace(const char *pStr, va_list args)
static bool_t myTrace(const uint8_t *pBuf, uint32_t len)
{
extern uint8_t wsfCsNesting;
if (wsfCsNesting == 0)
{
vprintf(pStr, args);
printf("\r\n");
fwrite(pBuf, len, 1, stdout);
return TRUE;
}
return FALSE;
}
/*************************************************************************************************/
/*!
* \brief Initialize WSF.
*
* \return None.
*/
/*************************************************************************************************/
static void WsfInit(void)
void PalSysAssertTrap(void)
{
WsfTimerInit();
WsfBufInit(sizeof(mainBufMem), (uint8_t*)mainBufMem, WSF_BUF_POOLS, mainPoolDesc);
WsfTraceRegister(myTrace);
printf("Assertion detected\n");
while(1) {}
}
/*************************************************************************************************/
/*!
* \brief Initialize platform.
*
* \param msPerTick Milliseconds per timer tick.
* \brief Initialize WSF.
*
* \return None.
*/
/*************************************************************************************************/
void PlatformInit(void)
static void WsfInit(void)
{
/* Change the pullup on the RST pin to 25K */
MXC_MCR->ctrl = 0x202;
uint32_t bytesUsed;
/* Set VREGO_D to 1.3V */
*((volatile uint32_t*)0x40004410) = 0x50;
/* Set TX LDO to 1.1V and enable LDO. Set RX LDO to 0.9V and enable LDO */
MXC_GCR->btleldocn = 0xD9; // TX 1.1V RX 0.9V
/* Power up the 32MHz XO */
MXC_GCR->clkcn |= MXC_F_GCR_CLKCN_X32M_EN;
/* Enable peripheral clocks */
MXC_GCR->perckcn0 &= ~(MXC_F_GCR_PERCKCN0_GPIO0D | MXC_F_GCR_PERCKCN0_GPIO1D); // Clear GPIO0 and GPIO1 Disable
MXC_GCR->perckcn1 &= ~(MXC_F_GCR_PERCKCN1_BTLED | MXC_F_GCR_PERCKCN1_TRNGD ); // Clear BTLE and ICACHE0 disable
/* setup the systick */
/* setup the systick for 1MS timer*/
SysTick->LOAD = (SystemCoreClock / 1000) * WSF_MS_PER_TICK;
SysTick->VAL = 0;
SysTick->CTRL |= (SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk | SysTick_CTRL_TICKINT_Msk);
#ifndef __IAR_SYSTEMS_ICC__
/* Added to prevent printf() and friends from using malloc() */
setvbuf(stdout, printf_buffer, _IOLBF, PRINTF_BUF_SIZE);
#endif
WsfTimerInit();
SystemHeapStart = (uint32_t)&SystemHeap;
memset(SystemHeap, 0, sizeof(SystemHeap));
printf("SystemHeapStart = 0x%x\n", SystemHeapStart);
printf("SystemHeapSize = 0x%x\n", SystemHeapSize);
bytesUsed = WsfBufInit(WSF_BUF_POOLS, mainPoolDesc);
printf("bytesUsed = 0x%x\n", bytesUsed);
WsfTraceRegisterHandler(myTrace);
WsfTraceEnable(TRUE);
}
/*
......@@ -169,39 +156,15 @@ void SetAddress(uint8_t event)
uint8_t bdAddr[6] = {0x02, 0x01, 0x44, 0x8B, 0x05, 0x00};
switch (event) {
case APP_UI_RESET_CMPL:
printf("Setting address -- MAC %02X:%02X:%02X:%02X:%02X:%02X\n", bdAddr[5], bdAddr[4], bdAddr[3], bdAddr[2], bdAddr[1], bdAddr[0]);
LlSetBdAddr((uint8_t*)&bdAddr);
LlGetBdAddr(hciCoreCb.bdAddr);
break;
default:
break;
case APP_UI_RESET_CMPL:
printf("Setting address -- MAC %02X:%02X:%02X:%02X:%02X:%02X\n", bdAddr[5], bdAddr[4], bdAddr[3], bdAddr[2], bdAddr[1], bdAddr[0]);
HciVsSetBdAddr(bdAddr);
break;
default:
break;
}
}
/*************************************************************************************************/
/*!
* \brief Initialize MAC layer.
*
* \param None.
*
* \return None.
*/
/*************************************************************************************************/
void MacInit(void)
{
wsfHandlerId_t handlerId;
/* Initialize link layer. */
BbInit();
handlerId = WsfOsSetNextHandler(SchHandler);
SchInit(handlerId);
LlScanMasterInit();
LlConnMasterInit();
handlerId = WsfOsSetNextHandler(LlHandler);
LlHandlerInit(handlerId);
}
/*************************************************************************************************/
/*!
* \fn main
......@@ -215,11 +178,15 @@ void MacInit(void)
/*************************************************************************************************/
int main(void)
{
#ifndef __IAR_SYSTEMS_ICC__
setvbuf(stdout, printf_buffer, _IOLBF, PRINTF_BUF_SIZE);
#endif
printf("\n\n***** MAX32665 BLE Data Collector *****\n");
PlatformInit();
/* Initialize Radio */
WsfInit();
MacInit();
StackInitDatc();
DatcStart();
......
......@@ -17,12 +17,12 @@
*/
/*************************************************************************************************/
#include <stdio.h>
#include <string.h>
#include "wsf_types.h"
#include "wsf_os.h"
#include "util/bstream.h"
#include "datc/datc_api.h"
#include "hci_handler.h"
#include "dm_handler.h"
#include "l2c_handler.h"
......@@ -35,6 +35,57 @@
#include "svc_dis.h"
#include "svc_core.h"
#include "sec_api.h"
#include "ll_init_api.h"
#define LL_IMPL_REV 0x2303
#define LL_MEMORY_FOOTPRINT 0xc152
uint8_t LlMem[LL_MEMORY_FOOTPRINT];
const LlRtCfg_t _ll_cfg = {
/* Device */
/*compId*/ LL_COMP_ID_ARM,
/*implRev*/ LL_IMPL_REV,
/*btVer*/ LL_VER_BT_CORE_SPEC_5_0,
/*_align32 */ 0, // padding for alignment
/* Advertiser */
/*maxAdvSets*/ 4, // 4 Extended Advertising Sets
/*maxAdvReports*/ 8,
/*maxExtAdvDataLen*/ LL_MAX_ADV_DATA_LEN,
/*defExtAdvDataFrag*/ 64,
/*auxDelayUsec*/ 0,
/* Scanner */
/*maxScanReqRcvdEvt*/ 4,
/*maxExtScanDataLen*/ LL_MAX_ADV_DATA_LEN,
/* Connection */
/*maxConn*/ 2,
/*numTxBufs*/ 16,
/*numRxBufs*/ 16,
/*maxAclLen*/ 512,
/*defTxPwrLvl*/ 0,
/*ceJitterUsec*/ 0,
/* DTM */
/*dtmRxSyncMs*/ 10000,
/* PHY */
/*phy2mSup*/ TRUE,
/*phyCodedSup*/ FALSE,
/*stableModIdxTxSup*/ FALSE,
/*stableModIdxRxSup*/ FALSE
};
const BbRtCfg_t _bb_cfg = {
/*clkPpm*/ 20,
/*rfSetupDelayUsec*/ BB_RF_SETUP_DELAY_US,
/*maxScanPeriodMsec*/ BB_MAX_SCAN_PERIOD_MS,
/*schSetupDelayUsec*/ BB_SCH_SETUP_DELAY_US
};
/*************************************************************************************************/
/*!
......@@ -46,29 +97,54 @@
void StackInitDatc(void)
{
wsfHandlerId_t handlerId;
uint8_t features[sizeof(uint64_t)];
uint8_t mask[sizeof(uint64_t)];
#ifndef ENABLE_SDMA
uint32_t memUsed;
/* Initialize link layer. */
LlInitRtCfg_t ll_init_cfg =
{
.pBbRtCfg = &_bb_cfg,
.wlSizeCfg = 4,
.rlSizeCfg = 4,
.plSizeCfg = 4,
.pLlRtCfg = &_ll_cfg,
.pFreeMem = LlMem,
.freeMemAvail = LL_MEMORY_FOOTPRINT
};
memUsed = LlInitControllerExtInit(&ll_init_cfg);
// memUsed = LlInitControllerInit(&ll_init_cfg);
if(memUsed != LL_MEMORY_FOOTPRINT)
{
printf("mem_used: 0x%x LL_MEMORY_FOOTPRINT: 0x%x\n", memUsed,
LL_MEMORY_FOOTPRINT);
}
#endif
SecInit();
SecRandInit();
SecAesInit();
SecCmacInit();
SecEccInit();
// Only use legacy API.
Uint64ToBstream(features, 0);
Uint64ToBstream(mask, HCI_LE_SUP_FEAT_LE_EXT_ADV);
HciVsSetFeatures(features, mask);
handlerId = WsfOsSetNextHandler(HciHandler);
HciHandlerInit(handlerId);
handlerId = WsfOsSetNextHandler(DmHandler);
DmDevVsInit(0);
DmDevPrivInit();
#ifdef BTLE_APP_USE_LEGACY_API
DmScanInit();
DmConnInit();
DmConnMasterInit();
#else /* BTLE_APP_USE_LEGACY_API */
DmExtScanInit();
DmConnInit();
DmExtConnMasterInit();
#endif /* BTLE_APP_USE_LEGACY_API */
DmSecInit();
DmPhyInit();
DmSecLescInit();
DmPrivInit();
DmHandlerInit(handlerId);
......@@ -81,6 +157,7 @@ void StackInitDatc(void)
AttsInit();
AttsIndInit();
AttcInit();
AttsSignInit();
handlerId = WsfOsSetNextHandler(SmpHandler);
SmpHandlerInit(handlerId);
......
......@@ -29,10 +29,15 @@
# property whatsoever. Maxim Integrated Products, Inc. retains all
# ownership rights.
#
# $Id: Makefile 38151 2018-09-27 21:32:49Z zach.metzinger $
# $Id: Makefile 44505 2019-07-09 20:32:03Z nathan.goldstick $
#
################################################################################
# Include project configuration.
ifneq "$(wildcard config.mk)" ""
include config.mk
endif
# This is the name of the build output file
ifeq "$(PROJECT)" ""
PROJECT=max32665
......@@ -67,10 +72,8 @@ endif
# This is the path to the CMSIS root directory
ifeq "$(MAXIM_PATH)" ""
LIBS_DIR=../../../Libraries
NDALIBS_DIR=../../../NDALibraries
else
LIBS_DIR=/$(subst \,/,$(subst :,,$(MAXIM_PATH))/Firmware/$(TARGET_UC)/Libraries)
NDALIBS_DIR=/$(subst \,/,$(subst :,,$(MAXIM_PATH))/Firmware/$(TARGET_UC)/NDALibraries)
endif
CMSIS_ROOT=$(LIBS_DIR)/CMSIS
......@@ -78,21 +81,105 @@ CMSIS_ROOT=$(LIBS_DIR)/CMSIS
SRCS = main.c
SRCS += stack_dats.c
SRCS += dats_main.c
# Where to find source files for this test
VPATH = .
# Where to find header files for this test
IPATH = .
################################################################################
# Project build configuration.
#-------------------------------------------------------------------------------
# Configuration passed via environment vars.
ifdef BTLE_APP_USE_LEGACY_API
ifeq "$(BTLE_APP_USE_LEGACY_API)" ""
PROJ_CFLAGS+=-DBTLE_APP_USE_LEGACY_API=TRUE
else
ifeq "$(BTLE_APP_USE_LEGACY_API)" "0"
else
ifeq "$(BTLE_APP_USE_LEGACY_API)" "FALSE"
else
PROJ_CFLAGS+=-DBTLE_APP_USE_LEGACY_API=TRUE
endif
endif
endif
endif
ifdef CONSOLE_UART
ifneq "$(CONSOLE_UART)" ""
PROJ_CFLAGS+=-DCONSOLE_UART=$(CONSOLE_UART)
endif
endif
ifdef ENABLE_SDMA
ifneq "$(ENABLE_SDMA)" ""
ifeq "$(ENABLE_SDMA)" "0"
undefine ENABLE_SDMA
else
ifeq "$(ENABLE_SDMA)" "FALSE"
undefine ENABLE_SDMA
else
ENABLE_SDMA=1
endif
endif
endif
endif
ifneq "$(ENABLE_SDMA)" ""
ifdef BTLE_APP_USE_LEGACY_API
ifneq "$(BTLE_APP_USE_LEGACY_API)" ""
ifeq "$(BTLE_APP_USE_LEGACY_API)" "0"
$(error SDMA currently requires BTLE_APP_USE_LEGACY_API)
endif
ifeq "$(BTLE_APP_USE_LEGACY_API)" "FALSE"
$(error SDMA currently requires BTLE_APP_USE_LEGACY_API)
endif
endif
endif
endif
#-------------------------------------------------------------------------------
# Configuration specified here.
#--------------------
# Stack configuration
# Enable assertion checking for development
PROJ_CFLAGS+=-DMXC_ASSERT_ENABLE
PROJ_CFLAGS+=-DMXC_ASSERT_ENABLE=TRUE
# PROJ_CFLAGS+=-DWSF_TRACE_ENABLED=TRUE
PROJ_CFLAGS+=-DWSF_ASSERT_ENABLED=TRUE
# PROJ_CFLAGS+=-DLL_TRACE_ENABLED=TRUE
# PROJ_CFLAGS+=-DLL_DBG_PIN_ENABLED=TRUE
PROJ_CFLAGS+=-DWSF_MS_PER_TICK=1
#--------------------
# Application CFLAGS configuration
#--------------------
# Stack CFLAGS configuration
PROJ_CFLAGS+=-DINIT_BROADCASTER
# PROJ_CFLAGS+=-DINIT_OBSERVER
# PROJ_CFLAGS+=-DINIT_CENTRAL
PROJ_CFLAGS+=-DINIT_PERIPHERAL
PROJ_CFLAGS+=-DINIT_ENCRYPTED
ENABLE_LL_TESTER?=#1
# Use this variable to override default compilier optimization.
#MXC_OPTIMIZE_CFLAGS=-Os
#MXC_OPTIMIZE_CFLAGS=-O0 -fomit-frame-pointer
# Point this variable to a linker file to override the default file
#LINKERFILE=$(CMSIS_ROOT)/Device/Maxim/$(TARGET_UC)/Source/GCC/$(TARGET_LC).ld
################################################################################
# Include external library makefiles here
DEBUG=1
# Include the BSP
BOARD_DIR=$(LIBS_DIR)/Boards/$(BOARD)
......@@ -103,8 +190,7 @@ PERIPH_DRIVER_DIR=$(LIBS_DIR)/$(TARGET)PeriphDriver
include ${PERIPH_DRIVER_DIR}/periphdriver.mk
# Include Cordio BTLE Library
TRACE=1
CORDIO_DIR=$(NDALIBS_DIR)/BTLE
CORDIO_DIR=$(LIBS_DIR)/BTLE
include ${CORDIO_DIR}/btle.mk
# Include MAXUSB library
......
# Specifies whether the legacy 4.2 api should be used.
# 1 by default.
# Set to 1 to use 4.2 advertisements.
# Set to 0 to use 5.0 extended advertisements.
BTLE_APP_USE_LEGACY_API?=1
# UART used for console output.
# 1 by default.
CONSOLE_UART?=1
# Run link layer using SDMA.
ENABLE_SDMA?=0
......@@ -26,6 +26,7 @@
#include "wsf_buf.h"
#include "wsf_assert.h"
#include "hci_api.h"
#include "hci_vs.h"
#include "sec_api.h"
#include "dm_api.h"
#include "smp_api.h"
......@@ -58,11 +59,23 @@ enum
/*! configurable parameters for advertising */
/* These intervals directly impact energy usage during the non-connected/advertising mode */
#ifdef BTLE_APP_USE_LEGACY_API
static const appAdvCfg_t datsAdvCfg =
{
{ 1000, 0, 0}, /*! Advertising durations in ms */
{ 96, 200, 0} /*! Advertising intervals in 0.625 ms units */
};
#else /* BTLE_APP_USE_LEGACY_API */
static const appExtAdvCfg_t datsExtAdvCfg =
{
{ 0, 0, 0}, /*! Advertising durations for extended advertising in ms */
{ 96, 200, 0}, /*! Advertising intervals for extended advertising in 0.625 ms units (20 ms to 10.24 s). */
{ 0, 0, 0}, /*! Maximum number of extended advertising events controller will send prior to terminating extended advertising */
{ 0, 0, 0}, /*! Whether to use legacy advertising PDUs with extended advertising. If set to TRUE then length of advertising data cannot exceed 31 octets. */
{ 6, 0, 0} /*! Advertising intervals for periodic advertising in 1.25 ms units (7.5 ms to 81.91875 s). */
};
#endif /* BTLE_APP_USE_LEGACY_API */
/*! configurable parameters for slave */
static const appSlaveCfg_t datsSlaveCfg =
......@@ -125,6 +138,7 @@ static uint8_t localIrk[] =
Advertising Data
**************************************************************************************************/
#ifdef BTLE_APP_USE_LEGACY_API
/*! advertising data, discoverable mode */
static const uint8_t datsAdvDataDisc[] =
{
......@@ -149,12 +163,55 @@ static const uint8_t datsScanDataDisc[] =
'D',
'a',
't',
's',
' ',
'T',
'X'
};
#else /* BTLE_APP_USE_LEGACY_API */
/*! extended advertising and scan data, discoverable mode */
static const uint8_t datsExtAdvDataDisc[] =
{
/*! flags */
2, /*! length */
DM_ADV_TYPE_FLAGS, /*! AD type */
DM_FLAG_LE_GENERAL_DISC | /*! flags */
DM_FLAG_LE_BREDR_NOT_SUP,
/*! manufacturer specific data */
3, /*! length */
DM_ADV_TYPE_MANUFACTURER, /*! AD type */
UINT16_TO_BYTES(HCI_ID_ARM), /*! company ID */
/*! device name */
8, /*! length */
DM_ADV_TYPE_LOCAL_NAME, /*! AD type */
'D',
'a',
't',
's',
' ',
'T',
'X'
};
static const uint8_t datsExtScanDataDisc[] =
{
/*! device name */
8, /*! length */
DM_ADV_TYPE_LOCAL_NAME, /*! AD type */
'D',
'a',
't',
's',
' ',
'T',
'X'
};
#endif /* BTLE_APP_USE_LEGACY_API */
/**************************************************************************************************
Client Characteristic Configuration Descriptors
**************************************************************************************************/
......@@ -343,13 +400,21 @@ static dmSecKey_t *datsGetPeerKey(dmEvt_t *pMsg)
/*************************************************************************************************/
static void datsPrivAddDevToResListInd(dmEvt_t *pMsg)
{
#ifndef BTLE_APP_USE_LEGACY_API
uint8_t addrZeros[BDA_ADDR_LEN] = { 0 };
#endif /* BTLE_APP_USE_LEGACY_API */
dmSecKey_t *pPeerKey;
/* if peer IRK present */
if ((pPeerKey = datsGetPeerKey(pMsg)) != NULL)
{
/* set advertising peer address */
#ifdef BTLE_APP_USE_LEGACY_API
AppSetAdvPeerAddr(pPeerKey->irk.addrType, pPeerKey->irk.bdAddr);
#else /* BTLE_APP_USE_LEGACY_API */
AppExtSetAdvPeerAddr(DM_ADV_HANDLE_DEFAULT, HCI_ADDR_TYPE_PUBLIC, addrZeros);
#endif /* BTLE_APP_USE_LEGACY_API */
}
}
......@@ -377,7 +442,11 @@ static void datsPrivRemDevFromResListInd(dmEvt_t *pMsg)
uint8_t addrZeros[BDA_ADDR_LEN] = { 0 };
/* clear advertising peer address and its type */
#ifdef BTLE_APP_USE_LEGACY_API
AppSetAdvPeerAddr(HCI_ADDR_TYPE_PUBLIC, addrZeros);
#else /* BTLE_APP_USE_LEGACY_API */
AppExtSetAdvPeerAddr(DM_ADV_HANDLE_DEFAULT, HCI_ADDR_TYPE_PUBLIC, addrZeros);
#endif /* BTLE_APP_USE_LEGACY_API */
}
}
}
......@@ -409,25 +478,45 @@ void datsDisplayStackVersion(const char *pVersion)
/*************************************************************************************************/
static void datsSetup(dmEvt_t *pMsg)
{
/* If this is defined to one, scan responses and connections limited to the EvKit dats peer */
#if 0
#ifndef BTLE_APP_USE_LEGACY_API
uint8_t advHandle;
#endif /* BTLE_APP_USE_LEGACY_API */
/* Scan responses and connections limited to the EvKit dats peer */
DmDevWhiteListAdd(DM_ADDR_PUBLIC, (bdAddr_t){0x02, 0x01, 0x44, 0x8B, 0x05, 0x00});
DmDevSetFilterPolicy(DM_FILT_POLICY_MODE_ADV, HCI_FILT_WHITE_LIST);
#endif
/* set advertising and scan response data for discoverable mode */
#ifdef BTLE_APP_USE_LEGACY_API
AppAdvSetData(APP_ADV_DATA_DISCOVERABLE, sizeof(datsAdvDataDisc), (uint8_t *) datsAdvDataDisc);
AppAdvSetData(APP_SCAN_DATA_DISCOVERABLE, sizeof(datsScanDataDisc), (uint8_t *) datsScanDataDisc);
#else /* BTLE_APP_USE_LEGACY_API */
AppExtAdvSetData(DM_ADV_HANDLE_DEFAULT, APP_ADV_DATA_DISCOVERABLE, sizeof(datsExtAdvDataDisc), (uint8_t *) datsExtAdvDataDisc, HCI_EXT_ADV_DATA_LEN);
AppExtAdvSetData(DM_ADV_HANDLE_DEFAULT, APP_SCAN_DATA_DISCOVERABLE, sizeof(datsExtScanDataDisc), (uint8_t *) datsExtScanDataDisc, HCI_EXT_ADV_DATA_LEN);
#endif /* BTLE_APP_USE_LEGACY_API */
/* set advertising and scan response data for connectable mode */
#ifdef BTLE_APP_USE_LEGACY_API
AppAdvSetData(APP_ADV_DATA_CONNECTABLE, sizeof(datsAdvDataDisc), (uint8_t *) datsAdvDataDisc);
AppAdvSetData(APP_SCAN_DATA_CONNECTABLE, sizeof(datsScanDataDisc), (uint8_t *) datsScanDataDisc);
#else /* BTLE_APP_USE_LEGACY_API */
AppExtAdvSetData(DM_ADV_HANDLE_DEFAULT, APP_ADV_DATA_CONNECTABLE, sizeof(datsExtAdvDataDisc), (uint8_t *) datsExtAdvDataDisc, HCI_EXT_ADV_DATA_LEN);
AppExtAdvSetData(DM_ADV_HANDLE_DEFAULT, APP_SCAN_DATA_CONNECTABLE, sizeof(datsExtScanDataDisc), (uint8_t *) datsExtScanDataDisc, HCI_EXT_ADV_DATA_LEN);
#endif /* BTLE_APP_USE_LEGACY_API */
/* 0x3 : 1M and 2M PHYs */
DmSetDefaultPhy(0, 0x3, 0x3);
DmSetDefaultPhy(0, HCI_PHY_LE_1M_BIT | HCI_PHY_LE_2M_BIT, HCI_PHY_LE_1M_BIT | HCI_PHY_LE_2M_BIT);
/* start advertising; automatically set connectable/discoverable mode and bondable mode */
#ifndef BTLE_APP_USE_LEGACY_API
advHandle = DM_ADV_HANDLE_DEFAULT;
#endif /* BTLE_APP_USE_LEGACY_API */
#ifdef BTLE_APP_USE_LEGACY_API
AppAdvStart(APP_MODE_AUTO_INIT);
#else /* BTLE_APP_USE_LEGACY_API */
AppExtAdvStart(1, &advHandle, APP_MODE_AUTO_INIT);
#endif /* BTLE_APP_USE_LEGACY_API */
}
/*************************************************************************************************/
......@@ -455,10 +544,22 @@ static void datsProcMsg(dmEvt_t *pMsg)
uiEvent = APP_UI_ADV_START;
break;
#ifndef BTLE_APP_IGNORE_EXT_EVENTS
case DM_ADV_SET_START_IND:
uiEvent = APP_UI_ADV_SET_START_IND;
break;
#endif /* BTLE_APP_IGNORE_EXT_EVENTS */
case DM_ADV_STOP_IND:
uiEvent = APP_UI_ADV_STOP;
break;
#ifndef BTLE_APP_IGNORE_EXT_EVENTS
case DM_ADV_SET_STOP_IND:
uiEvent = APP_UI_ADV_SET_STOP_IND;
break;
#endif /* BTLE_APP_IGNORE_EXT_EVENTS */
case DM_CONN_OPEN_IND:
uiEvent = APP_UI_CONN_OPEN;
break;
......@@ -534,6 +635,9 @@ static void datsProcMsg(dmEvt_t *pMsg)
case DM_ADV_NEW_ADDR_IND:
break;
case DM_VENDOR_SPEC_IND:
break;
default:
break;
}
......@@ -562,7 +666,11 @@ void DatsHandlerInit(wsfHandlerId_t handlerId)
/* Set configuration pointers */
pAppSlaveCfg = (appSlaveCfg_t *) &datsSlaveCfg;
#ifdef BTLE_APP_USE_LEGACY_API
pAppAdvCfg = (appAdvCfg_t *) &datsAdvCfg;
#else /* BTLE_APP_USE_LEGACY_API */
pAppExtAdvCfg = (appExtAdvCfg_t *) &datsExtAdvCfg;
#endif /* BTLE_APP_USE_LEGACY_API */
pAppSecCfg = (appSecCfg_t *) &datsSecCfg;
pAppUpdateCfg = (appUpdateCfg_t *) &datsUpdateCfg;
pSmpCfg = (smpCfg_t *) &datsSmpCfg;
......
......@@ -29,48 +29,47 @@
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2019-02-11 23:36:35 +0000 (Mon, 11 Feb 2019) $
* $Revision: 40967 $
* $Date: 2019-07-11 13:33:24 -0500 (Thu, 11 Jul 2019) $
* $Revision: 44549 $
*
******************************************************************************/
#include <stdio.h>
#include <string.h>
#include "mxc_config.h"
#include "wsf_types.h"
#include "wsf_os.h"
#include "wsf_buf.h"
#include "wsf_timer.h"
#include "wsf_trace.h"
#include "app_ui.h"
#include "ll_api.h"
#include "sch_api.h"
#include "dats/dats_api.h"
#include "mxc_config.h"
#include "gcr_regs.h"
#include "mcr_regs.h"
#include "app_ui.h"
#include "hci_vs.h"
#include "hci_core.h"
/**************************************************************************************************
Macros
**************************************************************************************************/
/* Number of WSF buffer pools */
#define WSF_BUF_POOLS 6
/* Size of buffer for stdio functions */
#define WSF_BUF_POOLS 6
#define WSF_BUF_SIZE 0x1048
/* Size of buffer for stdio functions */
#define PRINTF_BUF_SIZE 128
#define PRINTF_BUF_SIZE 128
/**************************************************************************************************
Local Variables
**************************************************************************************************/
uint32_t SystemHeapSize=WSF_BUF_SIZE;
uint32_t SystemHeap[WSF_BUF_SIZE/4];
uint32_t SystemHeapStart;
/*! Buffer for stdio functions */
char printf_buffer[PRINTF_BUF_SIZE];
/*! Free memory for pool buffers (use word elements for word alignment). */
static uint32_t mainBufMem[3584/sizeof(uint32_t)+96];
/*! Default pool descriptor. */
static wsfBufPoolDesc_t mainPoolDesc[WSF_BUF_POOLS] =
{
......@@ -79,7 +78,7 @@ static wsfBufPoolDesc_t mainPoolDesc[WSF_BUF_POOLS] =
{ 64, 4 },
{ 128, 4 },
{ 256, 4 },
{ 384, 4 }
{ 512, 4 }
};
/**************************************************************************************************
......@@ -89,6 +88,12 @@ static wsfBufPoolDesc_t mainPoolDesc[WSF_BUF_POOLS] =
/*! \brief Stack initialization for app. */
extern void StackInitDats(void);
/*************************************************************************************************/
void PalSysAssertTrap(void)
{
while(1) {}
}
/*************************************************************************************************/
void SysTick_Handler(void)
{
......@@ -96,15 +101,17 @@ void SysTick_Handler(void)
}
/*************************************************************************************************/
static void myTrace(const char *pStr, va_list args)
static bool_t myTrace(const uint8_t *pBuf, uint32_t len)
{
extern uint8_t wsfCsNesting;
if (wsfCsNesting == 0)
{
vprintf(pStr, args);
printf("\r\n");
fwrite(pBuf, len, 1, stdout);
return TRUE;
}
return FALSE;
}
/*************************************************************************************************/
......@@ -116,47 +123,23 @@ static void myTrace(const char *pStr, va_list args)
/*************************************************************************************************/
static void WsfInit(void)
{
WsfTimerInit();
WsfBufInit(sizeof(mainBufMem), (uint8_t*)mainBufMem, WSF_BUF_POOLS, mainPoolDesc);
WsfTraceRegister(myTrace);
}
/*************************************************************************************************/
/*!
* \brief Initialize platform.
*
* \param msPerTick Milliseconds per timer tick.
*
* \return None.
*/
/*************************************************************************************************/
void PlatformInit(void)
{
/* Change the pullup on the RST pin to 25K */
MXC_MCR->ctrl = 0x202;
/* Set VREGO_D to 1.3V */
*((volatile uint32_t*)0x40004410) = 0x50;
/* Set TX LDO to 1.1V and enable LDO. Set RX LDO to 0.9V and enable LDO */
MXC_GCR->btleldocn = 0xD9; // TX 1.1V RX 0.9V
/* Power up the 32MHz XO */
MXC_GCR->clkcn |= MXC_F_GCR_CLKCN_X32M_EN;
/* Enable peripheral clocks */
MXC_GCR->perckcn0 &= ~(MXC_F_GCR_PERCKCN0_GPIO0D | MXC_F_GCR_PERCKCN0_GPIO1D); // Clear GPIO0 and GPIO1 Disable
MXC_GCR->perckcn1 &= ~(MXC_F_GCR_PERCKCN1_BTLED | MXC_F_GCR_PERCKCN1_TRNGD ); // Clear BTLE and ICACHE0 disable
/* setup the systick */
uint32_t bytesUsed;
/* setup the systick for 1MS timer*/
SysTick->LOAD = (SystemCoreClock / 1000) * WSF_MS_PER_TICK;
SysTick->VAL = 0;
SysTick->CTRL |= (SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk | SysTick_CTRL_TICKINT_Msk);
#ifndef __IAR_SYSTEMS_ICC__
/* Added to prevent printf() and friends from using malloc() */
setvbuf(stdout, printf_buffer, _IOLBF, PRINTF_BUF_SIZE);
#endif
WsfTimerInit();
SystemHeapStart = (uint32_t)&SystemHeap;
memset(SystemHeap, 0, sizeof(SystemHeap));
printf("SystemHeapStart = 0x%x\n", SystemHeapStart);
printf("SystemHeapSize = 0x%x\n", SystemHeapSize);
bytesUsed = WsfBufInit(WSF_BUF_POOLS, mainPoolDesc);
printf("bytesUsed = 0x%x\n", bytesUsed);
WsfTraceRegisterHandler(myTrace);
WsfTraceEnable(TRUE);
}
/*
......@@ -170,39 +153,15 @@ void SetAddress(uint8_t event)
uint8_t bdAddr[6] = {0x02, 0x00, 0x44, 0x8B, 0x05, 0x00};
switch (event) {
case APP_UI_RESET_CMPL:
printf("Setting address -- MAC %02X:%02X:%02X:%02X:%02X:%02X\n", bdAddr[5], bdAddr[4], bdAddr[3], bdAddr[2], bdAddr[1], bdAddr[0]);
LlSetBdAddr((uint8_t*)&bdAddr);
LlGetBdAddr(hciCoreCb.bdAddr);
break;
default:
break;
case APP_UI_RESET_CMPL:
printf("Setting address -- MAC %02X:%02X:%02X:%02X:%02X:%02X\n", bdAddr[5], bdAddr[4], bdAddr[3], bdAddr[2], bdAddr[1], bdAddr[0]);
HciVsSetBdAddr(bdAddr);
break;
default:
break;
}
}
/*************************************************************************************************/
/*!
* \brief Initialize MAC layer.
*
* \param None.
*
* \return None.
*/
/*************************************************************************************************/
void MacInit(void)
{
wsfHandlerId_t handlerId;
/* Initialize link layer. */
BbInit();
handlerId = WsfOsSetNextHandler(SchHandler);
SchInit(handlerId);
LlAdvSlaveInit();
LlConnSlaveInit();
handlerId = WsfOsSetNextHandler(LlHandler);
LlHandlerInit(handlerId);
}
/*************************************************************************************************/
/*!
* \fn main
......@@ -216,11 +175,15 @@ void MacInit(void)
/*************************************************************************************************/
int main(void)
{
#ifndef __IAR_SYSTEMS_ICC__
setvbuf(stdout, printf_buffer, _IOLBF, PRINTF_BUF_SIZE);
#endif
printf("\n\n***** MAX32665 BLE Data Server *****\n");
PlatformInit();
/* Initialize Radio */
WsfInit();
MacInit();
StackInitDats();
DatsStart();
......
......@@ -17,13 +17,13 @@
*/
/*************************************************************************************************/
#include <stdio.h>
#include <string.h>
#include "wsf_types.h"
#include "wsf_os.h"
#include "util/bstream.h"
#include "dats/dats_api.h"
#include "wdxs/wdxs_api.h"
#include "hci_handler.h"
#include "dm_handler.h"
#include "l2c_handler.h"
......@@ -36,6 +36,56 @@
#include "svc_dis.h"
#include "svc_core.h"
#include "sec_api.h"
#include "ll_init_api.h"
#define LL_IMPL_REV 0x2303
#define LL_MEMORY_FOOTPRINT 0xc152
uint8_t LlMem[LL_MEMORY_FOOTPRINT];
const LlRtCfg_t _ll_cfg = {
/* Device */
/*compId*/ LL_COMP_ID_ARM,
/*implRev*/ LL_IMPL_REV,
/*btVer*/ LL_VER_BT_CORE_SPEC_5_0,
/*_align32 */ 0, // padding for alignment
/* Advertiser */
/*maxAdvSets*/ 4, // 4 Extended Advertising Sets
/*maxAdvReports*/ 8,
/*maxExtAdvDataLen*/ LL_MAX_ADV_DATA_LEN,
/*defExtAdvDataFrag*/ 64,
/*auxDelayUsec*/ 0,
/* Scanner */
/*maxScanReqRcvdEvt*/ 4,
/*maxExtScanDataLen*/ LL_MAX_ADV_DATA_LEN,
/* Connection */
/*maxConn*/ 2,
/*numTxBufs*/ 16,
/*numRxBufs*/ 16,
/*maxAclLen*/ 512,
/*defTxPwrLvl*/ 0,
/*ceJitterUsec*/ 0,
/* DTM */
/*dtmRxSyncMs*/ 10000,
/* PHY */
/*phy2mSup*/ TRUE,
/*phyCodedSup*/ FALSE,
/*stableModIdxTxSup*/ FALSE,
/*stableModIdxRxSup*/ FALSE
};
const BbRtCfg_t _bb_cfg = {
/*clkPpm*/ 20,
/*rfSetupDelayUsec*/ BB_RF_SETUP_DELAY_US,
/*maxScanPeriodMsec*/ BB_MAX_SCAN_PERIOD_MS,
/*schSetupDelayUsec*/ BB_SCH_SETUP_DELAY_US
};
/*************************************************************************************************/
/*!
......@@ -47,27 +97,49 @@
void StackInitDats(void)
{
wsfHandlerId_t handlerId;
uint8_t features[sizeof(uint64_t)];
uint8_t mask[sizeof(uint64_t)];
SecInit();
SecAesInit();
SecCmacInit();
SecEccInit();
#ifndef ENABLE_SDMA
uint32_t memUsed;
/* Initialize link layer. */
LlInitRtCfg_t ll_init_cfg =
{
.pBbRtCfg = &_bb_cfg,
.wlSizeCfg = 4,
.rlSizeCfg = 4,
.plSizeCfg = 4,
.pLlRtCfg = &_ll_cfg,
.pFreeMem = LlMem,
.freeMemAvail = LL_MEMORY_FOOTPRINT
};
// Only use legacy API.
Uint64ToBstream(features, 0);
Uint64ToBstream(mask, HCI_LE_SUP_FEAT_LE_EXT_ADV);
HciVsSetFeatures(features, mask);
memUsed = LlInitControllerExtInit(&ll_init_cfg);
if(memUsed != LL_MEMORY_FOOTPRINT)
{
printf("mem_used: 0x%x LL_MEMORY_FOOTPRINT: 0x%x\n", memUsed,
LL_MEMORY_FOOTPRINT);
}
#endif
handlerId = WsfOsSetNextHandler(HciHandler);
HciHandlerInit(handlerId);
SecInit();
SecAesInit();
SecCmacInit();
SecEccInit();
handlerId = WsfOsSetNextHandler(DmHandler);
DmDevVsInit(0);
#ifdef BTLE_APP_USE_LEGACY_API
DmAdvInit();
DmConnInit();
DmConnSlaveInit();
#else /* BTLE_APP_USE_LEGACY_API */
DmExtAdvInit();
DmConnInit();
DmExtConnSlaveInit();
#endif /* BTLE_APP_USE_LEGACY_API */
DmSecInit();
DmSecLescInit();
DmPrivInit();
......@@ -99,4 +171,5 @@ void StackInitDats(void)
handlerId = WsfOsSetNextHandler(WdxsHandler);
WdxsHandlerInit(handlerId);
#endif
}
......@@ -29,10 +29,15 @@
# property whatsoever. Maxim Integrated Products, Inc. retains all
# ownership rights.
#
# $Id: Makefile 38694 2018-10-24 20:41:14Z zach.metzinger $
# $Id: Makefile 44577 2019-07-11 21:47:07Z kevin.gillespie $
#
################################################################################
# Include project configuration.
ifneq "$(wildcard config.mk)" ""
include config.mk
endif
# This is the name of the build output file
ifeq "$(PROJECT)" ""
PROJECT=max32665
......@@ -67,10 +72,8 @@ endif
# This is the path to the CMSIS root directory
ifeq "$(MAXIM_PATH)" ""
LIBS_DIR=../../../Libraries
NDALIBS_DIR=../../../NDALibraries
else
LIBS_DIR=/$(subst \,/,$(subst :,,$(MAXIM_PATH))/Firmware/$(TARGET_UC)/Libraries)
NDALIBS_DIR=/$(subst \,/,$(subst :,,$(MAXIM_PATH))/Firmware/$(TARGET_UC)/NDALibraries)
endif
CMSIS_ROOT=$(LIBS_DIR)/CMSIS
......@@ -78,7 +81,6 @@ CMSIS_ROOT=$(LIBS_DIR)/CMSIS
SRCS = main.c
SRCS += stack_fit.c
SRCS += fit_main.c
SRCS += svc_dis.c
# Where to find source files for this test
VPATH = .
......@@ -86,10 +88,64 @@ VPATH = .
# Where to find header files for this test
IPATH = .
################################################################################
# Project build configuration.
#-------------------------------------------------------------------------------
# Configuration passed via environment vars.
ifdef CONSOLE_UART
ifneq "$(CONSOLE_UART)" ""
PROJ_CFLAGS+=-DCONSOLE_UART=$(CONSOLE_UART)
endif
endif
ifdef ENABLE_SDMA
ifneq "$(ENABLE_SDMA)" ""
ifeq "$(ENABLE_SDMA)" "0"
undefine ENABLE_SDMA
else
ifeq "$(ENABLE_SDMA)" "FALSE"
undefine ENABLE_SDMA
else
ENABLE_SDMA=1
endif
endif
endif
endif
#-------------------------------------------------------------------------------
# Configuration specified here.
#--------------------
# Stack configuration
# Enable assertion checking for development
PROJ_CFLAGS+=-DMXC_ASSERT_ENABLE
PROJ_CFLAGS+=-DMXC_ASSERT_ENABLE=TRUE
PROJ_CFLAGS+=-DWSF_TRACE_ENABLED=TRUE
PROJ_CFLAGS+=-DWSF_ASSERT_ENABLED=TRUE
# PROJ_CFLAGS+=-DLL_TRACE_ENABLED=TRUE
# PROJ_CFLAGS+=-DLL_DBG_PIN_ENABLED=TRUE
PROJ_CFLAGS+=-DWSF_MS_PER_TICK=1
#--------------------
# Application CFLAGS configuration
#--------------------
# Stack CFLAGS configuration
PROJ_CFLAGS+=-DINIT_BROADCASTER
# PROJ_CFLAGS+=-DINIT_OBSERVER
# PROJ_CFLAGS+=-DINIT_CENTRAL
PROJ_CFLAGS+=-DINIT_PERIPHERAL
PROJ_CFLAGS+=-DINIT_ENCRYPTED
ENABLE_LL_TESTER?=#1
# Use this variable to override default compilier optimization.
#MXC_OPTIMIZE_CFLAGS=-Os
#MXC_OPTIMIZE_CFLAGS=-O0 -fomit-frame-pointer
# Point this variable to a linker file to override the default file
#LINKERFILE=$(CMSIS_ROOT)/Device/Maxim/$(TARGET_UC)/Source/GCC/$(TARGET_LC).ld
......@@ -106,8 +162,7 @@ PERIPH_DRIVER_DIR=$(LIBS_DIR)/$(TARGET)PeriphDriver
include ${PERIPH_DRIVER_DIR}/periphdriver.mk
# Include Cordio BTLE Library
TRACE=1
CORDIO_DIR=$(NDALIBS_DIR)/BTLE
CORDIO_DIR=$(LIBS_DIR)/BTLE
include ${CORDIO_DIR}/btle.mk
# Include MAXUSB library
......
# UART used for console output.
# 1 by default.
CONSOLE_UART?=1
# Run link layer using SDMA.
ENABLE_SDMA?=0
......@@ -23,6 +23,7 @@
#include "util/bstream.h"
#include "wsf_msg.h"
#include "wsf_trace.h"
#include "wsf_buf.h"
#include "hci_api.h"
#include "dm_api.h"
#include "att_api.h"
......@@ -40,7 +41,8 @@
#include "bas/bas_api.h"
#include "hrps/hrps_api.h"
#include "rscp/rscp_api.h"
#include "fit_api.h"
#include "fit/fit_api.h"
#include "util/calc128.h"
/**************************************************************************************************
Macros
......@@ -88,7 +90,7 @@ static const appAdvCfg_t fitAdvCfg =
/*! configurable parameters for slave */
static const appSlaveCfg_t fitSlaveCfg =
{
FIT_CONN_MAX, /*! Maximum connections */
1, /*! Maximum connections */
};
/*! configurable parameters for security */
......@@ -98,9 +100,12 @@ static const appSecCfg_t fitSecCfg =
0, /*! Initiator key distribution flags */
DM_KEY_DIST_LTK, /*! Responder key distribution flags */
FALSE, /*! TRUE if Out-of-band pairing data is present */
TRUE /*! TRUE to initiate security upon connection */
FALSE /*! TRUE to initiate security upon connection */
};
/*! TRUE if Out-of-band pairing data is to be sent */
static const bool_t fitSendOobData = FALSE;
/*! configurable parameters for connection parameter update */
static const appUpdateCfg_t fitUpdateCfg =
{
......@@ -216,6 +221,9 @@ static uint16_t fitRscmPeriod = FIT_DEFAULT_RSCM_PERIOD;
/* Heart Rate Monitor feature flags */
static uint8_t fitHrmFlags = CH_HRM_FLAGS_VALUE_8BIT | CH_HRM_FLAGS_ENERGY_EXP;
/* LESC OOB configuration */
static dmSecLescOobCfg_t *fitOobCfg;
/*************************************************************************************************/
/*!
* \brief Application DM callback.
......@@ -230,12 +238,40 @@ static void fitDmCback(dmEvt_t *pDmEvt)
dmEvt_t *pMsg;
uint16_t len;
len = DmSizeOfEvt(pDmEvt);
if (pDmEvt->hdr.event == DM_SEC_ECC_KEY_IND)
{
DmSecSetEccKey(&pDmEvt->eccMsg.data.key);
if ((pMsg = WsfMsgAlloc(len)) != NULL)
// If the local device sends OOB data.
if (fitSendOobData)
{
uint8_t oobLocalRandom[SMP_RAND_LEN];
SecRand(oobLocalRandom, SMP_RAND_LEN);
DmSecCalcOobReq(oobLocalRandom, pDmEvt->eccMsg.data.key.pubKey_x);
}
}
else if (pDmEvt->hdr.event == DM_SEC_CALC_OOB_IND)
{
memcpy(pMsg, pDmEvt, len);
WsfMsgSend(fitHandlerId, pMsg);
if (fitOobCfg == NULL)
{
fitOobCfg = WsfBufAlloc(sizeof(dmSecLescOobCfg_t));
}
if (fitOobCfg)
{
Calc128Cpy(fitOobCfg->localConfirm, pDmEvt->oobCalcInd.confirm);
Calc128Cpy(fitOobCfg->localRandom, pDmEvt->oobCalcInd.random);
}
}
else
{
len = DmSizeOfEvt(pDmEvt);
if ((pMsg = WsfMsgAlloc(len)) != NULL)
{
memcpy(pMsg, pDmEvt, len);
WsfMsgSend(fitHandlerId, pMsg);
}
}
}
......
......@@ -29,47 +29,56 @@
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2019-02-11 23:36:35 +0000 (Mon, 11 Feb 2019) $
* $Revision: 40967 $
* $Date: 2019-07-11 16:47:07 -0500 (Thu, 11 Jul 2019) $
* $Revision: 44577 $
*
******************************************************************************/
#include <stdio.h>
#include <string.h>
#include "mxc_config.h"
#include "wsf_types.h"
#include "wsf_os.h"
#include "wsf_buf.h"
#include "wsf_timer.h"
#include "wsf_trace.h"
#include "app_ui.h"
#include "ll_api.h"
#include "sch_api.h"
#include "fit/fit_api.h"
#include "mxc_config.h"
#include "gcr_regs.h"
#include "mcr_regs.h"
#include "app_ui.h"
#include "hci_vs.h"
#include "hci_core.h"
#include "pb.h"
#include "tmr.h"
/**************************************************************************************************
Macros
**************************************************************************************************/
/* Number of WSF buffer pools */
#define WSF_BUF_POOLS 6
/* Size of buffer for stdio functions */
#define WSF_BUF_POOLS 6
#define WSF_BUF_SIZE 0x1048
/* Size of buffer for stdio functions */
#define PRINTF_BUF_SIZE 128
#define PRINTF_BUF_SIZE 128
/* Definitions for push button handling */
#define BUTTON0_TMR MXC_TMR0
#define BUTTON1_TMR MXC_TMR1
#define BUTTON_SHORT_MS 200
#define BUTTON_MED_MS 500
#define BUTTON_LONG_MS 1000
/**************************************************************************************************
Local Variables
**************************************************************************************************/
uint32_t SystemHeapSize=WSF_BUF_SIZE;
uint32_t SystemHeap[WSF_BUF_SIZE/4];
uint32_t SystemHeapStart;
/*! Buffer for stdio functions */
char printf_buffer[PRINTF_BUF_SIZE];
/*! Free memory for pool buffers (use word elements for word alignment). */
static uint32_t mainBufMem[3584/sizeof(uint32_t)+96];
/*! Default pool descriptor. */
static wsfBufPoolDesc_t mainPoolDesc[WSF_BUF_POOLS] =
{
......@@ -78,7 +87,7 @@ static wsfBufPoolDesc_t mainPoolDesc[WSF_BUF_POOLS] =
{ 64, 4 },
{ 128, 4 },
{ 256, 4 },
{ 384, 4 }
{ 512, 4 }
};
/**************************************************************************************************
......@@ -88,7 +97,11 @@ static wsfBufPoolDesc_t mainPoolDesc[WSF_BUF_POOLS] =
/*! \brief Stack initialization for app. */
extern void StackInitFit(void);
void HciVsSetPublicAddr(uint8_t *bdAddr);
/*************************************************************************************************/
void PalSysAssertTrap(void)
{
while(1) {}
}
/*************************************************************************************************/
void SysTick_Handler(void)
......@@ -97,15 +110,17 @@ void SysTick_Handler(void)
}
/*************************************************************************************************/
static void myTrace(const char *pStr, va_list args)
static bool_t myTrace(const uint8_t *pBuf, uint32_t len)
{
extern uint8_t wsfCsNesting;
if (wsfCsNesting == 0)
{
vprintf(pStr, args);
printf("\r\n");
fwrite(pBuf, len, 1, stdout);
return TRUE;
}
return FALSE;
}
/*************************************************************************************************/
......@@ -117,49 +132,24 @@ static void myTrace(const char *pStr, va_list args)
/*************************************************************************************************/
static void WsfInit(void)
{
WsfTimerInit();
WsfBufInit(sizeof(mainBufMem), (uint8_t*)mainBufMem, WSF_BUF_POOLS, mainPoolDesc);
WsfTraceRegister(myTrace);
}
/*************************************************************************************************/
/*!
* \brief Initialize platform.
*
* \param msPerTick Milliseconds per timer tick.
*
* \return None.
*/
/*************************************************************************************************/
void PlatformInit(void)
{
/* Change the pullup on the RST pin to 25K */
MXC_MCR->ctrl = 0x202;
/* Set VREGO_D to 1.3V */
*((volatile uint32_t*)0x40004410) = 0x50;
/* Set TX LDO to 1.1V and enable LDO. Set RX LDO to 0.9V and enable LDO */
MXC_GCR->btleldocn = 0xD9; // TX 1.1V RX 0.9V
/* Power up the 32MHz XO */
MXC_GCR->clkcn |= MXC_F_GCR_CLKCN_X32M_EN;
/* Enable peripheral clocks */
MXC_GCR->perckcn0 &= ~(MXC_F_GCR_PERCKCN0_GPIO0D | MXC_F_GCR_PERCKCN0_GPIO1D); // Clear GPIO0 and GPIO1 Disable
MXC_GCR->perckcn1 &= ~(MXC_F_GCR_PERCKCN1_BTLED | MXC_F_GCR_PERCKCN1_TRNGD ); // Clear BTLE and ICACHE0 disable
/* setup the systick */
uint32_t bytesUsed;
/* setup the systick for 1MS timer*/
SysTick->LOAD = (SystemCoreClock / 1000) * WSF_MS_PER_TICK;
SysTick->VAL = 0;
SysTick->CTRL |= (SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk | SysTick_CTRL_TICKINT_Msk);
#ifndef __IAR_SYSTEMS_ICC__
/* Added to prevent printf() and friends from using malloc() */
setvbuf(stdout, printf_buffer, _IOLBF, PRINTF_BUF_SIZE);
#endif
}
WsfTimerInit();
SystemHeapStart = (uint32_t)&SystemHeap;
memset(SystemHeap, 0, sizeof(SystemHeap));
printf("SystemHeapStart = 0x%x\n", SystemHeapStart);
printf("SystemHeapSize = 0x%x\n", SystemHeapSize);
bytesUsed = WsfBufInit(WSF_BUF_POOLS, mainPoolDesc);
printf("bytesUsed = 0x%x\n", bytesUsed);
WsfTraceRegisterHandler(myTrace);
WsfTraceEnable(TRUE);
}
/*
* In two-chip solutions, setting the address must wait until the HCI interface is initialized.
......@@ -172,37 +162,61 @@ void SetAddress(uint8_t event)
uint8_t bdAddr[6] = {0x02, 0x02, 0x44, 0x8B, 0x05, 0x00};
switch (event) {
case APP_UI_RESET_CMPL:
printf("Setting address -- MAC %02X:%02X:%02X:%02X:%02X:%02X\n", bdAddr[5], bdAddr[4], bdAddr[3], bdAddr[2], bdAddr[1], bdAddr[0]);
LlSetBdAddr((uint8_t*)&bdAddr);
LlGetBdAddr(hciCoreCb.bdAddr);
break;
default:
break;
case APP_UI_RESET_CMPL:
printf("Setting address -- MAC %02X:%02X:%02X:%02X:%02X:%02X\n", bdAddr[5], bdAddr[4], bdAddr[3], bdAddr[2], bdAddr[1], bdAddr[0]);
HciVsSetBdAddr(bdAddr);
break;
default:
break;
}
}
/*************************************************************************************************/
/*!
* \brief Initialize MAC layer.
*
* \param None.
*
* \return None.
*/
void HandleButton(int button)
{
mxc_tmr_regs_t* button_tmr = MXC_TMR_GET_TMR(button);
// Check if rising or falling
if(PB_Get(button)) {
// Start timer
TMR_Enable(button_tmr);
} else {
uint32_t time;
tmr_unit_t unit;
// Get the elapsed time since the button was pressed
TMR_GetTime(button_tmr, TMR_GetCount(button_tmr), &time, &unit);
TMR_Disable(button_tmr);
TMR_SetCount(button_tmr, 0);
if(unit == TMR_UNIT_NANOSEC) {
time /= 1000000;
} else if(unit == TMR_UNIT_MICROSEC) {
time /= 1000;
}
if(time < BUTTON_SHORT_MS) {
AppUiBtnTest(button ? APP_UI_BTN_2_SHORT : APP_UI_BTN_1_SHORT);
} else if (time < BUTTON_MED_MS) {
AppUiBtnTest(button ? APP_UI_BTN_2_MED : APP_UI_BTN_1_MED);
} else if (time < BUTTON_LONG_MS) {
AppUiBtnTest(button ? APP_UI_BTN_2_LONG : APP_UI_BTN_1_LONG);
} else {
AppUiBtnTest(button ? APP_UI_BTN_2_EX_LONG : APP_UI_BTN_1_EX_LONG);
}
}
}
/*************************************************************************************************/
void Button0Pressed(void* arg)
{
HandleButton(0);
}
/*************************************************************************************************/
void MacInit(void)
void Button1Pressed(void* arg)
{
wsfHandlerId_t handlerId;
/* Initialize link layer. */
BbInit();
handlerId = WsfOsSetNextHandler(SchHandler);
SchInit(handlerId);
LlAdvSlaveInit();
LlConnSlaveInit();
handlerId = WsfOsSetNextHandler(LlHandler);
LlHandlerInit(handlerId);
HandleButton(1);
}
/*************************************************************************************************/
......@@ -218,17 +232,34 @@ void MacInit(void)
/*************************************************************************************************/
int main(void)
{
#ifndef __IAR_SYSTEMS_ICC__
setvbuf(stdout, printf_buffer, _IOLBF, PRINTF_BUF_SIZE);
#endif
printf("\n\n***** MAX32665 BLE Fitness Profile *****\n");
PlatformInit();
/* Initialize Radio */
WsfInit();
MacInit();
StackInitFit();
FitStart();
/* Setup pushbuttons and timers */
PB_RegisterRiseFallCallback(0, Button0Pressed);
PB_RegisterRiseFallCallback(1, Button1Pressed);
PB_IntEnable(0);
TMR_Init(BUTTON0_TMR, TMR_PRES_16, NULL);
TMR_Init(BUTTON1_TMR, TMR_PRES_16, NULL);
tmr_cfg_t button_config;
button_config.mode = TMR_MODE_CONTINUOUS;
TMR_Config(BUTTON0_TMR, &button_config);
TMR_Config(BUTTON1_TMR, &button_config);
/* Register a handler for Application events */
AppUiActionRegister(SetAddress);
printf("Setup Complete\n");
while (1)
......@@ -236,3 +267,12 @@ int main(void)
wsfOsDispatcher();
}
}
/*****************************************************************/
void HardFault_Handler(void)
{
printf("\nFaultISR: CFSR %08X, BFAR %08x\n", (unsigned int)SCB->CFSR, (unsigned int)SCB->BFAR);
// Loop forever
while(1);
}
......@@ -17,6 +17,8 @@
*/
/*************************************************************************************************/
#include <stdio.h>
#include <string.h>
#include "wsf_types.h"
#include "wsf_os.h"
#include "util/bstream.h"
......@@ -33,6 +35,56 @@
#include "svc_dis.h"
#include "svc_core.h"
#include "sec_api.h"
#include "ll_init_api.h"
#define LL_IMPL_REV 0x2303
#define LL_MEMORY_FOOTPRINT 0xC152
uint8_t LlMem[LL_MEMORY_FOOTPRINT];
const LlRtCfg_t _ll_cfg = {
/* Device */
/*compId*/ LL_COMP_ID_ARM,
/*implRev*/ LL_IMPL_REV,
/*btVer*/ LL_VER_BT_CORE_SPEC_5_0,
/*_align32 */ 0, // padding for alignment
/* Advertiser */
/*maxAdvSets*/ 4, // 4 Extended Advertising Sets
/*maxAdvReports*/ 8,
/*maxExtAdvDataLen*/ LL_MAX_ADV_DATA_LEN,
/*defExtAdvDataFrag*/ 64,
/*auxDelayUsec*/ 0,
/* Scanner */
/*maxScanReqRcvdEvt*/ 4,
/*maxExtScanDataLen*/ LL_MAX_ADV_DATA_LEN,
/* Connection */
/*maxConn*/ 2,
/*numTxBufs*/ 16,
/*numRxBufs*/ 16,
/*maxAclLen*/ 512,
/*defTxPwrLvl*/ 0,
/*ceJitterUsec*/ 0,
/* DTM */
/*dtmRxSyncMs*/ 10000,
/* PHY */
/*phy2mSup*/ TRUE,
/*phyCodedSup*/ TRUE,
/*stableModIdxTxSup*/ FALSE,
/*stableModIdxRxSup*/ FALSE
};
const BbRtCfg_t _bb_cfg = {
/*clkPpm*/ 20,
/*rfSetupDelayUsec*/ BB_RF_SETUP_DELAY_US,
/*maxScanPeriodMsec*/ BB_MAX_SCAN_PERIOD_MS,
/*schSetupDelayUsec*/ BB_SCH_SETUP_DELAY_US
};
/*************************************************************************************************/
/*!
......@@ -44,22 +96,42 @@
void StackInitFit(void)
{
wsfHandlerId_t handlerId;
uint8_t features[sizeof(uint64_t)];
uint8_t mask[sizeof(uint64_t)];
SecInit();
SecAesInit();
SecCmacInit();
SecEccInit();
#ifndef ENABLE_SDMA
uint32_t memUsed;
/* Initialize link layer. */
LlInitRtCfg_t ll_init_cfg =
{
.pBbRtCfg = &_bb_cfg,
.wlSizeCfg = 4,
.rlSizeCfg = 4,
.plSizeCfg = 4,
.pLlRtCfg = &_ll_cfg,
.pFreeMem = LlMem,
.freeMemAvail = LL_MEMORY_FOOTPRINT
};
// Only use legacy API.
Uint64ToBstream(features, 0);
Uint64ToBstream(mask, HCI_LE_SUP_FEAT_LE_EXT_ADV);
HciVsSetFeatures(features, mask);
#ifdef DATS_APP_USE_LEGACY_API
memUsed = LlInitControllerExtInit(&ll_init_cfg);
#else /* DATS_APP_USE_LEGACY_API */
memUsed = LlInitControllerExtInit(&ll_init_cfg);
#endif /* DATS_APP_USE_LEGACY_API */
if(memUsed != LL_MEMORY_FOOTPRINT)
{
printf("Controller memory mismatch 0x%x != 0x%x\n", memUsed,
LL_MEMORY_FOOTPRINT);
}
#endif
handlerId = WsfOsSetNextHandler(HciHandler);
HciHandlerInit(handlerId);
SecInit();
SecAesInit();
SecCmacInit();
SecEccInit();
handlerId = WsfOsSetNextHandler(DmHandler);
DmDevVsInit(0);
DmAdvInit();
......@@ -68,6 +140,7 @@ void StackInitFit(void)
DmSecInit();
DmSecLescInit();
DmPrivInit();
DmPhyInit();
DmHandlerInit(handlerId);
handlerId = WsfOsSetNextHandler(L2cSlaveHandler);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment