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

fix(PeriphDrivers): Fix UART RevB Driver not cleaning up Async Transactions #1334

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Brandon-Hurst
Copy link
Contributor

Description

Currently, the private AsyncTxRequests and AsyncRxRequests arrays are used to track transactions in progress for uart_revb.c. The Tx/Rx Async Callbacks check for a callback function before clearing the Requests:

mxc_uart_req_t *req = (mxc_uart_req_t *)AsyncTxRequests[uart_num];
if ((req != NULL) && (req->callback != NULL)) {
    AsyncTxRequests[uart_num] = NULL;
    req->callback(req, retVal);
}

This means that if the user does not supply an explicit callback function, a transaction never gets cleared, causing problems after just one transaction.

This commit resolves this by moving the cleanup of this important struct outside of the conditional check for a callback function.

mxc_uart_req_t *req = (mxc_uart_req_t *)AsyncTxRequests[uart_num];
if ((req != NULL) && (req->callback != NULL)) {
    req->callback(req, retVal);
}

// Cleanup Async Transaction
AsyncTxRequests[uart_num] = NULL;

Testing

This was tested as part of development for UART functionality in the CircuitPython BUSIO.UART module:
https://github.com/Brandon-Hurst/circuitpython/blob/ports/analog/add-busio/ports/analog/common-hal/busio/UART.c

I found that it was necessary to submit a callback function for the Async API to work correctly. This fix is to correct this, so the user doesn't have to supply a callback to have the Async Requests cleaned up.

Checklist Before Requesting Review

  • PR Title follows correct guidelines.
  • Description of changes and all other relevant information.
  • (Optional) Link any related GitHub issues using a keyword
  • (Optional) Provide info on any relevant functional testing/validation. For API changes or significant features, this is not optional.

Currently, the private AsyncTxRequests and AsyncRxRequests arrays are used to track transactions in progress for uart_revb.c.
The Tx/Rx Async Callbacks check for a callback function before clearing the Requests:

```C
mxc_uart_req_t *req = (mxc_uart_req_t *)AsyncTxRequests[uart_num];
if ((req != NULL) && (req->callback != NULL)) {
    AsyncTxRequests[uart_num] = NULL;
    req->callback(req, retVal);
}
```

This means that if the user does not supply an explicit callback function, a transaction never gets cleared, causing problems after just one transaction.

This commit resolves this by moving the cleanup of this important struct outside of the conditional check for a callback function.

```C
mxc_uart_req_t *req = (mxc_uart_req_t *)AsyncTxRequests[uart_num];
if ((req != NULL) && (req->callback != NULL)) {
    req->callback(req, retVal);
}

// Cleanup Async Transaction
AsyncTxRequests[uart_num] = NULL;
```

Signed-off-by: Brandon Hurst <brandon.hurst@analog.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant