优化:

1.close函数关闭device同时重置device回调函数。
This commit is contained in:
MacRsh
2023-04-25 22:46:19 +08:00
parent c2a2e9f5e9
commit cfa851638c

View File

@@ -114,12 +114,9 @@ mr_err_t mr_device_close(mr_device_t device)
{
MR_ASSERT(device != MR_NULL);
/* If the reference count is zero, the device has already been closed */
if (device->ref_count == 0)
{
device->open_flag = MR_OPEN_CLOSED;
/* Check if the device is already closed */
if (device->open_flag == MR_OPEN_CLOSED)
return MR_ERR_OK;
}
/* Decrement the reference count */
device->ref_count --;
@@ -128,6 +125,11 @@ mr_err_t mr_device_close(mr_device_t device)
if (device->ref_count != 0)
return MR_ERR_OK;
/* Set the device status to closed */
device->open_flag = MR_OPEN_CLOSED;
device->rx_cb = MR_NULL;
device->tx_cb = MR_NULL;
/* Call the device-close function, if provided */
if (device->ops->close == MR_NULL)
return MR_ERR_OK;