Chinaunix首页 | 论坛 | 博客
  • 博客访问: 388279
  • 博文数量: 115
  • 博客积分: 2501
  • 博客等级: 少校
  • 技术积分: 1009
  • 用 户 组: 普通用户
  • 注册时间: 2009-09-23 17:05
文章分类

全部博文(115)

文章存档

2011年(2)

2010年(86)

2009年(27)

我的朋友

分类: 嵌入式

2010-08-07 22:48:39

先用scull模块默认的量子大小4000、量子集大小1000,直接插入模块。

[rootMrFeng]#ls

buttons_driver.ko  mkdev.sh           scull_test

buttons_test       scull.ko

[rootMrFeng]#insmod scull.ko

[rootMrFeng]#lsmod

    Not tainted

scull 6068 0 - Live 0xbf000000

先查看proc下为scull动态分配的设备号:

[rootMrFeng]#cat /proc/devices

Character devices:

  1 mem

  4 /dev/vc/0

  4 tty

  5 /dev/tty

  5 /dev/console

  5 /dev/ptmx

  7 vcs

 10 misc

 13 input

 14 sound

 21 sg

 29 fb

 81 video4linux

 89 i2c

 90 mtd

116 alsa

128 ptm

136 pts

180 usb

189 usb_device

204 s3c2410_serial

251 scull

252 hidraw

253 usb_endpoint

254 rtc

 

Block devices:

259 blkext

  7 loop

  8 sd

 31 mtdblock

 65 sd

 66 sd

 67 sd

 68 sd

 69 sd

 70 sd

 71 sd

128 sd

129 sd

130 sd

131 sd

132 sd

133 sd

134 sd

135 sd

179 mmc

这里scull分配的主设备号为251,于是在dev下面使用mkdev.sh脚本建立设备节点,脚本内容为:

mknod -m 666 /dev/scull0 c 251 0

mknod -m 666 /dev/scull1 c 251 1

mknod -m 666 /dev/scull2 c 251 2

mknod -m 666 /dev/scull3 c 251 3

用测试程序进行测试scull读写:

[rootMrFeng]#./scull_test

open /dev/scull0

scull0:write 10 data to scull!

write_buf[0]=1  write_buf[1]=2  write_buf[2]=3  write_buf[3]=4  write_buf[4]=5  write_buf[5]=6  write_buf[6]=7  write_buf[7]=8  write_buf[8]=9  write_buf[9]=10 

open /dev/scull0

scull0:read 10 data from read_buf ok

read_buf[0]=1  read_buf[1]=2  read_buf[2]=3  read_buf[3]=4  read_buf[4]=5  read_buf[5]=6  read_buf[6]=7  read_buf[7]=8  read_buf[8]=9  read_buf[9]=10 

open /dev/scull1

scull1:write 10 data to scull!

write_buf[0]=1  write_buf[1]=2  write_buf[2]=3  write_buf[3]=4  write_buf[4]=5  write_buf[5]=6  write_buf[6]=7  write_buf[7]=8  write_buf[8]=9  write_buf[9]=10 

open /dev/scull1

scull1:read 10 data from read_buf ok

read_buf[0]=1  read_buf[1]=2  read_buf[2]=3  read_buf[3]=4  read_buf[4]=5  read_buf[5]=6  read_buf[6]=7  read_buf[7]=8  read_buf[8]=9  read_buf[9]=10 

open /dev/scull2

scull2:write 10 data to scull!

write_buf[0]=1  write_buf[1]=2  write_buf[2]=3  write_buf[3]=4  write_buf[4]=5  write_buf[5]=6  write_buf[6]=7  write_buf[7]=8  write_buf[8]=9  write_buf[9]=10 

open /dev/scull2

scull2:read 10 data from read_buf ok

read_buf[0]=1  read_buf[1]=2  read_buf[2]=3  read_buf[3]=4  read_buf[4]=5  read_buf[5]=6  read_buf[6]=7  read_buf[7]=8  read_buf[8]=9  read_buf[9]=10 

open /dev/scull3

scull3:write 10 data to scull!

write_buf[0]=1  write_buf[1]=2  write_buf[2]=3  write_buf[3]=4  write_buf[4]=5  write_buf[5]=6  write_buf[6]=7  write_buf[7]=8  write_buf[8]=9  write_buf[9]=10 

open /dev/scull3

scull3:read 10 data from read_buf ok

read_buf[0]=1  read_buf[1]=2  read_buf[2]=3  read_buf[3]=4  read_buf[4]=5  read_buf[5]=6  read_buf[6]=7  read_buf[7]=8  read_buf[8]=9  read_buf[9]=10

 

卸载掉模块,重新加载模块,加载时将量子集设置为2,量子数设置为5

[rootMrFeng]#rmmod scull.ko

[rootMrFeng]#lsmod

    Not tainted

[rootMrFeng]#insmod scull.ko scull_quantum=5 scull_qset=2

[rootMrFeng]#./scull_test

open /dev/scull0

scull0:write 5 data to scull!

write_buf[0]=1  write_buf[1]=2  write_buf[2]=3  write_buf[3]=4  write_buf[4]=5 

open /dev/scull0

scull0:read 5 data from read_buf ok

read_buf[0]=1  read_buf[1]=2  read_buf[2]=3  read_buf[3]=4  read_buf[4]=5 

open /dev/scull1

scull1:write 5 data to scull!

write_buf[0]=1  write_buf[1]=2  write_buf[2]=3  write_buf[3]=4  write_buf[4]=5 

open /dev/scull1

scull1:read 5 data from read_buf ok

read_buf[0]=1  read_buf[1]=2  read_buf[2]=3  read_buf[3]=4  read_buf[4]=5 

open /dev/scull2

scull2:write 5 data to scull!

write_buf[0]=1  write_buf[1]=2  write_buf[2]=3  write_buf[3]=4  write_buf[4]=5 

open /dev/scull2

scull2:read 5 data from read_buf ok

read_buf[0]=1  read_buf[1]=2  read_buf[2]=3  read_buf[3]=4  read_buf[4]=5 

open /dev/scull3

scull3:write 5 data to scull!

write_buf[0]=1  write_buf[1]=2  write_buf[2]=3  write_buf[3]=4  write_buf[4]=5 

open /dev/scull3

scull3:read 5 data from read_buf ok

read_buf[0]=1  read_buf[1]=2  read_buf[2]=3  read_buf[3]=4  read_buf[4]=5 

由于加载模块时将量子大小设置为5,而应用程序读写字节数位10,大于量子大小,只能读到5个字节。

阅读(465) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~