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

cross mob

USBFS Suspend and Resume Functionality - KBA210675

USBFS Suspend and Resume Functionality - KBA210675

Anonymous
Not applicable

Version: **

Translation - Japanese: USBFS の サスペンド (Suspend) と レジューム (Resume) 機能 - KBA210675 - Community Translated (JA)

Question:

How do we implement Suspend-Resume functionality in USBFS?

Answer:

A USB device will enter suspend when there is no activity on the bus for greater than 3 ms. It then has a further 7 ms to shut down the device and draw no more than the designated suspend current. This means that the device must be drawing only the rated suspend current from the bus 10 ms after bus activity stopped.

The following piece of code shows how to implement Suspend-Resume functionality in USBFS.

            if(!USBFS_CheckActivity())
             {
                 noActivityCount++;
                 if(noActivityCount == USB_SUSPEND_TIME_TICKS)
                 {
                     PSOC_APP_LED_Write(1);       // To check if the device has entered Suspend.
                     USBFS_Suspend();     
                     CyPmSaveClocks();
                     CyPmSleep(PM_SLEEP_TIME_NONE, PM_SLEEP_SRC_PICU); /* PSoC 3/5LP enters sleep mode */
                     CyPmRestoreClocks();
                     USBFS_Resume();
                     init =1;                                // To initialize the endpoints again - Note 1.
                     noActivityCount = 0;
                     PSOC_APP_LED_Write(0);      // To view the status on a LED.
                 }
             }
             else
             {
                 noActivityCount = 0;
             }

Note 1: After the device wakes up, the endpoints have to be enabled again; if it is in Mode 3/2, you need to configure the DMAs again.
Note 2: The code snippet is written assuming that the USBFS Component is named as "USBFS".

Algorithm followed:

The firmware checks the status of the USB activity; if it is found to be inactive for 3 ms,it understands that a Suspend has been issued. Keep the USB_SUSPEND_TIME_TICKS value appropriately so that the firmware waits for minimum of 3 ms. A typical value will be 500 when the firmware has no or minimal delay in the firmware. The firmware then goes to low-power Sleep mode.

If a resume is issued, it wakes up by the port interrupt control unit (PICU) interrupt and then reconfigures the USBFS Component and initializes the endpoints again (to be done in the firmware by checking status of the init variable).

0 Likes
427 Views
Contributors