source: rtems/c/src/lib/libbsp/arm/lpc24xx/misc/dma.c @ edf846e4

4.104.115
Last change on this file since edf846e4 was edf846e4, checked in by Sebastian Huber <sebastian.huber@…>, on 05/20/10 at 14:23:13

2010-05-20 Sebastian Huber <sebastian.huber@…>

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