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

📄 t8422_ob.c

📁 F2833x / F2823x C/C++ Header Files and Peripheral Examples.It is very useful.
💻 C
📖 第 1 页 / 共 3 页
字号:
    if (pADS->xferBuffer[iIndex].ptrCallBack)
    {
        pADS->xferBuffer[iIndex].uiStatus = ADS8422_BUFOBJECT_COMPLETE;
        pADS->xferBuffer[iIndex].ptrCallBack(pADS);
    }
    pADS->xferBuffer[iIndex].uiStatus = ADS8422_BUFOBJECT_FREE;


   /* signal that the transfer was successful                   */
   pADS->xferInProgress -= 1;         /* decrement flag         */


   return TIDC_NO_ERR;
}




/****************************************************************/
/* ConfigIntPolarity():                                         */
/**Operation:
 *    - Configures the external interrupt polarity register to
 *      match the polarity of the BUSY\ signal.
 *
 * Parameters:
 *     - unsigned int uiBusyIntPol: BUSY\ interrupt polarity as
 *       selected in  the graphical user interface
 *     - unsigned int uiBusyIntNum: The number of the external
 *       interrupt the BUSY\ signal is connected to.
 *
 * Return values: Of type TTIDCSTATUS:
 *     - TIDC_NO_ERR: No error occurred
 *     - TIDC_ERR_BADARGS: The interrupt passed is not an
 *       external interrupt
 *
 * Globals modified:
 *     - None
 *
 * Resources used:
 *     - None
 */
/****************************************************************/
static TTIDCSTATUS ConfigIntPolarity(unsigned int uiBusyIntPol,
                                     unsigned int uiBusyIntNum)
{
    unsigned int uiXip;


    uiXip = IRQ_FGET(EXTPOL, XIP); /* get current value of XIP  */


    switch(uiBusyIntNum)           /* use the correct value     */
    {
        case IRQ_EVT_EXTINT4: uiXip = (uiXip & 0x000E)
                                      | uiBusyIntPol;
                              break;
        case IRQ_EVT_EXTINT5: uiXip = (uiXip & 0x000D)
                                      | (uiBusyIntPol << 1);
                              break;
        case IRQ_EVT_EXTINT6: uiXip = (uiXip & 0x000B)
                                      | (uiBusyIntPol << 2);
                              break;
        case IRQ_EVT_EXTINT7: uiXip = (uiXip & 0x0007)
                                      | (uiBusyIntPol << 3);
                              break;
        default:              return TIDC_ERR_BADARGS;
    }


    IRQ_FSET(EXTPOL, XIP, uiXip);  /* and set new value of XIP  */


    return TIDC_NO_ERR;
}




/****************************************************************/
/* InitConvstTimer():                                           */
/**Operation:
 *     - Opens and configures the timer needed for the time base
 *       of the CONVST\ signal.
 *     - Initializes the timer handle passed into the function.
 *
 * Parameters:
 *      - TIMER_Handle hTimer: Uninitialized when the function is
 *        called. Will contain the handle of the opened timer if
 *        the call was successfull.
 *      - unsigned int uiPeriod: Desired value for the timer
 *        period register.
 *      - int iTimerNumber: Number of the timer to be used
 *
 * Return values: Of type TTIDCSTATUS:
 *     - TIDC_NO_ERR: No error occurred
 *     - TIDC_ERR_TIMER: Timer could not be opened
 *
 * Globals modified:
 *      - hConvstTimer in the data converter object
 *
 * Resources used:
 *      - One timer
 */
/****************************************************************/
static TTIDCSTATUS InitConvstTimer(TIMER_Handle *hTimer,
                                   unsigned int uiPeriod,
                                   int iTimerNumber)
{
    /* try to open the timer needed for the CONVST signal       */
    *hTimer = TIMER_open(iTimerNumber, TIMER_OPEN_RESET);


    /* was the open call successfull?                           */
    if (*hTimer == INV)
        return TIDC_ERR_TIMER;


    TIMER_configArgs(*hTimer,
          TIMER_FMK(CTL, INVINP, TIMER_CTL_INVINP_NO)
        | TIMER_FMK(CTL, CLKSRC, TIMER_CTL_CLKSRC_CPUOVR4)
        | TIMER_FMK(CTL, CP, TIMER_CTL_CP_CLOCK)
        | TIMER_FMK(CTL, HLD, TIMER_CTL_HLD_YES)
        | TIMER_FMK(CTL, GO, TIMER_CTL_GO_NO)
        | TIMER_FMK(CTL, PWID, TIMER_CTL_PWID_DEFAULT)
        | TIMER_FMK(CTL, DATOUT, TIMER_CTL_DATOUT_DEFAULT)
        | TIMER_FMK(CTL, INVOUT, TIMER_CTL_INVOUT_NO)
        | TIMER_FMK(CTL, FUNC, TIMER_CTL_FUNC_TOUT),
        uiPeriod,
        0);


    return TIDC_NO_ERR;
}




/****************************************************************/
/* InitEdma():                                                  */
/* Operation:
 *    - Opens the EDMA channel assiciated with the timer in use
 *    - Allocates a parameter table for the EDMA link table and
 *      initializes the associated handle
 *    - Allocates a parameter table for the EDMA stop table and
 *      initializes the associated handle
 *    - Initializes the EDMA parameter table for the stop
 *      transfer to zero.
 *
 * Parameters:
 *     - unsigned int *hEdma: Pointer to the handle of the EDMA
 *       channel for the transfer
 *     - unsigned int *hLink: Pointer to the handle of the
 *       link transfer table
 *     - unsigned int *hStop: Pointer to the handle of the
 *       stop transfer table
 *     - unsigned int uiIntNumber: The interrupt number used
 *       to synchronize the transfer.
 *
 * Return value (of type TTIDCSTATUS):
 *     - TIDC_NO_ERR in case everything was OK
 *     - TIDC_ERR_EDMA if the EDMA channel could not be opened,
 *       or if one of the tables could not be allocated
 *
 * Globals modified: In the data converter object:
 *    - hEdma
 *    - hEdmaLink
 *    - hEdmaStop
 *
 * Resources used:
 *    - One EDMA channel
 *    - Two EDMA parameter RAM tables
 */
/****************************************************************/
static TTIDCSTATUS InitEdma(unsigned int *hEdma,
                    unsigned int *hLink, unsigned int *hStop,
                    unsigned int uiIntNumber)
{
    /* if the channel is not open yet, open it                  */
    if ((*hEdma == EDMA_HINV) || (*hEdma == 0))
    {
        *hEdma = EDMA_open((int)uiIntNumber, EDMA_OPEN_RESET);
        if (*hEdma == EDMA_HINV)
            return TIDC_ERR_EDMA;
    }


    /* get table entries for the link and the stop transfer and */
    /* check if the tables are valid                            */
    *hLink = EDMA_allocTable(-1);
    if (*hLink == EDMA_HINV)
        return TIDC_ERR_EDMA;


    if ((*hStop == 0) || (*hStop == EDMA_HINV))
    {
        *hStop = EDMA_allocTable(-1);
        if (*hStop == EDMA_HINV)
            return TIDC_ERR_EDMA;


        /* the stop transfer table contains only zeros, so it   */
        /* could be initialized now                             */
        EDMA_configArgs(*hStop, 0, 0, 0, 0, 0, 0);
    }


    return TIDC_NO_ERR;
}




/****************************************************************/
/* InitEmif()                                                   */
/**Operation:
 *     - Sets up the EMIF to the correct timings for the ADS8422
 *
 * Parameters:
 *     - unsigned int *pAddress: Address of the ADS8422
 *
 * Return value: Of type TTIDCSTATUS:
 *     - TIDC_NO_ERR: Everything was OK
 *
 * Globals modified:
 *     - None
 *
 * Resources used:
 *     - None
 */
/****************************************************************/
static TTIDCSTATUS InitEmif(volatile unsigned short *pAddress)
{
    volatile unsigned int *pCeCtrl;
    unsigned int uiCeValue;
    unsigned int uiCeSpace;


    uiCeValue = ADS8422_RD_HOLD
                | (ADS8422_MTYPE << 4)
                | (ADS8422_RD_STROBE << 8)
                | (ADS8422_RD_SETUP << 16);


    uiCeSpace = (((unsigned int)pAddress >> 28) & 0x00000007);


    /* det the variable for the CECNTR to the correct value     */
    switch (uiCeSpace)
    {
        case 0: pCeCtrl = (volatile unsigned int *) CECTRL0;
                break;
        case 1: pCeCtrl = (volatile unsigned int *) CECTRL1;
                break;
        case 2: pCeCtrl = (volatile unsigned int *) CECTRL2;
                break;
        case 3: pCeCtrl = (volatile unsigned int *) CECTRL3;
                break;
    }


    *pCeCtrl = (*pCeCtrl & ADS8422_CECTRL_MASK) | uiCeValue;


    return TIDC_NO_ERR;
}




/****************************************************************/
/* SubmitBlock()                                                */
/**Operation: The following operations are performed depending
 *     on if there is already a transfer running or not.
 *     - If this is the first transfer, it initalizes the EDMA
 *       channel registers.
 *     - If this is the second transfer, it initializes the
 *       link table and links the first transfer to the pending
 *       one.
 *     - If there was an ongoing transfer, the function tests if
 *       this transfer expired in the meantime. If yes, it does
 *       not link the new transfer, but configures the EDMA
 *       controller directly.
 *
 * Parameters:
 *     - EDMA_Handle hSubmit: This is either the handle to the
 *       EDMA channel or the handle to the link table.
 *     - unsigned int uiSrcAddress: Where to read from (ADS8481
 *       address)
 *     - unsigned int uiDstAddress: Address of the buffer to be
 *       filled
 *     - unsigned int uiCount: Number of elements to transfer
 *     - unsigned int uiIntNumber: Number of the interrupt used to
 *       synchronize the transfer (timer interrupt).
 *     - EDMA_Handle hPrevious: Is zero, if this is the first
 *       submitted transfer, contains the pointer to the EDMA
 *       handle, if this is the second submitted buffer.
 *       This parameter will be used for linking the two
 *       transfers together.
 *     - EDMA_Handle hStop: Handle for the stop transfer
 *
 * Return value (of type TTIDCSTATUS):
 *     - TIDC_NO_ERR: No error occurred
 *
 * Globals modified: in DC object:
 *     - None
 *
 * Resources used:
 *     - None
 */
/****************************************************************/
static TTIDCSTATUS SubmitBlock(EDMA_Handle hSubmit,
                               unsigned int uiAdsAddress,
                               unsigned int uiBufAddress,
                               unsigned int uiCount,
                               unsigned int uiIntNumber,
                               EDMA_Handle hPrevious,
                               EDMA_Handle hStop)
{
    /* if there was a previous transfer, look it it has         */
    /* finished in the meantime. if yes, don't link, but program*/
    /* the EDMA channel directly.                               */
    if (hPrevious != 0)
    {
        if (EDMA_RGETH(hPrevious, SRC) == 0)
        {
            EDMA_disableChannel(hPrevious);
            EDMA_RSETH(hPrevious, SRC, uiAdsAddress);
            EDMA_RSETH(hPrevious, DST, uiBufAddress);
            EDMA_RSETH(hPrevious, OPT, ADS8422_EDMAOPT_INPUT_VALUE | (uiIntNumber << 16));
            EDMA_RSETH(hPrevious, CNT, uiCount);
            EDMA_RSETH(hPrevious, IDX, 0);
            EDMA_RSETH(hPrevious,RLD,EDMA_getTableAddress(hStop) & 0x0000FFFFu);
            EDMA_clearChannel(hPrevious);
            EDMA_enableChannel(hPrevious);
            return TIDC_NO_ERR;
        }
    }


    EDMA_RSETH(hSubmit, SRC, uiAdsAddress);
    EDMA_RSETH(hSubmit, DST, uiBufAddress);
    EDMA_RSETH(hSubmit, OPT, ADS8422_EDMAOPT_INPUT_VALUE | (uiIntNumber << 16));
    EDMA_RSETH(hSubmit, CNT, uiCount);
    EDMA_RSETH(hSubmit, IDX, 0);
    EDMA_RSETH(hSubmit,RLD,EDMA_getTableAddress(hStop) & 0x0000FFFFu);


    if (hPrevious != 0)
        EDMA_link(hPrevious, hSubmit);


    return TIDC_NO_ERR;
}

/****************************************************************/
/* END OF t8422_ob.c                                             */
/****************************************************************/
/*TIDC_Wizard Auto Code End}}*/

⌨️ 快捷键说明

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