- 论坛徽章:
- 0
|
本帖最后由 jn200002 于 2010-11-09 11:03 编辑
我的测试文件的open写错了~?~~?
大家好,很久没写驱动的代码了,今天有需求拉高一个GPIO口,现在不知道为什么没有被拉高
哪位有时间瞅瞅这个入门级的代码呗~ 先谢过了!
文件系统里到是有了设备名称了,我也能打开,就是ioctl写的时候没起作用
- #define DEVICE_NAME "pix-audio-power"
- // 关于GPIO设置的地方可以忽略,那个设置是没错的,我觉得我应该是模块结构上出现了什么问题。。。
- static int sbc2440_audio_power_ioctl(struct inode *inode,struct file *file,unsigned int cmd)
- {
- printk("IO CTRL......\n");
- unsigned long gpg5,gpgup,gpgdat;
- gpg5 = __raw_readl(S3C2410_GPGCON);
- gpgdat = __raw_readl(S3C2410_GPGDAT);
- gpgup = __raw_readl(S3C2410_GPGUP);
- switch(cmd)
- {
- case 0:
- 拉高
- case 1:
- 拉低
- }
- }
- static struct file_operations my_dev_fops = {
- .owner = THIS_MODULE,
- .ioctl = sbc2440_audio_power_ioctl,
- };
- static struct miscdevice misc = {
- .minor = 255,
- .name = DEVICE_NAME,
- .fops = &my_dev_fops,
- };
- static void pix_audio_gpio_init(void)
- {
- unsigned long gpg5,gpgdat,gpgup;
- 初始化一下output 拉低。
- }
- static int __init dev_init(void)
- {
- int ret;
- pix_audio_gpio_init();
- ret = misc_register(&misc);
- printk(DEVICE_NAME"\tinitialized\n");
- return ret;
- }
- static void __exit dev_exit(void)
- {
- misc_deregister(&misc);
- }
- module_init(dev_init);
- module_exit(dev_exit);
- MODULE_LICENSE("GPL");
- MODULE_AUTHOR("PIXSTAR Inc.");
- =============test.c=================
- #include <stdio.h>
- #include <fcntl.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #define AUDIO_PWR_ON 1
- #define AUDIO_PWR_OFF 0
- //BEFORE: wrong
- #define AUDIO_PWR_NAME "/sys/devices/virtual/misc/pix-audio-power"
- //-------------------------------------------------------
- //mknod /dev /name c min maj 结贴!
- //-------------------------------------------------------
- #define AUDIO_PWR_NAME "/dev/name"
- int main(int agrc,char** argv)
- {
- int fd;
- fd=open(AUDIO_PWR_NAME,"r+w");
-
- if(fd<0)
- {
- printf("open error!\n");
- return -1;
- }
-
- if(!(strcmp(argv[1],"on"))){
- ioctl(fd,AUDIO_PWR_ON);
- printf("AUDIO_PWR_ON.\n");
- }
- else if(!(strcmp(argv[1],"off"))){
- ioctl(fd,AUDIO_PWR_OFF);
- printf("AUDIO_PWR_OFF.\n");
- }
- return 0;
- }
复制代码 |
|