Skip to content
Snippets Groups Projects
Commit 938f4a88 authored by schneider's avatar schneider
Browse files

fix(max32666): Update SDK to 0.2.1-7

parent b6832e3f
No related branches found
No related tags found
No related merge requests found
Showing
with 2401 additions and 301 deletions
build/
/build/
/Documentation/output/
__pycache__/
*.pyc
......
......@@ -29,14 +29,15 @@
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2019-07-12 10:56:57 -0500 (Fri, 12 Jul 2019) $
* $Revision: 44598 $
* $Date: 2019-08-22 20:18:08 -0500 (Thu, 22 Aug 2019) $
* $Revision: 45615 $
*
******************************************************************************/
#include <stdio.h>
#include <string.h>
#include "mxc_config.h"
#include "mxc_sys.h"
#include "wsf_types.h"
#include "wsf_os.h"
#include "wsf_buf.h"
......@@ -47,6 +48,7 @@
#include "app_ui.h"
#include "hci_vs.h"
#include "hci_core.h"
#include "dm_api.h"
/**************************************************************************************************
Macros
......@@ -150,12 +152,40 @@ static void WsfInit(void)
*/
void SetAddress(uint8_t event)
{
uint8_t bdAddr[6] = {0x02, 0x00, 0x44, 0x8B, 0x05, 0x00};
uint8_t usn[SYS_USN_CHECKSUM_LEN];
uint8_t checksum[SYS_USN_CHECKSUM_LEN];
uint8_t bdAddr[6];
uint8_t bdAddrRand[6];
if(SYS_GetUSN(usn, checksum) != E_NO_ERROR) {
printf("Error getting Checksum\n");
}
// MA-L assigend by IEEE to Maxim Integrated Products
bdAddr[5] = 0x00;
bdAddr[4] = 0x18;
bdAddr[3] = 0x80;
// USN checksum
bdAddr[2] = checksum[2];
bdAddr[1] = checksum[1];
bdAddr[0] = checksum[0];
bdAddrRand[0] = checksum[3];
bdAddrRand[1] = checksum[4];
bdAddrRand[2] = checksum[5];
bdAddrRand[3] = checksum[6];
bdAddrRand[4] = checksum[7];
bdAddrRand[5] = checksum[8];
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]);
HciVsSetBdAddr(bdAddr);
DM_RAND_ADDR_SET(bdAddrRand, DM_RAND_ADDR_STATIC);
DmDevSetRandAddr(bdAddrRand);
DmAdvSetAddrType(DM_ADDR_RANDOM);
printf("Setting random address -- MAC %02X:%02X:%02X:%02X:%02X:%02X\n",
bdAddrRand[5], bdAddrRand[4], bdAddrRand[3], bdAddrRand[2], bdAddrRand[1], bdAddrRand[0]);
break;
default:
break;
......
......@@ -20,6 +20,7 @@
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "mxc_device.h"
#include "wsf_types.h"
#include "util/bstream.h"
#include "wsf_msg.h"
......@@ -41,6 +42,7 @@
#include "wpc/wpc_api.h"
#include "datc/datc_api.h"
#include "util/calc128.h"
#include "gcr_regs.h"
/**************************************************************************************************
Macros
......@@ -983,7 +985,13 @@ static void datcSetup(dmEvt_t *pMsg)
DmDevSetFilterPolicy(DM_FILT_POLICY_MODE_INIT, HCI_FILT_WHITE_LIST);
#endif /* BTLE_APP_USE_WHITELIST */
/* Enable coded PHY */
if(MXC_GCR->revision != 0xA1) {
DmSetDefaultPhy(0, HCI_PHY_LE_1M_BIT | HCI_PHY_LE_2M_BIT | HCI_PHY_LE_CODED_BIT,
HCI_PHY_LE_1M_BIT | HCI_PHY_LE_2M_BIT | HCI_PHY_LE_CODED_BIT);
} else {
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);
......@@ -1153,12 +1161,21 @@ static void testTimerHandler(void)
(testCb.connId != DM_CONN_ID_NONE) &&
(datcCb.discState[testCb.connId-1] == DATC_DISC_SVC_MAX))
{
if(testCb.phy == HCI_PHY_LE_1M_BIT) {
if(testCb.phy == HCI_PHY_LE_2M_BIT) {
/* Change from 1M to 2M PHY */
testCb.phy = HCI_PHY_LE_1M_BIT;
} else if (testCb.phy == HCI_PHY_LE_1M_BIT) {
/* Change to the coded PHY if we're not using A1 */
if(MXC_GCR->revision != 0xA1) {
testCb.phy = HCI_PHY_LE_CODED_BIT;
} else {
testCb.phy = HCI_PHY_LE_2M_BIT;
}
} else {
/* Change from Coded to 1M PHY */
testCb.phy = HCI_PHY_LE_1M_BIT;
/* Change to 2M PHY */
testCb.phy = HCI_PHY_LE_2M_BIT;
}
DmSetPhy(testCb.connId, 0, testCb.phy, testCb.phy, 0);
......
......@@ -19,6 +19,7 @@
#include <stdio.h>
#include <string.h>
#include "mxc_device.h"
#include "wsf_types.h"
#include "wsf_os.h"
#include "util/bstream.h"
......@@ -36,7 +37,7 @@
#include "svc_core.h"
#include "sec_api.h"
#include "ll_init_api.h"
#include "gcr_regs.h"
#define LL_IMPL_REV 0x2303
......@@ -44,7 +45,7 @@
uint8_t LlMem[LL_MEMORY_FOOTPRINT];
const LlRtCfg_t _ll_cfg = {
LlRtCfg_t _ll_cfg = {
/* Device */
/*compId*/ LL_COMP_ID_ARM,
/*implRev*/ LL_IMPL_REV,
......@@ -102,6 +103,11 @@ void StackInitDatc(void)
#ifndef ENABLE_SDMA
uint32_t memUsed;
/* Enable coded PHY */
if(MXC_GCR->revision != 0xA1) {
_ll_cfg.phyCodedSup = TRUE;
}
/* Initialize link layer. */
LlInitRtCfg_t ll_init_cfg =
{
......
......@@ -19,6 +19,7 @@
#include <stdio.h>
#include <string.h>
#include "mxc_device.h"
#include "wsf_types.h"
#include "util/bstream.h"
#include "wsf_msg.h"
......@@ -40,6 +41,7 @@
#include "svc_wp.h"
#include "util/calc128.h"
#include "dats/dats_api.h"
#include "gcr_regs.h"
/**************************************************************************************************
Macros
......@@ -505,7 +507,13 @@ static void datsSetup(dmEvt_t *pMsg)
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 */
/* Enable coded PHY */
if(MXC_GCR->revision != 0xA1) {
DmSetDefaultPhy(0, HCI_PHY_LE_1M_BIT | HCI_PHY_LE_2M_BIT | HCI_PHY_LE_CODED_BIT,
HCI_PHY_LE_1M_BIT | HCI_PHY_LE_2M_BIT | HCI_PHY_LE_CODED_BIT);
} else {
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
......
......@@ -19,6 +19,7 @@
#include <stdio.h>
#include <string.h>
#include "mxc_device.h"
#include "wsf_types.h"
#include "wsf_os.h"
#include "util/bstream.h"
......@@ -37,6 +38,7 @@
#include "svc_core.h"
#include "sec_api.h"
#include "ll_init_api.h"
#include "gcr_regs.h"
#define LL_IMPL_REV 0x2303
......@@ -44,7 +46,7 @@
uint8_t LlMem[LL_MEMORY_FOOTPRINT];
const LlRtCfg_t _ll_cfg = {
LlRtCfg_t _ll_cfg = {
/* Device */
/*compId*/ LL_COMP_ID_ARM,
/*implRev*/ LL_IMPL_REV,
......@@ -102,6 +104,11 @@ void StackInitDats(void)
#ifndef ENABLE_SDMA
uint32_t memUsed;
/* Enable coded PHY */
if(MXC_GCR->revision != 0xA1) {
_ll_cfg.phyCodedSup = TRUE;
}
/* Initialize link layer. */
LlInitRtCfg_t ll_init_cfg =
{
......
......@@ -29,7 +29,7 @@
# property whatsoever. Maxim Integrated Products, Inc. retains all
# ownership rights.
#
# $Id: Makefile 45395 2019-08-13 21:04:28Z kevin.gillespie $
# $Id: Makefile 48012 2019-10-23 18:41:06Z kevin.gillespie $
#
################################################################################
......@@ -65,15 +65,20 @@ ifneq "$(BLE_ADDR_LSB)" ""
PROJ_CFLAGS+=-DBLE_ADDR_LSB=$(BLE_ADDR_LSB)
endif
## Subsitute WSF critical section entry for default MAXUSB
# Suppress compiler warnings on undefined names (define as zeros)
PROJ_CFLAGS+=-DIAR_PRAGMAS=0
# Subsitute WSF critical section entry for default MAXUSB
#PROJ_CFLAGS+=-DMAXUSB_ENTER_CRITICAL=WsfCsEnter
#PROJ_CFLAGS+=-DMAXUSB_EXIT_CRITICAL=WsfCsExit
# 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
......@@ -150,7 +155,7 @@ PROJ_CFLAGS+=-DINIT_BROADCASTER
PROJ_CFLAGS+=-DINIT_PERIPHERAL
PROJ_CFLAGS+=-DINIT_ENCRYPTED
ENABLE_LL_TESTER?=#1
# ENABLE_LL_TESTER?=#1
# Use this variable to override default compilier optimization.
#MXC_OPTIMIZE_CFLAGS=-Os
......@@ -174,10 +179,6 @@ include ${PERIPH_DRIVER_DIR}/periphdriver.mk
CORDIO_DIR=$(LIBS_DIR)/BTLE
include ${CORDIO_DIR}/btle.mk
# Include MAXUSB library
MAXUSB_DIR=$(LIBS_DIR)/MAXUSB
include $(MAXUSB_DIR)/maxusb.mk
################################################################################
# Include the rules for building for this target. All other makefiles should be
# included before this one.
......
......@@ -84,7 +84,7 @@ typedef union
static const appAdvCfg_t fitAdvCfg =
{
{ 1000, 0, 0}, /*! Advertising durations in ms */
{ 96, 200, 0} /*! Advertising intervals in 0.625 ms units */
{ 200, 200, 0} /*! Advertising intervals in 0.625 ms units */
};
/*! configurable parameters for slave */
......
......@@ -29,8 +29,8 @@
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2019-07-11 16:47:07 -0500 (Thu, 11 Jul 2019) $
* $Revision: 44577 $
* $Date: 2019-10-09 11:56:30 -0500 (Wed, 09 Oct 2019) $
* $Revision: 47576 $
*
******************************************************************************/
......@@ -50,6 +50,7 @@
#include "pb.h"
#include "tmr.h"
/**************************************************************************************************
Macros
**************************************************************************************************/
......@@ -233,6 +234,7 @@ void Button1Pressed(void* arg)
int main(void)
{
#ifndef __IAR_SYSTEMS_ICC__
setvbuf(stdout, printf_buffer, _IOLBF, PRINTF_BUF_SIZE);
#endif
......
......@@ -37,6 +37,11 @@
#include "sec_api.h"
#include "ll_init_api.h"
#ifdef _RTE_
#include "RTE_Components.h" // Component selection
#endif
#define LL_IMPL_REV 0x2303
#define LL_MEMORY_FOOTPRINT 0xC152
......@@ -98,6 +103,7 @@ void StackInitFit(void)
{
wsfHandlerId_t handlerId;
#ifndef ENABLE_SDMA
uint32_t memUsed;
......@@ -125,6 +131,7 @@ void StackInitFit(void)
}
#endif
handlerId = WsfOsSetNextHandler(HciHandler);
HciHandlerInit(handlerId);
......
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>BLE_fit_ds</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
</projectDescription>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project>
<configuration id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.1674944962" name="Debug">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings Cross ARM" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
</extension>
</configuration>
</project>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="ilg.gnuarmeclipse.debug.gdbjtag.openocd.launchConfigurationType">
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.doContinue" value="true"/>
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.doDebugInRam" value="false"/>
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.doFirstReset" value="true"/>
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.doGdbServerAllocateConsole" value="true"/>
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.doGdbServerAllocateTelnetConsole" value="false"/>
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.doSecondReset" value="true"/>
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.doStartGdbServer" value="true"/>
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.enableSemihosting" value="false"/>
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.firstResetType" value="init"/>
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.gdbClientOtherCommands" value=""/>
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.gdbClientOtherOptions" value=""/>
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.gdbServerConnectionAddress" value=""/>
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.gdbServerExecutable" value="openocd"/>
<intAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.gdbServerGdbPortNumber" value="3333"/>
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.gdbServerLog" value=""/>
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.gdbServerOther" value="-s ${env_var:TOOLCHAIN_PATH}/share/openocd/scripts -f interface/cmsis-dap.cfg -f target/max32665.cfg -c 'reset_config srst_only connect_assert_srst srst_nogate; init; reset; reset_config none; reset; halt'"/>
<intAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.gdbServerTelnetPortNumber" value="4444"/>
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.otherInitCommands" value=""/>
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.otherRunCommands" value=""/>
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.secondResetType" value="halt"/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.imageFileName" value=""/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.imageOffset" value=""/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.ipAddress" value="localhost"/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.jtagDevice" value="GNU ARM OpenOCD"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.loadImage" value="true"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.loadSymbols" value="true"/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.pcRegister" value=""/>
<intAttribute key="org.eclipse.cdt.debug.gdbjtag.core.portNumber" value="3333"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setPcRegister" value="false"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setResume" value="false"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setStopAt" value="true"/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.stopAt" value="main"/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.symbolsFileName" value=""/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.symbolsOffset" value=""/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useFileForImage" value="false"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useFileForSymbols" value="false"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useProjBinaryForImage" value="true"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useProjBinaryForSymbols" value="true"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useRemoteTarget" value="true"/>
<stringAttribute key="org.eclipse.cdt.dsf.gdb.DEBUG_NAME" value="arm-none-eabi-gdb"/>
<booleanAttribute key="org.eclipse.cdt.dsf.gdb.UPDATE_THREADLIST_ON_SUSPEND" value="false"/>
<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="2"/>
<stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/>
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_REGISTER_GROUPS" value=""/>
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="build/max32665.elf"/>
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="BLE_fit_ds"/>
<booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="true"/>
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.1674944962"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/BLE_fit_ds"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
</listAttribute>
<stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;memoryBlockExpressionList context=&quot;Context string&quot;&gt;&#13;&#10;&lt;memoryBlockExpression address=&quot;536918388&quot; label=&quot;0x2000b974&quot;/&gt;&#13;&#10;&lt;/memoryBlockExpressionList&gt;&#13;&#10;"/>
<stringAttribute key="process_factory_id" value="org.eclipse.cdt.dsf.gdb.GdbProcessFactory"/>
</launchConfiguration>
################################################################################
# Copyright (C) 2014 Maxim Integrated Products, Inc., All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
# OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
# Except as contained in this notice, the name of Maxim Integrated
# Products, Inc. shall not be used except as stated in the Maxim Integrated
# Products, Inc. Branding Policy.
#
# The mere transfer of this software does not imply any licenses
# of trade secrets, proprietary technology, copyrights, patents,
# trademarks, maskwork rights, or any other form of intellectual
# property whatsoever. Maxim Integrated Products, Inc. retains all
# ownership rights.
#
# $Id: Makefile 48023 2019-10-23 19:56:38Z 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
endif
# Specify the target processor
ifeq "$(TARGET)" ""
TARGET=MAX32665
endif
# Select 'GCC' or 'IAR' compiler
COMPILER=GCC
# Specify the board used
ifeq "$(BOARD)" ""
BOARD=EvKit_V1
endif
# Create Target name variables
TARGET_UC:=$(shell echo $(TARGET) | tr a-z A-Z)
TARGET_LC:=$(shell echo $(TARGET) | tr A-Z a-z)
# Last octet address modifier
ifneq "$(BLE_ADDR_LSB)" ""
PROJ_CFLAGS+=-DBLE_ADDR_LSB=$(BLE_ADDR_LSB)
endif
# Suppress compiler warnings on undefined names (define as zeros)
PROJ_CFLAGS+=-DIAR_PRAGMAS=0
# Subsitute WSF critical section entry for default MAXUSB
#PROJ_CFLAGS+=-DMAXUSB_ENTER_CRITICAL=WsfCsEnter
#PROJ_CFLAGS+=-DMAXUSB_EXIT_CRITICAL=WsfCsExit
# 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
# Source files for this test (add path to VPATH below)
SRCS = main.c
SRCS += stack_fit.c
SRCS += fit_main.c
SRCS += wakeup.c
# Where to find source files for this test
VPATH = .
# Where to find header files for this test
IPATH = .
##############################################################################
# OS Check/Utility definitions
ifeq '$(findstring ;,$(PATH))' ';'
BUILD_OS := Windows
else
BUILD_OS := $(shell uname 2>/dev/null || echo Unknown)
BUILD_OS := $(patsubst MSYS%,MSYS,$(BUILD_OS))
BUILD_OS := $(patsubst MINGW%,MSYS,$(BUILD_OS))
endif
################################################################################
# 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"
ENABLE_SDMA=
else
ifeq "$(ENABLE_SDMA)" "FALSE"
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=TRUE
PROJ_CFLAGS+=-DWSF_ASSERT_ENABLED=TRUE
# PROJ_CFLAGS+=-DWSF_TRACE_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
# Include the BSP
BOARD_DIR=$(LIBS_DIR)/Boards/$(BOARD)
include $(BOARD_DIR)/board.mk
# Include the Peripheral Driver Library
PERIPH_DRIVER_DIR=$(LIBS_DIR)/$(TARGET)PeriphDriver
include ${PERIPH_DRIVER_DIR}/periphdriver.mk
# Include Cordio BTLE Library
CORDIO_DIR=$(LIBS_DIR)/BTLE
include ${CORDIO_DIR}/btle.mk
################################################################################
# Include the rules for building for this target. All other makefiles should be
# included before this one.
include $(CMSIS_ROOT)/Device/Maxim/$(TARGET_UC)/Source/$(COMPILER)/$(TARGET_LC).mk
# Run link layer using SDMA.
ENABLE_SDMA?=0
This diff is collapsed.
/*******************************************************************************
* Copyright (C) 2018 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2019-10-30 09:44:34 -0500 (Wed, 30 Oct 2019) $
* $Revision: 48248 $
*
******************************************************************************/
#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 "fit/fit_api.h"
#include "app_ui.h"
#include "hci_vs.h"
#include "hci_core.h"
#include "pb.h"
#include "tmr.h"
#include "wakeup.h"
#include "uart.h"
#include "sch_api.h"
#include "wut.h"
#include "board.h"
#include "sch_api_ble.h"
#include "lp.h"
#include "bb_drv.h"
/**************************************************************************************************
Macros
**************************************************************************************************/
/* 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
/* 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];
/*! Default pool descriptor. */
static wsfBufPoolDesc_t mainPoolDesc[WSF_BUF_POOLS] = {
{ 16, 8 },
{ 32, 4 },
{ 64, 4 },
{ 128, 4 },
{ 256, 4 },
{ 512, 4 }
};
/**************************************************************************************************
Functions
**************************************************************************************************/
/*! \brief Stack initialization for app. */
extern void StackInitFit(void);
/*************************************************************************************************/
void PalSysAssertTrap(void)
{
while(1) {}
}
/*************************************************************************************************/
void SysTick_Handler(void)
{
WsfTimerUpdate(1);
}
/*************************************************************************************************/
static bool_t myTrace(const uint8_t *pBuf, uint32_t len)
{
extern uint8_t wsfCsNesting;
if (wsfCsNesting == 0) {
fwrite(pBuf, len, 1, stdout);
return TRUE;
}
return FALSE;
}
/*************************************************************************************************/
/*!
* \brief Initialize WSF.
*
* \return None.
*/
/*************************************************************************************************/
static void WsfInit(void)
{
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);
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.
* This handler can also catch other Application events, but none are currently implemented.
* See ble-profiles/sources/apps/app/common/app_ui.c for further details.
*
*/
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]);
HciVsSetBdAddr(bdAddr);
break;
default:
break;
}
}
/*************************************************************************************************/
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 Button1Pressed(void* arg)
{
HandleButton(1);
}
/*************************************************************************************************/
void Sleep(void)
{
WsfTaskLock();
/* WSF and UART are not busy ? */
if (wsfOsReadyToSleep() && UART_PrepForSleep(MXC_UART_GET_UART(CONSOLE_UART)) == E_NO_ERROR) {
/* get next due time and sleep time */
uint32_t nextDbbEventDue;
bool_t dueValid = SchBleGetNextDueTime(&nextDbbEventDue);
int sleep_ticks = nextDbbEventDue - BbDrvGetCurrentTime();
/* timing valid ? */
if(dueValid && (sleep_ticks > 0 )) {
/* need extra time to restore voltages */
uint32_t powerup_ticks = GetWakeDelay(sleep_ticks);
/* have enough time to deep sleep ? */
if(sleep_ticks > US_TO_BBTICKS(DS_WAKEUP_TIME_US + MIN_DEEPSLEEP_US) + powerup_ticks) {
/* Stop SysTick */
SysTick->CTRL = 0;
/* save DBB, WUT clocks, arm WUT for wakeup */
WUT_SetWakeup(sleep_ticks - powerup_ticks - US_TO_BBTICKS(DS_WAKEUP_TIME_US));
/* unschedule next BLE operation */
SchSleep();
/* power off unused hardware */
DisableUnused();
/* enterDeepSleep mode */
WsfTaskUnlock();
EnterDeepsleep();
/* initial restore */
ExitDeepsleep();
WsfTaskLock();
/* Restore BLE hardware state */
BbDrvInitWake();
/* Restore BB clock */
WUT_RestoreBBClock(BB_CLK_RATE_HZ);
WsfTimerUpdate((WUT_GetSleepTicks() * 1000) / SYS_WUT_GetFreq() / WSF_MS_PER_TICK );
/* Re-schedule next BLE operation */
SchWake();
/* have enough time to sleep ?*/
} else if (sleep_ticks > US_TO_BBTICKS(MIN_SLEEP_US)) {
WUT_SetInt(sleep_ticks - US_TO_BBTICKS(WAKEUP_TIME_US));
LP_EnterSleepMode();
}
/* Nothing scheduled, wait for interrupt */
} else {
LP_EnterSleepMode();
}
} /* if(not busy) */
WsfTaskUnlock();
}
/*************************************************************************************************/
/*!
* \fn main
*
* \brief Entry point for demo software.
*
* \param None.
*
* \return None.
*/
/*************************************************************************************************/
int main(void)
{
/* Restoring VREGOD when reset out of deep sleep */
MXC_PWRSEQ->lpvddpd &= ~MXC_F_PWRSEQ_LPVDDPD_VREGODPD;
printf("\n\n***** MAX32665 BLE Fitness Profile, Deep Sleep *****\n");
/* Initialize Wakeup timer */
WUT_Init(WUT_PRES_1);
wut_cfg_t wut_cfg;
wut_cfg.mode = WUT_MODE_COMPARE;
wut_cfg.cmp_cnt = 0xFFFFFFFF;
WUT_Config(&wut_cfg);
WUT_Enable();
/* Enable WUT as a wakup source */
MXC_GCR->pm |= MXC_F_GCR_PM_WUTWKEN;
NVIC_EnableIRQ(WUT_IRQn);
/* Delay before continuing with deep sleep code */
WUT_Delay_MS(3000);
/* Initialize Radio */
WsfInit();
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) {
wsfOsDispatcher();
Sleep();
}
}
/*****************************************************************/
void HardFault_Handler(void)
{
printf("\nFaultISR: CFSR %08X, BFAR %08x\n", (unsigned int)SCB->CFSR, (unsigned int)SCB->BFAR);
// Loop forever
while(1);
}
/*************************************************************************************************/
/*!
* \file
*
* \brief Stack initialization for fit.
*
* Copyright (c) 2016-2017 ARM Ltd. All Rights Reserved.
* ARM Ltd. confidential and proprietary.
*
* IMPORTANT. Your use of this file is governed by a Software License Agreement
* ("Agreement") that must be accepted in order to download or otherwise receive a
* copy of this file. You may not use or copy this file for any purpose other than
* as described in the Agreement. If you do not agree to all of the terms of the
* Agreement do not use this file and delete all copies in your possession or control;
* if you do not have a copy of the Agreement, you must contact ARM Ltd. prior
* to any use, copying or further distribution of this software.
*/
/*************************************************************************************************/
#include <stdio.h>
#include <string.h>
#include "wsf_types.h"
#include "wsf_os.h"
#include "util/bstream.h"
#include "fit/fit_api.h"
#include "hci_handler.h"
#include "dm_handler.h"
#include "l2c_handler.h"
#include "att_handler.h"
#include "smp_handler.h"
#include "l2c_api.h"
#include "att_api.h"
#include "smp_api.h"
#include "app_api.h"
#include "svc_dis.h"
#include "svc_core.h"
#include "sec_api.h"
#include "ll_init_api.h"
#ifdef _RTE_
#include "RTE_Components.h" // Component selection
#endif
#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,
/*defaultTxPower*/ -10,
/*maxScanPeriodMsec*/ BB_MAX_SCAN_PERIOD_MS,
/*schSetupDelayUsec*/ BB_SCH_SETUP_DELAY_US
};
/*************************************************************************************************/
/*!
* \brief Initialize stack.
*
* \return None.
*/
/*************************************************************************************************/
void StackInitFit(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
};
#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();
DmConnInit();
DmConnSlaveInit();
DmSecInit();
DmSecLescInit();
DmPrivInit();
DmPhyInit();
DmHandlerInit(handlerId);
handlerId = WsfOsSetNextHandler(L2cSlaveHandler);
L2cSlaveHandlerInit(handlerId);
L2cInit();
L2cSlaveInit();
handlerId = WsfOsSetNextHandler(AttHandler);
AttHandlerInit(handlerId);
AttsInit();
AttsIndInit();
handlerId = WsfOsSetNextHandler(SmpHandler);
SmpHandlerInit(handlerId);
SmprInit();
SmprScInit();
HciSetMaxRxAclLen(100);
handlerId = WsfOsSetNextHandler(AppHandler);
AppHandlerInit(handlerId);
handlerId = WsfOsSetNextHandler(FitHandler);
FitHandlerInit(handlerId);
}
/*******************************************************************************
* Copyright (C) 2018 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2019-10-25 14:21:06 -0500 (Fri, 25 Oct 2019) $
* $Revision: 48094 $
*
******************************************************************************/
#include "lp.h"
#include "icc.h"
#include "simo.h"
#include "board.h"
#include "wut_regs.h"
#include "wsf_types.h"
#include "wsf_timer.h"
#include "usbhs_regs.h"
#include "gcr_regs.h"
#include "mcr_regs.h"
#include "tmr_regs.h"
#include "wut.h"
#include "mxc_sys.h"
#include "bb_drv.h"
#include "wakeup.h"
uint32_t wut_count;
uint32_t wut_snapshot;
uint32_t vrego_d_setting;
uint32_t btleldocn_setting;
#define WAKEUP_32M_US 1105
#define MXC_R_SIR_SHR13 *((uint32_t*)(0x40000434))
#define MXC_R_SIR_SHR17 *((uint32_t*)(0x40000444))
/*************************************************/
void WUT_IRQHandler(void)
{
WUT_IntClear();
NVIC_ClearPendingIRQ(WUT_IRQn);
}
/*************************************************/
/* Arm WUT for wakeup from Sleep */
void WUT_SetInt(uint32_t sleep_time)
{
/* arm WUT for wakeup */
MXC_WUT->cmp = MXC_WUT->cnt + ((uint64_t)(sleep_time) * SYS_WUT_GetFreq() / BB_CLK_RATE_HZ);
}
/*************************************************/
/* Arm WUT for wakeup from Sleep, save BB clock */
void WUT_SetWakeup(uint32_t sleep_time)
{
/* save clocks */
WUT_Edge();
WUT_Store();
/* arm WUT for wakeup */
WUT_SetInt(sleep_time);
}
/*************************************************/
/* This will calculate extra delay needed to power up
after WAIT_TICKS long Sleep
Input and output are in DBB_TICK units (0.625us per tick)
This timing depends on how fast VT/RXIN voltage decay/restore,
i.e. must be characterized per board design
For now use data points for EvKit_V1 board:
1) Sleep time ~125ms -> power up delay ~0.5ms
2) Sleep time ~500ms -> power up delay ~1.5ms
3) Sleep time ~2 sec -> power up delay ~3.5ms
4) Sleep time ~8 sec -> power up delay ~5.5ms
Adding time to power 32 MHz crystal
*/
uint32_t GetWakeDelay(uint32_t wait_ticks)
{
uint32_t ret;
if( wait_ticks < US_TO_BBTICKS(125000))
ret = US_TO_BBTICKS(500);
else if( wait_ticks < US_TO_BBTICKS(500000))
ret = US_TO_BBTICKS(1500);
else if( wait_ticks < US_TO_BBTICKS(2000000))
ret = US_TO_BBTICKS(3500);
else
ret = US_TO_BBTICKS(5500);
ret += US_TO_BBTICKS(WAKEUP_32M_US);
return ret;
}
/*************************************************/
/* This will switch system clock to HIRC 60MHz source */
static void switchToHIRC(void)
{
MXC_GCR->clkcn &= ~(MXC_S_GCR_CLKCN_PSC_DIV128);
MXC_GCR->clkcn |= MXC_S_GCR_CLKCN_PSC_DIV4;
MXC_GCR->clkcn |= MXC_F_GCR_CLKCN_HIRC_EN;
MXC_SETFIELD(MXC_GCR->clkcn, MXC_F_GCR_CLKCN_CLKSEL, MXC_S_GCR_CLKCN_CLKSEL_HIRC);
// Disable unused clocks
while(!(MXC_GCR->clkcn & MXC_F_GCR_CLKCN_CKRDY)); // Wait for the switch to occur
MXC_GCR->clkcn &= ~(MXC_F_GCR_CLKCN_HIRC96M_EN);
SystemCoreClockUpdate();
}
/*************************************************/
/* This will switch system clock to 96MHz source */
static void switchToHIRC96M(void)
{
MXC_GCR->clkcn &= ~(MXC_S_GCR_CLKCN_PSC_DIV128);
MXC_GCR->clkcn |= MXC_S_GCR_CLKCN_PSC_DIV1;
MXC_GCR->clkcn |= MXC_F_GCR_CLKCN_HIRC96M_EN;
MXC_SETFIELD(MXC_GCR->clkcn, MXC_F_GCR_CLKCN_CLKSEL, MXC_S_GCR_CLKCN_CLKSEL_HIRC96);
while(!(MXC_GCR->clkcn & MXC_F_GCR_CLKCN_CKRDY)); // Wait for the switch to occur
// Disable unused clocks
MXC_GCR->clkcn &= ~(MXC_F_GCR_CLKCN_HIRC_EN);
SystemCoreClockUpdate();
}
/*************************************************/
/* This will power off unused hardware */
void DisableUnused(void)
{
// Allow the USB Switch to be turned off in deepsleep and backup modes
LP_USBSWLPDisable();
// Shut down all unneeded power gates
LP_ICacheXIPShutdown();
LP_CryptoShutdown();
LP_SysCacheShutdown();
LP_USBFIFOShutdown();
LP_ROMShutdown();
LP_ROM1Shutdown();
LP_ICache1Shutdown();
}
/*************************************************/
/* This will enter DeepSleep Mode */
void EnterDeepsleep(void)
{
MXC_GCR->pm &= ~ ( MXC_F_GCR_PM_GPIOWKEN
| MXC_F_GCR_PM_RTCWKEN
| MXC_F_GCR_PM_USBWKEN
| MXC_F_GCR_PM_SDMAWKEN ); // disable other wakeups
MXC_GCR->pm |= MXC_F_GCR_PM_WUTWKEN; // enable WUT wakeup
//Shutdown unused power domains
MXC_PWRSEQ->lpcn |= MXC_F_PWRSEQ_LPCN_BGOFF;
MXC_PWRSEQ->lpcn |= MXC_F_PWRSEQ_LPCN_FWKM;
if(MXC_GCR->revision == 0xA2) {
MXC_R_SIR_SHR13 = 0x0;
MXC_R_SIR_SHR17 &= ~(0xC0);
}
ICC_Disable();
LP_ICacheShutdown();
LP_VDD3PowerDown();
LP_VDD4PowerDown();
/* power down BLE VREGOD and LDOs */
MXC_PWRSEQ->lpvddpd |= MXC_F_PWRSEQ_LPVDDPD_VREGODPD;
vrego_d_setting = MXC_SIMO->vrego_d;
btleldocn_setting = MXC_GCR->btleldocn;
MXC_GCR->btleldocn = 0x66;
MXC_SIMO->vrego_d = 0;
BbDrvDisable();
// Retain all SRAM
MXC_PWRSEQ->lpcn |= (MXC_S_PWRSEQ_LPCN_RAMRET_EN3);
MXC_MCR->ctrl |= MXC_F_MCR_CTRL_VDDCSWEN;
switchToHIRC();
SIMO_setVregO_A(1800);
SIMO_setVregO_B(810);
SIMO_setVregO_C(810);
LP_EnterDeepSleepMode();
}
/*************************************************/
/* this will restore from DeepSleep Mode */
void ExitDeepsleep(void)
{
SIMO_setVregO_B(1100);
SIMO_setVregO_C(1100);
MXC_WUT->intr = 1;
NVIC_ClearPendingIRQ(WUT_IRQn);
MXC_PWRSEQ->lpvddpd &= ~MXC_F_PWRSEQ_LPVDDPD_VREGODPD;
MXC_SIMO->vrego_d = vrego_d_setting;
while(!(MXC_SIMO->buck_out_ready & MXC_F_SIMO_BUCK_OUT_READY_BUCKOUTRDYD)) {}
MXC_PWRSEQ->lpcn &= ~0x3FE00000; // Disable voltage Monitors for unused rails
MXC_GCR->pm |= MXC_F_GCR_PM_WUTWKEN;
SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
MXC_PWRSEQ->lpcn |= MXC_F_PWRSEQ_LPCN_BCKGRND;
LP_ICacheWakeup();
ICC_Enable();
/* Enable peripheral clocks */
MXC_GCR->perckcn0 &= ~(MXC_F_GCR_PERCKCN0_GPIO0D | MXC_F_GCR_PERCKCN0_GPIO1D);
MXC_GCR->perckcn1 &= ~(MXC_F_GCR_PERCKCN1_TRNGD);
// Restore BTLELDOCN setting
MXC_GCR->btleldocn = btleldocn_setting;
// Power up the 32MHz XO
MXC_GCR->clkcn |= MXC_F_GCR_CLKCN_X32M_EN;
// Wait for crystal warmup
WUT_SetInt(US_TO_BBTICKS(WAKEUP_32M_US));
LP_EnterSleepMode();
while(!(MXC_GCR->clkcn & MXC_F_GCR_CLKCN_X32M_RDY)) {}
/* setup the systick */
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);
switchToHIRC96M();
/* enable UART */
Console_Init();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment