Page 1 of 2
Power Button Control!!
Posted: Sat May 12, 2012 8:41 am
by LindusSystem
How do I come to know if the power button was pressed by the user?
I would like to execute a few commands before the computer shuts down(Even by a power cutoff,or forcing by removing the plug,etc)so that I can display a error screen next time when the user boots up.Or is there any other way for what I am trying to make.
Re: Power Button Control!!
Posted: Sat May 12, 2012 8:54 am
by Nable
Got a question? Search this first!
http://forum.osdev.org/viewtopic.php?f= ... hilit=ACPI
> Even by a power cutoff, or forcing by removing the plug, etc
No, these events cannot be properly intercepted.
Real world OSes determine incorrect shutdown by checking some flags (e.g. FS-was-mounted) that are set at startup and cleared only at the end of correct shutdown sequence.
Re: Power Button Control!!
Posted: Sat May 12, 2012 8:57 am
by bluemoon
LindusSystem wrote:I would like to execute a few commands before the computer shuts down(Even by a power cutoff,or forcing by removing the plug,etc)
For machine with battery, detect the unplug with ACPI, but unplug the power do not mean to shutdown however.
For machine without battery, a power cutoff,or forcing by removing the plug,etc will make the machine go off instantly unless you have UPS or multiple power supplies. If there is other mean of power supply(eg redundancy power input found on server machines) , you may detect such unplug with ACPI if the board ever report such event, and like the above, this does not mean a shutdown.
Re: Power Button Control!!
Posted: Sat May 12, 2012 9:04 am
by LindusSystem
Ok ,thanks.
This might do it fo right?
A system variable that is set to 1 during boot and changed to 0 during a normal shutdown.So the next time I boot I will check for the variable if it is set to 0 or not.if 1 an erro screen welcome them.
Excatly what I am trying is to do it like the Windows, it shows an menu with options (start normally or safe mode,etc when a direct shutdown or whatever takes place).I just wanted to know how can look if the computer underwent a normal shutdown or not.
OK? Or any builtin CPU flag or stuff for that?
Re: Power Button Control!!
Posted: Sat May 12, 2012 11:40 am
by neon
What you described is fine and iirc is also what Windows does (it stores the flag in the system registry hive). I am unaware of any hardware flag; after all if power has been completely removed the only way such flag can be set would be with an EEPROM. Different architectures may differ here, though, so storing the data on the system disk is probably also the most portable.
Re: Power Button Control!!
Posted: Sun May 13, 2012 2:04 am
by rdos
neon wrote:Different architectures may differ here, though, so storing the data on the system disk is probably also the most portable.
Provided there is a disk.
Personally, I haven't implemented this feature as I think the OS should be able to handle sudden power failures. And in an embedded environment, asking the user about boot method after a power-failure is a big NO. There is no user to do the selection. It would be similar to asking the user to reboot because the OS is out of memory or something. The OS should never interfere with the operation of the embedded application, regardless if it is during boot or operation.
What I have designed into the concept is a PCB that detects power failure, and a large capacitor that can keep the CPU alive a few seconds. This will eventually be used to flush disk buffers, and disallow further disk modifications. That is the right way to do it, but no standard PCs come with this feature AFAIK.
Re: Power Button Control!!
Posted: Sun May 13, 2012 4:06 am
by bluemoon
why not UPS and/or redundant power supply? some critical server already used this method.
Re: Power Button Control!!
Posted: Sun May 13, 2012 6:08 am
by rdos
bluemoon wrote:why not UPS and/or redundant power supply? some critical server already used this method.
We've used several methods in the past. The first generation terminals used a lead-battery backup. The problem with that solution is that when the battery stops working, it draws down the power supply so then the terminal often also malfunctions even in the presence of power. The next generation used a battery backed up RAM. It has no obvious drawbacks, but that solution is really not applicable to PC-based terminals.
The primary issue is to keep the filesystem consistent. There is really no need to keep the power up, as dispensers will not work witout power anyway. In the first generation the display simply says "Power failure", which is not much better than a blank display.
Re: Power Button Control!!
Posted: Sun May 13, 2012 2:56 pm
by Rudster816
rdos wrote:neon wrote:Different architectures may differ here, though, so storing the data on the system disk is probably also the most portable.
Provided there is a disk.
Personally, I haven't implemented this feature as I think the OS should be able to handle sudden power failures. And in an embedded environment, asking the user about boot method after a power-failure is a big NO. There is no user to do the selection. It would be similar to asking the user to reboot because the OS is out of memory or something. The OS should never interfere with the operation of the embedded application, regardless if it is during boot or operation.
What I have designed into the concept is a PCB that detects power failure, and a large capacitor that can keep the CPU alive a few seconds. This will eventually be used to flush disk buffers, and disallow further disk modifications. That is the right way to do it, but no standard PCs come with this feature AFAIK.
You wouldn't want a capacitor, you'd wan't a battery. A journaling filesystem provides enough data protection against power failure for almost all applications. Even with a battery, you'd still need a journaling filesystem for a system critical application.
Re: Power Button Control!!
Posted: Sun May 13, 2012 3:03 pm
by Combuster
Rudster816 wrote:You wouldn't want a capacitor, you'd wan't a battery.
An electrolytic capacitor functions as a rechargeable battery.
Re: Power Button Control!!
Posted: Sun May 13, 2012 3:46 pm
by Rudster816
Combuster wrote:Rudster816 wrote:You wouldn't want a capacitor, you'd wan't a battery.
An electrolytic capacitor functions as a rechargeable battery.
But there are some fundamental differences that make a battery much more suitable in this situation. I'll let
this guy explain them. You would need a fairly good size capacitor to output enough power at a steady voltage, which would probably cost more than a button battery that could last for several minutes compared to seconds for the capacitor.
Re: Power Button Control!!
Posted: Sun May 13, 2012 3:51 pm
by gerryg400
Rudster816 wrote:Combuster wrote:Rudster816 wrote:You wouldn't want a capacitor, you'd wan't a battery.
An electrolytic capacitor functions as a rechargeable battery.
But there are some fundamental differences that make a battery much more suitable in this situation. I'll let
this guy explain them. You would need a fairly good size capacitor to output enough power at a steady voltage, which would probably cost more than a button battery that could last for several minutes compared to seconds for the capacitor.
How do you switch from mains power to battery power quickly enough to not lose your Vcc ?
Re: Power Button Control!!
Posted: Sun May 13, 2012 9:07 pm
by LindusSystem
You cannot use Capacitors , they discharge quickly.The best idea would be for developers(I mean Hardware Developers, not us ,programmers) is to integrate something into CMOS Chip that will tells about the power failure as it is 24hrs powered by the battery.
Re: Power Button Control!!
Posted: Sun May 13, 2012 9:16 pm
by gerryg400
LindusSystem wrote:You cannot use Capacitors , they discharge quickly.The best idea would be for developers(I mean Hardware Developers, not us ,programmers) is to integrate something into CMOS Chip that will tells about the power failure as it is 24hrs powered by the battery.
How can you say they discharge quickly ? The rate of discharge depends on many thing. Which formula did you use ?
Re: Power Button Control!!
Posted: Sun May 13, 2012 9:26 pm
by bluemoon
So what's wrong with
http://en.wikipedia.org/wiki/Uninterrup ... wer_supply?
Some UPS can tell you on power failure by Ethernet or usb. And I think it's more than enough to have USP + 2 power inputs(dual transformer) to cover problems from power outage or one transformer fault. Taking it further you would do redundancy in machines or storage systems instead.