Document number
205065
Version
Rev. N
Issue date
2019-02-04
Sirius OBC and TCM User Manual
Page
92
of
174
errno values
RTEMS_NOT_DEFINED Invalid IOCTL
EINVAL
Invalid value supplied to
IOCTL
5.10.3. Usage description
The following #define needs to be set by the user application to be able to use the ADC:
CONFIGURE_APPLICATION_NEEDS_ADC_DRIVER
5.10.3.1. RTEMS application example
In order to use the ADC driver on RTEMS environment, the following code structure is
suggested to be used:
Inclusion of
<fcntl.h>
and <unistd.h>
are required for using the POSIX functions:
open
,
close, ioctl
.
Inclusion of
<errno.h>
is required for retrieving error values on failures.
Inclusion of <
bsp/adc_rtems.h>
is required for accessing the ADC.
#include <bsp.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <bsp/adc_rtems.h>
#define CONFIGURE_APPLICATION_NEEDS_ADC_DRIVER
#include <bsp/bsp_confdefs.h>
#include <rtems/confdefs.h>
#define CONFIGURE_INIT
rtems_task Init (rtems_task_argument argument);
rtems_task Init (rtems_task_argument argument) {
rtems_status_code status;
int read_fd;
uint32_t buffer;
ssize_t size;
read_fd = open(ADC_DEVICE_NAME, O_RDONLY);
status = ioctl(read_fd, ADC_ENABLE_CHANNEL_IOCTL, 4);
size = read(read_fd, &buffer, 4);
status = ioctl(read_fd, ADC_DISABLE_CHANNEL_IOCTL, 4);