Power Button Control!!

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
LindusSystem
Member
Member
Posts: 63
Joined: Sat Apr 28, 2012 9:41 am
Location: Earth -> Asia

Power Button Control!!

Post 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.
Anyone has a idea of making a ntfs bootsector?if yes PM me , plz.
Nable
Member
Member
Posts: 453
Joined: Tue Nov 08, 2011 11:35 am

Re: Power Button Control!!

Post 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.
Last edited by Nable on Sat May 12, 2012 8:57 am, edited 1 time in total.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Power Button Control!!

Post 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.
Last edited by bluemoon on Sat May 12, 2012 9:05 am, edited 1 time in total.
LindusSystem
Member
Member
Posts: 63
Joined: Sat Apr 28, 2012 9:41 am
Location: Earth -> Asia

Re: Power Button Control!!

Post 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?
Anyone has a idea of making a ntfs bootsector?if yes PM me , plz.
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Power Button Control!!

Post 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.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
rdos
Member
Member
Posts: 3307
Joined: Wed Oct 01, 2008 1:55 pm

Re: Power Button Control!!

Post 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.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Power Button Control!!

Post by bluemoon »

why not UPS and/or redundant power supply? some critical server already used this method.
rdos
Member
Member
Posts: 3307
Joined: Wed Oct 01, 2008 1:55 pm

Re: Power Button Control!!

Post 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.
Rudster816
Member
Member
Posts: 141
Joined: Thu Jun 17, 2010 2:36 am

Re: Power Button Control!!

Post 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.
User avatar
Combuster
Member
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!!

Post by Combuster »

Rudster816 wrote:You wouldn't want a capacitor, you'd wan't a battery.
An electrolytic capacitor functions as a rechargeable battery.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Rudster816
Member
Member
Posts: 141
Joined: Thu Jun 17, 2010 2:36 am

Re: Power Button Control!!

Post 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.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Power Button Control!!

Post 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 ?
If a trainstation is where trains stop, what is a workstation ?
LindusSystem
Member
Member
Posts: 63
Joined: Sat Apr 28, 2012 9:41 am
Location: Earth -> Asia

Re: Power Button Control!!

Post 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.
Anyone has a idea of making a ntfs bootsector?if yes PM me , plz.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Power Button Control!!

Post 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 ?
If a trainstation is where trains stop, what is a workstation ?
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Power Button Control!!

Post 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.
Post Reply