source: rtems/bsps/arm/lpc176x/start/dma.c @ ba619b7f

Last change on this file since ba619b7f was ba619b7f, checked in by Joel Sherrill <joel@…>, on 03/01/22 at 21:38:20

bsps/arm/: Scripted embedded brains header file clean up

Updates #4625.

  • Property mode set to 100644
File size: 2.6 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup RTEMSBSPsARMLPC176X_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 * The license and distribution terms for this file may be
13 * found in the file LICENSE in this distribution or at
14 * http://www.rtems.org/license/LICENSE.
15 */
16
17#include <rtems/endian.h>
18#include <bsp/dma.h>
19#include <bsp/io.h>
20
21/**
22 * @brief Table that indicates if a channel is currently occupied.
23 */
24static bool lpc176x_dma_channel_occupation[ GPDMA_CH_NUMBER ];
25
26void lpc176x_dma_initialize( void )
27{
28  /* Enable module power */
29  lpc176x_module_enable( LPC176X_MODULE_GPDMA, LPC176X_MODULE_PCLK_DEFAULT );
30
31  /* Disable module */
32  GPDMA_CONFIG = 0u;
33
34  /* Reset registers */
35  GPDMA_SOFT_SREQ = 0u;
36  GPDMA_SOFT_BREQ = 0u;
37  GPDMA_SOFT_LSREQ = 0u;
38  GPDMA_SOFT_LBREQ = 0u;
39  GPDMA_SYNC = 0u;
40  GPDMA_CH0_CFG = 0u;
41  GPDMA_CH1_CFG = 0u;
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
51rtems_status_code lpc176x_dma_channel_obtain( const unsigned channel )
52{
53  rtems_status_code status_code = RTEMS_INVALID_ID;
54
55  if ( channel < GPDMA_CH_NUMBER ) {
56    rtems_interrupt_level level = 0u;
57    bool                  occupation = true;
58
59    rtems_interrupt_disable( level );
60    occupation = lpc176x_dma_channel_occupation[ channel ];
61    lpc176x_dma_channel_occupation[ channel ] = true;
62    rtems_interrupt_enable( level );
63
64    status_code = occupation ? RTEMS_RESOURCE_IN_USE : RTEMS_SUCCESSFUL;
65  }
66
67  /* else implies that the channel is not valid. Also,
68     there is nothing to do. */
69
70  return status_code;
71}
72
73void lpc176x_dma_channel_release( const unsigned channel )
74{
75  if ( channel < GPDMA_CH_NUMBER ) {
76    lpc176x_dma_channel_occupation[ channel ] = false;
77  }
78
79  /* else implies that the channel is not valid. Also,
80     there is nothing to do. */
81}
82
83void lpc176x_dma_channel_disable(
84  const unsigned channel,
85  const bool     force
86)
87{
88  if ( channel < GPDMA_CH_NUMBER ) {
89    volatile lpc176x_dma_channel *ch = GPDMA_CH_BASE_ADDR( channel );
90    uint32_t                      cfg = ch->cfg;
91
92    if ( !force ) {
93      /* Halt */
94      ch->cfg |= GPDMA_CH_CFG_HALT;
95
96      /* Wait for inactive */
97      do {
98        cfg = ch->cfg;
99      } while ( ( cfg & GPDMA_CH_CFG_ACTIVE ) != 0u );
100    }
101
102    /* else implies that the channel is not to be forced. Also,
103       there is nothing to do. */
104
105    /* Disable */
106    ch->cfg &= ~GPDMA_CH_CFG_EN;
107  }
108
109  /* else implies that the channel is not valid. Also,
110     there is nothing to do. */
111}
Note: See TracBrowser for help on using the repository browser.