summaryrefslogtreecommitdiff
path: root/src/device.c
diff options
context:
space:
mode:
authorguo <[email protected]>2021-09-28 10:36:54 +0800
committerGitHub <[email protected]>2021-09-28 10:36:54 +0800
commit55a302cd092758a44b589d65470a69d9e8ae4ced (patch)
treee60fc53994c426007e9eb4877e5bd123f124ef39 /src/device.c
parent00727d6b6db92dc1cf98f028f26fd6168594b905 (diff)
parent00d42ef73cff61ecda7ff006b077a73e1a4ff669 (diff)
Merge branch 'master' into usbh_construct
Diffstat (limited to 'src/device.c')
-rw-r--r--src/device.c136
1 files changed, 69 insertions, 67 deletions
diff --git a/src/device.c b/src/device.c
index a4f004fb69..6e22c2b692 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -12,12 +12,13 @@
* 2012-12-25 Bernard return RT_EOK if the device interface not exist.
* 2013-07-09 Grissiom add ref_count support
* 2016-04-02 Bernard fix the open_flag initialization issue.
+ * 2021-03-19 Meco Man remove rt_device_init_all()
*/
#include <rtthread.h>
-#if defined(RT_USING_POSIX)
+#ifdef RT_USING_POSIX
#include <rtdevice.h> /* for wqueue_init */
-#endif
+#endif /* RT_USING_POSIX */
#ifdef RT_USING_DEVICE
@@ -35,14 +36,16 @@
#define device_read (dev->read)
#define device_write (dev->write)
#define device_control (dev->control)
-#endif
+#endif /* RT_USING_DEVICE_OPS */
/**
- * This function registers a device driver with specified name.
+ * @brief This function registers a device driver with a specified name.
*
- * @param dev the pointer of device driver structure
- * @param name the device driver's name
- * @param flags the capabilities flag of device
+ * @param dev is the pointer of device driver structure.
+ *
+ * @param name is the device driver's name.
+ *
+ * @param flags is the capabilities flag of device.
*
* @return the error code, RT_EOK on initialization successfully.
*/
@@ -61,19 +64,19 @@ rt_err_t rt_device_register(rt_device_t dev,
dev->ref_count = 0;
dev->open_flag = 0;
-#if defined(RT_USING_POSIX)
+#ifdef RT_USING_POSIX
dev->fops = RT_NULL;
rt_wqueue_init(&(dev->wait_queue));
-#endif
+#endif /* RT_USING_POSIX */
return RT_EOK;
}
RTM_EXPORT(rt_device_register);
/**
- * This function removes a previously registered device driver
+ * @brief This function removes a previously registered device driver.
*
- * @param dev the pointer of device driver structure
+ * @param dev is the pointer of device driver structure.
*
* @return the error code, RT_EOK on successfully.
*/
@@ -90,22 +93,9 @@ rt_err_t rt_device_unregister(rt_device_t dev)
RTM_EXPORT(rt_device_unregister);
/**
- * This function initializes all registered device driver
- *
- * @return the error code, RT_EOK on successfully.
- *
- * @deprecated since 1.2.x, this function is not needed because the initialization
- * of a device is performed when application opens it.
- */
-rt_err_t rt_device_init_all(void)
-{
- return RT_EOK;
-}
-
-/**
- * This function finds a device driver by specified name.
+ * @brief This function finds a device driver by specified name.
*
- * @param name the device driver's name
+ * @param name is the device driver's name.
*
* @return the registered device driver on successful, or RT_NULL on failure.
*/
@@ -117,10 +107,11 @@ RTM_EXPORT(rt_device_find);
#ifdef RT_USING_HEAP
/**
- * This function creates a device object with user data size.
+ * @brief This function creates a device object with user data size.
+ *
+ * @param type is the type of the device object.
*
- * @param type, the kind type of this device object.
- * @param attach_size, the size of user data.
+ * @param attach_size is the size of user data.
*
* @return the allocated device object, or RT_NULL when failed.
*/
@@ -146,9 +137,9 @@ rt_device_t rt_device_create(int type, int attach_size)
RTM_EXPORT(rt_device_create);
/**
- * This function destroy the specific device object.
+ * @brief This function destroy the specific device object.
*
- * @param dev, the specific device object.
+ * @param dev is a specific device object.
*/
void rt_device_destroy(rt_device_t dev)
{
@@ -162,14 +153,14 @@ void rt_device_destroy(rt_device_t dev)
rt_free(dev);
}
RTM_EXPORT(rt_device_destroy);
-#endif
+#endif /* RT_USING_HEAP */
/**
- * This function will initialize the specified device
+ * @brief This function will initialize the specified device.
*
- * @param dev the pointer of device driver structure
+ * @param dev is the pointer of device driver structure.
*
- * @return the result
+ * @return the result, RT_EOK on successfully.
*/
rt_err_t rt_device_init(rt_device_t dev)
{
@@ -199,12 +190,13 @@ rt_err_t rt_device_init(rt_device_t dev)
}
/**
- * This function will open a device
+ * @brief This function will open a device.
*
- * @param dev the pointer of device driver structure
- * @param oflag the flags for device open
+ * @param dev is the pointer of device driver structure.
*
- * @return the result
+ * @param oflag is the flags for device open.
+ *
+ * @return the result, RT_EOK on successfully.
*/
rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag)
{
@@ -265,11 +257,11 @@ rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag)
RTM_EXPORT(rt_device_open);
/**
- * This function will close a device
+ * @brief This function will close a device.
*
- * @param dev the pointer of device driver structure
+ * @param dev is the pointer of device driver structure.
*
- * @return the result
+ * @return the result, RT_EOK on successfully.
*/
rt_err_t rt_device_close(rt_device_t dev)
{
@@ -301,12 +293,15 @@ rt_err_t rt_device_close(rt_device_t dev)
RTM_EXPORT(rt_device_close);
/**
- * This function will read some data from a device.
+ * @brief This function will read some data from a device.
+ *
+ * @param dev is the pointer of device driver structure.
+ *
+ * @param pos is the position when reading.
*
- * @param dev the pointer of device driver structure
- * @param pos the position of reading
- * @param buffer the data buffer to save read data
- * @param size the size of buffer
+ * @param buffer is a data buffer to save the read data.
+ *
+ * @param size is the size of buffer.
*
* @return the actually read size on successful, otherwise negative returned.
*
@@ -340,12 +335,15 @@ rt_size_t rt_device_read(rt_device_t dev,
RTM_EXPORT(rt_device_read);
/**
- * This function will write some data to a device.
+ * @brief This function will write some data to a device.
+ *
+ * @param dev is the pointer of device driver structure.
+ *
+ * @param pos is the position when writing.
*
- * @param dev the pointer of device driver structure
- * @param pos the position of written
- * @param buffer the data buffer to be written to device
- * @param size the size of buffer
+ * @param buffer is the data buffer to be written to device.
+ *
+ * @param size is the size of buffer.
*
* @return the actually written size on successful, otherwise negative returned.
*
@@ -379,13 +377,15 @@ rt_size_t rt_device_write(rt_device_t dev,
RTM_EXPORT(rt_device_write);
/**
- * This function will perform a variety of control functions on devices.
+ * @brief This function will perform a variety of control functions on devices.
+ *
+ * @param dev is the pointer of device driver structure.
+ *
+ * @param cmd is the command sent to device.
*
- * @param dev the pointer of device driver structure
- * @param cmd the command sent to device
- * @param arg the argument of command
+ * @param arg is the argument of command.
*
- * @return the result
+ * @return the result, -RT_ENOSYS for failed.
*/
rt_err_t rt_device_control(rt_device_t dev, int cmd, void *arg)
{
@@ -403,11 +403,12 @@ rt_err_t rt_device_control(rt_device_t dev, int cmd, void *arg)
RTM_EXPORT(rt_device_control);
/**
- * This function will set the reception indication callback function. This callback function
- * is invoked when this device receives data.
+ * @brief This function will set the reception indication callback function. This callback function
+ * is invoked when this device receives data.
*
- * @param dev the pointer of device driver structure
- * @param rx_ind the indication callback function
+ * @param dev is the pointer of device driver structure.
+ *
+ * @param rx_ind is the indication callback function.
*
* @return RT_EOK
*/
@@ -425,11 +426,12 @@ rt_device_set_rx_indicate(rt_device_t dev,
RTM_EXPORT(rt_device_set_rx_indicate);
/**
- * This function will set the indication callback function when device has
- * written data to physical hardware.
+ * @brief This function will set a callback function. The callback function
+ * will be called when device has written data to physical hardware.
+ *
+ * @param dev is the pointer of device driver structure.
*
- * @param dev the pointer of device driver structure
- * @param tx_done the indication callback function
+ * @param tx_done is the indication callback function.
*
* @return RT_EOK
*/
@@ -446,4 +448,4 @@ rt_device_set_tx_complete(rt_device_t dev,
}
RTM_EXPORT(rt_device_set_tx_complete);
-#endif
+#endif /* RT_USING_DEVICE */