Re: alarm() - what am I doing wrong???



On Mon, 22 May 2006 18:10:05 +0000, Jan Panteltje wrote:

On a sunny day (Mon, 22 May 2006 17:39:35 GMT) it happened Charles Sullivan
<cwsulliv@xxxxxxxxxxxx> wrote in
<pan.2006.05.22.17.39.34.902403@xxxxxxxxxxxx>:

On Mon, 22 May 2006 09:44:37 +0000, Jan Panteltje wrote:

Cannot you use alarm_isr() to increment a variable each second,
and set a flag for main if it reaches 5?

Then have main set a flag that resets the counter in alarm_isr()
before it reaches 5 if data comes in?

Then when mai nsees the flag that 5 is reached (in your main loop),
it should do something.
?

If I'm using alarm() to count seconds, then the read() would only
be able to check for incoming data every second, no? I think I'd
lose a lot of data that way.

Not sure, maybe I undestand you wrong.
You read loop (using poll() or select(), or whatever, would run continously.
But the alrm servuice routine would only be called once a second, and
retrigger *itself*.
Normal 'clock'

static elapsed_seconds;


main()
{
// init

while(1)
{
//read input status
// if something do whatever, reset elapsed_seconds.
// else

if elapsed_seconds > 5)
{
scream TIME!!!!!

elapsed_second = 0;
}
}

// add alarm signal handler one_second_tick
alarm(1);



}


void one_second_tick()
{
elapsed_seconds++;

// re-trigger self
alarm(1);
}

Jan.
The process just stays in that 'while' loop forever, waiting
for data.

The problem is that the data tends to come in bursts lasting
between 1 and perhaps 30 seconds each, maybe separated by
one or two seconds, then there are typically relatively long
periods of inactivity.

The data has to be processed immediately when it arrives
(there may or may not be some software handshaking with the
appliance I haven't shown, between the arrival of the first
byte and the reading of subsequent bytes.)

There are some housekeeping activities which need to be
attended to, but they can be deferred until it looks like
there's a quiet period as evidenced by about 5 seconds of no
activity.

The read() is blocking, so with your scheme I wouldn't know
the elapsed_seconds until some data actually arrives, but
even after processing the data I couldn't be sure it won't
be followed shortly thereafter by more data.

I've found a solution which works, however crudely. See
my response to Nils' comments.

Thanks for having taken the time to ponder my query and make
your suggestion.

Regards,
Charles Sullivan




.



Relevant Pages

  • Re: alarm() - what am I doing wrong???
    ... Then have main set a flag that resets the counter in alarm_isr ... You read loop or select, or whatever, would run continously. ... retrigger *itself*. ...
    (comp.os.linux.development.apps)
  • df -kP != df -Pk
    ... It seems that -P flag to df resets previously specified -k for no good ... reason. ... Andriy Gapon ...
    (freebsd-stable)
  • Re: alarm() - what am I doing wrong???
    ... Then have main set a flag that resets the counter in alarm_isr ... If I'm using alarm() to count seconds, ... be able to check for incoming data every second, ...
    (comp.os.linux.development.apps)
  • Re: Any raw data specs for the Apple IIgs BRAM?
    ... original set of example data with the original assembly code and with ... the AppleScript, and they don't match. ... ' current value of the carry flag and then change the carry flag ... ' end of the loop ...
    (comp.sys.apple2.programmer)
  • Re: semi-timely interrupt
    ... check the flag on every RTS, LOOP, BREAK instruction. ... want to insinuate an interrupt flag check into RTS, LOOP, and BREAK ...
    (comp.programming.threads)