//——————————————————————————
// 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 ;
//——————————————————————————
// 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 = (1 << 16) | sample_size; // actual format: BCNT|ACNT
param.DST = (Uint32)uart_register; //(Uint32)dst; //目的地址 数据的接收地址 20160412mcg
param.SRC_DST_BIDX = 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_pingpong_rcv(void *src,
// void *dst_ping_L, void *dst_pong_L,
// void *dst_ping_R, void *dst_pong_R,
// Uint32 sample_size, Uint32 sample_count)
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 = (1 << 16) | sample_size; // actual format: BCNT|ACNT
param.DST = (Uint32)dst_ping_L; //目的地址
param.SRC_DST_BIDX = 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)
{
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
//——————————————————————————
调用方式
setup_edma_uart_xmt(uart_sendm,10);
EdmaEnableChannel(EDMA_UART2_RX, 0);
EdmaEnableChannel(EDMA_UART2_TX, 0);
EdmaIntEnable(EDMA_XMT_PING_TCC);
EdmaIntEnable(EDMA_RCV_PING_TCC);
//EdmaIntEnable(EDMA_XMT_PING_TCC);
但是串口没有数,是什么原因呢? 希望高手解答一下
Tony Tang:
可以参考一下L138 starterware里的UART_edma例程,两个芯片差不多。
http://processors.wiki.ti.com/index.php/StarterWare
例程在安装目录:
OMAPL138_StarterWare_1_10_03_03\examples\evmOMAPL138\uart_edma
TI中文支持网
