6747的串口通过EDMA接收数据,最后只收到32个字节 后续的数据丢失了,是什么原因,个人感觉好像DMA的空间填满了,没有清空,所以新的数据丢失了,但是不知道怎样处理,太着急了,希望高手指点一下!!! DMA配置如下:
//——————————————————————————
// File edma3.c
//——————————————————————————
// Copyright (c) 2010, Texas Instruments Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the Texas Instruments Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//——————————————————————————
#include <stdio.h>
#include "edma3.h"
#include "app.h"
#include "UniCtrlDspcfg.h"
#include "UniCtrlDspMain.h"
//——————————————————————————
// Local Variables
//——————————————————————————
static CSL_Edma3ccRegsOvly edmaCcRegs = (CSL_Edma3ccRegsOvly)CSL_EDMA3CC_0_REGS;
void *uart_register = (void *)CSL_UART_1_REGS ;//CSL_UART_1_REGS
//——————————————————————————
// Functions
//——————————————————————————
void edmaInit()
{
edmaCcRegs->ECR = 0xffffffff; // clear events 0 -> 31
edmaCcRegs->SECR = 0xffffffff; // clear secondary events 0 -> 31
edmaCcRegs->IECR = 0xffffffff; // disable all interrupts
edmaCcRegs->ICR = 0xffffffff; // clear all pending interrupts
}
//发送数据
//void setup_edma_pingpong_xmt(void *src_ping_L, void *src_pong_L,
// void *src_ping_R, void *src_pong_R,
// void *dst,
// Uint32 sample_size, Uint32 sample_count)
void setup_edma_uart_xmt(void *src_ping_L,Uint32 sample_size)
{
CSL_Edma3ccParamSetRegs param;
param.OPT = (EDMA_XMT_PING_TCC << 12) | (1 << 20); // transfer complete interrupt enabled
param.SRC = (Uint32)src_ping_L; //源地址 发送地址 20160412mcg
param.A_B_CNT = (sample_size<<16)| 0x0001; //(1 << 16) | sample_size; // actual format: BCNT|ACNT
param.DST = (Uint32)uart_register; //(Uint32)dst; //目的地址 数据的接收地址 20160412mcg
param.SRC_DST_BIDX = (0 << 16)| (0x0001); //0x0000; //实现多帧数据传输时设置源索引参数 mcg20160412// actual format: DSTBIDX|SCRBIDX
param.LINK_BCNTRLD = (0 << 16) | (0xffff); //(2 << 16) | (EDMA_XMTPONG * 0x20); // actual format: BCNTRLD|LINK
param.SRC_DST_CIDX = (0 << 16)| (0x0000); //(0 << 16) | (ping_c_idx & 0x0000FFFF); // actual format: DSTCIDX|SRCCIDX
param.CCNT = 0x0001;//sample_count; //三维计数器,当只有一帧数据时设置0x0001 mcg20160412
edmaWritePaRAM(EDMA_UART2_TX, ¶m); // EDMA_MCASPTXCH
}
void setup_edma_uart_rcv(void *dst_ping_L,Uint32 sample_size)
{
CSL_Edma3ccParamSetRegs param;
// 1. setup channel PaRAM slot
param.OPT = (EDMA_RCV_PING_TCC << 12) | (1 << 20); // transfer complete interrupt enabled
param.SRC = (Uint32)uart_register; //(Uint32)src; //源地址
param.A_B_CNT = (sample_size<<16)| 0x0001;//(1 << 16) | sample_size; // // actual format: BCNT|ACNT
param.DST = (Uint32)dst_ping_L; //目的地址(Uint16)
param.SRC_DST_BIDX = (1 << 16)| (0x0000); //0x0000; //实现多帧数据传输时设置源索引参数//(ping_offset << 16) | 0; // actual format: DSTBIDX|SCRBIDX
param.LINK_BCNTRLD = (0 << 16) | (0xffff); //(2 << 16) | (EDMA_RCVPONG * 0x20); // actual format: BCNTRLD|LINK
param.SRC_DST_CIDX = (0 << 16)| (0x0000); //((ping_c_idx << 16) & 0xFFFF0000) | 0; // actual format: DSTCIDX|SRCCIDX
param.CCNT = 0x0001; //sample_count; //三维计数器,当只有一帧数据时设置0x0001 mcg20160412
edmaWritePaRAM(EDMA_UART2_RX, ¶m);// EDMA_MCASPRXCH
}
void edmaWritePaRAM(Int ParamNum, CSL_Edma3ccParamSetRegs *ptrParamInfo)
{
edmaCcRegs->PARAMSET[ParamNum].OPT = ptrParamInfo->OPT;
edmaCcRegs->PARAMSET[ParamNum].SRC = ptrParamInfo->SRC;
edmaCcRegs->PARAMSET[ParamNum].A_B_CNT = ptrParamInfo->A_B_CNT;
edmaCcRegs->PARAMSET[ParamNum].DST = ptrParamInfo->DST;
edmaCcRegs->PARAMSET[ParamNum].SRC_DST_BIDX = ptrParamInfo->SRC_DST_BIDX;
edmaCcRegs->PARAMSET[ParamNum].LINK_BCNTRLD = ptrParamInfo->LINK_BCNTRLD; edmaCcRegs->PARAMSET[ParamNum].SRC_DST_CIDX = ptrParamInfo->SRC_DST_CIDX;
edmaCcRegs->PARAMSET[ParamNum].CCNT = ptrParamInfo->CCNT;
}
void edmaSetEvent(Int channelNumber)
{
int mask;
mask = 1 << channelNumber;
edmaCcRegs->ESR = mask;
}
void EdmaIntClear(Int channelNumber)
{
edmaCcRegs->ICR = 1 << channelNumber; }
void EdmaIntEnable(Int intNumber)
{
edmaCcRegs->IESR = 1 << intNumber;
edmaCcRegs->DRA[0].DRAE &= ~(1 << intNumber);
edmaCcRegs->DRA[1].DRAE |= 1 << intNumber;}
// not a tested function
void EdmaIntDisable(Int intNumber)
{
int mask;
mask = 1 << intNumber;
edmaCcRegs->DRA[0].DRAE &= ~mask;
}
void EdmaEnableChannel(Int channelNumber, Int QueueNumber)
{
int mask;
edmaCcRegs->EMCR = 1 << channelNumber;
edmaCcRegs->SECR = 1 << channelNumber;
QueueNumber &= 1; // only 0 or 1 are valid
mask = 0x07 << (4 * (channelNumber & 0x07) );
edmaCcRegs->DMAQNUM[channelNumber >> 3] &= ~mask;
edmaCcRegs->DMAQNUM[channelNumber >> 3] |= QueueNumber << (4 * (channelNumber & 0x07) ); edmaCcRegs->EESR = 1 << channelNumber;
}
void EdmaDisableChannel(Int channelNumber)
{
edmaCcRegs->EECR = 1 << channelNumber;
}
void edmaWaitForEvent(int event)
{
Uint32 mask = 1 << event;
while((edmaCcRegs->IPR & mask) == NULL)
asm(" nop");
EdmaIntClear(event);
}
void edma3ccIsr()
{
while(edmaCcRegs->IPR)//edmaCcRegs->SECR
{
if (edmaCcRegs->IPR & (1 << EDMA_RCV_PING_TCC)) // receive channel (ping)
{
EdmaIntClear(EDMA_RCV_PING_TCC);//sem_udpstart;//sem_nav_x
SEM_post(&sem_udpstart);//add by mcg 20160412
// SEM_post(&rcv_ping_sem);
//LOG_printf(&trace, "[ISR]: receive ping!");
}
// if (edmaCcRegs->IPR & (1 << EDMA_RCV_PONG_TCC)) // receive channel (pong)
// {
// EdmaIntClear(EDMA_RCV_PONG_TCC);
// // SEM_post(&rcv_pong_sem);
// //LOG_printf(&trace, "[ISR]: receive pong!");
// }
if (edmaCcRegs->IPR & (1 << EDMA_XMT_PING_TCC)) // transmit channel (ping)
{
EdmaIntClear(EDMA_XMT_PING_TCC);
SEM_post(&sem_nav_x);//add by mcg 20160412
// SEM_post(&xmt_ping_sem);
//LOG_printf(&trace, "[ISR]: transmit ping!");
}
// if (edmaCcRegs->IPR & (1 << EDMA_XMT_PONG_TCC)) // transmit channel (pong)
// {
// EdmaIntClear(EDMA_XMT_PONG_TCC);
// // SEM_post(&xmt_pong_sem);
// //LOG_printf(&trace, "[ISR]: transmit pong!");
// }
}
return;
}
//——————————————————————————
// End of File edma3.c
//——————————————————————————
串口配置如下所示:
UART_Handle EVMC6747_UART_open( Uint16 id, Uint32 baudrate )
{
UART_Handle uart_handle;
Uint32 divisor;
volatile Uint16 dummy;
/*
* UART clk / baudrate
* = 24,000,000 / (115200 * 16)
*/
// divisor = 120000000 / ( baudrate * 16);
divisor = 120000000 / ( baudrate*16);
switch ( id )
{
case 0:
uart_handle = ( UART_Handle )&UART_MODULE_0;
break;
case 1:
uart_handle = ( UART_Handle )&UART_MODULE_1;
break;
case 2:
uart_handle = ( UART_Handle )&UART_MODULE_2;
break;
default:
return ( UART_Handle )-1;
}
uart_handle->regs->PWREMU_MGMT = 0; // Reset UART TX & RX components
EVMC6747_wait( 100 );
uart_handle->regs->DLL = (divisor & 0xff); // Set baud rate
uart_handle->regs->DLH = (divisor >> 8);
// uart_handle->regs->FCR = 0x0001;
// uart_handle->regs->FCR = 0x0007; // Clear UART TX & RX FIFOs
// uart_handle->regs->FCR = 0x81; // 1bytes FIFO mode 41 0x0001
//*****************
uart_handle->regs->FCR = 0x01;
// uart_handle->regs->FCR |= 0x0007; // Clear UART TX & RX FIFOs
uart_handle->regs->FCR |= (1<<3); // 1bytes FIFO mode 41 0x0001
// uart_handle->regs->FCR = 0x87;
// uart_handle->regs->FCR = 0x81;
//**********************
//0x01: 1 bytes FIFO mode //0x41: 4 bytes FIFO mode //0x81: 8 bytes FIFO mode //0xC1: 14 bytes FIFO mode uart_handle->regs->IER = 0x0003; // Enable interrupts 0x0003 (0x00000003u)
uart_handle->regs->LCR = 0x0003; // 8-bit words,
// 1 STOP bit generated,
// No Parity, No Stick paritiy,
// No Break control
uart_handle->regs->MCR = 0x0000; // RTS & CTS disabled,
// Loopback mode disabled,
// Autoflow disabled
uart_handle->regs->PWREMU_MGMT = 0xE001; // Enable TX & RX componenets
// Clear any pre-existing characters
dummy = uart_handle->regs->THR;
edmaInit();///DMA初始化20160412mcg
// enable interrupts 使能中断
// ICR = (1 << 8); // clear INT8 (precaution)
// IER |= (1 << 8); // enable INT8 as CPU interrupt
// IER |= (1 << 11); // enable RTDX interrupts
// IER |= (1 << 12); // enable RTDX interrupts
//edma3ccIsr();//执行中断函数 20160413mcg
return uart_handle;
}
求指点!!!!!!!!!!
Denny%20Yang99373:
可以分别调试一下EDMA和串口,定位一下问题。
让EDMA从一块内存搬到另一块看看是否OK。
Da Jiang2:
小弟刚实习,也在学习C6747 uart通信,着急啊,领导让做这个,不知道您是否做好了,可否发个例程给我?qq:1728597823 多谢啦