File indexing completed on 2025-05-11 08:23:03
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 #include <rtems/endian.h>
0037 #include <bsp/dma.h>
0038 #include <bsp/io.h>
0039
0040
0041
0042
0043 static bool lpc176x_dma_channel_occupation[ GPDMA_CH_NUMBER ];
0044
0045 void lpc176x_dma_initialize( void )
0046 {
0047
0048 lpc176x_module_enable( LPC176X_MODULE_GPDMA, LPC176X_MODULE_PCLK_DEFAULT );
0049
0050
0051 GPDMA_CONFIG = 0u;
0052
0053
0054 GPDMA_SOFT_SREQ = 0u;
0055 GPDMA_SOFT_BREQ = 0u;
0056 GPDMA_SOFT_LSREQ = 0u;
0057 GPDMA_SOFT_LBREQ = 0u;
0058 GPDMA_SYNC = 0u;
0059 GPDMA_CH0_CFG = 0u;
0060 GPDMA_CH1_CFG = 0u;
0061
0062
0063 #if BYTE_ORDER == LITTLE_ENDIAN
0064 GPDMA_CONFIG = GPDMA_CONFIG_EN;
0065 #else
0066 GPDMA_CONFIG = GPDMA_CONFIG_EN | GPDMA_CONFIG_MODE;
0067 #endif
0068 }
0069
0070 rtems_status_code lpc176x_dma_channel_obtain( const unsigned channel )
0071 {
0072 rtems_status_code status_code = RTEMS_INVALID_ID;
0073
0074 if ( channel < GPDMA_CH_NUMBER ) {
0075 rtems_interrupt_level level = 0u;
0076 bool occupation = true;
0077
0078 rtems_interrupt_disable( level );
0079 occupation = lpc176x_dma_channel_occupation[ channel ];
0080 lpc176x_dma_channel_occupation[ channel ] = true;
0081 rtems_interrupt_enable( level );
0082
0083 status_code = occupation ? RTEMS_RESOURCE_IN_USE : RTEMS_SUCCESSFUL;
0084 }
0085
0086
0087
0088
0089 return status_code;
0090 }
0091
0092 void lpc176x_dma_channel_release( const unsigned channel )
0093 {
0094 if ( channel < GPDMA_CH_NUMBER ) {
0095 lpc176x_dma_channel_occupation[ channel ] = false;
0096 }
0097
0098
0099
0100 }
0101
0102 void lpc176x_dma_channel_disable(
0103 const unsigned channel,
0104 const bool force
0105 )
0106 {
0107 if ( channel < GPDMA_CH_NUMBER ) {
0108 volatile lpc176x_dma_channel *ch = GPDMA_CH_BASE_ADDR( channel );
0109 uint32_t cfg = ch->cfg;
0110
0111 if ( !force ) {
0112
0113 ch->cfg |= GPDMA_CH_CFG_HALT;
0114
0115
0116 do {
0117 cfg = ch->cfg;
0118 } while ( ( cfg & GPDMA_CH_CFG_ACTIVE ) != 0u );
0119 }
0120
0121
0122
0123
0124
0125 ch->cfg &= ~GPDMA_CH_CFG_EN;
0126 }
0127
0128
0129
0130 }