78
M3i.48xx / M3i.48xx-exp Manual
Buffer handling
Acquisition modes
Buffer handling example for transfer from PC to card
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.
char* pcData = new char[lBufferSizeInBytes];
// before starting transfer we ned to once fill complete buffer memory with data
vDoGenerateData (&pcData[0], lBufferSizeInBytes);
// we now define the transfer buffer with the minimum notify size of on page = 4 kByte
spcm_dwDefTransfer_i64 (hDrv, SPCM_BUF_DATA, SPCM_DIR_PCTOCARD , 4096, (void*) pcData, 0, lBufferSizeInBytes);
// before start we once have to fill some data in for the start of the output
spcm_dwSetParam_i32 (hDrv, SPC_DATA_AVAIL_CARD_LEN, lBufferSizeInBytes);
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_i32 (hDrv, SPC_DATA_AVAIL_USER_LEN, &lAvailBytes);
spcm_dwGetParam_i32 (hDrv, SPC_DATA_AVAIL_USER_POS, &lBytePos);
printf (“We now have %d free 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) >= lBufferSizeInBytes)
lAvailBytes = lBufferSizeInBytes - lBytePos;
// our do function gets a pointer to the start of the available data section and the length
vDoGenerateData (&pcData[lBytesPos], lAvailBytes);
// now we mark the number of bytes that we just generated for replay
// and wait for the next free buffer
spcm_dwSetParam_i32 (hDrv, SPC_DATA_AVAIL_CARD_LEN, lAvailBytes);
dwError = spcm_dwSetParam_i32 (hDrv, SPC_M2CMD, M2CMD_DATA_WAITDMA);
}
}
while (!dwError); // we loop forever if no error occurs