Implement pwm_get_mask_enabled #3046
No reviewers
Labels
No labels
bazel
bluetooth
board settings
boot_stage2
bug
build
c++
can't reproduce
clang
clib-interface
cmsis
code cleanliness
code size
compiler version issues
cyw43_driver
debug
discussion
documentation
duplicate
dynamic_clock
elf2uf2
enhancement
errata
filesystem
flash layout
floating point
FreeRTOS
hardware_adc
hardware_claim
hardware_clocks
hardware_dma
hardware_exception
hardware_flash
hardware_gpio
hardware_i2c
hardware_irq
hardware_pio
hardware_pwm
hardware_rcp
hardware_rtc
hardware_spi
hardware_sync
hardware_uart
hardware_vreg
hardware_watchdog
hardware_xosc
help wanted
host
IAR
installation
invalid
linker scripts
lto
lwip
mbedtls
missing API
needs reporter detail
networking
newlib
newlib-multicore
non-c
non-cmake
non-gcc
openocd
orphan PR
OS integration
pico_async_context
pico_base
pico_binary_info
pico_flash
picolibc
pico_lwip
pico_malloc
pico_multicore
pico_printf
pico_runtime
pico_stdio
pico_stdio_usb
pico_sync
pico_time
pico_util
pioasm
port
question
review
review2
rtos interop
runtime init
static library
svd
test
tinyusb
vscode
wifi integration
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-raspberrypi/pico-sdk!3046
Loading…
Reference in a new issue
No description provided.
Delete branch "sprickett/pwm_get_mask_enabled"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes #3045, pwm_set_mask_enabled missing complementary pwm_get_mask_enabled
It also addresses a small typo in pwm_set_mask_enabled comments, Bitmap --> Bitmask
@ -564,2 +564,4 @@}/** \brief Get PWM slice enabled status* \ingroup hardware_pwmor Get PWM enabled slice status?
That's not a typo. Bitmap is a correct term to use here. I'd even argue bitmask is incorrect because it's not masking anything.
What's the use case for this? Any combination of
get()+set()is a read-modify-write which causes a data race with concurrent writers. The correct way to modify the register is something like:...which is fairly straightforward and doesn't have the same failure modes.
@Wren6991 Thanks for commenting.
I don't have much skin in the game here. To argue my case...
Regarding
pwm_get_mask_enabled(void)I was addressing what i saw as an asymmetry with
pwm_set_mask_enabled(uint32_t mask)which is implemented simply aspwm_hw->en = mask;It would seem from your comment that this should maybe be implemented as
hw_set_bits(&pwm_hw->en, mask);?Regardless it still does not solve the conundrum I was facing when implementing logic that utilised multiple pwm pins.
I wanted logic that was reusable and self contained.
pwm_set_mask_enabled(uint32_t mask)offers an attractive way to toggle all the associated slices in one go. This does not work when there is some other self contained logic that is using pwm because one disables the other. The initial solution was to readpwm_hw->endirectly. This felt a bit wrong so I proposed this getter. This getter also would allow the logic to assert a slice conflict.Regarding concurrency. I might have the wrong idea of some fundamentals here. Its great that the SDK provides functions that handle concurrent writes but for a simple use case utilising one core is there any concurrency to guard against?
Ultimately I used
pwm_set_enabled(uint slice_num, bool enabled)on each of the slices individually. I used a mask to keep track of which slices had already been enabled by other pins in the set. I have also since noted that this function enables/disables a slice using different register addresses topwm_set_mask_enabled(uint32_t mask).Regarding Bitmap vs Bitmask, to me they both describe an integral type with zero or more bits set.
They are both used throughout the SDK interchangeably. Bitmask heavily outweighs Bitmap.
pwm.hhas eight instances of Bitmask and one instance of BitmapOverall there are roughly 144 instances of Bitmask to 13 instances of Bitmap
There is only one instance of "Bitmap" exact.
The suggested change was for more for consistency with the SDK as a whole than to say it is wrong.
Happy to close if you feel this is not well reasoned.
@Wren6991 See my comment in the associated issue.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.