1.优化设备命令。

This commit is contained in:
MacRsh
2023-11-29 15:16:37 +08:00
parent 68df69b294
commit 7bf435b6bd
11 changed files with 79 additions and 65 deletions

View File

@@ -200,6 +200,42 @@ struct mr_dev;
#define MR_SYNC (0) /**< Synchronous */
#define MR_ASYNC (1) /**< Asynchronous */
/**
* @brief Magic number.
*/
#define MR_MAGIC_NUMBER (0xdeadbeef)
/**
* @brief Lock flags.
*/
#define MR_LFLAG_RD ((0x01) << 24) /**< Read lock */
#define MR_LFLAG_WR ((0x02) << 24) /**< Write lock */
#define MR_LFLAG_RDWR ((0x03) << 24) /**< Read/write lock */
#define MR_LFLAG_NONBLOCK ((0x04) << 24) /**< Non-blocking lock */
#define MR_LFLAG_SLEEP ((0x08) << 24) /**< Sleep lock */
/**
* @brief Open flags.
*/
#define MR_OFLAG_CLOSED (0) /**< Closed */
#define MR_OFLAG_RDONLY ((0x01) << 24) /**< Read only */
#define MR_OFLAG_WRONLY ((0x02) << 24) /**< Write only */
#define MR_OFLAG_RDWR ((0x03) << 24) /**< Read/write */
#define MR_OFLAG_NONBLOCK ((0x04) << 24) /**< Non-blocking */
#define MR_OFLAG_DMA ((0x08) << 24) /**< DMA */
/**
* @brief Support flags.
*/
#define MR_SFLAG_NONRDWR MR_OFLAG_CLOSED /**< Non-read/write */
#define MR_SFLAG_RDONLY MR_OFLAG_RDONLY /**< Read only */
#define MR_SFLAG_WRONLY MR_OFLAG_WRONLY /**< Write only */
#define MR_SFLAG_RDWR MR_OFLAG_RDWR /**< Read/write */
#define MR_SFLAG_NONBLOCK MR_OFLAG_NONBLOCK /**< Non-blocking */
#define MR_SFLAG_DMA MR_OFLAG_DMA /**< DMA */
#define MR_SFLAG_NONDRV ((0x10) << 24) /**< Non-driver */
#define MR_SFLAG_ONLY ((0x20) << 24) /**< Only */
/**
* @brief Descriptor control command.
*/
@@ -241,42 +277,6 @@ struct mr_dev_ops
ssize_t (*isr)(struct mr_dev *dev, int event, void *args);
};
/**
* @brief Magic number.
*/
#define MR_MAGIC_NUMBER (0xdeadbeef)
/**
* @brief Lock flags.
*/
#define MR_LFLAG_RD ((0x01) << 24) /**< Read lock */
#define MR_LFLAG_WR ((0x02) << 24) /**< Write lock */
#define MR_LFLAG_RDWR ((0x03) << 24) /**< Read/write lock */
#define MR_LFLAG_NONBLOCK ((0x04) << 24) /**< Non-blocking lock */
#define MR_LFLAG_SLEEP ((0x08) << 24) /**< Sleep lock */
/**
* @brief Open flags.
*/
#define MR_OFLAG_CLOSED (0) /**< Closed */
#define MR_OFLAG_RDONLY ((0x01) << 24) /**< Read only */
#define MR_OFLAG_WRONLY ((0x02) << 24) /**< Write only */
#define MR_OFLAG_RDWR ((0x03) << 24) /**< Read/write */
#define MR_OFLAG_NONBLOCK ((0x04) << 24) /**< Non-blocking */
#define MR_OFLAG_DMA ((0x08) << 24) /**< DMA */
/**
* @brief Support flags.
*/
#define MR_SFLAG_NONRDWR MR_OFLAG_CLOSED /**< Non-read/write */
#define MR_SFLAG_RDONLY MR_OFLAG_RDONLY /**< Read only */
#define MR_SFLAG_WRONLY MR_OFLAG_WRONLY /**< Write only */
#define MR_SFLAG_RDWR MR_OFLAG_RDWR /**< Read/write */
#define MR_SFLAG_NONBLOCK MR_OFLAG_NONBLOCK /**< Non-blocking */
#define MR_SFLAG_DMA MR_OFLAG_DMA /**< DMA */
#define MR_SFLAG_NONDRV ((0x10) << 24) /**< Non-driver */
#define MR_SFLAG_ONLY ((0x20) << 24) /**< Only */
/**
* @brief Device structure.
*/

View File

@@ -127,6 +127,14 @@ extern "C" {
*/
#define mr_min(a, b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a < _b ? _a : _b; })
/**
* @brief This macro function swaps two values.
*
* @param a The first value.
* @param b The second value.
*/
#define mr_swap(a, b) (a ^= b, b ^= a, a ^= b)
/**
* @brief This macro function aligns the size up to a multiple of 4.
*