Browse Source

Add support for DMA memory allocator to FAT file system

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@5127 7fd9a85b-ad96-42d3-883c-3090e2eb8679
sbg
patacongo 13 years ago
parent
commit
648420e67a
  1. 10
      apps/netutils/webserver/Kconfig
  2. 6
      nuttx/ChangeLog
  3. 19
      nuttx/fs/fat/Kconfig
  4. 7
      nuttx/fs/fat/fs_fat32.c
  5. 28
      nuttx/fs/fat/fs_fat32.h
  6. 4
      nuttx/fs/fat/fs_fat32util.c
  7. 30
      nuttx/include/nuttx/fs/fat.h

10
apps/netutils/webserver/Kconfig

@ -72,7 +72,8 @@ config NETUTILS_HTTPD_MMAP @@ -72,7 +72,8 @@ config NETUTILS_HTTPD_MMAP
selected, then files can be accessed from the NuttX file system
as well. This selection will map the files into memory (using mmap)
so that the logic is still basically compatible with the classic
approach.
approach. NOTE, however, that since files are copied into memory,
this limits solution to small files that will fit into available RAM.
config NETUTILS_HTTPD_MMAP
bool "sendfile()"
@ -83,10 +84,9 @@ config NETUTILS_HTTPD_MMAP @@ -83,10 +84,9 @@ config NETUTILS_HTTPD_MMAP
However, extensions have been contributed. If this option is
selected, then files can be accessed from the NuttX file system
as well. This selection will use the NuttX sendfile() interface
to send files. NOTE: if this option is selected, then scripting
must be disabled.
to send files. NOTE: If this option is selected, then scripting
must be disabled since it depends on the classic, in-memory
representation.
endchoice
endif

6
nuttx/ChangeLog

@ -3309,4 +3309,10 @@ @@ -3309,4 +3309,10 @@
by Kate).
* arch/avr/src: Fixes from AVR32 build errors that have crept in
over the time; incorporated Kconfig for AVR3 (Richard Cochran).
* fs/fat and include/nuttx/fs/fat.h: The FAT file system allocates
memory for sector I/O buffers used to exchange data with the
configured block driver. In some contexts, the block driver may
require DMA-capable memory. If CONFIG_FAT_DMAMEMORY is defined,
then the FAT FS will use platform-provided DMA memory allocators
to allocate the block driver I/O buffers.

19
nuttx/fs/fat/Kconfig

@ -41,9 +41,26 @@ config FAT_MAXFNAME @@ -41,9 +41,26 @@ config FAT_MAXFNAME
config FS_FATTIME
bool "FAT timestamps"
default n
---help---
---help---
Support FAT date and time. NOTE: There is not
much sense in supporting FAT date and time unless you have a
hardware RTC or other way to get the time and date.
config FAT_DMAMEMORY
bool "DMA memory allocator"
default n
---help---
The FAT file system allocates two I/O buffers for data transfer, each
are the size of one device sector. One of the buffers is allocated
once for each FAT volume that is mounted; the other buffers are
allocated each time a FAT file is opened.
Some hardware, however, may require special DMA-capable memory in
order to perform the the transfers. If FAT_DMAMEMORY is defined
then the architecture-specific hardware must provide the funtions
fat_dma_alloc() and fat_dma_free(): fat_dmalloc() will allocate
DMA-capable memory of the specified size; fat_dmafree() is the
corresponding function that will be called to free the DMA-capable
memory.
endif

7
nuttx/fs/fat/fs_fat32.c

