Document number
205065
Version
Rev. N
Issue date
2019-02-04
Sirius OBC and TCM User Manual
Page
64
of
174
In order to use the mass memory flash driver in RTEMS environment with the runtime-
determined size usage mode, the following code structure is suggested to be used:
5.6.4.6. Defines and includes
Inclusion of
<fcntl.h>
and <unistd.h>
are required for using the POSIX functions
open
,
close
,
lseek
,
read
and
write
to access the mass memory bare metal driver.
Inclusion of
<errno.h>
is required for retrieving error values on failures.
Inclusion of <
bsp/massmem_flash_rtems.h>
is required for mass memory flash related
definitions
.
Inclusion of <
bsp/bsp_confdefs.h>
is required to initialise the driver at boot up.
CONFIGURE_APPLICATION_NEEDS_MASSMEM_FLASH_DRIVER
must be defined for using
the mass memory driver. This will automatically initialise the driver at boot up.
#include <bsp.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <bsp/massmem_flash_rtems.h>
#define CONFIGURE_APPLICATION_NEEDS_MASSMEM_FLASH_DRIVER
.
.
#define CONFIGURE_INIT
rtems_task Init (rtems_task_argument argument);
#include <bsp/bsp_confdefs.h>
#include <rtems/confdefs.h>
static uint8_t buf[MASSMEM_PAGE_BYTES_MAX];
rtems_task Init (rtems_task_argument ignored)
{
.
fd = open(MASSMEM_DEVICE_NAME, O_RDWR);
.
s = ioctl(fd, MASSMEM_IO_GET_PAGE_BYTES, &page_bytes)
.
off = lseek(fd, page_number, SEEK_SET);
.
sz = write(fd, buf, page_bytes);
.
off = lseek(fd, page_number, SEEK_SET)
.
sz = read(fd, buf, page_bytes);
.
}