我是靠谱客的博主 昏睡朋友,这篇文章主要介绍rtems驱动的组织目前支持的设备遗留问题,现在分享给大家,希望可以做个参考。

rtems中的设备,可以抽象成设备文件一样访问(例如/dev/ttyS0),也可以通过I/O manager来访问

 

设备文件的major和minor

major

核心的数据结构是 _IO_Driver_address_table ,  是一个结构体rtems_driver_address_table的数组(定义在cpukit/sapi/include/confdefs.h中),设备文件的major,其实就是对应驱动在数组中的下标,结构体的定义如下:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
cpukit/sapi/include/rtems/io.h typedef struct { rtems_device_driver_entry initialization_entry; rtems_device_driver_entry open_entry; rtems_device_driver_entry close_entry; rtems_device_driver_entry read_entry; rtems_device_driver_entry write_entry; rtems_device_driver_entry control_entry; } rtems_driver_address_table;

 除了initialization_entry外,其余五个函数指针与文件的五种操作一一对应(open close ioctl read write)。

initialization_entry在启动时调用(boot_card --> rtems_initialize_device_drivers  -->  _IO_Initialize_all_drivers  -->  rtems_io_initialize  --> initialization_entry )

这一层的函数在cpukit/sapi/src目录下的

io.c ioclose.c iocontrol.c ioinitialize.c ioopen.c ioread.c  iowrite.c  ioregisterdriver.c  iounregisterdriver.c  这几个文件中实现的。

 

minor

minor指的是一类设备中的其中一个设备,minor 为0和minor为1的设备可以是相同的驱动,也可以是不同的驱动。笔者将结合console驱动来对minor做说明,对于来说,

Console_Port_Tbl和Console_Port_Data是核心数据结构,Console_Port_Tbl可以看作一个指针数组

复制代码
1
2
3
c/src/lib/libbsp/shared/console.c console_tbl **Console_Port_Tbl = NULL;


其中,console_tbl的定义如下:

复制代码
1
2
3
4
5
6
7
8
9
c/src/libchip/serial/serial.h typedef struct _console_tbl { ... const console_fns *pDeviceFns; ... unsigned int ulIntVector; ... } console_tbl;

 

 在console_open函数中

复制代码
1
2
3
4
5
6
7
8
9
10
11
rtems_device_driver console_open( rtems_device_major_number major, rtems_device_minor_number minor, void * arg ) { ... cptr = Console_Port_Tbl[minor]; Callbacks.firstOpen = cptr->pDeviceFns->deviceFirstOpen; ... }


这里的minor,其实就是Console_Port_Tbl的下标索引,用minor可以找到具体某一设备的驱动

Console_Port_Tbl、Console_Port_Data是全局变量,但只是在console及具体的串口驱动中应用,为每个设备提供所需要的私有数据,对Major那一层来说是不知道这两个全局变量的存在的。

minor有用么?

当然,对于只有一个的一类设备,minor是没什么意义,比如对于tick的驱动程序来说,一个就够了(两个就乱套了吧,  ^_^)

复制代码
1
2
3
4
5
6
cpukit/libcsupport/include/clockdrv.h #define CLOCK_DRIVER_TABLE_ENTRY { Clock_initialize, NULL, NULL, NULL, NULL, NULL }

除了initialization_entry外,其他都不支持,它是不支持minor的,minor对它来说也是无意义的。

 

 如何关联到文件

调用函数rtems_io_register_name(const char * name,  major, minor), 这样把一个设备的(major, minor)号关联到一个文件上去, 这个函数一般在minor那一层初始化时做,因为在那时,才能确定下来minor号码是多少

目前支持的设备

console

clock

rtc

watchdog

/dev/null

/dev/zero

IDE

ATA

FrameBuffer等

另外,应用程序也可定义额外的驱动

 

遗留问题

网络的驱动,应该不是这种方式实现的

最后

以上就是昏睡朋友最近收集整理的关于rtems驱动的组织目前支持的设备遗留问题的全部内容,更多相关rtems驱动内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(67)

评论列表共有 0 条评论

立即
投稿
返回
顶部