??? 01/16/06 19:06 Read: times |
#107529 - Firmware Programming Guide for D12! Responding to: ???'s previous message |
Firmware Programming Guide for D12 By Philips said:
When the setup packet is received by the USB device D12, this device will generate an interrupt to the MCU. The microcontroller will need to service this interrupt by reading D12 interrupt register to determine whether the packet is send to Control Endpoint or the Generic Endpoint. If the packet is for the Control Endpoint, MCU will need to further determine whether the data is a setup packet through reading the D12 Read Last Transaction Status Register. For the Get_Descriptor device request, the first packet will have to be the setup packet. From the flowchart above, MCU will need to extract the content of the setup packet through Select Control Out Endpoint to determine whether this endpoint is full or empty. If the control endpoint is full, MCU will then read the content from the buffer and save the content to its memory. After that, it will validate the host device's request from the memory. If it is a valid request, MCU must send the Acknowledge Setup command to the Control Out endpoint to re-enable the next setup phase. Next, MCU will need to verify whether the control transfer is a Control Read/Write. This can be achieved through reading the 8th bit of the bmRequestType from the setup packet. In our case, the control transfer is a Control Read type, that is, the device will need to send data packet back to the host in the coming data phase. MCU will need to set a flag to indicate that the USB device is now in the transmit mode, that is, ready to send its data upon the host's request. After the Setup stage is finished, the host will execute the data phase.D12 will expect to receive the Control_In packet. The process is shown in the next flowchart, "Control_In Handler". Again, MCU will first need to clear the Control_In interrupt Bit on the D12 by reading its Read Last Transaction Register. Then, MCU will proceed to send the data packet after verifying that D12 is in the appropriate mode, that is, the Transmit mode. As D12 control endpoint has only 16 bytes FIFO, MCU will have to control the amount of data during the transmitting phase if the requested length is more than 16 bytes. As indicated on the flowchart, MCU will have to check its current and remaining size of the data to be sent to the host. If the remaining bytes are greater than 16 bytes, MCU will send the first 16 bytes and then subtract the reference length (requested length) by 16. When the next Control_In token comes, MCU will determine whether the remaining bytes is zero. If there is no more data to send, MCU will need to send an empty packet to inform the host that there will be no more data to be sent over. If the setup packet is Set_Descriptor() request, then the control transfer in the setup packet will indicate that it is a Control Write type. After executing the procedure for the Set_Descriptor request, MCU will wait for the data phase. The host will send a Control_Out token and MCU will have to extract the data from the D12 buffer. The flow will now be on the right side of the Control_Out Handler flow sequence. MCU will have to first verify whether D12 is in the USB_Receive mode. Then, MCU will have to verify whether the buffer is full by checking the Select Control_Out Endpoint and read the data out from the buffer. Joseph, After sending acknowledge i am expecting Control_In packet but it don't arrive? It is my main question. Mehdi |