Saturday, July 12, 2014

Pi Power - the rest of the CarPuter solution

A couple of people responded to my Twitter announcement of Pi Power by asking about achieving soft shutdown of an R-Pi when a car's power switch is turned off.

That's not a problem I'm 100% sure I'm prepared to solve, but I'll meet you half-way.

There's two parts of the problem: one is easy, the other is much harder than it sounds.

Detecting power on the accessory bus is easy:


You put 12 volts from the accessory bus on the left connector, and connect the right one to the R-Pi ground and a GPIO pin configured as an input. When the accessory bus shuts off, the pin will go low. Write yourself a little daemon that waits for that pin to go low and executes "shutdown."

And that's the easy part.

The hard part? Actually cycling the power on and off.

The assumption of the above circuit is that the R-Pi itself is powered from the battery bus - that is, it's power that never goes away even when the key is out. You need that, because if you power a *nix computer from a power supply that can just disappear, well, that's not terrific for the filesystem. So that's why we went to all the trouble of the circuit above.

But here's the thing... How do you know when a *nix system is shut down? If you're shutting it down, there's no processes left that can tell an external component that the kernel is all the way dead. You need a kernel process of some sort that will trigger an external event at or near the end of kernel shutdown. How you achieve that in the R-Pi kernel is an unknown to me.

You could guess... You could say, "well, we'll just leave the power on for a minute after shutdown and then just yank it." But how do you know that some rogue process/driver doesn't delay shutdown?

Even if you do solve that problem... What if you start shutting down the processor and the yahoo at the wheel turns the key back on? You've already started shutting down the OS. At the end, it's going to sit there like a rock. You still need to cycle the power - or at least reset the CPU - if the power came *back*.

All of that argues for something really smart - like an ATTiny85 or something like that - to intelligently communicate with the Linux kernel itself to control an external power switch and/or the R-Pi reset line.

That's not to say it can't be done... but it's not something trivial and tiny like Pi Power.


No comments:

Post a Comment