资源简介
该代码基于exynos4412编写,基于kerenl3.14的驱动模块,加载后执行音乐程序开始播放
代码片段和文件信息
/*************************************************************************
> File Name: pmw.c
> Author: BlueMoon
> Mail: Leeruile@outlook.com
> Created Time: 2018年08月28日 星期二 14时17分26秒
************************************************************************/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include“pmw.h“
#define TCFG0 0x00
#define TCFG1 0x04
#define TCON 0x08
#define TCNTB1 0x0c
#define TCMPB1 0x10
//主次设备号定义
#define PMW_MAJOR 410
#define PMW_MIJOR 0
#define PMW_NUM 1
dev_t dev_ID;
void auto_create_node(dev_t dev_ID);
struct _pmw
{
unsigned int *gpdcon;
void __iomem *timer_base;
struct cdev cdev;
}*pmw;
//定义字符设备
//定义寄存器变量
struct resource* pmw_con;
struct resource* pmw_timer_base;
unsigned int* gpdcon;
unsigned int* gpddat;
struct class* pmw_class;
int ret;
#define dev_node_name “PMW“
static int pmw_open(struct inode *inodestruct file *file)
{
writel((readl(pmw->gpdcon) & ~0xf) | 0x2pmw->gpdcon);
writel(readl(pmw->timer_base + TCFG0) | 0xffpmw->timer_base + TCFG0);
writel((readl(pmw->timer_base + TCFG1) & ~0xf) | 0x2 pmw->timer_base + TCFG1);
writel(300 pmw->timer_base + TCNTB1);
writel(150 pmw->timer_base + TCMPB1);
writel((readl(pmw->timer_base + TCON) & ~0x1f) | 0x2 pmw->timer_base + TCON);
//writel((readl(pwm->timer_base + TCON) & ~(0xf << 8)) | (0x9 << 8) pwm->timer_base + TCON);
return 0;
}
static int pmw_release(struct inode *inode struct file *file)
{
writel(readl(pmw->timer_base + TCON) & ~0xf pmw->timer_base + TCON);
return 0;
}
static long pmw_ioctl(struct file *file unsigned int cmd unsigned long arg)
{
int data = 0;
if (_IOC_TYPE(cmd) != ‘K‘)
return -ENOTTY;
if (_IOC_NR(cmd) > 3)
return -ENOTTY;
if (_IOC_DIR(cmd) == _IOC_WRITE)
if (copy_from_user(&data (void *)arg sizeof(data)))
return -EFAULT;
switch(cmd)
{
case PWM_ON:
writel((readl(pmw->timer_base + TCON) & ~0x1f) | 0x9 pmw->timer_base + TCON);
break;
case PWM_OFF:
writel(readl(pmw->timer_base + TCON) & ~0x1f pmw->timer_base + TCON);
break;
case SET_PRE:
writel(readl(pmw->timer_base + TCON) & ~0x1f pmw->timer_base + TCON);
writel((readl(pmw->timer_base + TCFG0) & ~0xff) | (data & 0xff) pmw->timer_base + TCFG0);
writel((readl(pmw->timer_base + TCON) & ~0x1f) | 0x9 pmw->timer_base + TCON);
break;
case SET_CNT:
writel(data pmw->timer_base + TCNTB1);
writel(data >> 1 pmw->timer_base + TCMPB1);
break;
}
return 0;
}
//定义操作函数
static struct file_operations pmw_fops = {
.owner = THIS_MODULE
.open = pmw_open
.release = pmw_release
.unlocked_ioctl
- 上一篇:STM32的硬件SPI驱动的ILI9341代码
- 下一篇:姓名抽奖系统
评论
共有 条评论