#include "em_device.h"
#include "em_chip.h"
#include "em_usart.h"
#include "em_gpio.h"
#include "em_dma.h"
#include "em_cmu.h"
#include "em_emu.h"
#include "em_timer.h"
#include "em_int.h"
#include "em_prs.h"
#include "InitDevice.h"
#define DMA_CHANNEL_UART_TX 0 //
/* DMA init structure */
DMA_Init_TypeDef dmaInit;
/* DMA callback structure */
DMA_CB_TypeDef cb[DMA_CHAN_COUNT];//DMA_CHAN_COUN????
/** DMA control block, requires proper alignment. */
DMA_DESCRIPTOR_TypeDef dmaControlBlock[DMA_CHAN_COUNT * 2] __attribute__ ((aligned(256)));
uint8_t ucComplete = 0;
uint8_t Tx_buffer[8] = {0x30,0x31,0x32,0x33,0x34,0x35,0x0D,0x0A};
void UARTTxTransferComplete(unsigned int channel, bool primary, void *user)
{
ucComplete = 1;
GPIO_PinOutToggle(gpioPortE, 12);
}
void DMA_for_UART_Tx(void)
{
DMA_CfgChannel_TypeDef chnlCfg;
DMA_CfgDescr_TypeDef descrCfg;
/* Setting up call-back function */
cb[DMA_CHANNEL_UART_TX].cbFunc = UARTTxTransferComplete; //Set DMA is completed, whether to call the callback function. If there is no callback function, it is set to NULL
cb[DMA_CHANNEL_UART_TX].userPtr = NULL;
/* Setting up channel */
chnlCfg.highPri = false;
chnlCfg.enableInt = true;
//Set the DMA to send the next byte of the conditions, here is: When the Tx is completed, DMA then start to take down a byte to send
chnlCfg.select = DMAREQ_USART1_TXEMPTY;
//Initializes the function of the callback part of the DMA register
chnlCfg.cb = &(cb[DMA_CHANNEL_UART_TX]);
DMA_CfgChannel(DMA_CHANNEL_UART_TX, &chnlCfg);
//Register that defines the logical portion of the DMA
/* Setting up channel descriptor */
descrCfg.dstInc = dmaDataIncNone; //Meaning of the target address unchanged
descrCfg.srcInc = dmaDataInc1; //This means that the source address is incremented by one byte at a time
descrCfg.size = dmaDataSize1; //The byte unit of each transmission
descrCfg.arbRate = dmaArbitrate1; //DMA arbitration, one arbitration for every 1 byte sent
descrCfg.hprot = 0;
DMA_CfgDescr(DMA_CHANNEL_UART_TX, true, &descrCfg);
}
void DMAInit(void)
{
CMU_ClockEnable(cmuClock_DMA, true);
/* Initializing the DMA */
dmaInit.hprot = 0;
dmaInit.controlBlock = dmaControlBlock;
DMA_Init(&dmaInit);
}
int main(void)
{
/* Initialize chip */
CHIP_Init();
enter_DefaultMode_from_RESET();
GPIO_PinModeSet(gpioPortE, 12, gpioModePushPullDrive, 0); /* TX */
DMAInit();
DMA_for_UART_Tx();
ucComplete = 1;
GPIO_PinOutSet(DE_PORT, DE_PIN);
/* Infinite blink loop */
while(1)
{
if(ucComplete)
{
GPIO_PinOutSet(DE_PORT, DE_PIN);
DMA_ActivateBasic(DMA_CHANNEL_UART_TX,
true,
false,
(void *)&(USART1->TXDATA),
(void *)&Tx_buffer,
sizeof(Tx_buffer) - 1);
ucComplete = 0;
}
}
}
#include "em_chip.h"
#include "em_usart.h"
#include "em_gpio.h"
#include "em_dma.h"
#include "em_cmu.h"
#include "em_emu.h"
#include "em_timer.h"
#include "em_int.h"
#include "em_prs.h"
#include "InitDevice.h"
#define DMA_CHANNEL_UART_TX 0 //
/* DMA init structure */
DMA_Init_TypeDef dmaInit;
/* DMA callback structure */
DMA_CB_TypeDef cb[DMA_CHAN_COUNT];//DMA_CHAN_COUN????
/** DMA control block, requires proper alignment. */
DMA_DESCRIPTOR_TypeDef dmaControlBlock[DMA_CHAN_COUNT * 2] __attribute__ ((aligned(256)));
uint8_t ucComplete = 0;
uint8_t Tx_buffer[8] = {0x30,0x31,0x32,0x33,0x34,0x35,0x0D,0x0A};
void UARTTxTransferComplete(unsigned int channel, bool primary, void *user)
{
ucComplete = 1;
GPIO_PinOutToggle(gpioPortE, 12);
}
void DMA_for_UART_Tx(void)
{
DMA_CfgChannel_TypeDef chnlCfg;
DMA_CfgDescr_TypeDef descrCfg;
/* Setting up call-back function */
cb[DMA_CHANNEL_UART_TX].cbFunc = UARTTxTransferComplete; //Set DMA is completed, whether to call the callback function. If there is no callback function, it is set to NULL
cb[DMA_CHANNEL_UART_TX].userPtr = NULL;
/* Setting up channel */
chnlCfg.highPri = false;
chnlCfg.enableInt = true;
//Set the DMA to send the next byte of the conditions, here is: When the Tx is completed, DMA then start to take down a byte to send
chnlCfg.select = DMAREQ_USART1_TXEMPTY;
//Initializes the function of the callback part of the DMA register
chnlCfg.cb = &(cb[DMA_CHANNEL_UART_TX]);
DMA_CfgChannel(DMA_CHANNEL_UART_TX, &chnlCfg);
//Register that defines the logical portion of the DMA
/* Setting up channel descriptor */
descrCfg.dstInc = dmaDataIncNone; //Meaning of the target address unchanged
descrCfg.srcInc = dmaDataInc1; //This means that the source address is incremented by one byte at a time
descrCfg.size = dmaDataSize1; //The byte unit of each transmission
descrCfg.arbRate = dmaArbitrate1; //DMA arbitration, one arbitration for every 1 byte sent
descrCfg.hprot = 0;
DMA_CfgDescr(DMA_CHANNEL_UART_TX, true, &descrCfg);
}
void DMAInit(void)
{
CMU_ClockEnable(cmuClock_DMA, true);
/* Initializing the DMA */
dmaInit.hprot = 0;
dmaInit.controlBlock = dmaControlBlock;
DMA_Init(&dmaInit);
}
int main(void)
{
/* Initialize chip */
CHIP_Init();
enter_DefaultMode_from_RESET();
GPIO_PinModeSet(gpioPortE, 12, gpioModePushPullDrive, 0); /* TX */
DMAInit();
DMA_for_UART_Tx();
ucComplete = 1;
GPIO_PinOutSet(DE_PORT, DE_PIN);
/* Infinite blink loop */
while(1)
{
if(ucComplete)
{
GPIO_PinOutSet(DE_PORT, DE_PIN);
DMA_ActivateBasic(DMA_CHANNEL_UART_TX,
true,
false,
(void *)&(USART1->TXDATA),
(void *)&Tx_buffer,
sizeof(Tx_buffer) - 1);
ucComplete = 0;
}
}
}