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

📄 pwm.c

📁 s3c44b0 uclinux pwm 驱动与相应的makefile。
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************Copyright (c)**************************************************
**                               Guangzou ZLG-MCU Development Co.,LTD.
**                                     graduate school
**                                 http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name:			pwm.c
** Last modified Date:  2005-04-21
** Last Version:		1.0
** Descriptions:		This is a Kernel module for uClinux 2.4.x .**                      This module let uClinux 2.4.x can use pwm. 
**------------------------------------------------------------------------------------------------------
** Created by:			Chenmingji
** Created date:		2005-04-21
** Version:				1.0
** Descriptions:		The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**

********************************************************************************************************/
#define IN_PWM#include "config.h"/********************************************************************************************************
              function announce********************************************************************************************************/
#if 0static loff_t pwm_llseek(struct file *filp, loff_t off, int whence);static ssize_t pwm_read(struct file *filp, char *buf, size_t count, loff_t *f_pos);static ssize_t pwm_write(struct file *filp, const char *buf, size_t count, loff_t *f_pos);#endifstatic int pwm_open(struct inode *inode, struct file *filp);static int pwm_release(struct inode *inode, struct file *filp); static int pwm_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,		              unsigned long param);int  pwm_init(void);void pwm_cleanup(void);
static void pwm_irq_handle(int irq, void *dev_id, struct pt_regs *regs);/********************************************************************************************************
              function announce********************************************************************************************************/
#define MAJOR_NR majormodule_init(pwm_init);module_exit(pwm_cleanup);MODULE_PARM(major, "i");MODULE_LICENSE("Proprietary");MODULE_DESCRIPTION("Guangzou ZLG-MCU Development Co.,LTD.\ngraduate school\nhttp://www.zlgmcu.com");MODULE_SUPPORTED_DEVICE("uClinux2.4.x LPC2200 pwm");MODULE_AUTHOR("chenmingji");/*********************************************************************************************************
**                  "全局和静态变量在这里定义"         
**        global variables and static variables define here
********************************************************************************************************/
static int major = PWM_MAJOR_NR;
static u32 RunTime;static u32 PinSel0Save, PinSel1Save;
static unsigned int usage;/********************************************************************************************************/
static struct file_operations pwm_fops =        /* driver info  */{    owner:      THIS_MODULE,#if 0    llseek:     pwm_llseek,    read:       pwm_read,    write:      pwm_write,#endif    ioctl:      pwm_ioctl,    open:       pwm_open,    release:    pwm_release,};#if 0/*********************************************************************************************************
** Function name: pwm_llseek
** Descriptions:  move read and write point
** Input: filp:   pointer of file
**        off:    ofset
**        whence: move mode
**                0: seek set
**                1: seek file' current point
**                2: seek file' end
** Output :      new point
** Created by:   Chenmingji
** Created Date: 2005-4-21
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        static loff_t pwm_llseek(struct file *filp, loff_t off, int whence){    return 0;}/*********************************************************************************************************
** Function name: pwm_read
** Descriptions:  read device
** Input: filp:   pointer of file
**        buf:    buf for save data
**        count:  size for read
**        f_pos:  *f_pos = read point
** Output : read size    
** Created by:   Chenmingji
** Created Date: 2005-4-21
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        static ssize_t pwm_read(struct file *filp, char *buf, size_t count,                           loff_t *f_pos){    return 0;}/*********************************************************************************************************
** Function name: pwm_write
** Descriptions:  write device
** Input: filp:   pointer of file
**        buf:    buf to write data
**        count:  size for read
**        f_pos:  *f_pos = read point
** Output : write size    
** Created by:   Chenmingji
** Created Date: 2005-4-21
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        static ssize_t pwm_write(struct file *filp, const char *buf, size_t count,                            loff_t *f_pos){    return 0;}#endif                /*********************************************************************************************************
** Function name: pwm_open
** Descriptions:  open device
** Input:inode:   information of device
**       filp:    pointer of file
** Output 0:      OK
**        other:  not OK
** Created by:    Chenmingji
** Created Date:  2005-4-21
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        static int pwm_open(struct inode *inode, struct file *filp){
    unsigned long flag;    unsigned long temp;
    if (usage == 0)
    {
        request_irq(S3C44B0X_INTERRUPT_TIMER2, pwm_irq_handle, SA_INTERRUPT, "my" DEVICE_NAME, NULL);
        local_irq_save(flag);        PinSel0Save = inl(S3C44B0X_PCONE) &(0x03<<10);
        PinSel1Save = inl(S3C44B0X_PUPE) & (0x01 << 5);
        outl((0x01<<11), S3C44B0X_I_ISPC);
//        temp = inl(S3C44B0X_PCONE);//        temp &= (~(0x03<<10));//        temp |= (0x02<<10);//        outl(temp,S3C44B0X_PCONE);        temp = inl(S3C44B0X_TCFG0);        temp &= 0xffff00ff;        outl(temp,S3C44B0X_TCFG0);        temp = inl(S3C44B0X_TCFG1);        temp &= (~(0x0F<<8));        temp |= (0x03<<8);        outl(temp,S3C44B0X_TCFG1);        outl(5000,S3C44B0X_TCNTB2);        outl(1000,S3C44B0X_TCMPB2);        temp = inl(S3C44B0X_TCON);        temp &= (~(0x0f<<12));        temp |= (0x01<<13);        outl(temp,S3C44B0X_TCON);        temp &= (~(0x0f<<12));        temp |= (0x09<<12);        outl(temp,S3C44B0X_TCON); 
        RunTime = 0;
        local_irq_restore(flag);    }    usage++;
    MOD_INC_USE_COUNT;    return 0;          /* success */} /*********************************************************************************************************
** Function name: pwm_release
** Descriptions:  release device
** Input:inode:   information of device
**       filp:    pointer of file
** Output 0:      OK
**        other:  not OK
** Created by:    Chenmingji
** Created Date:  2005-4-21
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        static int pwm_release(struct inode *inode, struct file *filp) {    unsigned long flag;    unsigned long temp;
    MOD_DEC_USE_COUNT;    usage--;
    if (usage == 0)
    {
        local_irq_save(flag);
       temp = inl(S3C44B0X_TCON);       temp &= (~(0x0f<<12));       outl(temp,S3C44B0X_TCON);        outl(PinSel0Save | (inl(S3C44B0X_PCONE) & (~(0x03<<10))), S3C44B0X_PCONE);
        outl(PinSel1Save | (inl(S3C44B0X_PUPE) & (~(0x01<<5))), S3C44B0X_PUPE);
        local_irq_restore(flag);        free_irq(S3C44B0X_INTERRUPT_TIMER2, NULL);
    }
    return(0); } 

⌨️ 快捷键说明

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