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

📄 t8422_ob.c

📁 F2833x / F2823x C/C++ Header Files and Peripheral Examples.It is very useful.
💻 C
📖 第 1 页 / 共 3 页
字号:
    if (pADS->iTimerNumber != ADS8422_TIMER_NOTUSED)
        uiIntNumber = TIMER_getEventId(pADS->hConvstTimer);
    else uiIntNumber = pADS->busyIntNum;


    IRQ_clear(uiIntNumber);      /* clear any old interrupt     */


    /* wait for the next interrupt; this is a blocking statement*/
    while((IRQ_test(uiIntNumber)) == 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 EDMA channel for the data transfer.
 *     - The EDMA channel for the collection of the data samples
 *       is synchronized to the BUSY signal, if no DSP timer is
 *       used for the creation of the CONVST\ signal. If a DSP
 *       timer is used, the timer interrupt will be used instead.
 *     - 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 *pD:CData converter object
 *     - void *pData: Pointer to the data block
 *     - unsigned long ulCount: Number of words to be read
 *     - void *readCallback: Pointer to callback function
 *
 * Return value:
 *     - TIDC_NO_ERR: Call was successfull.
 *     - TIDC_ERR_NODEVICE: No object was passed to the function.
 *     - TIDC_ERR_BADARGS: The block size is beyond its limits
 *     - TIDC_ERR_XFERPROG: The maximum number of transfers has
 *       been reached.
 *
 * Globals modified:
 *     - Inside the data converter object:
 *         - iObjectIndex
 *         - xferInProgress
 *     - Inside the xferBuffer object:
 *         - usbufPtr
 *         - uibufSize
 *         - uiStatus
 *         - ptrCallback
 *
 * Resources used:
 *     - One EDMA channel (opened by ADS8422_configure())
 *
 * Remarks:
 *     - Only one buffer can be active (transferring data) at one
 *       time while a second buffer can be submitted (queued).
 *     - No single word transfer is allowed. The ADS8422_readsample()
 *       routine should be used instead.
 *     - The number of samples to be transfered cannot exceed
 *       0xffff (limit given by the EDMA controller).
 */
/****************************************************************/
TTIDCSTATUS ADS8422_readblock(void *pDC,
                              void *pData,
                              unsigned long ulCount,
                              void (*readCallback) (void *))
{
    TADS8422 *pADS = pDC;
    unsigned int uiIntNumber;


    /* no single word transfer is allowed. Also return if the   */
    /* maximum number of transfers was already submitted        */
    if(pADS == 0)
        return TIDC_ERR_NODEVICE;


    if ((ulCount > ADS8422_MAX_BLOCKSIZE)
        || (ulCount < ADS8422_MIN_BLOCKSIZE))
        return TIDC_ERR_BADARGS;


    if (pADS->xferInProgress == ADS8422_MAX_BLOCKS)
        return TIDC_ERR_XFERPROG;
    else
        pADS->xferInProgress += 1;


    /* select the next free buffer object                       */
    if (pADS->xferBuffer[0].uiStatus == ADS8422_BUFOBJECT_FREE)
        pADS->iObjectIndex = 0; /* object 0 is free             */
    else
        pADS->iObjectIndex = 1; /* object 1 is free             */


    pADS->xferBuffer[pADS->iObjectIndex].ptrCallBack = readCallback;
    pADS->xferBuffer[pADS->iObjectIndex].usBufPtr = (unsigned short *)pData;
    pADS->xferBuffer[pADS->iObjectIndex].uiBufSize = (unsigned int)ulCount;
    pADS->xferBuffer[pADS->iObjectIndex].uiStatus = ADS8422_BUFOBJECT_INUSE;


    /* make sure the cache is coherent                          */
    CACHE_wbInvL1d((void *)pData,
                   2 * (unsigned int)ulCount,
                   CACHE_WAIT);


    if (pADS->iTimerNumber != ADS8422_TIMER_NOTUSED)
        uiIntNumber = TIMER_getEventId(pADS->hConvstTimer);
    else
        uiIntNumber = pADS->busyIntNum;


    /* there is no transfer running and no transfer pending     */
    if (pADS->xferInProgress == 1)
    {
        /* submit the block for the data transfer               */
        (void)SubmitBlock(pADS->hEdmaRead,
               (unsigned int)pADS->adcReadAdr,
               (unsigned int)pADS->xferBuffer[pADS->iObjectIndex].usBufPtr,
               pADS->xferBuffer[pADS->iObjectIndex].uiBufSize,
               uiIntNumber,
               (EDMA_Handle)0,
               pADS->hEdmaStop);


        /* start the EDMA channel                               */
        EDMA_clearChannel(pADS->hEdmaRead);
        EDMA_intClear(uiIntNumber);
        EDMA_intEnable(uiIntNumber);
        EDMA_enableChannel(pADS->hEdmaRead);


        IRQ_enable(IRQ_EVT_EDMAINT);    /* enable the EDMA interrupt*/
    }


    if (pADS->xferInProgress == 2)
        /* queue the block for the data transfer                */
        (void)SubmitBlock(pADS->hEdmaLinkRead,
               (unsigned int)pADS->adcReadAdr,
               (unsigned int)pADS->xferBuffer[pADS->iObjectIndex].usBufPtr,
               pADS->xferBuffer[pADS->iObjectIndex].uiBufSize,
               uiIntNumber,
               pADS->hEdmaRead,
               pADS->hEdmaStop);


    /* return to the calling routine                            */
    return TIDC_NO_ERR;
}


/****************************************************************/
/* ADS8422_writesample()                                        */
/**Operation:
 *     Not implemented. This function just returns.
 *
 * Parameters:
 *     - void* pDC: Data converter object
 *     - long lData: Data to be written to the converter
 *
 * Return value:  Status code of type TTIDCSTATUS
 *     - TIDC_ERR_FXNNULL: This function is not implemented
 *
 * Globals modified:
 *     - None
 *
 * Resources used:
 *     - None
 */
/****************************************************************/
TTIDCSTATUS ADS8422_writesample(void *pDC, long lData)
{
    return TIDC_ERR_FXNNULL;
}




/****************************************************************/
/* ADS8422_writeblock()                                         */
/**Operation:
 *     - Not implemented. This function just returns.
 *
 * Parameters:
 *     - void* pDC: Data converter object
 *     - void* lData: Pointer to the block of data to be written
 *     - unsigned long ulCount: Number of words
 *     - void (*callback): Pointer to the callback function
 *
 * Return value:  Status code of type TTIDCSTATUS
 *     - TIDC_ERR_FXNNULL: This function is not implemented
 *
 * Globals modified:
 *     - None
 *
 * Resources used:
 *     - None
 */
/****************************************************************/
TTIDCSTATUS ADS8422_writeblock(void *pDC, void *pData,
                               unsigned long ulCount,
                               void (*callback) (void *))
{
    return TIDC_ERR_FXNNULL;
}




/****************************************************************/
/* ADS8422_close()                                              */
/**Operation:
 *     - Closes all the resources used on the DSP.
 *     - Unregisters the interrupt service routine with the EDMA
 *       interrupt dispatcher
 *
 * Parameters:
 *     - void* pDC: Data converter object
 *
 * Return value:  Status code of type TTIDCSTATUS
 *     - TIDC_NO_ERR: No problem occurred
 *
 * Globals modified: The following items are modified inside
 *     data converter object:
 *         - hConvstTimer
 *         - hEdmaRead
 *         - hEdmaLinkRead
 *         - hEdmaStop
 *         - xferInProgress
 *         - iObjectIndex
 *     Inside the buffer objects:
 *         - uiStatus
 *
 * Resources used:
 *     - One EDMA channel (closed)
 *     - Two EDMA link tables (freed)
 *     - One timer (closed)
 */
/****************************************************************/
TTIDCSTATUS ADS8422_close(void *pDC)
{
    TADS8422 *pADS = pDC;
    unsigned int uiIntNumber;


    /* return, if no device object available                    */
    if (pADS == 0)
        return TIDC_ERR_NODEVICE;


    /* was BUSY\ or the timer used for synchrtonization?        */
    if  (pADS->iTimerNumber != ADS8422_TIMER_NOTUSED)
        uiIntNumber = TIMER_getEventId(pADS->hConvstTimer);
    else
        uiIntNumber = pADS->busyIntNum;


    /* close the EDMA channel, if they have been opened         */
    if ((pADS->hEdmaRead != 0) && (pADS->hEdmaRead != EDMA_HINV))
    {
        EDMA_intDisable(uiIntNumber);
        EDMA_disableChannel(pADS->hEdmaRead);
        EDMA_close(pADS->hEdmaRead);
        pADS->hEdmaRead = 0;
    }


    /* free the tables associated with the transfer             */
    if ((pADS->hEdmaLinkRead != 0)
        && (pADS->hEdmaLinkRead != EDMA_HINV))
    {
        EDMA_freeTable(pADS->hEdmaLinkRead);
        pADS->hEdmaLinkRead = 0;
    }
    if ((pADS->hEdmaStop != 0) && (pADS->hEdmaStop != EDMA_HINV))
    {
        EDMA_freeTable(pADS->hEdmaStop);
        pADS->hEdmaStop = 0;
    }


    /* close the timer, if it was open                          */
    if ((pADS->hConvstTimer != 0) && (pADS->hConvstTimer != INV))
    {
        TIMER_close(pADS->hConvstTimer);
        pADS->hConvstTimer = 0;
    }


    /* unregister the EDMA transfer complete code with the      */
    /* EDMA interrupt dispatcher                                */
    (void)DCPDISP_unregisterIsr(uiIntNumber);


    /* reset the transfer in progress semaphore                 */
    pADS->xferInProgress = 0;
    pADS->iObjectIndex = 0;
    pADS->xferBuffer[0].uiStatus = ADS8422_BUFOBJECT_FREE;
    pADS->xferBuffer[1].uiStatus = ADS8422_BUFOBJECT_FREE;


    return TIDC_NO_ERR;
}


/****************************************************************/
/* ADS8422_rblock finished()                                    */
/**Operation:
 *     - This function was registered with the DCP EDMA interrupt
 *       dispatcher by the ADS8422_configure() function.
 *     - If requested, a user-defined callback function will be
 *       called at the end.
 *     - Sets the status of the finished buffer to
 *       ADS8422_BUFOBJECT_COMPLETE before the call to the
 *       callback function and to ADS8422_BUFOBJECT_FREE
 *       after the return from the callback function.
 *
 * Parameters:
 *    - void *pDC: Data converter object. Will be provided by
 *      the DCP EDMA interrupt dispatcher
 *
 * Return value (of type TTIDCSTATUS):
 *     - TIDC_ERR_NODEVICE: The passed data converter object is
 *       not valid
 *     - TIDC_NO_ERR: Everything is fine
 *
 * Globals modified: In the data converter object:
 *     - xferInProgress
 *     - uiStatus inside the transfer buffer object
 *
 * Resources used:  None
 */
/****************************************************************/
TTIDCSTATUS ADS8422_rblock_finished(void *pDC)
{
    TADS8422 *pADS = pDC;
    int iIndex;


    if (pADS == 0)
        return TIDC_ERR_NODEVICE;


    if (pADS->xferInProgress == 2)
        iIndex = (pADS->iObjectIndex + 1) & 0x0001;
    else
    {
        iIndex = pADS->iObjectIndex;
        EDMA_disableChannel(pADS->hEdmaRead);
    }


⌨️ 快捷键说明

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