📄 dma.c
字号:
/******************************************************************************
Filename: dma.c
Target: cc2430
Revised: 16/12-2005
Revision: 1.0
Description:
This example shows how to set up a DMA transfer between two RAM locations.
See also other examples for DMA setup (e.g. AES, ADC_SERIES, FLASH).
******************************************************************************/
#include <string.h>
#include "RF04EB.h"
#include "app_ex.h"
#include "menu.h"
#include "lcd128_64.h"
#include "hal.h"
// Prototypes
void initDma(void);
void dma_main(void);
/******************************************************************************
* @fn initDma
*
* @brief
* Initializes components for the DMA transfer application example.
*
* Parameters:
*
* @param void
*
* @return void
*
******************************************************************************/
void initDma(void)
{
SET_MAIN_CLOCK_SOURCE(CRYSTAL);
INIT_GLED();
INIT_YLED();
}
/******************************************************************************
* @fn dma_main
*
* @brief
* Sets up the DMA to transfer data between to RAM locations, trigged by
* external interrupt generated by button S1. Checks validity of data
* after transfer.
*
* Parameters:
*
* @param void
*
* @return void
*
******************************************************************************/
#ifdef COMPLETE_APPLICATION
void dma_main(void){
#else
void main(void){
#endif
DMA_DESC dmaChannel;
char sourceString[56] = "This is a test string used to demonstrate DMA transfer."; //56 bytes
char destString[56];
INT8 i;
INT8 errors = 0;
initDma();
ClearScreen();
Print(0,5,"---DMA TEST---",1);
Rectangle(2 , 2 , 108 , 5);
//Clearing the destination
memset(destString,0,sizeof(destString));
// Setting up the DMA channel.
SET_WORD(dmaChannel.SRCADDRH, dmaChannel.SRCADDRL, &sourceString); // The start address of the data to be transmitted
SET_WORD(dmaChannel.DESTADDRH, dmaChannel.DESTADDRL, &destString); // The start address of the destination.
SET_WORD(dmaChannel.LENH, dmaChannel.LENL, sizeof(sourceString)); // Setting the number of bytes to transfer.
dmaChannel.VLEN = VLEN_USE_LEN; // Using the length field to determine how many bytes to transfer.
dmaChannel.PRIORITY = PRI_HIGH; // High priority.
dmaChannel.M8 = M8_USE_8_BITS; // Irrelevant since length is determined by the LENH and LENL.
dmaChannel.IRQMASK = FALSE; // The DMA shall not issue an IRQ upon completion.
dmaChannel.DESTINC = DESTINC_1; // The destination address is to be incremented by 1 after each transfer.
dmaChannel.SRCINC = SRCINC_1; // The source address inremented by 1 byte after each transfer.
dmaChannel.TRIG = DMATRIG_NONE; // The DMA channel will be started manually.
dmaChannel.TMODE = TMODE_BLOCK; // The number of bytes specified by LENH and LENL is transferred.
dmaChannel.WORDSIZE = WORDSIZE_BYTE; // One byte is transferred each time.
// Using DMA channel 0.
// Setting where the DMA channel is to read the desciptor and arming the DMA channel.
DMA_SET_ADDR_DESC0(&dmaChannel);
DMA_ABORT_CHANNEL(0);
DMA_ARM_CHANNEL(0);
//Waiting for the user to start the transfer.
if(LanguageSel == 1)
{
Print6(3,35, "Press OK",1);
Print6(4,20, "to start DMA.",1);
}
else
{
Print(3,4,"按OK键开始:",1);
}
// lcdUpdate((char*)"Press S1",(char*)"to start DMA.");
while(K_OK != ScanKey());
while(ScanKey() != 0Xff);
halWait(5);
// Clearing all DMA complete flags and starting the transfer.
DMAIRQ = 0x00;
DMA_START_CHANNEL(0);
// Waiting for the DMA to finish.
// while(K_OK != ScanKey());
if(LanguageSel == 1)
{
Print(3,8, " Waiting... ",1);
}
else
{
Print(3,4,"请稍等...",1);
}
while(!(DMAIRQ & DMA_CHANNEL_0));
if(LanguageSel == 1)
{
Print6(3,20, " Press UP ",1);
Print6(4,20, "to continue...",1);
}
else
{
Print(3,4,"按UP键继续...",1);
}
while(K_UP != ScanKey());
while(ScanKey() != 0Xff);
halWait(5);
// Verifying that data is transferred correctly
for(i=0;i<sizeof(sourceString);i++)
{
if(sourceString[i] != destString[i])
errors++;
}
//Displaying the result
if(errors == 0)
{
if(LanguageSel == 1)
{
Print6(3,20, "Dma transfer",1);
Print6(4,20, "correct! ",1);
}
else
{
Print(3,4," DMA正确! ",1);
}
}
else
{
if(LanguageSel == 1)
{
Print6(3,20, "Error in DMA",1);
Print6(4,20, " Transfer ",1);
}
else
{
Print(3,4," DMA错误! ",1);
}
}
Print6(7,13,"<CANCEL TO ESC>",1);
while (K_CANCEL != ScanKey());
while(ScanKey() != 0Xff);
halWait(5);
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -