// ================================================ ========================================
// Title:
// Software for soft switch design
// Author:
// Norains
// Date:
// Sunday 19-might-2009
// Environment:
// The Windows CE 5.0
// ================================================ ========================================
Compared with hardware, software code of soft switch is simpler. You only need to check the detect_key. This function is implemented mainly through gpio, while wince does not define the upper layer of gpio, And the gpio operations of each CPU are different, therefore, this article cannot provide a complete and available code, and can only be explained using pseudo code as an example. Although it is a pseudo-code, it is of some significance to understand its process.
Void power_on ()
{
...
// Set gpio_shdn to high
Setgpio_high (gpio_shdn );
...
}
DWORD pwr_intrthread (pvoid pparam)
{
....
// Enable interruption
Enableinterrupt ();
// Initialization interruption
Interruptinitialize (btnsysintr, hpolicyevent, 0, 0)
While (true)
{
// Wait for the interruption event
Dwret = waitforsingleobject (hpolicyevent, infinite );
If (dwret = wait_object_0)
{
// After the interrupt processing is completed, let the interrupt be processed again
Interruptdone (btnsysintr );
// Wait for the interrupted handling event again
Dwret = waitforsingleobject (hpolicyevent, 1000 );
If (dwret = wait_timeout)
{
// When the bit wait_timeout is used, it means to press long and enter the poweroff function.
Enterpoweroff ();
}
}
}
....
}
Void enterpoweroff ()
{
...
While (true)
{
If (isgpiohigh (gpio_detect_key )! = False)
{
// S1 has been released and jumps out of the loop
Break;
}
}
// Turn off the system power
Setgpio_low (gpio_shdn );
...
}
The only thing to note here is the enterpoweroff function. You must check whether S1 has been released. If the gpio_shdn is not released yet, the gpio_shdn is set to low. Because the S1 end has a vdd33d voltage input to the pwr_on end, the system still cannot be closed.