嵌入式linux设备驱动,无法打开设备文件

嵌入式linux设备驱动,无法打开设备文件,第1张

1. ls /dev/* 看看有没有你的LED节点

2.cat /proc/devices 看看有没有相关LED驱动信息。

===============================

static const struct file_operations fops_led =

{

.owner = THIS_MODULE,

//.open = open_led,

.unlocked_ioctl = unlocked_ioctl_led,

}

都屏蔽了open函数,怎么打开?

应用层默认open函数定义:int open( const char * pathname,int flags)

驱程序般open函数定义:int(*open)(struct inode *inode, struct file *filp)

LED点亮应用层主函数

[code=C/C++][/code]void main(void)

{

int testdev

int i

char buf[10]

testdev = open ("/dev/test",O_RDWR)//应该用应用层默认Open函数吧

if(testdev == -1)

{

printf("Cann't open file...../n")

exit(0)

}

printf("buf = 0x%x/n",buf)

read(testdev,buf,10)//功opentestdev值0能够file文件描述符呢

write(testdev,buf,1)

led_ctl.port='G'

led_ctl.bit=5

led_ctl.value=0

ioctl(testdev,GPIO_IO_SET_GPG,&led_ctl)

printf("%s",buf)

pause()

close(testdev)

}

我疑问:

1.驱程序open函数:int(*open)(struct inode *inode, struct file *filp)

哪使用啊

2.驱open函数般用做啊

3.文代码功opentestdev值0能够file文件描述符呢

才始习Linux设备驱发借本书代码没注释面驱意思懂希望各位神指点指点万谢

面都我编写字符设备驱代码请问static int read_test()函数始static void release_test()函数参数内部代码意义

万谢

采纳前加100谢谢

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

#include <linux/types.h>

#include <linux/fs.h>

#include <linux/mm.h>

#include <linux/errno.h>

#include <asm/segment.h>

#include <asm/uaccess.h>

#include <linux/module.h>

unsigned int test_major = 0

static int read_test(struct inode *node,struct file *fle,char *buf,int count)

{

int left

if (access_ok(VERIFY_WRITE, buf, count))

{

for (left = countleft >0left--)

{

_put_user('a',buf)

buf ++

}

}

return count

}

static int write_test(struct inode *node, struct file *fle, char *buf, int count)

{

return count

}

static int open_test(struct inode *inode,struct file *file)

{

try_module_get(THIS_MODULE)

return 0

}

static void release_test(struct inode *inode, struct file *file)

{

module_put(THIS_MODULE)

}

struct file_operations test_fops =

{

.owner = THIS_MODULE,

.read = read_test,

.write = write_test,

.open = open_test,

.release = release_test,

}

int init_module()

{

int result

result = register_chrdev(0,"test,&test_fops")

if (result <0)

{

printk(KERN_INFO "dddddddddddddddd")

return result

}

return 0

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/8954909.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-23
下一篇 2023-04-23

发表评论

登录后才能评论

评论列表(0条)

保存