RetroBSD

2.11BSD operating system for microcontrollers
It is currently Fri Feb 21, 2020 8:36 pm

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Mon Sep 28, 2015 8:44 am 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
Would it be possible to add following functionality into the kernel?
1. a signal from a powerdown detector at PinX (configurable active low or high)
2. when the signal triggers, it starts "halt"

So when the detector sees the power is dropping down, it does shutdown of the system cleanly.
There will be a backup battery to power system during power down, as the "halt" takes about 2-3secs.
P.

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
PostPosted: Mon Sep 28, 2015 9:37 am 
Committer
User avatar

Joined: Thu Oct 11, 2012 8:45 am
Posts: 1801
Location: Room 217, Floor 8, Arm 8, Wheel S7, Mars Base Alpha 3
Why do you need such functionality in the kernel? That's the kind of thing you run as a daemon in userland. Just open the GPIO and watch it. When it changes to your desired state you run the halt command.

There is no need for anything in the kernel...

_________________
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".


Top
 Profile  
 
PostPosted: Mon Sep 28, 2015 3:58 pm 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
So you want watch the power down from userland? How? With app in cron ?? :) :)
It must be in kernel, sure.. It is time critical thing.
Writing daemons is difficult..

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
PostPosted: Mon Sep 28, 2015 6:19 pm 
Committer
User avatar

Joined: Wed Oct 10, 2012 11:01 pm
Posts: 1081
Location: Sunnyvale, CA
Pito wrote:
So you want watch the power down from userland? How? With app in cron ?? :)
Well, it's definitely possible from userland with a daemon. Just poll a signal every second and invoke reboot() when needed. Not a good solution though, as it will result in excessive swapping. Every second this daemon will be swapped in, just to check the signal, and swap out again.

An optimal way would be to have a daemon suspended on a blocking system call like read(), and activated by a change of the hardware signal. We can enhance the gpio driver to do this. An alternative approach is to translate the hardware signal event into a software signal, and handle it much like SIGALRM in the daemon.

Pito wrote:
Writing daemons is difficult..
Writing "hello world" is also difficult, when you do it for the first time. :)
Here is the source of /sbin/update daemon, as an example:
Code:
int main()
{
    daemon(0, 0);
    for (;;) {
        sync();
        sleep(30);
    }
}


Top
 Profile  
 
PostPosted: Mon Sep 28, 2015 9:03 pm 
Committer
User avatar

Joined: Thu Oct 11, 2012 8:45 am
Posts: 1801
Location: Room 217, Floor 8, Arm 8, Wheel S7, Mars Base Alpha 3
The model used by the Linux GPIO is quite a good one.

You have a file per IO (which you have to "export" first) and you can enable interrupt mode. When the value of the input changes the value in its file is changed.

Reading it (blocking) is nice and easy, and here's some code I use on an ARM system to activate a function on a button press:

Code:
    while (1) {
        memset((void *)fdset, 0, sizeof(fdset));
        fdset[0].fd = fd;
        fdset[0].events = POLLPRI;
        rc = poll(fdset, nfds, timeout);
        if (rc < 0) {
            error("Error polling input");
        }

        if (fdset[0].revents & POLLPRI) {
            memset(temp, 0, 100);
            lseek(fd, 0, SEEK_SET);
            read(fd, temp, 100);
            if (isFirstExec == 0) {
                executeCommand();
            } else {
                isFirstExec = 0;
            }
        }
    }

_________________
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".


Top
 Profile  
 
PostPosted: Tue Sep 29, 2015 5:43 am 
Contributor
User avatar

Joined: Thu Nov 08, 2012 7:04 am
Posts: 2401
Location: Rapa Nui
So experts may help :).
I think that functionality is important as switching off the system via console would be nogo with standalone system (I do plan).
Imagine a box with an on/off switch. No console attached. Without that functionality you get a corrupt sdcard filesystem most of the time..

_________________
Pukao Hats Cleaning Services Ltd.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron




Powered by phpBB® Forum Software © phpBB Group

BSD Daemon used with permission