⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 t8422_ob.c

📁 F2833x / F2823x C/C++ Header Files and Peripheral Examples.It is very useful.
💻 C
📖 第 1 页 / 共 3 页
字号:
/*{{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\c6000\d8401_62.c> */
/****************************************************************/
/****************************************************************/
/* ADS8422 interface software version 2.0 for the TMS320C671x   */
/* 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:
 *      EDMA controller interrupt: DCPDISP_dispatchEdmaIsr()
 *
 * This interface software uses two peripherals:
 *   - One EDMA 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 TMS320C6713 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.
 *    - This software works only for the TMS320C671x devices, not
 *      the older TMS320C620x and TMS320C6701 devices. </b>     */
/*--------------------------------------------------------------*/
/* $Revision: 10 $                         $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_cache.h>
#include <csl_emif.h>
#include <csl_irq.h>


/* The following settings for the EMIF are optimized for the    */
/* C6713 DSK. If you are using a different H/W, you might want  */
/* change these settings to match your hardware                 */
#define ADS8422_CECTRL_MASK    (0xFFF0C008)
#define CECTRL0                (0x01800008)
#define CECTRL1                (0x01800004)
#define CECTRL2                (0x01800010)
#define CECTRL3                (0x01800014)
#define ADS8422_MTYPE          (2)
#define ADS8422_RD_SETUP       (1)
#define ADS8422_RD_STROBE      (3)
#define ADS8422_RD_HOLD        (1)


/* 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)


/* This driver does not support the older devices, as they have */
/* a different DMA controller                                   */
#if CHIP6701 | CHIP6201 | CHIP6202 | CHIP6203 | CHIP6204 | CHIP6205
#error Selected DSP is not supported by that software
#endif




/****************************************************************/
/* 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                    */
    0,                  /* link table pointer               */
    0,                  /* stop table pointer               */
    (volatile unsigned short*)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               */
    0                   /* xfer on progress flag            */
};



/****************************************************************/
/* local DSP function prototypes                                */
/****************************************************************/
static TTIDCSTATUS ConfigIntPolarity(unsigned int uiBusyIntPol,
                                     unsigned int uiBusyIntNum);
static TTIDCSTATUS InitConvstTimer(TIMER_Handle *hTimer,
                                   unsigned int uiPeriod,
                                   int iTimerNumber);
static TTIDCSTATUS InitEdma(unsigned int *hEdma,
                            unsigned int *hLink,
                            unsigned int *hStop,
                            unsigned int uiIntNumber);
static TTIDCSTATUS InitEmif(volatile unsigned short *pAddress);
static TTIDCSTATUS SubmitBlock(EDMA_Handle hSubmit,
                               unsigned int uiAdsAddress,
                               unsigned int uiBufAddress,
                               unsigned int uiCount,
                               unsigned int uiIntNumber,
                               EDMA_Handle hPrevious,
                               EDMA_Handle hStop);


/****************************************************************/
/* 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.
 *     - Configures the external interrupt polarity register to
 *       match the polarity of the BUSY\ signal.
 *     - Opens the EDMA channel needed for the transfer.
 *       Returns on error.
 *     - Acquires the handles for the EDMA link and stop transfer
 *       tables. Returns on error.
 *     - Registers the EDMA transfer complete code with the EDMA
 *       interrupt dispatcher.
 *
 * 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_EDMA: The EDMA channel could not be opened or
 *       one of the link tables could not be allocated.
 *     - 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
 *     - hEdmaRead
 *     - hEdmaLinkRead
 *     - hEdmaStop
 *
 * Resources used:
 *     - One Timer
 *     - One EDMA channel
 *     - Two EDMA link tables
*/
/****************************************************************/
TTIDCSTATUS ADS8422_configure(void *pDC)
{
    TADS8422 *pADS = pDC;
    TTIDCSTATUS iStatus;
    unsigned int uiIntNumber;


    /* 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;


    uiIntNumber = pADS->busyIntNum;


    /* 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;


        uiIntNumber = TIMER_getEventId(pADS->hConvstTimer);
    }


    /* configure the EMIF if selected by the customer           */
    if (pADS->emifSetup == ADS8422_EMIF_SETUP_YES)
        (void)InitEmif(pADS->adcReadAdr);


    /* configure the polarity used for the BUSY\ signal. This   */
    /* is needed for the ADS8422_readsample() function          */
    iStatus = ConfigIntPolarity(pADS->busyIntPol,pADS->busyIntNum);
    if (iStatus != TIDC_NO_ERR)
    {
        (void)ADS8422_close(pADS);
        return iStatus;
    }


    /* open the EDMA channel for the data transfer              */
    iStatus = InitEdma(&pADS->hEdmaRead,
                       &pADS->hEdmaLinkRead,
                       &pADS->hEdmaStop,
                       uiIntNumber);
    if (iStatus != TIDC_NO_ERR)
    {
        (void)ADS8422_close(pADS);
        return iStatus;
    }


    /* register the EDMA transfer complete code with the EDMA   */
    /* interrupt dispatcher                                     */
    iStatus = DCPDISP_registerIsr((void*)pADS,
                                 ADS8422_rblock_finished,
                                 uiIntNumber);
    if (iStatus != TIDC_NO_ERR)
    {
        (void)ADS8422_close(pADS);
        return iStatus;
    }


    /* now everything is setup, so start the conversions        */
    TIMER_start(pADS->hConvstTimer);


    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
 *     - If the internal timer is used for the generation of the
 *       CONVST\ signal, it waits for the next timer interrupt.
 *       If the timer is not used, it waits for the next falling
 *       edge of the BUSY\ signal.
 *     - 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;
    unsigned int uiIntNumber;


    /* 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;


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -