Demand of posting a message on NTFSD Forum - David Pujadas (joined in OSR)

Hello,

I am registered in OSR Forums recently and I would like to insert in NTSFD
Forums the next post for contribute with my software code and the hope that
people could help me with a problem that I have now.

I have sent this message yet, before the confirmation required by your
system and I don’t know if it was necessary to send it another time. Now the
confirmation was send it.

Thanks very much,

David Pujadas

////////////////////////////////////////////////////////////////////////////////////
START OF POST
///////////// TITLE OF POST: “Problem sending data to the host: ReadFile()
or HidD_GetFeature()”
Hello,

I am a software programmer working in HID USB firmware device and host
application, and I have a problem when I want to send data from the USB
device to the host, with ReadFile() and I would like to ask you if you could
help me.

I want to write an app code (in C language) and firmware HID Device (with
MC68HC908JB8 microprocessor). The target is to write data (a code in C
language) from host to device, and the device answer to the host if data has
been correctly received and if it has could program with the code another
component connected to it.

WriteFile() works correctly and it sends to the device the Output Report
with data (in the side of the device firmware the function getUSB(); works
correctly and I can receive data from EP2).

The problem is when I want to send to the host the simpliest character ‘y’
(of yes) in an Input Report. I use ReadFile() (without overlapped I/O) and
don’t work and program blocks here. If I use an Overlapped struct, timeout
occurs.

I think that the problem is in the device firmware, where I put the data
(‘y’) with:

>>putUSB (unsigned char);
and correctly works, copying data from variable to ring buffer ‘TxBuffer’
but when I do the request interrupt with ReadFile, I see with my debugger
that I never have the data in UE1D0-UE1D7 bits for sending by EP1. And I
never have the number of bytes to send in USB Control Register UCR1
(TPSIZ0-TPSIZ3). (I think that putUSB(), UCR1 and UE1D0-7 bits is property
of the microprocessor of Motorola, maybe is general. I don’t know).

Do you kow something about this? Somebody has been working with Input
Reports (transmiting data) on USB devices with “Motorola MC68HC908JB8”
microprocessor?

If it doesn’t works I want to try the same, to send the character ‘y’ from
the device to host, with: HidD_GetFeature() but I don’t know how to put data
in a Feature Report (from the point of view of the device), and after to
request this data with HidD_GetFeature().

Do you have examples of this? C code examples? In general, this is the same
in all microprocessors or is also specific of Motorola MC68HC908JB8?

I send you this part of my code:
*********************************Code example

//Application that enumerates the USB device and returns correctly the
handle.
DeviceHandle = connectToUSBHIDDevice (&vendorID, &productID,
&versionNumber);

if (DeviceHandle == INVALID_HANDLE_VALUE)
{
printf(“Press ENTER to close this window\n”);
wait();}

HidD_GetPreparsedData (DeviceHandle, &PreparsedData);

HidP_GetCaps (PreparsedData, &Capabilities);

OutputReport[0] = 0; // First byte contain report ID = 0
InputReport[0] = 0; // First byte contain report ID = 0
OutputReport[1] = *obuf; //data to send
OutputReport[2] = *obuf;

if (!WriteFile (DeviceHandle, OutputReport,
Capabilities.OutputReportByteLength, &BytesWritten, NULL))
{printf(“>Problem in WriteFile. Error number: %d\n”,
GetLastError());}

printf(“Bytes Written to the device are: %d\n”, BytesWritten);

//I create another handle for ReadFile, I don’t know if this is
necessary? or handle for WriteFile
// is correct yet.
readHandle = CreateFile (deviceDetail->DevicePath,
GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, // no LPSECURITY ATTRIBUTES
OPEN_EXISTING,
/*FILE_FLAG_OVERLAPPED,*/ 0, //Overlapped
struct if I use it
NULL);

if (!ReadFile (readHandle, InputReport,
Capabilities.InputReportByteLength, &BytesRead, NULL))
{printf(“>Problem in ReadFile. Error number: %d\n”, GetLastError());}

printf(“Bytes Read from the device are: %d\n”, BytesRead);

printf(“Input Report received from the device is: %s\n”,
InputReport[1]);

CloseHandle (DeviceHandle);
HidD_FreePreparsedData (PreparsedData);
printf(“Press ENTER to close this window\n”);
wait();
}
// Result: 0 bytes received.
******************************************************The end of Code
example
After, here you have the function putUSB(data); where data=‘y’;

void putUSB(unsigned char c) {

unsigned char newIdx;

newIdx = (TxBuf_WrIdx+1) & (MAX_TXBUF_SIZE-1);
while(newIdx == TxBuf_RdIdx)
; // wait if TxBuffer is full
TxBuffer[TxBuf_WrIdx] = c;
TxBuf_WrIdx = newIdx;
}
//********
And in HandleIN1 (application called if an EP1 interrupt is created)

UCR1 &= ~UCR1_TX1E_MASK; // Deactivate EP1 Transmitter
UIR2 = UIR2_TXD1FR_MASK; // Reset EP1 Transmit complete Flag

// refill EP1 Tx Data Buffer
n = 0;
dest = &UE1D0;
while((TxBuf_RdIdx != TxBuf_WrIdx) && n<8) {
*dest = TxBuffer[TxBuf_RdIdx];
TxBuf_RdIdx = (TxBuf_RdIdx+1) & (MAX_TXBUF_SIZE-1);
dest++;
n++;
}
// Activate EP1 Transmitter to send n Bytes
UCR1 = ((UCR1^UCR1_T1SEQ_MASK) & UCR1_T1SEQ_MASK) + UCR1_TX1E_MASK + n;
}
// Result: O bytes in UE1D0-UE1D7 bits for sending by EP1
************************************************
If somebody need more code, don’t hesitate to ask me.

Thanks very much for your help and answers. If you have a little free time
for me and you can answer this post, your better knowledge will be helpful.
And if you have examples C code of HidD_GetFeature(), of putting data on a
Feature Report or you know what is incorrect in my code of ReadFile() or
device firmware, will be perfect for me.

Best regards,
David Pujadas
///////////////////////////////////////////////////////////////////////////////////
THE END OF POST


Acepta el reto MSN Premium: Correos más divertidos con fotos y textos
increíbles en MSN Premium. Descárgalo y pruébalo 2 meses gratis.
http://join.msn.com?XAPID=1697&DI=1055&HL=Footer_mailsenviados_correosmasdivertidos

This relates to file systems in some obsure way? How?

