Skip to content

wireless/cc1101: Add standard RF IOCTL support#18472

Merged
acassis merged 1 commit intoapache:masterfrom
AuroraRAS:ioctl1101
Mar 4, 2026
Merged

wireless/cc1101: Add standard RF IOCTL support#18472
acassis merged 1 commit intoapache:masterfrom
AuroraRAS:ioctl1101

Conversation

@AuroraRAS
Copy link
Contributor

Summary

The CC1101 driver previously lacked support for standard NuttX wireless IOCTL commands, preventing runtime configuration of radio parameters by user-space applications.

This change implements the cc1101_file_ioctl function to map abstract WLIOC_* commands to specific CC1101 hardware registers.

  • Radio Frequency (WLIOC_SETRADIOFREQ): Calculates the 24-bit frequency word and applies it to FREQ[2:0], while zeroing CHANNR to prevent offset calculation errors.
  • Address (WLIOC_SETADDR): Maps to the single-byte hardware ADDR register.
  • Output Power (WLIOC_SETTXPOWER): Maps absolute dBm index values to the internal PATABLE via existing cc1101_setpower API.
  • Modulation (WLIOC_SETMODU): Applies bitmasks to MDMCFG2 to support FSK, GFSK, and OOK, while actively rejecting unsupported formats like LoRa with -ENOTSUP.
  • Data Rate (WLIOC_FSK_SETBITRATE): Calculates the required exponent and mantissa, updating MDMCFG4 and MDMCFG3 without overwriting receiver bandwidth configurations.
  • FSK Deviation (WLIOC_FSK_SETFDEV): Computes and applies the frequency deviation exponent and mantissa to the DEVIATN register.

Additionally, this implementation normalizes positive SPI status bytes returned by cc1101_access to OK (0), ensuring POSIX compliance and preventing silent bypasses of subsequent register writes.

Impact

  • Users/API: Exposes dynamic configuration capabilities to user-space applications via standard POSIX ioctl() calls using the <nuttx/wireless/ioctl.h> interface.
  • Hardware: Specific to the CC1101 transceiver.
  • Compatibility: Fully compatible with existing RF IOCTL definitions. Commands not applicable to CC1101 hardware (e.g., LoRa parameters, fine power steps) correctly return -ENOSYS or -ENOTSUP.
  • Build/Security: No impact on the core build process or system security.

Testing

To verify the quantitative accuracy of the mathematical conversions (e.g., Hz to register words, bps to mantissa/exponent) and ensure no regressions, a custom user-space application (ecrf_test) was executed.

Testing was performed on an ESP32 hardware platform interfacing with dual CC1101 modules (/dev/radio0, /dev/radio1) and an nRF24L01 module (/dev/nrf24l01), validating a multi-transceiver architecture similar to the EvilCrowRF-V2 project. The test performs sequential WLIOC_SET* and WLIOC_GET* operations, comparing the targeted integer values against the actual values calculated and read back from the hardware registers.

Runtime Logs:

nsh> ecrf_test
--- EvilCrowRF-V2 Hardware Validation ---

Testing device: /dev/radio0
  [PASS] FD: 3
Starting CC1101 IOCTL hardware test on /dev/radio0...
  [PASS] Frequency: Target 433000000 Hz, Actual 432999816 Hz
  [PASS] Address: Target 0x5A, Actual 0x5A
  [PASS] TX Power Index: Target 2, Actual 2
  [PASS] Modulation: Target 2, Actual 2
  [PASS] Bitrate: Target 250000 bps, Actual 249938 bps
  [PASS] FSK Deviation: Target 47000 Hz, Actual 44433 Hz
CC1101 IOCTL hardware test completed successfully.

Testing device: /dev/radio1
  [PASS] FD: 3
Starting CC1101 IOCTL hardware test on /dev/radio1...
  [PASS] Frequency: Target 433000000 Hz, Actual 432999816 Hz
  [PASS] Address: Target 0x5A, Actual 0x5A
  [PASS] TX Power Index: Target 2, Actual 2
  [PASS] Modulation: Target 2, Actual 2
  [PASS] Bitrate: Target 250000 bps, Actual 249938 bps
  [PASS] FSK Deviation: Target 47000 Hz, Actual 44433 Hz
CC1101 IOCTL hardware test completed successfully.

Testing device: /dev/nrf24l01
  [PASS] FD: 3
Starting nRF24L01 IOCTL tests...
  [PASS] Freq: 2450000000 Hz
  [PASS] TX Power: -6 dBm
  [PASS] Fine TX Power: 0 (0.01 dBm)
  [PASS] Modulation correctly rejected non-GFSK.
  [PASS] Address: AA:BB:CC:DD:EE
  [PASS] Retransmit Config (Delay: 5, Count: 10)
  [PASS] Data Rate: 2Mbps
  [PASS] State Transition to STANDBY
  [PASS] TX Payload NoACK: Enabled
Testing completed. Failures: 0

@github-actions github-actions bot added Area: Drivers Drivers issues Size: M The size of the change in this PR is medium labels Feb 28, 2026
Implement `cc1101_file_ioctl` to map common NuttX wireless IOCTL commands
to CC1101 hardware registers. This allows dynamic configuration of radio
parameters from user-space applications.

* Map `WLIOC_SETRADIOFREQ` and `GETRADIOFREQ` to `FREQ[2:0]`.
* Map `WLIOC_SETADDR` and `GETADDR` to `ADDR`.
* Map `WLIOC_SETTXPOWER` and `GETTXPOWER` to internal PATABLE indexing.
* Map `WLIOC_SETMODU` and `GETMODU` to `MDMCFG2`.
* Map `WLIOC_FSK_SETBITRATE` and `GETBITRATE` to `MDMCFG4` and `MDMCFG3`.
* Map `WLIOC_FSK_SETFDEV` and `GETFDEV` to `DEVIATN`.
* Normalize positive SPI status byte returns from `cc1101_access` to `OK` (0)
  to ensure POSIX compliance and prevent silently skipped register writes.

Signed-off-by: Chip L. <chplee@gmail.com>
@acassis acassis merged commit 440ad13 into apache:master Mar 4, 2026
94 of 151 checks passed
@acassis
Copy link
Contributor

acassis commented Mar 4, 2026

Nice work @AuroraRAS ! Thank you!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Drivers Drivers issues Size: M The size of the change in this PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants