⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gpiodrv.c

📁 该压缩包里面含两个源码
💻 C
字号:
#include <linux/config.h> 
#include <linux/init.h> 
#include <linux/module.h> 
#include <linux/fs.h> 
#include <linux/iobuf.h> 
#include <linux/kernel.h> 
#include <linux/major.h> 
#include <asm/uaccess.h> 
#include <asm/hardware.h> 
#include <asm/arch/cpu_s3c2410.h> 
#include <asm/io.h> 
#include <linux/vmalloc.h> 
#define IOPORT_MAJOR 220  /*定义主设备号*/ 
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); 
static struct file_operations gpio_ctl_fops={ 
  ioctl:   gpio_ctl_ioctl, 
  open :   gpio_open, 
  release:     gpio_release, 
};           
#define LED1_ON()  (GPFDAT &= ~0x10) 
#define LED2_ON()  (GPFDAT &= ~0x20) 
#define LED3_ON()  (GPFDAT &= ~0x40) 
#define LED4_ON()  (GPFDAT &= ~0x80) 
#define LED1_OFF() (GPFDAT |= 0x10) 
#define LED2_OFF() (GPFDAT |= 0x20) 
#define LED3_OFF() (GPFDAT |= 0x40) 
#define LED4_OFF() (GPFDAT |= 0x80) 
static int LedStatus; 
void LedSet(int led) 
{ 
  LedStatus = led; 
  if(LedStatus&1) 
    LED1_ON(); 
  else 
    LED1_OFF(); 
  if(LedStatus&2) 
    LED2_ON(); 
  else 
    LED2_OFF(); 
  if(LedStatus&4) 
    LED3_ON(); 
  else 
    LED3_OFF(); 
  if(LedStatus&8) 
    LED4_ON(); 
  else 
    LED4_OFF(); 
} 

void LedDisp(void) 
{ 
  LedSet(0x08);      //LED点亮/熄灭状态设置 
  udelay(0x500000);     //延时函数 
  LedSet(0x04);      //LED点亮/熄灭状态设置 
    udelay(0x500000); 
  LedSet(0x02);    //LED点亮/熄灭状态设置 
  udelay(0x500000); 
  LedSet(0x01);    //LED点亮/熄灭状态设置 
  udelay(0x500000); 
  LedSet(0x02);    //LED点亮/熄灭状态设置 
    udelay(0x500000); 
  LedSet(0x04);    //LED点亮/熄灭状态设置 
  udelay(0x500000); 
  LedSet(0x08);    //LED点亮/熄灭状态设置 
  udelay(0x500000); 
} 
static int __init gpio_init(void) 
{ 
  int err=0; 
        printk("gpio_init\n"); 
  err=register_chrdev(IOPORT_MAJOR,"gpio",&gpio_ctl_fops); 
  if(err) 
 { 
    printk("fail to register\n"); 
    return -1; 
 } 
  printk("success to register\n"); 
  return 0; 
} 
int gpio_open(struct inode *inode,struct file *fllp) 
{ 
  GPFCON=0x5500; 

  GPFUP=0xff; 
  printk("open gpio devices\n"); 
  return 0; 
} 
int gpio_release(struct inode *inode,struct file *filp) 
{ 
  printk("release this device\n"); 
  return 0; 
} 
int gpio_ctl_ioctl(struct inode *inode,struct file *flip,unsigned int command, 
unsigned long arg) 
{ 
  int err=0; 
  if(command==1){ 
    while(arg--) 
  { 
   LedDisp(); 
   printk("...."); 
  } 
    printk("\n"); 
    return 0; 
 } 
  return err; 
} 
module_init(gpio_init);            
module_exit(gpio_release);         

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -