
90
(c) Spectrum Instrumentation GmbH
Buffer handling
Acquisition modes
Buffer handling example for transfer from card to PC (Data acquisition)
Buffer handling example for transfer from PC to card (Data generation)
Please keep in mind that you are using a continuous buffer writing/reading that will start again at the zero
position if the buffer length is reached. However the DATA_AVAIL_USER_LEN register will give you the com
-
plete amount of available bytes even if one part of the free area is at the end of the buffer and the second
half at the beginning of the buffer.
int8* pcData = (int8*) pvAllocMemPageAligned (llBufferSizeInBytes);
// we now define the transfer buffer with the minimum notify size of one page = 4 kByte
spcm_dwDefTransfer_i64 (hDrv, SPCM_BUF_DATA, SPCM_DIR_CARDTOPC , 4096, (void*) pcData, 0, llBufferSizeInBytes);
// we start the DMA transfer
dwError = spcm_dwSetParam_i32 (hDrv, SPC_M2CMD, M2CMD_DATA_STARTDMA);
do
{
if (!dwError)
{
// we wait for the next data to be available. Afte this call we get at least 4k of data to proceed
dwError = spcm_dwSetParam_i32 (hDrv, SPC_M2CMD, M2CMD_DATA_WAITDMA);
// if there was no error we can proceed and read out the available bytes that are free again
spcm_dwGetParam_i64 (hDrv, SPC_DATA_AVAIL_USER_LEN, &llAvailBytes);
spcm_dwGetParam_i64 (hDrv, SPC_DATA_AVAIL_USER_POS, &llBytePos);
printf (“We now have %lld new bytes available\n”, llAvailBytes);
printf (“The available data starts at position %lld\n”, llBytesPos);
// we take care not to go across the end of the buffer, handling the wrap-around
if ((llB llAvailBytes) >= llBufferSizeInBytes)
llAvailBytes = llBufferSizeInBytes - llBytePos;
// our do function gets a pointer to the start of the available data section and the length
vDoSomething (&pcData[llBytesPos], llAvailBytes);
// the buffer section is now immediately set available for the card
spcm_dwSetParam_i64 (hDrv, SPC_DATA_AVAIL_CARD_LEN, llAvailBytes);
}
}
while (!dwError); // we loop forever if no error occurs
int8* pcData = (int8*) pvAllocMemPageAligned (llBufferSizeInBytes);
// before starting transfer we first need to fill complete buffer memory with meaningful data
vDoGenerateData (&pcData[0], llBufferSizeInBytes);
// we now define the transfer buffer with the minimum notify size of one page = 4 kByte
spcm_dwDefTransfer_i64 (hDrv, SPCM_BUF_DATA, SPCM_DIR_PCTOCARD , 4096, (void*) pcData, 0, llBufferSizeInBytes);
// and transfer some data to the hardware buffer before the start of the card
spcm_dwSetParam_i32 (hDrv, SPC_DATA_AVAIL_CARD_LEN, llBufferSizeInBytes);
dwError = spcm_dwSetParam_i32 (hDrv, SPC_M2CMD, M2CMD_DATA_STARTDMA | M2CMD_DATA_WAITDMA);
do
{
if (!dwError)
{
// if there was no error we can proceed and read out the current amount of available data
spcm_dwGetParam_i64 (hDrv, SPC_DATA_AVAIL_USER_LEN, &llAvailBytes);
spcm_dwGetParam_i64 (hDrv, SPC_DATA_AVAIL_USER_POS, &llBytePos);
printf (“We now have %lld free bytes available\n”, llAvailBytes);
printf (“The available data starts at position %lld\n”, llBytesPos);
// we take care not to go across the end of the buffer, handling the wrap-around
if ((llB llAvailBytes) >= llBufferSizeInBytes)
llAvailBytes = llBufferSizeInBytes - llBytePos;
// our do function gets a pointer to the start of the available data section and the length
vDoGenerateData (&pcData[llBytesPos], llAvailBytes);
// now we mark the number of bytes that we just generated for replay
// and wait for the next free buffer
spcm_dwSetParam_i64 (hDrv, SPC_DATA_AVAIL_CARD_LEN, llAvailBytes);
dwError = spcm_dwSetParam_i32 (hDrv, SPC_M2CMD, M2CMD_DATA_WAITDMA);
}
}
while (!dwError); // we loop forever if no error occurs
Содержание M2p.59 Series
Страница 190: ......