AN1134: Dynamic Multiprotocol Development with Bluetooth® and Proprietary Protocols on RAIL in GSDK v2.x
This application note provides details on how to develop a multiprotocol application running Bluetooth and a proprietary protocol at the same time. It discusses criteria for coexistence, guides through creating a new DMP application, configuring Bluetooth and proprietary protocols, and transmitting/receiving proprietary packets while Bluetooth is running. It also details the Light/Switch DMP example.
Key Points
- Generic guidelines for protocol coexistence
- Generating and configuring a new Bluetooth/Proprietary DMP project
- Sending and receiving proprietary packets
- Using RAIL priorities
- Building and understanding the Light/Switch DMP example
1. Introduction
UG305: Dynamic Multiprotocol User's Guide provides information about the Dynamic Multiprotocol solution, where two protocols run in parallel. It includes general background on Bluetooth task priorities and scheduling. This application note introduces the Bluetooth / Proprietary multiprotocol solution, assuming familiarity with Dynamic Multiprotocol principles.
1.1 Requirements
To use the features discussed, the following must be installed:
- Bluetooth SDK version 2.9.0 or higher
- Micrium OS-5 kernel
To run the Light/Switch example, the following are also required:
- Bluetooth SDK version 2.7.0 or higher
- Flex SDK version 2.1 or higher
- An EFR32 chip with at least 512 kB of flash
- IAR Embedded Workbench for ARM (IAR-EWARM)
2. Guidelines for Bluetooth and Proprietary Coexistence
When implementing a Bluetooth / Proprietary DMP application, consider the compatibility of your proprietary protocol with Bluetooth. Key guidelines include:
- Bluetooth is deterministic: It sends and receives packets at predefined time instances, typically at the start of a connection interval. This allows proprietary protocols to operate in the background with minimal interruptions.
- Bluetooth needs accuracy: Timing is critical (500 ppm accuracy). Delayed Bluetooth packets may not be received. Collisions with proprietary packets require the proprietary packet to be delayed or dropped.
- Bluetooth connection is active: Connections are maintained by sending empty packets every connection interval. Proprietary protocols must be prepared for interruptions. Connection intervals can be lengthened to reduce Bluetooth latency.
- Bluetooth uses short packets: Empty packets are used to maintain connections. The time taken for these packets, including inter-frame space, is typically 230 µs to 2350 µs depending on packet size and PHY.
- Bluetooth uses packet chains: Multiple packets can be sent/received within a connection interval, though this is rare.
- Bluetooth is robust: Retransmissions occur if packets are not sent or received with CRC errors. The connection drops if no successful transmission occurs within the supervision timeout. Higher priority radio tasks can subdue Bluetooth communication for short intervals.
Summary: Bluetooth requires radio access every connection interval for short durations (230 µs – 2350 µs) with precise timing. Bluetooth packets can interrupt proprietary packet transmission/reception. Proprietary protocols should implement acknowledgment and retransmission mechanisms or deterministic, interleaved timing.
3. Software Architecture of a Bluetooth / Proprietary DMP application
DMP applications are based on Micrium RTOS, enabling parallel and independent operation of Bluetooth and proprietary protocols. The Bluetooth stack functions are accessed via BGAPI. The developer implements the Bluetooth application logic in bluetoothAppTask()
. The proprietary protocol uses the RAIL API directly, with events handled by radioEventHandler()
. Communication between Bluetooth and proprietary applications occurs via inter-process communication (IPC).
Diagram Description: A block diagram shows the interaction between bluetoothAppTask()
(using Bluetooth stack, LinkLayerTask, BGAPI) and proprietaryAppTask()
(using Radio, RAIL API, radioEventHandler()
). Both communicate via IPC. The diagram indicates that the Bluetooth stack and LinkLayerTask can be used as-is, while the radio event handler is called from interrupt context.
4. Developing a Bluetooth / Proprietary DMP Project
4.1 Create a New Project
Silicon Labs Bluetooth SDK (v2.9 or later) provides the "SOC - Empty - RAIL - DMP" Software Example as a starting point. This example includes the multiprotocol RAIL library, Bluetooth library, Micrium RTOS, and default configurations for Bluetooth GATT, RAIL, and RTOS. It also implements Bluetooth, RAIL, and RTOS initialization.
To create a new project:
- Open Simplicity Studio.
- Select your device.
- Click [New Project] or File > New > Project.
- Select Bluetooth SDK.
- Select Bluetooth SDK v2.9.0 or later.
- Select SOC – Empty – RAIL - DMP sample application.
- Name your project.
- Check your part number.
- Select the compiler and click [Finish].
Diagram Description: A workflow diagram shows the creation of a DMP project. It starts with the Bluetooth SDK and Gecko SDK suite (including emlib, emdrv). These connect to the Radio Configurator (generating rail_config.c/h) and Visual GATT Editor (generating gatt_db.c/h). The output is a DMP project with project files and driver files.
4.2 Configure Bluetooth
Bluetooth configuration involves two steps:
- Configuring the local GATT database using the Visual GATT editor tool.
- Configuring the Bluetooth stack by modifying the
gecko_configuration_t config
structure inmain.c
.
Diagram Description: A screenshot shows the Bluetooth Configurator interface within Simplicity Studio, allowing configuration of GATT services and characteristics, and general Bluetooth settings.
4.3 Configure Proprietary Protocol
Proprietary protocol configuration involves:
- Configuring radio channels (frequency, modulation) using the Radio Configurator tool.
- Configuring the RAIL API.
To configure RAIL, open main.c
and find the proprietaryAppTask()
function where RAIL initialization is performed. Multiple radio configurations can be selected, and RAIL events can be subscribed to.
Diagram Description: A screenshot shows the EFR32 Multi PHY Configurator in Simplicity Studio, used for setting up protocol configuration, channels, modulation, packet formats, and generating RAIL configuration files.
4.4 Develop Bluetooth Application
Bluetooth applications are implemented similarly to non-DMP scenarios. BGAPI commands can be called from anywhere (except interrupt context), and BGAPI events are fetched from the Bluetooth stack's internal event queue, typically in an infinite loop. DMP Bluetooth applications require an RTOS. Event handling is implemented in bluetoothAppTask()
, with new events added as case statements.
Diagram Description: A flowchart illustrates the process within bluetoothAppTask()
: wait for Bluetooth event flag, fetch Bluetooth event, and then execute actions based on the event ID (e.g., event_id1
, event_id2
).
4.5 Develop Proprietary Application
Proprietary applications use the RAIL API directly. Commands can be called from anywhere, and events are handled in the callback function set during RAIL initialization (e.g., radioEventHandler()
). This callback is executed in interrupt context, so only time-critical calculations should be performed, setting flags to inform the main loop.
The main loop for processing radio events is in proprietaryAppTask()
. Communication between radioEventHandler()
and proprietaryAppTask()
is recommended via RTOS services like semaphores or flags.
Diagram Description: A flowchart shows the interaction between radioEventHandler()
and proprietaryAppTask()
. radioEventHandler()
checks RAIL event flags, performs immediate actions, and sets flags. proprietaryAppTask()
waits for these flags, checks protocol state, and executes actions.
4.6 Communication between Bluetooth and Proprietary Protocol
Bluetooth and proprietary protocols run in independent tasks but often require synchronization. To notify the Bluetooth task from the proprietary task, use gecko_external_signal()
to place an event in the Bluetooth stack's queue, handled by gecko_evt_system_external_signal_id
in bluetoothAppTask()
. To notify the proprietary task from the Bluetooth task, set an RTOS flag.
5. Examples
5.1 Sending Proprietary Packets
This example sends a proprietary packet when a specific GATT characteristic is written. It involves creating a new "SOC - Empty - RAIL - DMP" project, adding a characteristic (e.g., "Proprietary characteristic" with Read, Write, Notify properties), and defining flags and FIFOs.
In bluetoothAppTask()
, an event handler is added to detect changes to the proprietary characteristic and set a flag. In proprietaryAppTask()
, the code waits for this flag, reads the characteristic's value, copies it to the Tx FIFO, and sends the packet using RAIL. The radioEventHandler()
is used to yield the radio after a packet is sent.
5.2 Receiving Proprietary Packets
This example implements a receiver that updates a GATT characteristic upon receiving a proprietary packet. It extends the transmitter example by defining a packet reception flag and an Rx FIFO.
In proprietaryAppTask()
, Rx transitions are set for automatic state restoration, Rx priority is set lower than Tx, and Rx is started. The radioEventHandler()
checks for received packets, copies them to the Rx FIFO, and sets a flag. The main loop in proprietaryAppTask()
waits for either a characteristic change or packet reception. If a packet is received, its content is written to the GATT database, and an external signal is sent to the Bluetooth stack. In bluetoothAppTask()
, this external signal is handled to send a notification.
6. Light/Switch Example
This section details working with the Light/Switch example, which provides a user interface documented in QSG155. To use this example, Flex SDK v2.1.0+ and Bluetooth SDK v2.7.0+ are required, along with the Micrium kernel and specific IAR Embedded Workbench version.
6.1.1 Building the RAIL:Switch Application
Steps involve starting a new project in Simplicity Studio, selecting the Flex SDK and the "RAIL: Switch" application, configuring the project, and generating project files. Compilation and flashing can then be performed.
Diagram Description: An image shows "DMP Demo Switch" on an LCD display.
6.1.2 Building the Bluetooth Light Application
The Bluetooth Light application requires the Gecko Bootloader. This can be loaded with a precompiled "SOC - Light - RAIL - DMP" demonstration or by building a custom bootloader image. Steps involve starting a new project, selecting the Bluetooth SDK and the "SOC - Light - RAIL - DMP" application, configuring the project, and compiling/flashing.
Diagram Description: An image shows "DMP Demo Light" and "DMP:F754" on an LCD display.
6.1.3 Changing the PHY Configuration
The default PHY configuration is sub-Gigahertz. To change it, open the RAIL:Switch project, select the Radio Configuration tab, choose a new PHY, and generate new configuration files. These files (rail_config.c
and rail_config.h
) are then copied to the SOC - Light - RAIL - DMP project, overwriting existing ones. Both projects are then rebuilt and flashed.