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 |
---|---|
RTL8752H HDK |
RTL8752H EVB |
For more requirements, please refer to Quick Start.
Wiring
Please refer to RTL8752H EVB Interfaces and Modules in Quick Start.
Configurations
All the content that needs to be configured in APP is in src\app\ppt_simple_trx\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:
board\evb\ppt_simple_ptx\mdk
board\evb\ppt_simple_prx\mdk
Project file:
board\evb\ppt_simple_ptx\gcc
board\evb\ppt_simple_ptx\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 Initialization introduces the initialization flow of the chip.
Chapter PTX/PRX Flow introduces radio initialization and running process.
Source Code Directory
Project directory:
board\evb\ppt_simple_ptx
Source code directory:
src\app\ppt_simple_trx
Source files in the application project are currently categorized into several groups as below.
└── Project: ptx(prx)
└── secure_only_app
├── cmsis includes startup code
├── Lib includes all binary symbol files that user application is built on
├── ROM_NS.lib
├── lowerstack.lib
└── rtl8752h_sdk.lib
├── 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
└── APP includes the ble_peripheral user application implementation
├── overlay_mgr.c includes image section management
├── 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)
{
extern uint32_t random_seed_value;
srand(random_seed_value);
board_init();
pwr_mgr_init();
task_init();
os_sched_start();
return 0;
}
board_init()
initializes the IO modules.pwr_mgr_init()
initializes the DLPS power management module.task_init()
initializes 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()
.
void app_main_task(void *p_param)
{
/* avoid conflict with ble psd procedure */
os_delay(1000);
while (1)
{
void ppt_demo(void);
ppt_demo();
}
}
PTX/PRX Flow
ppt_demo()
will initialize and configure the radio, then start the 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.PTX and PRX mode configuration, header settings
ppt_set_tx_header()
, and prepare the data to be sentppt_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.
/* * 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.