summaryrefslogtreecommitdiff
path: root/bsp/x1000/drivers/dma.h
blob: 14e420004d5142a31f3d0b14863cb7717811a390 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
 * File      : dma.h
 * This file is part of RT-Thread RTOS
 * COPYRIGHT (C) 2008 - 2012, RT-Thread Development Team
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Change Logs:
 * Date           Author       Notes
 * 2015-11-19     Urey         the first version
 */

#ifndef _DMA_H_
#define _DMA_H_
/*********************************************************************************************************
**   ͷ�ļ�
*********************************************************************************************************/
#include <stdlib.h>
#include <rtdef.h>
#include <rtthread.h>

#ifdef __cplusplus
extern "C"{
#endif
#define RT_DMA_CHANNEL(n)       (n)
#ifndef RT_DMA_MAX_NODES
#	define RT_DMA_MAX_NODES        8
#endif

/*********************************************************************************************************
**   DMA ״̬����
*********************************************************************************************************/
#define RT_DMA_STATUS_IDLE     0                                        /*  DMA ���ڿ���ģʽ            */
#define RT_DMA_STATUS_BUSY     1                                        /*  DMA �������ڹ���            */
#define RT_DMA_STATUS_ERROR    2                                        /*  DMA ���ڴ���״̬            */

/*********************************************************************************************************
**   DMA ��ַ������
*********************************************************************************************************/
#define RT_DMA_ADDR_INC        0                                        /*  ��ַ������ʽ                */
#define RT_DMA_ADDR_FIX        1                                        /*  ��ַ����                    */
#define RT_DMA_ADDR_DEC        2                                        /*  ��ַ���ٷ�ʽ                */

/*********************************************************************************************************
**   DMA ���䷽����
*********************************************************************************************************/
#define RT_DMA_MEM_TO_MEM       0
#define RT_DMA_MEM_TO_DEV       1
#define RT_DMA_DEV_TO_MEM       2
#define RT_DMA_DEV_TO_DEV       3
#define RT_DMA_TRANS_NONE       4

/*********************************************************************************************************
**   DMA ���߿���
*********************************************************************************************************/
#define RT_DMA_BUSWIDTH_UNDEFINED   0
#define RT_DMA_BUSWIDTH_1_BYTE      1
#define RT_DMA_BUSWIDTH_2_BYTES     2
#define RT_DMA_BUSWIDTH_4_BYTES     4
#define RT_DMA_BUSWIDTH_8_BYTES     8

/*********************************************************************************************************
**   DMA ���� ʱ��
*********************************************************************************************************/
#define RT_DMA_EVENT_COMPLETE   0x01
#define RT_DMA_EVENT_ERROR      0x02


/*********************************************************************************************************
**   ���ݽṹ
*********************************************************************************************************/
struct rt_dma_channel;
struct dma_message;
struct dma_config;
struct dma_ops
{
    void        (*reset)(struct rt_dma_channel *dmac);
    rt_size_t   (*trans)(struct rt_dma_channel *dmac,struct dma_message *message);
    int         (*status)(struct rt_dma_channel *dmac);
    int         (*configure)(struct rt_dma_channel *dmac,struct dma_config *config);
};

struct dma_message
{
    rt_uint8_t  *src_addr;                          /*  Դ�˻�������ַ              */
    rt_uint8_t  *dst_addr;                          /*  Ŀ�Ķ˻�������ַ            */
    rt_uint8_t  src_option;                         /*  Դ�˵�ַ�������            */
    rt_uint8_t  dst_option;                         /*  Ŀ�ĵ�ַ�������            */
    rt_size_t   t_size;                             /*  ������ֽ���                */

    rt_uint32_t t_mode;                             /*  ����ģʽ, �Զ���            */

    void 	(*complete_cb)(void *data,void *pbuf);
    void	*complete_arg;
};


struct dma_config
{
    rt_uint32_t direction;
    rt_uint32_t src_addr_width;
    rt_uint32_t dst_addr_width;
    rt_uint32_t src_maxburst;
    rt_uint32_t dst_maxburst;
};

struct rt_dma_channel
{
    int ch;
    rt_list_t               list;               /* channel list     */

    struct dma_config       config;
    struct dma_ops         *ops;

    struct dma_message      msg_list[RT_DMA_MAX_NODES];
    rt_uint16_t get_index;
    rt_uint16_t put_index;

    void       (*start)(struct rt_dma_channel *dmac,struct dma_message *msg);        /* �������� �ص����� */
    void       (*complete)(struct rt_dma_channel *dmac,struct dma_message *msg);     /* ������� �ص����� */

    void       *user_data;          /* �Զ�������   */
};


/*********************************************************************************************************
**   ��������
*********************************************************************************************************/
rt_err_t rt_dma_drv_install(struct rt_dma_channel *dmac, struct dma_ops *ops,struct dma_config *config,void* user_data);
struct rt_dma_channel   *rt_dma_get_channel(int id);
struct dma_message      *rt_dma_get_current_message (struct rt_dma_channel *dmac);
rt_err_t  rt_dma_reset (struct rt_dma_channel *dmac);
rt_err_t  rt_dma_trans_message (struct rt_dma_channel *dmac,struct dma_message* message);
rt_err_t  rt_dma_configture (struct rt_dma_channel *dmac,struct dma_config *config);
rt_err_t rt_dma_contex_service (struct rt_dma_channel *dmac,rt_uint32_t event);



#ifdef __cplusplus
}
#endif

#endif /* _DMA_H_ */