drivers/adc: Use mutexlock to replace critical section protection #17764
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Use mutexlock to replace critical section protection when using adc_isr_thread
Note: Please adhere to Contributing Guidelines.
Summary
The modification replaces critical section protection with mutex locks in ADC driver functions when CONFIG_ADC_ISR_THREAD is enabled, ensuring thread-safe hardware operations without unnecessarily disabling interrupts.
Impact
Benefits:
Reduced Interrupt Latency: Interrupts remain enabled during hardware operations
Better System Throughput: Other interrupts can still be serviced
Improved Real-time Performance: Shorter critical sections mean better determinism
Testing
The ADC function was tested and verified to be working correctly using NuttX's built-in adc_drivers.(apps/examples/adc)
Test Results:
Test results: When you input adc -p in the nsh terminal, the pin corresponding to channel adc0 is shown below.
[core2] adc -p
[core2] adc_main:g_adcstate.count: 3
[core2] adc_main: Hardware initialized. Opening the ADC device: /dev/adc0
[core2] Sample:
[core2] 1: channel: 32 value: 986
[core2] 2: channel: 34 value: 933