Skip to content
ejoerns edited this page Aug 29, 2013 · 9 revisions

contiki-inga comes along with a microSD card reader and an onboard flash module. Both can be used to log sensor data, share configuration data or install encryption keys.

To access the microSD card there is both an SD card interface and a FAT32 library available in contiki-inga.

The driver does not support VFAT thus file names are allowed only in 8.3 format. Accessing subdirectories is supported, creation of subdirectories currently not.

Note: In INGA version 1.4 it is not possible to access both the accelerometer and the SD card interface simultaneously. The microSD card needs to be powered off to be able to read accelerometer measurements.

The basic file manipulation interface is provided by the standard contriki cfs-interface and are prefixed with cfs_. FAT implementation specific functions are prefixed cfs_fat_.

Compile FLAGS

To enable FAT you must specify

CFS=fat

in your projects makefile

Mount / Unmount file system

To be able to access a file system either on microSD card or internal flash the device first needs to be found and mounted correctly.

#include "fat/diskio.h"
#include "fat/cfs-fat.h"

struct diskio_device_info *info = 0;
if (diskio_detect_devices() != DISKIO_SUCCESS) {
  return -1;
}
info = diskio_devices();

for (i = 0; i < DISKIO_MAX_DEVICES; i++) {
  if ((info + i)->type == (DISKIO_DEVICE_TYPE_SD_CARD | DISKIO_DEVICE_TYPE_PARTITION)) {
    info += i;
    break;
  }
}

cfs_fat_mount_device(info);

// Read/write operations ...

cfs_fat_umount_device();

Write to file

int fd;

fd = cfs_open("path/to/file.txt", CFS_WRITE);
if (fd == -1) {
  return -1;
}

cfs_write(fd, buffer, buffer_size);

cfs_close(fd);

Read from file

int fd, n;

fd = cfs_open("path/to/file.txt", CFS_READ);
if (fd == -1) {
  return -1;
}

do {
  n = cfs_read(fd, buffer, buffer_size);
  // use data in buffer...
} while (n == buffer_size);

cfs_close(fd);

Get file information

Size

Creation date/time

Modification date/time

Clone this wiki locally