![]() |
![]() |
#include <stdint.h>
#include "register_remap.h"
#include <debug.h>
#include <interrupt.h>
#include <dma.h>
Functions | |
void | DMA_enableModule (void) |
void | DMA_disableModule (void) |
uint32_t | DMA_getErrorStatus (void) |
void | DMA_clearErrorStatus (void) |
void | DMA_enableChannel (uint32_t channelNum) |
void | DMA_disableChannel (uint32_t channelNum) |
bool | DMA_isChannelEnabled (uint32_t channelNum) |
void | DMA_setControlBase (void *controlTable) |
void * | DMA_getControlBase (void) |
void * | DMA_getControlAlternateBase (void) |
void | DMA_requestChannel (uint32_t channelNum) |
void | DMA_enableChannelAttribute (uint32_t channelNum, uint32_t attr) |
void | DMA_disableChannelAttribute (uint32_t channelNum, uint32_t attr) |
uint32_t | DMA_getChannelAttribute (uint32_t channelNum) |
void | DMA_setChannelControl (uint32_t channelStructIndex, uint32_t control) |
void | DMA_setChannelTransfer (uint32_t channelStructIndex, uint32_t mode, void *srcAddr, void *dstAddr, uint32_t transferSize) |
void | DMA_setChannelScatterGather (uint32_t channelNum, uint32_t taskCount, void *taskList, uint32_t isPeriphSG) |
uint32_t | DMA_getChannelSize (uint32_t channelStructIndex) |
uint32_t | DMA_getChannelMode (uint32_t channelStructIndex) |
void | DMA_assignChannel (uint32_t mapping) |
void | DMA_assignInterrupt (uint32_t interruptNumber, uint32_t channel) |
void | DMA_requestSoftwareTransfer (uint32_t channel) |
uint32_t | DMA_getInterruptStatus (void) |
void | DMA_clearInterruptFlag (uint32_t channel) |
void | DMA_enableInterrupt (uint32_t interruptNumber) |
void | DMA_disableInterrupt (uint32_t interruptNumber) |
void | DMA_registerInterrupt (uint32_t interruptNumber, void(*intHandler)(void)) |
void | DMA_unregisterInterrupt (uint32_t interruptNumber) |
void DMA_enableModule | ( | void | ) |
Enables the DMA controller for use.
This function enables the DMA controller. The DMA controller must be enabled before it can be configured and used.
void DMA_disableModule | ( | void | ) |
Disables the DMA controller for use.
This function disables the DMA controller. Once disabled, the DMA controller cannot operate until re-enabled with DMA_enableModule().
uint32_t DMA_getErrorStatus | ( | void | ) |
Gets the DMA error status.
This function returns the DMA error status. It should be called from within the DMA error interrupt handler to determine if a DMA error occurred.
void DMA_clearErrorStatus | ( | void | ) |
Clears the DMA error interrupt.
This function clears a pending DMA error interrupt. This function should be called from within the DMA error interrupt handler to clear the interrupt.
void DMA_enableChannel | ( | uint32_t | channelNum | ) |
Enables a DMA channel for operation.
channelNum | is the channel number to enable. |
This function enables a specific DMA channel for use. This function must be used to enable a channel before it can be used to perform a DMA transfer.
When a DMA transfer is completed, the channel is automatically disabled by the DMA controller. Therefore, this function should be called prior to starting up any new transfer.
References ASSERT.
void DMA_disableChannel | ( | uint32_t | channelNum | ) |
Disables a DMA channel for operation.
channelNum | is the channel number to disable. |
This function disables a specific DMA channel. Once disabled, a channel cannot respond to DMA transfer requests until re-enabled via DMA_enableChannel().
References ASSERT.
bool DMA_isChannelEnabled | ( | uint32_t | channelNum | ) |
Checks if a DMA channel is enabled for operation.
channelNum | is the channel number to check. |
This function checks to see if a specific DMA channel is enabled. This function can be used to check the status of a transfer, as the channel is automatically disabled at the end of a transfer.
References ASSERT.
void DMA_setControlBase | ( | void * | controlTable | ) |
Sets the base address for the channel control table.
controlTable | is a pointer to the 1024-byte-aligned base address of the DMA channel control table. |
This function configures the base address of the channel control table. This table resides in system memory and holds control information for each DMA channel. The table must be aligned on a 1024-byte boundary. The base address must be configured before any of the channel functions can be used.
The size of the channel control table depends on the number of DMA channels and the transfer modes that are used. Refer to the introductory text and the microcontroller datasheet for more information about the channel control table.
References ASSERT.
void* DMA_getControlBase | ( | void | ) |
Gets the base address for the channel control table.
This function gets the base address of the channel control table. This table resides in system memory and holds control information for each DMA channel.
void* DMA_getControlAlternateBase | ( | void | ) |
Gets the base address for the channel control table alternate structures.
This function gets the base address of the second half of the channel control table that holds the alternate control structures for each channel.
void DMA_requestChannel | ( | uint32_t | channelNum | ) |
Requests a DMA channel to start a transfer.
channelNum | is the channel number on which to request a DMA transfer. |
This function allows software to request a DMA channel to begin a transfer. This function could be used for performing a memory-to-memory transfer, or if for some reason a transfer needs to be initiated by software instead of the peripheral associated with that channel.
References ASSERT.
void DMA_enableChannelAttribute | ( | uint32_t | channelNum, |
uint32_t | attr | ||
) |
Enables attributes of a DMA channel.
channelNum | is the channel to configure. |
attr | is a combination of attributes for the channel. |
This function is used to enable attributes of a DMA channel.
The attr parameter is the logical OR of any of the following:
References ASSERT, UDMA_ATTR_ALTSELECT, UDMA_ATTR_HIGH_PRIORITY, UDMA_ATTR_REQMASK, and UDMA_ATTR_USEBURST.
void DMA_disableChannelAttribute | ( | uint32_t | channelNum, |
uint32_t | attr | ||
) |
Disables attributes of a DMA channel.
channelNum | is the channel to configure. |
attr | is a combination of attributes for the channel. |
This function is used to disable attributes of a DMA channel.
The attr parameter is the logical OR of any of the following:
References ASSERT, UDMA_ATTR_ALTSELECT, UDMA_ATTR_HIGH_PRIORITY, UDMA_ATTR_REQMASK, and UDMA_ATTR_USEBURST.
uint32_t DMA_getChannelAttribute | ( | uint32_t | channelNum | ) |
Gets the enabled attributes of a DMA channel.
channelNum | is the channel to configure. |
This function returns a combination of flags representing the attributes of the DMA channel.
References ASSERT, UDMA_ATTR_ALTSELECT, UDMA_ATTR_HIGH_PRIORITY, UDMA_ATTR_REQMASK, and UDMA_ATTR_USEBURST.
void DMA_setChannelControl | ( | uint32_t | channelStructIndex, |
uint32_t | control | ||
) |
Sets the control parameters for a DMA channel control structure.
channelStructIndex | is the logical OR of the DMA channel number with UDMA_PRI_SELECT or UDMA_ALT_SELECT. |
control | is logical OR of several control values to set the control parameters for the channel. |
This function is used to set control parameters for a DMA transfer. These parameters are typically not changed often.
The channelStructIndex parameter should be the logical OR of the channel number with one of UDMA_PRI_SELECT or UDMA_ALT_SELECT to choose whether the primary or alternate data structure is used.
The control parameter is the logical OR of five values: the data size, the source address increment, the destination address increment, the arbitration size, and the use burst flag. The choices available for each of these values is described below.
Choose the data size from one of UDMA_SIZE_8, UDMA_SIZE_16, or UDMA_SIZE_32 to select a data size of 8, 16, or 32 bits.
Choose the source address increment from one of UDMA_SRC_INC_8, UDMA_SRC_INC_16, UDMA_SRC_INC_32, or UDMA_SRC_INC_NONE to select an address increment of 8-bit bytes, 16-bit half-words, 32-bit words, or to select non-incrementing.
Choose the destination address increment from one of UDMA_DST_INC_8, UDMA_DST_INC_16, UDMA_DST_INC_32, or UDMA_SRC_INC_8 to select an address increment of 8-bit bytes, 16-bit half-words, 32-bit words, or to select non-incrementing.
The arbitration size determines how many items are transferred before the DMA controller re-arbitrates for the bus. Choose the arbitration size from one of UDMA_ARB_1, UDMA_ARB_2, UDMA_ARB_4, UDMA_ARB_8, through UDMA_ARB_1024 to select the arbitration size from 1 to 1024 items, in powers of 2.
The value UDMA_NEXT_USEBURST is used to force the channel to only respond to burst requests at the tail end of a scatter-gather transfer.
References ASSERT, and _DMA_ControlTable::control.
void DMA_setChannelTransfer | ( | uint32_t | channelStructIndex, |
uint32_t | mode, | ||
void * | srcAddr, | ||
void * | dstAddr, | ||
uint32_t | transferSize | ||
) |
Sets the transfer parameters for a DMA channel control structure.
channelStructIndex | is the logical OR of the DMA channel number with either UDMA_PRI_SELECT or UDMA_ALT_SELECT. |
mode | is the type of DMA transfer. |
srcAddr | is the source address for the transfer. |
dstAddr | is the destination address for the transfer. |
transferSize | is the number of data items to transfer. |
This function is used to configure the parameters for a DMA transfer. These parameters are typically changed often. The function DMA_setChannelControl() MUST be called at least once for this channel prior to calling this function.
The channelStructIndex parameter should be the logical OR of the channel number with one of UDMA_PRI_SELECT or UDMA_ALT_SELECT to choose whether the primary or alternate data structure is used.
The mode parameter should be one of the following values:
The srcAddr and dstAddr parameters are pointers to the first location of the data to be transferred. These addresses should be aligned according to the item size. The compiler takes care of this alignment if the pointers are pointing to storage of the appropriate data type.
The transferSize parameter is the number of data items, not the number of bytes.
The two scatter-gather modes, memory and peripheral, are actually different depending on whether the primary or alternate control structure is selected. This function looks for the UDMA_PRI_SELECT and UDMA_ALT_SELECT flag along with the channel number and sets the scatter-gather mode as appropriate for the primary or alternate control structure.
The channel must also be enabled using DMA_enableChannel() after calling this function. The transfer does not begin until the channel has been configured and enabled. Note that the channel is automatically disabled after the transfer is completed, meaning that DMA_enableChannel() must be called again after setting up the next transfer.
References ASSERT, _DMA_ControlTable::control, _DMA_ControlTable::dstEndAddr, _DMA_ControlTable::srcEndAddr, UDMA_ALT_SELECT, UDMA_DST_INC_NONE, UDMA_MODE_ALT_SELECT, UDMA_MODE_MEM_SCATTER_GATHER, UDMA_MODE_PER_SCATTER_GATHER, and UDMA_SRC_INC_NONE.
void DMA_setChannelScatterGather | ( | uint32_t | channelNum, |
uint32_t | taskCount, | ||
void * | taskList, | ||
uint32_t | isPeriphSG | ||
) |
Configures a DMA channel for scatter-gather mode.
channelNum | is the DMA channel number. |
taskCount | is the number of scatter-gather tasks to execute. |
taskList | is a pointer to the beginning of the scatter-gather task list. |
isPeriphSG | is a flag to indicate it is a peripheral scatter-gather transfer (else it is memory scatter-gather transfer) |
This function is used to configure a channel for scatter-gather mode. The caller must have already set up a task list and must pass a pointer to the start of the task list as the taskList parameter. The taskCount parameter is the count of tasks in the task list, not the size of the task list. The flag bIsPeriphSG should be used to indicate if scatter-gather should be configured for peripheral or memory operation.
References ASSERT, _DMA_ControlTable::control, _DMA_ControlTable::dstEndAddr, _DMA_ControlTable::spare, _DMA_ControlTable::srcEndAddr, and UDMA_ALT_SELECT.
uint32_t DMA_getChannelSize | ( | uint32_t | channelStructIndex | ) |
Gets the current transfer size for a DMA channel control structure.
channelStructIndex | is the logical OR of the DMA channel number with either UDMA_PRI_SELECT or UDMA_ALT_SELECT. |
This function is used to get the DMA transfer size for a channel. The transfer size is the number of items to transfer, where the size of an item might be 8, 16, or 32 bits. If a partial transfer has already occurred, then the number of remaining items is returned. If the transfer is complete, then 0 is returned.
References ASSERT, and _DMA_ControlTable::control.
uint32_t DMA_getChannelMode | ( | uint32_t | channelStructIndex | ) |
Gets the transfer mode for a DMA channel control structure.
channelStructIndex | is the logical OR of the DMA channel number with either UDMA_PRI_SELECT or UDMA_ALT_SELECT. |
This function is used to get the transfer mode for the DMA channel and to query the status of a transfer on a channel. When the transfer is complete the mode is UDMA_MODE_STOP.
References ASSERT, _DMA_ControlTable::control, UDMA_MODE_ALT_SELECT, UDMA_MODE_MEM_SCATTER_GATHER, and UDMA_MODE_PER_SCATTER_GATHER.
void DMA_assignChannel | ( | uint32_t | mapping | ) |
Assigns a peripheral mapping for a DMA channel.
mapping | is a macro specifying the peripheral assignment for a channel. |
This function assigns a peripheral mapping to a DMA channel. It is used to select which peripheral is used for a DMA channel. The parameter mapping should be one of the macros named UDMA_CHn_tttt from the header file dma.h. For example, to assign DMA channel 0 to the eUSCI AO RX channel, the parameter should be the macro UDMA_CH1_EUSCIA0RX.
Please consult the data sheet for a table showing all the possible peripheral assignments for the DMA channels for a particular device.
References ASSERT, DMA_CH0_AESTRIGGER0, DMA_CH0_EUSCIA0TX, DMA_CH0_EUSCIB0TX0, DMA_CH0_EUSCIB1TX3, DMA_CH0_EUSCIB2TX2, DMA_CH0_EUSCIB3TX1, DMA_CH0_RESERVED0, DMA_CH0_TIMERA0CCR0, DMA_CH1_AESTRIGGER1, DMA_CH1_EUSCIA0RX, DMA_CH1_EUSCIB0RX0, DMA_CH1_EUSCIB1RX3, DMA_CH1_EUSCIB2RX2, DMA_CH1_EUSCIB3RX1, DMA_CH1_RESERVED0, DMA_CH1_TIMERA0CCR2, DMA_CH2_AESTRIGGER2, DMA_CH2_EUSCIA1TX, DMA_CH2_EUSCIB0TX1, DMA_CH2_EUSCIB1TX0, DMA_CH2_EUSCIB2TX3, DMA_CH2_EUSCIB3TX2, DMA_CH2_RESERVED0, DMA_CH2_TIMERA1CCR0, DMA_CH3_EUSCIA1RX, DMA_CH3_EUSCIB0RX1, DMA_CH3_EUSCIB1RX0, DMA_CH3_EUSCIB2RX3, DMA_CH3_EUSCIB3RX2, DMA_CH3_RESERVED0, DMA_CH3_RESERVED1, DMA_CH3_TIMERA1CCR2, DMA_CH4_EUSCIA2TX, DMA_CH4_EUSCIB0TX2, DMA_CH4_EUSCIB1TX1, DMA_CH4_EUSCIB2TX0, DMA_CH4_EUSCIB3TX3, DMA_CH4_RESERVED0, DMA_CH4_RESERVED1, DMA_CH4_TIMERA2CCR0, DMA_CH5_EUSCIA2RX, DMA_CH5_EUSCIB0RX2, DMA_CH5_EUSCIB1RX1, DMA_CH5_EUSCIB2RX0, DMA_CH5_EUSCIB3RX3, DMA_CH5_RESERVED0, DMA_CH5_RESERVED1, DMA_CH5_TIMERA2CCR2, DMA_CH6_EUSCIA3TX, DMA_CH6_EUSCIB0TX3, DMA_CH6_EUSCIB1TX2, DMA_CH6_EUSCIB2TX1, DMA_CH6_EUSCIB3TX0, DMA_CH6_EXTERNALPIN, DMA_CH6_RESERVED0, DMA_CH6_TIMERA3CCR0, DMA_CH7_ADC12C, DMA_CH7_EUSCIA3RX, DMA_CH7_EUSCIB0RX3, DMA_CH7_EUSCIB1RX2, DMA_CH7_EUSCIB2RX1, DMA_CH7_EUSCIB3RX0, DMA_CH7_RESERVED0, and DMA_CH7_TIMERA3CCR2.
void DMA_assignInterrupt | ( | uint32_t | interruptNumber, |
uint32_t | channel | ||
) |
Assigns a specific DMA channel to the corresponding interrupt handler. For MSP432 devices, there are three configurable interrupts, and one master interrupt. This function will assign a specific DMA channel to the provided configurable DMA interrupt.
Note that once a channel is assigned to a configurable interrupt, it will be masked in hardware from the master DMA interrupt (interruptNumber zero). This function can also be used in conjunction with the DMAIntTrigger function to provide the feature to software trigger specific channel interrupts.
interruptNumber | is the configurable interrupt to assign the given channel. Valid values are:
|
channel | is the channel to assign the interrupt |
References ASSERT, DMA_enableInterrupt(), DMA_INT1, DMA_INT1_SRCCFG_INT_SRC__M, DMA_INT2, and DMA_INT3.
void DMA_requestSoftwareTransfer | ( | uint32_t | channel | ) |
Initializes a software transfer of the corresponding DMA channel. This is done if the user wants to force a DMA on the specified channel without the hardware precondition. Specific channels can be configured using the DMA_assignChannel function.
channel | is the channel to trigger the interrupt |
uint32_t DMA_getInterruptStatus | ( | void | ) |
Gets the DMA controller channel interrupt status for interrupt zero.
This function is used to get the interrupt status of the DMA controller. The returned value is a 32-bit bit mask that indicates which channels are requesting an interrupt. This function can be used from within an interrupt handler to determine or confirm which DMA channel has requested an interrupt.
Note that this will only apply to interrupt zero for the DMA controller as only one interrupt can be associated with interrupts one through three. If an interrupt is assigned to an interrupt other than interrupt zero, it will be masked by this function.
void DMA_clearInterruptFlag | ( | uint32_t | intChannel | ) |
Clears the DMA controller channel interrupt mask for interrupt zero.
channel | is the channel interrupt to clear. |
This function is used to clear the interrupt status of the DMA controller. Note that only interrupts that weren't assigned to DMA interrupts one through three using the DMA_assignInterrupt function will be affected by thisfunctions. For other DMA interrupts, only one channel can be associated and therefore clearing in unnecessary.
void DMA_enableInterrupt | ( | uint32_t | interruptNumber | ) |
Enables the specified interrupt for the DMA controller. Note for interrupts one through three, specific channels have to be mapped to the interrupt using the DMA_assignInterrupt function.
interruptNumber | identifies which DMA interrupt is to be enabled. This interrupt should be one of the following: |
References ASSERT, DMA_INT0, DMA_INT1, DMA_INT1_SRCCFG_EN, DMA_INT2, DMA_INT2_SRCCFG_EN, DMA_INT3, and DMA_INT3_SRCCFG_EN.
Referenced by DMA_assignInterrupt().
void DMA_disableInterrupt | ( | uint32_t | interruptNumber | ) |
Disables the specified interrupt for the DMA controller.
interruptNumber | identifies which DMA interrupt is to be disabled. This interrupt should be one of the following: |
DMA_INTERR the third configurable DMA interrupt handler
Note for interrupts that are associated with a specific DMA channel (DMA_INT1 - DMA_INT3), this function will also enable that specific channel for interrupts.
References ASSERT, DMA_INT0, DMA_INT1, DMA_INT1_SRCCFG_EN, DMA_INT2, DMA_INT2_SRCCFG_EN, DMA_INT3, and DMA_INT3_SRCCFG_EN.
void DMA_registerInterrupt | ( | uint32_t | intChannel, |
void(*)(void) | intHandler | ||
) |
Registers an interrupt handler for the DMA controller.
interruptNumber | identifies which DMA interrupt is to be registered. |
intHandler | is a pointer to the function to be called when the interrupt is called. |
This function registers and enables the handler to be called when the DMA controller generates an interrupt. The interrupt parameter should be one of the following:
References ASSERT, DMA_INT0, DMA_INT1, DMA_INT2, DMA_INT3, DMA_INTERR, Interrupt_enableInterrupt(), and Interrupt_registerInterrupt().
void DMA_unregisterInterrupt | ( | uint32_t | intChannel | ) |
Unregisters an interrupt handler for the DMA controller.
interruptNumber | identifies which DMA interrupt to unregister. |
This function disables and unregisters the handler to be called for the specified DMA interrupt. The interrupt parameter should be one of the parameters as documented for the function DMA_registerInterrupt().
Note fore interrupts that are associated with a specific DMA channel (DMA_INT1 - DMA_INT3), this function will also disable that specific channel for interrupts.
References ASSERT, DMA_INT0, DMA_INT1, DMA_INT2, DMA_INT3, DMA_INTERR, Interrupt_disableInterrupt(), and Interrupt_unregisterInterrupt().