📄 test.c
字号:
/****************************************Copyright (c)**************************************************
** XIAN FFT-COMPANY STUDYING ROM
**
** http://www.FFTChina.com
**-----------------------------------------文件信息-----------------------------------------------------
**文 件 名: cantest.c
**创 建 人:
**最后修改日期: 2005年6月30日
**描 述: CAN模块测试驱动程序(查询模式)
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
#ifndef __KERNEL__
#define __KERNEL__
#endif
#ifndef MODULE
#define MODULE
#endif
#include "linux/capability.h"
#include "linux/smp_lock.h"
#include "linux/module.h"
#include "linux/devfs_fs_kernel.h"
#include "linux/init.h"
#include "asm/hardware.h"
#include "asm/io.h"
#if LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,4,0)
#include "linux/smp_lock.h"
#endif
#include "iic.c"
#define FFTIIC_MAJOR 16
char kernel_version[]=UTS_RELEASE;
devfs_handle_t dev_handle1;
/*******************************************************
*函数原形:read_fftiic(struct file *file, char *buf, size_t count,loff_t *f_pos)
*参数: buf : 传入该函数的数据缓冲区指针
* count:CAN的通道号
*返回值 : 0
*函数说明:读出接收到的CAN数据
/*******************************************************/
int read_fftiic(struct file *file, char *buf, size_t count,loff_t *f_pos)
{
int i ;
P8563_gettime(buf);
/* for(i = 0;i < 7 ;i++)
printk("time %x\n",buf[i]);*/
return 0;
}
/*******************************************************
*函数原形:write_fftiic(struct file *file,const char *buf,size_t count,loff_t *f_pos)
*参数: buf : 传入该函数的数据缓冲区指针
* count:CAN的通道号
*返回值 : 0 说明成功写入
*函数说明:向CAN总线发送数据
/*******************************************************/
int write_fftiic(struct file *file, const char *buf,size_t count,loff_t *f_pos)
{
P8563_settime(buf,count);
return 0;
}
/*******************************************************
*函数原形:open_fftiic(struct inode *inode,struct file *file)
*参数:
*返回值 :
*函数说明:
/*******************************************************/
int open_fftiic(struct inode *inode,struct file *file)
{
MOD_INC_USE_COUNT;
return 0;
}
/*******************************************************
*函数原形:open_fftiic(struct inode *inode,struct file *file)
*参数:
*返回值 :
*函数说明:
/*******************************************************/
int release_fftiic(struct inode *inode,struct file *file)
{
MOD_DEC_USE_COUNT;
return 0;
}
/***************************************************************************************************
*function name : ioctl_fftiic(struct inode *inode,struct file *file,unsigned int cmd,unsigned long arg)
*parameter : cmd : comand
* 0 : set time and data
1 ::判断是否CAN1收到可用数据
3 :初始化CAN0总线
4 :初始化CAN1总线
arg : argument
*parameter 0 :接收到有效数据
1 :没有接收到有效数据
3 :成功初始化CAN0
4 :成功初始化CAN1
5 :无效的命令
*function description:
/**************************************************************************************************/
static int ioctl_fftiic(struct inode *inode,struct file *file,unsigned int cmd,unsigned long arg)
{
return 0;
}
/**************************************
** 函数指针结构: file_operations
** 说明 :
***************************************/
struct file_operations fftiic_fops={
read : read_fftiic,
write: write_fftiic,
ioctl: ioctl_fftiic,
open : open_fftiic,
release: release_fftiic,
};
/******************************************************
** 初始化模块:在加载模块时候调用
** 函数原形 : init_module(void)
** 说 明 :不用修改
******************************************************/
static int __init fftiic_init_module(void)
{
//int result;
int time=10000;
int i,rdat=0;
char buf[4];
/*result=register_chrdev(0,"fftiic",&fftiic_fops); //注册一个设备,得到驱动的主设备号
if(result<0)
{
printk("cannot get fftiic major number\n"); //没有成功
return result;
}*/
dev_handle1 = devfs_register( NULL, "fftiic", DEVFS_FL_DEFAULT, FFTIIC_MAJOR, 0, S_IFCHR, &fftiic_fops, NULL);
printk("congraulation,fftiic are successful registed\n");
outl(0x03,GPIO_EEDRIVE); //init io port to be IIC interface
outl(0x03,GPIO_PGDDR);
P8563_init();
/*if(fftiic_major==0)
{
fftiic_major=result; //记录下主设备号
}*/
return 0;
}
/*******************************************************
** 函数原形 : cleanup_module(void)
** 说明 : 在卸载模块时调用
******************************************************/
static void __exit fftclriic_module(void)
{
//unregister_chrdev(fftiic_major,"fftiic");
devfs_unregister (dev_handle1);
printk("exit fftiic\n");
}
MODULE_LICENSE("GPL");
module_init(fftiic_init_module);
module_exit(fftclriic_module);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -