串口的中断回调函数第一个参数是 rt_device_t dev,定义如下
struct rt_device
{
struct rt_object parent; /**< inherit from rt_object */
enum rt_device_class_type type; /**< device type */
rt_uint16_t flag; /**< device flag */
rt_uint16_t open_flag; /**< device open flag */
rt_uint8_t ref_count; /**< reference count */
rt_uint8_t device_id; /**< 0 - 255 */
/* device call back */
rt_err_t (*rx_indicate)(rt_device_t dev, rt_size_t size);
rt_err_t (*tx_complete)(rt_device_t dev, void *buffer);
#ifdef RT_USING_DEVICE_OPS
const struct rt_device_ops *ops;
#else
/* common device interface */
rt_err_t (*init) (rt_device_t dev);
rt_err_t (*open) (rt_device_t dev, rt_uint16_t oflag);
rt_err_t (*close) (rt_device_t dev);
rt_size_t (*read) (rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size);
rt_size_t (*write) (rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size);
rt_err_t (*control)(rt_device_t dev, int cmd, void *args);
#endif
#if defined(RT_USING_POSIX)
const struct dfs_file_ops *fops;
struct rt_wqueue wait_queue;
#endif
void *user_data; /**< device private data */
};
struct rt_object
{
char name[RT_NAME_MAX]; /**< name of kernel object */
rt_uint8_t type; /**< type of kernel object */
rt_uint8_t flag; /**< flag of kernel object */
#ifdef RT_USING_MODULE
void *module_id; /**< id of application module */
#endif
rt_list_t list; /**< list node of kernel object */
};
typedef struct rt_object *rt_object_t; /**< Type for kernel objects. */
在串口驱动注册时,每个串口的名字是不一样的,可以用 dev->parent->name 来进行区分。串口设备的名字在文件 drivers/include/config/uart_config.h 中定义。
#ifndef UART1_CONFIG
#define UART1_CONFIG
{
.name = "uart1",
.Instance = USART1,
.irq_type = USART1_IRQn,
.tx_pin_name = BSP_UART1_TX_PIN,
.rx_pin_name = BSP_UART1_RX_PIN,
}
#endif /* UART1_CONFIG */
#ifndef UART2_CONFIG
#define UART2_CONFIG
{
.name = "uart2",
.Instance = USART2,
.irq_type = USART2_IRQn,
.tx_pin_name = BSP_UART2_TX_PIN,
.rx_pin_name = BSP_UART2_RX_PIN,
}
#endif /* UART2_CONFIG */
串口的中断回调函数第一个参数是 rt_device_t dev,定义如下
struct rt_device
{
struct rt_object parent; /**< inherit from rt_object */
enum rt_device_class_type type; /**< device type */
rt_uint16_t flag; /**< device flag */
rt_uint16_t open_flag; /**< device open flag */
rt_uint8_t ref_count; /**< reference count */
rt_uint8_t device_id; /**< 0 - 255 */
/* device call back */
rt_err_t (*rx_indicate)(rt_device_t dev, rt_size_t size);
rt_err_t (*tx_complete)(rt_device_t dev, void *buffer);
#ifdef RT_USING_DEVICE_OPS
const struct rt_device_ops *ops;
#else
/* common device interface */
rt_err_t (*init) (rt_device_t dev);
rt_err_t (*open) (rt_device_t dev, rt_uint16_t oflag);
rt_err_t (*close) (rt_device_t dev);
rt_size_t (*read) (rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size);
rt_size_t (*write) (rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size);
rt_err_t (*control)(rt_device_t dev, int cmd, void *args);
#endif
#if defined(RT_USING_POSIX)
const struct dfs_file_ops *fops;
struct rt_wqueue wait_queue;
#endif
void *user_data; /**< device private data */
};
struct rt_object
{
char name[RT_NAME_MAX]; /**< name of kernel object */
rt_uint8_t type; /**< type of kernel object */
rt_uint8_t flag; /**< flag of kernel object */
#ifdef RT_USING_MODULE
void *module_id; /**< id of application module */
#endif
rt_list_t list; /**< list node of kernel object */
};
typedef struct rt_object *rt_object_t; /**< Type for kernel objects. */
在串口驱动注册时,每个串口的名字是不一样的,可以用 dev->parent->name 来进行区分。串口设备的名字在文件 drivers/include/config/uart_config.h 中定义。
#ifndef UART1_CONFIG
#define UART1_CONFIG
{
.name = "uart1",
.Instance = USART1,
.irq_type = USART1_IRQn,
.tx_pin_name = BSP_UART1_TX_PIN,
.rx_pin_name = BSP_UART1_RX_PIN,
}
#endif /* UART1_CONFIG */
#ifndef UART2_CONFIG
#define UART2_CONFIG
{
.name = "uart2",
.Instance = USART2,
.irq_type = USART2_IRQn,
.tx_pin_name = BSP_UART2_TX_PIN,
.rx_pin_name = BSP_UART2_RX_PIN,
}
#endif /* UART2_CONFIG */
举报