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

4.104.115
Last change on this file since ba938b8d was ba938b8d, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on 09/18/09 at 08:05:40

Changes throughout.

  • Property mode set to 100644
File size: 2.2 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  rtems_interrupt_level level;
36
37  /* Enable module power */
38  lpc24xx_module_enable(LPC24XX_MODULE_GPDMA, 0, LPC24XX_MODULE_PCLK_DEFAULT);
39
40  /* Disable module */
41  GPDMA_CONFIG = 0;
42
43  /* Enable module */
44  #if BYTE_ORDER == LITTLE_ENDIAN
45    GPDMA_CONFIG = GPDMA_CONFIG_EN;
46  #else
47    GPDMA_CONFIG = GPDMA_CONFIG_EN | GPDMA_CONFIG_MODE;
48  #endif
49
50  /* Reset registers */
51  GPDMA_SOFT_SREQ = 0;
52  GPDMA_SOFT_BREQ = 0;
53  GPDMA_SOFT_LSREQ = 0;
54  GPDMA_SOFT_LBREQ = 0;
55  GPDMA_SYNC = 0;
56}
57
58rtems_status_code lpc24xx_dma_channel_obtain(unsigned channel)
59{
60  if (channel < GPDMA_CH_NUMBER) {
61    rtems_interrupt_level level;
62    bool occupation = true;
63
64    rtems_interrupt_disable(level);
65    occupation = lpc24xx_dma_channel_occupation [channel];
66    lpc24xx_dma_channel_occupation [channel] = true;
67    rtems_interrupt_enable(level);
68
69    return occupation ? RTEMS_RESOURCE_IN_USE : RTEMS_SUCCESSFUL;
70  } else {
71    return RTEMS_INVALID_ID;
72  }
73}
74
75void lpc24xx_dma_channel_release(unsigned channel)
76{
77  if (channel < GPDMA_CH_NUMBER) {
78    lpc24xx_dma_channel_occupation [channel] = false;
79  }
80}
81
82void lpc24xx_dma_channel_disable(unsigned channel, bool force)
83{
84  if (channel < GPDMA_CH_NUMBER) {
85    volatile lpc24xx_dma_channel *ch = GPDMA_CH_BASE_ADDR(channel);
86    uint32_t cfg = ch->cfg;
87 
88    if (!force) {
89      /* Halt */
90      ch->cfg = SET_FLAG(cfg, GPDMA_CH_CFG_HALT);
91 
92      /* Wait for inactive */
93      do {
94        cfg = ch->cfg;
95      } while (IS_FLAG_SET(cfg, GPDMA_CH_CFG_ACTIVE));
96    }
97 
98    /* Disable */
99    ch->cfg = CLEAR_FLAG(cfg, GPDMA_CH_CFG_EN);
100  }
101}
Note: See TracBrowser for help on using the repository browser.