Document number
205065
Version
Rev. N
Issue date
2019-02-04
Sirius OBC and TCM User Manual
Page
77
of
174
Inclusion of
<fcntl.h>
and <unistd.h>
are required for using the POSIX functions:
open
,
close, read, write and ioctl
.
Inclusion of
<errno.h>
is required for retrieving error values on failures.
Inclusion of <
bsp/gpio_rtems.h>
is required for accessing the GPIO.
5.8.4. Limitations
Differential mode works on output only.
#include <bsp.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <bsp/gpio_rtems.h>
#define CONFIGURE_APPLICATION_NEEDS_GPIO_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
#define CONFIGURE_MAXIMUM_DRIVERS 15
#define CONFIGURE_MAXIMUM_SEMAPHORES 20
#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 30
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
#define CONFIGURE_MAXIMUM_TASKS 20
#define CONFIGURE_INIT
#include <bsp/bsp_confdefs.h>
#include <rtems/confdefs.h>
rtems_task Init (rtems_task_argument argument) {
rtems_status_code status;
int gpio_fd;
uint32_t buffer;
uint32_t config;
ssize_t size;
gpio_fd = open("/dev/gpio0", O_RDWR);
config = GPIO_DIRECTION_IN;
status = ioctl(gpio_fd, GPIO_IOCTL_SET_DIRECTION,
&config);
size = read(gpio_fd, &buffer, 1);
status = close(gpio_fd);
}