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
0038 #include <bsp/lpc24xx.h>
0039 #include <bsp/dma.h>
0040 #include <bsp/io.h>
0041
0042
0043
0044
0045 static bool lpc24xx_dma_channel_occupation [GPDMA_CH_NUMBER];
0046
0047 void lpc24xx_dma_initialize(void)
0048 {
0049
0050 lpc24xx_module_enable(LPC24XX_MODULE_GPDMA, LPC24XX_MODULE_PCLK_DEFAULT);
0051
0052
0053 GPDMA_CONFIG = 0;
0054
0055
0056 GPDMA_SOFT_SREQ = 0;
0057 GPDMA_SOFT_BREQ = 0;
0058 GPDMA_SOFT_LSREQ = 0;
0059 GPDMA_SOFT_LBREQ = 0;
0060 GPDMA_SYNC = 0;
0061 GPDMA_CH0_CFG = 0;
0062 GPDMA_CH1_CFG = 0;
0063
0064
0065 #if BYTE_ORDER == LITTLE_ENDIAN
0066 GPDMA_CONFIG = GPDMA_CONFIG_EN;
0067 #else
0068 GPDMA_CONFIG = GPDMA_CONFIG_EN | GPDMA_CONFIG_MODE;
0069 #endif
0070 }
0071
0072 rtems_status_code lpc24xx_dma_channel_obtain(unsigned channel)
0073 {
0074 if (channel < GPDMA_CH_NUMBER) {
0075 rtems_interrupt_level level;
0076 bool occupation = true;
0077
0078 rtems_interrupt_disable(level);
0079 occupation = lpc24xx_dma_channel_occupation [channel];
0080 lpc24xx_dma_channel_occupation [channel] = true;
0081 rtems_interrupt_enable(level);
0082
0083 return occupation ? RTEMS_RESOURCE_IN_USE : RTEMS_SUCCESSFUL;
0084 } else {
0085 return RTEMS_INVALID_ID;
0086 }
0087 }
0088
0089 void lpc24xx_dma_channel_release(unsigned channel)
0090 {
0091 if (channel < GPDMA_CH_NUMBER) {
0092 lpc24xx_dma_channel_occupation [channel] = false;
0093 }
0094 }
0095
0096 void lpc24xx_dma_channel_disable(unsigned channel, bool force)
0097 {
0098 if (channel < GPDMA_CH_NUMBER) {
0099 volatile lpc24xx_dma_channel *ch = GPDMA_CH_BASE_ADDR(channel);
0100 uint32_t cfg = ch->cfg;
0101
0102 if (!force) {
0103
0104 ch->cfg |= GPDMA_CH_CFG_HALT;
0105
0106
0107 do {
0108 cfg = ch->cfg;
0109 } while ((cfg & GPDMA_CH_CFG_ACTIVE) != 0);
0110 }
0111
0112
0113 ch->cfg &= ~GPDMA_CH_CFG_EN;
0114 }
0115 }