dawsonjon / PicoRX

Build a SDR SW/MW/LW Receiver with a Raspberry Pi Pico
MIT License
223 stars 30 forks source link

usb controls for level/volume and mute now get applied #113

Closed penfold42 closed 10 hours ago

mryndzionek commented 18 hours ago

I think than access to usb_volume and usb_mute might need locking.

penfold42 commented 17 hours ago

I think than access to usb_volume and usb_mute might need locking.

How come ? are usb and rx_dsp on separate cores ?

mryndzionek commented 15 hours ago

I think than access to usb_volume and usb_mute might need locking.

How come ? are usb and rx_dsp on separate cores ?

No, but on_usb_set_mutevol will, most likely, be called from usb_audio_device_task, which is run from an interrupt. on_usb_audio_tx_ready only communicates via a ring buffer, which has locking.

penfold42 commented 14 hours ago

There's only 1 writer/1 reader and they're each less than 32 bit objects. Can i be lazy and mark them volatile?

mryndzionek commented 14 hours ago

There's only 1 writer/1 reader and they're each less than 32 bit objects. Can i be lazy and mark them volatile?

Yes, sure, we can try, should be atomic.

penfold42 commented 14 hours ago

It seemed to work fine and continues to work fine with volatile.

mryndzionek commented 13 hours ago

It seemed to work fine and continues to work fine with volatile.

With concurrency issues it always seems to work fine at the beginning :wink:

penfold42 commented 12 hours ago

If you still want me to add the locking, is this approach IRQ safe ?

sem_acquire_blocking(&usbcontrol_semaphore);
sem_release(&usbcontrol_semaphore);
mryndzionek commented 12 hours ago

If you still want me to add the locking, is this approach IRQ safe ?

sem_acquire_blocking(&usbcontrol_semaphore);
sem_release(&usbcontrol_semaphore);

I think a critical section is appropriate in this case: https://www.raspberrypi.com/documentation/pico-sdk/high_level.html#group_critical_section

penfold42 commented 11 hours ago

Thanks - please have a peek if you have a moment.

mryndzionek commented 11 hours ago

Looks good and works okay on Linux :+1:

dawsonjon commented 10 hours ago

Cheers

penfold42 commented 10 hours ago

oh excellent - thanks for checking that. Does alsamixer behave sensibly?

mryndzionek commented 10 hours ago

oh excellent - thanks for checking that. Does alsamixer behave sensibly?

Yes.