yangsong8-a1 opened a new pull request, #21887:
URL: https://github.com/apache/nuttx/pull/21887
## Summary
Add a SiFive PWM lower-half driver (sifive_pwm.c) on top of the generic
drivers/timers/pwm.c upper half.
- start() picks the PWMCFG.SCALE prescaler from the requested frequency
and writes PWMCMP(ch-1) = 0x10000 - duty for each channel, the exact
inverse of the duty = 1 - PWMCMPx/period the device publishes;
- stop() parks the outputs at 0%. The counter runs in its natural 16-bit
wrap mode, so all four compare registers are usable as duty outputs
and the frequency is approximated by SCALE, matching the mainline
Linux pwm-sifive driver;
- register access is local volatile MMIO so the driver builds on
armv8-a, armv8-r and RISC-V.
Works with both the plain u32 and the CONFIG_PWM_FREQUENCY_FIXED
(ub32_t) frequency interface.
## Impact
New driver, no change to existing code. Enabled with
CONFIG_PWM_SIFIVE; the base address comes from the device tree
("sifive,pwm0").
## Testing
Ubuntu 22.04, QEMU 6.2. Builds with no new warnings:
- rv-virt:nsh (rv32) + CONFIG_PWM + CONFIG_PWM_SIFIVE
(riscv64-unknown-elf-gcc 10.2)
- qemu-armv8a:nsh + CONFIG_PWM + CONFIG_PWM_SIFIVE +
CONFIG_PWM_FREQUENCY_FIXED (aarch64-none-elf-gcc 13.2)
QEMU has no SiFive PWM model, so on rv-virt the driver was pointed at
plain guest RAM above the memory NuttX manages, and a test program
read back the registers it programs after each ioctl. The counter
does not run there, so this verifies the programming path, not the
waveform:
- after open (setup): PWMCFG=0, counter=0, PWMCMP0-3=0xffff (idle);
- after START with duties 50/25/100/0 % on channels 1-4:
PWMCMP0-3 = 0x8000 0xc000 0x0000 0xffff and PWMCFG = 0x1000
(ENALWAYS, SCALE=0);
- a frequency above the reference clock is rejected with -EINVAL;
- after STOP: PWMCFG=0, PWMCMP0-3=0xffff (idle).
SIFIVE after START CFG=0x00001000 COUNT=0x00000000 CMP0-3=0x8000 0xc000
0x0000 0xffff
SIFIVE SETCHARACTERISTICS(2x clk) ret=-1 errno=22
SIFIVE after STOP CFG=0x00000000 COUNT=0x00000000 CMP0-3=0xffff 0xffff
0xffff 0xffff
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]