Skip to content

Commit

Permalink
modules: hal_silabs: Add Proprietary TRX example
Browse files Browse the repository at this point in the history
Add Proprietary TRX example to show SiliconLabs radio board capabilities.

Signed-off-by: Zoltan Havas <[email protected]>
  • Loading branch information
zohavas committed Jan 16, 2024
1 parent 7a6ba7c commit f9876a9
Show file tree
Hide file tree
Showing 32 changed files with 3,637 additions and 0 deletions.
41 changes: 41 additions & 0 deletions examples/proprietary_trx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(propriatery_trx)


if (${CONFIG_BOARD} STREQUAL "efr32xg24_dk2601b")
set(SILABS_GECKO_BOARD "brd2601b")
endif()

if (${CONFIG_BOARD} STREQUAL "efr32bg27_brd2602a")
set(SILABS_GECKO_BOARD "brd2602a")
endif()

if (${CONFIG_BOARD} STREQUAL "efr32bg22_brd4184a")
set(SILABS_GECKO_BOARD "brd4184a")
endif()

if (${CONFIG_BOARD} STREQUAL "efr32bg22_brd4184b")
set(SILABS_GECKO_BOARD "brd4184b")
endif()

zephyr_include_directories(
src/config/rail/${SILABS_GECKO_BOARD}
)

target_include_directories(app PRIVATE
src/
src/autogen/
src/config/
src/config/rail
)

target_sources(app PRIVATE src/main.c)
target_sources(app PRIVATE src/app_gpio.c)
target_sources(app PRIVATE src/app_cli.c)
target_sources(app PRIVATE src/app_rail.c)
target_sources(app PRIVATE src/autogen/sl_rail_util_callbacks.c)
target_sources(app PRIVATE src/autogen/sl_rail_util_init.c)
target_sources(app PRIVATE src/config/rail/${SILABS_GECKO_BOARD}/rail_config.c)
110 changes: 110 additions & 0 deletions examples/proprietary_trx/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
Proprietary TRX
###############

Overview
********

The Proprietary TRX example demonstrates the simplest exchange of transmit and
receive operation between two nodes implemented in RAIL.

This application can be used for setting up a simple link test, where the nodes
are listening except for the short periods where packet transmission takes
place. Also, this application can be used as a learning material.

Requirements
************

This application requires part or board that support RAIL, has radio antenna
connection and has at least one LED and one button.

Building and Running
********************

This sample can be built for multiple boards, in this example we will build it
for the efr32bg22_brd4184a board:

.. code-block:: bash
west build -p always -b efr32bg22_brd4184a
This example implements both the receiver (RX) and the transmitter (TX) nodes.
The implementation is therefore symmetric, as both nodes are capable of sending
and receiving messages. In this document the use of `RX node` and `TX node` are
implicit and these terms refer the devices temporary, while the denoted
operations are performed.

Compile the project and download the application to two radio boards.

On startup the Zephyr boot will be displayed, with additional information
about the RAIL library version.

The devices start in the receiving state.

Issue the `send` command on the TX node to request packet transmission:

.. code-block:: bash
send
> Send packet request
> Packet has been sent
Additional logs can be viewed by the logger, which can be turned off.

On the receiver side the following response will be printed out on packet
reception:

.. code-block:: bash
> Packet has been received: 0x0F, 0x16, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE,
Additional logs can be viewed by the logger, which can be turned off.

If the reception is enabled the device will automatically switch back to RX mode
either after a successful or faulty reception or a transmission.


The reception can be disabled by the `receive` command.

.. code-block:: bash
receive 0
> Received packets: NOK
Receive mode can be enabled again by the same command:

.. code-block:: bash
receive 1
> Received packets: OK
Peripherals
***********

Same working can be achieved by pushing button or buttons and waiting for the led
or LEDs to toggle.

Extra settings
**************

For changing any settings for the used radio or radio phy please update the
configuration files under the following folders:

.. code-block:: bash
zephyrproject/modules/hal/silabs/gecko/platform/radio/rail_lib/plugin/pa-conversions/
zephyrproject/modules/hal/silabs/gecko/platform/radio/rail_lib/plugin/rail_util_protocol/config/
And to re-generate the radio_conf c and h files use Simplicity Studio's `EFR32 Radio Configurator`_ .

.. _EFR32 Radio Configurator: https://www.silabs.com/documents/public/application-notes/an1253-efr32-radio-configurator-guide-for-ssv5.pdf

Extra Resources
***************

- `RAIL Tutorial Series`_:
it is advised to read through the `Studio v5 series` first to familiarize the
basics of packet transmission and reception

.. _RAIL Tutorial Series: https://community.silabs.com/s/article/rail-tutorial-series?language=en_US
9 changes: 9 additions & 0 deletions examples/proprietary_trx/boards/efr32bg22_brd4184a.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright (c) 2023 Silicon Laboratories Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/

&cpu0 {
cpu-power-states = <&pstate_em1>;
};
9 changes: 9 additions & 0 deletions examples/proprietary_trx/boards/efr32bg22_brd4184b.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright (c) 2023 Silicon Laboratories Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/

&cpu0 {
cpu-power-states = <&pstate_em1>;
};
9 changes: 9 additions & 0 deletions examples/proprietary_trx/boards/efr32mg22_brd4182a.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright (c) 2023 Silicon Laboratories Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/

&cpu0 {
cpu-power-states = <&pstate_em1>;
};
14 changes: 14 additions & 0 deletions examples/proprietary_trx/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# SPDX-License-Identifier: Apache-2.0
CONFIG_GPIO=y
CONFIG_SOC_GECKO_CUSTOM_RADIO_PHY=y
CONFIG_FPU=y
CONFIG_PM=y
CONFIG_PRINTK=y
CONFIG_LOG=y
CONFIG_SHELL=y
CONFIG_EVENTS=y
CONFIG_ASSERT=y
CONFIG_BOOT_BANNER=y
CONFIG_POSIX_CLOCK=y
CONFIG_INIT_STACKS=y
CONFIG_SMF=y
14 changes: 14 additions & 0 deletions examples/proprietary_trx/prj_efr32xg24_dk2601b.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# SPDX-License-Identifier: Apache-2.0
CONFIG_GPIO=y
CONFIG_SOC_GECKO_CUSTOM_RADIO_PHY=y
CONFIG_FPU=y
CONFIG_PRINTK=y
CONFIG_LOG=y
CONFIG_SHELL=y
CONFIG_EVENTS=y
CONFIG_ASSERT=y
CONFIG_BOOT_BANNER=y
CONFIG_POSIX_CLOCK=y
CONFIG_INIT_STACKS=y
CONFIG_SMF=y

62 changes: 62 additions & 0 deletions examples/proprietary_trx/src/app_cli.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* SPDX-License-Identifier: Apache-2.0
*/

// -----------------------------------------------------------------------------
// Includes

#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/sys/util.h>
#include <zephyr/sys/printk.h>
#include <inttypes.h>
#include <zephyr/shell/shell.h>
#include <zephyr/logging/log.h>
#include <stdlib.h>
#include "em_chip.h"
#include "app_process.h"

// -----------------------------------------------------------------------------
// Public Function Definitions

/******************************************************************************
* CLI - send: Sets a flag indicating that a packet has to be sent
*****************************************************************************/
void cli_send_packet(const struct shell *sh, size_t argc, char **argv)
{
shell_fprintf(sh, SHELL_NORMAL, "Send packet request\n");
k_event_post(&s_sl_machine.smf_event, EVENT_REQUEST_SEND);
}

/******************************************************************************
* CLI - info message: Unique ID of the board
*****************************************************************************/
void cli_info(const struct shell *sh, size_t argc, char **argv)
{
shell_fprintf(sh, SHELL_NORMAL, "Info:\n");
shell_fprintf(sh, SHELL_NORMAL, " MCU Id: 0x%llx\n", SYSTEM_GetUnique());
}

/******************************************************************************
* CLI - receive: Turn on/off continues packet receiving
*****************************************************************************/
void cli_receive_packet(const struct shell *sh, size_t argc, char **argv)
{
uint8_t rxForward = (uint8_t)(strtoul(argv[1], NULL, 0));
if (rxForward == 0) {
shell_fprintf(sh, SHELL_NORMAL, "Continues packet receiving is OFF\n");
s_sl_machine.allow_rx = false;
} else {
shell_fprintf(sh, SHELL_NORMAL, "Continues packet receiving is ON\n");
s_sl_machine.allow_rx = true;
}
k_event_post(&s_sl_machine.smf_event, EVENT_CLI_RECEIVE_SETTING);
}

SHELL_CMD_ARG_REGISTER(info, NULL, "Display unique ID of the MCU", cli_info, 1, 0);

SHELL_CMD_ARG_REGISTER(send, NULL, "Send a packet", cli_send_packet, 1, 0);

SHELL_CMD_ARG_REGISTER(receive, NULL, "Turn ON/OFF continues packet receiving", cli_receive_packet,
2, 0);
Loading

0 comments on commit f9876a9

Please sign in to comment.