
162
(c) Spectrum Instrumentation GmbH
Reading out the timestamps
Timestamps
Buffer handling example for DMA timestamp transfer (ABA transfer is similar, just using other registers)
The extra FIFO has a quite small size compared to the main data buffer. As the transfer is done initiated by
the hardware using busmaster DMA this is not critical as long as the application data buffers are large
enough and as long as the extra transfer is started BEFORE starting the card.
Data Transfer using Polling
If the extra data is quite slow and the delay caused by the notify size on DMA transfers is unacceptable for your application it is possible to
use the polling mode. Please be aware that the polling mode uses CPU processing power to get the data and that there might be an overrun
if your CPU is otherwise busy. You should only use polling mode in special cases and if the amount of data to transfer is not too high.
Most of the functionality is similar to the DMA based transfer mode as explained above.
The polling data transfer mode is activated as soon as the M2CMD_EXTRA_POLL is executed.
Definition of the transfer buffer
This is similar to the above explained DMA buffer transfer. The value „notify size“ is ignored and should be set to 4k (4096).
Buffer handling
The buffer handling is also similar to the DMA transfer. As soon as one of the registers SPC_TS_AVAIL_USER_LEN or SPC_ABA_AVAIL_US
-
ER_LEN is read the driver will read out all available data from the hardware and will return the number of bytes that has been read. In min
-
imum this will be one DWORD = 4 bytes.
int8* pcData = (int8*) pvAllocMemPageAligned (lBufSizeInBytes);
// we now define the transfer buffer with the minimum notify size of one page = 4 kByte
spcm_dwDefTransfer_i64 (hDrv, SPCM_BUF_TIMESTAMP, SPCM_DIR_CARDTOPC, 4096, (void*) pcData, 0, lBufSizeInBytes);
do
{
// we wait for the next data to be available. After this call we get at least 4k of data to proceed
dwError = spcm_dwSetParam_i32 (hDrv, SPC_M2CMD, M2CMD_EXTRA_STARTDMA | M2CMD_EXTRA_WAITDMA);
if (!dwError)
{
// if there was no error we can proceed and read out the current amount of available data
spcm_dwGetParam_i32 (hDrv, SPC_TS_AVAIL_USER_LEN, &lAvailBytes);
spcm_dwGetParam_i32 (hDrv, SPC_TS_AVAIL_USER_POS, &lBytePos);
printf (“We now have %d new bytes available\n”, lAvailBytes);
printf (“The available data starts at position %d\n”, lBytesPos);
// we take care not to go across the end of the buffer
if ((lB lAvailBytes) >= lBufSizeInBytes)
lAvailBytes = lBufSizeInBytes - lBytePos;
// our do function gets a pointer to the start of the available data section and the length
vProcessTimestamps (&pcData[lBytesPos], lAvailBytes);
// the buffer section is now immediately set available for the card
spcm_dwSetParam_i32 (hDrv, SPC_TS_AVAIL_CARD_LEN, lAvailBytes);
}
}
while (!dwError); // we loop forever if no error occurs
Summary of Contents for M2p.59 Series
Page 190: ......