USB Library
USBGet1msTickCount Function
Syntax
uint32_t USBGet1msTickCount();
Description

This function retrieves a 32-bit unsigned integer that normally increments by one every one millisecond. The count value starts from zero when the USBDeviceInit() function is first called. See the remarks section for details on special circumstances where the tick count will not increment.

Preconditions

This function should be called only after USBDeviceInit() has been called (at least once at the start of the application).

Remarks

On 8-bit USB full speed devices, the internal counter is incremented on every SOF packet detected. Therefore, it will not increment during suspend or when the USB cable is detached. However, on 16-bit devices, the T1MSECIF hardware interrupt source is used to increment the internal counter. Therefore, on 16-bit devices, the count continue to increment during USB suspend or detach events, so long as the application code has not put the microcontroller to sleep during these events, and the application firmware is regularly calling the USBDeviceTasks() function (or allowing it to execute, if using USB_INTERRUPT mode operation). 

In USB low speed applications, the host does not broadcast SOF packets to the device, so the application firmware becomes responsible for calling USBIncrement1msInternalTimers() periodically (ex: from a general purpose timer interrupt handler), or else the returned value from this function will not increment. 

Prior to calling USBDeviceInit() for the first time the returned value will be unpredictable. 

This function is USB_INTERRUPT mode safe and may be called from main loop code without risk of retrieving a partially updated 32-bit number. 

However, this value only increments when the USBDeviceTasks() function is allowed to execute. If USB_INTERRUPT mode is used, it is allowable to block on this function. If however USB_POLLING mode is used, one must not block on this function without also calling USBDeviceTasks() continuously for the blocking duration (since the USB stack must still be allowed to execute, and the USB stack is also responsible for updating the tick counter internally). 

If the application is operating in USB_POLLING mode, this function should only be called from the main loop context, and not from an interrupt handler, as the returned value could be incorrect, if the main loop context code was in the process of updating the internal count at the moment of the interrupt event.

MLA - USB Library Help Version : 2.16
http://www.microchip.com/mla