/**************************************************************************//**
* [url=home.php?mod=space&uid=288409]@file[/url] main.c
* [url=home.php?mod=space&uid=895143]@version[/url] V1.00
* $Revision: 7 $
* $Date: 14/10/28 5:32p $
* [url=home.php?mod=space&uid=247401]@brief[/url] Use PDMA channel 2 to transfer data from memory to memory.
* @note
* Copyright (C) 2014 Nuvoton Technology Corp. All rights reserved.
*
******************************************************************************/
#include <stdio.h>
#include "M451Series.h"
/*---------------------------------------------------------------------------------------------------------*/
/* Macro, type and constant definitions */
/*---------------------------------------------------------------------------------------------------------*/
#define PLL_CLOCK 72000000
/*---------------------------------------------------------------------------------------------------------*/
/* Global variables */
/*---------------------------------------------------------------------------------------------------------*/
uint32_t PDMA_TEST_LENGTH = 12;
uint8_t SrcArray[256] = "hello world!";
uint32_t volatile u32IsSendOver = 0;
/**
* @brief DMA IRQ
*
* @param None
*
* [url=home.php?mod=space&uid=266161]@return[/url] None
*
* @details The DMA default IRQ, declared in startup_nuc400series.s.
*/
void PDMA_IRQHandler(void)
{
uint32_t status = PDMA_GET_INT_STATUS();
if(status & 0x1) /* abort */
{
if(PDMA_GET_ABORT_STS() & 0x4)
u32IsSendOver = 2;
PDMA_CLR_ABORT_FLAG(PDMA_ABTSTS_ABTIFn_Msk);
}
else if(status & 0x2) /* done */
{
if(PDMA_GET_TD_STS() & 0x4)
u32IsSendOver = 1;
PDMA_CLR_TD_FLAG(PDMA_TDSTS_TDIFn_Msk);
}
else
printf("unknown interrupt !!\n");
}
void SYS_Init(void)
{
/*---------------------------------------------------------------------------------------------------------*/
/* Init System Clock */
/*---------------------------------------------------------------------------------------------------------*/
/* Enable HIRC clock (Internal RC 22.1184MHz) */
CLK_EnableXtalRC(CLK_PWRCTL_HIRCEN_Msk);
/* Waiting for HIRC clock ready */
CLK_WaitClockReady(CLK_STATUS_HIRCSTB_Msk);
/* Select HCLK clock source as HIRC and and HCLK clock divider as 1 */
CLK_SetHCLK(CLK_CLKSEL0_HCLKSEL_HIRC, CLK_CLKDIV0_HCLK(1));
/* Enable HXT clock (external XTAL 12MHz) */
CLK_EnableXtalRC(CLK_PWRCTL_HXTEN_Msk);
/* Waiting for HXT clock ready */
CLK_WaitClockReady(CLK_STATUS_HXTSTB_Msk);
/* Set core clock as PLL_CLOCK from PLL */
CLK_SetCoreClock(PLL_CLOCK);
/* Waiting for PLL clock ready */
CLK_WaitClockReady(CLK_STATUS_PLLSTB_Msk);
/* Enable UART module clock */
CLK_EnableModuleClock(UART0_MODULE);
/* Select UART module clock source as HXT and UART module clock divider as 1 */
CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UARTSEL_HXT, CLK_CLKDIV0_UART(1));
/* Enable PDMA clock source */
CLK_EnableModuleClock(PDMA_MODULE);
/*---------------------------------------------------------------------------------------------------------*/
/* Init I/O Multi-function */
/*---------------------------------------------------------------------------------------------------------*/
/* Set PD multi-function pins for UART0 RXD and TXD */
SYS->GPD_MFPL &= ~(SYS_GPD_MFPL_PD0MFP_Msk | SYS_GPD_MFPL_PD1MFP_Msk);
SYS->GPD_MFPL |= (SYS_GPD_MFPL_PD0MFP_UART0_RXD | SYS_GPD_MFPL_PD1MFP_UART0_TXD);
}
void UART0_Init()
{
/*---------------------------------------------------------------------------------------------------------*/
/* Init UART */
/*---------------------------------------------------------------------------------------------------------*/
/* Reset UART module */
SYS_ResetModule(UART0_RST);
/* Configure UART0 and set UART0 baud rate */
UART_Open(UART0, 115200);
}
void PDMA_Init()
{
/* Enable PDMA clock source */
CLK_EnableModuleClock(PDMA_MODULE);
/* Reset PDMA module */
SYS_ResetModule(PDMA_RST);
PDMA_Open(0x4);
PDMA_SetTransferCnt(2, PDMA_WIDTH_8, PDMA_TEST_LENGTH);
PDMA_SetTransferAddr(2, (uint32_t)SrcArray, PDMA_SAR_INC, (uint32_t)&UART0->DAT, PDMA_DAR_FIX);
PDMA_SetTransferMode(2, PDMA_UART0_TX, FALSE, 0);
PDMA_EnableInt(2, PDMA_INT_TRANS_DONE);
NVIC_EnableIRQ(PDMA_IRQn);
UART0->INTEN = UART0->INTEN | (1<<14);//UARTO DMA send enable
}
void PDMA_Set()
{
PDMA_SetTransferCnt(2, PDMA_WIDTH_8, PDMA_TEST_LENGTH);
PDMA_SetTransferAddr(2, (uint32_t)SrcArray, PDMA_SAR_INC, (uint32_t)&UART0->DAT, PDMA_DAR_FIX);
PDMA_SetTransferMode(2, PDMA_UART0_TX, FALSE, 0);
UART0->INTEN = UART0->INTEN | (1<<14);//UARTO DMA send enable
}
/*---------------------------------------------------------------------------------------------------------*/
/* Main Function */
/*---------------------------------------------------------------------------------------------------------*/
int main(void)
{
/* Unlock protected registers */
SYS_UnlockReg();
/* Init System, IP clock and multi-function I/O */
SYS_Init();
/* Lock protected registers */
/* If user want to write protected register, please issue SYS_UnlockReg() to unlock protected register. */
SYS_LockReg();
/* Init UART for printf */
UART0_Init();
printf("\n\nCPU [url=home.php?mod=space&uid=72445]@[/url] %dHz\n", SystemCoreClock);
printf("+------------------------------------------------------+ \n");
printf("| UART PDMA SEND Sample Code | \n");
printf("+------------------------------------------------------+ \n");
PDMA_Init();
while(1)
{
if(u32IsSendOver == 1)
{
u32IsSendOver = 0;
PDMA_Set();
}
}
}
|