zkkkk12 opened a new pull request, #17708: URL: https://github.com/apache/nuttx/pull/17708
*Note: Please adhere to [Contributing Guidelines](https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md).* ## Summary 1. Original Problem In the `adc_open()` and `adc_close()` functions, the code used critical sections to protect hardware initialization and shutdown operations: `irqstate_t flags = enter_critical_section(); // Hardware operations ... leave_critical_section(flags);` This approach disables interrupts, but in `adc_isr_thread` mode, the ISR actually runs in a thread. Disabling interrupts might: Because it's not a true interrupt context May cause problems or performance degradation Be less flexible than mutexes 2. Benefits of the Modified Version After the modification, hardware operations only rely on existing mutex protection: `ret = nxmutex_lock(&dev->ad_lock); // Hardware operations ... nxmutex_unlock(&dev->ad_lock);` Advantages: Thread safety: Mutexes work correctly in all contexts More precise synchronization: Only protects the critical sections that need protection Better performance: Doesn't blindly disable interrupts More suitable for threaded ISRs: Consistent with the design philosophy of `adc_isr_thread` ## Impact *Update this section, where applicable, on how change affects users, build process, hardware, documentation, security, compatibility, etc.* ## 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. <img width="454" height="204" alt="e0717703-40b9-43ca-88c2-f0a21737e9d9" src="https://github.com/user-attachments/assets/10875d7c-7fd3-4a77-a3f4-82bc053f6264" /> -- 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]
