aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios-contrib/os/hal/ports/MSP430X/hal_dma_lld.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios-contrib/os/hal/ports/MSP430X/hal_dma_lld.h')
-rw-r--r--lib/chibios-contrib/os/hal/ports/MSP430X/hal_dma_lld.h173
1 files changed, 173 insertions, 0 deletions
diff --git a/lib/chibios-contrib/os/hal/ports/MSP430X/hal_dma_lld.h b/lib/chibios-contrib/os/hal/ports/MSP430X/hal_dma_lld.h
new file mode 100644
index 000000000..dd707b324
--- /dev/null
+++ b/lib/chibios-contrib/os/hal/ports/MSP430X/hal_dma_lld.h
@@ -0,0 +1,173 @@
1/*
2 ChibiOS - Copyright (C) 2016 Andrew Wygle aka awygle
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17/**
18 * @file MSP430X/hal_dma_lld.c
19 * @brief MSP430X DMA subsystem low level driver header.
20 * @note This driver is used as a DMA engine for the other
21 * low level drivers.
22 *
23 * @addtogroup MSP430X_DMA
24 * @{
25 */
26
27#ifndef HAL_MSP430X_DMA_H
28#define HAL_MSP430X_DMA_H
29
30#if (HAL_USE_DMA == TRUE) || defined(__DOXYGEN__)
31
32/*===========================================================================*/
33/* Driver constants. */
34/*===========================================================================*/
35
36#define MSP430X_DMA_SINGLE DMADT_0
37#define MSP430X_DMA_BLOCK DMADT_1
38#define MSP430X_DMA_BURST DMADT_2
39
40#define MSP430X_DMA_SRCINCR DMASRCINCR_3
41#define MSP430X_DMA_SRCDECR DMASRCINCR_2
42#define MSP430X_DMA_DSTINCR DMADSTINCR_3
43#define MSP430X_DMA_DSTDECR DMADSTINCR_2
44
45#define MSP430X_DMA_SRCBYTE DMASRCBYTE
46#define MSP430X_DMA_DSTBYTE DMADSTBYTE
47#define MSP430X_DMA_SRCWORD 0
48#define MSP430X_DMA_DSTWORD 0
49
50/*===========================================================================*/
51/* Driver pre-compile time settings. */
52/*===========================================================================*/
53
54/*===========================================================================*/
55/* Derived constants and error checks. */
56/*===========================================================================*/
57
58#if !defined(DMA_BASE) && !defined(MSP430X_DMA_SOFTWARE)
59#error "The MSP430 device in use does not support DMA. Explicitly enable"
60#error "software emulation by defining MSP430X_DMA_SOFTWARE."
61#endif
62
63#if defined(__MSP430_HAS_DMAX_1__) || defined(__MSP430X_HAS_DMA_1__)
64#define MSP430X_DMA_CHANNELS 1
65#elif defined(__MSP430_HAS_DMAX_3__) || defined(__MSP430X_HAS_DMA_3__)
66#define MSP430X_DMA_CHANNELS 3
67#elif defined(__MSP430_HAS_DMAX_6__) || defined(__MSP430X_HAS_DMA_6__)
68#define MSP430X_DMA_CHANNELS 6
69#else
70#error "Unexpected error - how many DMA channels does your MSP have?"
71#endif
72
73/*===========================================================================*/
74/* Driver data structures and types. */
75/*===========================================================================*/
76
77/**
78 * @brief Type of DMA callback function pointer.
79 */
80typedef void (*msp430x_dma_cbp_t)(void * args);
81
82/**
83 * @brief DMA callback, function and argument.
84 */
85typedef struct {
86 msp430x_dma_cbp_t callback; /**< @brief Callback function pointer */
87 void * args; /**< @brief Callback function arguments */
88} msp430x_dma_cb_t;
89
90/**
91 * @brief MSP430X DMA request structure.
92 */
93typedef struct {
94 const void * source_addr; /**< @brief Source address */
95 void * dest_addr; /**< @brief Destination address */
96 uint16_t size; /**< @brief Number of values to transfer */
97 uint16_t addr_mode; /**< @brief Address manipulation mode */
98 uint16_t data_mode; /**< @brief Data sizes (b2b, w2w, b2w, w2b) */
99 uint16_t transfer_mode; /**< @brief Transfer mode (single, block, burst) */
100 uint16_t trigger; /**< @brief Triggering event (see datasheet) */
101 msp430x_dma_cb_t callback; /**< @brief Callback function and arguments */
102} msp430x_dma_req_t;
103
104/**
105 * @brief MSP430X DMA channel register structure.
106 */
107typedef struct {
108 volatile uint16_t ctl; /**< @brief Control register */
109 volatile uint32_t sa; /**< @brief Source address register */
110 volatile uint32_t da; /**< @brief Destination address register */
111 volatile uint16_t sz; /**< @brief Size register */
112 volatile uint16_t pad1;
113 volatile uint16_t pad2;
114} msp430x_dma_ch_reg_t;
115
116/**
117 * @brief MSP430X DMA controller register structure.
118 */
119typedef struct {
120 volatile uint8_t tsel0; /**< @brief Trigger select for channel 0 */
121 volatile uint8_t tsel1; /**< @brief Trigger select for channel 1 */
122 volatile uint8_t tsel2; /**< @brief Trigger select for channel 2 */
123 volatile uint8_t tsel3; /**< @brief Trigger select for channel 3 */
124 volatile uint8_t tsel4; /**< @brief Trigger select for channel 4 */
125 volatile uint8_t tsel5; /**< @brief Trigger select for channel 5 */
126 volatile uint8_t tsel6; /**< @brief Trigger select for channel 6 */
127 volatile uint8_t tsel7; /**< @brief Trigger select for channel 7 */
128 volatile uint16_t ctl4; /**< @brief Controller register 4 */
129} msp430x_dma_ctl_reg_t;
130
131/**
132 * @brief MSP430X DMA channel structure.
133 */
134typedef struct {
135 msp430x_dma_ch_reg_t * registers; /**< @brief Pointer to channel registers */
136 uint8_t index; /**< @brief Index of channel trigger control register */
137 msp430x_dma_cb_t * cb; /**< @brief Pointer to callback function and args */
138} msp430x_dma_ch_t;
139
140/*===========================================================================*/
141/* Driver macros. */
142/*===========================================================================*/
143
144/**
145 * @brief Identifies a DMA trigger using a mnemonic.
146 *
147 * @param[in] mnem The mnemonic for the trigger, e.g. UCA0RXIFG to trigger
148 * on UART receive.
149 */
150#define DMA_TRIGGER_MNEM(mnem) DMA0TSEL__##mnem
151
152/** @} */
153
154/*===========================================================================*/
155/* External declarations. */
156/*===========================================================================*/
157
158#ifdef __cplusplus
159extern "C" {
160#endif
161void dmaInit(void);
162int dmaRequestS(msp430x_dma_req_t * request, systime_t timeout);
163bool dmaAcquireI(msp430x_dma_ch_t * channel, uint8_t index);
164void dmaTransfer(msp430x_dma_ch_t * channel, msp430x_dma_req_t * request);
165void dmaRelease(msp430x_dma_ch_t * channel);
166
167#ifdef __cplusplus
168}
169#endif
170
171#endif /* HAL_USE_DMA == true */
172
173#endif /* HAL_MSP430X_DMA_H */