@ -302,7 +302,7 @@ static int fat_open(FAR struct file *filep, const char *relpath, @@ -302,7 +302,7 @@ static int fat_open(FAR struct file *filep, const char *relpath,
/* Create a file buffer to support partial sector accesses */
ff->ff_buffer = (uint8_t*)kmalloc(fs->fs_hwsectorsize);
ff->ff_buffer = (uint8_t*)fat_io_alloc(fs->fs_hwsectorsize);
if (!ff->ff_buffer)
{
ret = -ENOMEM;
@ -405,7 +405,7 @@ static int fat_close(FAR struct file *filep) @@ -405,7 +405,7 @@ static int fat_close(FAR struct file *filep)
if (ff->ff_buffer)
{
kfree(ff->ff_buffer);
fat_io_free(ff->ff_buffer);
}
/* Then free the file structure itself. */
@ -1651,8 +1651,9 @@ static int fat_unbind(void *handle, FAR struct inode **blkdriver) @@ -1651,8 +1651,9 @@ static int fat_unbind(void *handle, FAR struct inode **blkdriver)
if (fs->fs_buffer)
{
kfree(fs->fs_buffer);
fat_io_free(fs->fs_buffer);
}
kfree(fs);
}

28
nuttx/fs/fat/fs_fat32.h

@ -48,6 +48,7 @@ @@ -48,6 +48,7 @@
#include <semaphore.h>
#include <time.h>
#include <nuttx/kmalloc.h>
#include <nuttx/fs/dirent.h>
/****************************************************************************
@ -676,6 +677,33 @@ @@ -676,6 +677,33 @@
#endif
/****************************************************************************
* Name: fat_io_alloc and fat_io_free
*
* Description:
* The FAT file system allocates two I/O buffers for data transfer, each
* are the size of one device sector. One of the buffers is allocated
* once for each FAT volume that is mounted; the other buffers are
* allocated each time a FAT file is opened.
*
* Some hardware, however, may require special DMA-capable memory in
* order to perform the the transfers. If CONFIG_FAT_DMAMEMORY is defined
* then the architecture-specific hardware must provide the funtions
* fat_dma_alloc() and fat_dma_free() as prototyped below: fat_dmalloc()
* will allocate DMA-capable memory of the specified size; fat_dmafree()
* is the corresponding function that will be called to free the DMA-
* capable memory.
*
****************************************************************************/
#ifdef CONFIG_FAT_DMAMEMORY
# define fat_io_alloc(s) fat_dma_alloc(s)
# define fat_io_free(s) fat_dma_free(s)
#else
# define fat_io_alloc(s) kmalloc(s)
# define fat_io_free(s) kfree(s)
#endif
/****************************************************************************
* Public Types
****************************************************************************/

4
nuttx/fs/fat/fs_fat32util.c

@ -542,7 +542,7 @@ int fat_mount(struct fat_mountpt_s *fs, bool writeable) @@ -542,7 +542,7 @@ int fat_mount(struct fat_mountpt_s *fs, bool writeable)
/* Allocate a buffer to hold one hardware sector */
fs->fs_buffer = (uint8_t*)kmalloc(fs->fs_hwsectorsize);
fs->fs_buffer = (uint8_t*)fat_io_alloc(fs->fs_hwsectorsize);
if (!fs->fs_buffer)
{
ret = -ENOMEM;
@ -668,7 +668,7 @@ int fat_mount(struct fat_mountpt_s *fs, bool writeable) @@ -668,7 +668,7 @@ int fat_mount(struct fat_mountpt_s *fs, bool writeable)
return OK;
errout_with_buffer:
kfree(fs->fs_buffer);
fat_io_free(fs->fs_buffer);
fs->fs_buffer = 0;
errout:
fs->fs_mounted = false;

30
nuttx/include/nuttx/fs/fat.h

@ -75,11 +75,39 @@ extern "C" { @@ -75,11 +75,39 @@ extern "C" {
#define EXTERN extern
#endif
/* Non-standard functions to get and set FAT file/directory attributes */
/****************************************************************************
* Name: fat_getattrib and fat_setattrib
*
* Description:
* Non-standard functions to get and set FAT file/directory attributes
*
****************************************************************************/
EXTERN int fat_getattrib(const char *path, fat_attrib_t *attrib);
EXTERN int fat_setattrib(const char *path, fat_attrib_t setbits, fat_attrib_t clearbits);
/****************************************************************************
* Name: fat_dma_alloc and fat_dma_free
*
* Description:
* The FAT file system allocates two I/O buffers for data transfer, each
* are the size of one device sector. One of the buffers is allocated
* once for each FAT volume that is mounted; the other buffers are
* allocated each time a FAT file is opened.
*
* Some hardware, however, may require special DMA-capable memory in
* order to perform the the transfers. If CONFIG_FAT_DMAMEMORY is defined
* then the architecture-specific hardware must provide the funtions
* fat_dma_alloc() and fat_dma_free() as prototyped below: fat_dmalloc()
* will allocate DMA-capable memory of the specified size; fat_dmafree()
* is the corresponding function that will be called to free the DMA-
* capable memory.
*
****************************************************************************/
EXTERN FAR void *fat_dma_alloc(size_t size);
EXTERN void fat_dma_free(FAR void *memory);
#undef EXTERN
#ifdef __cplusplus
}

Loading…
Cancel
Save