-
Notifications
You must be signed in to change notification settings - Fork 13
FAT file system
INGA is equipped both 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 contiki cfs-interface and are prefixed with cfs_
.
FAT implementation specific functions are prefixed cfs_fat_
.
To enable FAT you must specify
CFS=fat
in your projects Makefile
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();
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);
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);
You can use cfs_seek()
to get the file size with only using the Contiki interface
int fd = cfs_open(name, CFS_READ);
uint32_t file_size = cfs_seek(fd, 0, CFS_SEEK_END) + 1;
Or you use the cfs_fat
specific function cfs_fat_file_size()
#include "cfs-fat.h"
uint32_t file_size = cfs_fat_file_size(int fd)
To get the date/time of creation use
uint16_t cfs_fat_get_create_date(int fd);
uint16_t cfs_fat_get_create_time(int fd);
To get the date/time of last modification use
uint16_t cfs_fat_get_last_date(int fd);
uint16_t cfs_fat_get_last_time(int fd);