modify drvmodel.md
This commit is contained in:
parent
38ac854746
commit
c4fab1c1c9
|
@ -14,8 +14,9 @@
|
|||
|
||||
xs_Device 结构体同样采用类似面向对象的方法,它集合了所有设备的共有特征,为设备的基类。平台上接入的具体设备以它为基类进行派生,如 IICHardwareDevice 、USBHardwareDevice 、SPIHardwareDevice 、CANHardwareDevice等。从而为众多不同性质的设备实现统一的管理架构。
|
||||
|
||||
## 关键数据结构
|
||||
|
||||
## struct xs_Bus结构
|
||||
* struct xs_Bus结构
|
||||
```c
|
||||
struct xs_Bus {
|
||||
char Bus_name[XS_NAME_MAX]; /* name of bus */
|
||||
|
@ -49,7 +50,7 @@ enum xs_BusType {
|
|||
xs_BusType成员表示不同的总线类型,其具体定义在上文给出。
|
||||
|
||||
|
||||
### enum Bus_priority枚举结构
|
||||
* enum Bus_priority枚举结构
|
||||
```c
|
||||
enum Bus_priority{
|
||||
PriorityLevelOne = 1,
|
||||
|
@ -64,7 +65,7 @@ enum Bus_priority{
|
|||
Bus_priority变量表示总线优先级,数值越低优先级越高
|
||||
|
||||
|
||||
### struct xs_IIC_bus结构
|
||||
* struct xs_IIC_bus结构
|
||||
```c
|
||||
struct xs_I2CBus {
|
||||
struct xs_Bus bus; /* Basic properties of the bus */
|
||||
|
@ -73,7 +74,7 @@ struct xs_I2CBus {
|
|||
```
|
||||
speed成员记录I2C总线与传感器设备通信的速率
|
||||
|
||||
### struct xs_SPIBus结构
|
||||
* struct xs_SPIBus结构
|
||||
```c
|
||||
struct xs_SPIBus {
|
||||
struct xs_Bus bus; /* Basic properties of the bus */
|
||||
|
@ -84,7 +85,7 @@ struct xs_SPIBus {
|
|||
```
|
||||
CPHA成员记录SPI总线的时钟相位,CPOL成员记录SPI总线的时钟极性
|
||||
|
||||
### struct xs_CANBus结构
|
||||
* struct xs_CANBus结构
|
||||
```c
|
||||
struct xs_CAN_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
|
||||
struct xs_USB_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
|
||||
typedef struct xs_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
|
||||
struct device_ops{
|
||||
int (*init)(struct xs_Device * dev);
|
||||
|
@ -135,9 +136,9 @@ typedef struct xs_Device * xs_DevicePointer ;
|
|||
```
|
||||
device_ops包含统一的、类似文件系统的API,用于对具体外设进行实际的数据读写。如在使用一个传感器前后需要打开(open)/关闭(close)该传感器,read、write分别用与从传感器接收数据与向传感器发送数据,ioctl用于配置传感器属性(如波特率)
|
||||
|
||||
### struct xs_HardwareDev结构
|
||||
* struct xs_HardwareDev结构
|
||||
```c
|
||||
struct xs_HardwareDev{
|
||||
|
||||
struct xs_Device dev;
|
||||
struct device_ops ops;
|
||||
|
||||
|
@ -146,11 +147,10 @@ struct xs_HardwareDev{
|
|||
void (*shutdown)(struct xs_Device * dev);
|
||||
int (*suspend)(struct xs_Device * dev, int state);
|
||||
int (*resume)(struct xs_Device * dev);
|
||||
|
||||
};
|
||||
```
|
||||
|
||||
## struct IICHardwareDevice结构
|
||||
* struct IICHardwareDevice结构
|
||||
```c
|
||||
struct IICHardwareDevice{
|
||||
struct xs_HardwareDev hardware;
|
||||
|
@ -159,7 +159,7 @@ struct xs_HardwareDev{
|
|||
}
|
||||
```
|
||||
|
||||
### struct SPIHardwareDevice结构
|
||||
* struct SPIHardwareDevice结构
|
||||
```c
|
||||
struct SPIHardwareDevice{
|
||||
struct xs_HardwareDev hardware;
|
||||
|
@ -168,7 +168,7 @@ struct xs_HardwareDev{
|
|||
}
|
||||
```
|
||||
|
||||
### struct CANHardwareDevice结构
|
||||
* struct CANHardwareDevice结构
|
||||
```c
|
||||
struct CANHardwareDevice{
|
||||
struct xs_HardwareDev hardware;
|
||||
|
@ -177,7 +177,7 @@ struct xs_HardwareDev{
|
|||
}
|
||||
```
|
||||
|
||||
### struct USBHardwareDevice结构
|
||||
* struct USBHardwareDevice结构
|
||||
```c
|
||||
struct USBHardwareDevice{
|
||||
struct xs_HardwareDev hardware;
|
||||
|
@ -187,10 +187,9 @@ struct xs_HardwareDev{
|
|||
```
|
||||
|
||||
|
||||
## struct xs_DeviceDriver结构
|
||||
* struct xs_DeviceDriver结构
|
||||
```c
|
||||
struct xs_DeviceDriver{
|
||||
|
||||
char driver_name[XS_NAME_MAX];
|
||||
struct bus_type * bus;
|
||||
enum driver_state falg;
|
||||
|
@ -204,13 +203,14 @@ struct xs_DeviceDriver{
|
|||
struct xs_DeviceDriver * next;
|
||||
void * data;
|
||||
};
|
||||
|
||||
}Device_driver_head;
|
||||
} Device_driver_head;
|
||||
```
|
||||
|
||||
|
||||
## 使用场景
|
||||
在获取i2c数据前,需要匹配设备驱动,设备驱动打开后对设备进行读写,使用完毕后,须关闭设备驱动。完整的使用过程示例如下:
|
||||
在获取i2c数据前,要匹配设备驱动,在设备驱动打开后对设备进行读写。使用完毕后,关闭设备驱动。
|
||||
|
||||
完整的使用过程示例如下:
|
||||
```c
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
@ -219,9 +219,9 @@ int main(int argc, char *argv[])
|
|||
|
||||
/* find the i2c device instance */
|
||||
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 */
|
||||
|
|
|
@ -74,7 +74,7 @@ struct xs_Timer
|
|||
xs_tick_x origin_timeslice; ///< 超时时间
|
||||
xs_tick_x deadline_timeslice; ///< 截止时间
|
||||
XS_DOUBLE_LINKLIST link; ///< 管理链表
|
||||
XS_DOUBLE_LINKLIST levels[XS_TIMER_SKIP_LIST_LEVEL]; ///< 查询链表
|
||||
XS_DOUBLE_LINKLIST Sortlist; ///< 查询链表
|
||||
};
|
||||
typedef struct xs_Timer *xs_timer_x;
|
||||
```
|
||||
|
|
Loading…
Reference in New Issue