今天学习了在linux2.6平台下的 char drvier ,在linux下推荐使用的是cdev结构体来实现对character设备的描述,代码如下
/*This module is desired for sunplusapp s3c2440_board */
#include <linux/fs.h>
#include <linux/types.h>
#include <linux/cdev.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <asm/uaccess.h>
#include <linux/errno.h>
#include <mach/regs-gpio.h>
#include <mach/hardware.h>
#include <linux/platform_device.h>
#include <linux/mm.h>
#include <linux/sched.h>
#include <asm/io.h>
#include <asm/system.h>
#define DEVICE_NAME "LED_S3C2440"
struct LED_dev{
struct cdev cdev;
char name[10];
/*...*/
}*LED_devp;
static dev_t LED_device_num;
static struct class *LED_class;
//struct class *LED_class;
static unsigned long LED_table[]={
S3C2410_GPG0,
S3C2410_GPG1,
S3C2410_GPG2,
};
static unsigned int LED_cfg_table[]={
S3C2410_GPG0_OUTP,
S3C2410_GPG1_OUTP,
S3C2410_GPG2_OUTP,
};
int LED_open(struct inode *inode, struct file *filp)
{
/*将设备结构体指针赋值给文件私有数据指针*/
filp->private_data = LED_devp;
printk("Open OK\n");
return 0;
}
/*文件释放函数*/
int LED_release(struct inode *inode, struct file *filp)
{
printk("Release OK\n");
return 0;
}
static ssize_t LED_write(struct file *filp,const char __user *buf,size_t size,loff_t *f_pos)
{
unsigned char buff = 0;
int ret;
int i;
/*用户空间->内核空间*/
if (copy_from_user(&buff, buf, size))
ret = - EFAULT;
printk("write:buff=0x%x,buff=0x%x,count=%d\n", buff, buf, size);
buff-=0x30;
for(i=0;i<3;i++)
{
if(i==buff)
s3c2410_gpio_setpin(LED_table[i],1);
else
s3c2410_gpio_
命令行级别 命令行中敲入 ulimit -n 12345 用户级别 编辑/etc/security/limits.conf: 文件,插入一行:userx hard nofile 12345 系统级别 在/etc/sysctl.conf文件中加入一行 fs.file-max=12345,然后在命令行中输入:sysctl -p ,使其生效 ......