1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup lpc24xx_dma |
---|
5 | * |
---|
6 | * @brief Direct memory access (DMA) support. |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * Copyright (c) 2008-2011 embedded brains GmbH. All rights reserved. |
---|
11 | * |
---|
12 | * embedded brains GmbH |
---|
13 | * Obere Lagerstr. 30 |
---|
14 | * 82178 Puchheim |
---|
15 | * Germany |
---|
16 | * <rtems@embedded-brains.de> |
---|
17 | * |
---|
18 | * The license and distribution terms for this file may be |
---|
19 | * found in the file LICENSE in this distribution or at |
---|
20 | * http://www.rtems.org/license/LICENSE. |
---|
21 | */ |
---|
22 | |
---|
23 | #include <rtems/endian.h> |
---|
24 | |
---|
25 | #include <bsp/lpc24xx.h> |
---|
26 | #include <bsp/dma.h> |
---|
27 | #include <bsp/io.h> |
---|
28 | |
---|
29 | /** |
---|
30 | * @brief Table that indicates if a channel is currently occupied. |
---|
31 | */ |
---|
32 | static bool lpc24xx_dma_channel_occupation [GPDMA_CH_NUMBER]; |
---|
33 | |
---|
34 | void lpc24xx_dma_initialize(void) |
---|
35 | { |
---|
36 | /* Enable module power */ |
---|
37 | lpc24xx_module_enable(LPC24XX_MODULE_GPDMA, LPC24XX_MODULE_PCLK_DEFAULT); |
---|
38 | |
---|
39 | /* Disable module */ |
---|
40 | GPDMA_CONFIG = 0; |
---|
41 | |
---|
42 | /* Reset registers */ |
---|
43 | GPDMA_SOFT_SREQ = 0; |
---|
44 | GPDMA_SOFT_BREQ = 0; |
---|
45 | GPDMA_SOFT_LSREQ = 0; |
---|
46 | GPDMA_SOFT_LBREQ = 0; |
---|
47 | GPDMA_SYNC = 0; |
---|
48 | GPDMA_CH0_CFG = 0; |
---|
49 | GPDMA_CH1_CFG = 0; |
---|
50 | |
---|
51 | /* Enable module */ |
---|
52 | #if BYTE_ORDER == LITTLE_ENDIAN |
---|
53 | GPDMA_CONFIG = GPDMA_CONFIG_EN; |
---|
54 | #else |
---|
55 | GPDMA_CONFIG = GPDMA_CONFIG_EN | GPDMA_CONFIG_MODE; |
---|
56 | #endif |
---|
57 | } |
---|
58 | |
---|
59 | rtems_status_code lpc24xx_dma_channel_obtain(unsigned channel) |
---|
60 | { |
---|
61 | if (channel < GPDMA_CH_NUMBER) { |
---|
62 | rtems_interrupt_level level; |
---|
63 | bool occupation = true; |
---|
64 | |
---|
65 | rtems_interrupt_disable(level); |
---|
66 | occupation = lpc24xx_dma_channel_occupation [channel]; |
---|
67 | lpc24xx_dma_channel_occupation [channel] = true; |
---|
68 | rtems_interrupt_enable(level); |
---|
69 | |
---|
70 | return occupation ? RTEMS_RESOURCE_IN_USE : RTEMS_SUCCESSFUL; |
---|
71 | } else { |
---|
72 | return RTEMS_INVALID_ID; |
---|
73 | } |
---|
74 | } |
---|
75 | |
---|
76 | void lpc24xx_dma_channel_release(unsigned channel) |
---|
77 | { |
---|
78 | if (channel < GPDMA_CH_NUMBER) { |
---|
79 | lpc24xx_dma_channel_occupation [channel] = false; |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | void lpc24xx_dma_channel_disable(unsigned channel, bool force) |
---|
84 | { |
---|
85 | if (channel < GPDMA_CH_NUMBER) { |
---|
86 | volatile lpc24xx_dma_channel *ch = GPDMA_CH_BASE_ADDR(channel); |
---|
87 | uint32_t cfg = ch->cfg; |
---|
88 | |
---|
89 | if (!force) { |
---|
90 | /* Halt */ |
---|
91 | ch->cfg |= GPDMA_CH_CFG_HALT; |
---|
92 | |
---|
93 | /* Wait for inactive */ |
---|
94 | do { |
---|
95 | cfg = ch->cfg; |
---|
96 | } while ((cfg & GPDMA_CH_CFG_ACTIVE) != 0); |
---|
97 | } |
---|
98 | |
---|
99 | /* Disable */ |
---|
100 | ch->cfg &= ~GPDMA_CH_CFG_EN; |
---|
101 | } |
---|
102 | } |
---|