📄 udma.c
字号:
//*****************************************************************************
//
// udma.c - Driver for the micro-DMA controller.
//
// Copyright (c) 2007-2010 Texas Instruments Incorporated. All rights reserved.
// Software License Agreement
//
// Texas Instruments (TI) is supplying this software for use solely and
// exclusively on TI's microcontroller products. The software is owned by
// TI and/or its suppliers, and is protected under applicable copyright
// laws. You may not combine this software with "viral" open-source
// software in order to form a larger program.
//
// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
// DAMAGES, FOR ANY REASON WHATSOEVER.
//
// This is part of revision 5821 of the Stellaris Peripheral Driver Library.
//
//*****************************************************************************
//*****************************************************************************
//
//! \addtogroup udma_api
//! @{
//
//*****************************************************************************
#include "inc/hw_types.h"
#include "inc/hw_udma.h"
#include "driverlib/debug.h"
#include "driverlib/interrupt.h"
#include "driverlib/udma.h"
//*****************************************************************************
//
//! Enables the uDMA controller for use.
//!
//! This function enables the uDMA controller. The uDMA controller must be
//! enabled before it can be configured and used.
//!
//! \return None.
//
//*****************************************************************************
void
uDMAEnable(void)
{
//
// Set the master enable bit in the config register.
//
HWREG(UDMA_CFG) = UDMA_CFG_MASTEN;
}
//*****************************************************************************
//
//! Disables the uDMA controller for use.
//!
//! This function disables the uDMA controller. Once disabled, the uDMA
//! controller will not operate until re-enabled with uDMAEnable().
//!
//! \return None.
//
//*****************************************************************************
void
uDMADisable(void)
{
//
// Clear the master enable bit in the config register.
//
HWREG(UDMA_CFG) = 0;
}
//*****************************************************************************
//
//! Gets the uDMA error status.
//!
//! This function returns the uDMA error status. It should be called from
//! within the uDMA error interrupt handler to determine if a uDMA error
//! occurred.
//!
//! \return Returns non-zero if a uDMA error is pending.
//
//*****************************************************************************
unsigned long
uDMAErrorStatusGet(void)
{
//
// Return the uDMA error status.
//
return(HWREG(UDMA_ERRCLR));
}
//*****************************************************************************
//
//! Clears the uDMA error interrupt.
//!
//! This function clears a pending uDMA error interrupt. It should be called
//! from within the uDMA error interrupt handler to clear the interrupt.
//!
//! \return None.
//
//*****************************************************************************
void
uDMAErrorStatusClear(void)
{
//
// Clear the uDMA error interrupt.
//
HWREG(UDMA_ERRCLR) = 1;
}
//*****************************************************************************
//
//! Enables a uDMA channel for operation.
//!
//! \param ulChannel is the channel number to enable.
//!
//! This function enables a specific uDMA channel for use. This function must
//! be used to enable a channel before it can be used to perform a uDMA
//! transfer.
//!
//! When a uDMA transfer is completed, the channel will be automatically
//! disabled by the uDMA controller. Therefore, this function should be called
//! prior to starting up any new transfer.
//!
//! The \e ulChannel parameter must be one of the following:
//!
//! - \b UDMA_CHANNEL_UART0RX for UART 0 receive channel
//! - \b UDMA_CHANNEL_UART0TX for UART 0 transmit channel
//! - \b UDMA_CHANNEL_UART1RX for UART 1 receive channel
//! - \b UDMA_CHANNEL_UART1TX for UART 1 transmit channel
//! - \b UDMA_CHANNEL_SSI0RX for SSI 0 receive channel
//! - \b UDMA_CHANNEL_SSI0TX for SSI 0 transmit channel
//! - \b UDMA_CHANNEL_SSI1RX for SSI 1 receive channel
//! - \b UDMA_CHANNEL_SSI1TX for SSI 1 transmit channel
//! - \b UDMA_CHANNEL_SW for the software dedicated uDMA channel
//!
//! And for microcontrollers that have a USB peripheral:
//!
//! - \b UDMA_CHANNEL_USBEP1RX for USB endpoint 1 receive
//! - \b UDMA_CHANNEL_USBEP1TX for USB endpoint 1 transmit
//! - \b UDMA_CHANNEL_USBEP2RX for USB endpoint 2 receive
//! - \b UDMA_CHANNEL_USBEP2TX for USB endpoint 2 transmit
//! - \b UDMA_CHANNEL_USBEP3RX for USB endpoint 3 receive
//! - \b UDMA_CHANNEL_USBEP3TX for USB endpoint 3 transmit
//!
//! \return None.
//
//*****************************************************************************
void
uDMAChannelEnable(unsigned long ulChannel)
{
//
// Check the arguments.
//
ASSERT(ulChannel < 32);
//
// Set the bit for this channel in the enable set register.
//
HWREG(UDMA_ENASET) = 1 << ulChannel;
}
//*****************************************************************************
//
//! Disables a uDMA channel for operation.
//!
//! \param ulChannel is the channel number to disable.
//!
//! This function disables a specific uDMA channel. Once disabled, a channel
//! will not respond to uDMA transfer requests until re-enabled via
//! uDMAChannelEnable().
//!
//! The \e ulChannel parameter must be one of the following:
//!
//! - \b UDMA_CHANNEL_UART0RX for UART 0 receive channel
//! - \b UDMA_CHANNEL_UART0TX for UART 0 transmit channel
//! - \b UDMA_CHANNEL_UART1RX for UART 1 receive channel
//! - \b UDMA_CHANNEL_UART1TX for UART 1 transmit channel
//! - \b UDMA_CHANNEL_SSI0RX for SSI 0 receive channel
//! - \b UDMA_CHANNEL_SSI0TX for SSI 0 transmit channel
//! - \b UDMA_CHANNEL_SSI1RX for SSI 1 receive channel
//! - \b UDMA_CHANNEL_SSI1TX for SSI 1 transmit channel
//! - \b UDMA_CHANNEL_SW for the software dedicated uDMA channel
//!
//! And for microcontrollers that have a USB peripheral:
//!
//! - \b UDMA_CHANNEL_USBEP1RX for USB endpoint 1 receive
//! - \b UDMA_CHANNEL_USBEP1TX for USB endpoint 1 transmit
//! - \b UDMA_CHANNEL_USBEP2RX for USB endpoint 2 receive
//! - \b UDMA_CHANNEL_USBEP2TX for USB endpoint 2 transmit
//! - \b UDMA_CHANNEL_USBEP3RX for USB endpoint 3 receive
//! - \b UDMA_CHANNEL_USBEP3TX for USB endpoint 3 transmit
//!
//! \return None.
//
//*****************************************************************************
void
uDMAChannelDisable(unsigned long ulChannel)
{
//
// Check the arguments.
//
ASSERT(ulChannel < 32);
//
// Set the bit for this channel in the enable clear register.
//
HWREG(UDMA_ENACLR) = 1 << ulChannel;
}
//*****************************************************************************
//
//! Checks if a uDMA channel is enabled for operation.
//!
//! \param ulChannel is the channel number to check.
//!
//! This function checks to see if a specific uDMA channel is enabled. This
//! can be used to check the status of a transfer, since the channel will
//! be automatically disabled at the end of a transfer.
//!
//! The \e ulChannel parameter must be one of the following:
//!
//! - \b UDMA_CHANNEL_UART0RX for UART 0 receive channel
//! - \b UDMA_CHANNEL_UART0TX for UART 0 transmit channel
//! - \b UDMA_CHANNEL_UART1RX for UART 1 receive channel
//! - \b UDMA_CHANNEL_UART1TX for UART 1 transmit channel
//! - \b UDMA_CHANNEL_SSI0RX for SSI 0 receive channel
//! - \b UDMA_CHANNEL_SSI0TX for SSI 0 transmit channel
//! - \b UDMA_CHANNEL_SSI1RX for SSI 1 receive channel
//! - \b UDMA_CHANNEL_SSI1TX for SSI 1 transmit channel
//! - \b UDMA_CHANNEL_SW for the software dedicated uDMA channel
//!
//! And for microcontrollers that have a USB peripheral:
//!
//! - \b UDMA_CHANNEL_USBEP1RX for USB endpoint 1 receive
//! - \b UDMA_CHANNEL_USBEP1TX for USB endpoint 1 transmit
//! - \b UDMA_CHANNEL_USBEP2RX for USB endpoint 2 receive
//! - \b UDMA_CHANNEL_USBEP2TX for USB endpoint 2 transmit
//! - \b UDMA_CHANNEL_USBEP3RX for USB endpoint 3 receive
//! - \b UDMA_CHANNEL_USBEP3TX for USB endpoint 3 transmit
//!
//! \return Returns \b true if the channel is enabled, \b false if disabled.
//
//*****************************************************************************
tBoolean
uDMAChannelIsEnabled(unsigned long ulChannel)
{
//
// Check the arguments.
//
ASSERT(ulChannel < 32);
//
// AND the specified channel bit with the enable register, and return the
// result.
//
return((HWREG(UDMA_ENASET) & (1 << ulChannel)) ? true : false);
}
//*****************************************************************************
//
//! Sets the base address for the channel control table.
//!
//! \param pControlTable is a pointer to the 1024 byte aligned base address
//! of the uDMA channel control table.
//!
//! This function sets the base address of the channel control table. This
//! table resides in system memory and holds control information for each uDMA
//! channel. The table must be aligned on a 1024 byte boundary. The base
//! address must be set before any of the channel functions can be used.
//!
//! The size of the channel control table depends on the number of uDMA
//! channels, and which transfer modes are used. Refer to the introductory
//! text and the microcontroller datasheet for more information about the
//! channel control table.
//!
//! \return None.
//
//*****************************************************************************
void
uDMAControlBaseSet(void *pControlTable)
{
//
// Check the arguments.
//
ASSERT(((unsigned long)pControlTable & ~0x3FF) ==
(unsigned long)pControlTable);
ASSERT((unsigned long)pControlTable >= 0x20000000);
//
// Program the base address into the register.
//
HWREG(UDMA_CTLBASE) = (unsigned long)pControlTable;
}
//*****************************************************************************
//
//! 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 uDMA
//! channel.
//!
//! \return Returns a pointer to the base address of the channel control table.
//
//*****************************************************************************
void *
uDMAControlBaseGet(void)
{
//
// Read the current value of the control base register, and return it to
// the caller.
//
return((void *)HWREG(UDMA_CTLBASE));
}
//*****************************************************************************
//
//! Requests a uDMA channel to start a transfer.
//!
//! \param ulChannel is the channel number on which to request a uDMA transfer.
//!
//! This function allows software to request a uDMA channel to begin a
//! transfer. This 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.
//!
//! The \e ulChannel parameter must be one of the following:
//!
//! - \b UDMA_CHANNEL_UART0RX for UART 0 receive channel
//! - \b UDMA_CHANNEL_UART0TX for UART 0 transmit channel
//! - \b UDMA_CHANNEL_UART1RX for UART 1 receive channel
//! - \b UDMA_CHANNEL_UART1TX for UART 1 transmit channel
//! - \b UDMA_CHANNEL_SSI0RX for SSI 0 receive channel
//! - \b UDMA_CHANNEL_SSI0TX for SSI 0 transmit channel
//! - \b UDMA_CHANNEL_SSI1RX for SSI 1 receive channel
//! - \b UDMA_CHANNEL_SSI1TX for SSI 1 transmit channel
//! - \b UDMA_CHANNEL_SW for the software dedicated uDMA channel
//!
//! And for microcontrollers that have a USB peripheral:
//!
//! - \b UDMA_CHANNEL_USBEP1RX for USB endpoint 1 receive
//! - \b UDMA_CHANNEL_USBEP1TX for USB endpoint 1 transmit
//! - \b UDMA_CHANNEL_USBEP2RX for USB endpoint 2 receive
//! - \b UDMA_CHANNEL_USBEP2TX for USB endpoint 2 transmit
//! - \b UDMA_CHANNEL_USBEP3RX for USB endpoint 3 receive
//! - \b UDMA_CHANNEL_USBEP3TX for USB endpoint 3 transmit
//!
//! \note If the channel is \b UDMA_CHANNEL_SW and interrupts are used, then
//! the completion will be signaled on the uDMA dedicated interrupt. If a
//! peripheral channel is used, then the completion will be signaled on the
//! peripheral's interrupt.
//!
//! \return None.
//
//*****************************************************************************
void
uDMAChannelRequest(unsigned long ulChannel)
{
//
// Check the arguments.
//
ASSERT(ulChannel < 32);
//
// Set the bit for this channel in the software uDMA request register.
//
HWREG(UDMA_SWREQ) = 1 << ulChannel;
}
//*****************************************************************************
//
//! Enables attributes of a uDMA channel.
//!
//! \param ulChannel is the channel to configure.
//! \param ulAttr is a combination of attributes for the channel.
//!
//! The \e ulChannel parameter must be one of the following:
//!
//! - \b UDMA_CHANNEL_UART0RX for UART 0 receive channel
//! - \b UDMA_CHANNEL_UART0TX for UART 0 transmit channel
//! - \b UDMA_CHANNEL_UART1RX for UART 1 receive channel
//! - \b UDMA_CHANNEL_UART1TX for UART 1 transmit channel
//! - \b UDMA_CHANNEL_SSI0RX for SSI 0 receive channel
//! - \b UDMA_CHANNEL_SSI0TX for SSI 0 transmit channel
//! - \b UDMA_CHANNEL_SSI1RX for SSI 1 receive channel
//! - \b UDMA_CHANNEL_SSI1TX for SSI 1 transmit channel
//! - \b UDMA_CHANNEL_SW for the software dedicated uDMA channel
//!
//! And for microcontrollers that have a USB peripheral:
//!
//! - \b UDMA_CHANNEL_USBEP1RX for USB endpoint 1 receive
//! - \b UDMA_CHANNEL_USBEP1TX for USB endpoint 1 transmit
//! - \b UDMA_CHANNEL_USBEP2RX for USB endpoint 2 receive
//! - \b UDMA_CHANNEL_USBEP2TX for USB endpoint 2 transmit
//! - \b UDMA_CHANNEL_USBEP3RX for USB endpoint 3 receive
//! - \b UDMA_CHANNEL_USBEP3TX for USB endpoint 3 transmit
//!
//! The \e ulAttr parameter is the logical OR of any of the following:
//!
//! - \b UDMA_ATTR_USEBURST is used to restrict transfers to use only a burst
//! mode.
//! - \b UDMA_ATTR_ALTSELECT is used to select the alternate control structure
//! for this channel.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -