NAND Flash File Server - nandfsys
#include <fsysinit.h>
#include <device.h>
#include <fsys.h>
#include <nand_flash.h>
struct fsysinit {
uint_16 fsi_msgsize;
uint_16 fsi_nclones; /* Number of servers to create. */
uint_32 fsi_datalog; /* datlog bit definition */
uint_16 fsi_nbuffers; /* Number of buffers in buffer cache, minimum 2*/
uint_16 fsi_blocksize; /* Memory block size: 256 for NAND Flash, 512 for sd/mmc-card */
uint_16 fsi_maxopen; /* Max number of open files */
uint_16 fsi_ndrives; /* Maximum number of allocated disks, valid for FATFS only*/
};
The NAND Flash file server - fsys is Linux compatible file system with NAND Flash . File can use RAM disc or SD card or equivalent or NAND flash depending of low level driver implementation specified in demo application. The files are devstrad.c, nand_flash.c and nand_flash.h (see example below)
Nandfsys supports the following operations:
Typical operation for the file server involves several steps common in various operating system environments including Linux. There is no difference with the various media choices.
Create a file server first so that commands can be carried out for the selected media. Use pthread_create to do this.
Register the file server so that it can be found as a server in the system.
Make a file system using mkfs. This creates a root directory structure on the media (formatting media, all content will be deleted).
Mount the file system. Note that an extra directory or a root directory is specified in addition to the registered file server name.
The file system is now ready to use with the remaining file system commands.
Compile Options
The following compile options are for the Nand Flash File Server. The driver has the second set of options.
NAND Driver Options setup in devstrad
Run Time Options
Initialization Options
Open Options
IOCTL Options for NAND Flash
For more details, see functions description in I/O Library.
In case of successful start up pthread_create will return 0 value.
In case of any errors during operation with fsys system set errno to the corresponding POSIX compatible error code.
struct fsysinit {
uint_16 fsi_msgsize;
uint_16 fsi_nclones; /* Number of servers to create. */
uint_32 fsi_datalog; /* datlog bit definition */
uint_16 fsi_nbuffers; /* Number of buffers in buffer cache, minimum 2*/
uint_16 fsi_blocksize; /* Memory block size: 256 for NAND Flash, 512 for sd/mmc-card */
uint_16 fsi_maxopen; /* Max number of open files */
uint_16 fsi_ndrives; /* Maximum number of allocated disks, valid for FATFS only*/
};
...
/*
* FSYS Initialization
*/
/* create the File server and mount the ram disk */
fsysinit.fsi_msgsize = sizeof(struct fsysinit);
fsysinit.fsi_nclones = 1;
fsysinit.fsi_datalog = 0x3;
fsysinit.fsi_nbuffers = 4; /* num of disk buffers (cache size) */
fsysinit.fsi_maxopen = 2; /* max num of open files */
fsysinit.fsi_blocksize = PAGE_DATA_SIZE;
// set up stack size and priority for main fsys threads and all clones
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, FSYSSTACKSIZE);
myNewFsysPriority.sched_priority = FSYSPRIO;
pthread_attr_setschedparam(&attr, &myNewFsysPriority);
if(!pthread_create(&tid, &attr, (void*(*)(void*))_nand_file_server, (char*)&fsysinit))
{
if(!dir_register(FSYS_DIRECTORY, tid, TYPE_SERVER))
{
xprintf("..Unable to register name of Nand File Server..\n");
xprintf("..Required resource not present - aborting..\n");
#if RTOS_DEBUG
dir_deregister("Main thread");
#endif
pthread_exit((void*)1);
}
}
else
{
xprintf("..Unable to create File Server..\n");
xprintf("..Required resource for program not present - aborting..\n");
#if RTOS_DEBUG
dir_deregister("Main thread");
#endif
pthread_exit((void*)1);
}
xprintf(".. Nand Fsys File server is now created..\n");
xprintf("..Attempting to mkfs and mount it...\n");
// parameters found in main.h
mkfs_status = mkfs(FSYS_DIRECTORY, NAND_DEVICE_NO, 0, NAND_DISK_MAX_FILES);
if(mkfs_status == -1)
{
xprintf("..Unable to make a file system. errno=%d\n", errno);
xprintf("..Please fix me\n");
#if RTOS_DEBUG
dir_deregister("Main thread");
#endif
pthread_exit((void*)1);
}
// must mount a directory for each mount point, here d1,
// unique name for each
if((mount_status = mount(NAND_DEVICE_NO, FSYS_MOUNT, 0)) == -1)
{
xprintf("..Unable to mount nand flash disk. errno=%d\n", errno);
xprintf("..Please fix me\n");
#if RTOS_DEBUG
dir_deregister("Main thread");
#endif
pthread_exit((void*)1);
}
...
File devstrad.c content
...
******** NAND FLASH usage *********
struct bdevsw bdevsw[] = {
{(int(*)(udev_t,int,int,char*,int))nodev, nodev, nodev,(int(*)(udev_t,char,void*))nodev, 0}, /* zero is an invalid dev num */
{disk_strategy, disk_open, disk_close,disk_ioctl,0}
};
...
int disk_open(udev_t dev) - will initialize the NAND flash driver
int disk_close(udev_t dev) - will close the NAND flash driver.
int disk_strategy(udev_t dev, int_32 off, int len, char *buf, int rwflag)- this routine is used to read/write data from/to the NAND flash disk
int disk_ioctl(udev_t dev, char ctrl, void *buff)- this routine is used to control NAND flash parameters and spare page operations for the NAND flash disk
See demo examples for more details
chmod(), close(), lseek(),mkdir(), mkfs(), mount(), open(), read(), stat(), write(), fatfs