#include <linux/fs.h>
#include <linux/config.h>//配置头文件
#include <linux/kernel.h>//内核头文件
#include <linux/sched.h>
#include <linux/timer.h>//时钟头文件
#include <linux/init.h>//用户定义模块初始函数名需引用的头文件
#include <linux/module.h>//模块加载的头文件
//#include <asm-arm/arch-omap/hardware.h>
#include <asm-arm/leds.h>
#include <linux/delay.h>
#include "systypes.h"
#include <asm-arm/arch-pxa/pxa-regs.h>//定义物理地址
#include <asm-arm/arch-pxa/hardware.h>
void DM_WaitMs(int msVal)
{
OMCR4 = (1<<7)|0;
OSMR4 = msVal;
OSCR4 = 0;
OIER = 1<<4;
OSSR = 1<<4;
OMCR4 |= 2;
while(!(OSSR&(1<<4)));
}
/*file_operations结构*/
int gpio_open(struct inode*,struct file*);
int gpio_release(struct inode*,struct file*);
int gpio_ctl_ioctl(struct inode*,struct file*,unsigned int,unsigned long);
struct file_operations gpio_ctl_fops = {
owner:THIS_MODULE,
ioctl:gpio_ctl_ioctl,
open:gpio_open,
release:gpio_release,
};
/*入口函数*/
#define IOPORT_MAJOR 220 //major
int _init_module(void)
{
int ret = 0;
int test_major = 0;
printk("gpio_init\n");
ret = register_chrdev(IOPORT_MAJOR,"GPIO",&gpio_ctl_fops);
if(ret < 0)
{
printk("fail to register\n");
return -1;
}
if(test_major == 0) test_major = ret;
printk("success to register\n");
return 0;
}
/*led控制函数*/
void LedOn(int led)
{
switch(led){
case 0:
GPCR3 = 1 << 10;
break;
case 1:
GPCR3 = 1 << 11;
break;
case 2:
GPCR3 = 1 << 12;
break;
case 3:
GPCR3 = 1 << 0;
break;
default:
break;
}
}
void LedOff(int led)
{
switch(led){
case 0: //GPIO106输出1,D4灭
GPSR3 = 1 << 10;
break;
case 1: //GPIO107输出1,D5灭
GPSR3 = 1 << 11;
break;
case 2: //GPIO108输出1,D6灭
GPSR3 = 1 << 12;
break;
case 3: //GPIO96输出1,D7灭
GPSR3 = 1 << 0;
break;
default:
break;
}
}
/*gpio_open函数*/
int gpio_open(struct inode *inode,struct file *file)
{
//禁止内核的LED事件改变LED灯状态
leds_event(led_halted);
GAFR3_L &= ~((3 << 20)|(3 << 22)|(3 << 24)|(3 << 0)); //the corresponding pin (GPIO106\107\108\96)are used as general purpose I/O
GPDR3 |= (1 << 10)|(1 << 11)|(1 << 12)|(1 << 0); //the pins of GPIO106\107\108\96 are used as output pins
GPSR3 = (1 << 10)|(1 << 11)|(1 << 12)|(1 << 0); //置GPIO106\107\108\96为"1"
printk("open gpio devices\n");
return 0;
}
/*gpio_release函数*/
int gpio_release(struct inode *inode,struct file *file)
{
leds_event(led_halted + 2);
printk("release this device\n");
return 0;
}
/*gpio_ctl_ioctl函数*/
int gpio_ctl_ioctl(struct inode *inode,struct file *file,unsigned int command,unsigned long arg )
{
int err = 0;
int i = 0;
if (command == 1)
{
while(arg--)
{
i = 0 ;
//循环一次点亮各个LED灯
while(1)
{
LedOn(i);
DM_WaitMs(200);
LedOff(i);
DM_WaitMs(200);
i++;
if(i >= 4)
{
break;
}
printk("...");
}
}
printk("\n");
return 0;
}
else if (command ==2)
{
return 0;
}
return err;
}
没有合适的资源?快使用搜索试试~ 我知道了~
led_driver_test.rar_sysTypes.h_test led driver
共26个文件
c:6个
h:5个
cmd:3个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 6 浏览量
2022-09-24
15:57:26
上传
评论
收藏 45KB RAR 举报
温馨提示
嵌入式PXA270开发板LED驱动的测试程序,编译通过,测试可用
资源推荐
资源详情
资源评论
收起资源包目录
led_driver_test.rar (26个子文件)
led驱动测试
systypes.h 4KB
gpiodrv.ko 3KB
gpio_test.c 630B
LedTest
.gpiodrv1.mod.o.cmd 7KB
ledtest1 14KB
.gpiodrv1.o.cmd 8KB
gpiodrv1.mod.o 1KB
ledtest.c 768B
gpiodrv1.c 3KB
systypes.h 4KB
ledtest.bin 12KB
gpiodrv1.ko 3KB
gpiodrv1.mod.c 454B
regsdef.h 6KB
ledtest 13KB
.tmp_versions
gpiodrv1.mod 63B
led.sh 90B
utils.h 693B
Makefile 262B
gpiodrv.c 3KB
.gpiodrv1.ko.cmd 186B
gpiodrv1.o 3KB
globals.h 812B
Makefile 228B
gpiodrv.c 3KB
led 62KB
共 26 条
- 1
资源评论
Kinonoyomeo
- 粉丝: 77
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功