USBCBSendResume Function

Microchip USB Device Library

USB Device Library Help
USBCBSendResume Function
C
void USBCBSendResume();
Description

The USB specifications allow some types of USB peripheral devices to wake up a host PC (such as if it is in a low power suspend to RAM state). This can be a very useful feature in some USB applications, such as an Infrared remote control receiver. If a user presses the "power" button on a remote control, it is nice that the IR receiver can detect this signalling, and then send a USB "command" to the PC to wake up. 

The USBCBSendResume() "callback" function is used to send this special USB signalling which wakes up the PC. This function may be called by application firmware to wake up the PC. This function should only be called when: 

  1. The USB driver used on the host PC supports the remote wakeup capability.
  2. The USB configuration descriptor indicates the device is remote wakeup capable in the bmAttributes field. (see usb_descriptors.c and _RWU)
  3. The USB host PC is currently sleeping, and has previously sent your device a SET FEATURE setup packet which "armed" the remote wakeup capability. (see USBGetRemoteWakeupStatus())
 

This callback should send a RESUME signal that has the period of 1-15ms. 

Typical Usage:

if((USBDeviceState == CONFIGURED_STATE)
    && (USBIsDeviceSuspended() == TRUE)
    && (USBGetRemoteWakeupStatus() == TRUE))
{
    if(ButtonPressed)
    {
        //Wake up the USB module from suspend
        USBWakeFromSuspend();

        //Issue a remote wakeup command on the bus
        USBCBSendResume();
    }
}
Preconditions

None

Remarks

A user can switch to primary first by calling USBCBWakeFromSuspend() if required/desired. 

The modifiable section in this routine should be changed to meet the application needs. Current implementation temporary blocks other functions from executing for a period of 1-13 ms depending on the core frequency. 

According to USB 2.0 specification section 7.1.7.7, "The remote wakeup device must hold the resume signaling for at lest 1 ms but for no more than 15 ms." The idea here is to use a delay counter loop, using a common value that would work over a wide range of core frequencies. That value selected is 1800. See table below:

Core Freq(MHz) 
MIP (for PIC18) 
RESUME Signal Period (ms) 
48 
12 
1.05 
12.6 

  • These timing could be incorrect when using code optimization or extended instruction mode, or when having other interrupts enabled. Make sure to verify using the MPLAB SIM's Stopwatch and verify the actual signal on an oscilloscope.
  • These timing numbers should be recalculated when using PIC24 or PIC32 as they have different clocking structures.
  • A timer can be used in place of the blocking loop if desired.

Microchip MCHPFSUSB v2.3 - Sept 20, 2008
Copyright © 2008 Microchip Technology, Inc.  All rights reserved.