当前位置:   article > 正文

S32 Design Studio PE工具配置DMA

S32 Design Studio PE工具配置DMA

工具配置

DMA位置跟设备不一样,在Referenced_components里面。

Configurations里面就默认配置就行

channels是比较重要的,一条信号传输用到一个通道。可以选择UART、ADC、CAN之类的,这里用在了SPI通讯里面。

生成代码

在 Generated_Code\dmaController1.c里面,对应刚才配置的信息。

  1. edma_state_t dmaController1_State;
  2. edma_chn_state_t dmaController1Chn0_State;
  3. edma_chn_state_t dmaController1Chn1_State;
  4. edma_chn_state_t * const edmaChnStateArray[] = {
  5. &dmaController1Chn0_State,
  6. &dmaController1Chn1_State
  7. };
  8. edma_channel_config_t dmaController1Chn0_Config = {//通道0配置
  9. .channelPriority = EDMA_CHN_DEFAULT_PRIORITY,
  10. .virtChnConfig = EDMA_CHN0_NUMBER,
  11. .source = EDMA_REQ_LPSPI0_RX,
  12. .callback = NULL,
  13. .callbackParam = NULL,
  14. .enableTrigger = false
  15. };
  16. edma_channel_config_t dmaController1Chn1_Config = {//通道1配置
  17. .channelPriority = EDMA_CHN_DEFAULT_PRIORITY,
  18. .virtChnConfig = EDMA_CHN1_NUMBER,
  19. .source = EDMA_REQ_LPSPI0_TX,
  20. .callback = NULL,
  21. .callbackParam = NULL,
  22. .enableTrigger = false
  23. };
  24. const edma_channel_config_t * const edmaChnConfigArray[] = {//通道数组
  25. &dmaController1Chn0_Config,
  26. &dmaController1Chn1_Config
  27. };
  28. const edma_user_config_t dmaController1_InitConfig0 = {//控制器配置
  29. .chnArbitration = EDMA_ARBITRATION_FIXED_PRIORITY,
  30. .haltOnError = false
  31. };

接口使用

EDMA_DRV_Init

初始化接口,基本上调用这个就能把DMA用起来,里面的参数都是自动生成的。

EDMA_DRV_Init(&dmaController1_State,&dmaController1_InitConfig0,edmaChnStateArray, edmaChnConfigArray,EDMA_CONFIGURED_CHANNELS_COUNT);

函数原型

  1. /*FUNCTION**********************************************************************
  2. *
  3. * Function Name : EDMA_DRV_Init
  4. * Description : Initializes the eDMA module.
  5. *
  6. * Implements : EDMA_DRV_Init_Activity
  7. *END**************************************************************************/
  8. status_t EDMA_DRV_Init(edma_state_t *edmaState,
  9. const edma_user_config_t *userConfig,
  10. edma_chn_state_t * const chnStateArray[],
  11. const edma_channel_config_t * const chnConfigArray[],
  12. uint32_t chnCount)
  13. {
  14. uint32_t index = 0U;
  15. DMA_Type *edmaRegBase = NULL;
  16. IRQn_Type irqNumber = NotAvail_IRQn;
  17. status_t edmaStatus = STATUS_SUCCESS;
  18. status_t chnInitStatus = STATUS_SUCCESS;
  19. #if defined (CUSTOM_DEVASSERT) || defined (DEV_ERROR_DETECT)
  20. uint32_t freq = 0U;
  21. status_t clockManagerStatus = STATUS_SUCCESS;
  22. #endif
  23. /* Check the state and configuration structure pointers are valid */
  24. DEV_ASSERT((edmaState != NULL) && (userConfig != NULL));
  25. /* Check the module has not already been initialized */
  26. DEV_ASSERT(s_virtEdmaState == NULL);
  27. #if defined (CUSTOM_DEVASSERT) || defined (DEV_ERROR_DETECT)
  28. /* Check that eDMA and DMAMUX modules are clock gated on */
  29. for (index = 0U; index < (uint32_t)DMA_INSTANCE_COUNT; index++)
  30. {
  31. clockManagerStatus = CLOCK_SYS_GetFreq(s_edmaClockNames[index], &freq);
  32. DEV_ASSERT(clockManagerStatus == STATUS_SUCCESS);
  33. }
  34. #ifdef FEATURE_DMAMUX_AVAILABLE
  35. for (index = 0U; index < (uint32_t)DMAMUX_INSTANCE_COUNT; index++)
  36. {
  37. clockManagerStatus = CLOCK_SYS_GetFreq(s_dmamuxClockNames[index], &freq);
  38. DEV_ASSERT(clockManagerStatus == STATUS_SUCCESS);
  39. }
  40. #endif /* FEATURE_DMAMUX_AVAILABLE */
  41. #endif /* (CUSTOM_DEVASSERT) || defined (DEV_ERROR_DETECT) */
  42. /* Save the runtime state structure for the driver */
  43. s_virtEdmaState = edmaState;
  44. /* Clear the state structure. */
  45. EDMA_DRV_ClearStructure((uint8_t *)s_virtEdmaState, sizeof(edma_state_t));
  46. /* Init all DMA instances */
  47. for(index = 0U; index < (uint32_t)DMA_INSTANCE_COUNT; index++)
  48. {
  49. edmaRegBase = s_edmaBase[index];
  50. /* Init eDMA module on hardware level. */
  51. EDMA_Init(edmaRegBase);
  52. #ifdef FEATURE_DMA_HWV3
  53. /* Set arbitration mode */
  54. EDMA_SetChannelArbitrationMode(edmaRegBase, userConfig->chnArbitration);
  55. #else /* FEATURE_DMA_HWV3 */
  56. /* Set arbitration mode */
  57. EDMA_SetChannelArbitrationMode(edmaRegBase, userConfig->chnArbitration);
  58. #if (FEATURE_DMA_CHANNEL_GROUP_COUNT > 0x1U)
  59. EDMA_SetGroupArbitrationMode(edmaRegBase, userConfig->groupArbitration);
  60. EDMA_SetGroupPriority(edmaRegBase, userConfig->groupPriority);
  61. #endif /* (FEATURE_DMA_CHANNEL_GROUP_COUNT > 0x1U) */
  62. #endif /* FEATURE_DMA_HWV3 */
  63. /* Set 'Halt on error' configuration */
  64. EDMA_SetHaltOnErrorCmd(edmaRegBase, userConfig->haltOnError);
  65. }
  66. #if defined FEATURE_DMA_HAS_ERROR_IRQ
  67. /* Enable the error interrupts for eDMA module. */
  68. for (index = 0U; index < (uint32_t)FEATURE_DMA_VIRTUAL_ERROR_INTERRUPT_LINES; index++)
  69. {
  70. /* Enable channel interrupt ID. */
  71. irqNumber = s_edmaErrIrqId[index];
  72. INT_SYS_EnableIRQ(irqNumber);
  73. }
  74. #endif
  75. /* Register all edma channel interrupt handlers into vector table. */
  76. for (index = 0U; index < (uint32_t)FEATURE_DMA_VIRTUAL_CHANNELS_INTERRUPT_LINES; index++)
  77. {
  78. /* Enable channel interrupt ID. */
  79. irqNumber = s_edmaIrqId[index];
  80. INT_SYS_EnableIRQ(irqNumber);
  81. }
  82. #ifdef FEATURE_DMAMUX_AVAILABLE
  83. /* Initialize all DMAMUX instances */
  84. for (index = 0U; index < (uint32_t)DMAMUX_INSTANCE_COUNT; index++)
  85. {
  86. DMAMUX_Init(s_dmaMuxBase[index]);
  87. }
  88. #endif
  89. /* Initialize the channels based on configuration list */
  90. if ((chnStateArray != NULL) && (chnConfigArray != NULL))
  91. {
  92. for (index = 0U; index < chnCount; index++)
  93. {
  94. chnInitStatus = EDMA_DRV_ChannelInit(chnStateArray[index], chnConfigArray[index]);
  95. if (chnInitStatus != STATUS_SUCCESS)
  96. {
  97. edmaStatus = chnInitStatus;
  98. }
  99. }
  100. }
  101. return edmaStatus;
  102. }

EDMA_DRV_Deinit

逆初始化接口

  1. /*FUNCTION**********************************************************************
  2. *
  3. * Function Name : EDMA_DRV_Deinit
  4. * Description : Deinitialize EDMA.
  5. *
  6. * Implements : EDMA_DRV_Deinit_Activity
  7. *END**************************************************************************/
  8. status_t EDMA_DRV_Deinit(void)
  9. {
  10. uint32_t index = 0U;
  11. IRQn_Type irqNumber = NotAvail_IRQn;
  12. const edma_chn_state_t *chnState = NULL;
  13. #if defined FEATURE_DMA_HAS_ERROR_IRQ
  14. /* Disable the error interrupts for eDMA module. */
  15. for (index = 0U; index < (uint32_t)FEATURE_DMA_VIRTUAL_ERROR_INTERRUPT_LINES; index++)
  16. {
  17. /* Enable channel interrupt ID. */
  18. irqNumber = s_edmaErrIrqId[index];
  19. INT_SYS_DisableIRQ(irqNumber);
  20. }
  21. #endif
  22. if (s_virtEdmaState != NULL)
  23. {
  24. /* Release all edma channel. */
  25. for (index = 0U; index < (uint32_t)FEATURE_DMA_VIRTUAL_CHANNELS; index++)
  26. {
  27. /* Release all channels. */
  28. chnState = s_virtEdmaState->virtChnState[index];
  29. if (chnState != NULL)
  30. {
  31. (void) EDMA_DRV_ReleaseChannel(chnState->virtChn);
  32. }
  33. }
  34. for (index = 0U; index < (uint32_t)FEATURE_DMA_VIRTUAL_CHANNELS_INTERRUPT_LINES; index++)
  35. {
  36. /* Disable channel interrupts. */
  37. irqNumber = s_edmaIrqId[index];
  38. INT_SYS_DisableIRQ(irqNumber);
  39. }
  40. }
  41. s_virtEdmaState = NULL;
  42. return STATUS_SUCCESS;
  43. }

EDMA_DRV_ChannelInit

通道初始化,在初始化接口里面有调用,不用再另外调用。

  1. /*FUNCTION**********************************************************************
  2. *
  3. * Function Name : EDMA_DRV_ChannelInit
  4. * Description : Initialize EDMA channel.
  5. *
  6. * Implements : EDMA_DRV_ChannelInit_Activity
  7. *END**************************************************************************/
  8. status_t EDMA_DRV_ChannelInit(edma_chn_state_t *edmaChannelState,
  9. const edma_channel_config_t *edmaChannelConfig)
  10. {
  11. /* Check the state and configuration structure pointers are valid */
  12. DEV_ASSERT((edmaChannelState != NULL) && (edmaChannelConfig != NULL));
  13. /* Check if the module is initialized */
  14. DEV_ASSERT(s_virtEdmaState != NULL);
  15. /* Check the channel has not already been allocated */
  16. DEV_ASSERT(s_virtEdmaState->virtChnState[edmaChannelConfig->virtChnConfig] == NULL);
  17. /* Check if the channel defined by user in the channel configuration structure is valid */
  18. DEV_ASSERT(edmaChannelConfig->virtChnConfig < FEATURE_DMA_VIRTUAL_CHANNELS);
  19. /* Get DMA instance from virtual channel */
  20. uint8_t dmaInstance = (uint8_t)FEATURE_DMA_VCH_TO_INSTANCE(edmaChannelConfig->virtChnConfig);
  21. /* Get DMA channel from virtual channel */
  22. uint8_t dmaChannel = (uint8_t)FEATURE_DMA_VCH_TO_CH(edmaChannelConfig->virtChnConfig);
  23. /* Get virtual channel value */
  24. uint8_t virtualChannel = edmaChannelConfig->virtChnConfig;
  25. /* Get status */
  26. status_t retStatus = STATUS_SUCCESS;
  27. /* Load corresponding DMA instance pointer */
  28. DMA_Type *edmaRegBase = s_edmaBase[dmaInstance];
  29. /* Reset the channel state structure to default value. */
  30. EDMA_DRV_ClearStructure((uint8_t *)edmaChannelState, sizeof(edma_chn_state_t));
  31. #ifdef FEATURE_DMAMUX_AVAILABLE
  32. retStatus = EDMA_DRV_SetChannelRequestAndTrigger(edmaChannelConfig->virtChnConfig, (uint8_t)edmaChannelConfig->source, edmaChannelConfig->enableTrigger);
  33. #endif
  34. /* Clear the TCD registers for this channel */
  35. EDMA_TCDClearReg(edmaRegBase, dmaChannel);
  36. #ifdef FEATURE_DMAMUX_AVAILABLE
  37. if (retStatus == STATUS_SUCCESS)
  38. #endif
  39. {
  40. /* Set virtual channel state */
  41. s_virtEdmaState->virtChnState[virtualChannel] = edmaChannelState;
  42. /* Set virtual channel value */
  43. s_virtEdmaState->virtChnState[virtualChannel]->virtChn = virtualChannel;
  44. /* Set virtual channel status to normal */
  45. s_virtEdmaState->virtChnState[virtualChannel]->status = EDMA_CHN_NORMAL;
  46. /* Enable error interrupt for this channel */
  47. EDMA_SetErrorIntCmd(edmaRegBase, dmaChannel, true);
  48. #ifdef FEATURE_DMA_HWV3
  49. /* Put the channel in a priority group, as defined in configuration */
  50. EDMA_SetChannelPriorityGroup(edmaRegBase, dmaChannel, edmaChannelConfig->groupPriority);
  51. #endif
  52. /* Set the channel priority, as defined in the configuration, only if fixed arbitration mode is selected */
  53. if ((EDMA_GetChannelArbitrationMode(edmaRegBase) == EDMA_ARBITRATION_FIXED_PRIORITY) &&
  54. (edmaChannelConfig->channelPriority != EDMA_CHN_DEFAULT_PRIORITY))
  55. {
  56. EDMA_SetChannelPriority(edmaRegBase, dmaChannel, edmaChannelConfig->channelPriority);
  57. }
  58. /* Install the user callback */
  59. retStatus = EDMA_DRV_InstallCallback(edmaChannelConfig->virtChnConfig, edmaChannelConfig->callback, edmaChannelConfig->callbackParam);
  60. }
  61. return retStatus;
  62. }

EDMA_DRV_InstallCallback

安装回调函数

  1. /*FUNCTION**********************************************************************
  2. *
  3. * Function Name : EDMA_DRV_InstallCallback
  4. * Description : Register callback function and parameter.
  5. *
  6. * Implements : EDMA_DRV_InstallCallback_Activity
  7. *END**************************************************************************/
  8. status_t EDMA_DRV_InstallCallback(uint8_t virtualChannel,
  9. edma_callback_t callback,
  10. void *parameter)
  11. {
  12. /* Check the channel number is valid */
  13. DEV_ASSERT(virtualChannel < FEATURE_DMA_VIRTUAL_CHANNELS);
  14. /* Check the channel is allocated */
  15. DEV_ASSERT(s_virtEdmaState->virtChnState[virtualChannel] != NULL);
  16. s_virtEdmaState->virtChnState[virtualChannel]->callback = callback;
  17. s_virtEdmaState->virtChnState[virtualChannel]->parameter = parameter;
  18. return STATUS_SUCCESS;
  19. }

EDMA_DRV_ReleaseChannel

释放通道软硬件

  1. /*FUNCTION**********************************************************************
  2. *
  3. * Function Name : EDMA_DRV_ReleaseChannel
  4. * Description : Free eDMA channel's hardware and software resource.
  5. *
  6. * Implements : EDMA_DRV_ReleaseChannel_Activity
  7. *END**************************************************************************/
  8. status_t EDMA_DRV_ReleaseChannel(uint8_t virtualChannel)
  9. {
  10. /* Check that virtual channel number is valid */
  11. DEV_ASSERT(virtualChannel < FEATURE_DMA_VIRTUAL_CHANNELS);
  12. /* Check the DMA module is initialized */
  13. DEV_ASSERT(s_virtEdmaState != NULL);
  14. /* Get DMA instance from virtual channel */
  15. uint8_t dmaInstance = (uint8_t)FEATURE_DMA_VCH_TO_INSTANCE(virtualChannel);
  16. /* Get DMA channel from virtual channel*/
  17. uint8_t dmaChannel = (uint8_t)FEATURE_DMA_VCH_TO_CH(virtualChannel);
  18. /* Get pointer to channel state */
  19. edma_chn_state_t *chnState = s_virtEdmaState->virtChnState[virtualChannel];
  20. /* Check that virtual channel is initialized */
  21. DEV_ASSERT(chnState != NULL);
  22. DMA_Type *edmaRegBase = s_edmaBase[dmaInstance];
  23. /* Stop edma channel. */
  24. EDMA_SetDmaRequestCmd(edmaRegBase, dmaChannel, false);
  25. /* Reset the channel state structure to default value. */
  26. EDMA_DRV_ClearStructure((uint8_t *)chnState, sizeof(edma_chn_state_t));
  27. s_virtEdmaState->virtChnState[virtualChannel] = NULL;
  28. return STATUS_SUCCESS;
  29. }

EDMA_DRV_ClearIntStatus

清除所有中断状态

  1. /*FUNCTION**********************************************************************
  2. *
  3. * Function Name : EDMA_DRV_ClearIntStatus
  4. * Description : Clear done and interrupt retStatus.
  5. *
  6. *END**************************************************************************/
  7. static void EDMA_DRV_ClearIntStatus(uint8_t virtualChannel)
  8. {
  9. /* Get DMA instance from virtual channel */
  10. uint8_t dmaInstance = (uint8_t)FEATURE_DMA_VCH_TO_INSTANCE(virtualChannel);
  11. /* Get DMA channel from virtual channel*/
  12. uint8_t dmaChannel = (uint8_t)FEATURE_DMA_VCH_TO_CH(virtualChannel);
  13. DMA_Type *edmaRegBase = s_edmaBase[dmaInstance];
  14. EDMA_ClearDoneStatusFlag(edmaRegBase, dmaChannel);
  15. EDMA_ClearIntStatusFlag(edmaRegBase, dmaChannel);
  16. }

EDMA_DRV_ClearSoftwareTCD

清除软件TCD结构体

  1. /*FUNCTION**********************************************************************
  2. *
  3. * Function Name : EDMA_DRV_ClearSoftwareTCD
  4. * Description : Clear the software tcd structure.
  5. *
  6. *END**************************************************************************/
  7. static void EDMA_DRV_ClearSoftwareTCD(edma_software_tcd_t *stcd)
  8. {
  9. EDMA_DRV_ClearStructure((uint8_t *)stcd, sizeof(edma_software_tcd_t));
  10. }

EDMA_DRV_IRQHandler

默认的中断处理函数

  1. /*FUNCTION**********************************************************************
  2. *
  3. * Function Name : EDMA_DRV_IRQHandler
  4. * Description : EDMA IRQ handler.
  5. *END**************************************************************************/
  6. void EDMA_DRV_IRQHandler(uint8_t virtualChannel)
  7. {
  8. const edma_chn_state_t *chnState = s_virtEdmaState->virtChnState[virtualChannel];
  9. EDMA_DRV_ClearIntStatus(virtualChannel);
  10. if (chnState != NULL)
  11. {
  12. if (chnState->callback != NULL)
  13. {
  14. chnState->callback(chnState->parameter, chnState->status);
  15. }
  16. }
  17. }

EDMA_DRV_ErrorIRQHandler

错误中断处理函数

  1. /*FUNCTION**********************************************************************
  2. *
  3. * Function Name : EDMA_DRV_ErrorIRQHandler
  4. * Description : EDMA error IRQ handler
  5. *END**************************************************************************/
  6. void EDMA_DRV_ErrorIRQHandler(uint8_t virtualChannel)
  7. {
  8. /* Get DMA instance from virtual channel */
  9. uint8_t dmaInstance = (uint8_t)FEATURE_DMA_VCH_TO_INSTANCE(virtualChannel);
  10. /* Get DMA channel from virtual channel*/
  11. uint8_t dmaChannel = (uint8_t)FEATURE_DMA_VCH_TO_CH(virtualChannel);
  12. DMA_Type *edmaRegBase = s_edmaBase[dmaInstance];
  13. EDMA_SetDmaRequestCmd(edmaRegBase, dmaChannel, false);
  14. edma_chn_state_t *chnState = s_virtEdmaState->virtChnState[virtualChannel];
  15. if (chnState != NULL)
  16. {
  17. EDMA_DRV_ClearIntStatus(virtualChannel);
  18. EDMA_ClearErrorIntStatusFlag(edmaRegBase, dmaChannel);
  19. chnState->status = EDMA_CHN_ERROR;
  20. if (chnState->callback != NULL)
  21. {
  22. chnState->callback(chnState->parameter, chnState->status);
  23. }
  24. }
  25. }

EDMA_DRV_ConfigSingleBlockTransfer

配置信号块传输

  1. /*FUNCTION**********************************************************************
  2. *
  3. * Function Name : EDMA_DRV_ConfigSingleBlockTransfer
  4. * Description : Configures a DMA single block transfer.
  5. *
  6. * Implements : EDMA_DRV_ConfigSingleBlockTransfer_Activity
  7. *END**************************************************************************/
  8. status_t EDMA_DRV_ConfigSingleBlockTransfer(uint8_t virtualChannel,
  9. edma_transfer_type_t type,
  10. uint32_t srcAddr,
  11. uint32_t destAddr,
  12. edma_transfer_size_t transferSize,
  13. uint32_t dataBufferSize)
  14. {
  15. /* Check that virtual channel number is valid */
  16. DEV_ASSERT(virtualChannel < FEATURE_DMA_VIRTUAL_CHANNELS);
  17. /* Check that eDMA module is initialized */
  18. DEV_ASSERT(s_virtEdmaState != NULL);
  19. /* Check that virtual channel is initialized */
  20. DEV_ASSERT(s_virtEdmaState->virtChnState[virtualChannel] != NULL);
  21. #if defined (CUSTOM_DEVASSERT) || defined (DEV_ERROR_DETECT)
  22. /* Check if the value passed for 'transferSize' is valid */
  23. DEV_ASSERT(EDMA_DRV_ValidTransferSize(transferSize));
  24. #endif
  25. /* Get DMA instance from virtual channel */
  26. uint8_t dmaInstance = (uint8_t)FEATURE_DMA_VCH_TO_INSTANCE(virtualChannel);
  27. /* Get DMA channel from virtual channel*/
  28. uint8_t dmaChannel = (uint8_t)FEATURE_DMA_VCH_TO_CH(virtualChannel);
  29. DMA_Type *edmaRegBase = s_edmaBase[dmaInstance];
  30. uint8_t transferOffset;
  31. status_t retStatus = STATUS_SUCCESS;
  32. /* Compute the transfer offset, based on transfer size.
  33. * The number of bytes transferred in each source read/destination write
  34. * is obtained with the following formula:
  35. * source_read_size = 2^SSIZE
  36. * destination_write_size = 2^DSIZE
  37. */
  38. transferOffset = (uint8_t) (1U << ((uint8_t)transferSize));
  39. /* The number of bytes to be transferred (buffer size) must
  40. * be a multiple of the source read/destination write size
  41. */
  42. if ((dataBufferSize % transferOffset) != 0U)
  43. {
  44. retStatus = STATUS_ERROR;
  45. }
  46. if (retStatus == STATUS_SUCCESS)
  47. {
  48. /* Clear transfer control descriptor for the current channel */
  49. EDMA_TCDClearReg(edmaRegBase, dmaChannel);
  50. #ifdef FEATURE_DMA_ENGINE_STALL
  51. /* Configure the DMA Engine to stall for a number of cycles after each R/W */
  52. EDMA_TCDSetEngineStall(edmaRegBase, dmaChannel, EDMA_ENGINE_STALL_4_CYCLES);
  53. #endif
  54. #ifdef FEATURE_DMA_HWV3
  55. EDMA_SetMinorLoopMappingCmd(edmaRegBase, dmaChannel, false);
  56. #else
  57. EDMA_SetMinorLoopMappingCmd(edmaRegBase, false);
  58. #endif
  59. /* Configure source and destination addresses */
  60. EDMA_TCDSetSrcAddr(edmaRegBase, dmaChannel, srcAddr);
  61. EDMA_TCDSetDestAddr(edmaRegBase, dmaChannel, destAddr);
  62. /* Set transfer size (1B/2B/4B/16B/32B) */
  63. EDMA_TCDSetAttribute(edmaRegBase, dmaChannel, EDMA_MODULO_OFF, EDMA_MODULO_OFF, transferSize, transferSize);
  64. /* Configure source/destination offset. */
  65. switch (type)
  66. {
  67. case EDMA_TRANSFER_PERIPH2MEM:
  68. EDMA_TCDSetSrcOffset(edmaRegBase, dmaChannel, 0);
  69. EDMA_TCDSetDestOffset(edmaRegBase, dmaChannel, (int8_t) transferOffset);
  70. break;
  71. case EDMA_TRANSFER_MEM2PERIPH:
  72. EDMA_TCDSetSrcOffset(edmaRegBase, dmaChannel, (int8_t) transferOffset);
  73. EDMA_TCDSetDestOffset(edmaRegBase, dmaChannel, 0);
  74. break;
  75. case EDMA_TRANSFER_MEM2MEM:
  76. EDMA_TCDSetSrcOffset(edmaRegBase, dmaChannel, (int8_t) transferOffset);
  77. EDMA_TCDSetDestOffset(edmaRegBase, dmaChannel, (int8_t) transferOffset);
  78. break;
  79. case EDMA_TRANSFER_PERIPH2PERIPH:
  80. EDMA_TCDSetSrcOffset(edmaRegBase, dmaChannel, 0);
  81. EDMA_TCDSetDestOffset(edmaRegBase, dmaChannel, 0);
  82. break;
  83. default:
  84. /* This should never be reached - all the possible values have been handled. */
  85. break;
  86. }
  87. /* Set the total number of bytes to be transfered */
  88. EDMA_TCDSetNbytes(edmaRegBase, dmaChannel, dataBufferSize);
  89. /* Set major iteration count to 1 (single block mode) */
  90. EDMA_TCDSetMajorCount(edmaRegBase, dmaChannel, 1U);
  91. /* Enable interrupt when the transfer completes */
  92. EDMA_TCDSetMajorCompleteIntCmd(edmaRegBase, dmaChannel, true);
  93. /* Set virtual channel status to normal */
  94. s_virtEdmaState->virtChnState[virtualChannel]->status = EDMA_CHN_NORMAL;
  95. }
  96. return retStatus;
  97. }

EDMA_DRV_ConfigMultiBlockTransfer

