LED驱动程序设计

《《字符设备驱动程序》》

《设备控制理论》

<作用>

大部分驱动除了对外部设备提供读和写的基本功能以外,还需要对设备进行控制。

 

<应用程序接口>

在用户空间使用ioctl()系统调用来控制设备。

函数原型:

int ioctl (int fd,unsigned long cmd,........)

参数分析:

fd:要控制的设备描述符

cmd:要发送的命令

.......:第三个是可选参数,存在与否依赖于控制命令(第二个参数)

 

<驱动控制方法>

当程序使用ioctl() 函数后,驱动成程序的响应函数:
1)2.6.36 内核之前:

long (*ioctl)(struct inode* node ,struct file *filep,unsigned int cmd ,unsigned long arg)

2)2.6.36 内核之后

long (*unlock_ioctl)(struct file *filep,unsigned int cmd ,unsigned long arg)

 

《设备控制实现》

<定义命令>

命令从其实质而言就是一长串整数,为了让着长传整数具有更好的可读性,通常会把这个整数分成几段:类型(8),序号,参数传递方向,参数长度

Type(类型/幻数):表明是属于那种设备的命令

Number(序号):用来区分同一设备的不同命令

Direction(方向):参数传递方向,可能的值有(_IOC_NONE()没有数据传输,_IOC_READ/_IOC_WRITE(向设备写入参数)

Size:参数长度

 

如果用传统的方法拼接命令字,比较麻烦,linux系统提供了相应的函数。

_IO(type,nr) :不带参数的命令

 

_IOR(type,nr,dataype):从设备中读参数的命令

 

_IOW(type,nr,datatype):往设备写参数的命令

 

例:

#define  MEM_MAGIC  m

#define  MEM_SET -IOW(MEM_MAGIC ,0,int)

注意:为什么类型/幻术是一个字符?因为对类型的要求是一个8位的数据,字符数据就是一个8位的数据,这样使用比较方便。

 

<实现设备方法>

unlocked_iotcl() 函数的实现通常是根据执行的cmd 使用switch 语句。但是当命令不能匹配任何设备所支持的命令时,返回 _EINVAL

 

编程模型:

switch cmd

case  cmd1:

//执行相应操作

case cmd2:

//执行相应操作

case cmd2:

//执行相应操作

case cmd3:

//执行相应操作

 

default

return  _EINVAL

 

<wiz_tmp_tag id="wiz-table-range-border" contenteditable="false" style="display: none;">

 
 
 
 

转载于:https://www.cnblogs.com/big-devil/p/8589860.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
HD2010操作说明(HD2010 operating instructions) ⅰ.软件安装(Installed software) 双击光盘HD2010 V2.0目录下的安装文件图标 ,将控制系统安装到个人电脑.如下图2-1 (Open Profile HD2010 V2.0 in the compact disk,Dblclick Installed the HD2010 V2.0 in your personal computer.As shown in Figure 2-1) 图(Figure)2-1 点击确定后进入下一步如图2-2 (Click确定intro- next step.As shown in Figure 2-2 ) 图(Figure)2-2 点击下一步后进入下一步(英文环境)在中文环境直接点击下一步完成安装)如图2-3 2-4 2-5 2-6 2-7 (Click next intro- next step.As shown in Figure 2-3 2-4 2-5 2-6 2-7) 图(Figure)2-3 注意:发送的文件保存在安装目录下的ProjFile文件夹里,点击下一步完成安装 (Announcements:The file what you send saved in the ProjFile in path of Install.And click next to install and finish) 图(Figure)2-4 图(Figure)2-5 图(Figure)2-6 安装最后一步如图2-7 (The final step of install. As shown in Figure 2-7) 图(Figure)2-7 点击完成打开软件主界面如图2-8 (Click finish open main interface of the software. As shown in Figure 2-8) ⅱ.软件设置(Setting software) ⅱ.ⅰ主界面如图2-8(Main interface.As shown in Figure 2-8) 图(Figure)2-8 ⅱ.ⅱ软件属性(Software properties) 1.文件菜单(File menu) a.新建--新建一个新的显示屏(New—Create a new screen) b.打开--打开一个显示屏(Open—Open a exist screen) c.保存--保存建立的文件(Save—Save file) d.另存为--保存副本(Save as—save a copy) e.导出.hds--导出.hds文件,用于u盘读取文件 (Export.hds—Export.hds file,for usb reading) f.退出--退出软件(Exit—Exit the software) 2.设置菜单(Settings menu) a.屏参设置--设置显示屏属性 (Screen settings—Display Screen configuration attributes) b.通信设置--通信端口/方式设置 (Communication settings—Set Communication prot and fashion) c.系统设置--配置系统默认项 (System settings—Set the acquice properties of software) 3.操作菜单(Operate menu) a.发送项目--发送节目(Send project—send the programmes) b.导出到U盘--把节目导入到U盘 (Export to U disk—send the programme to your U disk) c.时间设置--时间校对 (Time setting—get the right time im your computer) d.亮度设置--选择亮度模式 (Luminance setting—Choice the module of Luminance) e.固件更新--固件升级(Update Firmware—Update your controller Firmware) 4.语言菜单(Language menu) a.简体中文(Simplified Chinese) b.繁体中文(Chinese Traditional) c.英语(English) ⅱ.ⅲ节目编辑(Edit
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值