Document number
205065
Version
Rev. N
Issue date
2019-02-04
Sirius OBC and TCM User Manual
Page
28
of
174
Inclusion of
<fcntl.h>
and <unistd.h>
are required for using the POSIX functions
open
,
close
,
lseek
,
read
and
write
.
Inclusion of
<errno.h>
is required for retrieving error values on failures.
Inclusion of <
bsp/wdt_rtems.h>
is required for accessing watchdog device name
RTEMS_WATCHDOG_DEVICE_NAME.
CONFIGURE_APPLICATION_NEEDS_WDT_DRIVER
must be defined for using the watchdog
driver. By defining this as part of the RTEMS configuration, the driver will automatically be
initialised at boot up.
If the application is run directly via GDB (not via the bootrom),
CONFIGURE_APPLICATION_NEEDS_ERROR_MANAGER_DRIVER
must be defined in order
to initialise the error manager and enable board reset on watchdog timeout.
#include <bsp.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <bsp/wdt_rtems.h>
#define CONFIGURE_APPLICATION_NEEDS_WDT_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_MAXIMUM_DRIVERS
#define CONFIGURE_MAXIMUM_TASKS 2 /* Idle & Init */
#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 1
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
#define CONFIGURE_INIT
#include <bsp/bsp_confdefs.h>
#include <rtems/confdefs.h>
rtems_task Init (rtems_task_argument ignored)
{
int fd = open(RTEMS_WATCHDOG_DEVICE_NAME, O_WRONLY);
ioctl(fd, WATCHDOG_ENABLE_IOCTL, WATCHDOG_DISABLE);
ioctl(fd, WATCHDOG_SET_TIMEOUT_IOCTL, 10);
ioctl(fd, WATCHDOG_ENABLE_IOCTL, WATCHDOG_ENABLE);
while (1) {
sleep(9);
const unsigned char payload = WATCHDOG_KICK;
write(fd, &payload, sizeof(payload));
}
}