A puzzle in the kbdclass.c

I just want to know how to implement “ring buffer” in driver ,so I study the kbdclass in DDK 2600.

And I find the processing section of the buffer locates in KeyboardClassServiceCallback function.

I read it some times , but still can’t understand how the “second move” happens :

if ( ( bytesToMove - moveSize ) > 0 )
/****************************************************************
this is the obscure place. I have deduce it for some times , but I just find ( bytesToMove == moveSize ) , I think there should be a “second move” , but the parametes used here is wrog. /****************************************************************/
{

// Special case. The data must wrap in the class input data buffer.
// Copy the rest of the port input data into the beginning of the
// class input data queue.

// MoveSize <- Number of bytes to handle in the second move.
moveSize = bytesToMove - moveSize;

// Do the move from the port data queue to the class data queue.

KbdPrint((
3,
“KBDCLASS-KeyboardClassServiceCallback: number of bytes in second move to class 0x%lx\n”,
moveSize
));
KbdPrint((
3,
“KBDCLASS-KeyboardClassServiceCallback: move bytes from 0x%lx to 0x%lx\n”,
(PCHAR) InputDataStart,
(PCHAR) deviceExtension->DataIn
));

RtlMoveMemory(
(PCHAR) deviceExtension->DataIn,
(PCHAR) InputDataStart,
moveSize
);

// Update the class input data queue insertion pointer.
deviceExtension->DataIn = (PKEYBOARD_INPUT_DATA)(((PCHAR) deviceExtension->DataIn) + moveSize);
}

// Update the input data queue counter.
deviceExtension->InputCount += ( bytesToMove / sizeof(KEYBOARD_INPUT_DATA));
/****************************************************************/
count all the input charaters ? why ? for what purpose?

/****************************************************************/
*InputDataConsumed += (bytesToMove / sizeof(KEYBOARD_INPUT_DATA));

The ring buffer deals in bytes, but InputCount is a count of packets (ie number of KEYBOARD_INPUT_DATA’s in the queue that are valid), this is why you see both byte counts as well and packet counts.

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Sunday, June 13, 2010 3:10 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] A puzzle in the kbdclass.c

I just want to know how to implement “ring buffer” in driver ,so I study the kbdclass in DDK 2600.

And I find the processing section of the buffer locates in KeyboardClassServiceCallback function.

I read it some times , but still can’t understand how the “second move” happens :

if ( ( bytesToMove - moveSize ) > 0 )
/****************************************************************
this is the obscure place. I have deduce it for some times , but I just find ( bytesToMove == moveSize ) , I think there should be a “second move” , but the parametes used here is wrog. /****************************************************************/
{

// Special case. The data must wrap in the class input data buffer.
// Copy the rest of the port input data into the beginning of the
// class input data queue.

// MoveSize <- Number of bytes to handle in the second move.
moveSize = bytesToMove - moveSize;

// Do the move from the port data queue to the class data queue.

KbdPrint((
3,
“KBDCLASS-KeyboardClassServiceCallback: number of bytes in second move to class 0x%lx\n”,
moveSize
));
KbdPrint((
3,
“KBDCLASS-KeyboardClassServiceCallback: move bytes from 0x%lx to 0x%lx\n”,
(PCHAR) InputDataStart,
(PCHAR) deviceExtension->DataIn
));

RtlMoveMemory(
(PCHAR) deviceExtension->DataIn,
(PCHAR) InputDataStart,
moveSize
);

// Update the class input data queue insertion pointer.
deviceExtension->DataIn = (PKEYBOARD_INPUT_DATA)(((PCHAR) deviceExtension->DataIn) + moveSize);
}

// Update the input data queue counter.
deviceExtension->InputCount += ( bytesToMove / sizeof(KEYBOARD_INPUT_DATA));
/****************************************************************/
count all the input charaters ? why ? for what purpose?

/****************************************************************/
*InputDataConsumed += (bytesToMove / sizeof(KEYBOARD_INPUT_DATA));


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer