IEEE 802.15.4/2.4G Switchable Demo
This example demos how to switch between Realtek 2.4G proprietary protocol/IEEE 802.15.4 protocol and transmit data using one protocol at a time.
Note
Due to hardware limitations, it is not possible to simultaneously transmit Realtek 2.4G proprietary protocol packets and IEEE 802.15.4 packets on RTL8752H series chips.
Requirements
The sample supports the following development kits. For more requirements for booting, please refer to Quick Start.
Hardware Platforms |
Board Name |
---|---|
RTL8752H HDK |
RTL8752H EVB |
This demo project requires three EVBs to demo the T/RX of Realtek 2.4G proprietary protocol and IEEE 802.15.4 protocol.
EVB Board Number |
Purpose |
---|---|
EVB Board1 |
TX packets of Realtek 2.4G proprietary and IEEE 802.15.4 |
EVB Board2 |
Realtek 2.4G proprietary Receiver |
EVB Board3 |
Realtek IEEE 802.15.4 Receiver |
For the requirements of
EVB Board2
, please refer to 2.4G Simple TRX.For the requirements of
EVB Board3
, please refer to IEEE 802.15.4 TRX.
Wiring
Please refer to RTL8752H EVB Interfaces and Modules in Quick Start.
Configurations
For Realtek 2.4G proprietary configurations, refer to
src\app\ppt_154_switch_demo\ppt\ppt_cfg.h
.Note
EVB Board1
andEVB Board2
should share the same proprietary configuration.For IEEE 802.15.4 configurations, please refer to
zb_demo
insrc\app\ppt_154_switch_demo\zb\zb_main.c
. The default configuration hasPanID=0x05
,ShortAddr=1
,Channel=12
.Note
EVB Board1
andEVB Board3
should share the same IEEE 802.15.4 configuration.Please refer to IEEE 802.15.4 TRX for configuring
EVB Board3
to receive packets fromEVB Board1
.
Building and Downloading
This sample can be found in the SDK folder:
Project file: sdk\board\evb\ppt_154_switch_demo\mdk
Currently this project only supports Keil compiler.
To build and run the sample, follow the steps listed below:
Open project file.
To build the target, follow the steps listed on the Generating App Image in Quick Start.
After a successful compilation, the APP bin
app_MP_sdk_xxx.bin
will be generated in the directorybin
.To download APP bin into evaluation board, follow the steps listed on the MP Tool Download in Quick Start.
Press reset button on evaluation board and it will start running.
Experimental Verification
After programming the sample to EVB Board1
, use the Debug Analyzer
to obtain logs and view the running results.
Testing
After pressing the reset button, EVB Board1
uses a software timer with three-second period to loop the following procedures periodically.
APP receive 3s timeout event from the software timer.
Switch to IEEE 802.15.4 protocol.
Send IEEE 802.15.4 packets.
Idle for next timeout event.
APP receive 3s timeout event from the software timer.
Switch to 2.4G proprietary protocol.
Send 2.4G proprietary packet.
Idle for next timeout event.
After pressing the reset button and it’s 2.4G’s turn,
EVB Board1
will start send 2.4G packets and listen for responses.If
ACK_MODE
is enabled,EVB Board2
will send packet back toEVB Board1
.If it is successfully started, the following log will be printed: [APP] !**ptx: statistics tx 95, rx 70, miss 25(26.315%)
After pressing the reset button,
EVB Board2
will start listening to the air according to 2.4G proprietary configurations.If it starts successfully, the following log will be printed when it receives a packet from the air: [APP] !**prx: rx count 1774, int count 2969, rx stack 0x0008, entry 0, hp 0x00, len 15, hs 0x00000000, payload 01 02 01 02 01 01 02 01 05 05 09 32 2E 34 67
Note
Because the default configuration is BLE Advertising Channel 37, which is 2402MHz, PTX may hear the BLE device reply and PRX may hear the BLE device broadcast. You can modify parameters such as FREQUENCY to avoid BLE devices.
After pressing the reset button and it’s IEEE 802.15.4’s turn,
EVB Board1
will start send IEEE 802.15.4 packets and listen for responses.If it is successfully started, the following log will be printed: [APP] !**IO_MSG_TYPE_154
Please refer to IEEE 802.15.4 TRX for the testing results of
EVB Board3
.
Code Overview
The main purpose of this chapter is to help APP developers get familiar with the development process. This chapter will be introduced according to the following several parts:
Chapter Initialization introduce the initialization flow of the chip.
Chapter Switch Flow introduce switching flow and initialization/de-initialization of 2.4G proprietary and IEEE 802.15.4.
Source Code Directory
Project directory:
sdk\board\evb\ppt_154_switch_demo\
Source code directory:
sdk\src\app\ppt_154_switch_demo\
Source files in the application project are currently categorized into several groups as below.
└── Project: ppt_154_switch_demo
└── app
├── include includes rom UUID and part of ISR declaration
├── Lib includes all binary symbol files that user application is built on
├── ROM.lib
├── lowerstack.lib
└── rtl8752h_sdk.lib
├── cmsis includes vector table declaration and boot code
├── startup_rtl876x.s
└── system_rtl876x.c
├── platform includes all peripheral drivers and module code used by the application
├── ppt driver includes radio driver
├── ppt_driver.c includes hw registers operation
└── ppt_simple.c includes hw management and sw wrapper
├──zb_driver includes source files for IEEE 802.15.4 protocols
├── dbg_printf.c
├── patch.c
├── strtol.c
├── strtoll.c
├── strtoul.c
├── strtoull.c
├── mac_test_common.c
├── mac_test_cmds.c
├── mac_802154_frame_parser.c
├── mac_priv_cmds.c
├── mac_driver_ext.c
├── cmd_shell.c
├── cmd_shell_rom.c
├── consol_cmds.c
├── shell.c
└── stdio_port.c
└── app includes the user application implementation
├── overlay_mgr.c
├── main.c includes the io, os and platform initialization
└── app_task.c includes app task initialization and main loop for protocol switching demo
└── zb_demo includes IEEE 802.15.4 initialization
└── zb_main.c includes IEEE 802.15.4 task
└── ppt_demo
├── ppt_cfg.c includes the radio configurations and initialization
└── ppt_ptx.c includes tx and rx operations and interrupt routine
Initialization
When the EVB board boots up and the chip is reset, the main function will be called, which executes the following initialization functions:
int main(void)
{
extern uint32_t random_seed_value;
srand(random_seed_value);
board_init();
pwr_mgr_init();
task_init();
os_sched_start();
return 0;
}
pwr_mgr_init()
inits the DLPS power management module.task_init()
inits the app task and register the task main functionapp_main_task()
.os_sched_start()
starts the os scheduler. When the scheduler is started,app_main_task()
will be called and start the 3-second sw timer for triggering tx event.
void app_main_task(void *p_param)
{
os_msg_queue_create(&app_task_evt_queue_handle, APP_TASK_EVT_QUEUE_SIZE,
sizeof(uint8_t)); // T_EVENT_TYPE
os_msg_queue_create(&app_task_io_queue_handle, APP_TASK_IO_QUEUE_SIZE, sizeof(T_IO_MSG));
/* initialize IEEE 802.15.4 uart log and IEEE 802.15.4 rx task */
zb_task_init();
/* avoid confliction with ble psd procedure */
os_delay(1000);
os_timer_create(&tx_timer, "tx timer", 1, TX_TIMER_PERIOD, true, tx_timer_callback);
os_timer_start(&tx_timer);
T_EVENT_TYPE event;
while (1)
{
if (os_msg_recv(app_task_evt_queue_handle, &event, 0xFFFFFFFF) == true)
{
if (event == EVENT_IO_TO_APP)
{
T_IO_MSG msg = {0};
if (os_msg_recv(app_task_io_queue_handle, &msg, 0) == true)
{
app_handle_io_msg(msg);
}
}
}
}
}
Switch Flow
tx_timer_callback()
will be referenced every 3 seconds, which sends out a timeout event message with event typeIO_MSG_TYPE_TIMER
toapp_main_task()
, whereapp_handle_io_msg()
is responsible for handling all the message events transmitted to app task.Upon receiving the timeout event, it will trigger corresponding protocol initialization of 2.4G/IEEE 802.15.4, and transmit packet according to pre-defined protocol demo configuration.
After the protocol tx demo is finished, a message with event type
IO_MSG_TYPE_MULTIPROTOCOL
is issued toapp_main_task()
The subtype of this message indicates which protocol is applied in this round’s transmission demo.
2.4G Proprietary
Initialize and Configure
ppt_cfg()
will initialize and configure the radio, including frequency, PHY type, frame format, CRC parameters, whitening parameters, access address and transmit power.ppt_reg_handler()
register the radio’s interrupt handler.PTX mode configuration, header settings
ppt_set_tx_header()
, and prepare the data to be sentppt_push_tx_data()
.
Main Loop
PTX will send data in a loop for three times, the process is as follows:
prepare data
enable PTX and wait for completion
modify data content and length
delay 500ms
return to step 1
Radio Interrupt Handler
After enabling PTX or PRX, the radio will run and trigger the corresponding interrupt.
The registered interrupt function by ppt_reg_handler()
will be called. The interrupt type can be found in 2.4G Radio User Guide.
PTX will process
tx_int
.If ACK mode is turned on,
rx_int
will also be processed.If periodic mode is turned on,
tx_early_int
will be processed.When the number of retransmissions in periodic mode reaches the requirement, PTX will be turned off in the TRX interrupt, and then
kill_ptx_int
needs to be processed.
After the interrupt handling is complete and 2.4G proprietary hw state machine is in idle state, ppt_send_complete_msg_to_apptask()
is referenced to send 2.4G TX complete message with subtype IO_MSG_MPM_PPT
to app task.
Deinitialization
When app_handle_io_msg()
receives IO_MSG_MPM_PPT
event, it executes the following functions to disable 2.4G protocol.
ppt_disable_ptx()
blocks cpu until 2.4G proprietary hw state machine is in idle state.ppt_dlps_deinit()
executes dlps related configurations and recover to default state.ppt_deinit()
disables 2.4G MAC and free buffer memory allocated previously.
ppt_disable_ptx(NULL);
ppt_deinit();
ppt_dlps_deinit();
IEEE 802.15.4
Initialize and Configure
zb_mac_enable()
is referenced to enable IEEE 802.15.4 protocol.mac_SetPANId()
,mac_SetChannel()
,mac_SetShortAddress()
are referenced to configure pre-defined IEEE 802.15.4 tx packet.stub_zb_mac_data()
is referenced to transmit IEEE 802.15.4 packets, CPU is blocked until the transmission is completed.
After IEEE 802.15.4 TX finished, IO message with subtype IO_MSG_MPM_154
is sent to app task to notify application.
void zb_demo(void)
{
zb_mac_disable();
zb_mac_enable();
mac_SetPANId(0x5);
mac_SetChannel(12);
mac_SetShortAddress(0x1);
char *cmds[] = {"1", "7", "7"};
bool ret = stub_zb_mac_data(3, cmds);
if (ret)
{
T_IO_MSG bee_msg = {0};
bee_msg.type = IO_MSG_TYPE_MULTIPROTOCOL;
bee_msg.subtype = IO_MSG_MPM_154;
if (app_send_msg_to_apptask(&bee_msg) == false)
{
APP_PRINT_ERROR0("send message to app queue failed");
}
}
}
Deinitialization
zb_mac_disable()
is referenced to disable IEEE 802.15.4 mac driver.