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

📄 pwm.c

📁 fft的工业级的EP9315的开发板的所有驱动程序
💻 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  FFTPWM1_MAJOR  19
devfs_handle_t  dev_handle4; 

void fft_pwminit(void)
{
    unsigned int uiTemp;
    uiTemp = inl(SYSCON_DEVCFG);                           //read the syscon register value
	uiTemp |=(SYSCON_DEVCFG_PonG);                       // or the setting value,activate the matrix 
	SysconSetLocked(SYSCON_DEVCFG, uiTemp);              //write the register
	uiTemp = inl(GPIO_PBDDR);
	uiTemp|=(1<<6);
	outl(uiTemp,GPIO_PBDDR);
	
	outl(0,PWM1_EN);
	outl(0,PWM1_TC);
	outl(0,PWM1_DC);
	outl(1,PWM1_INV);
	outl(1,PWM1_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,PWM1_EN);
       pwmcmd = 0;
    } else if (cmd == 1) {
       pwmtc_old = inl(PWM1_TC);
       if (pwmtc_new >= pwmtc_old) {
          outl(pwmtc_new,PWM1_TC);
          outl(pwmduty_new,PWM1_DC);
       } else {
          outl(pwmduty_new,PWM1_DC);
          outl(pwmtc_new,PWM1_TC);
       }
       if (pwmcmd != 1) {
          printk("switch status!\n");
          outl(1,PWM1_INV);
	      outl(1,PWM1_EN);
	   }
	   pwmcmd = 1;
    }
    
   	return 0;
}
/**************************************
** 函数指针结构: file_operations
** 说明        :
***************************************/
static 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  fftpwm1_init_module(void)
{
   /*int result;
   result=register_chrdev(0,"fftpwm",&fftpwm_fops);           //注册一个设备,得到驱动的主设备号
   if(result<0)
   {
      printk("cannot get fftpwm major number\n");           //没有成功
      return result;
   }*/
   dev_handle4 = devfs_register( NULL, "fftpwm1", DEVFS_FL_DEFAULT, FFTPWM1_MAJOR, 0, S_IFCHR, &fftpwm_fops, NULL);
   printk("congraulation,fftpwm are successful registed\n");
   /*if(fftpwm_major==0)
   {
      fftpwm_major=result;                                 //记录下主设备号
   }*/
    fft_pwminit();
    return 0;
}
/*******************************************************
**  函数原形 : cleanup_module(void)
**  说明     : 在卸载模块时调用
******************************************************/
void fftclrpwm1_module(void)
{
   //unregister_chrdev(fftpwm_major,"fftpwm");
   devfs_unregister (dev_handle4);
   printk("exit fftpwm\n");

}
MODULE_LICENSE("GPL");

module_init(fftpwm1_init_module);
module_exit(fftclrpwm1_module);


⌨️ 快捷键说明

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