📄 t8422_ob.c
字号:
*
* Return value: Of type TTIDCSTATUS
* - TIDC_NO_ERR: No error
* - TIDC_ERR_NO_DEVICE: No data converter object was passed
* - TIDC_ERR_BADARGS: The number of words to be transferred
* was less than 2 or larger than 0xffff
* - TIDC_ERR_XFERPROG: It was attempted to submit a 3rd
* transfer.
*
* Globals modified:
* - Inside the data converter object:
* - iObjectIndex
* - xferInProgress
* - Inside the xferBuffer object:
* - uibufPtr
* - uibufSize
* - uiStatus
* - ptrCallback
*
* Resources used:
* - One DMA 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 DMA controller).
*/
/****************************************************************/
TTIDCSTATUS ADS8422_readblock(void *pDC,
void *pData,
unsigned long ulCount,
void (*readCallback) (void *))
{
TADS8422 *pADS = pDC;
/* 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 */
/* store the information in the ADS8422 object */
pADS->xferBuffer[pADS->iObjectIndex].ptrCallBack = readCallback;
pADS->xferBuffer[pADS->iObjectIndex].uiBufPtr = (unsigned int *)pData;
pADS->xferBuffer[pADS->iObjectIndex].uiBufSize = (unsigned int)ulCount;
pADS->xferBuffer[pADS->iObjectIndex].uiStatus = ADS8422_BUFOBJECT_INUSE;
(void)SubmitBlock(pADS->hDmaRead,
pADS->xferBuffer[pADS->iObjectIndex],
pADS->uiCcrValue,
pADS->xferInProgress);
/* this is the first transfer in a row */
if (pADS->xferInProgress == 1)
(void)IRQ_enable(DMA_getEventId(pADS->hDmaRead));
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.
*
* 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
* - hDmaRead
* - xferInProgress
* - iObjectIndex
* Inside the buffer objects:
* - uiStatus
*
* Resources used:
* - One DMA channel (closed)
* - One timer (closed)
*/
/****************************************************************/
TTIDCSTATUS ADS8422_close(void *pDC)
{
TADS8422 *pADS = pDC;
/* return, if no device object available */
if (pADS == 0)
return TIDC_ERR_NODEVICE;
/* close the DMA channel, if it was open */
if ((pADS->hDmaRead != 0) && (pADS->hDmaRead != INV))
{
DMA_close(pADS->hDmaRead);
pADS->hDmaRead = 0;
}
/* close the timer, if it was open */
if ((pADS->hConvstTimer != 0) && (pADS->hConvstTimer != INV))
{
TIMER_close(pADS->hConvstTimer);
pADS->hConvstTimer = 0;
}
/* reset transfer in progress semaphore and buffer objects */
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:
* - Is called at the end of the DMA transfer by the DMA
* channel interrupt request.
* - Clears the event flag in the CCR
* - 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:
* - None
*
* Return value:
* - None
*
* Globals modified: In the data converter object:
* - xferInProgress
* - uiStatus inside the transfer buffer object
*
* Resources used: None
*/
/****************************************************************/
interrupt void ADS8422_rblock_finished(void)
{
int iIndex;
if (pgADS->xferInProgress == 1)
{
/* avoid additional synchronization events to the DMA */
/* by clearing the DMACCR register */
DMA_RSETH(pgADS->hDmaRead, DMACCR, 0);
(void)IRQ_disable(DMA_getEventId(pgADS->hDmaRead));
}
(void)DMA_RGETH(pgADS->hDmaRead, DMACSR);
if (pgADS->xferInProgress == 2)
iIndex = (pgADS->iObjectIndex + 1) & 0x0001;
else
iIndex = pgADS->iObjectIndex;
/* if there is a callback function requested, call it */
if (pgADS->xferBuffer[iIndex].ptrCallBack)
{
pgADS->xferBuffer[iIndex].uiStatus =
ADS8422_BUFOBJECT_COMPLETE;
pgADS->xferBuffer[iIndex].ptrCallBack(pgADS);
}
pgADS->xferBuffer[iIndex].uiStatus = ADS8422_BUFOBJECT_FREE;
/* signal that the transfer was successful */
pgADS->xferInProgress -= 1; /* adjust flag */
}
/****************************************************************/
/* 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)
{
*hTimer = TIMER_open(iTimerNumber, TIMER_OPEN_RESET);
/* was the open call successfull? */
if (*hTimer == INV)
return TIDC_ERR_NOCHIPRES;
/* if yes, configure the timer registers */
TIMER_configArgs(*hTimer,
TIMER_FMK(TCR, IDLEEN, TIMER_TCR_IDLEEN_DISABLE)
| TIMER_FMK(TCR, FUNC, TIMER_TCR_FUNC_OF(1))
| TIMER_FMK(TCR, TLB, TIMER_TCR_TLB_RESET)
| TIMER_FMK(TCR, SOFT, TIMER_TCR_SOFT_BRKPTNOW)
| TIMER_FMK(TCR, FREE, TIMER_TCR_FREE_WITHSOFT)
| TIMER_FMK(TCR, PWID, TIMER_TCR_PWID_DEFAULT)
| TIMER_FMK(TCR, ARB, TIMER_TCR_ARB_RESET)
| TIMER_FMK(TCR, TSS, TIMER_TCR_TSS_STOP)
| TIMER_FMK(TCR, CP, TIMER_TCR_CP_CLOCK)
| TIMER_FMK(TCR, POLAR, TIMER_TCR_POLAR_DEFAULT)
| TIMER_FMK(TCR, DATOUT, TIMER_TCR_DATOUT_0),
uiPeriod,
0);
return TIDC_NO_ERR;
}
/****************************************************************/
/* InitDma() */
/** Operation:
* - Opens the DMA channel selected in the graphical user
* interface to read words from the data converter.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -