PSoC 5LP HID Generic Overwrite IN-Endpoint

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Karl_Rossmann
Level 1
Level 1
First question asked Welcome!

Hello,


using PSoC 5 LP I'm writing an USB HID Generic Client Software similar to AN82072_0.

The USB device will evaluate sensor datas. I use an IN endpoint to communicate the sensor data to the host.

In the example code this would be done by checking for empty IN Endpoint buffer and write data into the buffer as soon as it's empty. 

In my case the Host won't be polling the IN-Endpoint every 10 ms or so. It will only check data in IN-endpoint when the Host Software will need it.

Because of this the sensor datas won't be up to date. The problematic sequence would be as follows:
- In the beginning the USB-IN-Buffer is empty and client writes actual sensor data into the IN-Buffer
- HOST application won't read in-buffer yet
- After 5 seconds the sensor datas have changed
- Because HOST hasn't read the IN-Endpiont yet, in-buffer is not empty and I cant write into the IN-Buffer
- After 7 seconds HOST will read the IN-Endpoint, but only can read "old" sensor datas.

How could I solve this problem?
I think it could be solved if the host reads the data twice in direct succession.
However is there a better solution? Can I overright the IN-Endpoint buffer when I have new sensor data and it is not read yet? Or can I somehow not wright the sensor datas into the IN-Endpoint buffer before the host requests it? If yes, which interrupt could be used?

Thanks for your help

0 Likes
1 Solution
Ekta_N
Moderator
Moderator
Moderator
750 replies posted First like given 250 solutions authored

Hello @Karl_Rossmann 

I went through the description of the issue. Here, are my answers:


I think it could be solved if the host reads the data twice in direct succession.


You can use this approach based on your application. In this case you need to write your host Application such that it reads data twice from the device at a go.



However is there a better solution? Can I overright the IN-Endpoint buffer when I have new sensor data and it is not read yet? 

Yes, the IN Endpoint data can be overwritten. In this case, you would need to remove the check:

if(USBFS_GetEPState(IN_ENDPOINT) == USBFS_IN_BUFFER_EMPTY) as this statement will ensure that the data is written to the IN Endpoint only when the IN Endpoint is empty. Also, since this is called in a for loop, removing the if condition will cause the IN Endpoint to be continuously updated with the IN_Data_Buffer value regardless of whether it has the old data or the new data. If required you can keep a check to load the IN Endpoint only when there is an update in the IN_Data_Buffer value.


 Or can I somehow not wright the sensor datas into the IN-Endpoint buffer before the host requests it? If yes, which interrupt could be used?

Since in your Application EP 1 in the IN Endpoint you can use the USBFS_EP_1_ISR_EntryCallback(void) function which is used at the beginning of the USBFS_EP_1_ISR() interrupt handler to perform additional application-specific actions to load the data.

The USBFS datasheet provides more information on how to use the entry callback functions. Refer to the Macro Callback section in the same.

Best Regards
Ekta

 

View solution in original post

0 Likes
1 Reply
Ekta_N
Moderator
Moderator
Moderator
750 replies posted First like given 250 solutions authored

Hello @Karl_Rossmann 

I went through the description of the issue. Here, are my answers:


I think it could be solved if the host reads the data twice in direct succession.


You can use this approach based on your application. In this case you need to write your host Application such that it reads data twice from the device at a go.



However is there a better solution? Can I overright the IN-Endpoint buffer when I have new sensor data and it is not read yet? 

Yes, the IN Endpoint data can be overwritten. In this case, you would need to remove the check:

if(USBFS_GetEPState(IN_ENDPOINT) == USBFS_IN_BUFFER_EMPTY) as this statement will ensure that the data is written to the IN Endpoint only when the IN Endpoint is empty. Also, since this is called in a for loop, removing the if condition will cause the IN Endpoint to be continuously updated with the IN_Data_Buffer value regardless of whether it has the old data or the new data. If required you can keep a check to load the IN Endpoint only when there is an update in the IN_Data_Buffer value.


 Or can I somehow not wright the sensor datas into the IN-Endpoint buffer before the host requests it? If yes, which interrupt could be used?

Since in your Application EP 1 in the IN Endpoint you can use the USBFS_EP_1_ISR_EntryCallback(void) function which is used at the beginning of the USBFS_EP_1_ISR() interrupt handler to perform additional application-specific actions to load the data.

The USBFS datasheet provides more information on how to use the entry callback functions. Refer to the Macro Callback section in the same.

Best Regards
Ekta

 

0 Likes