📄 pwm0.c
字号:
/****************************************Copyright (c)**************************************************
** 西安傅立叶电子有限公司
** 研 发 部
** 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 "asm/hardware.h"
#include "asm/io.h"
#include "linux/devfs_fs_kernel.h"
#include "linux/init.h"
#if LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,4,0)
#include "linux/smp_lock.h"
#endif
char kernel_version[]=UTS_RELEASE;
#define FFTPWM0_MAJOR 18
devfs_handle_t dev_handle3;
void fft_pwminit(void)
{
unsigned int uiTemp;
outl(0,PWM0_EN);
outl(0,PWM0_TC);
outl(0,PWM0_DC);
outl(1,PWM0_INV);
outl(1,PWM0_EN);
}
/*******************************************************
*函数原形:read_fftpwm(struct file *file, char *buf, size_t count,loff_t *f_pos)
*参数: buf : 传入该函数的数据缓冲区指针
* count:CAN的通道号
*返回值 : 0
*函数说明:读出接收到的CAN数据
/*******************************************************/
static int read_fftpwm(struct file *file, char *buf, size_t count,loff_t *f_pos)
{
return (0);
}
/*******************************************************
*函数原形:write_fftpwm(struct file *file,const char *buf,size_t count,loff_t *f_pos)
*参数: buf : 传入该函数的数据缓冲区指针
* count:CAN的通道号
*返回值 : 0 说明成功写入
*函数说明:向CAN总线发送数据
/*******************************************************/
static int write_fftpwm(struct file *file,const char *buf,size_t count,loff_t *f_pos)
{
return 0;
}
/*******************************************************
*函数原形:open_fftpwm(struct inode *inode,struct file *file)
*参数:
*返回值 :
*函数说明:
/*******************************************************/
static int open_fftpwm(struct inode *inode,struct file *file)
{
MOD_INC_USE_COUNT;
return 0;
}
/*******************************************************
*函数原形:open_fftpwm(struct inode *inode,struct file *file)
*参数:
*返回值 :
*函数说明:
/*******************************************************/
static int release_fftpwm(struct inode *inode,struct file *file)
{
MOD_DEC_USE_COUNT;
return 0;
}
/***************************************************************************************************
*函数原形:ioctl_fftpwm(struct inode *inode,struct file *file,unsigned int cmd,unsigned long arg)
*参数: cmd : 传入该函数的命令参数
* 0 :判断是否CAN0收到可用数据
1 :判断是否CAN1收到可用数据
3 :初始化CAN0总线
4 :初始化CAN1总线
arg :传入的参数
*返回值 : 0 :接收到有效数据
1 :没有接收到有效数据
3 :成功初始化CAN0
4 :成功初始化CAN1
5 :无效的命令
*函数说明:向CAN总线发送数据
/**************************************************************************************************/
static int ioctl_fftpwm(struct inode *inode,struct file *file,unsigned int cmd,unsigned long arg)
{
int uiTemp;
int pwmtc_new,pwmtc_old;
int pwmduty_new,pwmduty_old;
static pwmcmd = 1;
pwmtc_new = (arg & 0xffff);
printk("pwmtcnew is %d\n",pwmtc_new);
pwmduty_new= (arg >> 16) & 0xffff;
printk("pwmdtnew is %d\n",pwmduty_new);
printk("cmd is %d\n",cmd);
if (cmd == 0) {
outl(0,PWM0_EN);
pwmcmd = 0;
} else if (cmd == 1) {
pwmtc_old = inl(PWM0_TC);
if (pwmtc_new >= pwmtc_old) {
outl(pwmtc_new,PWM0_TC);
outl(pwmduty_new,PWM0_DC);
} else {
outl(pwmduty_new,PWM0_DC);
outl(pwmtc_new,PWM0_TC);
}
if (pwmcmd != 1) {
printk("switch status!\n");
outl(1,PWM0_INV);
outl(1,PWM0_EN);
}
pwmcmd = 1;
}
return 0;
}
/***************************************
** 函数指针结构: file_operations
** 说明 :
***************************************/
struct file_operations fftpwm_fops={
read : read_fftpwm,
write: write_fftpwm,
ioctl: ioctl_fftpwm,
open : open_fftpwm,
release: release_fftpwm,
};
/******************************************************
** 初始化模块:在加载模块时候调用
** 函数原形 : init_module(void)
** 说 明 :不用修改
******************************************************/
static int __init fftpwm0_init_module(void)
{
int result;
dev_handle3 = devfs_register( NULL, "fftpwm0", DEVFS_FL_DEFAULT, FFTPWM0_MAJOR, 0, S_IFCHR, &fftpwm_fops, NULL);
/*result=register_chrdev(0,"fftpwm",&fftpwm_fops); //注册一个设备,得到驱动的主设备号
if(result<0)
{
printk("cannot get fftpwm major number\n"); //没有成功
return result;
}*/
printk("congraulation,fftpwm are successful registed\n");
/*if(fftpwm_major==0)
{
fftpwm_major=result; //记录下主设备号
}*/
fft_pwminit();
return 0;
}
/*******************************************************
** 函数原形 : cleanup_module(void)
** 说明 : 在卸载模块时调用
******************************************************/
static void __exit fftclrpwm0_module(void)
{
//unregister_chrdev(fftpwm_major,"fftpwm");
devfs_unregister (dev_handle3);
outl(0, PWM0_EN);
printk("exit fftpwm\n");
}
MODULE_LICENSE("GPL");
module_init(fftpwm0_init_module);
module_exit(fftclrpwm0_module);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -