??? 02/01/06 08:27 Read: times |
#108861 - Two USB communication procedure Responding to: ???'s previous message |
Hi Mehdi,
You may wonder why the 'strange' feature of IN EndPoint (EP) is so important as I mentioned in my previous post. "IN EP interrupt after sending packet" http://www.8052.com/forum/read.phtml?id=108839 Because this feature regulates USB communication procedure as follows. a) Handshake method Host sends a command to device OUT EP, then receive an answer from IN EP. b) Polling method Host polls IN EP periodically (or frequently) Please suppose that a host PC wants to know the current status of switches connecting to a port of an USB MCU. Because of the 'strange' feature of IN EP, there is no acceptable way other than above method. a) Handshake method - The host sends a command to read the port status to the MCU OUT EP - An OUT EP interrupt is triggered on MCU when the OUT packet arrives. - In the OUT EP ISR, the firmware unloads the command to a buffer and raises a flag. - In mainloop of the firmware, MCU catches the flag and interprets the command on the buffer. - According to the comand, MCU fills the IN EP buffer with the current port status. - The host receives the current port status as the answer from IN EP. (actually, the host may poll the IN EP several times and get NAk before accepting the answer.) In this method, the OUT EP interrupt provides a trigger to capture the current port status. b) Polling method - The host polls the MCU IN EP and retrieve the previous port status, prepared by the firmware in advance. - An IN EP interrupt is triggered on MCU after the IN packet is sent. - In the IN EP ISR, the firmware raises a flag. - In the mainloop of the firmware, MCU catches the flag and fills the IN EP buffer with the current port status. - The host polls the MCU IN EP again and retrieves the current port status. - An IN EP interrupt is triggered on MCU after the IN packet is sent, and the MCU prepares next answer in advance. I described a snapshot of polling method above. Usually, as polling is done periodically, the host can retrieve the current port status with a polling interval delay at worst. This periodical polling method is took by the interrupt EP on HID implementation. HID device driver issues IN transaction periodically according to the bInterval field on the interrupt EP descriptor. From this discussion, you will notice another important conclusion on the USB communication. The only way for a device to notify to a host is that the host polls the device. I must go to a business trip now, I'll return this weekend. Happy USB coding! Tsuneo |