92 lines
3.1 KiB
C
92 lines
3.1 KiB
C
![]() |
/******************************************************************************
|
||
|
|
||
|
Copyright @2024 - 2044 Shenzhen dcenzix Technology Ltd.
|
||
|
|
||
|
******************************************************************************
|
||
|
@file cola_device.h
|
||
|
@brief 设备节点管理
|
||
|
@author xiexiongwu
|
||
|
@version V1.0
|
||
|
@date 2024年5月25日
|
||
|
|
||
|
******************************************************************************/
|
||
|
#ifndef __COLA_DEVICE_H__
|
||
|
#define __COLA_DEVICE_H__
|
||
|
|
||
|
/*----------------------------------------------*
|
||
|
* 包含头文件 *
|
||
|
*----------------------------------------------*/
|
||
|
#include <stdint.h>
|
||
|
#include <stdbool.h>
|
||
|
#include "cola_init.h"
|
||
|
|
||
|
/*----------------------------------------------*
|
||
|
* 宏定义 *
|
||
|
*----------------------------------------------*/
|
||
|
typedef struct cola_device cola_device_t;
|
||
|
|
||
|
/*----------------------------------------------*
|
||
|
* 结构体定义 *
|
||
|
*----------------------------------------------*/
|
||
|
|
||
|
/**\struct cola_device_ops
|
||
|
* \brief 硬件操作抽象接口
|
||
|
*/
|
||
|
struct cola_device_ops
|
||
|
{
|
||
|
int (*init)(cola_device_t *dev); ///<初始化接口
|
||
|
int (*open)(cola_device_t *dev, int oflag); ///<打开接口
|
||
|
int (*close)(cola_device_t *dev); ///<关闭接口
|
||
|
int (*read)(cola_device_t *dev, int pos, void *buffer, int size); ///<数据读取接口
|
||
|
int (*write)(cola_device_t *dev, int pos, const void *buffer, int size); ///<数据写入接口
|
||
|
int (*control)(cola_device_t *dev, int cmd, void *args); ///<数据控制接口
|
||
|
int (*config)(cola_device_t *dev, void *args, void *var); ///<数据配置接口
|
||
|
};
|
||
|
|
||
|
|
||
|
/**\struct cola_device
|
||
|
* \brief 设备
|
||
|
*/
|
||
|
|
||
|
struct cola_device
|
||
|
{
|
||
|
const char *name; ///<设备名称
|
||
|
const struct cola_device_ops *dops; ///<设备操作接口
|
||
|
void *owner; ///<设备所属任务
|
||
|
void *argv; ///<参数
|
||
|
int data; ///<数据
|
||
|
struct cola_device *next; ///<设备连表的下一个
|
||
|
};
|
||
|
|
||
|
/*----------------------------------------------*
|
||
|
* 函数原型说明 *
|
||
|
*----------------------------------------------*/
|
||
|
|
||
|
#ifdef __cplusplus
|
||
|
#if __cplusplus
|
||
|
extern "C" {
|
||
|
#endif
|
||
|
#endif /* __cplusplus */
|
||
|
|
||
|
extern int cola_device_cfg(cola_device_t *dev, void *args, void *var);
|
||
|
extern int cola_device_close(cola_device_t *dev);
|
||
|
extern int cola_device_ctrl(cola_device_t *dev, int cmd, void *arg);
|
||
|
extern cola_device_t *cola_device_find(const char *name);
|
||
|
extern int cola_device_init(cola_device_t *dev);
|
||
|
extern bool cola_device_is_exists(cola_device_t *dev);
|
||
|
extern int cola_device_open(cola_device_t *dev, int oflag);
|
||
|
extern int cola_device_read(cola_device_t *dev, int pos, void *buffer, int size);
|
||
|
extern void cola_device_register(cola_device_t *dev);
|
||
|
extern void cola_device_set_owner(cola_device_t *dev, const void *owner);
|
||
|
extern int cola_device_write(cola_device_t *dev, int pos, const void *buffer, int size);
|
||
|
extern void device_list_insert(cola_device_t *dev);
|
||
|
|
||
|
#ifdef __cplusplus
|
||
|
#if __cplusplus
|
||
|
}
|
||
|
#endif
|
||
|
#endif /* __cplusplus */
|
||
|
|
||
|
|
||
|
#endif /* __COLA_DEVICE_H__ */
|