mirror of
https://github.com/apache/nuttx.git
synced 2026-05-19 20:06:24 +08:00
Add support for DMA memory allocator to FAT file system
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5127 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
@@ -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.
|
||||
|
||||
|
||||
+18
-1
@@ -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
|
||||
|
||||
+4
-3
@@ -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)
|
||||
|
||||
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)
|
||||
|
||||
if (fs->fs_buffer)
|
||||
{
|
||||
kfree(fs->fs_buffer);
|
||||
fat_io_free(fs->fs_buffer);
|
||||
}
|
||||
|
||||
kfree(fs);
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
#include <semaphore.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/fs/dirent.h>
|
||||
|
||||
/****************************************************************************
|
||||
@@ -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
|
||||
****************************************************************************/
|
||||
|
||||
@@ -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)
|
||||
return OK;
|
||||
|
||||
errout_with_buffer:
|
||||
kfree(fs->fs_buffer);
|
||||
fat_io_free(fs->fs_buffer);
|
||||
fs->fs_buffer = 0;
|
||||
errout:
|
||||
fs->fs_mounted = false;
|
||||
|
||||
+29
-1
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user