配置复合信号块传输

  1. /*FUNCTION**********************************************************************
  2. *
  3. * Function Name : EDMA_DRV_ConfigMultiBlockTransfer
  4. * Description : Configures a DMA single block transfer.
  5. *
  6. * Implements : EDMA_DRV_ConfigMultiBlockTransfer_Activity
  7. *END**************************************************************************/
  8. status_t EDMA_DRV_ConfigMultiBlockTransfer(uint8_t virtualChannel,
  9. edma_transfer_type_t type,
  10. uint32_t srcAddr,
  11. uint32_t destAddr,
  12. edma_transfer_size_t transferSize,
  13. uint32_t blockSize,
  14. uint32_t blockCount,
  15. bool disableReqOnCompletion)
  16. {
  17. /* Check that virtual channel number is valid */
  18. DEV_ASSERT(virtualChannel < FEATURE_DMA_VIRTUAL_CHANNELS);
  19. /* Check that eDMA module is initialized */
  20. DEV_ASSERT(s_virtEdmaState != NULL);
  21. /* Get DMA instance from virtual channel */
  22. uint8_t dmaInstance = (uint8_t)FEATURE_DMA_VCH_TO_INSTANCE(virtualChannel);
  23. /* Get DMA channel from virtual channel*/
  24. uint8_t dmaChannel = (uint8_t)FEATURE_DMA_VCH_TO_CH(virtualChannel);
  25. status_t retStatus = STATUS_SUCCESS;
  26. /* Configure the transfer for one data block */
  27. retStatus = EDMA_DRV_ConfigSingleBlockTransfer(virtualChannel, type, srcAddr, destAddr, transferSize, blockSize);
  28. if (retStatus == STATUS_SUCCESS)
  29. {
  30. DMA_Type *edmaRegBase = s_edmaBase[dmaInstance];
  31. /* Set the number of data blocks */
  32. EDMA_TCDSetMajorCount(edmaRegBase, dmaChannel, blockCount);
  33. /* Enable/disable requests upon completion */
  34. EDMA_TCDSetDisableDmaRequestAfterTCDDoneCmd(edmaRegBase, dmaChannel, disableReqOnCompletion);
  35. }
  36. return retStatus;
  37. }

EDMA_DRV_ConfigLoopTransfer

配置轮询传输

  1. /*FUNCTION**********************************************************************
  2. *
  3. * Function Name : EDMA_DRV_ConfigLoopTransfer
  4. * Description : Configures the DMA transfer in a loop.
  5. *
  6. * Implements : EDMA_DRV_ConfigLoopTransfer_Activity
  7. *END**************************************************************************/
  8. status_t EDMA_DRV_ConfigLoopTransfer(uint8_t virtualChannel,
  9. const edma_transfer_config_t *transferConfig)
  10. {
  11. /* Check that virtual channel number is valid */
  12. DEV_ASSERT(virtualChannel < FEATURE_DMA_VIRTUAL_CHANNELS);
  13. /* Check that eDMA module is initialized */
  14. DEV_ASSERT(s_virtEdmaState != NULL);
  15. /* Check that virtual channel is initialized */
  16. DEV_ASSERT(s_virtEdmaState->virtChnState[virtualChannel] != NULL);
  17. /* Check the transfer configuration structure is valid */
  18. DEV_ASSERT(transferConfig != NULL);
  19. /* Check the minor/major loop properties are defined */
  20. DEV_ASSERT(transferConfig->loopTransferConfig != NULL);
  21. /* If the modulo feature is enabled, check alignment of addresses */
  22. DEV_ASSERT((transferConfig->srcModulo == EDMA_MODULO_OFF) ||
  23. ((transferConfig->srcAddr % (((uint32_t)1U) << (uint32_t)transferConfig->srcModulo)) == 0U));
  24. DEV_ASSERT((transferConfig->destModulo == EDMA_MODULO_OFF) ||
  25. ((transferConfig->destAddr % (((uint32_t)1U) << (uint32_t)transferConfig->destModulo)) == 0U));
  26. /* Get DMA instance from virtual channel */
  27. uint8_t dmaInstance = (uint8_t)FEATURE_DMA_VCH_TO_INSTANCE(virtualChannel);
  28. #ifdef FEATURE_DMA_HWV3
  29. /* Get DMA channel from virtual channel*/
  30. uint8_t dmaChannel = (uint8_t)FEATURE_DMA_VCH_TO_CH(virtualChannel);
  31. #endif
  32. DMA_Type *edmaRegBase = s_edmaBase[dmaInstance];
  33. #ifdef FEATURE_DMA_HWV3
  34. EDMA_SetMinorLoopMappingCmd(edmaRegBase, dmaChannel, true);
  35. #else
  36. EDMA_SetMinorLoopMappingCmd(edmaRegBase, true);
  37. #endif
  38. /* Write the configuration in the transfer control descriptor registers */
  39. EDMA_DRV_PushConfigToReg(virtualChannel, transferConfig);
  40. /* Set virtual channel status to normal */
  41. s_virtEdmaState->virtChnState[virtualChannel]->status = EDMA_CHN_NORMAL;
  42. return STATUS_SUCCESS;
  43. }

EDMA_DRV_ConfigScatterGatherTransfer

配置分散或者聚集操作

  1. /*FUNCTION**********************************************************************
  2. *
  3. * Function Name : EDMA_DRV_ConfigScatterGatherTransfer
  4. * Description : Configure eDMA for scatter/gather operation
  5. *
  6. * Implements : EDMA_DRV_ConfigScatterGatherTransfer_Activity
  7. *END**************************************************************************/
  8. status_t EDMA_DRV_ConfigScatterGatherTransfer(uint8_t virtualChannel,
  9. edma_software_tcd_t *stcd,
  10. edma_transfer_size_t transferSize,
  11. uint32_t bytesOnEachRequest,
  12. const edma_scatter_gather_list_t *srcList,
  13. const edma_scatter_gather_list_t *destList,
  14. uint8_t tcdCount)
  15. {
  16. /* Check that virtual channel number is valid */
  17. DEV_ASSERT(virtualChannel < FEATURE_DMA_VIRTUAL_CHANNELS);
  18. /* Check that eDMA module is initialized */
  19. DEV_ASSERT(s_virtEdmaState != NULL);
  20. /* Check that virtual channel is initialized */
  21. DEV_ASSERT(s_virtEdmaState->virtChnState[virtualChannel] != NULL);
  22. /* Check the input arrays for scatter/gather operation are valid */
  23. DEV_ASSERT((stcd != NULL) && (srcList != NULL) && (destList != NULL));
  24. #if defined (CUSTOM_DEVASSERT) || defined (DEV_ERROR_DETECT)
  25. /* Check if the value passed for 'transferSize' is valid */
  26. DEV_ASSERT(EDMA_DRV_ValidTransferSize(transferSize));
  27. #endif
  28. uint8_t i = 0U;
  29. uint16_t transferOffset = 0U;
  30. uint32_t stcdAlignedAddr = STCD_ADDR(stcd);
  31. edma_software_tcd_t *edmaSwTcdAddr = (edma_software_tcd_t *)stcdAlignedAddr;
  32. edma_loop_transfer_config_t edmaLoopConfig;
  33. edma_transfer_config_t edmaTransferConfig;
  34. status_t retStatus = STATUS_SUCCESS;
  35. /* Set virtual channel status to normal */
  36. s_virtEdmaState->virtChnState[virtualChannel]->status = EDMA_CHN_NORMAL;
  37. /* Compute the transfer offset, based on transfer size.
  38. * The number of bytes transferred in each source read/destination write
  39. * is obtained with the following formula:
  40. * source_read_size = 2^SSIZE
  41. * destination_write_size = 2^DSIZE
  42. */
  43. transferOffset = (uint16_t) (1UL << ((uint16_t)transferSize));
  44. /* The number of bytes to be transferred on each request must
  45. * be a multiple of the source read/destination write size
  46. */
  47. if ((bytesOnEachRequest % transferOffset) != 0U)
  48. {
  49. retStatus = STATUS_ERROR;
  50. }
  51. /* Clear the configuration structures before initializing them. */
  52. EDMA_DRV_ClearStructure((uint8_t *)(&edmaTransferConfig), sizeof(edma_transfer_config_t));
  53. EDMA_DRV_ClearStructure((uint8_t *)(&edmaLoopConfig), sizeof(edma_loop_transfer_config_t));
  54. /* Configure the transfer for scatter/gather mode. */
  55. edmaTransferConfig.srcLastAddrAdjust = 0;
  56. edmaTransferConfig.destLastAddrAdjust = 0;
  57. edmaTransferConfig.srcModulo = EDMA_MODULO_OFF;
  58. edmaTransferConfig.destModulo = EDMA_MODULO_OFF;
  59. edmaTransferConfig.srcTransferSize = transferSize;
  60. edmaTransferConfig.destTransferSize = transferSize;
  61. edmaTransferConfig.minorByteTransferCount = bytesOnEachRequest;
  62. edmaTransferConfig.interruptEnable = true;
  63. edmaTransferConfig.scatterGatherEnable = true;
  64. edmaTransferConfig.loopTransferConfig = &edmaLoopConfig;
  65. edmaTransferConfig.loopTransferConfig->srcOffsetEnable = false;
  66. edmaTransferConfig.loopTransferConfig->dstOffsetEnable = false;
  67. edmaTransferConfig.loopTransferConfig->minorLoopChnLinkEnable = false;
  68. edmaTransferConfig.loopTransferConfig->majorLoopChnLinkEnable = false;
  69. /* Copy scatter/gather lists to transfer configuration*/
  70. for (i = 0U; (i < tcdCount) && (retStatus == STATUS_SUCCESS); i++)
  71. {
  72. edmaTransferConfig.srcAddr = srcList[i].address;
  73. edmaTransferConfig.destAddr = destList[i].address;
  74. if ((srcList[i].length != destList[i].length) || (srcList[i].type != destList[i].type))
  75. {
  76. retStatus = STATUS_ERROR;
  77. break;
  78. }
  79. edmaTransferConfig.loopTransferConfig->majorLoopIterationCount = srcList[i].length/bytesOnEachRequest;
  80. switch (srcList[i].type)
  81. {
  82. case EDMA_TRANSFER_PERIPH2MEM:
  83. /* Configure Source Read. */
  84. edmaTransferConfig.srcOffset = 0;
  85. /* Configure Dest Write. */
  86. edmaTransferConfig.destOffset = (int16_t) transferOffset;
  87. break;
  88. case EDMA_TRANSFER_MEM2PERIPH:
  89. /* Configure Source Read. */
  90. edmaTransferConfig.srcOffset = (int16_t) transferOffset;
  91. /* Configure Dest Write. */
  92. edmaTransferConfig.destOffset = 0;
  93. break;
  94. case EDMA_TRANSFER_MEM2MEM:
  95. /* Configure Source Read. */
  96. edmaTransferConfig.srcOffset = (int16_t) transferOffset;
  97. /* Configure Dest Write. */
  98. edmaTransferConfig.destOffset = (int16_t) transferOffset;
  99. break;
  100. case EDMA_TRANSFER_PERIPH2PERIPH:
  101. /* Configure Source Read. */
  102. edmaTransferConfig.srcOffset = 0;
  103. /* Configure Dest Write. */
  104. edmaTransferConfig.destOffset = 0;
  105. break;
  106. default:
  107. /* This should never be reached - all the possible values have been handled. */
  108. break;
  109. }
  110. /* Configure the pointer to next software TCD structure; for the last one, this address should be 0 */
  111. if (i == ((uint8_t)(tcdCount - 1U)))
  112. {
  113. edmaTransferConfig.scatterGatherNextDescAddr = 0U;
  114. }
  115. else
  116. {
  117. edma_software_tcd_t * ptNextAddr = &edmaSwTcdAddr[i];
  118. edmaTransferConfig.scatterGatherNextDescAddr = ((uint32_t) ptNextAddr);
  119. }
  120. if (i == 0U)
  121. {
  122. /* Push the configuration for the first descriptor to registers */
  123. EDMA_DRV_PushConfigToReg(virtualChannel, &edmaTransferConfig);
  124. }
  125. else
  126. {
  127. /* Copy configuration to software TCD structure */
  128. EDMA_DRV_PushConfigToSTCD(&edmaTransferConfig, &edmaSwTcdAddr[i - 1U]);
  129. }
  130. }
  131. return retStatus;
  132. }

EDMA_DRV_StartChannel

开启通道,这个在SPI里面调用到

  1. /*FUNCTION**********************************************************************
  2. *
  3. * Function Name : EDMA_DRV_StartChannel
  4. * Description : Starts an eDMA channel.
  5. *
  6. * Implements : EDMA_DRV_StartChannel_Activity
  7. *END**************************************************************************/
  8. status_t EDMA_DRV_StartChannel(uint8_t virtualChannel)
  9. {
  10. /* Check that virtual channel number is valid */
  11. DEV_ASSERT(virtualChannel < FEATURE_DMA_VIRTUAL_CHANNELS);
  12. /* Check that eDMA module is initialized */
  13. DEV_ASSERT(s_virtEdmaState != NULL);
  14. /* Check that virtual channel is initialized */
  15. DEV_ASSERT(s_virtEdmaState->virtChnState[virtualChannel] != NULL);
  16. /* Get DMA instance from virtual channel */
  17. uint8_t dmaInstance = (uint8_t)FEATURE_DMA_VCH_TO_INSTANCE(virtualChannel);
  18. /* Get DMA channel from virtual channel*/
  19. uint8_t dmaChannel = (uint8_t)FEATURE_DMA_VCH_TO_CH(virtualChannel);
  20. /* Enable requests for current channel */
  21. DMA_Type *edmaRegBase = s_edmaBase[dmaInstance];
  22. EDMA_SetDmaRequestCmd(edmaRegBase, dmaChannel, true);
  23. return STATUS_SUCCESS;
  24. }

EDMA_DRV_StopChannel

暂停通道

  1. /*FUNCTION**********************************************************************
  2. *
  3. * Function Name : EDMA_DRV_StopChannel
  4. * Description : Stops an eDMA channel.
  5. *
  6. * Implements : EDMA_DRV_StopChannel_Activity
  7. *END**************************************************************************/
  8. status_t EDMA_DRV_StopChannel(uint8_t virtualChannel)
  9. {
  10. /* Check that virtual channel number is valid */
  11. DEV_ASSERT(virtualChannel < FEATURE_DMA_VIRTUAL_CHANNELS);
  12. /* Check that eDMA module is initialized */
  13. DEV_ASSERT(s_virtEdmaState != NULL);
  14. /* Check that virtual channel is initialized */
  15. DEV_ASSERT(s_virtEdmaState->virtChnState[virtualChannel] != NULL);
  16. /* Get DMA instance from virtual channel */
  17. uint8_t dmaInstance = (uint8_t)FEATURE_DMA_VCH_TO_INSTANCE(virtualChannel);
  18. /* Get DMA channel from virtual channel*/
  19. uint8_t dmaChannel = (uint8_t)FEATURE_DMA_VCH_TO_CH(virtualChannel);
  20. /* Disable requests for current channel */
  21. DMA_Type *edmaRegBase = s_edmaBase[dmaInstance];
  22. EDMA_SetDmaRequestCmd(edmaRegBase, dmaChannel, false);
  23. return STATUS_SUCCESS;
  24. }

EDMA_DRV_SetChannelRequestAndTrigger

设置通道请求和触发

  1. /*FUNCTION**********************************************************************
  2. *
  3. * Function Name : EDMA_DRV_SetChannelRequestAndTrigger
  4. * Description : Sets DMA channel request source in DMAMUX and controls
  5. * the DMA channel periodic triggering.
  6. *
  7. * Implements : EDMA_DRV_SetChannelRequestAndTrigger_Activity
  8. *END**************************************************************************/
  9. status_t EDMA_DRV_SetChannelRequestAndTrigger(uint8_t virtualChannel,
  10. uint8_t request,
  11. bool enableTrigger)
  12. {
  13. /* Check the virtual channel number is valid */
  14. DEV_ASSERT(virtualChannel < (uint32_t)FEATURE_DMA_VIRTUAL_CHANNELS);
  15. /* Check that eDMA module is initialized */
  16. DEV_ASSERT(s_virtEdmaState != NULL);
  17. #ifdef FEATURE_DMAMUX_AVAILABLE
  18. /* Retrieve the DMAMUX instance serving this request */
  19. uint8_t dmaMuxInstance = (uint8_t)FEATURE_DMAMUX_REQ_SRC_TO_INSTANCE(request);
  20. /* Get request index for the corresponding DMAMUX instance */
  21. uint8_t dmaMuxRequest = (uint8_t)FEATURE_DMAMUX_REQ_SRC_TO_CH(request);
  22. /* Get DMAMUX channel for the selected request */
  23. uint8_t dmaMuxChannel = (uint8_t)FEATURE_DMAMUX_DMA_CH_TO_CH(virtualChannel);
  24. /* Retrieve the appropriate DMAMUX instance */
  25. DMAMUX_Type *dmaMuxRegBase = s_dmaMuxBase[dmaMuxInstance];
  26. /* Set request and trigger */
  27. DMAMUX_SetChannelCmd(dmaMuxRegBase, dmaMuxChannel, false);
  28. DMAMUX_SetChannelSource(dmaMuxRegBase, dmaMuxChannel, dmaMuxRequest);
  29. #ifdef FEATURE_DMAMUX_HAS_TRIG
  30. DMAMUX_SetChannelTrigger(dmaMuxRegBase, dmaMuxChannel, enableTrigger);
  31. #else
  32. (void)enableTrigger;
  33. #endif
  34. DMAMUX_SetChannelCmd(dmaMuxRegBase, dmaMuxChannel, true);
  35. return STATUS_SUCCESS;
  36. #else
  37. (void)virtualChannel;
  38. (void)request;
  39. (void)enableTrigger;
  40. return STATUS_UNSUPPORTED;
  41. #endif
  42. }

EDMA_DRV_ClearTCD

