Power Button Control!!
-
- Member
- Posts: 63
- Joined: Sat Apr 28, 2012 9:41 am
- Location: Earth -> Asia
Power Button Control!!
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.
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.
Anyone has a idea of making a ntfs bootsector?if yes PM me , plz.
Re: Power Button Control!!
http://forum.osdev.org/viewtopic.php?f= ... hilit=ACPIGot a question? Search this first!
> 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.
Last edited by Nable on Sat May 12, 2012 8:57 am, edited 1 time in total.
Re: Power Button Control!!
For machine with battery, detect the unplug with ACPI, but unplug the power do not mean to shutdown however.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 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.
Last edited by bluemoon on Sat May 12, 2012 9:05 am, edited 1 time in total.
-
- Member
- Posts: 63
- Joined: Sat Apr 28, 2012 9:41 am
- Location: Earth -> Asia
Re: Power Button Control!!
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?
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?
Anyone has a idea of making a ntfs bootsector?if yes PM me , plz.
Re: Power Button Control!!
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.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Re: Power Button Control!!
Provided there is a disk.neon wrote:Different architectures may differ here, though, so storing the data on the system disk is probably also the most portable.
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!!
why not UPS and/or redundant power supply? some critical server already used this method.
Re: Power Button Control!!
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.bluemoon wrote:why not UPS and/or redundant power supply? some critical server already used this method.
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.
-
- Member
- Posts: 141
- Joined: Thu Jun 17, 2010 2:36 am
Re: Power Button Control!!
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.rdos wrote:Provided there is a disk.neon wrote:Different architectures may differ here, though, so storing the data on the system disk is probably also the most portable.
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.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Power Button Control!!
An electrolytic capacitor functions as a rechargeable battery.Rudster816 wrote:You wouldn't want a capacitor, you'd wan't a battery.
-
- Member
- Posts: 141
- Joined: Thu Jun 17, 2010 2:36 am
Re: Power Button Control!!
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.Combuster wrote:An electrolytic capacitor functions as a rechargeable battery.Rudster816 wrote:You wouldn't want a capacitor, you'd wan't a battery.
Re: Power Button Control!!
How do you switch from mains power to battery power quickly enough to not lose your Vcc ?Rudster816 wrote: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.Combuster wrote:An electrolytic capacitor functions as a rechargeable battery.Rudster816 wrote:You wouldn't want a capacitor, you'd wan't a battery.
If a trainstation is where trains stop, what is a workstation ?
-
- Member
- Posts: 63
- Joined: Sat Apr 28, 2012 9:41 am
- Location: Earth -> Asia
Re: Power Button Control!!
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.
Anyone has a idea of making a ntfs bootsector?if yes PM me , plz.
Re: Power Button Control!!
How can you say they discharge quickly ? The rate of discharge depends on many thing. Which formula did you use ?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.
If a trainstation is where trains stop, what is a workstation ?
Re: Power Button Control!!
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.
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.