CrossCore XA
Revision: 1.0
Programmers Guide
Date: Jul 1, 10
5.4.
Power signal handling
There are two signals that user applications can use for monitoring status of the power supply
voltage. When either one of them activates, the application should call the power interface to turn
off all unnecessary built-in peripherals, in order to preserve power.
Then program should start writing any modified data to file, close all open files as soon as possible
and exit. As a last action, the program should initiate system shutdown by calling post-
powerfailure. System shutdown will kill all other tasks and remount file systems as read-only.
5.4.1.
Configuring signal handler
Signal handler is registered through /dev/cross_pwr_io – device’s ioctl call
CROSS_IOC_SET_SIGNAL. The handler receives reason for the signal as an argument.
Argument bitfield
Define
Description
POWER_DOWN_SIGNAL
Power down occurred
OVERVOLTAGE_SIGNAL
Overvoltage occurred
It is possible to have only one or both reasons active at the same time, especially in case of
overvoltage.
Example
This example shows a very simple signal handler. All possible errors are not handled, since the
purpose of the example is to explain how the calls are made.
int
fd, result;
set_pwr_signal_struct
pwrsig;
int
pwr_state = 0;
void power_failure_handler(int state)
{
pwr_state = state;
}
pwrsig.pid = getpid();
pwrsig.sig = CROSS_PWR_SIG_INTERFACE;
fd = open(
“/dev/cross_pwr_io”
, O_RDWR | O_NONBLOCK);
/* Register power failure signal handler */
result = ioctl(fd, CROSS_PWR_IOC_SET_SIGNAL, &pwrsig);
/* Wait for signal */
while(!pwr_state) {
sleep(1);
}
if (pwr_state) {
system(“/usr/bin/post-powerfailure”);
}
www.crosscontrol.com
34