Document number
205065
Version
Rev. N
Issue date
2019-02-04
Sirius OBC and TCM User Manual
Page
44
of
174
#include <bsp.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <assert.h>
#include <bsp/scet_rtems.h>
#define CONFIGURE_APPLICATION_NEEDS_SCET_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 30
#define CONFIGURE_MAXIMUM_DRIVERS 10
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
#define CONFIGURE_MAXIMUM_TASKS 20
#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 20
#define CONFIGURE_INIT
#include <bsp/bsp_confdefs.h>
#include <rtems/confdefs.h>
static const int32_t secs_to_adjust = -10;
static const int16_t subsecs_to_adjust = 1000;
/* Adjust SCET time 10 seconds backwards and 1000
* subseconds forwards */
rtems_task Init (rtems_task_argument ignored)
{
int result;
int scet_fd;
uint32_t old_seconds;
uint16_t old_subseconds;
uint32_t new_seconds;
uint16_t new_subseconds;
uint8_t read_buffer[6];
uint8_t write_buffer[6];
scet_fd = open(RTEMS_SCET_DEVICE_NAME, O_RDWR);
assert(scet_fd >= 0);
result = read(scet_fd, read_buffer, 6);
assert(result == 6);
memcpy(&old_seconds, read_buffer,
sizeof(uint32_t));
memcpy(&old_subseconds, read_
sizeof(uint32_t), sizeof(uint16_t));
printf("\nOld SCET time is %lu.%u\n", old_seconds,
old_subseconds);
printf("Adjusting seconds with %ld, subseconds
with %d\n",
secs_to_adjust, subsecs_to_adjust);
memcpy(write_buffer, &secs_to_adjust,
sizeof(uint32_t));
memcpy(write_ sizeof(uint32_t),
&subsecs_to_adjust, sizeof(uint16_t));
result = write(scet_fd, write_buffer, 6);