📄 csl2_dat.c
字号:
/*
* Copyright 2006
* Texas Instruments Incorporated
*
* All rights reserved. Property of Texas Instruments Incorporated
* Restricted rights to use, duplicate or disclose this code are
* granted through contract.
*
*/
/**
* @file csl_dat2.c
*
* @brief Implements the CSL DAT2 API using EDMA3 Driver and Resource
* Manager Package (EDMA3LLD).
* Behaviour mimics DAT2 on EDMA2 hardware
*/
#include <stdio.h>
#include "csl_dat.h"
/*
* Includes for accessing EDMA3 DRV and RM layer
*/
#include <ti/sdo/edma3/drv/edma3_drv.h>
/*
* Include for setting up the EDMA3 LLD
*/
#include <csl2_dat_edma3lld.h>
/*
* extern declarations
*/
/*
* OS dependent functions, that must be implemented by user of CSL DAT adapter
* These functions mark the entry and exit to critical sections of the code
*/
extern void _dat_critical_section_enter();
extern void _dat_critical_section_exit();
/*
* Flag to indicate if EDMA3 LLD was initialized before calling the DAT APIs
*/
extern int DAT_EDMA3LLD_initCalled;
/*
* typedef declarations
*/
typedef struct DAT_EDMA3LLD_ChannelDesc {
/* Holds the param number allocated */
Uint32 paramNo;
/* Holds the tcc number allocated */
Uint32 tccNo;
} DAT_EDMA3LLD_ChannelDesc;
/*
* static variable definitions
*/
/*
* Max size array to hold the allocated resources for DAT
*/
static DAT_EDMA3LLD_ChannelDesc
DAT_allocatedChannels[DAT_EDMA3LLD_HW_MAXPHYCHANNELS];
/*
* Flag to indicate that the DAT instance has been opened
*/
static Uint32 DAT_EDMA3LLD_openFlag = 0;
/*
* 64 bit internal Transfer completion register, used to hold status
* of the channel
* It has a bit set to one whenever a Transfer is submitted, and cleared
* when it completes
*/
static Uint32 TransferCompleteH = 0x0;
static Uint32 TransferCompleteL = 0x0;
/*
* Set to the last allocated bit index number in the TransferComplete fxn
*/
static Uint32 lastAllocatedIndex = DAT_INVALID_ID;
/*
* static function declarations
*/
/*
* Call back function declaration for transfer completion
*/
static void _transferComplete(Uint32 tcc, EDMA3_RM_TccStatus status,
void *param);
/*
* Obtain the next free channel from available channels
*/
static inline Uint32 _getFreeChannel(Uint32 *tccNum);
/*
* Function to setup and enable DAT transfer for given channel number tcc number
*/
static inline Uint32 _setupTransferOptions(Uint32 chNum, Uint32 tccNum);
/*
* global variable definitions
*/
/*
* Holds the EDMA3 driver handle
*/
EDMA3_DRV_Handle DAT_EDMA3LLD_hEdma = NULL;
/*
* number of EDMA3 channels allocated for the DAT module
*/
int DAT_EDMA3LLD_numAllocatedChannels = 0;
/*
* global function definitions
*/
/*
* ======== DAT_open =========
* Opens the DAT module, called before all other DAT APIs
* Ignore all paramters of DAT_open, open any channel,
* all channels are opened with equal priority
* All channels can be used in 2D mode etc, flags are not applicable
*/
int DAT_open(int chNum, int priority, Uint32 flags) {
int i = 0;
int j = 0;
Uint32 chaNum = DAT_INVALID_ID;
Uint32 tccNum = DAT_INVALID_ID;
chNum = chNum;
priority = priority;
flags = flags;
/*
* Ensure _initCalled is called before DAT_open
* Also ensure DAT_open is called only once
*/
_dat_critical_section_enter();
if (DAT_EDMA3LLD_initCalled == 0) {
_dat_critical_section_exit();
return 0;
}
if (1 == DAT_EDMA3LLD_openFlag) {
_dat_critical_section_exit();
return 0;
}
DAT_EDMA3LLD_openFlag = 1;
_dat_critical_section_exit();
/*
* Request default number of channels and Tccs from the EDMA3 DRV package
*/
for(i=0; i < DAT_EDMA3LLD_numAllocatedChannels; i++) {
chaNum = EDMA3_DRV_DMA_CHANNEL_ANY;
tccNum = EDMA3_DRV_TCC_ANY;
/*
* EDMA3 DRV call to request for channel and tcc resources
*/
if (EDMA3_DRV_SOK != EDMA3_DRV_requestChannel(DAT_EDMA3LLD_hEdma,
&chaNum, &tccNum,
(EDMA3_RM_EventQueue)DAT_EDMA3LLD_HW_EVT_QUEUE_ID,
(EDMA3_RM_TccCallback)&_transferComplete, NULL)) {
/*
* Error requesting channels, Clean up all channels requested so far
*/
for(j = i-1; j >=0; j--) {
EDMA3_DRV_freeChannel(DAT_EDMA3LLD_hEdma,
DAT_allocatedChannels[j].paramNo);
DAT_allocatedChannels[i].paramNo = DAT_INVALID_ID;
DAT_allocatedChannels[i].tccNo = DAT_INVALID_ID;
}
if (EDMA3_DRV_SOK != EDMA3_DRV_close(DAT_EDMA3LLD_hEdma, NULL)){
printf("Error closing DRV instance \n");
}
else {
if (EDMA3_DRV_SOK != EDMA3_DRV_delete(DAT_EDMA3LLD_HW_INST_ID,
NULL)){
printf("Error deleting EDMA3 DRV\n");
}
}
DAT_EDMA3LLD_openFlag = 0;
return 0;
}
/*
* Store the allocated Channels in an array
*/
DAT_allocatedChannels[i].paramNo = chaNum;
DAT_allocatedChannels[i].tccNo = tccNum;
}
return 1;
}
/*
* ======== DAT_close =========
* Close the DAT module
*/
void DAT_close() {
int i = 0;
/*
* Ensure DAT_open was called
*/
_dat_critical_section_enter();
if (DAT_EDMA3LLD_openFlag == 0)
{
_dat_critical_section_exit();
return;
}
DAT_EDMA3LLD_openFlag = 0;
_dat_critical_section_exit();
/*
* Wait for all pending transfers to complete
*/
DAT_wait(DAT_XFRID_WAITALL);
/*
* Free all requested channels
*/
for(i=0; i < DAT_EDMA3LLD_numAllocatedChannels; i++) {
EDMA3_DRV_freeChannel(DAT_EDMA3LLD_hEdma,
DAT_allocatedChannels[i].paramNo);
DAT_allocatedChannels[i].paramNo = DAT_INVALID_ID;
DAT_allocatedChannels[i].tccNo = DAT_INVALID_ID;
}
}
/*
* ======== DAT_copy =========
* One dimensional copy from source to destination of byteCnt bytes
*/
Uint32 DAT_copy(void *src, void *dst, Uint16 byteCnt ) {
Uint32 chNum = 0;
Uint32 tccNum = 0;
/*
* An alternate way to setup the params
* EDMA3_DRV_PaRAMRegs param;
* const EDMA3_DRV_PaRAMRegs *newPaRAM = ¶m;
*/
/*
* Obtain a free channel
* This call spins till a free channel is obtained
*/
chNum = _getFreeChannel(&tccNum);
/*
* Set up Transfer Paramters for this channel
*/
EDMA3_DRV_setTransferParams(DAT_EDMA3LLD_hEdma, chNum, byteCnt, 1, 1, 0,
EDMA3_DRV_SYNC_AB);
EDMA3_DRV_setDestParams(DAT_EDMA3LLD_hEdma, chNum, (unsigned int)dst,
EDMA3_DRV_ADDR_MODE_INCR,(EDMA3_DRV_FifoWidth)0);
EDMA3_DRV_setSrcParams(DAT_EDMA3LLD_hEdma, chNum, (unsigned int)src,
EDMA3_DRV_ADDR_MODE_INCR,(EDMA3_DRV_FifoWidth)0);
/*
* To set up all the parameters in a single call, can use
* EDMA3_DRV_PARAMRegs structure, and populate it as indicated
param.srcAddr = (Uint32)src;
param.aCnt = (unsigned short) byteCnt;
param.bCnt = 1;
param.destAddr = (Uint32)dst;
param.srcBIdx = (short)0;
param.destBIdx = (short)0;
param.linkAddr = DAT_NULL_LINK;
param.bCntReload = 0x0 ;
param.srcCIdx = 0x0 ;
param.destCIdx = 0x0;
param.cCnt = 0x1;
param.opt = DAT_OPT_TCC(DAT_OPT_DEFAULT, tccNum);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -