Skip to content

Commit

Permalink
[EFR32 examples] Move EFR platform files higher up the tree for other…
Browse files Browse the repository at this point in the history
… examples uses (project-chip#2416)

* Move EFR32 board specific files in examples platform so they can be reused for other demos
Use those board files for opentread gn build so we add or remove board supports from the CHIP repo independantly
Add trigger in the function button handler to have Start joiner, Factory Reset and Software Update on the same button

* Restyled by gn

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
jmartinez-silabs and restyled-commits authored Sep 2, 2020
1 parent 1ab4db0 commit a4239eb
Show file tree
Hide file tree
Showing 30 changed files with 130 additions and 52 deletions.
12 changes: 7 additions & 5 deletions examples/lock-app/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,20 @@ import("${efr32_sdk_build_root}/efr32_sdk.gni")
assert(current_os == "freertos")

efr32_project_dir = "${chip_root}/examples/lock-app/efr32"
examples_plat_dir = "${chip_root}/examples/platform/efr32"

efr32_sdk("sdk") {
include_dirs = [
"${chip_root}/src/platform/EFR32",
"${efr32_project_dir}/include/",
"${efr32_project_dir}/src/",
"${efr32_project_dir}/src/platform/${efr32_family}/${efr32_board}",
"${examples_plat_dir}/${efr32_family}/${efr32_board}",
]

sources = [
"${efr32_project_dir}/include/CHIPProjectConfig.h",
"${efr32_project_dir}/include/FreeRTOSConfig.h",
"${efr32_project_dir}/src/platform/${efr32_family}/${efr32_board}/hal-config.h",
"${examples_plat_dir}/${efr32_family}/${efr32_board}/hal-config.h",
]

defines = []
Expand Down Expand Up @@ -63,6 +64,7 @@ efr32_executable("lock_app") {
include_dirs += [
"${efr32_project_dir}/include/",
"${chip_root}/src/app/util",
"${examples_plat_dir}/",
]

sources = [
Expand All @@ -78,6 +80,9 @@ efr32_executable("lock_app") {
"${chip_root}/src/app/util/process-cluster-message.c",
"${chip_root}/src/app/util/process-global-message.c",
"${chip_root}/src/app/util/util.c",
"${examples_plat_dir}/${efr32_family}/${efr32_board}/hal-config.h",
"${examples_plat_dir}/${efr32_family}/${efr32_board}/init_board.c",
"${examples_plat_dir}/${efr32_family}/${efr32_board}/init_mcu.c",
"src/AppTask.cpp",
"src/BoltLockManager.cpp",
"src/ButtonHandler.cpp",
Expand All @@ -88,9 +93,6 @@ efr32_executable("lock_app") {
"src/gen/callback-stub.c",
"src/gen/znet-bookkeeping.c",
"src/main.cpp",
"src/platform/${efr32_family}/${efr32_board}/hal-config.h",
"src/platform/${efr32_family}/${efr32_board}/init_board.c",
"src/platform/${efr32_family}/${efr32_board}/init_mcu.c",
]

output_dir = root_out_dir
Expand Down
9 changes: 6 additions & 3 deletions examples/lock-app/efr32/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ FREERTOSCONFIG_DIR := $(PROJECT_ROOT)/include

GECKO_SDK_SUITE_DIR := $(EFR32_SDK_ROOT)/..

EXAMPLES_PLAT_DIR := $(PROJECT_ROOT)/../../platform/efr32

all : |

BUILD_SUPPORT_DIR := $(CHIP_ROOT)/config/efr32
Expand All @@ -84,11 +86,11 @@ SRCS = \
$(PROJECT_ROOT)/src/ButtonHandler.cpp \
$(PROJECT_ROOT)/src/DataModelHandler.cpp \
$(PROJECT_ROOT)/src/Server.cpp \
$(PROJECT_ROOT)/src/platform/$(EFR32FAMILY)/$(BOARD)/init_mcu.c \
$(PROJECT_ROOT)/src/platform/$(EFR32FAMILY)/$(BOARD)/init_board.c \
$(PROJECT_ROOT)/src/gen/call-command-handler.c \
$(PROJECT_ROOT)/src/gen/callback-stub.c \
$(PROJECT_ROOT)/src/gen/znet-bookkeeping.c \
$(EXAMPLES_PLAT_DIR)/$(EFR32FAMILY)/$(BOARD)/init_mcu.c \
$(EXAMPLES_PLAT_DIR)/$(EFR32FAMILY)/$(BOARD)/init_board.c \
$(CHIP_ROOT)/src/app/util/attribute-size.c \
$(CHIP_ROOT)/src/app/util/attribute-storage.c \
$(CHIP_ROOT)/src/app/util/attribute-table.c \
Expand Down Expand Up @@ -132,10 +134,11 @@ SRCS = \
INC_DIRS = \
$(PROJECT_ROOT) \
$(PROJECT_ROOT)/src/ \
$(PROJECT_ROOT)/src/platform/$(EFR32FAMILY)/$(BOARD) \
$(PROJECT_ROOT)/include \
$(PROJECT_ROOT)/traits/include \
$(PROJECT_ROOT)/schema/include \
$(EXAMPLES_PLAT_DIR) \
$(EXAMPLES_PLAT_DIR)/$(EFR32FAMILY)/$(BOARD) \
$(CHIP_ROOT)/src/include/ \
$(CHIP_ROOT)/src/lib \
$(CHIP_ROOT)/src/ \
Expand Down
8 changes: 1 addition & 7 deletions examples/lock-app/efr32/include/AppConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,13 @@
// EFR32 WSTK Buttons
#define PB0 0
#define PB1 1
// TODO There is no set 3rd push button on the WSTK keep.
// Keep this for function button future use
#define PB2 2

// EFR32 WSTK LEDs
#define BSP_LED_0 0
#define BSP_LED_1 1

#define APP_JOIN_BUTTON PB0
#define APP_LOCK_BUTTON PB1
// TODO Currently no Function Button for EFR32,
// OTA not implemented but keep for future use. (Reused PB0 for Join button)
#define APP_FUNCTION_BUTTON PB2
#define APP_FUNCTION_BUTTON PB0
#define APP_BUTTON_DEBOUNCE_PERIOD_MS 50

#define APP_BUTTON_PRESSED 0
Expand Down
4 changes: 2 additions & 2 deletions examples/lock-app/efr32/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class AppTask

static void FunctionTimerEventHandler(AppEvent * aEvent);
static void FunctionHandler(AppEvent * aEvent);
static void JoinHandler(AppEvent * aEvent);
static void LockActionEventHandler(AppEvent * aEvent);
static void TimerEventHandler(TimerHandle_t xTimer);

Expand All @@ -71,7 +70,8 @@ class AppTask
{
kFunction_NoneSelected = 0,
kFunction_SoftwareUpdate = 0,
kFunction_FactoryReset,
kFunction_Joiner = 1,
kFunction_FactoryReset = 2,

kFunction_Invalid
} Function;
Expand Down
58 changes: 31 additions & 27 deletions examples/lock-app/efr32/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ using namespace chip::DeviceLayer;
#include <platform/OpenThread/OpenThreadUtils.h>
#include <platform/ThreadStackManager.h>
#include <platform/internal/DeviceNetworkInfo.h>
#define JOINER_START_TRIGGER_TIMEOUT 1500
#endif

#define FACTORY_RESET_TRIGGER_TIMEOUT 3000
#define FACTORY_RESET_CANCEL_WINDOW_TIMEOUT 3000
#define APP_TASK_STACK_SIZE (4096)
Expand Down Expand Up @@ -318,25 +320,9 @@ void AppTask::LockActionEventHandler(AppEvent * aEvent)
}
}

#if CHIP_ENABLE_OPENTHREAD
void AppTask::JoinHandler(AppEvent * aEvent)
{
assert(aEvent != NULL);
if (aEvent->ButtonEvent.ButtonIdx != APP_JOIN_BUTTON)
return;

CHIP_ERROR error = ThreadStackMgr().JoinerStart();
EFR32_LOG("Thread joiner triggered: %s", chip::ErrorStr(error));
}
#endif

void AppTask::ButtonEventHandler(uint8_t btnIdx, uint8_t btnAction)
{
if (btnIdx != APP_LOCK_BUTTON
#if CHIP_ENABLE_OPENTHREAD
&& btnIdx != APP_JOIN_BUTTON
#endif
&& btnIdx != APP_FUNCTION_BUTTON)
if (btnIdx != APP_LOCK_BUTTON && btnIdx != APP_FUNCTION_BUTTON)
{
return;
}
Expand All @@ -356,13 +342,6 @@ void AppTask::ButtonEventHandler(uint8_t btnIdx, uint8_t btnAction)
button_event.Handler = FunctionHandler;
sAppTask.PostEvent(&button_event);
}
#if CHIP_ENABLE_OPENTHREAD
else if (btnIdx == APP_JOIN_BUTTON)
{
button_event.Handler = JoinHandler;
sAppTask.PostEvent(&button_event);
}
#endif
}

void AppTask::TimerEventHandler(TimerHandle_t xTimer)
Expand All @@ -385,7 +364,16 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent)
// initiate factory reset
if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_SoftwareUpdate)
{
EFR32_LOG("Factory Reset Triggered. Release button within %ums to cancel.", FACTORY_RESET_TRIGGER_TIMEOUT);
#if CHIP_ENABLE_OPENTHREAD
EFR32_LOG("Release button now to Start Thread Joiner");
EFR32_LOG("Hold to trigger Factory Reset");
sAppTask.mFunction = kFunction_Joiner;
sAppTask.StartTimer(FACTORY_RESET_TRIGGER_TIMEOUT);
}
else if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_Joiner)
{
#endif
EFR32_LOG("Factory Reset Triggered. Release button within %ums to cancel.", FACTORY_RESET_CANCEL_WINDOW_TIMEOUT);

// Start timer for FACTORY_RESET_CANCEL_WINDOW_TIMEOUT to allow user to
// cancel, if required.
Expand All @@ -403,7 +391,9 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent)
}
else if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_FactoryReset)
{
EFR32_LOG("Factory Reset is not supported at this time.");
// Actually trigger Factory Reset
sAppTask.mFunction = kFunction_NoneSelected;
ConfigurationMgr().InitiateFactoryReset();
}
}

Expand All @@ -425,7 +415,11 @@ void AppTask::FunctionHandler(AppEvent * aEvent)
{
if (!sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_NoneSelected)
{
#if CHIP_ENABLE_OPENTHREAD
sAppTask.StartTimer(JOINER_START_TRIGGER_TIMEOUT);
#else
sAppTask.StartTimer(FACTORY_RESET_TRIGGER_TIMEOUT);
#endif

sAppTask.mFunction = kFunction_SoftwareUpdate;
}
Expand All @@ -440,8 +434,18 @@ void AppTask::FunctionHandler(AppEvent * aEvent)

sAppTask.mFunction = kFunction_NoneSelected;

EFR32_LOG("Software Update is not supported at this time");
EFR32_LOG("Software Update currently not supported.");
}
#if CHIP_ENABLE_OPENTHREAD
else if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_Joiner)
{
sAppTask.CancelTimer();
sAppTask.mFunction = kFunction_NoneSelected;

CHIP_ERROR error = ThreadStackMgr().JoinerStart();
EFR32_LOG("Thread joiner triggered: %s", chip::ErrorStr(error));
}
#endif
else if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_FactoryReset)
{
// Set lock status LED back to show state of lock.
Expand Down
67 changes: 67 additions & 0 deletions examples/platform/efr32/board_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright (c) 2018, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

/**
* @file
* This file includes dev borad compile-time configuration constants for efr32.
*
*/

#ifndef __BOARD_CONFIG_H__
#define __BOARD_CONFIG_H__

/// Dev board suppports OQPSK modulation in 2.4GHz band.
#if (BRD4161A || BRD4163A || BRD4164A || BRD4166A || BRD4170A || BRD4304A || BRD4180A)
#define RADIO_CONFIG_2P4GHZ_OQPSK_SUPPORT 1
#else
#define RADIO_CONFIG_2P4GHZ_OQPSK_SUPPORT 0
#endif

/// Dev board doesn't support OQPSK modulation in 915MHz band.
#if (BRD4170A)
#define RADIO_CONFIG_915MHZ_OQPSK_SUPPORT 1
#else
#define RADIO_CONFIG_915MHZ_OQPSK_SUPPORT 0
#endif

/// The PA(s) is(are) fed from the DCDC
#if (BRD4166A)
#define RADIO_CONFIG_PA_USES_DCDC 1
#else
#define RADIO_CONFIG_PA_USES_DCDC 0
#endif

#ifndef RADIO_CONFIG_DEBUG_COUNTERS_SUPPORT
#define RADIO_CONFIG_DEBUG_COUNTERS_SUPPORT 0 /// Set to 1 to enable debug counters in radio.c
#endif

#ifndef RADIO_CONFIG_DMP_SUPPORT
#define RADIO_CONFIG_DMP_SUPPORT 0 /// Set to 1 to enable Dynamic Multi-Protocol support in radio.c
#endif

#endif // __BOARD_CONFIG_H__
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@
#define HAL_SERIAL_USART3_ENABLE (0)
#define HAL_SERIAL_RXWAKE_ENABLE (0)

#define HAL_SERIAL_APP_RX_QUEUE_SIZE (128)
#define HAL_SERIAL_APP_BAUD_RATE (115200)
#define HAL_SERIAL_APP_RXSTOP (16)
#define HAL_SERIAL_APP_RXSTART (16)
#define HAL_SERIAL_APP_TX_QUEUE_SIZE (128)
#define HAL_SERIAL_APP_FLOW_CONTROL (HAL_USART_FLOW_CONTROL_HWUART)

#define HAL_USART0_ENABLE (1)
#define HAL_USART0_RX_QUEUE_SIZE (128)
#define HAL_USART0_BAUD_RATE (115200)
Expand Down
File renamed without changes.
File renamed without changes.
17 changes: 9 additions & 8 deletions third_party/openthread/platforms/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import("//build_overrides/chip.gni")
import("//build_overrides/efr32_sdk.gni")
import("//build_overrides/openthread.gni")

Expand All @@ -20,15 +21,15 @@ import("${efr32_sdk_build_root}/efr32_board.gni")
config("openthread_efr32_config") {
include_dirs = [ "${openthread_root}/examples/platforms/${efr32_family}" ]

defines = [ "RADIO_CONFIG_DMP_SUPPORT=1" ]
defines = [
"RADIO_CONFIG_DMP_SUPPORT=1",
"${efr32_board}=1"
]

if (efr32_board == "BRD4161A") {
include_dirs +=
[ "${openthread_root}/examples/platforms/${efr32_family}/brd4161a" ]
} else if (efr32_board == "BRD4166A") {
include_dirs +=
[ "${openthread_root}/examples/platforms/${efr32_family}/brd4166a" ]
}
include_dirs += [
"${chip_root}/examples/platform/efr32",
"${chip_root}/examples/platform/efr32/${efr32_family}/${efr32_board}",
]
}

source_set("openthread_core_config_efr32") {
Expand Down

0 comments on commit a4239eb

Please sign in to comment.