modify drvmodel.md

This commit is contained in:
Yan_yan 2020-11-16 18:02:37 +08:00
parent 38ac854746
commit c4fab1c1c9
2 changed files with 23 additions and 23 deletions

View File

@ -14,8 +14,9 @@
xs_Device 结构体同样采用类似面向对象的方法,它集合了所有设备的共有特征,为设备的基类。平台上接入的具体设备以它为基类进行派生,如 IICHardwareDevice 、USBHardwareDevice 、SPIHardwareDevice 、CANHardwareDevice等。从而为众多不同性质的设备实现统一的管理架构。 xs_Device 结构体同样采用类似面向对象的方法,它集合了所有设备的共有特征,为设备的基类。平台上接入的具体设备以它为基类进行派生,如 IICHardwareDevice 、USBHardwareDevice 、SPIHardwareDevice 、CANHardwareDevice等。从而为众多不同性质的设备实现统一的管理架构。
## 关键数据结构
## struct xs_Bus结构 * struct xs_Bus结构
```c ```c
struct xs_Bus { struct xs_Bus {
char Bus_name[XS_NAME_MAX]; /* name of bus */ char Bus_name[XS_NAME_MAX]; /* name of bus */
@ -49,7 +50,7 @@ enum xs_BusType {
xs_BusType成员表示不同的总线类型其具体定义在上文给出。 xs_BusType成员表示不同的总线类型其具体定义在上文给出。
### enum Bus_priority枚举结构 * enum Bus_priority枚举结构
```c ```c
enum Bus_priority{ enum Bus_priority{
PriorityLevelOne = 1, PriorityLevelOne = 1,
@ -64,7 +65,7 @@ enum Bus_priority{
Bus_priority变量表示总线优先级数值越低优先级越高 Bus_priority变量表示总线优先级数值越低优先级越高
### struct xs_IIC_bus结构 * struct xs_IIC_bus结构
```c ```c
struct xs_I2CBus { struct xs_I2CBus {
struct xs_Bus bus; /* Basic properties of the bus */ struct xs_Bus bus; /* Basic properties of the bus */
@ -73,7 +74,7 @@ struct xs_I2CBus {
``` ```
speed成员记录I2C总线与传感器设备通信的速率 speed成员记录I2C总线与传感器设备通信的速率
### struct xs_SPIBus结构 * struct xs_SPIBus结构
```c ```c
struct xs_SPIBus { struct xs_SPIBus {
struct xs_Bus bus; /* Basic properties of the bus */ struct xs_Bus bus; /* Basic properties of the bus */
@ -84,7 +85,7 @@ struct xs_SPIBus {
``` ```
CPHA成员记录SPI总线的时钟相位CPOL成员记录SPI总线的时钟极性 CPHA成员记录SPI总线的时钟相位CPOL成员记录SPI总线的时钟极性
### struct xs_CANBus结构 * struct xs_CANBus结构
```c ```c
struct xs_CAN_bus { struct xs_CAN_bus {
struct xs_Bus bus; /* Basic properties of the bus */ struct xs_Bus bus; /* Basic properties of the bus */
@ -93,7 +94,7 @@ struct xs_CAN_bus {
}; };
``` ```
### struct xs_USBBus结构 * struct xs_USBBus结构
```c ```c
struct xs_USB_bus { struct xs_USB_bus {
struct xs_Bus bus; /* Basic properties of the bus */ struct xs_Bus bus; /* Basic properties of the bus */
@ -103,7 +104,7 @@ struct xs_USB_bus {
``` ```
## struct xs_Device结构 * struct xs_Device结构
```c ```c
typedef struct xs_Device { typedef struct xs_Device {
char dev_name[XS_NAME_MAX]; /* name of device */ char dev_name[XS_NAME_MAX]; /* name of device */
@ -122,7 +123,7 @@ typedef struct xs_Device * xs_DevicePointer ;
### struct device_ops结构 * struct device_ops结构
```c ```c
struct device_ops{ struct device_ops{
int (*init)(struct xs_Device * dev); int (*init)(struct xs_Device * dev);
@ -135,9 +136,9 @@ typedef struct xs_Device * xs_DevicePointer ;
``` ```
device_ops包含统一的、类似文件系统的API用于对具体外设进行实际的数据读写。如在使用一个传感器前后需要打开open/关闭close该传感器read、write分别用与从传感器接收数据与向传感器发送数据ioctl用于配置传感器属性如波特率 device_ops包含统一的、类似文件系统的API用于对具体外设进行实际的数据读写。如在使用一个传感器前后需要打开open/关闭close该传感器read、write分别用与从传感器接收数据与向传感器发送数据ioctl用于配置传感器属性如波特率
### struct xs_HardwareDev结构 * struct xs_HardwareDev结构
```c
struct xs_HardwareDev{ struct xs_HardwareDev{
struct xs_Device dev; struct xs_Device dev;
struct device_ops ops; struct device_ops ops;
@ -146,11 +147,10 @@ struct xs_HardwareDev{
void (*shutdown)(struct xs_Device * dev); void (*shutdown)(struct xs_Device * dev);
int (*suspend)(struct xs_Device * dev, int state); int (*suspend)(struct xs_Device * dev, int state);
int (*resume)(struct xs_Device * dev); int (*resume)(struct xs_Device * dev);
}; };
``` ```
## struct IICHardwareDevice结构 * struct IICHardwareDevice结构
```c ```c
struct IICHardwareDevice{ struct IICHardwareDevice{
struct xs_HardwareDev hardware; struct xs_HardwareDev hardware;
@ -159,7 +159,7 @@ struct xs_HardwareDev{
} }
``` ```
### struct SPIHardwareDevice结构 * struct SPIHardwareDevice结构
```c ```c
struct SPIHardwareDevice{ struct SPIHardwareDevice{
struct xs_HardwareDev hardware; struct xs_HardwareDev hardware;
@ -168,7 +168,7 @@ struct xs_HardwareDev{
} }
``` ```
### struct CANHardwareDevice结构 * struct CANHardwareDevice结构
```c ```c
struct CANHardwareDevice{ struct CANHardwareDevice{
struct xs_HardwareDev hardware; struct xs_HardwareDev hardware;
@ -177,7 +177,7 @@ struct xs_HardwareDev{
} }
``` ```
### struct USBHardwareDevice结构 * struct USBHardwareDevice结构
```c ```c
struct USBHardwareDevice{ struct USBHardwareDevice{
struct xs_HardwareDev hardware; struct xs_HardwareDev hardware;
@ -187,10 +187,9 @@ struct xs_HardwareDev{
``` ```
## struct xs_DeviceDriver结构 * struct xs_DeviceDriver结构
```c ```c
struct xs_DeviceDriver{ struct xs_DeviceDriver{
char driver_name[XS_NAME_MAX]; char driver_name[XS_NAME_MAX];
struct bus_type * bus; struct bus_type * bus;
enum driver_state falg; enum driver_state falg;
@ -204,13 +203,14 @@ struct xs_DeviceDriver{
struct xs_DeviceDriver * next; struct xs_DeviceDriver * next;
void * data; void * data;
}; };
} Device_driver_head;
}Device_driver_head;
``` ```
## 使用场景 ## 使用场景
在获取i2c数据前需要匹配设备驱动设备驱动打开后对设备进行读写使用完毕后须关闭设备驱动。完整的使用过程示例如下 在获取i2c数据前要匹配设备驱动在设备驱动打开后对设备进行读写。使用完毕后关闭设备驱动。
完整的使用过程示例如下:
```c ```c
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
@ -219,9 +219,9 @@ int main(int argc, char *argv[])
/* find the i2c device instance */ /* find the i2c device instance */
dev = (struct xs_I2cDevice*)xs_DeviceFind("i2c_temp",XS_IIC_BUS); //获取设备句柄 dev = (struct xs_I2cDevice*)xs_DeviceFind("i2c_temp",XS_IIC_BUS); //获取设备句柄
if(dev==NULL) if(dev == NULL)
{ {
xs_kprintf("find iic device error\n") xs_kprintf("find iic device error\n");
} }
/* open the device instance */ /* open the device instance */

View File

@ -74,7 +74,7 @@ struct xs_Timer
xs_tick_x origin_timeslice; ///< 超时时间 xs_tick_x origin_timeslice; ///< 超时时间
xs_tick_x deadline_timeslice; ///< 截止时间 xs_tick_x deadline_timeslice; ///< 截止时间
XS_DOUBLE_LINKLIST link; ///< 管理链表 XS_DOUBLE_LINKLIST link; ///< 管理链表
XS_DOUBLE_LINKLIST levels[XS_TIMER_SKIP_LIST_LEVEL]; ///< 查询链表 XS_DOUBLE_LINKLIST Sortlist; ///< 查询链表
}; };
typedef struct xs_Timer *xs_timer_x; typedef struct xs_Timer *xs_timer_x;
``` ```