8650ac7f9d9e6ab861549e55fdd9c5ab56b53760
[bertos.git] / bertos / cpu / cortex-m3 / drv / dmac_sam3.h
1 /**
2  * \file
3  * <!--
4  * This file is part of BeRTOS.
5  *
6  * Bertos is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  * As a special exception, you may use this file as part of a free software
21  * library without restriction.  Specifically, if other files instantiate
22  * templates or use macros or inline functions from this file, or you compile
23  * this file and link it with other files to produce an executable, this
24  * file does not by itself cause the resulting executable to be covered by
25  * the GNU General Public License.  This exception does not however
26  * invalidate any other reasons why the executable file might be covered by
27  * the GNU General Public License.
28  *
29  * Copyright 2011 Develer S.r.l. (http://www.develer.com/)
30  *
31  * -->
32  *
33  * \brief DMAC utility interface.
34  *
35  * \author Daniele Basile <asterix@develer.com>
36  */
37
38 #ifndef DRV_DMAC_SAM3_H
39 #define DRV_DMAC_SAM3_H
40
41 #include <cfg/macros.h>
42
43 #include <cpu/types.h>
44 #include <drv/irq_cm3.h>
45
46 typedef void (*dmac_handler_t)(uint32_t status);
47
48 /**
49  * DMA Transfer Descriptor as well as Linked List Item
50  */
51 typedef struct DmacDesc
52 {
53     uint32_t src_addr;     ///< Source buffer address
54     uint32_t dst_addr;     ///< Destination buffer address
55     uint32_t ctrla;       ///< Control A register settings
56     uint32_t ctrlb;       ///< Control B register settings
57     uint32_t dsc_addr;     ///< Next descriptor address
58 } DmacDesc;
59
60 typedef struct Dmac
61 {
62         DmacDesc lli;
63         uint8_t errors;
64         size_t transfer_size;
65         dmac_handler_t handler;
66 } Dmac;
67
68 #define DMAC_ERR_CH_ALREDY_ON    BV(0)
69
70 INLINE void dmac_setSourcesLLI(int ch, DmacDesc *lli, uint32_t src, uint32_t dst, uint32_t desc)
71 {
72         ASSERT(lli);
73         DMAC_CHDR = BV(ch);
74
75         lli->src_addr = src;
76         lli->dst_addr = dst;
77         lli->dsc_addr = desc;
78 }
79
80 void dmac_configureDmaCfgLLI(int ch, DmacDesc *lli, uint32_t cfg);
81 void dmac_setSourcesLLI(int ch, DmacDesc *lli, uint32_t src, uint32_t dst, uint32_t desc);
82 void dmac_configureDmacLLI(int ch, DmacDesc *lli, size_t transfer_size, uint32_t cfg, uint32_t ctrla, uint32_t ctrlb);
83
84 void dmac_setSources(int ch, uint32_t src, uint32_t dst);
85 void dmac_configureDmac(int ch, size_t transfer_size, uint32_t cfg, uint32_t ctrla, uint32_t ctrlb);
86 int dmac_start(int ch);
87 void dmac_stop(int ch);
88 int dmac_error(int ch);
89 bool dmac_enableCh(int ch, dmac_handler_t handler);
90 void dmac_init(void);
91
92 #endif /* DRV_DMAC_SAM3_H */