Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not checking for ESP_FAIL in AsyncCanDriver::transmit #350

Closed
leonardodanelutti opened this issue Dec 4, 2023 · 5 comments
Closed

Not checking for ESP_FAIL in AsyncCanDriver::transmit #350

leonardodanelutti opened this issue Dec 4, 2023 · 5 comments

Comments

@leonardodanelutti
Copy link

For non-blocking implementations of the embedded-hal the ESP_FAIL error is treated as WouldBlock, shouldn't the same be done for the async function implementation?

pub async fn transmit(&self, frame: &Frame) -> Result<(), EspError> {
    loop {
        let res = self.driver.borrow().transmit(frame, delay::NON_BLOCK);

        match res {
            Ok(()) => return Ok(()),
            Err(e) if e.code() != ESP_ERR_TIMEOUT => return Err(e),
            _ => (),
        }

        WRITE_NOTIFICATION.wait().await;
    }
}
@ivmarkov
Copy link
Collaborator

ivmarkov commented Dec 8, 2023

No idea without digging (again) into the ESP IDF C source code of the TWAI driver...

@ivmarkov
Copy link
Collaborator

ivmarkov commented Dec 8, 2023

@leonardodanelutti The way I read the code (I might be wrong) is that ESP_FAIL would only be returned if you are creating the driver without a TX queue (i.e. tx_queue_len == 0)

Can you confirm if you are doing that?

@leonardodanelutti
Copy link
Author

@ivmarkov I actually didn't get that error, I was looking at the async implementation for the CanDriver and it seemed strange that the ESP_FAIL error wasn't also checked. Yes, I think you are right, as it is also written in the documentation, ESP_FAIL is returned only if the TX queue is disabled and another message is transmitting at that moment. When that error occurs, I don't think the function should return, right?

@ivmarkov
Copy link
Collaborator

ivmarkov commented Dec 9, 2023

Yes I'll patch the driver shortly.

ivmarkov added a commit that referenced this issue Dec 21, 2023
@ivmarkov
Copy link
Collaborator

f958b77

@github-project-automation github-project-automation bot moved this from Todo to Done in esp-rs Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

2 participants