Simple TRX
This example uses two projects to play the roles of PTX and PRX respectively. They can send messages to each other to demonstrate the basic usage of radio.
Requirements
The sample supports the following development kits:
Hardware Platforms |
Board Name |
---|---|
RTL87x2G HDK |
RTL87x2G EVB |
For more requirements, please refer to Quick Start.
Wiring
Please refer to RTL87x2G EVB Interfaces and Modules in Quick Start.
Configurations
All the content that needs to be configured in APP is in samples\ppt\ppt_simple_trx\src\ppt_cfg.h
.
The default configuration is what is required for BLE Advertising, and developers can configure it according to actual needs.
Building and Downloading
This sample can be found in the SDK folder:
Project file:
samples\ppt\ppt_simple_trx\proj_ptx\rtl87x2g\mdk
samples\ppt\ppt_simple_trx\proj_prx\rtl87x2g\mdk
Project file:
samples\ppt\ppt_simple_trx\proj_ptx\rtl87x2g\gcc
samples\ppt\ppt_simple_trx\proj_prx\rtl87x2g\gcc
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 two evaluation boards, use the Debug Analyzer
to obtain logs and view the running results.
Testing
After pressing the reset button, the PTX EVB will start simulating BLE Adv to send broadcasts and listen for responses. The PTX role is to send packets periodically and can enter sleep mode when idle. 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, the PRX EVB will start simulating BLE Scan to listen to broadcasts and send responses. If it starts successfully, the following log will be printed.
[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
Attention
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.
Code Overview
The main purpose of this chapter is to help APP developers familiar with the development process. This chapter will be introduced according to the following several parts:
Chapter Source Code Directory introduces the directory path of the project and the source files.
Chapter Initialization introduces the initialization flow of the chip.
Chapter PTX/PRX Flow introduces radio initialization and running process.
Source Code Directory
Project directory:
samples\ppt\ppt_simple_trx\proj_xxx
Source code directory:
samples\ppt\ppt_simple_trx\src
Source files in the application project are currently categorized into several groups as below.
└── Project: ptx(prx)
└── secure_only_app
├── Device includes startup code
├── CMSE Library Non-secure callable lib
├── Lib includes all binary symbol files that user application is built on
├── ROM_NS.lib
├── lowerstack.lib
├── rtl87x2g_sdk.lib
└── rtl87x2g_io.lib
├── Peripheral 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
└── APP includes the ble_peripheral user application implementation
├── main_ns.c includes the io, os and platform initialization
├── app_task.c includes app task initialization and main loop
├── ppt_cfg.c includes the radio configurations
└── ppt_ptx(prx).c includes ptx and prx 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)
{
DBG_DIRECT("Non-Secure World: main");
#if DLPS_EN
pwr_mgr_init();
#endif
app_task_init();
/* Start scheduler. */
os_sched_start();
/* Should not reach here as the scheduler is already started. */
for (; ;)
{
}
}
pwr_mgr_init
inits the DLPS power management module.app_task_init
inits the app task and registers 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 invoke the radio main functionppt_demo
, as shown below.
void app_main_task(void *p_param)
{
uint8_t event;
/* This task calls secure side functions. So allocate a secure context for
* it. */
//must locate at the first line
os_alloc_secure_ctx(configMINIMAL_SECURE_STACK_SIZE);
/* avoid ppt initialization conflict with ble psd procedure */
os_delay(1000);
void ppt_demo(void);
ppt_demo();
while (1);
}
PTX/PRX Flow
ppt_demo
will initialize and configure the radio, then start the loop of PTX or PRX.
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()
registers the radio’s interrupt handler.Configure the PTX and PRX mode, set the packet header via
ppt_set_tx_header()
, and prepare the data to be sent viappt_push_tx_data()
.
Note
The PRX character also demonstrated the process of doing a PSD channel scan on 79 channels from 2402 MHz to 2480 MHz, as shown below.
/*
* psd sample code
* get the channel rssi of different frequencies from 2402 to 2480 MHz
*/
for (uint8_t loop = 0; loop < 79; loop++)
{
ppt_psd_mode_ext_t param =
{
{
.chann_start = loop,
.chann_stop = loop,
.chann_step = 1,
.mode = 0,
.timeout = PSD_TIMEOUT_DEFAULT
}
};
ppt_set_psd_mode_ext(¶m);
ppt_enable_psd(NULL);
}
for (uint8_t loop = 0; loop < 79; loop++)
{
int16_t rssi = ppt_get_psd_result(loop);
DBG_DIRECT("PSD: freq %dMHz rssi = %ddBm", 2402 + loop, rssi);
}
Main Loop
PTX will send data in a loop, the process is as follows:
prepare data.
enable PTX and wait for completion.
modify data content and length.
if it is periodic mode, delay 100ms.
return to step 1.
PRX will monitor in a loop, the process is as follows:
If it is oneshot mode, the process is as follows:
enable PRX and wait for completion.
delay 100ms to allow the platform time to log.
return to step 1.
If it is continuous mode, PRX will be continuously enabled, and the process is as follows:
enable PRX without waiting for completion.
delay 100ms to allow the platform time to log.
return to step 2.
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 Interrupt.
TX 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 thenkill_ptx_int
needs to be processed.
PRX will process
rx_int
.If ACK mode is turned on,
tx_int
will also be processed.