清除TCD结构体

  1. /*FUNCTION**********************************************************************
  2. *
  3. * Function Name : EDMA_DRV_ClearTCD
  4. * Description : Clears all registers to 0 for the hardware TCD.
  5. *
  6. * Implements : EDMA_DRV_ClearTCD_Activity
  7. *END**************************************************************************/
  8. void EDMA_DRV_ClearTCD(uint8_t virtualChannel)
  9. {
  10. /* Check that virtual channel number is valid */
  11. DEV_ASSERT(virtualChannel < FEATURE_DMA_VIRTUAL_CHANNELS);
  12. /* Check that eDMA module is initialized */
  13. DEV_ASSERT(s_virtEdmaState != NULL);
  14. /* Check that virtual channel is initialized */
  15. DEV_ASSERT(s_virtEdmaState->virtChnState[virtualChannel] != NULL);
  16. /* Get DMA instance from virtual channel */
  17. uint8_t dmaInstance = (uint8_t)FEATURE_DMA_VCH_TO_INSTANCE(virtualChannel);
  18. /* Get DMA channel from virtual channel*/
  19. uint8_t dmaChannel = (uint8_t)FEATURE_DMA_VCH_TO_CH(virtualChannel);
  20. /* Clear the TCD memory */
  21. DMA_Type *edmaRegBase = s_edmaBase[dmaInstance];
  22. EDMA_TCDClearReg(edmaRegBase, dmaChannel);
  23. }

EDMA_DRV_SetSrcAddr

设置源地址

  1. /*FUNCTION**********************************************************************
  2. *
  3. * Function Name : EDMA_DRV_SetSrcAddr
  4. * Description : Configures the source address for the eDMA channel.
  5. *
  6. * Implements : EDMA_DRV_SetSrcAddr_Activity
  7. *END**************************************************************************/
  8. void EDMA_DRV_SetSrcAddr(uint8_t virtualChannel,
  9. uint32_t address)
  10. {
  11. /* Check that virtual channel number is valid */
  12. DEV_ASSERT(virtualChannel < FEATURE_DMA_VIRTUAL_CHANNELS);
  13. /* Check that eDMA module is initialized */
  14. DEV_ASSERT(s_virtEdmaState != NULL);
  15. /* Check that virtual channel is initialized */
  16. DEV_ASSERT(s_virtEdmaState->virtChnState[virtualChannel] != NULL);
  17. /* Get DMA instance from virtual channel */
  18. uint8_t dmaInstance = (uint8_t)FEATURE_DMA_VCH_TO_INSTANCE(virtualChannel);
  19. /* Get DMA channel from virtual channel*/
  20. uint8_t dmaChannel = (uint8_t)FEATURE_DMA_VCH_TO_CH(virtualChannel);
  21. /* Set channel TCD source address */
  22. DMA_Type *edmaRegBase = s_edmaBase[dmaInstance];
  23. EDMA_TCDSetSrcAddr(edmaRegBase, dmaChannel, address);
  24. }

EDMA_DRV_SetSrcOffset

设置原地址偏移

  1. /*FUNCTION**********************************************************************
  2. *
  3. * Function Name : EDMA_DRV_SetSrcOffset
  4. * Description : Configures the source address signed offset for the eDMA channel.
  5. *
  6. * Implements : EDMA_DRV_SetSrcOffset_Activity
  7. *END**************************************************************************/
  8. void EDMA_DRV_SetSrcOffset(uint8_t virtualChannel,
  9. int16_t offset)
  10. {
  11. /* Check that virtual channel number is valid */
  12. DEV_ASSERT(virtualChannel < FEATURE_DMA_VIRTUAL_CHANNELS);
  13. /* Check that eDMA module is initialized */
  14. DEV_ASSERT(s_virtEdmaState != NULL);
  15. /* Check that virtual channel is initialized */
  16. DEV_ASSERT(s_virtEdmaState->virtChnState[virtualChannel] != NULL);
  17. /* Get DMA instance from virtual channel */
  18. uint8_t dmaInstance = (uint8_t)FEATURE_DMA_VCH_TO_INSTANCE(virtualChannel);
  19. /* Get DMA channel from virtual channel*/
  20. uint8_t dmaChannel = (uint8_t)FEATURE_DMA_VCH_TO_CH(virtualChannel);
  21. /* Set channel TCD source offset */
  22. DMA_Type *edmaRegBase = s_edmaBase[dmaInstance];
  23. EDMA_TCDSetSrcOffset(edmaRegBase, dmaChannel, offset);
  24. }

EDMA_DRV_SetSrcReadChunkSize

配置源读数据块大小

  1. /*FUNCTION**********************************************************************
  2. *
  3. * Function Name : EDMA_DRV_SetSrcReadChunkSize
  4. * Description : Configures the source read data chunk size (transferred in a read sequence).
  5. *
  6. * Implements : EDMA_DRV_SetSrcReadChunkSize_Activity
  7. *END**************************************************************************/
  8. void EDMA_DRV_SetSrcReadChunkSize(uint8_t virtualChannel,
  9. edma_transfer_size_t size)
  10. {
  11. /* Check that virtual channel number is valid */
  12. DEV_ASSERT(virtualChannel < FEATURE_DMA_VIRTUAL_CHANNELS);
  13. /* Check that eDMA module is initialized */
  14. DEV_ASSERT(s_virtEdmaState != NULL);
  15. /* Check that virtual channel is initialized */
  16. DEV_ASSERT(s_virtEdmaState->virtChnState[virtualChannel] != NULL);
  17. /* Get DMA instance from virtual channel */
  18. uint8_t dmaInstance = (uint8_t)FEATURE_DMA_VCH_TO_INSTANCE(virtualChannel);
  19. /* Get DMA channel from virtual channel*/
  20. uint8_t dmaChannel = (uint8_t)FEATURE_DMA_VCH_TO_CH(virtualChannel);
  21. /* Set channel TCD source transfer size */
  22. DMA_Type *edmaRegBase = s_edmaBase[dmaInstance];
  23. EDMA_TCDSetSrcTransferSize(edmaRegBase, dmaChannel, size);
  24. }

EDMA_DRV_SetSrcLastAddrAdjustment

配置源地址最后一次调整

  1. /*FUNCTION**********************************************************************
  2. *
  3. * Function Name : EDMA_DRV_SetSrcLastAddrAdjustment
  4. * Description : Configures the source address last adjustment.
  5. *
  6. * Implements : EDMA_DRV_SetSrcLastAddrAdjustment_Activity
  7. *END**************************************************************************/
  8. void EDMA_DRV_SetSrcLastAddrAdjustment(uint8_t virtualChannel,
  9. int32_t adjust)
  10. {
  11. /* Check that virtual channel number is valid */
  12. DEV_ASSERT(virtualChannel < FEATURE_DMA_VIRTUAL_CHANNELS);
  13. /* Check that eDMA module is initialized */
  14. DEV_ASSERT(s_virtEdmaState != NULL);
  15. /* Check that virtual channel is initialized */
  16. DEV_ASSERT(s_virtEdmaState->virtChnState[virtualChannel] != NULL);
  17. /* Get DMA instance from virtual channel */
  18. uint8_t dmaInstance = (uint8_t)FEATURE_DMA_VCH_TO_INSTANCE(virtualChannel);
  19. /* Get DMA channel from virtual channel*/
  20. uint8_t dmaChannel = (uint8_t)FEATURE_DMA_VCH_TO_CH(virtualChannel);
  21. /* Set channel TCD source last adjustment */
  22. DMA_Type *edmaRegBase = s_edmaBase[dmaInstance];
  23. EDMA_TCDSetSrcLastAdjust(edmaRegBase, dmaChannel, adjust);
  24. }

EDMA_DRV_SetDestLastAddrAdjustment

配置目标地址最后一次调整

  1. /*FUNCTION**********************************************************************
  2. *
  3. * Function Name : EDMA_DRV_SetDestLastAddrAdjustment
  4. * Description : Configures the source address last adjustment.
  5. *
  6. * Implements : EDMA_DRV_SetDestLastAddrAdjustment_Activity
  7. *END**************************************************************************/
  8. void EDMA_DRV_SetDestLastAddrAdjustment(uint8_t virtualChannel,
  9. int32_t adjust)
  10. {
  11. /* Check that virtual channel number is valid */
  12. DEV_ASSERT(virtualChannel < FEATURE_DMA_VIRTUAL_CHANNELS);
  13. /* Check that eDMA module is initialized */
  14. DEV_ASSERT(s_virtEdmaState != NULL);
  15. /* Check that virtual channel is initialized */
  16. DEV_ASSERT(s_virtEdmaState->virtChnState[virtualChannel] != NULL);
  17. /* Get DMA instance from virtual channel */
  18. uint8_t dmaInstance = (uint8_t)FEATURE_DMA_VCH_TO_INSTANCE(virtualChannel);
  19. /* Get DMA channel from virtual channel*/
  20. uint8_t dmaChannel = (uint8_t)FEATURE_DMA_VCH_TO_CH(virtualChannel);
  21. /* Set channel TCD source last adjustment */
  22. DMA_Type *edmaRegBase = s_edmaBase[dmaInstance];
  23. EDMA_TCDSetDestLastAdjust(edmaRegBase, dmaChannel, adjust);
  24. }

