17_DMA驱动

17_DMA驱动

1、DMA介绍

DMA:Direct Memory Access,直接存储器访问
在这里插入图片描述
我们知道,cpu同一时间只能做一件事情,如果cpu执行右边的代码,那岂不是不能做其他事?如上图,DMA是一个独立的模块存在于处理器,DMA是不通过CPU而是直接访问内存,使用DMA,可以释放CPU的"压力",使得它不会一直在做一件事,使用了DMA也能达到直接使用CPU的效果。

字符设备驱动程序结构框架:
在这里插入图片描述

2、dma驱动程序

在请求DMA中断时,查看内核中其他地方是否用到DMA的通道:
在这里插入图片描述
显然33、34、35的DMA通道被占用,需要使用DMA3的36通道:
在这里插入图片描述
所以在入口函数中映射dma寄存器的物理地址为DMA3_BASE_ADDR:
dma_regs = ioremap(DMA3_BASE_ADDR, sizeof(struct s3c_dma_regs));

需要设置的dma寄存器在2440的手册上查看:
在这里插入图片描述

2.7、参数初始化

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/irq.h>
#include <asm/uaccess.h>
#include <asm/irq.h>
#include <asm/io.h>
#include <asm/arch/regs-gpio.h>
#include <asm/hardware.h>
#include <linux/poll.h>
#include <linux/dma-mapping.h>

#define MEM_CPY_NO_DMA 	0
#define MEM_CPY_DMA		1

#define BUF_SIZE	(512*1024)

#define DMA0_BASE_ADDR  0x4B000000
#define DMA1_BASE_ADDR  0x4B000040
#define DMA2_BASE_ADDR  0x4B000080
#define DMA3_BASE_ADDR  0x4B0000C0

struct s3c_dma_regs {
   
	unsigned long disrc;
	unsigned long disrcc;
	unsigned long didst;
	unsigned long didstc;
	unsigned long dcon;
	unsigned long dstat;
	unsigned long dcsrc;
	unsigned long dcdst;
	unsigned long dmasktrig;
};

static char *src;
static u32 src_phys;
static char *dst;
static u32 dst_phys;

2.1、构造主设备号

static int major = 0;

static struct class *cls;

static volatile struct s3c_dma_regs *dma_regs;

static DECLARE_WAIT_QUEUE_HEAD
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

「已注销」

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值