Forced sleep, Error handling – Echelon Neuron C User Manual

Page 180

Advertising
background image

168 Additional

Features

Forced Sleep

You can force a device to sleep even though a flush operation is not complete.

Under certain network conditions, such as extreme network congestion, the flush
could take a long time to complete. To avoid consuming too much power, the

application can stop waiting for the flush to complete and sleep anyway.
To force a device to sleep, call the sleep( ) function without waiting for the
flush_completes event. An example of forcing a device to sleep is shown below:

...
flush(TRUE);

// start flush; ignore

// incoming packets

flush_timeout = 300; // start flush timeout

// timer (300 msec)

}

when (timer_expires(flush_timeout))
when (flush_completes)
{ // Ready to go to sleep since the flush

// either completed or timed out

flush_timeout = 0;

// First, turn off timer

// if not expired

sleep(comm_ignore);
}

When you force sleep mode, the following occurs:

1

All pending network variable updates, outstanding application output

buffers, and outstanding network output buffers are not sent and freed.

2

If you specify the comm_ignore option, any incoming network buffers are
freed.

3

If any outstanding incoming application buffers remain, the device fails

to sleep (regardless of whether the COMM_IGNORE option was
specified). This feature prevents the device from receiving stale messages

when it wakes up. In the example above, the application would have 300

milliseconds to process any incoming messages already in the queue. In
addition, since the comm_ignore parameter was set to TRUE in the call to

flush( ), no new incoming messages would arrive. Thus, it is likely that

the device sleeps, assuming it processes, in the 300 msec prior to the
timeout, any incoming messages that were outstanding prior to the call to

flush( ).

Error Handling

You can take one or more of the following actions to recover from or report an
application error:

• Reset the device
• Restart the application
• Take the application offline
• Disable a functional block
• Change functional block status

Advertising