8月2日 USB的继续

时间:2022-01-15 14:37:45

        今天没有做太多的技术活,被Yamazaki和longhorn给玩了(我也不知道是主动还是被动)。

一些纪录:



电源管理之内核状态

当一个设备被要求挂起的时候,持续供电,保持在一点,RAM保持在一个自刷新状态。当一个中断来的时候会唤醒设备。
一般有3个途径挂起:
1 键盘驱动发送一个VK_OFF给GWES。最终导致函数GwesPowerOffSystem 被调用;
2 OEM层直接调用GwesPowerOffSystem;
3 OEM层直接调用SetSystemPowerState.


The GwesPowerOff function performs key operations before a device can suspend.

To suspend a device

Notify the Taskbar that the device is being suspended.
Post the WM_POWERBROADCAST message with the flag PBT_APMSUSPEND. Only the registered Taskbar will get this message.

Abort calibration if the calibration screen is up and in one of the following states:
Waiting at cross hairs.
If calibration was waiting at confirmation.
Turn off window message queues, stopping the processing of messages.
Determine if the Startup UI screen needs to appear on resume.
Save video RAM to system RAM is necessary to preserve state on resume.
Call SetSystemPowerState with the arguments (NULL, POWER_STATE_SUSPEND, POWER_FORCE). This calls into the power manager that coordinates the rest of the suspend operation. At this point, GwesPowerOff is not completed until the system resumes.
Power manager performs the following actions:
Calls FileSystemPowerFunction(FSNOTIFY_POWER_OFF) to power off file system drivers.
Calls PowerOffSystem.
Calls Sleep(0) to allow the kernel scheduler to run and perform the final suspend process.
The kernel performs the following final steps to suspend:
Power off GWES process.
Power off Filesys.exe.
If this is an SHx microprocessor, call OEMFlushCache.
Call OEMPowerOff.


=======================================================
When a resume occurs the kernel is the first to execute. A device will only resume from a halted state if an interrupt occurs and the CPU has been programmed to wake when an interrupt occurs.

To resume a device

The kernel performs the following clean-up tasks before resuming normal scheduling:
If this is an SHx, it calls OEMFlushCache.
Calls InitClock to re-initialize timer hardware to a 1 ms tick.
Calls Filesys.exe with a power on notification.
Calls GWES with a power on notification.
Initializes the KITL interrupt if one is in use.
Power manager then calls FileSystemPowerFunction with the (FSNOTIFY_POWER_ON) argument.
On the resume, GWES performs the following tasks:
Restores video memory from RAM.
Powers on the Window Manager.
Sets the screen contrast.
Shows the Startup UI screen, if required.
Posts a message to the Taskbar to tell it the device has resumed by send a WM_POWERBROADCAST message with PBT_APMRESUMESUSPEND parameter.
Sends the same message to the User notification subsystem.
Triggers applications that have requested to be triggered on resume.


 USB Function Driver
        也是分为Function Controller和Function Client Driver.
        从USB SPEC 2.0上看,Function属于Device的最上层。

Boot-time Initialization

The following steps show the boot-time initialization process:

  1. The OS locates the function controller, and then loads the function controller driver by loading the dynamic-link library (DLL) that contains the PDD and the MDD.
  2. The DllMain function in the PDD calls DllEntry in the MDD.
  3. The OS activates the stream interface that the MDD contains by calling UFN_Init.
  4. UFN_Init calls into the PDD to initialize the hardware.
  5. UFN_Init determines the client driver to load, and then calls the client driver's initialization routine.

The hardware initialization function carries out its responsibilities in the following order:

  1. Initializes the function controller on its bus.
  2. Places the function controller in the initialized state because the configuration might persist after a soft reset.
  3. Disables the USB connection.
  4. Disables device and endpoint interrupts.
  5. Clears pending device and endpoint interrupts.
  6. Clears configuration registers and the first in, first out (FIFO) buffer.
  7. Resets any internal data structures.