82
M2i.60xx / M2i.60xx-exp Manual
Buffer handling
Generation modes
Buffer handling example for transfer from card to PC
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];
// 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_CARDTOPC , 4096, (void*) pcData, 0, lBufferSizeInBytes);
// 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_i32 (hDrv, SPC_DATA_AVAIL_USER_LEN, &lAvailBytes);
spcm_dwGetParam_i32 (hDrv, SPC_DATA_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) >= lBufferSizeInBytes)
lAvailBytes = lBufferSizeInBytes - lBytePos;
// our do function gets a pointer to the start of the available data section and the length
vDoSomething (&pcData[lBytesPos], lAvailBytes);
// the buffer section is now immediately set available for the card
spcm_dwSetParam_i32 (hDrv, SPC_DATA_AVAIL_CARD_LEN, lAvailBytes);
}
}
while (!dwError); // we loop forever if no error occurs
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