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

📄 leddrv.c

📁 Atmel公司的ARM9261的LED控制程序
💻 C
字号:
/**************************************************************** Green Automation* File Name: leddrv.c* Description: Light leds on h9261 board* Author: Holland* Date: 081229***************************************************************/#include <linux/module.h>#include <linux/version.h>#define MOD_INC_USE_COUNT#define MOD_DEC_USE_COUNT//#define CONFIG_ARCH_AT91SAM9261//#define __KERNEL__#include <linux/module.h>#include <linux/kernel.h>#include <linux/init.h>#include <linux/sched.h>#include <linux/fs.h>#include <linux/mm.h>#include <linux/poll.h>#include <linux/slab.h>#include <linux/ioport.h>#include <asm/uaccess.h>#include <asm/io.h>#include <linux/fcntl.h>#include <linux/at91sam9261.h>#include <asm/hardware.h>static int led_write(struct file *,const char *,int,loff_t *);static int led_open(struct inode *inode, struct file *file );static int led_release(struct inode *inode, struct file *file); static void Delay(int);static unsigned int major = 250;static struct file_operations led_fops={      write	:(void(*))led_write,      open	:(void(*))led_open,      release	:(void(*))led_release,};char led_name[]="leddrv";            static int __init leddrv_init_module(void){      int result;      result=register_chrdev(major,led_name,&led_fops);      if(result<0)      {         printk("<1>Register Fail!\n");         return result;      }     if(major==0)        major=result;          printk("<1>Led device OK!\n"); 	 AT91PS_SYS sys = (AT91PS_SYS) AT91_VA_BASE_SYS;	 	 sys->PIOA_PPUDR = (unsigned int)(1<<14)|(unsigned int)(1<<23);  // Pull-up Disable	 sys->PIOA_PER=(unsigned int)(1<<14)|(unsigned int)(1<<23);	// PIO Enable	 sys->PIOA_OER=(unsigned int)(1<<14)|(unsigned int)(1<<23);	 // Output Enable 	 sys->PIOA_CODR=(unsigned int)(1<<14)|(unsigned int)(1<<23);	 // Clear Output Data,the lights is on 	 Delay(1000); 	 sys->PIOA_SODR=(unsigned int)(1<<14)|(unsigned int)(1<<23);	 // Set Output Data,the lights is off		       Delay(1000);	 sys->PIOA_CODR=(unsigned int)(1<<14)|(unsigned int)(1<<23);	  // Clear Output Data,the lights is on     return 0;}static void __exit leddrv_cleanup(void){     int result;	 AT91PS_SYS sys = (AT91PS_SYS) AT91_VA_BASE_SYS;	  	 sys->PIOA_SODR=(unsigned int)(1<<14)|(unsigned int)(1<<23);	 // Set Output Data,the lights is off     result=unregister_chrdev(major,led_name);     if(result<0)      {        printk("<1>UnRegister Fail!\n");        return;      }	 printk("<1>LEDDRV:GOOD-bye!\n");}static int led_write(struct file *led_file, const char *buf,int len,loff_t *loff){     unsigned int iopdata;   	 AT91PS_SYS sys = (AT91PS_SYS) AT91_VA_BASE_SYS;	            if(copy_from_user((char*)&iopdata,buf,len))         return -EFAULT;	 sys->PIOA_CODR=iopdata;      Delay(1000);     sys->PIOA_SODR=iopdata;      return len;}static int led_open(struct inode *inode, struct file *file ) {	MOD_INC_USE_COUNT; 	return 0; } static int led_release(struct inode *inode, struct file *file) { 	MOD_DEC_USE_COUNT; 	return 0;}  static void Delay(int x){	int i,j,k;	for(i=0;i<x;i++)		for(j=0;j<0xff;j++)			for(k=0;k<0xff;k++);}module_init(leddrv_init_module);module_exit(leddrv_cleanup);MODULE_LICENSE("GPL");MODULE_AUTHOR("Holland");MODULE_DESCRIPTION("Led driver for H9261 board");/*end of leddrv.c*/

⌨️ 快捷键说明

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