EDMA_DRV_SetDestAddr

设置目标地址

  1. /*FUNCTION**********************************************************************
  2. *
  3. * Function Name : EDMA_DRV_SetDestAddr
  4. * Description : Configures the destination address for the eDMA channel.
  5. *
  6. * Implements : EDMA_DRV_SetDestAddr_Activity
  7. *END**************************************************************************/
  8. void EDMA_DRV_SetDestAddr(uint8_t virtualChannel,
  9. uint32_t address)
  10. {
  11. /* Check that virtual channel number is valid */
  12. DEV_ASSERT(virtualChannel < FEATURE_DMA_VIRTUAL_CHANNELS);
  13. /* Check that eDMA module is initialized */
  14. DEV_ASSERT(s_virtEdmaState != NULL);
  15. /* Check that virtual channel is initialized */
  16. DEV_ASSERT(s_virtEdmaState->virtChnState[virtualChannel] != NULL);
  17. /* Get DMA instance from virtual channel */
  18. uint8_t dmaInstance = (uint8_t)FEATURE_DMA_VCH_TO_INSTANCE(virtualChannel);
  19. /* Get DMA channel from virtual channel*/
  20. uint8_t dmaChannel = (uint8_t)FEATURE_DMA_VCH_TO_CH(virtualChannel);
  21. /* Set channel TCD destination address */
  22. DMA_Type *edmaRegBase = s_edmaBase[dmaInstance];
  23. EDMA_TCDSetDestAddr(edmaRegBase, dmaChannel, address);
  24. }

EDMA_DRV_SetDestOffset

设置目标地址偏移

  1. /*FUNCTION**********************************************************************
  2. *
  3. * Function Name : EDMA_DRV_SetDestOffset
  4. * Description : Configures the destination address signed offset for the eDMA channel.
  5. *
  6. * Implements : EDMA_DRV_SetDestOffset_Activity
  7. *END**************************************************************************/
  8. void EDMA_DRV_SetDestOffset(uint8_t virtualChannel,
  9. int16_t offset)
  10. {
  11. /* Check that virtual channel number is valid */
  12. DEV_ASSERT(virtualChannel < FEATURE_DMA_VIRTUAL_CHANNELS);
  13. /* Check that eDMA module is initialized */
  14. DEV_ASSERT(s_virtEdmaState != NULL);
  15. /* Check that virtual channel is initialized */
  16. DEV_ASSERT(s_virtEdmaState->virtChnState[virtualChannel] != NULL);
  17. /* Get DMA instance from virtual channel */
  18. uint8_t dmaInstance = (uint8_t)FEATURE_DMA_VCH_TO_INSTANCE(virtualChannel);
  19. /* Get DMA channel from virtual channel*/
  20. uint8_t dmaChannel = (uint8_t)FEATURE_DMA_VCH_TO_CH(virtualChannel);
  21. /* Set channel TCD destination offset */
  22. DMA_Type *edmaRegBase = s_edmaBase[dmaInstance];
  23. EDMA_TCDSetDestOffset(edmaRegBase, dmaChannel, offset);
  24. }

EDMA_DRV_SetDestWriteChunkSize

配置写入目标地址数据块大小

  1. /*FUNCTION**********************************************************************
  2. *
  3. * Function Name : EDMA_DRV_SetDestWriteChunkSize
  4. * Description : Configures the destination data chunk size (transferred in a write sequence).
  5. *
  6. * Implements : EDMA_DRV_SetDestWriteChunkSize_Activity
  7. *END**************************************************************************/
  8. void EDMA_DRV_SetDestWriteChunkSize(uint8_t virtualChannel,
  9. edma_transfer_size_t size)
  10. {
  11. /* Check that virtual channel number is valid */
  12. DEV_ASSERT(virtualChannel < FEATURE_DMA_VIRTUAL_CHANNELS);
  13. /* Check that eDMA module is initialized */
  14. DEV_ASSERT(s_virtEdmaState != NULL);
  15. /* Check that virtual channel is initialized */
  16. DEV_ASSERT(s_virtEdmaState->virtChnState[virtualChannel] != NULL);
  17. /* Get DMA instance from virtual channel */
  18. uint8_t dmaInstance = (uint8_t)FEATURE_DMA_VCH_TO_INSTANCE(virtualChannel);
  19. /* Get DMA channel from virtual channel*/
  20. uint8_t dmaChannel = (uint8_t)FEATURE_DMA_VCH_TO_CH(virtualChannel);
  21. /* Set channel TCD source transfer size */
  22. DMA_Type *edmaRegBase = s_edmaBase[dmaInstance];
  23. EDMA_TCDSetDestTransferSize(edmaRegBase, dmaChannel, size);
  24. }

EDMA_DRV_SetMinorLoopBlockSize

配置通道的每个服务请求中传输的字节数

  1. /*FUNCTION**********************************************************************
  2. *
  3. * Function Name : EDMA_DRV_SetMinorLoopBlockSize
  4. * Description : Configures the number of bytes to be transferred in each service request of the channel.
  5. *
  6. * Implements : EDMA_DRV_SetMinorLoopBlockSize_Activity
  7. *END**************************************************************************/
  8. void EDMA_DRV_SetMinorLoopBlockSize(uint8_t virtualChannel,
  9. uint32_t nbytes)
  10. {
  11. /* Check that virtual channel number is valid */
  12. DEV_ASSERT(virtualChannel < FEATURE_DMA_VIRTUAL_CHANNELS);
  13. /* Check that eDMA module is initialized */
  14. DEV_ASSERT(s_virtEdmaState != NULL);
  15. /* Check that virtual channel is initialized */
  16. DEV_ASSERT(s_virtEdmaState->virtChnState[virtualChannel] != NULL);
  17. /* Get DMA instance from virtual channel */
  18. uint8_t dmaInstance = (uint8_t)FEATURE_DMA_VCH_TO_INSTANCE(virtualChannel);
  19. /* Get DMA channel from virtual channel*/
  20. uint8_t dmaChannel = (uint8_t)FEATURE_DMA_VCH_TO_CH(virtualChannel);
  21. /* Set channel TCD minor loop block size */
  22. DMA_Type *edmaRegBase = s_edmaBase[dmaInstance];
  23. EDMA_TCDSetNbytes(edmaRegBase, dmaChannel, nbytes);
  24. }

EDMA_DRV_SetMajorLoopIterationCount

配置主循环迭代的次数

  1. /*FUNCTION**********************************************************************
  2. *
  3. * Function Name : EDMA_DRV_SetMajorLoopIterationCount
  4. * Description : Configures the number of major loop iterations.
  5. *
  6. * Implements : EDMA_DRV_SetMajorLoopIterationCount_Activity
  7. *END**************************************************************************/
  8. void EDMA_DRV_SetMajorLoopIterationCount(uint8_t virtualChannel,
  9. uint32_t majorLoopCount)
  10. {
  11. /* Check that virtual channel number is valid */
  12. DEV_ASSERT(virtualChannel < FEATURE_DMA_VIRTUAL_CHANNELS);
  13. /* Check that eDMA module is initialized */
  14. DEV_ASSERT(s_virtEdmaState != NULL);
  15. /* Check that virtual channel is initialized */
  16. DEV_ASSERT(s_virtEdmaState->virtChnState[virtualChannel] != NULL);
  17. /* Get DMA instance from virtual channel */
  18. uint8_t dmaInstance = (uint8_t)FEATURE_DMA_VCH_TO_INSTANCE(virtualChannel);
  19. /* Get DMA channel from virtual channel*/
  20. uint8_t dmaChannel = (uint8_t)FEATURE_DMA_VCH_TO_CH(virtualChannel);
  21. /* Set the major loop iteration count */
  22. DMA_Type *edmaRegBase = s_edmaBase[dmaInstance];
  23. EDMA_TCDSetMajorCount(edmaRegBase, dmaChannel, majorLoopCount);
  24. }

EDMA_DRV_GetRemainingMajorIterationsCount

返回剩余的主循环迭代计数

  1. /*FUNCTION**********************************************************************
  2. *
  3. * Function Name : EDMA_DRV_GetRemainingMajorIterationsCount
  4. * Description : Returns the remaining major loop iteration count.
  5. *
  6. * Implements : EDMA_DRV_GetRemainingMajorIterationsCount_Activity
  7. *END**************************************************************************/
  8. uint32_t EDMA_DRV_GetRemainingMajorIterationsCount(uint8_t virtualChannel)
  9. {
  10. /* Check that virtual channel number is valid */
  11. DEV_ASSERT(virtualChannel < FEATURE_DMA_VIRTUAL_CHANNELS);
  12. /* Check that eDMA module is initialized */
  13. DEV_ASSERT(s_virtEdmaState != NULL);
  14. /* Check that virtual channel is initialized */
  15. DEV_ASSERT(s_virtEdmaState->virtChnState[virtualChannel] != NULL);
  16. /* Get DMA instance from virtual channel */
  17. uint8_t dmaInstance = (uint8_t)FEATURE_DMA_VCH_TO_INSTANCE(virtualChannel);
  18. /* Get DMA channel from virtual channel*/
  19. uint8_t dmaChannel = (uint8_t)FEATURE_DMA_VCH_TO_CH(virtualChannel);
  20. /* Retrieve the number of minor loops yet to be triggered */
  21. const DMA_Type *edmaRegBase = s_edmaBase[dmaInstance];
  22. uint32_t count = EDMA_TCDGetCurrentMajorCount(edmaRegBase, dmaChannel);
  23. return count;
  24. }

EDMA_DRV_SetScatterGatherLink

配置下一个TCD的内存地址

  1. /*FUNCTION**********************************************************************
  2. *
  3. * Function Name : EDMA_DRV_SetScatterGatherLink
  4. * Description : Configures the memory address of the next TCD, in scatter/gather mode.
  5. *
  6. * Implements : EDMA_DRV_SetScatterGatherLink_Activity
  7. *END**************************************************************************/
  8. void EDMA_DRV_SetScatterGatherLink(uint8_t virtualChannel,
  9. uint32_t nextTCDAddr)
  10. {
  11. /* Check that virtual channel number is valid */
  12. DEV_ASSERT(virtualChannel < FEATURE_DMA_VIRTUAL_CHANNELS);
  13. /* Check that eDMA module is initialized */
  14. DEV_ASSERT(s_virtEdmaState != NULL);
  15. /* Check that virtual channel is initialized */
  16. DEV_ASSERT(s_virtEdmaState->virtChnState[virtualChannel] != NULL);
  17. /* Get DMA instance from virtual channel */
  18. uint8_t dmaInstance = (uint8_t)FEATURE_DMA_VCH_TO_INSTANCE(virtualChannel);
  19. /* Get DMA channel from virtual channel*/
  20. uint8_t dmaChannel = (uint8_t)FEATURE_DMA_VCH_TO_CH(virtualChannel);
  21. /* Configures the memory address of the next TCD */
  22. DMA_Type *edmaRegBase = s_edmaBase[dmaInstance];
  23. EDMA_TCDSetScatterGatherLink(edmaRegBase, dmaChannel, nextTCDAddr);
  24. }

EDMA_DRV_DisableRequestsOnTransferComplete

在TCD的主循环完成后禁用/启用DMA请求

  1. /*FUNCTION**********************************************************************
  2. *
  3. * Function Name : EDMA_DRV_DisableRequestsOnTransferComplete
  4. * Description : Disables/Enables the DMA request after the major loop completes for the TCD.
  5. *
  6. * Implements : EDMA_DRV_DisableRequestsOnTransferComplete_Activity
  7. *END**************************************************************************/
  8. void EDMA_DRV_DisableRequestsOnTransferComplete(uint8_t virtualChannel,
  9. bool disable)
  10. {
  11. /* Check that virtual channel number is valid */
  12. DEV_ASSERT(virtualChannel < FEATURE_DMA_VIRTUAL_CHANNELS);
  13. /* Check that eDMA module is initialized */
  14. DEV_ASSERT(s_virtEdmaState != NULL);
  15. /* Check that virtual channel is initialized */
  16. DEV_ASSERT(s_virtEdmaState->virtChnState[virtualChannel] != NULL);
  17. /* Get DMA instance from virtual channel */
  18. uint8_t dmaInstance = (uint8_t)FEATURE_DMA_VCH_TO_INSTANCE(virtualChannel);
  19. /* Get DMA channel from virtual channel*/
  20. uint8_t dmaChannel = (uint8_t)FEATURE_DMA_VCH_TO_CH(virtualChannel);
  21. /* Disables/Enables the DMA request upon TCD completion */
  22. DMA_Type *edmaRegBase = s_edmaBase[dmaInstance];
  23. EDMA_TCDSetDisableDmaRequestAfterTCDDoneCmd(edmaRegBase, dmaChannel, disable);
  24. }

EDMA_DRV_ConfigureInterrupt

使能失能通道中断

  1. /*FUNCTION**********************************************************************
  2. *
  3. * Function Name : EDMA_DRV_ConfigureInterrupt
  4. * Description : Disables/Enables the channel interrupt requests.
  5. *
  6. * Implements : EDMA_DRV_ConfigureInterrupt_Activity
  7. *END**************************************************************************/
  8. void EDMA_DRV_ConfigureInterrupt(uint8_t virtualChannel,
  9. edma_channel_interrupt_t intSrc,
  10. bool enable)
  11. {
  12. /* Check that virtual channel number is valid */
  13. DEV_ASSERT(virtualChannel < FEATURE_DMA_VIRTUAL_CHANNELS);
  14. /* Check that eDMA module is initialized */
  15. DEV_ASSERT(s_virtEdmaState != NULL);
  16. /* Check that virtual channel is initialized */
  17. DEV_ASSERT(s_virtEdmaState->virtChnState[virtualChannel] != NULL);
  18. /* Get DMA instance from virtual channel */
  19. uint8_t dmaInstance = (uint8_t)FEATURE_DMA_VCH_TO_INSTANCE(virtualChannel);
  20. /* Get DMA channel from virtual channel*/
  21. uint8_t dmaChannel = (uint8_t)FEATURE_DMA_VCH_TO_CH(virtualChannel);
  22. /* Disables/Enables the channel interrupt requests. */
  23. DMA_Type *edmaRegBase = s_edmaBase[dmaInstance];
  24. switch (intSrc)
  25. {
  26. case EDMA_CHN_ERR_INT:
  27. /* Enable channel interrupt request when error conditions occur */
  28. EDMA_SetErrorIntCmd(edmaRegBase, dmaChannel, enable);
  29. break;
  30. case EDMA_CHN_HALF_MAJOR_LOOP_INT:
  31. /* Enable channel interrupt request when major iteration count reaches halfway point */
  32. EDMA_TCDSetMajorHalfCompleteIntCmd(edmaRegBase, dmaChannel, enable);
  33. break;
  34. case EDMA_CHN_MAJOR_LOOP_INT:
  35. /* Enable channel interrupt request when major iteration count reaches zero */
  36. EDMA_TCDSetMajorCompleteIntCmd(edmaRegBase, dmaChannel, enable);
  37. break;
  38. default:
  39. /* This branch should never be reached if driver API is used properly */
  40. break;
  41. }
  42. }

EDMA_DRV_CancelTransfer

取消传输

  1. /*FUNCTION**********************************************************************
  2. *
  3. * Function Name : EDMA_DRV_CancelTransfer
  4. * Description : Cancels the running transfer for this channel.
  5. *
  6. * Implements : EDMA_DRV_CancelTransfer_Activity
  7. *END**************************************************************************/
  8. void EDMA_DRV_CancelTransfer(bool error)
  9. {
  10. /* Check that eDMA module is initialized */
  11. DEV_ASSERT(s_virtEdmaState != NULL);
  12. uint32_t dmaInstance = 0U;
  13. for(dmaInstance = 0U; dmaInstance < (uint32_t)DMA_INSTANCE_COUNT; dmaInstance++)
  14. {
  15. /* Cancel the running transfer. */
  16. DMA_Type *edmaRegBase = s_edmaBase[dmaInstance];
  17. if (error)
  18. {
  19. EDMA_CancelTransferWithError(edmaRegBase);
  20. }
  21. else
  22. {
  23. EDMA_CancelTransfer(edmaRegBase);
  24. }
  25. }
  26. }

EDMA_DRV_TriggerSwRequest

触发DMA请求

  1. /*FUNCTION**********************************************************************
  2. *
  3. * Function Name : EDMA_DRV_TriggerSwRequest
  4. * Description : Triggers a sw request for the current channel.
  5. *
  6. * Implements : EDMA_DRV_TriggerSwRequest_Activity
  7. *END**************************************************************************/
  8. void EDMA_DRV_TriggerSwRequest(uint8_t virtualChannel)
  9. {
  10. /* Check that virtual channel number is valid */
  11. DEV_ASSERT(virtualChannel < FEATURE_DMA_VIRTUAL_CHANNELS);
  12. /* Check that eDMA module is initialized */
  13. DEV_ASSERT(s_virtEdmaState != NULL);
  14. /* Check that virtual channel is initialized */
  15. DEV_ASSERT(s_virtEdmaState->virtChnState[virtualChannel] != NULL);
  16. /* Get DMA instance from virtual channel */
  17. uint8_t dmaInstance = (uint8_t)FEATURE_DMA_VCH_TO_INSTANCE(virtualChannel);
  18. /* Get DMA channel from virtual channel*/
  19. uint8_t dmaChannel = (uint8_t)FEATURE_DMA_VCH_TO_CH(virtualChannel);
  20. /* Trigger the channel transfer. */
  21. DMA_Type *edmaRegBase = s_edmaBase[dmaInstance];
  22. EDMA_TriggerChannelStart(edmaRegBase, dmaChannel);
  23. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/282401
推荐阅读
相关标签
  

闽ICP备14008679号