Document number
204911
Version
Rev. K
Issue date
2016-10-11
Sirius Breadboard User Manual
www.aacmicrotec.com
Page
75
of
106
5.12.3. Usage description
The following #define needs to be set by the user application to be able to use the SPI RAM:
CONFIGURE_APPLICATION_NEEDS_SPI_RAM_DRIVER
5.12.3.1. RTEMS application example
In order to use the SPI RAM 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/spi_ram_rtems.h>
is required for accessing the SPI_RAM.
#include <bsp.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <bsp/spi_ram_rtems.h>
#define CONFIGURE_APPLICATION_NEEDS_SPI_RAM_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 dsc;
uint8_t buf[8];
ssize_t cnt;
off_t offset;
dsc = open(SPI_RAM_DEVICE_NAME, O_RDWR);
offset = lseek(dsc, 0x200, SEEK_SET);
cnt = write(dsc, &buf[0], sizeof(buf));
offset = lseek(dsc, 0x200, SEEK_SET);
cnt = read(dsc, &buf[0], sizeof(buf));
status = close(dsc);
}