📄 t8422_ob.c
字号:
/*{{TIDC_Wizard Auto Code Start */
/****************************************************************/
/* don't change anything here until you know what you are doing!*/
/* the plug-in will change all text between the code marks */
/* without user interaction! */
/* */
/****************************************************************/
/****************************************************************/
/* software generated by Data Converter Plug-in (DCP) */
/* based on <C:\CCSTUD~1.1\PLUGINS\AAP_DEV\c5500\d8401_55.c> */
/****************************************************************/
/****************************************************************/
/* ADS8422 interface software version 2.0 for the TMS320C55xx */
/* Copyright (C) 2004 - 2006 Texas Instruments Incorporated */
/* All Rights Reserved */
/*--------------------------------------------------------------*/
/** \file
* This interface software needs one interrupt to be mapped in
* either the DSP/BIOS configuration file or the interrupt
* vector table:
* DMA controller interrupt: ADS8422_rblock_finished
*
* This interface software uses two peripherals:
* - One DMA channel (for data transfer)
* - One Timer (for the CONVST\)
*
* <b>Restrictions:
* - This interface software does not support the byte wide
* transfers of the ADS8422, as all of the DSPs feature a
* 16 bit bus
* - It is only possible to submit two buffers at a time. If a
* third buffer needs to be submitted, the application has
* to wait until the xferInProgress member of the data
* converter structure is less than two.
* Please note that if the size of the submitted buffers is
* too small, there will be a loss of samples between the
* two buffers. This is due to the time necessary to link
* the transfers together. Therefore, it is recommended to
* have a minimum buffer size of 64.
* - This version 2.0 is not binary compatible with previous
* versions of this software.
* - The timings of the external memory interface are
* optimized for the TMS320C5510 DSK running at the EMIF
* at 100 MHz.If a different H/W platform or a different
* EMIF speed is used, the values in the ADS8422_RD_SETUP,
* ADS8422_RD_STROBE and ADS8422_RD_HOLD macros below have to
* be changed to match the H/W.
* - This software requires the buffer to be of type signed or
* unsigned short, depending on the converter.</b> */
/*--------------------------------------------------------------*/
/* $Revision: 12 $ $JustDate: 7/13/06 $ */
/* $Author: A0746714 $ */
/****************************************************************/
#undef _INLINE
/* Include the interface files for the driver */
#include "dc_conf.h"
#include "t8422_fn.h"
/* Include the interface files for the chip support library */
#include <csl.h>
#include <csl_dma.h>
#include <csl_emif.h>
#include <csl_irq.h>
#include <csl_timer.h>
/* The following settings for the EMIF are optimized for the */
/* C5510 DSK. If you are using a different H/W, you might want */
/* change these settings to match your hardware */
#define ADS8422_MTYPE (1)
#define ADS8422_RD_SETUP (0)
#define ADS8422_RD_STROBE (7)
#define ADS8422_RD_HOLD (0)
/* some other usefull defines */
#define ADS8422_TIMER_NOTUSED (-1)
#define ADS8422_EMIF_SETUP_YES (1)
#define ADS8422_MAX_BLOCKS (2)
#define ADS8422_MAX_BLOCKSIZE (0x0000FFFFul)
#define ADS8422_MIN_BLOCKSIZE (0x00000002ul)
/* global pointer to DC object for interrupts */
static TADS8422 *pgADS;
/****************************************************************/
/* define and initialize data converter objects */
/****************************************************************/
TADS8422 Ads8422_1 = {
&ADS8422_configure,
&ADS8422_control,
&ADS8422_readsample,
&ADS8422_writesample,
&ADS8422_readblock,
&ADS8422_writeblock,
&ADS8422_close,
0, 0, 3, /* reserved */
0, 0, 0, 0, /* buffer object 0 */
0, 0, 0, 0, /* buffer object 1 */
0, /* timer handle */
0, /* (E)DMA handle */
(volatile unsigned int*)ADC1_RD_ADDR, /* ADC read addr */
ADC1_INTPOL, /* IRQ polarity of BUSY\ */
ADC1_CONVST_PERIOD, /* sampling period */
0, /* LRU buffer object ptr */
ADC1_INTNUM, /* IRQ number of BUSY\ */
ADC1_EMIF_CONFIGURE,/* EMIF setup to do? */
ADC1_TIMER, /* used timer, if any */
ADC1_DMACHAN_USED, /* DMA channel to use */
0, /* DMA CCR value */
0 /* xfer on progress flag */
};
/****************************************************************/
/* DSP function prototypes */
/****************************************************************/
static TTIDCSTATUS InitConvstTimer(TIMER_Handle *hTimer, \
unsigned int uiPeriod, \
int iTimerNumber);
static TTIDCSTATUS InitDma(DMA_Handle *hDma, \
unsigned long ulAdcAddress, \
unsigned int uiIrq, \
unsigned int iChannelNumber, \
unsigned int *pCcr);
static TTIDCSTATUS InitEmif(volatile unsigned int *pAddress);
static TTIDCSTATUS SubmitBlock(DMA_Handle hDma, \
TADS8422BUFOBJ bufObj, \
unsigned int uiCcr, \
int iIndex); \
static TTIDCSTATUS SubmitDummyXfer(DMA_Handle hDma);
/****************************************************************/
/* ADS8422_configure() */
/**
* Operation: The following operations are performed:
* - Opens and configures the timer needed for the correct
* sampling frequency, if the use of a timer was selected
* in the graphical user interface. Returns on error.
* - Configures the EMIF to the correct timings, if this was
* requested by the user during configuration.
* - Opens the DMA channel needed for the transfer.
* Returns on error.
*
* Parameters:
* - void* pDC: Data converter object
*
* Return values: Status code of type TTIDCSTATUS
* - TIDC_NO_ERR: Call was successful
* - TIDC_ERR_NODEVICE: No object was passed to the function
* - TIDC_ERR_TIMER: The timer could not be opened
* - TIDC_ERR_DMA: The DMA channel could not be opened.
* - TIDC_ERR_XFERPROG: dc_configure was called during an
* ongoing transfer
* - TIDC_ERR_BADARGS: An invalid argument was passed to the
* function
*
* Globals modified: In the data converter object:
* - hConvstTimer
* - hDmaRead
*
* Resources used:
* - One Timer
* - One DMA channel
*/
/****************************************************************/
TTIDCSTATUS ADS8422_configure(void *pDC)
{
TADS8422 *pADS = pDC;
int iStatus;
/* return, if no device object available */
if (pADS == 0)
return TIDC_ERR_NODEVICE;
/* be sure no block transfer is in progress */
if (pADS->xferInProgress !=0)
return TIDC_ERR_XFERPROG;
/* open and configure the timer for the CONVST\ signal */
/* this call will initialize the hConvstTimer field of the */
/* data converter object; return on error */
if (pADS->iTimerNumber != ADS8422_TIMER_NOTUSED)
{
iStatus = InitConvstTimer(&pADS->hConvstTimer,
pADS->convstTimerPeriod,
pADS->iTimerNumber);
if (iStatus != TIDC_NO_ERR)
return iStatus;
}
/* configure the EMIF if selected by the customer */
if (pADS->emifSetup == ADS8422_EMIF_SETUP_YES)
(void)InitEmif(pADS->adcReadAdr);
/* create the DMA handle and pre-configure the channel */
iStatus = InitDma(&pADS->hDmaRead,
(unsigned long)pADS->adcReadAdr,
pADS->busyIntNum,
pADS->dmaChanNum,
&(pADS->uiCcrValue));
/* now everything is setup, so start the conversions */
TIMER_start(pADS->hConvstTimer);
pgADS = pADS; /* global pointer needed by ISR */
return TIDC_NO_ERR;
}
/****************************************************************/
/* ADS8422_control() */
/** Operation:
* - None, as this device supports no S/W or H/W control
*
* Parameters:
* - void* pDC: Data converter object
* - int iCmd: Action to be performed.
* - void *pValue: Additional parameters for the command.
*
* Return value:
* - TIDC_ERR_FXNNULL, signalling that this function is not
* performing any action
*
* Globals modified:None
*
* Resources used: None
*/
/****************************************************************/
TTIDCSTATUS ADS8422_control(void *pDC, int iCmd, void *pValue)
{
return TIDC_ERR_FXNNULL;
}
/****************************************************************/
/* ADS8422_readsample() */
/**Operation:
* - Reads a single 16 bit word from the ADS8422
* - Clear the BUSY\ interrupt
* - Waits for the next interrupt to happen
* - Reads the data word from the converter.
* - This routine is not interrupt driven, but uses the
* polling method instead, so it could be blocking.
*
* Parameters:
* - void *pDC: Data converter object
* - long *lData: Memory location used to return the
* conversion result (out-parameter).
*
* Return value: Status code of type TTIDCSTATUS
* - TIDC_NO_ERR: Call was successfull.
* - TIDC_ERR_NODEVICE: No object was passed to the function.
* - TIDC_ERR_XFERPROG: A block transfer is in progress, so
* this function cannot be executed.
*
* Globals modified:
* - None
*
* Resources used:
* - None
*/
/****************************************************************/
TTIDCSTATUS ADS8422_readsample(void *pDC, long * lData)
{
TADS8422 *pADS = pDC;
/* return, if no device object available */
if (pADS == 0)
return TIDC_ERR_NODEVICE;
/* return, if a block transfer is ongoing */
if (pADS->xferInProgress !=0)
return TIDC_ERR_XFERPROG;
IRQ_clear(pADS->busyIntNum); /* clear any old interrupt */
/* wait for the next interrupt; this is a blocking statement*/
while((IRQ_test(pADS->busyIntNum)) == 0);
*lData = (long)(*(pADS->adcReadAdr));
return TIDC_NO_ERR;
}
/****************************************************************/
/* ADS8422_readblock() */
/**Operation:
* - Initializes the transfer of a block of data from the
* ADS8422. Once the transfer is started, the function
* returns to the application level.
* - It uses one DMA channel for the data transfer.
* - The DMA channel for the collection of the data samples
* is synchronized to the BUSY\ signal.
* - Once the transfer is complete, the ADS8422_rblock_finished
* routine will be called, which then signals the end of the
* transfer to the application level by the means of a
* callback function.
*
* Parameters:
* - void *pDC: Data converter object
* - void *pData: Pointer to the data block
* - unsigned long ulCount: Number of words to be read
* - void *readCallback: Pointer to callback function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -