📄 led.c
字号:
/****************************************Copyright (c)**************************************************
** 西安傅立叶电子有限公司
** 研 发 部
** http://www.FFTChina.com
**-----------------------------------------文件信息-----------------------------------------------------
**文 件 名: ledtest.c
**创 建 人:
**最后修改日期: 2005年6月30日
**描 述: led模块测试驱动程序(查询模式)
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
#ifndef __KERNEL__
#define __KERNEL__
#endif
#ifndef MODULE
#define MODULE
#endif
#include "linux/types.h"
#include "linux/fs.h"
#include "linux/mm.h"
#include "linux/errno.h"
#include "linux/major.h"
#include "linux/blkdev.h"
#include "linux/capability.h"
#include "linux/smp_lock.h"
#include "linux/module.h"
#include "linux/version.h"
#include "linux/kernel.h"
#include "linux/config.h"
#include "asm/uaccess.h"
#include "asm/io.h"
void *AT91C_BASE_PIOB;
long int *pio;
char kernel_version[]=UTS_RELEASE;
unsigned int fftled_major=0;
/*******************************************************
** 函数原形:setledport(unsigned char chanal, unsigned char reg, unsigned char data1)
** 参数: chanal : led通道号
** reg : 寄存器地址
** data : 要写入的数据
** 函数说明:向led写数据
/*******************************************************/
void setledport(unsigned char chanal, unsigned char reg, unsigned char data1)
{
}
/*******************************************************
*函数原形:getledport(unsigned char chanal, unsigned char reg)
*参数: chanal : led的通道号
* reg :寄存器地址
*返回值 : 读出寄存器的值
*函数说明:读出寄存器的值
/*******************************************************/
unsigned char getledport(unsigned char chanal, unsigned char reg)
{
return (0);
}
/*******************************************************
** 函数原形:ifgetdata(unsigned char chanal)
** 参数: chanal : led通道号
** 返回值 :1:有可用数据
** 0:无可用数据
** 函数说明:判断led是否收到数据
/*******************************************************/
unsigned char ifgetdata(unsigned char chanal)
{
return (0);
}
/*******************************************************
*函数原形:read_fftled(struct file *file, char *buf, size_t count,loff_t *f_pos)
*参数: buf : 传入该函数的数据缓冲区指针
* count:led的通道号
*返回值 : 0
*函数说明:读出接收到的led数据
/*******************************************************/
int read_fftled(struct file *file, char *buf, size_t count,loff_t *f_pos)
{
return (0);
}
/*******************************************************
*函数原形:write_fftled(struct file *file,const char *buf,size_t count,loff_t *f_pos)
*参数: buf : 传入该函数的数据缓冲区指针
* count:led的通道号
*返回值 : 0 说明成功写入
*函数说明:向led总线发送数据
/*******************************************************/
int write_fftled(struct file *file,const char *buf,size_t count,loff_t *f_pos)
{
pio=AT91C_BASE_PIOB+0x30;
*pio=0xffffffff;
pio=AT91C_BASE_PIOB+0x34;
switch(buf[0])
{
case 1:*pio=1<<15;break;
case 2:*pio=1<<16;break;
case 3:*pio=1<<17;break;
case 4:*pio=1<<26;break;
break;
} //If it is transmitted succeded?
return (0);
}
/*******************************************************
*函数原形:open_fftled(struct inode *inode,struct file *file)
*参数:
*返回值 :
*函数说明:
/*******************************************************/
int open_fftled(struct inode *inode,struct file *file)
{
return 0;
}
/*******************************************************
*函数原形:open_fftled(struct inode *inode,struct file *file)
*参数:
*返回值 :
*函数说明:
/*******************************************************/
int release_fftled(struct inode *inode,struct file *file)
{
return 0;
}
/***************************************************************************************************
*函数原形:ioctl_fftled(struct inode *inode,struct file *file,unsigned int cmd,unsigned long arg)
*参数: cmd : 传入该函数的命令参数
* 0 :判断是否led0收到可用数据
1 :判断是否led1收到可用数据
3 :初始化led0总线
4 :初始化led1总线
arg :传入的参数
*返回值 : 0 :接收到有效数据
1 :没有接收到有效数据
3 :成功初始化led0
4 :成功初始化led1
5 :无效的命令
*函数说明:向led总线发送数据
/**************************************************************************************************/
static int ioctl_fftled(struct inode *inode,struct file *file,unsigned int cmd,unsigned long arg)
{
return (0);
}
/**************************************
** 函数指针结构: file_operations
** 说明 :
***************************************/
struct file_operations fftled_fops={
read : read_fftled,
write: write_fftled,
ioctl: ioctl_fftled,
open : open_fftled,
release: release_fftled,
};
/******************************************************
** 初始化模块:在加载模块时候调用
** 函数原形 : init_module(void)
** 说 明 :不用修改
******************************************************/
int init_module(void)
{
int result;
result=register_chrdev(0,"fftled",&fftled_fops); //注册一个设备,得到驱动的主设备号
if(result<0)
{
printk("led not get fftled major number\n"); //没有成功
return result;
}
printk("congraulation,fftled are successful registed\n");
printk("result=%d\n",result);
if(fftled_major==0)
{
fftled_major=result; //记录下主设备号
}
//映射物理地址到IO内存,可以让软件直接访问IO内存
AT91C_BASE_PIOB= ioremap(0xFFFFF600,0xf0);
/*将物理地址直接映射到IO内存*/
pio=AT91C_BASE_PIOB;
*pio=0xffffffff;
pio=AT91C_BASE_PIOB+0x10;
*pio=0xffffffff;
pio=AT91C_BASE_PIOB+0x34;
*pio=0xffffffff;
return 0;
}
/*******************************************************
** 函数原形 : cleanup_module(void)
** 说明 : 在卸载模块时调用
******************************************************/
void cleanup_module(void)
{
// shumaaddr=0xffffffff;
pio=AT91C_BASE_PIOB+0x30;
*pio=0xffffffff;
iounmap(AT91C_BASE_PIOB);
unregister_chrdev(fftled_major,"fftled");
printk("exit fftled\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -