diff options
| author | CXSforHPU <[email protected]> | 2026-11-07 17:16:10 +0800 |
|---|---|---|
| committer | Rbb666 <[email protected]> | 2026-11-18 09:11:48 +0800 |
| commit | 629a7970ebb0902383db6cbc003e5bc248ff76d6 (patch) | |
| tree | 222a4396ec34b3a15a0e158809f2ddbb469f791c | |
| parent | 265116d74d753d5605546f798a9a8f54c571b22b (diff) | |
[components][dfs]Class-encode RT_DEVICE_CTRL_* commands to fix POSIX/dev command collisions: class in high byte, index low byte.
| -rw-r--r-- | bsp/efm32/drv_acmp.c | 6 | ||||
| -rw-r--r-- | bsp/efm32/drv_adc.c | 6 | ||||
| -rw-r--r-- | bsp/efm32/drv_ethernet.c | 8 | ||||
| -rw-r--r-- | bsp/efm32/drv_iic.c | 8 | ||||
| -rw-r--r-- | bsp/efm32/drv_leuart.c | 8 | ||||
| -rw-r--r-- | bsp/efm32/drv_sdcard.c | 8 | ||||
| -rw-r--r-- | bsp/efm32/drv_timer.c | 8 | ||||
| -rw-r--r-- | bsp/efm32/drv_usart.c | 8 | ||||
| -rw-r--r-- | bsp/hk32/hk32f030c8-mini/rtconfig.py | 2 | ||||
| -rw-r--r-- | components/drivers/include/drivers/dev_pin.h | 2 | ||||
| -rw-r--r-- | components/drivers/include/drivers/dev_serial_v2.h | 11 | ||||
| -rw-r--r-- | components/utilities/rt-link/inc/rtlink_dev.h | 10 | ||||
| -rw-r--r-- | components/utilities/rt-link/src/rtlink_dev.c | 2 | ||||
| -rw-r--r-- | include/rtdef.h | 50 |
14 files changed, 80 insertions, 57 deletions
diff --git a/bsp/efm32/drv_acmp.c b/bsp/efm32/drv_acmp.c index 24a2d1b53e..2809b07f8b 100644 --- a/bsp/efm32/drv_acmp.c +++ b/bsp/efm32/drv_acmp.c @@ -90,9 +90,9 @@ ACMP_WarmTime_TypeDef efm32_acmp_WarmTimeCalc(rt_uint32_t hfperFreq); * Error code ******************************************************************************/ static rt_err_t rt_acmp_control( - rt_device_t dev, - rt_uint8_t cmd, - void *args) + rt_device_t dev, + int cmd, + void *args) { RT_ASSERT(dev != RT_NULL); diff --git a/bsp/efm32/drv_adc.c b/bsp/efm32/drv_adc.c index 1559af1768..37451294e5 100644 --- a/bsp/efm32/drv_adc.c +++ b/bsp/efm32/drv_adc.c @@ -368,9 +368,9 @@ void efm32_adc_on_dma( * Error code ******************************************************************************/ static rt_err_t rt_adc_control( - rt_device_t dev, - rt_uint8_t cmd, - void *args) + rt_device_t dev, + int cmd, + void *args) { RT_ASSERT(dev != RT_NULL); diff --git a/bsp/efm32/drv_ethernet.c b/bsp/efm32/drv_ethernet.c index 7792f20158..a7375548e6 100644 --- a/bsp/efm32/drv_ethernet.c +++ b/bsp/efm32/drv_ethernet.c @@ -669,10 +669,10 @@ static rt_ssize_t efm_eth_write ( * @return * Error code ******************************************************************************/ -static rt_err_t efm_eth_control ( - rt_device_t dev, - rt_uint8_t cmd, - void *args) +static rt_err_t efm_eth_control( + rt_device_t dev, + int cmd, + void *args) { rt_err_t ret; diff --git a/bsp/efm32/drv_iic.c b/bsp/efm32/drv_iic.c index 4bae9ae94a..0654e6637a 100644 --- a/bsp/efm32/drv_iic.c +++ b/bsp/efm32/drv_iic.c @@ -438,10 +438,10 @@ static rt_ssize_t rt_iic_write ( * @return * Error code ******************************************************************************/ -static rt_err_t rt_iic_control ( - rt_device_t dev, - rt_uint8_t cmd, - void *args) +static rt_err_t rt_iic_control( + rt_device_t dev, + int cmd, + void *args) { RT_ASSERT(dev != RT_NULL); diff --git a/bsp/efm32/drv_leuart.c b/bsp/efm32/drv_leuart.c index 8534f4b194..11ac9e765c 100644 --- a/bsp/efm32/drv_leuart.c +++ b/bsp/efm32/drv_leuart.c @@ -505,10 +505,10 @@ static rt_ssize_t rt_leuart_write ( * @return * Error code ******************************************************************************/ -static rt_err_t rt_leuart_control ( - rt_device_t dev, - rt_uint8_t cmd, - void *args) +static rt_err_t rt_leuart_control( + rt_device_t dev, + int cmd, + void *args) { RT_ASSERT(dev != RT_NULL); diff --git a/bsp/efm32/drv_sdcard.c b/bsp/efm32/drv_sdcard.c index 7cb55367e9..2a48db2529 100644 --- a/bsp/efm32/drv_sdcard.c +++ b/bsp/efm32/drv_sdcard.c @@ -990,10 +990,10 @@ static rt_ssize_t rt_spiSd_write ( * @return * Error code ******************************************************************************/ -static rt_err_t rt_spiSd_control ( - rt_device_t dev, - rt_uint8_t ctrl, - void *buffer) +static rt_err_t rt_spiSd_control( + rt_device_t dev, + int ctrl, + void *buffer) { rt_err_t ret; rt_uint32_t c_size; diff --git a/bsp/efm32/drv_timer.c b/bsp/efm32/drv_timer.c index 9f63063227..b4599d6646 100644 --- a/bsp/efm32/drv_timer.c +++ b/bsp/efm32/drv_timer.c @@ -91,10 +91,10 @@ * @return * Error code ******************************************************************************/ -static rt_err_t rt_hs_timer_control ( - rt_device_t dev, - rt_uint8_t cmd, - void *args) +static rt_err_t rt_hs_timer_control( + rt_device_t dev, + int cmd, + void *args) { RT_ASSERT(dev != RT_NULL); diff --git a/bsp/efm32/drv_usart.c b/bsp/efm32/drv_usart.c index e12b1c3da9..bc77dbb824 100644 --- a/bsp/efm32/drv_usart.c +++ b/bsp/efm32/drv_usart.c @@ -746,10 +746,10 @@ static rt_ssize_t rt_usart_write ( * @return * Error code ******************************************************************************/ -static rt_err_t rt_usart_control ( - rt_device_t dev, - rt_uint8_t cmd, - void *args) +static rt_err_t rt_usart_control( + rt_device_t dev, + int cmd, + void *args) { RT_ASSERT(dev != RT_NULL); diff --git a/bsp/hk32/hk32f030c8-mini/rtconfig.py b/bsp/hk32/hk32f030c8-mini/rtconfig.py index d6e1b750b0..932e28dd8c 100644 --- a/bsp/hk32/hk32f030c8-mini/rtconfig.py +++ b/bsp/hk32/hk32f030c8-mini/rtconfig.py @@ -52,7 +52,7 @@ if PLATFORM == 'gcc': LPATH = '' if BUILD == 'debug': - CFLAGS += ' -O0 -gdwarf-2 -g' + CFLAGS += ' -Og -gdwarf-2 -g' AFLAGS += ' -gdwarf-2' else: CFLAGS += ' -O2' diff --git a/components/drivers/include/drivers/dev_pin.h b/components/drivers/include/drivers/dev_pin.h index 2039870983..7155ef0624 100644 --- a/components/drivers/include/drivers/dev_pin.h +++ b/components/drivers/include/drivers/dev_pin.h @@ -122,7 +122,7 @@ struct rt_device_pin #ifdef RT_USING_PINCTRL enum { - PIN_CONFIG_BIAS_BUS_HOLD, + PIN_CONFIG_BIAS_BUS_HOLD = RT_DEVICE_CTRL_BASE(Pin) + 1, PIN_CONFIG_BIAS_DISABLE, PIN_CONFIG_BIAS_HIGH_IMPEDANCE, PIN_CONFIG_BIAS_PULL_DOWN, diff --git a/components/drivers/include/drivers/dev_serial_v2.h b/components/drivers/include/drivers/dev_serial_v2.h index 2a8d9145e6..daa1a0ef58 100644 --- a/components/drivers/include/drivers/dev_serial_v2.h +++ b/components/drivers/include/drivers/dev_serial_v2.h @@ -186,10 +186,15 @@ /** * hw serial control commands + * + * The 0x40-0x4f index range is reserved for hardware serial controls. */ -#define RT_HW_SERIAL_CTRL_GETC 0x01 /* Tx irq get char */ -#define RT_HW_SERIAL_CTRL_PUTC 0x02 /* Rx irq put char */ -#define RT_HW_SERIAL_CTRL_GET_DMA_PING_BUF 0x03 /* Get DMA ping-pong buffer */ +typedef enum rt_hw_serial_ctrl_cmd +{ + RT_HW_SERIAL_CTRL_GETC = RT_DEVICE_CTRL_BASE(Char) + 0x40, /* Tx irq get char */ + RT_HW_SERIAL_CTRL_PUTC, /* Rx irq put char */ + RT_HW_SERIAL_CTRL_GET_DMA_PING_BUF, /* Get DMA ping-pong buffer */ +} rt_hw_serial_ctrl_cmd_t; /** * hw isr event diff --git a/components/utilities/rt-link/inc/rtlink_dev.h b/components/utilities/rt-link/inc/rtlink_dev.h index 01fd04373c..0445e4d868 100644 --- a/components/utilities/rt-link/inc/rtlink_dev.h +++ b/components/utilities/rt-link/inc/rtlink_dev.h @@ -11,11 +11,11 @@ #include <rtthread.h> #include <rtlink.h> -#define RT_LINK_RX_NONBLOCKING 0x1000 -#define RT_LINK_RX_BLOCKING 0x2000 -#define RT_LINK_TX_NONBLOCKING 0x4000 -#define RT_LINK_TX_BLOCKING 0x8000 -#define RT_LINK_DEVICE_MASK 0xf000 +#define RT_LINK_RX_NONBLOCKING 0x01000000 +#define RT_LINK_RX_BLOCKING 0x02000000 +#define RT_LINK_TX_NONBLOCKING 0x04000000 +#define RT_LINK_TX_BLOCKING 0x08000000 +#define RT_LINK_DEVICE_MASK 0x0f000000 struct rtlink_recv_list { diff --git a/components/utilities/rt-link/src/rtlink_dev.c b/components/utilities/rt-link/src/rtlink_dev.c index b4f1add678..b130b27927 100644 --- a/components/utilities/rt-link/src/rtlink_dev.c +++ b/components/utilities/rt-link/src/rtlink_dev.c @@ -320,7 +320,7 @@ rt_err_t rt_link_dev_control(rt_device_t dev, int cmd, void *args) { RT_ASSERT(dev != RT_NULL); - if (cmd & RT_DEVICE_CTRL_CONFIG) + if ((cmd & ~RT_LINK_DEVICE_MASK) == RT_DEVICE_CTRL_CONFIG) { if (args == RT_NULL) return -RT_EINVAL; diff --git a/include/rtdef.h b/include/rtdef.h index 5e243a9766..d2cda86508 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -63,6 +63,7 @@ * 2025-11-10 Rbb666 update version number to v5.3.0 * 2026-09-10 CYFS update version number to v5.3.1 * 2026-10-17 Rbb666 update version number to v5.4.0 + * 2026-11-07 CXSforHPU class-encode RT_DEVICE_CTRL_* commands */ #ifndef __RT_DEF_H__ @@ -1316,26 +1317,43 @@ enum rt_device_class_type #define RT_DEVICE_OFLAG_MASK 0xf0f /**< mask of open flag */ /** - * general device commands - * 0x01 - 0x1F general device control commands - * 0x20 - 0x3F udevice control commands - * 0x40 - special device control commands + * device control base command */ -#define RT_DEVICE_CTRL_RESUME 0x01 /**< resume device */ -#define RT_DEVICE_CTRL_SUSPEND 0x02 /**< suspend device */ -#define RT_DEVICE_CTRL_CONFIG 0x03 /**< configure device */ -#define RT_DEVICE_CTRL_CLOSE 0x04 /**< close device */ -#define RT_DEVICE_CTRL_NOTIFY_SET 0x05 /**< set notify func */ -#define RT_DEVICE_CTRL_SET_INT 0x06 /**< set interrupt */ -#define RT_DEVICE_CTRL_CLR_INT 0x07 /**< clear interrupt */ -#define RT_DEVICE_CTRL_GET_INT 0x08 /**< get interrupt status */ -#define RT_DEVICE_CTRL_CONSOLE_OFLAG 0x09 /**< get console open flag */ -#define RT_DEVICE_CTRL_MASK 0x1f /**< mask for contrl commands */ +#define RT_DEVICE_CTRL_BASE(Type) ((RT_Device_Class_##Type + 1) * 0x100) +#define RT_DEVICE_CTRL_CLASS_MASK 0xff00 /* High byte: class */ +#define RT_DEVICE_CTRL_INDEX_MASK 0x00ff /* Low byte: index within class */ /** - * device control + * device control commands + * + * Layout: + * \code{.c} + * RT_DEVICE_CTRL_BASE(Type) = (RT_Device_Class_##Type + 1) * 0x100 + * \endcode + * high byte : class id (RT_DEVICE_CTRL_CLASS_MASK = 0xff00) + * low byte : index within class (RT_DEVICE_CTRL_INDEX_MASK = 0x00ff) + * + * The general-purpose commands below live in the Unknown class + * (Class_Unknown is the last entry in rt_device_class_t, so + * BASE(Unknown) = 0x2000), giving RESUME = 0x2001 .. CONSOLE_OFLAG = 0x2009. + * Class-specific commands should use BASE(Char), BASE(Block), ... instead + * of reusing these indices. + * 0x01 - 0x1F general device control commands + * 0x20 - 0x3F udevice control commands + * 0x40 - special device control commands */ -#define RT_DEVICE_CTRL_BASE(Type) ((RT_Device_Class_##Type + 1) * 0x100) +typedef enum +{ + RT_DEVICE_CTRL_RESUME = RT_DEVICE_CTRL_BASE(Unknown) + 1, /**< resume device */ + RT_DEVICE_CTRL_SUSPEND, /**< suspend device */ + RT_DEVICE_CTRL_CONFIG, /**< configure device */ + RT_DEVICE_CTRL_CLOSE, /**< close device */ + RT_DEVICE_CTRL_NOTIFY_SET, /**< set notify func */ + RT_DEVICE_CTRL_SET_INT, /**< set interrupt */ + RT_DEVICE_CTRL_CLR_INT, /**< clear interrupt */ + RT_DEVICE_CTRL_GET_INT, /**< get interrupt status */ + RT_DEVICE_CTRL_CONSOLE_OFLAG, /**< get console open flag */ +} rt_device_cmd_t; typedef struct rt_driver *rt_driver_t; typedef struct rt_device *rt_device_t; |