“David Pujadas” wrote in message news:xxxxx@ntfsd…
> Hello,
>
> I am registered in OSR Forums recently and I would like to insert in NTSFD
> Forums the next post for contribute with my software code and the hope
> that people could help me with a problem that I have now.
>
> I have sent this message yet, before the confirmation required by your
> system and I don’t know if it was necessary to send it another time. Now
> the confirmation was send it.
>
> Thanks very much,
>
> David Pujadas
>
> ////////////////////////////////////////////////////////////////////////////////////
> START OF POST
> ///////////// TITLE OF POST: “Problem sending data to the host: ReadFile()
> or HidD_GetFeature()”
> Hello,
>
> I am a software programmer working in HID USB firmware device and host
> application, and I have a problem when I want to send data from the USB
> device to the host, with ReadFile() and I would like to ask you if you
> could help me.
>
> I want to write an app code (in C language) and firmware HID Device (with
> MC68HC908JB8 microprocessor). The target is to write data (a code in C
> language) from host to device, and the device answer to the host if data
> has been correctly received and if it has could program with the code
> another component connected to it.
>
> WriteFile() works correctly and it sends to the device the Output Report
> with data (in the side of the device firmware the function getUSB(); works
> correctly and I can receive data from EP2).
>
> The problem is when I want to send to the host the simpliest character ‘y’
> (of yes) in an Input Report. I use ReadFile() (without overlapped I/O) and
> don’t work and program blocks here. If I use an Overlapped struct, timeout
> occurs.
>
> I think that the problem is in the device firmware, where I put the data
> (‘y’) with:
>>>>putUSB (unsigned char);
> and correctly works, copying data from variable to ring buffer ‘TxBuffer’
> but when I do the request interrupt with ReadFile, I see with my debugger
> that I never have the data in UE1D0-UE1D7 bits for sending by EP1. And I
> never have the number of bytes to send in USB Control Register UCR1
> (TPSIZ0-TPSIZ3). (I think that putUSB(), UCR1 and UE1D0-7 bits is
> property of the microprocessor of Motorola, maybe is general. I don’t
> know).
>
> Do you kow something about this? Somebody has been working with Input
> Reports (transmiting data) on USB devices with “Motorola MC68HC908JB8”
> microprocessor?
>
> If it doesn’t works I want to try the same, to send the character ‘y’ from
> the device to host, with: HidD_GetFeature() but I don’t know how to put
> data in a Feature Report (from the point of view of the device), and after
> to request this data with HidD_GetFeature().
>
> Do you have examples of this? C code examples? In general, this is the
> same in all microprocessors or is also specific of Motorola MC68HC908JB8?
>
> I send you this part of my code:
> *********************************Code example
> …
> //Application that enumerates the USB device and returns correctly the
> handle.
> DeviceHandle = connectToUSBHIDDevice (&vendorID, &productID,
> &versionNumber);
>
> if (DeviceHandle == INVALID_HANDLE_VALUE)
> {
> printf(“Press ENTER to close this window\n”);
> wait();}
>
> HidD_GetPreparsedData (DeviceHandle, &PreparsedData);
>
> HidP_GetCaps (PreparsedData, &Capabilities);
>
> OutputReport[0] = 0; // First byte contain report ID = 0
> InputReport[0] = 0; // First byte contain report ID = 0
> OutputReport[1] = *obuf; //data to send
> OutputReport[2] = obuf;
>
> if (!WriteFile (DeviceHandle, OutputReport,
> Capabilities.OutputReportByteLength, &BytesWritten, NULL))
> {printf(“>Problem in WriteFile. Error number: %d\n”,
> GetLastError());}
>
> printf(“Bytes Written to the device are: %d\n”, BytesWritten);
>
> //I create another handle for ReadFile, I don’t know if this is
> necessary? or handle for WriteFile
> // is correct yet.
> readHandle = CreateFile (deviceDetail->DevicePath,
> GENERIC_READ,
> FILE_SHARE_READ | FILE_SHARE_WRITE,
> NULL, // no LPSECURITY ATTRIBUTES
> OPEN_EXISTING,
> /FILE_FLAG_OVERLAPPED,/ 0, //Overlapped
> struct if I use it
> NULL);
>
> if (!ReadFile (readHandle, InputReport,
> Capabilities.InputReportByteLength, &BytesRead, NULL))
> {printf(“>Problem in ReadFile. Error number: %d\n”, GetLastError());}
>
> printf(“Bytes Read from the device are: %d\n”, BytesRead);
>
> printf(“Input Report received from the device is: %s\n”,
> InputReport[1]);
>
> CloseHandle (DeviceHandle);
> HidD_FreePreparsedData (PreparsedData);
> printf(“Press ENTER to close this window\n”);
> wait();
> }
> // Result: 0 bytes received.
>The end of Code
> example
> After, here you have the function putUSB(data); where data=‘y’;
>
> void putUSB(unsigned char c) {
>
> unsigned char newIdx;
>
> newIdx = (TxBuf_WrIdx+1) & (MAX_TXBUF_SIZE-1);
> while(newIdx == TxBuf_RdIdx)
> ; // wait if TxBuffer is full
> TxBuffer[TxBuf_WrIdx] = c;
> TxBuf_WrIdx = newIdx;
> }
> //

> And in HandleIN1 (application called if an EP1 interrupt is created)
> …
> UCR1 &= ~UCR1_TX1E_MASK; // Deactivate EP1 Transmitter
> UIR2 = UIR2_TXD1FR_MASK; // Reset EP1 Transmit complete Flag
>
> // refill EP1 Tx Data Buffer
> n = 0;
> dest = &UE1D0;
> while((TxBuf_RdIdx != TxBuf_WrIdx) && n<8) {
> dest = TxBuffer[TxBuf_RdIdx];
> TxBuf_RdIdx = (TxBuf_RdIdx+1) & (MAX_TXBUF_SIZE-1);
> dest++;
> n++;
> }
> // Activate EP1 Transmitter to send n Bytes
> UCR1 = ((UCR1^UCR1_T1SEQ_MASK) & UCR1_T1SEQ_MASK) + UCR1_TX1E_MASK + n;
> }
> // Result: O bytes in UE1D0-UE1D7 bits for sending by EP1
>

> If somebody need more code, don’t hesitate to ask me.
>
> Thanks very much for your help and answers. If you have a little free time
> for me and you can answer this post, your better knowledge will be
> helpful. And if you have examples C code of HidD_GetFeature(), of putting
> data on a Feature Report or you know what is incorrect in my code of
> ReadFile() or device firmware, will be perfect for me.
>
> Best regards,
> David Pujadas
> ///////////////////////////////////////////////////////////////////////////////////
> THE END OF POST
>
> _________________________________________________________________
> Acepta el reto MSN Premium: Correos más divertidos con fotos y textos
> increíbles en MSN Premium. Descárgalo y pruébalo 2 meses gratis.
> http://join.msn.com?XAPID=1697&amp;DI=1055&amp;HL=Footer_mailsenviados_correosmasdivertidos
>
>