]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/pdk.git/commitdiff
fatfs-rtos: add to PDK
authorJacob Stiffler <j-stiffler@ti.com>
Fri, 1 Nov 2019 18:53:54 +0000 (14:53 -0400)
committerJacob Stiffler <j-stiffler@ti.com>
Fri, 1 Nov 2019 18:53:54 +0000 (14:53 -0400)
Development of fatfs-rtos has been relocated here from:
* Repo: https://git.ti.com/keystone-rtos/fatfs
* Branch: master
* Commit ID: b72b4eca86d5aa7e44510f3d7ff6c12822ab59ac

Signed-off-by: Jacob Stiffler <j-stiffler@ti.com>
86 files changed:
packages/ti/fs/fatfs/.gitignore [new file with mode: 0644]
packages/ti/fs/fatfs/FATFS.h [new file with mode: 0644]
packages/ti/fs/fatfs/FATFSver.h [new file with mode: 0644]
packages/ti/fs/fatfs/FATFSver.h.xdt [new file with mode: 0644]
packages/ti/fs/fatfs/Settings.xdc.xdt [new file with mode: 0644]
packages/ti/fs/fatfs/build/buildlib.xs [new file with mode: 0644]
packages/ti/fs/fatfs/build/makefile_indp.mk [new file with mode: 0644]
packages/ti/fs/fatfs/build/makefile_mp_indp.mk [new file with mode: 0644]
packages/ti/fs/fatfs/build/makefile_profile_indp.mk [new file with mode: 0644]
packages/ti/fs/fatfs/config.bld [new file with mode: 0644]
packages/ti/fs/fatfs/config_mk.bld [new file with mode: 0644]
packages/ti/fs/fatfs/diskio.h [new file with mode: 0644]
packages/ti/fs/fatfs/docs/FATFS_LLD_SoftwareManifest.doc [new file with mode: 0644]
packages/ti/fs/fatfs/docs/FATFS_LLD_SoftwareManifest.pdf [new file with mode: 0644]
packages/ti/fs/fatfs/docs/FATFS_LLD_UserGuide.pdf [new file with mode: 0644]
packages/ti/fs/fatfs/docs/Module.xs [new file with mode: 0644]
packages/ti/fs/fatfs/docs/ReleaseNotes_FATFS_LLD.doc [new file with mode: 0644]
packages/ti/fs/fatfs/docs/ReleaseNotes_FATFS_LLD.pdf [new file with mode: 0644]
packages/ti/fs/fatfs/docs/doxyfile.xdt [new file with mode: 0644]
packages/ti/fs/fatfs/docs/tifooter.htm [new file with mode: 0644]
packages/ti/fs/fatfs/docs/tiheader.htm [new file with mode: 0644]
packages/ti/fs/fatfs/docs/tilogo.gif [new file with mode: 0644]
packages/ti/fs/fatfs/docs/titagline.gif [new file with mode: 0644]
packages/ti/fs/fatfs/example/Module.xs [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/am335x/armv7/bios/FATFS_Console_evmAM335x_armExampleProject.txt [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/am335x/armv7/bios/FATFS_Console_icev2AM335x_armExampleProject.txt [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/am335x/armv7/bios/fatfs_evm.cfg [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/am335x/armv7/bios/fatfs_icev2.cfg [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/am437x/armv7/bios/FATFS_Console_evmAM437x_armExampleProject.txt [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/am437x/armv7/bios/FATFS_Console_idkAM437x_armExampleProject.txt [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/am437x/armv7/bios/fatfs_evm.cfg [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/am437x/armv7/bios/fatfs_idk.cfg [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/am571x/armv7/bios/FATFS_Console_idkAM571x_armExampleProject.txt [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/am571x/armv7/bios/fatfs_idk.cfg [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/am571x/c66/bios/FATFS_Console_idkAM571x_c66xExampleProject.txt [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/am571x/c66/bios/fatfs_idk.cfg [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/am572x/armv7/bios/FATFS_Console_MultiPartition_evmAM572x_armExampleProject.txt [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/am572x/armv7/bios/FATFS_Console_evmAM572x_SMP_armExampleProject.txt [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/am572x/armv7/bios/FATFS_Console_evmAM572x_armExampleProject.txt [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/am572x/armv7/bios/FATFS_Console_idkAM572x_armExampleProject.txt [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/am572x/armv7/bios/fatfs_evm.cfg [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/am572x/armv7/bios/fatfs_idk.cfg [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/am572x/c66/bios/FATFS_Console_evmAM572x_c66xExampleProject.txt [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/am572x/c66/bios/FATFS_Console_idkAM572x_c66xExampleProject.txt [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/am572x/c66/bios/fatfs_evm.cfg [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/am572x/c66/bios/fatfs_idk.cfg [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/am574x/armv7/bios/FATFS_Console_idkAM574x_armExampleProject.txt [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/am574x/armv7/bios/fatfs_idk.cfg [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/am574x/c66/bios/FATFS_Console_idkAM574x_c66xExampleProject.txt [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/am574x/c66/bios/fatfs_idk.cfg [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/am65xx/a53/fatfsConsole_a53.cfg [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/am65xx/r5/fatfsConsole_r5.cfg [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/am65xx/r5/mpu.xs [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/dra7xx/armv7/bios/FATFS_Console_evmDRA72x_armExampleProject.txt [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/dra7xx/armv7/bios/FATFS_Console_evmDRA75x_armExampleProject.txt [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/dra7xx/armv7/bios/fatfs.cfg [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/dra7xx/c66/bios/FATFS_Console_evmDRA72x_c66xExampleProject.txt [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/dra7xx/c66/bios/FATFS_Console_evmDRA75x_c66xExampleProject.txt [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/dra7xx/c66/bios/FATFS_Console_evmDRA78x_c66xExampleProject.txt [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/dra7xx/c66/bios/fatfs.cfg [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/dra7xx/m4/bios/FATFS_Console_evmDRA72x_m4ExampleProject.txt [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/dra7xx/m4/bios/FATFS_Console_evmDRA75x_m4ExampleProject.txt [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/dra7xx/m4/bios/FATFS_Console_evmDRA78x_m4ExampleProject.txt [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/dra7xx/m4/bios/fatfs.cfg [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/makefile [new file with mode: 0755]
packages/ti/fs/fatfs/example/console/src/FATFS_log.c [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/src/FATFS_log.h [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/src/fs_shell_app_utils.c [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/src/fs_shell_app_utils.h [new file with mode: 0644]
packages/ti/fs/fatfs/example/console/src/main_console.c [new file with mode: 0644]
packages/ti/fs/fatfs/fatfs_component.mk [new file with mode: 0644]
packages/ti/fs/fatfs/ff.h [new file with mode: 0644]
packages/ti/fs/fatfs/ffconf.h [new file with mode: 0644]
packages/ti/fs/fatfs/integer.h [new file with mode: 0644]
packages/ti/fs/fatfs/makefile [new file with mode: 0644]
packages/ti/fs/fatfs/package.bld [new file with mode: 0644]
packages/ti/fs/fatfs/package.xdc [new file with mode: 0644]
packages/ti/fs/fatfs/package.xs [new file with mode: 0644]
packages/ti/fs/fatfs/src/FATFS_drv.c [new file with mode: 0644]
packages/ti/fs/fatfs/src/FATFS_drv_log.h [new file with mode: 0644]
packages/ti/fs/fatfs/src/FATFS_osal.h [new file with mode: 0644]
packages/ti/fs/fatfs/src/Module.xs [new file with mode: 0644]
packages/ti/fs/fatfs/src/diskio.c [new file with mode: 0644]
packages/ti/fs/fatfs/src/ff.c [new file with mode: 0644]
packages/ti/fs/fatfs/src/src_files_common.mk [new file with mode: 0644]
packages/ti/fs/fatfs/temp.txt [new file with mode: 0644]

diff --git a/packages/ti/fs/fatfs/.gitignore b/packages/ti/fs/fatfs/.gitignore
new file mode 100644 (file)
index 0000000..700b267
--- /dev/null
@@ -0,0 +1,26 @@
+*.swp
+*~
+.dlls
+.executables
+.interfaces
+.libraries
+.xdcenv.mak
+Settings.h
+Settings.xdc
+build/c66/
+build/k2[heklg]/
+build/am57*/
+build/am335x/
+build/am437x/
+build/m4/
+build/armv7/
+docs/Doxyfile
+docs/doxygen/
+example/console/*/*/bios/src
+FATFSver.h
+lib/
+package.mak
+package/
+packages/
+*.o
+*.dep
diff --git a/packages/ti/fs/fatfs/FATFS.h b/packages/ti/fs/fatfs/FATFS.h
new file mode 100644 (file)
index 0000000..7708b1e
--- /dev/null
@@ -0,0 +1,421 @@
+/*
+ * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of Texas Instruments Incorporated nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+/** ============================================================================
+ *  @file       FATFS.h
+ *
+ *  @brief      FATFS interface for driver
+ *
+ *  The SD header file should be included in an application as follows:
+ *  @code
+ *  #include <ti/fs/fatfs/FATFS.h>
+ *  @endcode
+ *
+ *  ============================================================================
+ */
+
+#ifndef FATFS_H
+#define FATFS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdint.h>
+#include <stddef.h>
+#include <ti/fs/fatfs/ff.h>
+#include <ti/fs/fatfs/diskio.h>
+
+/*@{*/
+/**
+ *  @def  FATFS_OK
+ *        FATFS return code -- Function executed successfully
+ */
+#define FATFS_OK                                        0
+
+/**
+ *  @def  FATFS_ERR
+ *        FATFS return code -- Function executed failed
+ */
+#define FATFS_ERR                                   (-(1))
+
+/**
+ *  @def  FATFS_VOLUME_FULL_ERR
+ *        FATFS return code -- VolToPart structure is full and
+ *                             no index to add more partitions
+ */
+#define FATFS_VOLUME_FULL_ERR                       (-(10))
+
+/**
+ *  @def  FATFS_VOLUME_DISK_AVL
+ *        FATFS status code -- VolToPart structure is available
+ *                             to add partitions
+ */
+#define FATFS_VOLUME_DISK_AVL                       (0)
+
+/*Offset macros of MBR table */
+/**
+ *  @def  FATFS_MBR_TABLE
+ *        MBR: Partition table offset
+ */
+#define FATFS_MBR_TABLE                             (446)
+
+/**
+ *  @def  FATFS_SZ_PTE
+ *        MBR: Size of a partition table entry
+ */
+#define FATFS_SZ_PTE                                (16)
+
+/**
+ *  @def  FATFS_NUM_OF_PARTITIONS
+ *        Number of partitions supported
+ */
+#define FATFS_NUM_OF_PARTITIONS                     (4)
+
+/**
+ *  @def  FATFS_MBR_PT_TYPE_OFFSET
+ *        Partition Type offset of each partition entry in MBR
+ */
+#define FATFS_MBR_PT_TYPE_OFFSET                    (4)
+
+/**
+ *  @def  FATFS_DFLT_VOLUME_PD
+ *        Default value of the VolToPart structure variable: partition disk
+ */
+#define FATFS_DFLT_VOLUME_PD                        (0xf)
+
+/**
+ *  @def  FATFS_DFLT_VOLUME_PT
+ *        Default value of the VolToPart structure variable: partition number
+ */
+#define FATFS_DFLT_VOLUME_PT                        (0xf)
+
+/**
+ *  @def  FATFS_MOUNT_IMMEDIATE
+ *        Value to mount the partition immediately during f_mount function call
+ */
+#define FATFS_MOUNT_IMMEDIATE                        (1)
+
+/**
+ *  @def  FATFS_MOUNT_LATER
+ *        Value to mount the partition later during f_open function call but not during f_mount function call
+ */
+#define FATFS_MOUNT_LATER                            (0)
+
+/**
+ *  @def  FATFS_MEDIA_BOOT_SEC_OFFSET
+ *        Offset of Media field in the BOOT Sector which holds the information of the device
+ *        is removable or non removable media.
+ */
+#define FATFS_MEDIA_BOOT_SEC_OFFSET                  (21)
+
+/**
+ *  @def  FATFS_JUMP_BOOT_SEC_OFFSET
+ *        Offset of the JUMP instruction field which holds the information of three byte
+ *        unconditional branch instruction.
+ */
+#define FATFS_JUMP_BOOT_SEC_OFFSET                   (0)
+
+/**
+ *  @def  FATFS_BOOT_MEDIA_TYPE_NON_REM
+ *        Standard value of Media offset in Boot sector for non removable media.
+ */
+#define FATFS_BOOT_MEDIA_TYPE_NON_REM                (0xF0)
+
+/**
+ *  @def  FATFS_BOOT_MEDIA_REM_TYPE_MIN
+ *        Legal minimum value of Media offset in Boot sector for removable media.
+ */
+#define FATFS_BOOT_MEDIA_REM_TYPE_MIN                (0xF8)
+
+/**
+ *  @def  FATFS_BOOT_MEDIA_REM_TYPE_MAX
+ *        Legal maximum value of Media offset in Boot sector for removable media.
+ */
+#define FATFS_BOOT_MEDIA_REM_TYPE_MAX                (0xFF)
+
+/**
+ *  @def  FATFS_JUMP_BOOT_SEC_JMP_INS_0
+ *        Valid JUMP INstruction code value to jump to bootstrap code.
+ */
+#define FATFS_JUMP_BOOT_SEC_JMP_INS_0                (0xEB)
+
+/**
+ *  @def  FATFS_JUMP_BOOT_SEC_JMP_INS_1
+ *        Another Valid JUMP INstruction code value to jump to bootstrap code.
+ */
+#define FATFS_JUMP_BOOT_SEC_JMP_INS_1                (0xE9)
+
+/*@}*/
+/** @} */
+
+
+
+/*!
+ *  @brief      Return status of FATFS.
+ */
+typedef int32_t                   FATFS_Error;
+
+/*!
+ *  @brief      A handle that is returned from a FATFS_open() call.
+ */
+typedef void                     *FATFS_Handle;
+
+/*!
+ *  @brief      Parameters that is required for FATFS_open() call.
+ */
+typedef void                     *FATFS_Params;
+
+/*!
+ *  @brief      A handle that is returned to open driver.
+ */
+typedef void                     *FATFS_DrvHandle;
+
+/*!
+ *  @brief      Parameters that is required to open driver.
+ */
+typedef void                     *FATFS_DrvParams;
+
+/*!
+ *  @brief      The definition of a SD function table that contains the
+ *              required set of functions to control a specific SD driver
+ *              implementation.
+ */
+typedef struct FATFS_DrvFxnTable_s  FATFS_DrvFxnTable;
+
+/*!
+ *  @brief  SD Parameters
+ *
+ *  SD parameters are used to with the FATFS_open() call. Default values for
+ *  these parameters are set using FATFS_Params_init().
+ *
+ *  @sa     FATFS_Params_init()
+ */
+typedef struct FATFS_ConfigParams_s {
+    FATFS_DrvHandle    drvHandle;       /*!< Driver Handle. */
+    FATFS_DrvParams    drvParams;       /*!< Driver Parameters. */
+    FATFS_DrvFxnTable *drvFxnTablePtr;  /*!< FATFS functional table to be
+                                             register on open. */
+    void              *custom;          /*!< Custom argument used by driver
+                                             implementation */
+} FATFS_ConfigParams;
+
+/*!
+ *  @brief      A function pointer to a driver specific implementation of
+ *              FATFS_close().
+ */
+typedef FATFS_Error (*FATFS_CloseDrvFxn) (FATFS_DrvHandle drvHandle);
+
+/*!
+ *  @brief      A function pointer to a driver specific implementation of
+ *              FATFS_control().
+ */
+typedef FATFS_Error (*FATFS_ControlDrvFxn) (FATFS_DrvHandle drvHandle,
+                                            uint32_t cmd,
+                                            void *arg);
+
+/*!
+ *  @brief      A function pointer to a driver specific implementation of
+ *              FATFS_init().
+ */
+typedef FATFS_Error (*FATFS_InitDrvFxn) (void);
+
+/*!
+ *  @brief      A function pointer to a driver specific implementation of
+ *              FATFS_open().
+ */
+typedef FATFS_Error (*FATFS_OpenDrvFxn) (uint32_t index,
+                                         FATFS_DrvParams  drvParams,
+                                         FATFS_DrvHandle *drvHandle);
+
+/*!
+ *  @brief      A function pointer to a driver specific implementation of
+ *              FATFS_transfer().
+ */
+typedef FATFS_Error (*FATFS_WriteDrvFxn) (FATFS_DrvHandle drvHandle,
+                                          uint8_t *buf,
+                                          uint32_t block,
+                                          uint32_t numBlks);
+
+/*!
+ *  @brief      A function pointer to a driver specific implementation of
+ *              FATFS_transfer().
+ */
+typedef FATFS_Error (*FATFS_ReadDrvFxn) (FATFS_DrvHandle drvHandle,
+                                         uint8_t *buf,
+                                         uint32_t block,
+                                         uint32_t numBlks);
+
+/*!
+ *  @brief      The definition of a SD function table that contains the
+ *              required set of functions to control a specific SD driver
+ *              implementation.
+ */
+struct FATFS_DrvFxnTable_s {
+    /*! Function to close the specified peripheral */
+    FATFS_CloseDrvFxn             closeDrvFxn;
+
+    /*! Function to implementation specific control function */
+    FATFS_ControlDrvFxn           controlDrvFxn;
+
+    /*! Function to initialize the given data object */
+    FATFS_InitDrvFxn              initDrvFxn;
+
+    /*! Function to open the specified peripheral */
+    FATFS_OpenDrvFxn              openDrvFxn;
+
+    /*! Function to initiate a driver data write */
+    FATFS_WriteDrvFxn             writeDrvFxn;
+
+    /*! Function to initiate a driver data read */
+    FATFS_ReadDrvFxn              readDrvFxn;
+};
+
+/* SD function table pointer */
+extern FATFS_DrvFxnTable FATFS_drvFxnTable;
+
+/*!
+ *  @brief  SDAm57x Hardware attributes
+ */
+typedef struct FATFS_HwAttrs_s {
+    uint32_t        drvInst; /*!< Driver instance if driver is not opened. */
+} FATFS_HwAttrs;
+
+/*!
+ *  @brief  SDAm572x Object
+ *
+ *  The application must not access any member variables of this structure!
+ */
+typedef struct FATFS_Object_s {
+    FATFS_DrvHandle     drvHandle;     /*!< Driver Handle. */
+    uint32_t            drvInst;       /*!< SD driver instance if SD driver is not
+                                            opened. */
+    uint32_t            driveNumber;   /*!< Drive number used by FatFs */
+    DSTATUS             diskState;     /*!< Disk status */
+    FATFS               filesystem[FATFS_NUM_OF_PARTITIONS];    /*!< FATFS data object */
+
+    FATFS_ConfigParams  FATFSConfigParams;   /*! Stores SD parameters */
+
+    uint32_t            isOpen;        /*! flag to indicate module is open */
+
+} FATFS_Object;
+
+/*!
+ *  @brief  SD Global configuration
+ *
+ *  The FATFS_Config structure contains a set of pointers used to characterize
+ *  the SD driver implementation.
+ *
+ *  This structure needs to be defined before calling FATFS_init() and it must
+ *  not be changed thereafter.
+ *
+ *  @sa     FATFS_init()
+ */
+typedef struct FATFS_Config_s {
+    /*! Pointer to a table of driver-specific implementations of SD APIs */
+    FATFS_DrvFxnTable    *drvFxnTablePtr;
+
+    /*! Pointer to a driver specific data object */
+    FATFS_Object         *object;
+
+    /*! Pointer to a driver specific hardware attributes structure */
+    FATFS_HwAttrs        *hwAttrs;
+} FATFS_Config;
+
+
+/* Avoid Misra warning "MISRA.DECL.ARRAY_SIZE" by pairing config array type 
+ * with its array size to avoid externs with [] (no size) */
+typedef FATFS_Config FATFSConfigList[((uint32_t)_VOLUMES) + (uint32_t)1U];
+
+
+/*!
+ *  @brief  Function to close a SD peripheral specified by the SD handle
+ *
+ *  @pre    FATFS_open() had to be called first.
+ *
+ *  @param  handle  A FATFS_Handle returned from FATFS_open
+ *
+ *  @sa     FATFS_open()
+ */
+extern FATFS_Error FATFS_close(FATFS_Handle handle);
+
+/*!
+ *  @brief  Function to initialize a given SD peripheral specified by the
+ *          particular index value. The parameter specifies which mode the SD
+ *          will operate.
+ *
+ *  @pre    SD controller has been initialized
+ *
+ *  @param  index         Logical peripheral number for the disk indexed into
+ *                        the FATFS_config table
+ *
+ *  @param  params        Pointer to an parameter block, if NULL it will use
+ *                        default values. All the fields in this structure are
+ *                        RO (read-only).
+ *
+ *  @param  handle        Handle to the FATFS driver which holds the hardware
+ *                        attributes and object filesystem parameters.
+ *
+ *  @return A FATFS_Handle on success or a NULL on an error or if it has been
+ *          opened already.
+ *
+ *  @sa     FATFS_init()
+ *  @sa     FATFS_close()
+ */
+extern FATFS_Error FATFS_open(uint32_t index,
+                              FATFS_Params  params,
+                              FATFS_Handle *handle);
+
+/*!
+ *  @brief  Function to initialize the FATFS_Params struct to its defaults
+ *
+ *  @param  params      An pointer to FATFS_Params structure for
+ *                      initialization
+ *
+ */
+extern FATFS_Error FATFS_Params_init(FATFS_Params params);
+
+/*!
+ *  @brief  Function to initializes the FATFS module
+ *
+ *  @pre    The FATFS_config structure must exist and be persistent before this
+ *          function can be called. This function must also be called before
+ *          any other FATFS APIs. This function call does not modify any
+ *          peripheral registers.
+ */
+extern FATFS_Error FATFS_init(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* FATFS_H */
diff --git a/packages/ti/fs/fatfs/FATFSver.h b/packages/ti/fs/fatfs/FATFSver.h
new file mode 100644 (file)
index 0000000..0d7a5c4
--- /dev/null
@@ -0,0 +1,68 @@
+#ifndef _FATFSVER_H
+#define _FATFSVER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* ============================================================= */
+/**
+ *   @file  FATFSver.h
+ *
+ *   path  ti/fs/fatfs/FATFSver.h
+ *
+ *   @brief  fatfs Driver Version Definitions
+ *
+ *  ============================================================
+ *  Copyright (c) Texas Instruments Incorporated 2009-Present
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *
+ *    Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the
+ *    distribution.
+ *
+ *    Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+*/
+
+/**
+ * @brief   This is the fatfs Driver Version. Versions numbers are encoded in the
+ * following format:
+ *  0xAABBCCDD -> Arch (AA); API Changes (BB); Major (CC); Minor (DD)
+ */
+#define FATFS_DRV_VERSION_ID                     (0x0100000F)
+
+/**
+ * @brief   This is the version string which describes the FATFS driver along with
+ * the date and build information.
+ */
+#define FATFS_DRV_VERSION_STR                    "fatfs Driver Revision: 01.00.00.15"
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif  /* _FATFSVER_H */
diff --git a/packages/ti/fs/fatfs/FATFSver.h.xdt b/packages/ti/fs/fatfs/FATFSver.h.xdt
new file mode 100644 (file)
index 0000000..7b11087
--- /dev/null
@@ -0,0 +1,100 @@
+%%{
+/*!
+ *  This template implements the FATFSver.h
+ */
+  /* Versioning */
+  var ver = this;
+  var ver1 = [00,00,00,00];
+  var ver2 = [00,00,00,00];
+
+  for each(i=0;i<ver.length;i++)
+  {
+      if(String(ver[i]).length < 2)
+      {
+        ver1[i]="0"+ver[i];
+      }
+      else
+      {
+        ver1[i] = ver[i];
+      }
+
+      ver2[i] = Number(ver[i]).toString(16).toUpperCase();
+
+      if(String(ver2[i]).length < 2)
+      {
+        ver2[i]="0"+ver2[i];
+      }
+  }
+
+  var versionStr = "\""+"fatfs Driver Revision: "+ver1[0]+"."+ver1[1]+"."+ver1[2]+"."+ver1[3]+"\"";
+  var versionID = "(0x"+ver2[0]+ver2[1]+ver2[2]+ver2[3]+")";
+
+%%}
+#ifndef _FATFSVER_H
+#define _FATFSVER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* ============================================================= */
+/**
+ *   @file  FATFSver.h
+ *
+ *   path  ti/fs/fatfs/FATFSver.h
+ *
+ *   @brief  fatfs Driver Version Definitions
+ *
+ *  ============================================================
+ *  Copyright (c) Texas Instruments Incorporated 2009-Present
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *
+ *    Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the
+ *    distribution.
+ *
+ *    Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+*/
+
+/**
+ * @brief   This is the mmcsd Driver Version. Versions numbers are encoded in the
+ * following format:
+ *  0xAABBCCDD -> Arch (AA); API Changes (BB); Major (CC); Minor (DD)
+ */
+#define FATFS_DRV_VERSION_ID                     `versionID`
+
+/**
+ * @brief   This is the version string which describes the FATFS driver along with
+ * the date and build information.
+ */
+#define FATFS_DRV_VERSION_STR                    `versionStr`
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif  /* _FATFSVER_H */
diff --git a/packages/ti/fs/fatfs/Settings.xdc.xdt b/packages/ti/fs/fatfs/Settings.xdc.xdt
new file mode 100644 (file)
index 0000000..6fb7f03
--- /dev/null
@@ -0,0 +1,36 @@
+
+%%{
+/*!
+ *  This template implements the Settings.xdc
+ */  
+  /* Versioning */
+  var ver = this;
+  for each(i=0;i<ver.length;i++)
+  {
+      if(String(ver[i]).length < 2)
+      {
+        ver[i]="0"+ver[i];
+      }
+  }
+  
+  var packageVersion = "\""+ver[0]+"."+ver[1]+"."+ver[2]+"."+ver[3]+"\"";
+
+%%}
+
+module Settings
+{
+    config string fatfsVersionString = `packageVersion`;
+       
+    /*! This variable is to control the device library type selection.
+     * By default this variable is set to release.
+     * 
+     * To use CSL to use the debug/release library, add the following lines to config
+     * file and set the library profile accordingly:
+     * 
+     *      var Uart Settings = xdc.useModule ('ti.Uart.Settings');
+     *      UartSettings.libProfile = "debug";
+     * 
+     */
+    metaonly config string libProfile = "release";     
+}
+
diff --git a/packages/ti/fs/fatfs/build/buildlib.xs b/packages/ti/fs/fatfs/build/buildlib.xs
new file mode 100644 (file)
index 0000000..fd51571
--- /dev/null
@@ -0,0 +1,589 @@
+/******************************************************************************
+ * FILE PURPOSE: Build Library Utilities
+ ******************************************************************************
+ * FILE NAME: buildlib.xs
+ *
+ * DESCRIPTION: 
+ *  This file contains common routines that are used by the various LLD
+ *  components.
+ *
+ * Copyright (C) 2014-2015, Texas Instruments, Inc.
+ *****************************************************************************/
+
+/**************************************************************************
+ * FUNCTION NAME : listAllFiles
+ **************************************************************************
+ * DESCRIPTION   :
+ *  Utility function which lists all files with a specific extension 
+ *  present in a directory and any directory inside it.
+ **************************************************************************/
+function listAllFiles(ext, dir, recurse)
+{     
+    var srcFile = [];
+    var d;
+
+    /* If recurse parameter is not specified we default to recursive search. */
+    if (recurse == null)
+        recurse = true;
+
+    if (dir == undefined) 
+          d = ".";
+    else 
+      d = dir;
+
+    /* Get access to the current directory. */
+    var file = new java.io.File(d);
+
+    /* Check if the file exists and it is a directory. */
+    if (file.exists() && file.isDirectory()) 
+    {
+        /* Get a list of all files in the specific directory. */
+        var fileList = file.listFiles();
+        for (var i = 0; i < fileList.length; i++) 
+        {
+            /* Dont add the generated directory 'package' and any of its files 
+             * to the list here. */
+            if (fileList[i].getName().matches("package") == false)
+            {
+                /* Check if the detected file is a directory */
+                if (fileList[i].isDirectory())
+                {
+                    /* We will recurse into the subdirectory only if required to do so. */
+                    if (recurse == true)
+                    {
+                        /* Generate the directory Name in which we will recurse. */ 
+                        var directoryName = d + "/" + fileList[i].getName();
+
+                        /* Get a list of all files in this directory */
+                        var fileListing = listAllFiles (ext, directoryName, recurse);
+                        if (fileListing != null)
+                        {
+                            /* Return a list of all file names in the directory. */
+                            for (var j = 0 ; j < fileListing.length; j++) 
+                                srcFile[srcFile.length++] = fileListing[j];
+                        }
+                    }
+                }
+                else
+                {
+                    /* This was a file. Check if the file name matches the extension */
+                    if (fileList[i].getName().endsWith(ext) == true)
+                        srcFile[srcFile.length++] = d + "/" + fileList[i].getName();
+                }
+            }
+        }
+
+        return srcFile;
+    }
+    return null;
+}
+
+
+function createMake(makefile)
+{
+    /* Create the main make file */
+    var fileModule = xdc.module('xdc.services.io.File');
+    if(makefile==undefined)
+    {
+      try{
+          makefile = fileModule.open("makefile", "w");
+         } catch (ex)
+         {
+           print("makefile cannot be written to. Please check Writing Permissions.");
+           java.lang.System.exit(1);
+         }   
+    
+      Pkg.makePrologue += "\ninclude makefile\n"; 
+         
+      Pkg.makeEpilogue += "\nclean::\n\t-$(RM)  makefile\n";
+      makefile.writeLine("#*******************************************************************************");
+      makefile.writeLine("#* FILE PURPOSE: Top level makefile for Creating Component Libraries");
+      makefile.writeLine("#*******************************************************************************");
+      makefile.writeLine("#* FILE NAME: makefile");
+      makefile.writeLine("#*");
+      makefile.writeLine("#* DESCRIPTION: Defines Compiler tools paths, libraries , Build Options ");
+      makefile.writeLine("#*");
+      makefile.writeLine("#*");
+      makefile.writeLine("#*******************************************************************************");
+      makefile.writeLine("#*");
+      makefile.writeLine("# (Mandatory) Specify where various tools are installed.");
+
+      var file = xdc.module('xdc.services.io.File');
+    
+      
+      makefile.writeLine("\n# Output for prebuilt generated libraries");
+      makefile.writeLine("export LIBDIR ?= ./lib");
+      /* use sectti.exe from path */
+      makefile.writeLine("export SECTTI ?= sectti");
+
+      /* Create INCDIR from XDCPATH */
+    
+      /* copy the environment array from the current environment */
+      var env   = java.lang.System.getenv();
+      var getxdcpath=String(java.lang.System.getenv("XDCPATH"));
+      getxdcpath= getxdcpath.replace(/\\/g,"/");
+      var keys  = env.keySet().toArray();
+      var key;
+      var stat={};
+      var env_j=[];
+      var listxdcpath = new Array();
+      for (var i = 0; i < keys.length; i++) {
+           key = String(keys[i]);
+           if((key.match("INSTALL_PATH")) || (key.match("INSTALLDIR")))
+           {
+             var keyPath=String(env.get(key));
+             keyPath=keyPath.replace(/\\/g,"/");
+             var file = xdc.module('xdc.services.io.File');
+             keyPath=file.getDOSPath(keyPath);
+             if(getxdcpath.toString().match(keyPath))
+             {
+                 listxdcpath.push({keyname: key,keypath: keyPath});
+                 while(getxdcpath.toString().match(keyPath))
+                 {
+                   getxdcpath=getxdcpath.toString().replace(keyPath,"$("+key+")");
+                 }
+             }
+           }
+    
+     }
+       var pkgroot="..";
+       for (var i = Pkg.name.split('.').length; i > 1; i--) {
+              pkgroot+="/..";
+          }
+        
+      makefile.writeLine("\n# ROOT Directory");        
+      makefile.writeLine("export ROOTDIR := "+pkgroot);
+    
+      makefile.writeLine("\n# INCLUDE Directory");
+      makefile.writeLine("export INCDIR := "+getxdcpath+";$(ROOTDIR)");       
+    
+      makefile.writeLine("\n# Common Macros used in make");  
+      makefile.writeLine("\nifndef RM");     
+      makefile.writeLine("export RM = rm -f");
+      makefile.writeLine("endif");        
+    
+      makefile.writeLine("\nifndef CP");     
+      makefile.writeLine("export CP = cp -p");    
+      makefile.writeLine("endif");    
+        
+      makefile.writeLine("\nexport MKDIR = mkdir -p");
+    
+      makefile.writeLine("\nifndef RMDIR");         
+      makefile.writeLine("export RMDIR = rm -rf");
+      makefile.writeLine("endif");        
+    
+      makefile.writeLine("\nifndef SED"); 
+      makefile.writeLine("export SED = sed");    
+      makefile.writeLine("endif");    
+    
+      makefile.writeLine("\nifndef MAKE"); 
+      makefile.writeLine("export MAKE = make");    
+      makefile.writeLine("endif");        
+
+      makefile.writeLine("\n# PHONY Targets");                
+      makefile.writeLine(".PHONY: all clean cleanall ");    
+      
+      makefile.writeLine("\n# FORCE Targets");                
+      makefile.writeLine("FORCE: ");          
+      
+      makefile.writeLine("\n# all rule");                
+      makefile.writeLine("all: .executables");           
+      makefile.writeLine(".executables: .libraries");
+      makefile.writeLine(".libraries:");
+      
+      makefile.writeLine("\n# Clean Rule");          
+      makefile.writeLine("clean:: clean_package");                  
+      makefile.writeLine("# Clean Top Level Object Directory ");          
+      makefile.writeLine("clean_package :\n\t$(RMDIR) $(LIBDIR)/*/");      
+      makefile.writeLine("\t$(RMDIR) package/cfg");            
+   }
+   else
+   {
+     try{
+          makefile = fileModule.open("makefile", "a");
+         } catch (ex)
+         {
+           print("makefile cannot be written to. Please check Writing Permissions.");
+           java.lang.System.exit(1);
+         }  
+    
+    }
+
+ return makefile;
+}
+
+function createLibMake(makelibname,targetname, objectPath)
+{
+   var tooldir;
+   var cmdprefix;
+   var targetDir;
+   var stringname=String(targetname).replace("(xdc.bld.ITarget.Module)","");
+   
+   switch(stringname)
+   {
+    case String(C66LE):
+      tooldir="C6X_GEN_INSTALL_PATH";
+      cmdprefix="";
+      targetDir="c66/release";
+      targetname=C66LE;
+      break;
+    case String(A15LE):
+      tooldir="TOOLCHAIN_PATH_A15"; 
+      cmdprefix="CROSS_TOOL_PRFX";
+      targetDir="a15/release";
+      targetname=A15LE;
+      break;
+       case String(A9LE):
+      tooldir="TOOLCHAIN_PATH_A9";
+      cmdprefix="CROSS_TOOL_PRFX";
+      targetDir="a9/release";
+      targetname=A9LE;
+      break;
+       case String(A8LE):
+      tooldir="TOOLCHAIN_PATH_A8";
+      cmdprefix="CROSS_TOOL_PRFX";
+      targetDir="a8/release";
+      targetname=A8LE;
+      break;
+    case String(M4LE):
+      tooldir="TOOLCHAIN_PATH_M4";
+      cmdprefix="";
+      targetDir="m4/release";
+      targetname=M4LE;
+      break;
+   }
+   
+    var fileModule = xdc.module('xdc.services.io.File');
+    try{
+     var dstFile = new java.io.File(makelibname);
+     dstFile.getParentFile().mkdirs();    
+     libmakefile = fileModule.open(makelibname, "w");
+     /* Add to Archive list */
+    } catch (ex)
+    {
+     print(makelibname+" cannot be written to. Please check Writing Permissions.");
+     java.lang.System.exit(1);
+    }   
+    libmakefile.writeLine("#*******************************************************************************");
+    libmakefile.writeLine("#* FILE PURPOSE: Lower level makefile for Creating Component Libraries");
+    libmakefile.writeLine("#*******************************************************************************");
+    libmakefile.writeLine("#* FILE NAME: "+makelibname);
+    libmakefile.writeLine("#*");
+    libmakefile.writeLine("#* DESCRIPTION: Defines Source Files, Compilers flags and build rules");
+    libmakefile.writeLine("#*");
+    libmakefile.writeLine("#*");
+    libmakefile.writeLine("#*******************************************************************************");
+    libmakefile.writeLine("#");
+    libmakefile.writeLine("");
+    libmakefile.writeLine("#");
+    libmakefile.writeLine("# Macro definitions referenced below");
+    libmakefile.writeLine("#");
+    libmakefile.writeLine("empty =");
+    libmakefile.writeLine("space =$(empty) $(empty)");
+    
+    if ((targetname.name == "A15F") || (targetname.name == "A9F") || (targetname.name == "A8F"))
+    {
+    
+        if(stringname.match("gnu.targets"))
+        {
+            libmakefile.writeLine("CC = $("+tooldir+")/bin/$("+cmdprefix+")gcc");
+            libmakefile.writeLine("AC = $("+tooldir+")/bin/$("+cmdprefix+")as");    
+            libmakefile.writeLine("ARIN = $("+tooldir+")/bin/$("+cmdprefix+")ar");    
+            libmakefile.writeLine("LD = $("+tooldir+")/bin/$("+cmdprefix+")gcc");   
+        }
+        else
+        {
+            print("Error: Non-GNU targets are not currently supported ");
+            java.lang.System.exit(1);
+
+        }
+       
+        libmakefile.writeLine("INCS = -I. -I$(strip $(subst ;, -I,$(subst $(space),\\$(space),$(INCDIR)))) -I$("+tooldir+")/include");
+        libmakefile.writeLine("OBJEXT = o"+targetname.suffix); 
+        libmakefile.writeLine("AOBJEXT = s"+targetname.suffix);     
+        libmakefile.writeLine("CFLAGS_INTERNAL = " +targetname.ccOpts.prefix+" "+targetname.cc.opts);
+        libmakefile.writeLine("ASFLAGS_INTERNAL = " +targetname.asmOpts.prefix+" "+targetname.asm.opts);
+        libmakefile.writeLine("ARFLAGS_INTERNAL = " +targetname.ar.opts);
+        libmakefile.writeLine("LNKFLAGS_INTERNAL = " +targetname.lnk.opts);
+        libmakefile.writeLine("INTERNALDEFS = -MD -MF $@.dep");
+        libmakefile.writeLine("INTERNALLINKDEFS = -o $@ -m $@.map");  /* TBD */
+        libmakefile.writeLine("OBJDIR =  ./obj/obj_" +targetname.suffix +"/"+targetDir+"/obj"); 
+    
+    }
+    else
+    {
+  
+        if(stringname.match("ti.targets"))
+        {
+
+            var rtslibtemp = targetname.lnkOpts.suffix.toString().split("/");
+            var rtslib;
+            for(n=0;n<rtslibtemp.length;n++)
+            {
+                if(rtslibtemp[n].match(".lib"))
+                { 
+                    rtslib=rtslibtemp[n];
+                }
+            }
+
+            libmakefile.writeLine("CC = $("+tooldir+")/bin/"+targetname.cc.cmd);
+            libmakefile.writeLine("AC = $("+tooldir+")/bin/"+targetname.asm.cmd);    
+            libmakefile.writeLine("ARIN = $("+tooldir+")/bin/"+targetname.ar.cmd);    
+            libmakefile.writeLine("LD = $("+tooldir+")/bin/"+targetname.lnk.cmd);   
+            libmakefile.writeLine("RTSLIB = -l $("+tooldir+")/lib/"+rtslib);        
+        }
+        else
+        {
+            print("Error: Non-TI targets are not currently supported ");
+            java.lang.System.exit(1);
+
+        }
+       
+        libmakefile.writeLine("INCS = -I. -I$(strip $(subst ;, -I,$(subst $(space),\\$(space),$(INCDIR)))) -I$("+tooldir+")/include");
+        libmakefile.writeLine("OBJEXT = o"+targetname.suffix); 
+        libmakefile.writeLine("AOBJEXT = s"+targetname.suffix);     
+        libmakefile.writeLine("CFLAGS_INTERNAL = " +targetname.ccOpts.prefix+" "+targetname.cc.opts);
+        libmakefile.writeLine("ASFLAGS_INTERNAL = " +targetname.asmOpts.prefix+" "+targetname.asm.opts);
+        libmakefile.writeLine("ARFLAGS_INTERNAL = " +targetname.ar.opts);
+        libmakefile.writeLine("LNKFLAGS_INTERNAL = " +targetname.lnk.opts);
+        /* libmakefile.writeLine("INTERNALDEFS = -D"+stringname.replace(/\./g,"_")+" -Dxdc_target_types__=ti/targets/std.h -DMAKEFILE_BUILD -eo.$(OBJEXT) -ea.$(AOBJEXT) -fr=$(@D) -fs=$(@D) -ppa -ppd=$@.dep");*/
+        libmakefile.writeLine("INTERNALDEFS = -D"+stringname.replace(/\./g,"_")+"  -DMAKEFILE_BUILD -eo.$(OBJEXT) -ea.$(AOBJEXT) -fr=$(@D) -fs=$(@D) -ppa -ppd=$@.dep");
+        libmakefile.writeLine("INTERNALLINKDEFS = -o $@ -m $@.map");
+        libmakefile.writeLine("OBJDIR =  ./obj/obj_" +targetname.suffix +"/"+targetDir+"/obj"); 
+    }
+   
+ return libmakefile;
+
+}
+
+function makeAddObjects(srcString, makefilename, srcfiles, flags,fileExt, targetName)
+{
+  var  sourcestring = (srcString + fileExt).toString().toUpperCase();
+  var  compileflagstring = sourcestring + "FLAGS";
+  var  objectliststring = sourcestring + "OBJS";
+  /* List all the source files */
+  makefilename.writeLine("\n#List the "+srcString+" Files");  
+  makefilename.writeLine(sourcestring + "= \\");
+  for(var i=0;i<srcfiles.length-1;i++)
+  {
+    makefilename.writeLine("    "+srcfiles[i]+"\\");
+  }
+    makefilename.writeLine("    "+srcfiles[i]+"\n");
+    
+ /* Flags for the source files */
+ makefilename.writeLine("# FLAGS for the "+srcString+" Files"); 
+ var compileflags="";
+ if(fileExt == "asm" && flags.aopts != undefined)
+ {
+   compileflags+=" "+flags.aopts;
+ }
+ else if((fileExt == "c" || fileExt == "sa")&& flags.copts != undefined)
+ {
+   compileflags+=" "+flags.copts;
+ } 
+
+ if(flags.incs != undefined)
+ {
+   compileflags+=" "+flags.incs;
+ }
+
+
+ makefilename.writeLine(compileflagstring+" = "+compileflags +" \n");     
+ makefilename.writeLine("# Make Rule for the "+srcString+" Files");  
+ makefilename.writeLine(objectliststring +" = $(patsubst %."+fileExt+", $(OBJDIR)/%.$(OBJEXT), $(" + sourcestring + "))"); 
+ makefilename.writeLine("\n$("+objectliststring+"): $(OBJDIR)/%.$(OBJEXT): %."+fileExt);   
+ if(fileExt == "c")
+ { 
+   makefilename.writeLine("\t-@echo cl"+targetName.suffix +" $< ...");     
+ }
+ else
+ {
+   makefilename.writeLine("\t-@echo asm"+targetName.suffix +" $< ...");      
+ }
+ makefilename.writeLine("\tif [ ! -d $(@D) ]; then $(MKDIR) $(@D) ; fi;");           
+ if(fileExt == "c")
+ {
+   if ((targetName.name == "A15F") || (targetName.name == "A9F") || (targetName.name == "A8F"))
+   {
+    makefilename.writeLine("\t$(RM) $@.dep");
+    makefilename.writeLine("\t$(CC) $(CFLAGS_INTERNAL) $("+compileflagstring+") $(INTERNALDEFS) $(INCS) $< -o $@");
+   /* 
+    TBD
+   */
+   }
+   else
+   {
+    makefilename.writeLine("\t$(RM) $@.dep");
+    makefilename.writeLine("\t$(CC) $(CFLAGS_INTERNAL) $("+compileflagstring+") $(INTERNALDEFS) $(INCS) -fc $< ");
+    makefilename.writeLine("\t-@$(CP) $@.dep $@.pp; \\");
+    makefilename.writeLine("         $(SED) -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\\\$$//' \\");
+    makefilename.writeLine("             -e '/^$$/ d' -e 's/$$/ :/' < $@.pp >> $@.dep; \\");
+    makefilename.writeLine("         $(RM) $@.pp ");
+   }
+ }
+ else if(fileExt == "asm")
+ {
+   makefilename.writeLine("\t$(AC) $(ASFLAGS_INTERNAL) $("+compileflagstring+") $(INTERNALDEFS) $(INCS) -fa $< ");
+ }
+ else if(fileExt == "sa")
+ {
+   makefilename.writeLine("\t$(AC) $(ASFLAGS_INTERNAL) $("+compileflagstring+") $(INTERNALDEFS) $(INCS) $< ");
+ }
+ makefilename.writeLine("\n#Create Empty rule for dependency");
+ makefilename.writeLine("$("+objectliststring+"):"+makefilename.$private.fd);
+ makefilename.writeLine(makefilename.$private.fd+":");
+ makefilename.writeLine("\n#Include Depedency for "+srcString+" Files");
+ makefilename.writeLine("ifneq (clean,$(MAKECMDGOALS))");
+ makefilename.writeLine(" -include $("+objectliststring+":%.$(OBJEXT)=%.$(OBJEXT).dep)");
+ makefilename.writeLine("endif");
+}
+
+/**************************************************************************
+ * FUNCTION NAME : buildLibrary
+ **************************************************************************
+ * DESCRIPTION   :
+ *  Utility function which will build a specific library
+ **************************************************************************/
+var makefilelocal;
+function buildLibrary (libOptions, libName, target, libFiles) 
+{
+    var targetDir;
+
+    if (target.name == "A15F")
+    {
+        targetDir = "a15/release";
+    }
+       else if (target.name == "A9F")
+    {
+        targetDir = "a9/release";
+    }
+       else if (target.name == "A8F")
+    {
+        targetDir = "a8/release";
+    }
+    else if (target.name == "M4")
+    {
+        targetDir = "m4/release";
+    }
+    else
+    {
+        targetDir = "c66/release";
+    }
+    
+        
+    var lldFullLibraryPath = "./lib/" + targetDir +"/" + libName;
+    var lldFullBuildPath = "./build/" + targetDir +"/" + libName;
+    var lldFullLibraryPathMake = "$(LIBDIR)/" + targetDir +"/" + libName;
+
+    /* Create Main make file in the root of package folder */
+    makefilelocal = createMake(makefilelocal);
+
+    /* Write the rule to make library in main makefile */
+    lib = lldFullBuildPath+".a"+target.suffix;
+    libMake = lldFullLibraryPathMake+".a"+target.suffix;
+    var objectPath= "./package/"+lldFullBuildPath;
+    makefilelocal.writeLine("\n\n# Make rule to create "+libMake+" library");
+    makefilelocal.writeLine(".libraries: "+ libMake);
+    makefilelocal.writeLine(libMake+": FORCE\n\t$(MAKE) -f "+lib+".mk $@");                                 
+
+    /* Create Library make file in the lib folder */
+    var makefilelib= createLibMake(lib+".mk",target,objectPath);  
+
+    /* Rule to clean library in main makefile */
+    makefilelocal.writeLine("# Rule to clean "+libMake+" library");                                              
+    makefilelocal.writeLine("clean ::\n\t$(RM) "+ libMake);                                          
+    librule="\n\n"+libMake+" :";
+
+    /* Add files to be compiled */
+    /* Separate out the C and assembly files */
+    var cfiles= new Array();
+    var afiles= new Array();
+    var safiles= new Array();
+    for each(var srcFile in libFiles)
+    {
+        var srcFile=String(srcFile);
+        var dot = srcFile.lastIndexOf(".");
+        var extension = srcFile.substr(dot,srcFile.length);      
+        if(extension == ".c")
+        {
+            cfiles.push(srcFile);
+        }
+        else if(extension == ".sa")
+        {
+            safiles.push(srcFile);
+        }
+        else if(extension == ".asm")
+        {
+            afiles.push(srcFile);
+        }
+        else
+        {
+            print("ERROR: Unsupported file extension");
+            java.lang.System.exit(1);
+        }
+    }
+    if(cfiles.length > 0)
+    {                                                
+        makeAddObjects("COMMONSRC",makefilelib,cfiles,libOptions,"c",target);
+        librule += " $(COMMONSRCCOBJS)";                   
+    }
+    if(afiles.length > 0)
+    {                                                
+        makeAddObjects("COMMONSRC",makefilelib,afiles,libOptions,"asm",target);
+        librule += " $(COMMONSRCASMOBJS)";                   
+    }
+    if(safiles.length > 0)
+    {                                                
+        makeAddObjects("COMMONSRC",makefilelib,safiles,libOptions,"sa",target);
+        librule += " $(COMMONSRCSAOBJS)";                   
+    }
+
+    makefilelib.writeLine(librule);
+    makefilelib.writeLine("\t@echo archiving $? into $@ ...");
+    makefilelib.writeLine("\tif [ ! -d $(LIBDIR)/"+targetDir+" ]; then $(MKDIR) $(LIBDIR)/"+targetDir+" ; fi;"); 
+       makefilelib.writeLine("\t$(ARIN) $(ARFLAGS_INTERNAL) $@ $?");
+       makefilelib.close();   
+
+    /* Create the Epilogue; which executes after all the builds are completed. 
+     * This is used to generate the benchmark information for the built library. 
+     * Also add the benchmarking information file to the package. */
+    /* Put the temp file in object directory since javascript doesn't have a built in tmpname, 
+     * and don't want --jobs=# with # > 1 to result in collisions */
+    var libFullName = lldFullLibraryPath + ".a" + target.suffix;
+    var tempFile = libFullName + ".xml";
+    Pkg.makeEpilogue += ".libraries: " + libFullName +  "_size.txt\n";
+    Pkg.makeEpilogue += libFullName +  "_size.txt: " + libFullName + "\n";
+    if ( java.lang.String(target.name).contains('66') )
+    {    
+        Pkg.makeEpilogue += "\n\t $(C6X_GEN_INSTALL_PATH)/bin/ofd6x -x " + libFullName + " > " + tempFile;
+        Pkg.makeEpilogue += "\n\t $(SECTTI) " + tempFile + " > " + libFullName +  "_size.txt";
+        Pkg.makeEpilogue += "\n\t $(RM) " + tempFile + "\n\n";
+    }   
+    else if (target.name == "M4")
+    {
+        Pkg.makeEpilogue += "\n\t $(TOOLCHAIN_PATH_M4)/bin/armofd -x " + libFullName + " > " + tempFile;
+        Pkg.makeEpilogue += "\n\t $(SECTTI) " + tempFile + " > " + libFullName +  "_size.txt";
+        Pkg.makeEpilogue += "\n\t $(RM) " + tempFile + "\n\n";
+    }
+    else
+    {
+        Pkg.makeEpilogue += "\n\t $(TOOLCHAIN_PATH_A15)/bin/$(CROSS_TOOL_PRFX)size " + libFullName + " > " + libFullName + "_size.txt";
+    }                
+    Pkg.otherFiles[Pkg.otherFiles.length++] = lldFullLibraryPath + ".a" + target.suffix + "_size.txt";
+    Pkg.otherFiles[Pkg.otherFiles.length++] = lldFullBuildPath + ".a" + target.suffix + ".mk";
+    Pkg.otherFiles[Pkg.otherFiles.length++] = lldFullLibraryPath + ".a" + target.suffix;
+
+    /* We need to clean after ourselves; extend the 'clean' target to take care of this. */
+    Pkg.makeEpilogue += "\nclean::\n";
+    Pkg.makeEpilogue += "\t$(RM) " + lldFullBuildPath + ".a" + target.suffix + "_size.txt\n"; 
+    Pkg.makeEpilogue += "\t$(RMDIR) " + "$(LIBDIR)/" + targetDir + "/ \n\n";
+
+    return lib;
+}
+
+
+
diff --git a/packages/ti/fs/fatfs/build/makefile_indp.mk b/packages/ti/fs/fatfs/build/makefile_indp.mk
new file mode 100644 (file)
index 0000000..8098c39
--- /dev/null
@@ -0,0 +1,56 @@
+#
+# Copyright (c) 2016, Texas Instruments Incorporated
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# *  Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+#
+# *  Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# *  Neither the name of Texas Instruments Incorporated nor the names of
+#    its contributors may be used to endorse or promote products derived
+#    from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+include $(PDK_INSTALL_PATH)/ti/build/Rules.make
+include $(PDK_FATFS_COMP_PATH)/src/src_files_common.mk
+
+MODULE_NAME = fatfs_indp
+
+# List all the external components/interfaces, whose interface header files
+#  need to be included for this component
+INCLUDE_EXTERNAL_INTERFACES = pdk
+
+ifneq ($(SOC),$(filter $(SOC), am65xx j721e))
+INCLUDE_EXTERNAL_INTERFACES += edma
+endif
+
+CFLAGS_LOCAL_COMMON = $(PDK_CFLAGS)
+
+# Include common make files
+ifeq ($(MAKERULEDIR), )
+#Makerule path not defined, define this and assume relative path from ROOTDIR
+  MAKERULEDIR := $(ROOTDIR)/ti/build/makerules
+  export MAKERULEDIR
+endif
+include $(MAKERULEDIR)/common.mk
+
+# Nothing beyond this point
diff --git a/packages/ti/fs/fatfs/build/makefile_mp_indp.mk b/packages/ti/fs/fatfs/build/makefile_mp_indp.mk
new file mode 100644 (file)
index 0000000..6481570
--- /dev/null
@@ -0,0 +1,52 @@
+#
+# Copyright (c) 2018, Texas Instruments Incorporated
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# *  Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+#
+# *  Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# *  Neither the name of Texas Instruments Incorporated nor the names of
+#    its contributors may be used to endorse or promote products derived
+#    from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+include $(PDK_INSTALL_PATH)/ti/build/Rules.make
+include $(PDK_FATFS_COMP_PATH)/src/src_files_common.mk
+
+MODULE_NAME = fatfs_multi_indp
+
+# List all the external components/interfaces, whose interface header files
+#  need to be included for this component
+INCLUDE_EXTERNAL_INTERFACES = pdk
+
+CFLAGS_LOCAL_COMMON = $(PDK_CFLAGS) -DMULTIPARTITION
+
+# Include common make files
+ifeq ($(MAKERULEDIR), )
+#Makerule path not defined, define this and assume relative path from ROOTDIR
+  MAKERULEDIR := $(ROOTDIR)/ti/build/makerules
+  export MAKERULEDIR
+endif
+include $(MAKERULEDIR)/common.mk
+
+# Nothing beyond this point
diff --git a/packages/ti/fs/fatfs/build/makefile_profile_indp.mk b/packages/ti/fs/fatfs/build/makefile_profile_indp.mk
new file mode 100644 (file)
index 0000000..69a0d6b
--- /dev/null
@@ -0,0 +1,62 @@
+#
+# Copyright (c) 2016, Texas Instruments Incorporated
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# *  Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+#
+# *  Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# *  Neither the name of Texas Instruments Incorporated nor the names of
+#    its contributors may be used to endorse or promote products derived
+#    from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+include $(PDK_INSTALL_PATH)/ti/build/Rules.make
+include $(PDK_FATFS_COMP_PATH)/src/src_files_common.mk
+
+MODULE_NAME = fatfs_profile_indp
+
+# List all the external components/interfaces, whose interface header files
+#  need to be included for this component
+INCLUDE_EXTERNAL_INTERFACES = pdk
+
+ifneq ($(SOC),$(filter $(SOC), am65xx j721e))
+INCLUDE_EXTERNAL_INTERFACES += edma
+endif
+
+ifeq ($(BUILDTYPE),$(filter $(BUILDTYPE), profile profiledma))
+  ifeq ($(CORE),$(filter $(CORE), a15_0 a9host a8host mpu mcu))
+    CFLAGS_LOCAL_COMMON = $(PDK_CFLAGS) -finstrument-functions -gdwarf-3 -g -D_ENABLE_BM
+  else
+    CFLAGS_LOCAL_COMMON = $(PDK_CFLAGS) --entry_parm=address --exit_hook=ti_utils_exit --exit_parm=address --entry_hook=ti_utils_entry -g -D_ENABLE_BM
+  endif
+endif
+
+# Include common make files
+ifeq ($(MAKERULEDIR), )
+#Makerule path not defined, define this and assume relative path from ROOTDIR
+  MAKERULEDIR := $(ROOTDIR)/ti/build/makerules
+  export MAKERULEDIR
+endif
+include $(MAKERULEDIR)/common.mk
+
+# Nothing beyond this point
diff --git a/packages/ti/fs/fatfs/config.bld b/packages/ti/fs/fatfs/config.bld
new file mode 100644 (file)
index 0000000..2f102ca
--- /dev/null
@@ -0,0 +1,89 @@
+/******************************************************************************
+ * FILE PURPOSE: Build configuration Script for the fatfs Driver
+ ******************************************************************************
+ * FILE NAME: config.bld
+ *
+ * DESCRIPTION: 
+ *  This file contains the build configuration script for the fatfs driver
+ *  and is responsible for configuration of the paths for the various 
+ *  tools required to build the driver.
+ *
+ * Copyright (C) 2014-2017, Texas Instruments, Inc.
+ *****************************************************************************/
+
+/* Get the Tools Base directory from the Environment Variable. */
+var c66ToolsBaseDir = java.lang.System.getenv("C6X_GEN_INSTALL_PATH");
+var c674ToolsBaseDir = java.lang.System.getenv("C6X_GEN_INSTALL_PATH");
+var m4ToolsBaseDir = java.lang.System.getenv("TOOLCHAIN_PATH_M4");
+var a15ToolsBaseDir = java.lang.System.getenv("TOOLCHAIN_PATH_A15");
+var a9ToolsBaseDir = java.lang.System.getenv("TOOLCHAIN_PATH_A9");
+var a8ToolsBaseDir = java.lang.System.getenv("TOOLCHAIN_PATH_A8");
+var arm9ToolsBaseDir = java.lang.System.getenv("TOOLCHAIN_PATH_ARM9");
+
+/* Get the base directory for the fatfs Socket Driver Package */
+var driverPath = new java.io.File(".//").getPath();
+
+/* Read the part number from the environment variable. */
+var LLDPartNumber = java.lang.System.getenv("PARTNO");
+
+/* Include Path */
+var lldIncludePath = " -I" + driverPath + "/src" + " -I" + driverPath;
+
+/* Configure the fatfs Socket Release Version Information */
+/* 3 steps: remove SPACE and TAB, convert to string and split to make array */
+var driverReleaseVersion = (""+Pkg.version.replace(/\s/g, "")).split(',');
+
+/* Print the Compiler Options */
+var pOpts = 1;
+
+/* C66 ELF compiler configuration for Little Endian Mode. */
+var C66LE           = xdc.useModule('ti.targets.elf.C66');
+C66LE.rootDir       = c66ToolsBaseDir;
+C66LE.ccOpts.prefix = "-mo -o3 -q -k -eo.o";
+
+/* ARMv7 A15 compiler configuration */
+var A15LE            = xdc.useModule('gnu.targets.arm.A15F');
+A15LE.rootDir        = a15ToolsBaseDir;
+A15LE.ccOpts.prefix  = "-mno-unaligned-access -c -mtune=cortex-a15 -marm -DDRA7xx -gstrict-dwarf -Wall -D__ARMv7 -D_LITTLE_ENDIAN=1";
+
+/* ARMv7 A9 compiler configuration */
+var A9LE            = xdc.useModule('gnu.targets.arm.A9F');
+A9LE.rootDir        = a9ToolsBaseDir;
+A9LE.ccOpts.prefix  = "-mno-unaligned-access -c -mtune=cortex-a9 -marm -DDRA7xx -gstrict-dwarf -Wall -D__ARMv7 -D_LITTLE_ENDIAN=1";
+
+/* ARMv7 A8 compiler configuration */
+var A8LE            = xdc.useModule('gnu.targets.arm.A8F');
+A8LE.rootDir        = a8ToolsBaseDir;
+A8LE.ccOpts.prefix  = "-mno-unaligned-access -c -mtune=cortex-a8 -marm -DDRA7xx -gstrict-dwarf -Wall -D__ARMv7 -D_LITTLE_ENDIAN=1";
+
+/* M4 ELF compiler configuration for Little Endian Mode. */
+var M4LE            = xdc.useModule('ti.targets.arm.elf.M4');
+M4LE.rootDir        = m4ToolsBaseDir;
+M4LE.ccOpts.prefix  = "-o4 -qq -pdsw255 -DMAKEFILE_BUILD";
+
+/* Check if we need to run the STATIC Analysis or not? */
+var coverityAnalysis = java.lang.System.getenv("STATIC_ANALYZE");
+
+/* Setup the Coverity Filters to perform Static Analysis. */
+if (coverityAnalysis == "ON") {
+    var coverityInstallPath = java.lang.System.getenv("STATIC_ANALYZE_PATH");
+    var cfgBase = xdc.getPackageBase("tisb.coverity.filters") + "cfg";
+
+    var coverityFilter = [
+    {
+        moduleName: "tisb.coverity.filters.Coverity",
+        params: {
+            cfgDir:  cfgBase,  // The Coverity configuration file directory
+            rootDir: coverityInstallPath,
+            outDir: xdc.csd() + "cov_out",
+            analyzeLibs: true
+        }
+    },
+    ];
+
+    /* Run the coverity filters on the LE Build only. */
+    C66LE.profiles["release"].filters = coverityFilter;
+}
+
+/* List all the build targets here. */
+Build.targets = [ A8LE, A9LE, C66LE, M4LE, A15LE];
diff --git a/packages/ti/fs/fatfs/config_mk.bld b/packages/ti/fs/fatfs/config_mk.bld
new file mode 100644 (file)
index 0000000..cb64190
--- /dev/null
@@ -0,0 +1,47 @@
+/******************************************************************************
+ * FILE PURPOSE: Build configuration Script for the fatfs Driver
+ ******************************************************************************
+ * FILE NAME: config.bld
+ *
+ * DESCRIPTION: 
+ *  This file contains the build configuration script for the fatfs driver
+ *  and is responsible for configuration of the paths for the various 
+ *  tools required to build the driver.
+ *
+ * Copyright (C) 2014-2015, Texas Instruments, Inc.
+ *****************************************************************************/
+
+/* Get the Tools Base directory from the Environment Variable. */
+var c66ToolsBaseDir = java.lang.System.getenv("C6X_GEN_INSTALL_PATH");
+var c674ToolsBaseDir = java.lang.System.getenv("C6X_GEN_INSTALL_PATH");
+var m4ToolsBaseDir = java.lang.System.getenv("TOOLCHAIN_PATH_M4");
+var a15ToolsBaseDir = java.lang.System.getenv("TOOLCHAIN_PATH_A15");
+var a9ToolsBaseDir = java.lang.System.getenv("TOOLCHAIN_PATH_A9");
+var arm9ToolsBaseDir = java.lang.System.getenv("TOOLCHAIN_PATH_ARM9");
+var a8ToolsBaseDir = java.lang.System.getenv("TOOLCHAIN_PATH_A8");
+
+/* Get the base directory for the fatfs Socket Driver Package */
+var driverPath = new java.io.File(".//").getPath();
+
+/* Read the part number from the environment variable. */
+var LLDPartNumber = java.lang.System.getenv("PARTNO");
+
+/* Include Path */
+var lldIncludePath = " -I" + driverPath + "/src" + " -I" + driverPath;
+
+/* Configure the fatfs Socket Release Version Information */
+/* 3 steps: remove SPACE and TAB, convert to string and split to make array */
+var driverReleaseVersion = (""+Pkg.version.replace(/\s/g, "")).split(',');
+
+/* Do not Print the Compiler Options */
+var pOpts = 0;
+
+/* List of all devices that needs to be build via XDC
+ * As the build happens through makefile, there is nothing to build via XDC
+ * using the below for packaging infrastructure
+ */
+var socs = [];
+var devices = [];
+var build_devices = [];
+Build.targets = []
+
diff --git a/packages/ti/fs/fatfs/diskio.h b/packages/ti/fs/fatfs/diskio.h
new file mode 100644 (file)
index 0000000..727809e
--- /dev/null
@@ -0,0 +1,107 @@
+/*-----------------------------------------------------------------------/\r
+/  Low level disk interface modlue include file   (C)ChaN, 2014          /\r
+/-----------------------------------------------------------------------*/\r
+\r
+#ifndef _DISKIO_DEFINED\r
+#define _DISKIO_DEFINED\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#include "integer.h"\r
+#include <ti/csl/hw_types.h>\r
+#include <stdio.h>\r
+\r
+/* Status of Disk Functions */\r
+typedef BYTE   DSTATUS;\r
+\r
+/* Results of Disk Functions */\r
+typedef enum {\r
+       RES_OK = 0,             /* 0: Successful */\r
+       RES_ERROR,              /* 1: R/W Error */\r
+       RES_WRPRT,              /* 2: Write Protected */\r
+       RES_NOTRDY,             /* 3: Not Ready */\r
+       RES_PARERR              /* 4: Invalid Parameter */\r
+} DRESULT;\r
+\r
+\r
+/*---------------------------------------*/\r
+/* Prototypes for disk control functions */\r
+\r
+\r
+DSTATUS disk_initialize (BYTE pdrv);\r
+DSTATUS disk_status (BYTE pdrv);\r
+DRESULT disk_read (BYTE pdrv, BYTE* buff, DWORD sector, UINT count);\r
+DRESULT disk_write (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count);\r
+DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);\r
+\r
+\r
+/* Disk Status Bits (DSTATUS) */\r
+\r
+#define STA_NOINIT             ((uint32_t)0x01U)       /* Drive not initialized */\r
+#define STA_NODISK             ((uint32_t)0x02U)       /* No medium in the drive */\r
+#define STA_PROTECT            ((uint32_t)0x04U)       /* Write protected */\r
+\r
+\r
+/* Command code for disk_ioctrl fucntion */\r
+\r
+/* Generic command (Used by FatFs) */\r
+#define CTRL_SYNC                      0       /* Complete pending write process (needed at _FS_READONLY == 0) */\r
+#define GET_SECTOR_COUNT       1       /* Get media size (needed at _USE_MKFS == 1) */\r
+#define GET_SECTOR_SIZE                2       /* Get sector size (needed at _MAX_SS != _MIN_SS) */\r
+#define GET_BLOCK_SIZE         3       /* Get erase block size (needed at _USE_MKFS == 1) */\r
+#define CTRL_TRIM                      4       /* Inform device that the data on the block of sectors is no longer used (needed at _USE_TRIM == 1) */\r
+\r
+/* Generic command (Not used by FatFs) */\r
+#define CTRL_POWER                     5       /* Get/Set power status */\r
+#define CTRL_LOCK                      6       /* Lock/Unlock media removal */\r
+#define CTRL_EJECT                     7       /* Eject media */\r
+#define CTRL_FORMAT                    8       /* Create physical format on the media */\r
+\r
+/* MMC/SDC specific ioctl command */\r
+#define MMC_GET_TYPE           10      /* Get card type */\r
+#define MMC_GET_CSD                    11      /* Get CSD */\r
+#define MMC_GET_CID                    12      /* Get CID */\r
+#define MMC_GET_OCR                    13      /* Get OCR */\r
+#define MMC_GET_SDSTAT         14      /* Get SD status */\r
+#define ISDIO_READ                     55      /* Read data form SD iSDIO register */\r
+#define ISDIO_WRITE                    56      /* Write data to SD iSDIO register */\r
+#define ISDIO_MRITE                    57      /* Masked write data to SD iSDIO register */\r
+\r
+/* ATA/CF specific ioctl command */\r
+#define ATA_GET_REV                    20      /* Get F/W revision */\r
+#define ATA_GET_MODEL          21      /* Get model name */\r
+#define ATA_GET_SN                     22      /* Get serial number */\r
+\r
+/*\r
+ * Updates made by Texas Instruments\r
+ *\r
+ * The following additions are needed in order to control the total number of\r
+ * volumes supported and to allow the disk_* APIs to call media specific disk\r
+ * functions which are registered in a table of type 'diskio_fxns'\r
+ */\r
+\r
+/* Disk I/O function table object, used to map media specific implementations */\r
+typedef struct {\r
+    DSTATUS (*d_init)   (BYTE drive);\r
+    DSTATUS (*d_status) (BYTE drive);\r
+    DRESULT (*d_read)   (BYTE drive, BYTE *buf, DWORD start, BYTE num);\r
+    DRESULT (*d_write)  (BYTE drive, const BYTE *buf, DWORD start, BYTE num);\r
+    DRESULT (*d_ioctl)  (BYTE drive, BYTE cmd, void * buf);\r
+} diskio_fxns;\r
+\r
+DRESULT disk_register(\r
+        BYTE drive,\r
+        DSTATUS (*d_init)  (BYTE drive),\r
+        DSTATUS (*d_status) (BYTE drive),\r
+        DRESULT (*d_read)  (BYTE drive, BYTE *buf, DWORD start, BYTE num),\r
+        DRESULT (*d_write) (BYTE drive, const BYTE *buf, DWORD start, BYTE num),\r
+        DRESULT (*d_ioctl) (BYTE drive, BYTE cmd, void * buf));\r
+\r
+DRESULT disk_unregister(BYTE drive);\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif\r
diff --git a/packages/ti/fs/fatfs/docs/FATFS_LLD_SoftwareManifest.doc b/packages/ti/fs/fatfs/docs/FATFS_LLD_SoftwareManifest.doc
new file mode 100644 (file)
index 0000000..9e56639
Binary files /dev/null and b/packages/ti/fs/fatfs/docs/FATFS_LLD_SoftwareManifest.doc differ
diff --git a/packages/ti/fs/fatfs/docs/FATFS_LLD_SoftwareManifest.pdf b/packages/ti/fs/fatfs/docs/FATFS_LLD_SoftwareManifest.pdf
new file mode 100644 (file)
index 0000000..14fd642
Binary files /dev/null and b/packages/ti/fs/fatfs/docs/FATFS_LLD_SoftwareManifest.pdf differ
diff --git a/packages/ti/fs/fatfs/docs/FATFS_LLD_UserGuide.pdf b/packages/ti/fs/fatfs/docs/FATFS_LLD_UserGuide.pdf
new file mode 100644 (file)
index 0000000..6ea92dd
Binary files /dev/null and b/packages/ti/fs/fatfs/docs/FATFS_LLD_UserGuide.pdf differ
diff --git a/packages/ti/fs/fatfs/docs/Module.xs b/packages/ti/fs/fatfs/docs/Module.xs
new file mode 100644 (file)
index 0000000..13fb80c
--- /dev/null
@@ -0,0 +1,60 @@
+/******************************************************************************
+ * FILE PURPOSE: FATFS Driver DOCS Module specification file.
+ ******************************************************************************
+ * FILE NAME: module.xs
+ *
+ * DESCRIPTION: 
+ *  This file contains the module specification for the FATFS Driver Documentation .
+ *
+ * Copyright (C) 2008, Texas Instruments, Inc.
+ *****************************************************************************/
+
+/* Load the library utility. */
+var libUtility = xdc.loadCapsule ("../build/buildlib.xs");
+
+/**************************************************************************
+ * FUNCTION NAME : modBuild
+ **************************************************************************
+ * DESCRIPTION   :
+ *  The function is used to build the LLD documentation and add it to the
+ *  package.
+ **************************************************************************/
+function modBuild() 
+{
+    /* Create the actual PROLOGUE Section for the Documentation.*/
+    Pkg.makePrologue += "release: fatfs_document_generation\n";
+    Pkg.makePrologue += "fatfs_document_generation:\n";
+    Pkg.makePrologue += "\t @echo ----------------------------\n";
+    Pkg.makePrologue += "\t @echo Generating FATFS Driver Documentation\n";
+    Pkg.makePrologue += "\t doxygen docs/Doxyfile\n";
+    Pkg.makePrologue += "\t @echo FATFS Driver Documentation Generated \n";
+    Pkg.makePrologue += "\t @echo ----------------------------\n";
+
+    /* Add the documentation file to the package. */
+    Pkg.otherFiles[Pkg.otherFiles.length++] = "docs/tifooter.htm";
+    Pkg.otherFiles[Pkg.otherFiles.length++] = "docs/tiheader.htm";
+    Pkg.otherFiles[Pkg.otherFiles.length++] = "docs/tilogo.gif";
+    Pkg.otherFiles[Pkg.otherFiles.length++] = "docs/titagline.gif";
+
+    /* Add the FATFS Software Manifest to the package */
+    Pkg.otherFiles[Pkg.otherFiles.length++] = "docs/FATFS_LLD_SoftwareManifest.pdf";
+
+    /* Add the HTML documentation to the package */
+    Pkg.otherFiles[Pkg.otherFiles.length++] = "docs/doxygen";
+
+    /* Add the release notes to the package */
+    Pkg.otherFiles[Pkg.otherFiles.length++] = "docs/ReleaseNotes_FATFS_LLD.pdf";
+
+    /* Generate the ECLIPSE Plugin Generation: Only for SETUP Releases. */
+    if (driverInstallType == "SETUP")
+    {
+        Pkg.makePrologue += "all: eclipse_plugin_generation\n";
+        Pkg.makePrologue += "eclipse_plugin_generation:\n";
+        Pkg.makePrologue += "\t @echo ----------------------------\n";
+        Pkg.makePrologue += "\t @echo FATFS Eclipse Plugin Generation\n";
+        Pkg.makePrologue += "\t xs xdc.tools.eclipsePluginGen -o . -x ./eclipseDocs/sample.xml -c ./eclipseDocs/toc_cdoc_sample.xml\n";
+        Pkg.makePrologue += "\t @echo FATFS Eclipse Plugin Generated \n";
+        Pkg.makePrologue += "\t @echo ----------------------------\n";
+    }
+}
+
diff --git a/packages/ti/fs/fatfs/docs/ReleaseNotes_FATFS_LLD.doc b/packages/ti/fs/fatfs/docs/ReleaseNotes_FATFS_LLD.doc
new file mode 100644 (file)
index 0000000..8094944
Binary files /dev/null and b/packages/ti/fs/fatfs/docs/ReleaseNotes_FATFS_LLD.doc differ
diff --git a/packages/ti/fs/fatfs/docs/ReleaseNotes_FATFS_LLD.pdf b/packages/ti/fs/fatfs/docs/ReleaseNotes_FATFS_LLD.pdf
new file mode 100644 (file)
index 0000000..d7ddedf
Binary files /dev/null and b/packages/ti/fs/fatfs/docs/ReleaseNotes_FATFS_LLD.pdf differ
diff --git a/packages/ti/fs/fatfs/docs/doxyfile.xdt b/packages/ti/fs/fatfs/docs/doxyfile.xdt
new file mode 100644 (file)
index 0000000..62915ae
--- /dev/null
@@ -0,0 +1,298 @@
+%%{\r
+/*!\r
+ *  This template implements the Doxyfile\r
+ */  \r
+  /* Versioning */\r
+  var ver = this;\r
+  var packageVersion = ver[0]+"."+ver[1]+"."+ver[2]+"."+ver[3];\r
+\r
+%%}\r
+\r
+# Doxyfile 1.5.6\r
+\r
+#---------------------------------------------------------------------------\r
+# Project related configuration options\r
+#---------------------------------------------------------------------------\r
+DOXYFILE_ENCODING      = UTF-8\r
+PROJECT_NAME           = "FATFS Low Level Driver"
+PROJECT_NUMBER         = `packageVersion`\r
+OUTPUT_DIRECTORY       = ./docs/doxygen\r
+CREATE_SUBDIRS         = NO\r
+OUTPUT_LANGUAGE        = English\r
+BRIEF_MEMBER_DESC      = YES\r
+REPEAT_BRIEF           = YES\r
+ABBREVIATE_BRIEF       = "The $name class" \\r
+                         "The $name widget" \\r
+                         "The $name file" \\r
+                         is \\r
+                         provides \\r
+                         specifies \\r
+                         contains \\r
+                         represents \\r
+                         a \\r
+                         an \\r
+                         the\r
+ALWAYS_DETAILED_SEC    = NO\r
+INLINE_INHERITED_MEMB  = NO\r
+FULL_PATH_NAMES        = NO\r
+STRIP_FROM_PATH        = \r
+STRIP_FROM_INC_PATH    = \r
+SHORT_NAMES            = NO\r
+JAVADOC_AUTOBRIEF      = NO\r
+QT_AUTOBRIEF           = NO\r
+MULTILINE_CPP_IS_BRIEF = NO\r
+INHERIT_DOCS           = YES\r
+SEPARATE_MEMBER_PAGES  = NO\r
+TAB_SIZE               = 8\r
+ALIASES                = \r
+OPTIMIZE_OUTPUT_FOR_C  = YES\r
+OPTIMIZE_OUTPUT_JAVA   = NO\r
+OPTIMIZE_FOR_FORTRAN   = NO\r
+OPTIMIZE_OUTPUT_VHDL   = NO\r
+BUILTIN_STL_SUPPORT    = NO\r
+CPP_CLI_SUPPORT        = NO\r
+SIP_SUPPORT            = NO\r
+IDL_PROPERTY_SUPPORT   = YES\r
+DISTRIBUTE_GROUP_DOC   = NO\r
+SUBGROUPING            = YES\r
+TYPEDEF_HIDES_STRUCT   = NO\r
+#---------------------------------------------------------------------------\r
+# Build related configuration options\r
+#---------------------------------------------------------------------------\r
+EXTRACT_ALL            = NO\r
+EXTRACT_PRIVATE        = NO\r
+EXTRACT_STATIC         = YES\r
+EXTRACT_LOCAL_CLASSES  = YES\r
+EXTRACT_LOCAL_METHODS  = NO\r
+EXTRACT_ANON_NSPACES   = NO\r
+HIDE_UNDOC_MEMBERS     = YES\r
+HIDE_UNDOC_CLASSES     = YES\r
+HIDE_FRIEND_COMPOUNDS  = NO\r
+HIDE_IN_BODY_DOCS      = NO\r
+INTERNAL_DOCS          = NO\r
+CASE_SENSE_NAMES       = NO\r
+HIDE_SCOPE_NAMES       = NO\r
+SHOW_INCLUDE_FILES     = YES\r
+INLINE_INFO            = YES\r
+SORT_MEMBER_DOCS       = YES\r
+SORT_BRIEF_DOCS        = NO\r
+SORT_GROUP_NAMES       = NO\r
+SORT_BY_SCOPE_NAME     = NO\r
+GENERATE_TODOLIST      = YES\r
+GENERATE_TESTLIST      = YES\r
+GENERATE_BUGLIST       = YES\r
+GENERATE_DEPRECATEDLIST= YES\r
+ENABLED_SECTIONS       = \r
+MAX_INITIALIZER_LINES  = 30\r
+SHOW_USED_FILES        = YES\r
+SHOW_FILES             = YES\r
+SHOW_NAMESPACES        = YES\r
+FILE_VERSION_FILTER    = \r
+#---------------------------------------------------------------------------\r
+# configuration options related to warning and progress messages\r
+#---------------------------------------------------------------------------\r
+QUIET                  = NO\r
+WARNINGS               = YES\r
+WARN_IF_UNDOCUMENTED   = YES\r
+WARN_IF_DOC_ERROR      = YES\r
+WARN_NO_PARAMDOC       = NO\r
+WARN_FORMAT            = "$file:$line: $text"\r
+WARN_LOGFILE           = \r
+#---------------------------------------------------------------------------\r
+# configuration options related to the input files\r
+#---------------------------------------------------------------------------\r
+INPUT                  = \r
+INPUT_ENCODING         = UTF-8\r
+FILE_PATTERNS          = *.c \\r
+                         *.cc \\r
+                         *.cxx \\r
+                         *.cpp \\r
+                         *.c++ \\r
+                         *.d \\r
+                         *.java \\r
+                         *.ii \\r
+                         *.ixx \\r
+                         *.ipp \\r
+                         *.i++ \\r
+                         *.inl \\r
+                         *.h \\r
+                         *.hh \\r
+                         *.hxx \\r
+                         *.hpp \\r
+                         *.h++ \\r
+                         *.idl \\r
+                         *.odl \\r
+                         *.cs \\r
+                         *.php \\r
+                         *.php3 \\r
+                         *.inc \\r
+                         *.m \\r
+                         *.mm \\r
+                         *.dox \\r
+                         *.py \\r
+                         *.f90 \\r
+                         *.f \\r
+                         *.vhd \\r
+                         *.vhdl\r
+RECURSIVE              = YES\r
+EXCLUDE                = YES \\r
+                         ./example \\r
+                         ./test \\r
+                         ./package \\r
+                         ./packages\r
+EXCLUDE_SYMLINKS       = NO\r
+EXCLUDE_PATTERNS       = cslr_*.h\r
+EXCLUDE_SYMBOLS        = \r
+EXAMPLE_PATH           = \r
+EXAMPLE_PATTERNS       = *\r
+EXAMPLE_RECURSIVE      = NO\r
+IMAGE_PATH             = \r
+INPUT_FILTER           = \r
+FILTER_PATTERNS        = \r
+FILTER_SOURCE_FILES    = NO\r
+#---------------------------------------------------------------------------\r
+# configuration options related to source browsing\r
+#---------------------------------------------------------------------------\r
+SOURCE_BROWSER         = NO\r
+INLINE_SOURCES         = NO\r
+STRIP_CODE_COMMENTS    = YES\r
+REFERENCED_BY_RELATION = NO\r
+REFERENCES_RELATION    = NO\r
+REFERENCES_LINK_SOURCE = YES\r
+USE_HTAGS              = NO\r
+VERBATIM_HEADERS       = NO\r
+#---------------------------------------------------------------------------\r
+# configuration options related to the alphabetical class index\r
+#---------------------------------------------------------------------------\r
+ALPHABETICAL_INDEX     = NO\r
+COLS_IN_ALPHA_INDEX    = 5\r
+IGNORE_PREFIX          = \r
+#---------------------------------------------------------------------------\r
+# configuration options related to the HTML output\r
+#---------------------------------------------------------------------------\r
+GENERATE_HTML          = YES\r
+HTML_OUTPUT            = html\r
+HTML_FILE_EXTENSION    = .html\r
+HTML_HEADER            = ./docs/tiheader.htm\r
+HTML_FOOTER            = ./docs/tifooter.htm\r
+HTML_STYLESHEET        = \r
+GENERATE_HTMLHELP      = YES\r
+GENERATE_DOCSET        = NO\r
+DOCSET_FEEDNAME        = "Doxygen generated docs"\r
+DOCSET_BUNDLE_ID       = org.doxygen.Project\r
+HTML_DYNAMIC_SECTIONS  = NO\r
+CHM_FILE               = ..\..\fatfslldDocs.chm
+HHC_LOCATION           = hhc.exe\r
+GENERATE_CHI           = NO\r
+CHM_INDEX_ENCODING     = \r
+BINARY_TOC             = NO\r
+TOC_EXPAND             = NO\r
+DISABLE_INDEX          = NO\r
+ENUM_VALUES_PER_LINE   = 4\r
+GENERATE_TREEVIEW      = NONE\r
+TREEVIEW_WIDTH         = 250\r
+FORMULA_FONTSIZE       = 10\r
+#---------------------------------------------------------------------------\r
+# configuration options related to the LaTeX output\r
+#---------------------------------------------------------------------------\r
+GENERATE_LATEX         = NO\r
+LATEX_OUTPUT           = latex\r
+LATEX_CMD_NAME         = latex\r
+MAKEINDEX_CMD_NAME     = makeindex\r
+COMPACT_LATEX          = NO\r
+PAPER_TYPE             = a4wide\r
+EXTRA_PACKAGES         = \r
+LATEX_HEADER           = \r
+PDF_HYPERLINKS         = YES\r
+USE_PDFLATEX           = YES\r
+LATEX_BATCHMODE        = NO\r
+LATEX_HIDE_INDICES     = NO\r
+#---------------------------------------------------------------------------\r
+# configuration options related to the RTF output\r
+#---------------------------------------------------------------------------\r
+GENERATE_RTF           = NO\r
+RTF_OUTPUT             = rtf\r
+COMPACT_RTF            = NO\r
+RTF_HYPERLINKS         = NO\r
+RTF_STYLESHEET_FILE    = \r
+RTF_EXTENSIONS_FILE    = \r
+#---------------------------------------------------------------------------\r
+# configuration options related to the man page output\r
+#---------------------------------------------------------------------------\r
+GENERATE_MAN           = NO\r
+MAN_OUTPUT             = man\r
+MAN_EXTENSION          = .3\r
+MAN_LINKS              = NO\r
+#---------------------------------------------------------------------------\r
+# configuration options related to the XML output\r
+#---------------------------------------------------------------------------\r
+GENERATE_XML           = NO\r
+XML_OUTPUT             = xml\r
+XML_SCHEMA             = \r
+XML_DTD                = \r
+XML_PROGRAMLISTING     = YES\r
+#---------------------------------------------------------------------------\r
+# configuration options for the AutoGen Definitions output\r
+#---------------------------------------------------------------------------\r
+GENERATE_AUTOGEN_DEF   = NO\r
+#---------------------------------------------------------------------------\r
+# configuration options related to the Perl module output\r
+#---------------------------------------------------------------------------\r
+GENERATE_PERLMOD       = NO\r
+PERLMOD_LATEX          = NO\r
+PERLMOD_PRETTY         = YES\r
+PERLMOD_MAKEVAR_PREFIX = \r
+#---------------------------------------------------------------------------\r
+# Configuration options related to the preprocessor   \r
+#---------------------------------------------------------------------------\r
+ENABLE_PREPROCESSING   = YES\r
+MACRO_EXPANSION        = NO\r
+EXPAND_ONLY_PREDEF     = NO\r
+SEARCH_INCLUDES        = YES\r
+INCLUDE_PATH           = \r
+INCLUDE_FILE_PATTERNS  = \r
+PREDEFINED             = \r
+EXPAND_AS_DEFINED      = \r
+SKIP_FUNCTION_MACROS   = YES\r
+#---------------------------------------------------------------------------\r
+# Configuration::additions related to external references   \r
+#---------------------------------------------------------------------------\r
+TAGFILES               = \r
+GENERATE_TAGFILE       = \r
+ALLEXTERNALS           = NO\r
+EXTERNAL_GROUPS        = YES\r
+PERL_PATH              = /usr/bin/perl\r
+#---------------------------------------------------------------------------\r
+# Configuration options related to the dot tool   \r
+#---------------------------------------------------------------------------\r
+CLASS_DIAGRAMS         = NO\r
+MSCGEN_PATH            = \r
+HIDE_UNDOC_RELATIONS   = YES\r
+HAVE_DOT               = NO\r
+DOT_FONTPATH           = \r
+CLASS_GRAPH            = YES\r
+COLLABORATION_GRAPH    = YES\r
+GROUP_GRAPHS           = YES\r
+UML_LOOK               = NO\r
+TEMPLATE_RELATIONS     = NO\r
+INCLUDE_GRAPH          = YES\r
+INCLUDED_BY_GRAPH      = YES\r
+CALL_GRAPH             = NO\r
+CALLER_GRAPH           = NO\r
+GRAPHICAL_HIERARCHY    = YES\r
+DIRECTORY_GRAPH        = YES\r
+DOT_IMAGE_FORMAT       = png\r
+DOT_PATH               = \r
+DOTFILE_DIRS           = \r
+DOT_GRAPH_MAX_NODES    = 50\r
+MAX_DOT_GRAPH_DEPTH    = 1000\r
+DOT_TRANSPARENT        = YES\r
+DOT_MULTI_TARGETS      = NO\r
+GENERATE_LEGEND        = YES\r
+DOT_CLEANUP            = YES\r
+#---------------------------------------------------------------------------\r
+# Configuration::additions related to the search engine   \r
+#---------------------------------------------------------------------------\r
+SEARCHENGINE           = NO\r
+\r
+\r
diff --git a/packages/ti/fs/fatfs/docs/tifooter.htm b/packages/ti/fs/fatfs/docs/tifooter.htm
new file mode 100644 (file)
index 0000000..c35c513
--- /dev/null
@@ -0,0 +1,4 @@
+<hr size="1"><small>\r
+Copyright  $year, Texas Instruments Incorporated</small>\r
+</body>\r
+</html>\r
diff --git a/packages/ti/fs/fatfs/docs/tiheader.htm b/packages/ti/fs/fatfs/docs/tiheader.htm
new file mode 100644 (file)
index 0000000..c38e6fb
--- /dev/null
@@ -0,0 +1,12 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">\r
+<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">\r
+<title>$title</title>\r
+<link href="$relpath$doxygen.css" rel="stylesheet" type="text/css">\r
+<link href="$relpath$tabs.css" rel="stylesheet" type="text/css">\r
+</head><body>\r
+<table width=100%>\r
+<tr>\r
+  <td bgcolor="black" width="1"><a href="http://www.ti.com"><img border=0 src="../../tilogo.gif"></a></td>\r
+  <td bgcolor="red"><img src="../../titagline.gif"></td>\r
+</tr>\r
+</table>\r
diff --git a/packages/ti/fs/fatfs/docs/tilogo.gif b/packages/ti/fs/fatfs/docs/tilogo.gif
new file mode 100644 (file)
index 0000000..f2fab2d
Binary files /dev/null and b/packages/ti/fs/fatfs/docs/tilogo.gif differ
diff --git a/packages/ti/fs/fatfs/docs/titagline.gif b/packages/ti/fs/fatfs/docs/titagline.gif
new file mode 100644 (file)
index 0000000..743a024
Binary files /dev/null and b/packages/ti/fs/fatfs/docs/titagline.gif differ
diff --git a/packages/ti/fs/fatfs/example/Module.xs b/packages/ti/fs/fatfs/example/Module.xs
new file mode 100644 (file)
index 0000000..313ed1c
--- /dev/null
@@ -0,0 +1,64 @@
+/******************************************************************************
+ * FILE PURPOSE: FATFS LLD example files.
+ ******************************************************************************
+ * FILE NAME: module.xs
+ *
+ * DESCRIPTION: 
+ *  This file contains the module specification for FATFS LLD example files.
+ *
+ * Copyright (C) 2009, Texas Instruments, Inc.
+ *****************************************************************************/
+
+/* Load the library utility. */
+var libUtility = xdc.loadCapsule ("../build/buildlib.xs");
+
+/**************************************************************************
+ * FUNCTION NAME : modBuild
+ **************************************************************************
+ * DESCRIPTION   :
+ *  The function is used to add all the source files in the example 
+ *  directory into the package.
+ **************************************************************************/
+function modBuild() 
+{
+    /* Add all the .c files to the release package. */
+    var exampleFiles = libUtility.listAllFiles (".c", "example", true);
+    for (var k = 0 ; k < exampleFiles.length; k++)
+        Pkg.otherFiles[Pkg.otherFiles.length++] = exampleFiles[k];
+
+    /* Add all the .h files to the release package. */
+    var exampleFiles = libUtility.listAllFiles (".h", "example", true);
+    for (var k = 0 ; k < exampleFiles.length; k++)
+        Pkg.otherFiles[Pkg.otherFiles.length++] = exampleFiles[k];
+
+    /* Add all the .cmd files to the release package. */
+    var exampleFiles = libUtility.listAllFiles (".cmd", "example", true);
+    for (var k = 0 ; k < exampleFiles.length; k++)
+        Pkg.otherFiles[Pkg.otherFiles.length++] = exampleFiles[k];
+
+    /* Add all the .cfg files to the release package. */
+    var exampleFiles = libUtility.listAllFiles (".cfg", "example", true);
+    for (var k = 0 ; k < exampleFiles.length; k++)
+        Pkg.otherFiles[Pkg.otherFiles.length++] = exampleFiles[k];
+
+    /* Add all the make files to the release package. */
+    var exampleFiles = libUtility.listAllFiles ("makefile", "example", true);
+    for (var k = 0 ; k < exampleFiles.length; k++)
+        Pkg.otherFiles[Pkg.otherFiles.length++] = exampleFiles[k];
+
+    /* Add the .txt to the package */
+    var exampleFiles = libUtility.listAllFiles (".txt", "example", true);
+    for (var k = 0 ; k < exampleFiles.length; k++)
+        Pkg.otherFiles[Pkg.otherFiles.length++] = exampleFiles[k];
+
+    /* Add all the .xs files to the release package. */
+    var exampleFiles = libUtility.listAllFiles (".xs", "example", true);
+    for (var k = 0 ; k < exampleFiles.length; k++)
+        Pkg.otherFiles[Pkg.otherFiles.length++] = exampleFiles[k];
+
+    /* Add all the .mk files to the release package. */
+    var mkFiles = libUtility.listAllFiles (".mk", "example", true);
+    for (var k = 0 ; k < mkFiles.length; k++)
+        Pkg.otherFiles[Pkg.otherFiles.length++] = mkFiles[k];
+
+}
diff --git a/packages/ti/fs/fatfs/example/console/am335x/armv7/bios/FATFS_Console_evmAM335x_armExampleProject.txt b/packages/ti/fs/fatfs/example/console/am335x/armv7/bios/FATFS_Console_evmAM335x_armExampleProject.txt
new file mode 100644 (file)
index 0000000..ddebb1b
--- /dev/null
@@ -0,0 +1,9 @@
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/mmcsd/soc/am335x/MMCSD_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/fs_shell_app_utils.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/main_console.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/FATFS_log.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/uart/soc/am335x/UART_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/gpio/soc/am335x/GPIO_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/am335x/armv7/bios/fatfs_evm.cfg"
+-ccs.setCompilerOptions "-c -mcpu=cortex-a8 -mtune=cortex-a8 -march=armv7-a -marm -mfloat-abi=hard  -DSOC_AM335x -DevmAM335x -g -gstrict-dwarf -Wall -MMD -MP -I${PDK_INSTALL_PATH}/ti/fs/fatfs "  -rtsc.enableRtsc
+-ccs.setLinkerOptions " -lrdimon -lgcc -lm -lnosys -nostartfiles -static -Wl,--gc-sections -L$(BIOS_INSTALL_PATH)/packages/gnu/targets/arm/libs/install-native/arm-none-eabi/lib/fpu "
diff --git a/packages/ti/fs/fatfs/example/console/am335x/armv7/bios/FATFS_Console_icev2AM335x_armExampleProject.txt b/packages/ti/fs/fatfs/example/console/am335x/armv7/bios/FATFS_Console_icev2AM335x_armExampleProject.txt
new file mode 100644 (file)
index 0000000..379c8df
--- /dev/null
@@ -0,0 +1,9 @@
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/mmcsd/soc/am335x/MMCSD_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/fs_shell_app_utils.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/main_console.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/FATFS_log.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/uart/soc/am335x/UART_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/gpio/soc/am335x/GPIO_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/am335x/armv7/bios/fatfs_icev2.cfg"
+-ccs.setCompilerOptions "-c -mcpu=cortex-a8 -mtune=cortex-a8 -march=armv7-a -marm -mfloat-abi=hard  -DSOC_AM335x -Dicev2AM335x -g -gstrict-dwarf -Wall -MMD -MP -I${PDK_INSTALL_PATH}/ti/fs/fatfs "  -rtsc.enableRtsc
+-ccs.setLinkerOptions " -lrdimon -lgcc -lm -lnosys -nostartfiles -static -Wl,--gc-sections -L$(BIOS_INSTALL_PATH)/packages/gnu/targets/arm/libs/install-native/arm-none-eabi/lib/fpu "
diff --git a/packages/ti/fs/fatfs/example/console/am335x/armv7/bios/fatfs_evm.cfg b/packages/ti/fs/fatfs/example/console/am335x/armv7/bios/fatfs_evm.cfg
new file mode 100644 (file)
index 0000000..4ee659b
--- /dev/null
@@ -0,0 +1,216 @@
+/**
+ *  \file   fatfs_evm.cfg
+ *
+ *  \brief  Sysbios config file for fatfs example project on AM335x GP EVM.
+ *
+ */
+
+/*
+ * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of Texas Instruments Incorporated nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/* ================ General configuration ================ */
+var Defaults = xdc.useModule('xdc.runtime.Defaults');
+var Diags = xdc.useModule('xdc.runtime.Diags');
+var Error = xdc.useModule('xdc.runtime.Error');
+var Main = xdc.useModule('xdc.runtime.Main');
+var Memory = xdc.useModule('xdc.runtime.Memory')
+var SysMin = xdc.useModule('xdc.runtime.SysMin');
+var System = xdc.useModule('xdc.runtime.System');
+var Text = xdc.useModule('xdc.runtime.Text');
+var Clock = xdc.useModule('ti.sysbios.knl.Clock');
+var Swi = xdc.useModule('ti.sysbios.knl.Swi');
+var Task = xdc.useModule('ti.sysbios.knl.Task');
+var Semaphore = xdc.useModule('ti.sysbios.knl.Semaphore');
+var Hwi = xdc.useModule('ti.sysbios.hal.Hwi');
+var Timer = xdc.useModule('ti.sysbios.hal.Timer');
+var HeapMem = xdc.useModule('ti.sysbios.heaps.HeapMem');
+var SemihostSupport = xdc.useModule('ti.sysbios.rts.gnu.SemiHostSupport');
+
+/* 
+ * Program.argSize sets the size of the .args section. 
+ * The examples don't use command line args so argSize is set to 0.
+ */
+Program.argSize = 0x0;
+
+/* System stack size (used by ISRs and Swis) */
+Program.stack = 0x4000;
+
+/*
+ * Uncomment this line to globally disable Asserts.
+ * All modules inherit the default from the 'Defaults' module.  You
+ * can override these defaults on a per-module basis using Module.common$. 
+ * Disabling Asserts will save code space and improve runtime performance.
+Defaults.common$.diags_ASSERT = Diags.ALWAYS_OFF;
+ */
+Defaults.common$.diags_ASSERT = Diags.ALWAYS_OFF;
+
+
+/*
+ * Uncomment this line to keep module names from being loaded on the target.
+ * The module name strings are placed in the .const section. Setting this
+ * parameter to false will save space in the .const section.  Error and
+ * Assert messages will contain an "unknown module" prefix instead
+ * of the actual module name.
+Defaults.common$.namedModule = false;
+ */
+Defaults.common$.namedModule = false;
+
+/*
+ * Minimize exit handler array in System.  The System module includes
+ * an array of functions that are registered with System_atexit() to be
+ * called by System_exit().
+ */
+System.maxAtexitHandlers = 4;
+
+/* 
+ * Uncomment this line to disable the Error print function.  
+ * We lose error information when this is disabled since the errors are
+ * not printed.  Disabling the raiseHook will save some code space if
+ * your app is not using System_printf() since the Error_print() function
+ * calls System_printf().
+Error.raiseHook = null;
+ */
+Error.raiseHook = null;
+
+/* 
+ * Uncomment this line to keep Error, Assert, and Log strings from being
+ * loaded on the target.  These strings are placed in the .const section.
+ * Setting this parameter to false will save space in the .const section.
+ * Error, Assert and Log message will print raw ids and args instead of
+ * a formatted message.
+Text.isLoaded = false;
+ */
+Text.isLoaded = false;
+
+/*
+ * Uncomment this line to disable the output of characters by SysMin
+ * when the program exits.  SysMin writes characters to a circular buffer.
+ * This buffer can be viewed using the SysMin Output view in ROV.
+ */
+SysMin.flushAtExit = false;
+
+
+/* ================ BIOS configuration ================ */
+
+var BIOS = xdc.useModule('ti.sysbios.BIOS');
+BIOS.libType = BIOS.LibType_Custom;
+BIOS.assertsEnabled = false;
+BIOS.logsEnabled = false;
+BIOS.swiEnabled = false;
+BIOS.customCCOpts = BIOS.customCCOpts.replace(" -g ","");
+
+/*
+ * The BIOS module will create the default heap for the system.
+ * Specify the size of this default heap.
+ */
+BIOS.heapSize = 32000;
+
+Swi.common$.namedInstance = true;
+
+Program.sectionsExclude = ".*";
+
+Clock.tickPeriod = 1000;
+Hwi.dispatcherSwiSupport = true;
+Hwi.dispatcherTaskSupport = true;
+Hwi.dispatcherAutoNestingSupport = true;
+
+Task.enableIdleTask = false;
+Task.initStackFlag = false;
+Task.checkStackFlag = false;
+
+
+/* ================ Driver configuration ================ */
+var socType="am335x";
+
+/*use CSL package*/
+var Csl = xdc.loadPackage('ti.csl');
+Csl.Settings.deviceType = socType;
+
+/* Load the OSAL package */
+var osType = "tirtos";
+var Osal = xdc.useModule('ti.osal.Settings');
+Osal.osType = osType;
+Osal.socType = socType;
+/* Load the I2C package required by board */
+var I2C               = xdc.loadPackage('ti.drv.i2c');
+I2C.Settings.socType  = socType;
+
+/* Load the board package */
+var Board = xdc.loadPackage('ti.board');
+Board.Settings.boardName = "evmAM335x";
+
+/* Load the GPIO package */
+var GPIO = xdc.loadPackage('ti.drv.gpio');
+
+/* Load the uart package */
+var UartPackage = xdc.loadPackage('ti.drv.uart');
+
+/* Load the MMCSD package */
+var Mmcsd = xdc.loadPackage('ti.drv.mmcsd');
+var Fatfs = xdc.loadPackage('ti.fs.fatfs');
+
+
+/* ================ Cache and MMU configuration ================ */
+
+var Cache = xdc.useModule('ti.sysbios.family.arm.a8.Cache');
+Cache.enableCache = true; 
+
+var Mmu = xdc.useModule('ti.sysbios.family.arm.a8.Mmu');
+Mmu.enableMMU = true;
+
+/* Force peripheral section to be NON cacheable strongly-ordered memory */
+var peripheralAttrs = {
+    type : Mmu.FirstLevelDesc_SECTION, // SECTION descriptor
+    tex: 0,
+    bufferable : false,                // bufferable
+    cacheable  : false,                // cacheable
+    shareable  : false,                // shareable
+    noexecute  : true,                 // not executable
+};
+
+/* Define the base address of the 1 Meg page the peripheral resides in. */
+var peripheralBaseAddr = 0x44e00400;
+
+/* Configure the corresponding MMU page descriptor accordingly */
+Mmu.setFirstLevelDescMeta(peripheralBaseAddr,
+                          peripheralBaseAddr,
+                          peripheralAttrs);
+
+                          
+/* Define the base address of the 1 Meg page the peripheral resides in. */
+var peripheralBaseAddr = 0x481a6000;
+
+/* Configure the corresponding MMU page descriptor accordingly */
+Mmu.setFirstLevelDescMeta(peripheralBaseAddr,
+                          peripheralBaseAddr,
+                          peripheralAttrs);
diff --git a/packages/ti/fs/fatfs/example/console/am335x/armv7/bios/fatfs_icev2.cfg b/packages/ti/fs/fatfs/example/console/am335x/armv7/bios/fatfs_icev2.cfg
new file mode 100644 (file)
index 0000000..4f64ef3
--- /dev/null
@@ -0,0 +1,212 @@
+/**
+ *  \file   fatfs_icev2.cfg
+ *
+ *  \brief  Sysbios config file for fatfs example project on AM335X iceV2 EVM.
+ *
+ */
+
+/*
+ * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of Texas Instruments Incorporated nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/* ================ General configuration ================ */
+var Defaults = xdc.useModule('xdc.runtime.Defaults');
+var Diags = xdc.useModule('xdc.runtime.Diags');
+var Error = xdc.useModule('xdc.runtime.Error');
+var Main = xdc.useModule('xdc.runtime.Main');
+var Memory = xdc.useModule('xdc.runtime.Memory')
+var SysMin = xdc.useModule('xdc.runtime.SysMin');
+var System = xdc.useModule('xdc.runtime.System');
+var Text = xdc.useModule('xdc.runtime.Text');
+var Clock = xdc.useModule('ti.sysbios.knl.Clock');
+var Swi = xdc.useModule('ti.sysbios.knl.Swi');
+var Task = xdc.useModule('ti.sysbios.knl.Task');
+var Semaphore = xdc.useModule('ti.sysbios.knl.Semaphore');
+var Hwi = xdc.useModule('ti.sysbios.hal.Hwi');
+var Timer = xdc.useModule('ti.sysbios.hal.Timer');
+var HeapMem = xdc.useModule('ti.sysbios.heaps.HeapMem');
+var SemihostSupport = xdc.useModule('ti.sysbios.rts.gnu.SemiHostSupport');
+
+/* 
+ * Program.argSize sets the size of the .args section. 
+ * The examples don't use command line args so argSize is set to 0.
+ */
+Program.argSize = 0x0;
+
+/* System stack size (used by ISRs and Swis) */
+Program.stack = 0x4000;
+
+/*
+ * Uncomment this line to globally disable Asserts.
+ * All modules inherit the default from the 'Defaults' module.  You
+ * can override these defaults on a per-module basis using Module.common$. 
+ * Disabling Asserts will save code space and improve runtime performance.
+Defaults.common$.diags_ASSERT = Diags.ALWAYS_OFF;
+ */
+Defaults.common$.diags_ASSERT = Diags.ALWAYS_OFF;
+
+
+/*
+ * Uncomment this line to keep module names from being loaded on the target.
+ * The module name strings are placed in the .const section. Setting this
+ * parameter to false will save space in the .const section.  Error and
+ * Assert messages will contain an "unknown module" prefix instead
+ * of the actual module name.
+Defaults.common$.namedModule = false;
+ */
+Defaults.common$.namedModule = false;
+
+/*
+ * Minimize exit handler array in System.  The System module includes
+ * an array of functions that are registered with System_atexit() to be
+ * called by System_exit().
+ */
+System.maxAtexitHandlers = 4;
+
+/* 
+ * Uncomment this line to disable the Error print function.  
+ * We lose error information when this is disabled since the errors are
+ * not printed.  Disabling the raiseHook will save some code space if
+ * your app is not using System_printf() since the Error_print() function
+ * calls System_printf().
+Error.raiseHook = null;
+ */
+Error.raiseHook = null;
+/* 
+ * Uncomment this line to keep Error, Assert, and Log strings from being
+ * loaded on the target.  These strings are placed in the .const section.
+ * Setting this parameter to false will save space in the .const section.
+ * Error, Assert and Log message will print raw ids and args instead of
+ * a formatted message.
+Text.isLoaded = false;
+ */
+Text.isLoaded = false;
+/*
+ * Uncomment this line to disable the output of characters by SysMin
+ * when the program exits.  SysMin writes characters to a circular buffer.
+ * This buffer can be viewed using the SysMin Output view in ROV.
+ */
+SysMin.flushAtExit = false;
+
+
+/* ================ BIOS configuration ================ */
+var BIOS = xdc.useModule('ti.sysbios.BIOS');
+BIOS.libType = BIOS.LibType_Custom;
+BIOS.logsEnabled = false;
+BIOS.swiEnabled = false;
+BIOS.assertsEnabled = false;
+BIOS.customCCOpts = BIOS.customCCOpts.replace(" -g ","");
+
+/*
+ * The BIOS module will create the default heap for the system.
+ * Specify the size of this default heap.
+ */
+BIOS.heapSize = 32000;
+
+Swi.common$.namedInstance = true;
+Program.sectionsExclude = ".*";
+
+Clock.tickPeriod = 1000;
+Hwi.dispatcherSwiSupport = true;
+Hwi.dispatcherTaskSupport = true;
+Hwi.dispatcherAutoNestingSupport = true;
+
+Task.enableIdleTask = false;
+Task.initStackFlag = false;
+Task.checkStackFlag = false;
+
+/* ================ Driver configuration ================ */
+var socType="am335x";
+
+/*use CSL package*/
+var Csl = xdc.loadPackage('ti.csl');
+Csl.Settings.deviceType = socType;
+
+
+/* Load the OSAL package */
+var osType = "tirtos";
+var Osal = xdc.useModule('ti.osal.Settings');
+Osal.osType = osType;
+Osal.socType = socType;
+/* Load the I2C package required by board */
+var I2C               = xdc.loadPackage('ti.drv.i2c');
+I2C.Settings.socType  = socType;
+
+/* Load the board package */
+var Board = xdc.loadPackage('ti.board');
+Board.Settings.boardName = "icev2AM335x";
+
+/* Load the GPIO package */
+var GPIO = xdc.loadPackage('ti.drv.gpio');
+
+/* Load the uart package */
+var UartPackage = xdc.loadPackage('ti.drv.uart');
+
+/* Load the MMCSD package */
+var Mmcsd = xdc.loadPackage('ti.drv.mmcsd');
+var Fatfs = xdc.loadPackage('ti.fs.fatfs');
+
+
+/* ================ Cache and MMU configuration ================ */
+var Cache = xdc.useModule('ti.sysbios.family.arm.a8.Cache');
+Cache.enableCache = true; 
+
+var Mmu = xdc.useModule('ti.sysbios.family.arm.a8.Mmu');
+Mmu.enableMMU = true;
+
+/* Force peripheral section to be NON cacheable strongly-ordered memory */
+var peripheralAttrs = {
+    type : Mmu.FirstLevelDesc_SECTION, // SECTION descriptor
+    tex: 0,
+    bufferable : false,                // bufferable
+    cacheable  : false,                // cacheable
+    shareable  : false,                // shareable
+    noexecute  : true,                 // not executable
+};
+
+/* Define the base address of the 1 Meg page the peripheral resides in. */
+var peripheralBaseAddr = 0x44e00400;;
+
+/* Configure the corresponding MMU page descriptor accordingly */
+Mmu.setFirstLevelDescMeta(peripheralBaseAddr,
+                          peripheralBaseAddr,
+                          peripheralAttrs);
+
+                          
+/* Define the base address of the 1 Meg page the peripheral resides in. */
+var peripheralBaseAddr = 0x481a6000;
+
+/* Configure the corresponding MMU page descriptor accordingly */
+Mmu.setFirstLevelDescMeta(peripheralBaseAddr,
+                          peripheralBaseAddr,
+                          peripheralAttrs);
+                                                                               
diff --git a/packages/ti/fs/fatfs/example/console/am437x/armv7/bios/FATFS_Console_evmAM437x_armExampleProject.txt b/packages/ti/fs/fatfs/example/console/am437x/armv7/bios/FATFS_Console_evmAM437x_armExampleProject.txt
new file mode 100644 (file)
index 0000000..222f354
--- /dev/null
@@ -0,0 +1,9 @@
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/mmcsd/soc/am437x/MMCSD_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/fs_shell_app_utils.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/main_console.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/FATFS_log.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/uart/soc/am437x/UART_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/gpio/soc/am437x/GPIO_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/am437x/armv7/bios/fatfs_evm.cfg"
+-ccs.setCompilerOptions "-c -mcpu=cortex-a9 -mtune=cortex-a9 -march=armv7-a -marm -mfloat-abi=hard -DSOC_AM437x -DevmAM437x -g -gstrict-dwarf -Wall -MMD -MP -I${PDK_INSTALL_PATH}/ti/fs/fatfs "  -rtsc.enableRtsc
+-ccs.setLinkerOptions " -lrdimon -lgcc -lm -lnosys -nostartfiles -static -Wl,--gc-sections -L$(BIOS_INSTALL_PATH)/packages/gnu/targets/arm/libs/install-native/arm-none-eabi/lib/fpu "
diff --git a/packages/ti/fs/fatfs/example/console/am437x/armv7/bios/FATFS_Console_idkAM437x_armExampleProject.txt b/packages/ti/fs/fatfs/example/console/am437x/armv7/bios/FATFS_Console_idkAM437x_armExampleProject.txt
new file mode 100644 (file)
index 0000000..92dd813
--- /dev/null
@@ -0,0 +1,9 @@
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/mmcsd/soc/am437x/MMCSD_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/fs_shell_app_utils.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/main_console.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/FATFS_log.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/uart/soc/am437x/UART_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/gpio/soc/am437x/GPIO_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/am437x/armv7/bios/fatfs_idk.cfg"
+-ccs.setCompilerOptions "-c -mcpu=cortex-a9 -mtune=cortex-a9 -march=armv7-a -marm -mfloat-abi=hard -DSOC_AM437x -DidkAM437x -g -gstrict-dwarf -Wall -MMD -MP -I${PDK_INSTALL_PATH}/ti/fs/fatfs "  -rtsc.enableRtsc
+-ccs.setLinkerOptions " -lrdimon -lgcc -lm -lnosys -nostartfiles -static -Wl,--gc-sections -L$(BIOS_INSTALL_PATH)/packages/gnu/targets/arm/libs/install-native/arm-none-eabi/lib/fpu "
diff --git a/packages/ti/fs/fatfs/example/console/am437x/armv7/bios/fatfs_evm.cfg b/packages/ti/fs/fatfs/example/console/am437x/armv7/bios/fatfs_evm.cfg
new file mode 100644 (file)
index 0000000..755c2d3
--- /dev/null
@@ -0,0 +1,213 @@
+/**
+ *  \file   fatfs_evm.cfg
+ *
+ *  \brief  Sysbios config file for fatfs example project on AM437x GP EVM.
+ *
+ */
+
+/*
+ * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of Texas Instruments Incorporated nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/* ================ General configuration ================ */
+var Defaults = xdc.useModule('xdc.runtime.Defaults');
+var Diags = xdc.useModule('xdc.runtime.Diags');
+var Error = xdc.useModule('xdc.runtime.Error');
+var Main = xdc.useModule('xdc.runtime.Main');
+var Memory = xdc.useModule('xdc.runtime.Memory')
+var SysMin = xdc.useModule('xdc.runtime.SysMin');
+var System = xdc.useModule('xdc.runtime.System');
+var Text = xdc.useModule('xdc.runtime.Text');
+var Clock = xdc.useModule('ti.sysbios.knl.Clock');
+var Swi = xdc.useModule('ti.sysbios.knl.Swi');
+var Task = xdc.useModule('ti.sysbios.knl.Task');
+var Semaphore = xdc.useModule('ti.sysbios.knl.Semaphore');
+var Hwi = xdc.useModule('ti.sysbios.hal.Hwi');
+var Timer = xdc.useModule('ti.sysbios.hal.Timer');
+var HeapMem = xdc.useModule('ti.sysbios.heaps.HeapMem');
+var SemihostSupport = xdc.useModule('ti.sysbios.rts.gnu.SemiHostSupport');
+
+/* 
+ * Program.argSize sets the size of the .args section. 
+ * The examples don't use command line args so argSize is set to 0.
+ */
+Program.argSize = 0x0;
+
+/* System stack size (used by ISRs and Swis) */
+Program.stack = 0x4000;
+
+/*
+ * Uncomment this line to globally disable Asserts.
+ * All modules inherit the default from the 'Defaults' module.  You
+ * can override these defaults on a per-module basis using Module.common$. 
+ * Disabling Asserts will save code space and improve runtime performance.
+Defaults.common$.diags_ASSERT = Diags.ALWAYS_OFF;
+ */
+Defaults.common$.diags_ASSERT = Diags.ALWAYS_OFF;
+
+
+/*
+ * Uncomment this line to keep module names from being loaded on the target.
+ * The module name strings are placed in the .const section. Setting this
+ * parameter to false will save space in the .const section.  Error and
+ * Assert messages will contain an "unknown module" prefix instead
+ * of the actual module name.
+Defaults.common$.namedModule = false;
+ */
+Defaults.common$.namedModule = false;
+
+/*
+ * Minimize exit handler array in System.  The System module includes
+ * an array of functions that are registered with System_atexit() to be
+ * called by System_exit().
+ */
+System.maxAtexitHandlers = 4;
+
+/* 
+ * Uncomment this line to disable the Error print function.  
+ * We lose error information when this is disabled since the errors are
+ * not printed.  Disabling the raiseHook will save some code space if
+ * your app is not using System_printf() since the Error_print() function
+ * calls System_printf().
+Error.raiseHook = null;
+ */
+Error.raiseHook = null;
+/* 
+ * Uncomment this line to keep Error, Assert, and Log strings from being
+ * loaded on the target.  These strings are placed in the .const section.
+ * Setting this parameter to false will save space in the .const section.
+ * Error, Assert and Log message will print raw ids and args instead of
+ * a formatted message.
+Text.isLoaded = false;
+ */
+Text.isLoaded = false;
+
+/*
+ * Uncomment this line to disable the output of characters by SysMin
+ * when the program exits.  SysMin writes characters to a circular buffer.
+ * This buffer can be viewed using the SysMin Output view in ROV.
+ */
+SysMin.flushAtExit = false;
+
+/* ================ BIOS configuration ================ */
+var BIOS = xdc.useModule('ti.sysbios.BIOS');
+BIOS.libType = BIOS.LibType_Custom;
+BIOS.logsEnabled = false;
+BIOS.swiEnabled = false;
+BIOS.assertsEnabled = false;
+BIOS.customCCOpts = BIOS.customCCOpts.replace(" -g ","");
+BIOS.cpuFreq.lo = 600000000;
+/*
+ * The BIOS module will create the default heap for the system.
+ * Specify the size of this default heap.
+ */
+BIOS.heapSize = 32000;
+
+Swi.common$.namedInstance = true;
+Program.sectionsExclude = ".*";
+
+Clock.tickPeriod = 1000;
+Hwi.dispatcherSwiSupport = false;
+Hwi.dispatcherTaskSupport = true;
+Hwi.dispatcherAutoNestingSupport = true;
+Hwi.initStackFlag = false;
+Hwi.checkStackFlag = false;
+
+Task.enableIdleTask = false;
+Task.initStackFlag = false;
+Task.checkStackFlag = false;
+
+
+
+/* ================ Driver configuration ================ */
+var socType="am437x";
+/*use CSL package*/
+var Csl = xdc.loadPackage('ti.csl');
+Csl.Settings.deviceType = socType;
+
+/* Load the OSAL package */
+var osType = "tirtos";
+var Osal = xdc.useModule('ti.osal.Settings');
+Osal.osType = osType;
+Osal.socType = socType;
+/* Load the I2C package required by board */
+var I2C               = xdc.loadPackage('ti.drv.i2c');
+I2C.Settings.socType  = socType;
+
+
+/* Load the board package */
+var Board = xdc.loadPackage('ti.board');
+Board.Settings.boardName = "evmAM437x";
+
+/* Load the MMCSD package */
+var Mmcsd = xdc.loadPackage('ti.drv.mmcsd');
+var Fatfs = xdc.loadPackage('ti.fs.fatfs');
+
+/* Load the GPIO package */
+var GPIO = xdc.loadPackage('ti.drv.gpio');
+
+/* Load the UART package */
+var UARTPackage = xdc.loadPackage('ti.drv.uart');
+
+/* ================ Cache and MMU configuration ================ */
+
+var Cache = xdc.useModule('ti.sysbios.family.arm.a9.Cache');
+Cache.enableCache = true; 
+Cache.configureL2Sram = false;//DDR build
+
+var Mmu = xdc.useModule('ti.sysbios.family.arm.a8.Mmu');
+Mmu.enableMMU = true;
+
+/* Force peripheral section to be NON cacheable strongly-ordered memory */
+var peripheralAttrs = {
+    type : Mmu.FirstLevelDesc_SECTION, // SECTION descriptor
+    tex: 0,
+    bufferable : false,                // bufferable
+    cacheable  : false,                // cacheable
+    shareable  : false,                // shareable
+    noexecute  : true,                 // not executable
+};
+
+/* Define the base address of the 1 Meg page the peripheral resides in. */
+var peripheralBaseAddr = 0x44DF2800;
+
+/* Configure the corresponding MMU page descriptor accordingly */
+Mmu.setFirstLevelDescMeta(peripheralBaseAddr,
+                          peripheralBaseAddr,
+                          peripheralAttrs);
+                          
+var peripheralBaseAddr = 0x44e0b000;
+
+/* Configure the corresponding MMU page descriptor accordingly */
+Mmu.setFirstLevelDescMeta(peripheralBaseAddr,
+                          peripheralBaseAddr,
+                          peripheralAttrs);
diff --git a/packages/ti/fs/fatfs/example/console/am437x/armv7/bios/fatfs_idk.cfg b/packages/ti/fs/fatfs/example/console/am437x/armv7/bios/fatfs_idk.cfg
new file mode 100644 (file)
index 0000000..a8cfc9b
--- /dev/null
@@ -0,0 +1,212 @@
+/**
+ *  \file   fatfs_idk.cfg
+ *
+ *  \brief  Sysbios config file for fatfs example project on AM437x IDK EVM.
+ *
+ */
+
+/*
+ * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of Texas Instruments Incorporated nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/* ================ General configuration ================ */ 
+var Defaults = xdc.useModule('xdc.runtime.Defaults');
+var Diags = xdc.useModule('xdc.runtime.Diags');
+var Error = xdc.useModule('xdc.runtime.Error');
+var Main = xdc.useModule('xdc.runtime.Main');
+var Memory = xdc.useModule('xdc.runtime.Memory')
+var SysMin = xdc.useModule('xdc.runtime.SysMin');
+var System = xdc.useModule('xdc.runtime.System');
+var Text = xdc.useModule('xdc.runtime.Text');
+var Clock = xdc.useModule('ti.sysbios.knl.Clock');
+var Swi = xdc.useModule('ti.sysbios.knl.Swi');
+var Task = xdc.useModule('ti.sysbios.knl.Task');
+var Semaphore = xdc.useModule('ti.sysbios.knl.Semaphore');
+var Hwi = xdc.useModule('ti.sysbios.hal.Hwi');
+var Timer = xdc.useModule('ti.sysbios.hal.Timer');
+var HeapMem = xdc.useModule('ti.sysbios.heaps.HeapMem');
+var SemihostSupport = xdc.useModule('ti.sysbios.rts.gnu.SemiHostSupport');
+
+/* 
+ * Program.argSize sets the size of the .args section. 
+ * The examples don't use command line args so argSize is set to 0.
+ */
+Program.argSize = 0x0;
+
+/* System stack size (used by ISRs and Swis) */
+Program.stack = 0x4000;
+
+/*
+ * Uncomment this line to globally disable Asserts.
+ * All modules inherit the default from the 'Defaults' module.  You
+ * can override these defaults on a per-module basis using Module.common$. 
+ * Disabling Asserts will save code space and improve runtime performance.
+Defaults.common$.diags_ASSERT = Diags.ALWAYS_OFF;
+ */
+Defaults.common$.diags_ASSERT = Diags.ALWAYS_OFF;
+
+/*
+ * Uncomment this line to keep module names from being loaded on the target.
+ * The module name strings are placed in the .const section. Setting this
+ * parameter to false will save space in the .const section.  Error and
+ * Assert messages will contain an "unknown module" prefix instead
+ * of the actual module name.
+Defaults.common$.namedModule = false;
+ */
+Defaults.common$.namedModule = false;
+
+/*
+ * Minimize exit handler array in System.  The System module includes
+ * an array of functions that are registered with System_atexit() to be
+ * called by System_exit().
+ */
+System.maxAtexitHandlers = 4;
+
+/* 
+ * Uncomment this line to disable the Error print function.  
+ * We lose error information when this is disabled since the errors are
+ * not printed.  Disabling the raiseHook will save some code space if
+ * your app is not using System_printf() since the Error_print() function
+ * calls System_printf().
+Error.raiseHook = null;
+ */
+Error.raiseHook = null;
+
+/* 
+ * Uncomment this line to keep Error, Assert, and Log strings from being
+ * loaded on the target.  These strings are placed in the .const section.
+ * Setting this parameter to false will save space in the .const section.
+ * Error, Assert and Log message will print raw ids and args instead of
+ * a formatted message.
+Text.isLoaded = false;
+ */
+Text.isLoaded = false;
+
+/*
+ * Uncomment this line to disable the output of characters by SysMin
+ * when the program exits.  SysMin writes characters to a circular buffer.
+ * This buffer can be viewed using the SysMin Output view in ROV.
+ */
+SysMin.flushAtExit = false;
+
+/* ================ BIOS configuration ================ */
+var BIOS = xdc.useModule('ti.sysbios.BIOS');
+BIOS.libType = BIOS.LibType_Custom;
+BIOS.assertsEnabled = false;
+BIOS.logsEnabled = false;
+BIOS.swiEnabled = false;
+BIOS.customCCOpts = BIOS.customCCOpts.replace(" -g ","");
+BIOS.cpuFreq.lo = 600000000;
+/*
+ * The BIOS module will create the default heap for the system.
+ * Specify the size of this default heap.
+ */
+BIOS.heapSize = 32000;
+
+Swi.common$.namedInstance = true;
+Program.sectionsExclude = ".*";
+
+Clock.tickPeriod = 1000;
+Hwi.dispatcherSwiSupport = false;
+Hwi.dispatcherTaskSupport = true;
+Hwi.dispatcherAutoNestingSupport = true;
+Hwi.initStackFlag = false;
+Hwi.checkStackFlag = false;
+
+Task.enableIdleTask = false;
+Task.initStackFlag = false;
+Task.checkStackFlag = false;
+
+
+
+/* ================ Driver configuration ================ */
+var socType="am437x";
+/*use CSL package*/
+var Csl = xdc.loadPackage('ti.csl');
+Csl.Settings.deviceType = socType;
+
+/* Load the OSAL package */
+var osType = "tirtos";
+var Osal = xdc.useModule('ti.osal.Settings');
+Osal.osType = osType;
+Osal.socType = socType;
+/* Load the I2C package required by board */
+var I2C               = xdc.loadPackage('ti.drv.i2c');
+I2C.Settings.socType  = socType;
+
+/* Load the board package */
+var Board = xdc.loadPackage('ti.board');
+Board.Settings.boardName = "idkAM437x";
+
+/* Load the MMCSD package */
+var Mmcsd = xdc.loadPackage('ti.drv.mmcsd');
+var Fatfs = xdc.loadPackage('ti.fs.fatfs');
+
+/* Load the GPIO package */
+var GPIO = xdc.loadPackage('ti.drv.gpio');
+
+/* Load the UART package */
+var UARTPackage = xdc.loadPackage('ti.drv.uart');
+
+/* ================ Cache and MMU configuration ================ */
+
+var Cache = xdc.useModule('ti.sysbios.family.arm.a9.Cache');
+Cache.enableCache = true; 
+Cache.configureL2Sram = false;//DDR build
+
+var Mmu = xdc.useModule('ti.sysbios.family.arm.a8.Mmu');
+Mmu.enableMMU = true;
+
+/* Force peripheral section to be NON cacheable strongly-ordered memory */
+var peripheralAttrs = {
+    type : Mmu.FirstLevelDesc_SECTION, // SECTION descriptor
+    tex: 0,
+    bufferable : false,                // bufferable
+    cacheable  : false,                // cacheable
+    shareable  : false,                // shareable
+    noexecute  : true,                 // not executable
+};
+
+/* Define the base address of the 1 Meg page the peripheral resides in. */
+var peripheralBaseAddr = 0x44DF2800;
+
+/* Configure the corresponding MMU page descriptor accordingly */
+Mmu.setFirstLevelDescMeta(peripheralBaseAddr,
+                          peripheralBaseAddr,
+                          peripheralAttrs);
+                          
+var peripheralBaseAddr = 0x44e0b000;
+
+/* Configure the corresponding MMU page descriptor accordingly */
+Mmu.setFirstLevelDescMeta(peripheralBaseAddr,
+                          peripheralBaseAddr,
+                          peripheralAttrs);
diff --git a/packages/ti/fs/fatfs/example/console/am571x/armv7/bios/FATFS_Console_idkAM571x_armExampleProject.txt b/packages/ti/fs/fatfs/example/console/am571x/armv7/bios/FATFS_Console_idkAM571x_armExampleProject.txt
new file mode 100644 (file)
index 0000000..35fb2f5
--- /dev/null
@@ -0,0 +1,9 @@
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/mmcsd/soc/am57xx/MMCSD_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/fs_shell_app_utils.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/main_console.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/FATFS_log.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/uart/soc/am571x/UART_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/gpio/soc/am571x/GPIO_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/am571x/armv7/bios/fatfs_idk.cfg"
+-ccs.setCompilerOptions "-c -mcpu=cortex-a15 -mtune=cortex-a15 -marm -mfloat-abi=hard -DDRA7xx -DSOC_AM571x -DidkAM571x -g -gstrict-dwarf -Wall -MMD -MP -I${PDK_INSTALL_PATH}/ti/fs/fatfs "  -rtsc.enableRtsc
+-ccs.setLinkerOptions " -lrdimon -lgcc -lm -lnosys -nostartfiles -static -Wl,--gc-sections -L$(BIOS_INSTALL_PATH)/packages/gnu/targets/arm/libs/install-native/arm-none-eabi/lib/fpu "
diff --git a/packages/ti/fs/fatfs/example/console/am571x/armv7/bios/fatfs_idk.cfg b/packages/ti/fs/fatfs/example/console/am571x/armv7/bios/fatfs_idk.cfg
new file mode 100644 (file)
index 0000000..a9f3300
--- /dev/null
@@ -0,0 +1,244 @@
+/**
+ *  \file   fatfs_idk.cfg
+ *
+ *  \brief  Sysbios config file for fatfs example project on AM571X IDK EVM.
+ *
+ */
+
+/*
+ * Copyright (C) 2015-2018 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of Texas Instruments Incorporated nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+/* ================ General configuration ================ */
+var Defaults = xdc.useModule('xdc.runtime.Defaults');
+var Diags = xdc.useModule('xdc.runtime.Diags');
+var Error = xdc.useModule('xdc.runtime.Error');
+var Log = xdc.useModule('xdc.runtime.Log');
+var LoggerBuf = xdc.useModule('xdc.runtime.LoggerBuf');
+var Main = xdc.useModule('xdc.runtime.Main');
+var Memory = xdc.useModule('xdc.runtime.Memory')
+var SysMin = xdc.useModule('xdc.runtime.SysMin');
+var System = xdc.useModule('xdc.runtime.System');
+var Text = xdc.useModule('xdc.runtime.Text');
+var Clock = xdc.useModule('ti.sysbios.knl.Clock');
+var Swi = xdc.useModule('ti.sysbios.knl.Swi');
+var Task = xdc.useModule('ti.sysbios.knl.Task');
+var Semaphore = xdc.useModule('ti.sysbios.knl.Semaphore');
+var Hwi = xdc.useModule('ti.sysbios.hal.Hwi');
+var ti_sysbios_family_arm_gic_Hwi = xdc.useModule('ti.sysbios.family.arm.gic.Hwi');
+var Cache = xdc.useModule('ti.sysbios.hal.Cache');
+var IntXbar    = xdc.useModule('ti.sysbios.family.shared.vayu.IntXbar');
+
+/*
+ * Program.argSize sets the size of the .args section.
+ * The examples don't use command line args so argSize is set to 0.
+ */
+Program.argSize = 0x0;
+
+/* System stack size (used by ISRs and Swis) */
+Program.stack = 0x20000;
+
+/*
+ * Uncomment this line to globally disable Asserts.
+ * All modules inherit the default from the 'Defaults' module.  You
+ * can override these defaults on a per-module basis using Module.common$.
+ * Disabling Asserts will save code space and improve runtime performance.
+Defaults.common$.diags_ASSERT = Diags.ALWAYS_OFF;
+ */
+
+/*
+ * Uncomment this line to keep module names from being loaded on the target.
+ * The module name strings are placed in the .const section. Setting this
+ * parameter to false will save space in the .const section.  Error and
+ * Assert messages will contain an "unknown module" prefix instead
+ * of the actual module name.
+Defaults.common$.namedModule = false;
+ */
+
+/*
+ * Minimize exit handler array in System.  The System module includes
+ * an array of functions that are registered with System_atexit() to be
+ * called by System_exit().
+ */
+System.maxAtexitHandlers = 4;
+
+/*
+ * Uncomment this line to disable the Error print function.
+ * We lose error information when this is disabled since the errors are
+ * not printed.  Disabling the raiseHook will save some code space if
+ * your app is not using System_printf() since the Error_print() function
+ * calls System_printf().
+Error.raiseHook = null;
+ */
+
+/*
+ * Uncomment this line to keep Error, Assert, and Log strings from being
+ * loaded on the target.  These strings are placed in the .const section.
+ * Setting this parameter to false will save space in the .const section.
+ * Error, Assert and Log message will print raw ids and args instead of
+ * a formatted message.
+Text.isLoaded = false;
+ */
+
+/*
+ * Uncomment this line to disable the output of characters by SysMin
+ * when the program exits.  SysMin writes characters to a circular buffer.
+ * This buffer can be viewed using the SysMin Output view in ROV.
+SysMin.flushAtExit = false;
+ */
+
+/* Circular buffer size for System_printf() */
+SysMin.bufSize = 0x200;
+System.SupportProxy = SysMin;
+
+/*
+ * Create and install logger for the whole system
+ */
+var loggerBufParams = new LoggerBuf.Params();
+loggerBufParams.numEntries = 16;
+var logger0 = LoggerBuf.create(loggerBufParams);
+Defaults.common$.logger = logger0;
+Main.common$.diags_INFO = Diags.ALWAYS_ON;
+
+if (Program.build.target.$name.match(/gnu/)) {
+    if (Program.build.target.$name.match(/A8F/) ||
+        Program.build.target.$name.match(/A9F/) ||
+        Program.build.target.$name.match(/A15F/)) {
+        var SemiHost = xdc.useModule('ti.sysbios.rts.gnu.SemiHostSupport');
+    }
+}
+
+/* ================ BIOS configuration ================ */
+
+var BIOS = xdc.useModule('ti.sysbios.BIOS');
+/*
+ * Build a custom SYS/BIOS library from sources.
+ */
+BIOS.libType = BIOS.LibType_Custom;
+
+/*
+ * The BIOS module will create the default heap for the system.
+ * Specify the size of this default heap.
+ */
+BIOS.heapSize = 0x1000;
+
+
+/* No runtime stack checking is performed */
+Task.checkStackFlag = false;
+
+/* Reduce the number of task priorities */
+Task.numPriorities = 4;
+
+/* ================ Driver configuration ================ */
+var socType           = "am571x";
+/*use CSL package*/
+var Csl = xdc.loadPackage('ti.csl');
+Csl.Settings.deviceType = socType;
+
+/* Load the OSAL package */
+var osType = "tirtos"
+var Osal = xdc.useModule('ti.osal.Settings');
+Osal.osType = osType;
+Osal.socType = socType;
+/* Load the MMCSD package */
+var Mmcsd = xdc.loadPackage('ti.drv.mmcsd');
+var Fatfs = xdc.loadPackage('ti.fs.fatfs');
+
+/* Load the GPIO package */
+var GPIO = xdc.loadPackage('ti.drv.gpio');
+
+/* Load the UART package */
+var UART = xdc.loadPackage('ti.drv.uart');    
+
+/* Load the I2C package */
+var I2C = xdc.loadPackage('ti.drv.i2c');    
+
+/* Load the Board package and set the board name */
+var Board = xdc.loadPackage('ti.board');
+Board.Settings.boardName = "idkAM571x";
+
+/* ================ Cache and MMU configuration ================ */
+
+var Cache1  = xdc.useModule('ti.sysbios.family.arm.a15.Cache');
+var Mmu = xdc.useModule('ti.sysbios.family.arm.a15.Mmu');
+
+/* Enable the cache */
+Cache1.enableCache = true;
+
+/* Enable the MMU (Required for L1 data caching) */
+Mmu.enableMMU = true;
+
+/******************************************************************************
+ *
+ * SYS/BIOS assigns the following defaults to MAIR0 ATTR0, ATTR1 and ATTR2:
+ *
+ * ATTR0 -> 0x44 (mark memory region as non-cacheable normal memory)
+ * ATTR1 -> 0x04 (mark memory region as device memory, i.e. strongly
+ * ordered and non-cacheable)
+ * ATTR2 -> 0xFF (mark memory region as normal memory, RW cacheable and
+ * RW allocate)
+ ******************************************************************************
+ */
+
+
+// descriptor attribute structure
+var attrs0 = new Mmu.DescriptorAttrs();
+
+Mmu.initDescAttrsMeta(attrs0);
+attrs0.type = Mmu.DescriptorType_BLOCK;    // BLOCK descriptor
+attrs0.shareable = 2;                      // sharerable
+attrs0.attrIndx = 1;                       // Non-cache, device memory
+attrs0.noExecute = true;                   // Not executable
+
+// Set the descriptor for each entry in the address range
+for (var i=0x40600000; i < 0x60000000; i = i + 0x00200000) {
+    // Each 'BLOCK' descriptor entry spans a 2MB address range
+    Mmu.setSecondLevelDescMeta(i, i, attrs0);
+}
+
+// descriptor attribute structure
+var attrs1 = new Mmu.DescriptorAttrs();
+
+Mmu.initDescAttrsMeta(attrs1);
+attrs1.type = Mmu.DescriptorType_BLOCK;    // BLOCK descriptor
+attrs1.shareable = 2;                      // sharerable
+attrs1.attrIndx = 2;                       // Cached, normal memory
+
+// Set the descriptor for each entry in the address range
+for (var i=0x80000000; i < 0xA0000000; i = i + 0x00200000) {
+    // Each 'BLOCK' descriptor entry spans a 2MB address range
+    Mmu.setSecondLevelDescMeta(i, i, attrs1);
+}
+
+
+/* ================ Memory sections configuration ================ */
+Program.sectMap["BOARD_IO_DELAY_DATA"] = "OCMC_RAM1";
+Program.sectMap["BOARD_IO_DELAY_CODE"] = "OCMC_RAM1";
diff --git a/packages/ti/fs/fatfs/example/console/am571x/c66/bios/FATFS_Console_idkAM571x_c66xExampleProject.txt b/packages/ti/fs/fatfs/example/console/am571x/c66/bios/FATFS_Console_idkAM571x_c66xExampleProject.txt
new file mode 100644 (file)
index 0000000..d784c72
--- /dev/null
@@ -0,0 +1,8 @@
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/mmcsd/soc/am57xx/MMCSD_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/fs_shell_app_utils.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/main_console.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/FATFS_log.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/uart/soc/am571x/UART_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/gpio/soc/am571x/GPIO_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/am571x/c66/bios/fatfs_idk.cfg"
+-ccs.setCompilerOptions "-D -mv6600 -g -dSOC_AM571x -didkAM571x -dUSE_BIOS -dC66X -dNSS_GEN2  --diag_warning=225 --diag_warning=994 --diag_warning=262 --diag_suppress=1111 --diag_suppress=827  --diag_suppress=824  --diag_suppress=837  --diag_suppress=1037 --diag_suppress=195 --diag_suppress=77  --diag_suppress=232 -I${PDK_INSTALL_PATH}/ti/fs/fatfs"  -rtsc.enableRtsc
diff --git a/packages/ti/fs/fatfs/example/console/am571x/c66/bios/fatfs_idk.cfg b/packages/ti/fs/fatfs/example/console/am571x/c66/bios/fatfs_idk.cfg
new file mode 100644 (file)
index 0000000..ab3adf1
--- /dev/null
@@ -0,0 +1,124 @@
+/**
+ *  \file   fatfs_idk.cfg
+ *
+ *  \brief  Sysbios config file for fatfs C66X test project on AM571X IDK EVM.
+ *
+ */
+
+/*
+ * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of Texas Instruments Incorporated nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+/* ================ General configuration ================ */
+var Memory                      =   xdc.useModule('xdc.runtime.Memory');
+var HeapMem                     =   xdc.useModule('ti.sysbios.heaps.HeapMem');
+var HeapBuf                     =   xdc.useModule('ti.sysbios.heaps.HeapBuf');
+var Log                         =   xdc.useModule('xdc.runtime.Log');
+var Task                        =   xdc.useModule('ti.sysbios.knl.Task');
+var Semaphore                   =   xdc.useModule('ti.sysbios.knl.Semaphore');
+var Hwi                         =   xdc.useModule('ti.sysbios.family.c64p.Hwi');
+var ECM                         =   xdc.useModule('ti.sysbios.family.c64p.EventCombiner');
+var System                      =   xdc.useModule('xdc.runtime.System');
+SysStd                          =   xdc.useModule('xdc.runtime.SysStd');
+var IntXbar                     =   xdc.useModule('ti.sysbios.family.shared.vayu.IntXbar');
+
+System.SupportProxy             =   SysStd;
+
+/* Create a default system heap using ti.bios.HeapMem. */
+var heapMemParams1              =   new HeapMem.Params;
+heapMemParams1.size             =   8192 * 25;
+heapMemParams1.sectionName      =   "systemHeap";
+Program.global.heap0            =   HeapMem.create(heapMemParams1);
+
+/* This is the default memory heap. */
+Memory.defaultHeapInstance      =   Program.global.heap0;
+Program.sectMap["systemHeap"]   =   Program.platform.stackMemory;
+
+/*
+ * Enable Event Groups here and registering of ISR for specific GEM INTC is done
+ * using EventCombiner_dispatchPlug() and Hwi_eventMap() APIs
+ */
+var exception            =     xdc.useModule('ti.sysbios.family.c64p.Exception');
+exception.enablePrint = true;
+
+/* ================ BIOS configuration ================ */
+
+var BIOS                        =   xdc.useModule('ti.sysbios.BIOS'); 
+
+/* Enable BIOS Task Scheduler */
+BIOS.taskEnabled                       =   true;
+
+/* ================ Task configuration ================ */
+
+/* No runtime stack checking is performed */
+Task.checkStackFlag = false;
+
+
+/* Reduce the number of task priorities */
+Task.numPriorities = 4;
+
+
+/* ================ Driver configuration ================ */
+var socType           = "am571x";
+
+/*use CSL package*/
+var Csl = xdc.loadPackage('ti.csl');
+Csl.Settings.deviceType = socType;
+
+
+/* Load the OSAL package */
+var osType = "tirtos"
+var Osal = xdc.useModule('ti.osal.Settings');
+Osal.osType = osType;
+Osal.socType = socType;
+/* Load the MMCSD package */
+var Mmcsd = xdc.loadPackage('ti.drv.mmcsd');
+var Fatfs = xdc.loadPackage('ti.fs.fatfs');
+
+/* Load the GPIO package */
+var GPIO = xdc.loadPackage('ti.drv.gpio');
+
+/* Load the UART package */
+var UART = xdc.loadPackage('ti.drv.uart');    
+
+/* Load the I2C package */
+var I2C = xdc.loadPackage('ti.drv.i2c');    
+
+/* Load the Board package and set the board name */
+var Board = xdc.loadPackage('ti.board');
+Board.Settings.boardName = "idkAM571x";
+
+/* ================ Memory sections configuration ================ */
+Program.sectMap[".text"] = "EXT_RAM";
+Program.sectMap[".const"] = "EXT_RAM";
+Program.sectMap[".plt"] = "EXT_RAM";
+Program.sectMap["BOARD_IO_DELAY_DATA"] = "OCMC_RAM1";
+Program.sectMap["BOARD_IO_DELAY_CODE"] = "OCMC_RAM1";
diff --git a/packages/ti/fs/fatfs/example/console/am572x/armv7/bios/FATFS_Console_MultiPartition_evmAM572x_armExampleProject.txt b/packages/ti/fs/fatfs/example/console/am572x/armv7/bios/FATFS_Console_MultiPartition_evmAM572x_armExampleProject.txt
new file mode 100644 (file)
index 0000000..eb7edf5
--- /dev/null
@@ -0,0 +1,9 @@
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/mmcsd/soc/am57xx/MMCSD_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/fs_shell_app_utils.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/main_console.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/FATFS_log.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/uart/soc/am572x/UART_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/gpio/soc/am572x/GPIO_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/am572x/armv7/bios/fatfs_evm.cfg"
+-ccs.setCompilerOptions "-c -mcpu=cortex-a15 -mtune=cortex-a15 -marm -mfloat-abi=hard -DDRA7xx -DSOC_AM572x -DevmAM572x -DMULTI_PARTITION -DCONSOLE_EMMC -g -gstrict-dwarf -Wall -MMD -MP -I${PDK_INSTALL_PATH}/ti/fs/fatfs "  -rtsc.enableRtsc
+-ccs.setLinkerOptions " -lrdimon -lgcc -lm -lnosys -nostartfiles -static -Wl,--gc-sections -L$(BIOS_INSTALL_PATH)/packages/gnu/targets/arm/libs/install-native/arm-none-eabi/lib/fpu "
diff --git a/packages/ti/fs/fatfs/example/console/am572x/armv7/bios/FATFS_Console_evmAM572x_SMP_armExampleProject.txt b/packages/ti/fs/fatfs/example/console/am572x/armv7/bios/FATFS_Console_evmAM572x_SMP_armExampleProject.txt
new file mode 100644 (file)
index 0000000..0c08a01
--- /dev/null
@@ -0,0 +1,10 @@
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/mmcsd/soc/am57xx/MMCSD_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/fs_shell_app_utils.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/main_console.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/FATFS_log.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/uart/soc/am572x/UART_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/gpio/soc/am572x/GPIO_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/am572x/armv7/bios/fatfs_evm.cfg"
+-ccs.setCompilerOptions "-c -mcpu=cortex-a15 -mtune=cortex-a15 -marm -mfloat-abi=hard -DDRA7xx -DSOC_AM572x -DevmAM572x -g -gstrict-dwarf -Wall -MMD -MP -I${PDK_INSTALL_PATH}/ti/fs/fatfs "  -rtsc.enableRtsc
+-ccs.setLinkerOptions " -lrdimon -lgcc -lm -lnosys -nostartfiles -static -Wl,--gc-sections -L$(BIOS_INSTALL_PATH)/packages/gnu/targets/arm/libs/install-native/arm-none-eabi/lib/fpu "
+-rtsc.setConfiguroOptions "--cfgArgs {SMP:\"enable\"}"
diff --git a/packages/ti/fs/fatfs/example/console/am572x/armv7/bios/FATFS_Console_evmAM572x_armExampleProject.txt b/packages/ti/fs/fatfs/example/console/am572x/armv7/bios/FATFS_Console_evmAM572x_armExampleProject.txt
new file mode 100644 (file)
index 0000000..d7bc6e3
--- /dev/null
@@ -0,0 +1,9 @@
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/mmcsd/soc/am57xx/MMCSD_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/fs_shell_app_utils.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/main_console.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/FATFS_log.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/uart/soc/am572x/UART_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/gpio/soc/am572x/GPIO_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/am572x/armv7/bios/fatfs_evm.cfg"
+-ccs.setCompilerOptions "-c -mcpu=cortex-a15 -mtune=cortex-a15 -marm -mfloat-abi=hard -DDRA7xx -DSOC_AM572x -DevmAM572x -g -gstrict-dwarf -Wall -MMD -MP -I${PDK_INSTALL_PATH}/ti/fs/fatfs "  -rtsc.enableRtsc
+-ccs.setLinkerOptions " -lrdimon -lgcc -lm -lnosys -nostartfiles -static -Wl,--gc-sections -L$(BIOS_INSTALL_PATH)/packages/gnu/targets/arm/libs/install-native/arm-none-eabi/lib/fpu "
diff --git a/packages/ti/fs/fatfs/example/console/am572x/armv7/bios/FATFS_Console_idkAM572x_armExampleProject.txt b/packages/ti/fs/fatfs/example/console/am572x/armv7/bios/FATFS_Console_idkAM572x_armExampleProject.txt
new file mode 100644 (file)
index 0000000..310d31b
--- /dev/null
@@ -0,0 +1,9 @@
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/mmcsd/soc/am57xx/MMCSD_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/fs_shell_app_utils.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/main_console.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/FATFS_log.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/uart/soc/am572x/UART_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/gpio/soc/am572x/GPIO_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/am572x/armv7/bios/fatfs_idk.cfg"
+-ccs.setCompilerOptions "-c -mcpu=cortex-a15 -mtune=cortex-a15 -marm -mfloat-abi=hard -DDRA7xx -DSOC_AM572x -DidkAM572x -g -gstrict-dwarf -Wall -MMD -MP -I${PDK_INSTALL_PATH}/ti/fs/fatfs "  -rtsc.enableRtsc
+-ccs.setLinkerOptions " -lrdimon -lgcc -lm -lnosys -nostartfiles -static -Wl,--gc-sections -L$(BIOS_INSTALL_PATH)/packages/gnu/targets/arm/libs/install-native/arm-none-eabi/lib/fpu "
diff --git a/packages/ti/fs/fatfs/example/console/am572x/armv7/bios/fatfs_evm.cfg b/packages/ti/fs/fatfs/example/console/am572x/armv7/bios/fatfs_evm.cfg
new file mode 100644 (file)
index 0000000..99c83a3
--- /dev/null
@@ -0,0 +1,245 @@
+/**
+ *  \file   fatfs_evm.cfg
+ *
+ *  \brief  Sysbios config file for fatfs example project on AM572X GP EVM.
+ *
+ */
+
+/*
+ * Copyright (C) 2015-2019 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of Texas Instruments Incorporated nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+/* ================ General configuration ================ */
+var Defaults = xdc.useModule('xdc.runtime.Defaults');
+var Diags = xdc.useModule('xdc.runtime.Diags');
+var Error = xdc.useModule('xdc.runtime.Error');
+var Log = xdc.useModule('xdc.runtime.Log');
+var LoggerBuf = xdc.useModule('xdc.runtime.LoggerBuf');
+var Main = xdc.useModule('xdc.runtime.Main');
+var Memory = xdc.useModule('xdc.runtime.Memory')
+var SysMin = xdc.useModule('xdc.runtime.SysMin');
+var System = xdc.useModule('xdc.runtime.System');
+var Text = xdc.useModule('xdc.runtime.Text');
+var Clock = xdc.useModule('ti.sysbios.knl.Clock');
+var Swi = xdc.useModule('ti.sysbios.knl.Swi');
+var Task = xdc.useModule('ti.sysbios.knl.Task');
+var Semaphore = xdc.useModule('ti.sysbios.knl.Semaphore');
+var Hwi = xdc.useModule('ti.sysbios.hal.Hwi');
+var ti_sysbios_family_arm_gic_Hwi = xdc.useModule('ti.sysbios.family.arm.gic.Hwi');
+var IntXbar    = xdc.useModule('ti.sysbios.family.shared.vayu.IntXbar');
+
+/*
+ * Program.argSize sets the size of the .args section.
+ * The examples don't use command line args so argSize is set to 0.
+ */
+Program.argSize = 0x0;
+
+/* System stack size (used by ISRs and Swis) */
+Program.stack = 0x20000;
+
+/*
+ * Uncomment this line to globally disable Asserts.
+ * All modules inherit the default from the 'Defaults' module.  You
+ * can override these defaults on a per-module basis using Module.common$.
+ * Disabling Asserts will save code space and improve runtime performance.
+Defaults.common$.diags_ASSERT = Diags.ALWAYS_OFF;
+ */
+
+/*
+ * Uncomment this line to keep module names from being loaded on the target.
+ * The module name strings are placed in the .const section. Setting this
+ * parameter to false will save space in the .const section.  Error and
+ * Assert messages will contain an "unknown module" prefix instead
+ * of the actual module name.
+Defaults.common$.namedModule = false;
+ */
+
+/*
+ * Minimize exit handler array in System.  The System module includes
+ * an array of functions that are registered with System_atexit() to be
+ * called by System_exit().
+ */
+System.maxAtexitHandlers = 4;
+
+/*
+ * Uncomment this line to disable the Error print function.
+ * We lose error information when this is disabled since the errors are
+ * not printed.  Disabling the raiseHook will save some code space if
+ * your app is not using System_printf() since the Error_print() function
+ * calls System_printf().
+Error.raiseHook = null;
+ */
+
+/*
+ * Uncomment this line to keep Error, Assert, and Log strings from being
+ * loaded on the target.  These strings are placed in the .const section.
+ * Setting this parameter to false will save space in the .const section.
+ * Error, Assert and Log message will print raw ids and args instead of
+ * a formatted message.
+Text.isLoaded = false;
+ */
+
+/*
+ * Uncomment this line to disable the output of characters by SysMin
+ * when the program exits.  SysMin writes characters to a circular buffer.
+ * This buffer can be viewed using the SysMin Output view in ROV.
+SysMin.flushAtExit = false;
+ */
+
+/* Circular buffer size for System_printf() */
+SysMin.bufSize = 0x200;
+System.SupportProxy = SysMin;
+
+/*
+ * Create and install logger for the whole system
+ */
+var loggerBufParams = new LoggerBuf.Params();
+loggerBufParams.numEntries = 16;
+var logger0 = LoggerBuf.create(loggerBufParams);
+Defaults.common$.logger = logger0;
+Main.common$.diags_INFO = Diags.ALWAYS_ON;
+
+if (Program.build.target.$name.match(/gnu/)) {
+    if (Program.build.target.$name.match(/A8F/) ||
+        Program.build.target.$name.match(/A9F/) ||
+        Program.build.target.$name.match(/A15F/)) {
+        var SemiHost = xdc.useModule('ti.sysbios.rts.gnu.SemiHostSupport');
+    }
+}
+
+/* ================ BIOS configuration ================ */
+
+var BIOS = xdc.useModule('ti.sysbios.BIOS');
+
+var smpCfg;
+/* Enable BIOS SMP mode */
+if (Program.build.cfgArgs !=  null)
+{
+    smpCfg = Program.build.cfgArgs.SMP;
+    if(smpCfg == 'enable')
+    {
+        xdc.print("Enabling BIOS SMP mode");
+        BIOS.smpEnabled = true;
+        var Cache = xdc.module("ti.sysbios.hal.Cache");
+    }
+}
+
+/*
+ * Build a custom SYS/BIOS library from sources.
+ */
+BIOS.libType = BIOS.LibType_Custom;
+
+/*
+ * The BIOS module will create the default heap for the system.
+ * Specify the size of this default heap.
+ */
+BIOS.heapSize = 0x1000;
+
+
+/* No runtime stack checking is performed */
+Task.checkStackFlag = false;
+
+/* Reduce the number of task priorities */
+Task.numPriorities = 4;
+
+/* ================ Driver configuration ================ */
+var socType           = "am572x";
+
+/*use CSL package*/
+var Csl = xdc.loadPackage('ti.csl');
+Csl.Settings.deviceType = socType;
+
+/* Load the OSAL package */
+var osType = "tirtos"
+var Osal = xdc.useModule('ti.osal.Settings');
+Osal.osType = osType;
+Osal.socType = socType;
+/* Load the MMCSD package */
+var Mmcsd = xdc.loadPackage('ti.drv.mmcsd');
+var Fatfs = xdc.loadPackage('ti.fs.fatfs');
+
+/* Load the GPIO package */
+var GPIO = xdc.loadPackage('ti.drv.gpio');
+
+/* Load the UART package */
+var UART = xdc.loadPackage('ti.drv.uart');    
+
+/* Load the I2C package */
+var I2C = xdc.loadPackage('ti.drv.i2c');    
+
+/* Load the Board package and set the board name */
+var Board = xdc.loadPackage('ti.board');
+Board.Settings.boardName = "evmAM572x";
+
+/* ================ Cache and MMU configuration ================ */
+
+var Mmu = xdc.useModule('ti.sysbios.family.arm.a15.Mmu');
+
+/* Enable the cache */
+if(smpCfg == null || smpCfg == '')
+{
+    var Cache  = xdc.useModule('ti.sysbios.family.arm.a15.Cache');
+    Cache.enableCache = true;
+}
+
+/* Enable the MMU (Required for L1 data caching) */
+Mmu.enableMMU = true;
+
+/* Map MMC1 regs in MMU */
+var peripheralAttrs = new Mmu.DescriptorAttrs();
+Mmu.initDescAttrsMeta(peripheralAttrs);
+peripheralAttrs.type = Mmu.DescriptorType_BLOCK;  // BLOCK descriptor
+peripheralAttrs.noExecute = true;                 // not executable
+peripheralAttrs.accPerm = 0;                      // read/write at PL1
+peripheralAttrs.attrIndx = 1;                     // MAIR0 Byte1 describes
+                                                  // memory attributes for
+                                                  // each BLOCK MMU entry
+var peripheralBaseAddr = 0x4ae00000;
+// Configure the corresponding MMU page descriptor accordingly
+Mmu.setSecondLevelDescMeta(peripheralBaseAddr,
+                           peripheralBaseAddr,
+                           peripheralAttrs);
+
+var attrs = new Mmu.DescriptorAttrs();
+Mmu.initDescAttrsMeta(attrs);
+attrs.type = Mmu.DescriptorType_BLOCK;
+attrs.noExecute = true;
+attrs.accPerm = 0;
+attrs.attrIndx = 1;
+
+/* Set IO Delay configuration areas as non-cache */
+Mmu.setSecondLevelDescMeta(0x4844a000, 0x4844a000, attrs);
+Mmu.setSecondLevelDescMeta(0x4ae07d00, 0x4ae07d00, attrs);
+
+
+/* ================ Memory sections configuration ================ */
+Program.sectMap["BOARD_IO_DELAY_DATA"] = "OCMC_RAM1";
+Program.sectMap["BOARD_IO_DELAY_CODE"] = "OCMC_RAM1";
diff --git a/packages/ti/fs/fatfs/example/console/am572x/armv7/bios/fatfs_idk.cfg b/packages/ti/fs/fatfs/example/console/am572x/armv7/bios/fatfs_idk.cfg
new file mode 100644 (file)
index 0000000..7d706e6
--- /dev/null
@@ -0,0 +1,229 @@
+/**
+ *  \file   fatfs_idk.cfg
+ *
+ *  \brief  Sysbios config file for fatfs example project on AM572X IDK EVM.
+ *
+ */
+
+/*
+ * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of Texas Instruments Incorporated nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+/* ================ General configuration ================ */
+var Defaults = xdc.useModule('xdc.runtime.Defaults');
+var Diags = xdc.useModule('xdc.runtime.Diags');
+var Error = xdc.useModule('xdc.runtime.Error');
+var Log = xdc.useModule('xdc.runtime.Log');
+var LoggerBuf = xdc.useModule('xdc.runtime.LoggerBuf');
+var Main = xdc.useModule('xdc.runtime.Main');
+var Memory = xdc.useModule('xdc.runtime.Memory')
+var SysMin = xdc.useModule('xdc.runtime.SysMin');
+var System = xdc.useModule('xdc.runtime.System');
+var Text = xdc.useModule('xdc.runtime.Text');
+var Clock = xdc.useModule('ti.sysbios.knl.Clock');
+var Swi = xdc.useModule('ti.sysbios.knl.Swi');
+var Task = xdc.useModule('ti.sysbios.knl.Task');
+var Semaphore = xdc.useModule('ti.sysbios.knl.Semaphore');
+var Hwi = xdc.useModule('ti.sysbios.hal.Hwi');
+var ti_sysbios_family_arm_gic_Hwi = xdc.useModule('ti.sysbios.family.arm.gic.Hwi');
+var Cache = xdc.useModule('ti.sysbios.hal.Cache');
+var IntXbar    = xdc.useModule('ti.sysbios.family.shared.vayu.IntXbar');
+
+/*
+ * Program.argSize sets the size of the .args section.
+ * The examples don't use command line args so argSize is set to 0.
+ */
+Program.argSize = 0x0;
+
+/* System stack size (used by ISRs and Swis) */
+Program.stack = 0x20000;
+
+/*
+ * Uncomment this line to globally disable Asserts.
+ * All modules inherit the default from the 'Defaults' module.  You
+ * can override these defaults on a per-module basis using Module.common$.
+ * Disabling Asserts will save code space and improve runtime performance.
+Defaults.common$.diags_ASSERT = Diags.ALWAYS_OFF;
+ */
+
+/*
+ * Uncomment this line to keep module names from being loaded on the target.
+ * The module name strings are placed in the .const section. Setting this
+ * parameter to false will save space in the .const section.  Error and
+ * Assert messages will contain an "unknown module" prefix instead
+ * of the actual module name.
+Defaults.common$.namedModule = false;
+ */
+
+/*
+ * Minimize exit handler array in System.  The System module includes
+ * an array of functions that are registered with System_atexit() to be
+ * called by System_exit().
+ */
+System.maxAtexitHandlers = 4;
+
+/*
+ * Uncomment this line to disable the Error print function.
+ * We lose error information when this is disabled since the errors are
+ * not printed.  Disabling the raiseHook will save some code space if
+ * your app is not using System_printf() since the Error_print() function
+ * calls System_printf().
+Error.raiseHook = null;
+ */
+
+/*
+ * Uncomment this line to keep Error, Assert, and Log strings from being
+ * loaded on the target.  These strings are placed in the .const section.
+ * Setting this parameter to false will save space in the .const section.
+ * Error, Assert and Log message will print raw ids and args instead of
+ * a formatted message.
+Text.isLoaded = false;
+ */
+
+/*
+ * Uncomment this line to disable the output of characters by SysMin
+ * when the program exits.  SysMin writes characters to a circular buffer.
+ * This buffer can be viewed using the SysMin Output view in ROV.
+SysMin.flushAtExit = false;
+ */
+
+/* Circular buffer size for System_printf() */
+SysMin.bufSize = 0x200;
+System.SupportProxy = SysMin;
+
+/*
+ * Create and install logger for the whole system
+ */
+var loggerBufParams = new LoggerBuf.Params();
+loggerBufParams.numEntries = 16;
+var logger0 = LoggerBuf.create(loggerBufParams);
+Defaults.common$.logger = logger0;
+Main.common$.diags_INFO = Diags.ALWAYS_ON;
+
+if (Program.build.target.$name.match(/gnu/)) {
+    if (Program.build.target.$name.match(/A8F/) ||
+        Program.build.target.$name.match(/A9F/) ||
+        Program.build.target.$name.match(/A15F/)) {
+        var SemiHost = xdc.useModule('ti.sysbios.rts.gnu.SemiHostSupport');
+    }
+}
+
+/* ================ BIOS configuration ================ */
+
+var BIOS = xdc.useModule('ti.sysbios.BIOS');
+/*
+ * Build a custom SYS/BIOS library from sources.
+ */
+BIOS.libType = BIOS.LibType_Custom;
+
+/*
+ * The BIOS module will create the default heap for the system.
+ * Specify the size of this default heap.
+ */
+BIOS.heapSize = 0x1000;
+
+
+/* No runtime stack checking is performed */
+Task.checkStackFlag = false;
+
+/* Reduce the number of task priorities */
+Task.numPriorities = 4;
+
+/* ================ Driver configuration ================ */
+var socType           = "am572x";
+
+/*use CSL package*/
+var Csl = xdc.loadPackage('ti.csl');
+Csl.Settings.deviceType = socType;
+
+/* Load the OSAL package */
+var osType = "tirtos"
+var Osal = xdc.useModule('ti.osal.Settings');
+Osal.osType = osType;
+Osal.socType = socType;
+/* Load the MMCSD package */
+var Mmcsd = xdc.loadPackage('ti.drv.mmcsd');
+var Fatfs = xdc.loadPackage('ti.fs.fatfs');
+
+/* Load the GPIO package */
+var GPIO = xdc.loadPackage('ti.drv.gpio');
+
+/* Load the UART package */
+var UART = xdc.loadPackage('ti.drv.uart');    
+
+/* Load the I2C package */
+var I2C = xdc.loadPackage('ti.drv.i2c');    
+
+/* Load the Board package and set the board name */
+var Board = xdc.loadPackage('ti.board');
+Board.Settings.boardName = "idkAM572x";
+
+/* ================ Cache and MMU configuration ================ */
+
+var Cache1  = xdc.useModule('ti.sysbios.family.arm.a15.Cache');
+var Mmu = xdc.useModule('ti.sysbios.family.arm.a15.Mmu');
+
+/* Enable the cache */
+Cache1.enableCache = true;
+
+/* Enable the MMU (Required for L1 data caching) */
+Mmu.enableMMU = true;
+
+/* Map MMC1 regs in MMU */
+var peripheralAttrs = new Mmu.DescriptorAttrs();
+Mmu.initDescAttrsMeta(peripheralAttrs);
+peripheralAttrs.type = Mmu.DescriptorType_BLOCK;  // BLOCK descriptor
+peripheralAttrs.noExecute = true;                 // not executable
+peripheralAttrs.accPerm = 0;                      // read/write at PL1
+peripheralAttrs.attrIndx = 1;                     // MAIR0 Byte1 describes
+                                                  // memory attributes for
+                                                  // each BLOCK MMU entry
+var peripheralBaseAddr = 0x4ae00000;
+// Configure the corresponding MMU page descriptor accordingly
+Mmu.setSecondLevelDescMeta(peripheralBaseAddr,
+                           peripheralBaseAddr,
+                           peripheralAttrs);
+
+var attrs = new Mmu.DescriptorAttrs();
+Mmu.initDescAttrsMeta(attrs);
+attrs.type = Mmu.DescriptorType_BLOCK;
+attrs.noExecute = true;
+attrs.accPerm = 0;
+attrs.attrIndx = 1;
+
+/* Set IO Delay configuration areas as non-cache */
+Mmu.setSecondLevelDescMeta(0x4844a000, 0x4844a000, attrs);
+Mmu.setSecondLevelDescMeta(0x4ae07d00, 0x4ae07d00, attrs);
+
+
+/* ================ Memory sections configuration ================ */
+Program.sectMap["BOARD_IO_DELAY_DATA"] = "OCMC_RAM1";
+Program.sectMap["BOARD_IO_DELAY_CODE"] = "OCMC_RAM1";
diff --git a/packages/ti/fs/fatfs/example/console/am572x/c66/bios/FATFS_Console_evmAM572x_c66xExampleProject.txt b/packages/ti/fs/fatfs/example/console/am572x/c66/bios/FATFS_Console_evmAM572x_c66xExampleProject.txt
new file mode 100644 (file)
index 0000000..67f7ed6
--- /dev/null
@@ -0,0 +1,8 @@
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/mmcsd/soc/am57xx/MMCSD_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/fs_shell_app_utils.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/main_console.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/FATFS_log.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/uart/soc/am572x/UART_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/gpio/soc/am572x/GPIO_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/am572x/c66/bios/fatfs_evm.cfg"
+-ccs.setCompilerOptions "-D -mv6600 -g -dSOC_AM572x -devmAM572x -dUSE_BIOS -dC66X -dNSS_GEN2  --diag_warning=225 --diag_warning=994 --diag_warning=262 --diag_suppress=1111 --diag_suppress=827  --diag_suppress=824  --diag_suppress=837  --diag_suppress=1037 --diag_suppress=195 --diag_suppress=77  --diag_suppress=232 -I${PDK_INSTALL_PATH}/ti/fs/fatfs"  -rtsc.enableRtsc
diff --git a/packages/ti/fs/fatfs/example/console/am572x/c66/bios/FATFS_Console_idkAM572x_c66xExampleProject.txt b/packages/ti/fs/fatfs/example/console/am572x/c66/bios/FATFS_Console_idkAM572x_c66xExampleProject.txt
new file mode 100644 (file)
index 0000000..045434b
--- /dev/null
@@ -0,0 +1,8 @@
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/mmcsd/soc/am57xx/MMCSD_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/fs_shell_app_utils.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/main_console.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/FATFS_log.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/uart/soc/am572x/UART_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/gpio/soc/am572x/GPIO_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/am572x/c66/bios/fatfs_idk.cfg"
+-ccs.setCompilerOptions "-D -mv6600 -g -dSOC_AM572x -didkAM572x -dUSE_BIOS -dC66X -dNSS_GEN2  --diag_warning=225 --diag_warning=994 --diag_warning=262 --diag_suppress=1111 --diag_suppress=827  --diag_suppress=824  --diag_suppress=837  --diag_suppress=1037 --diag_suppress=195 --diag_suppress=77  --diag_suppress=232 -I${PDK_INSTALL_PATH}/ti/fs/fatfs"  -rtsc.enableRtsc
diff --git a/packages/ti/fs/fatfs/example/console/am572x/c66/bios/fatfs_evm.cfg b/packages/ti/fs/fatfs/example/console/am572x/c66/bios/fatfs_evm.cfg
new file mode 100644 (file)
index 0000000..90cfecc
--- /dev/null
@@ -0,0 +1,124 @@
+/**
+ *  \file   fatfs_evm.cfg
+ *
+ *  \brief  Sysbios config file for fatfs C66X test project on AM572X GP EVM.
+ *
+ */
+
+/*
+ * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of Texas Instruments Incorporated nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+/* ================ General configuration ================ */
+var Memory                      =   xdc.useModule('xdc.runtime.Memory');
+var HeapMem                     =   xdc.useModule('ti.sysbios.heaps.HeapMem');
+var HeapBuf                     =   xdc.useModule('ti.sysbios.heaps.HeapBuf');
+var Log                         =   xdc.useModule('xdc.runtime.Log');
+var Task                        =   xdc.useModule('ti.sysbios.knl.Task');
+var Semaphore                   =   xdc.useModule('ti.sysbios.knl.Semaphore');
+var Hwi                         =   xdc.useModule('ti.sysbios.family.c64p.Hwi');
+var ECM                         =   xdc.useModule('ti.sysbios.family.c64p.EventCombiner');
+var System                      =   xdc.useModule('xdc.runtime.System');
+SysStd                          =   xdc.useModule('xdc.runtime.SysStd');
+var IntXbar                     =   xdc.useModule('ti.sysbios.family.shared.vayu.IntXbar');
+
+System.SupportProxy             =   SysStd;
+
+/* Create a default system heap using ti.bios.HeapMem. */
+var heapMemParams1              =   new HeapMem.Params;
+heapMemParams1.size             =   8192 * 25;
+heapMemParams1.sectionName      =   "systemHeap";
+Program.global.heap0            =   HeapMem.create(heapMemParams1);
+
+/* This is the default memory heap. */
+Memory.defaultHeapInstance      =   Program.global.heap0;
+Program.sectMap["systemHeap"]   =   Program.platform.stackMemory;
+
+/*
+ * Enable Event Groups here and registering of ISR for specific GEM INTC is done
+ * using EventCombiner_dispatchPlug() and Hwi_eventMap() APIs
+ */
+var exception            =     xdc.useModule('ti.sysbios.family.c64p.Exception');
+exception.enablePrint = true;
+
+/* ================ BIOS configuration ================ */
+
+var BIOS                        =   xdc.useModule('ti.sysbios.BIOS'); 
+
+/* Enable BIOS Task Scheduler */
+BIOS.taskEnabled                       =   true;
+
+/* ================ Task configuration ================ */
+
+/* No runtime stack checking is performed */
+Task.checkStackFlag = false;
+
+
+/* Reduce the number of task priorities */
+Task.numPriorities = 4;
+
+
+/* ================ Driver configuration ================ */
+var socType           = "am572x";
+
+/*use CSL package*/
+var Csl = xdc.loadPackage('ti.csl');
+Csl.Settings.deviceType = socType;
+
+
+/* Load the OSAL package */
+var osType = "tirtos"
+var Osal = xdc.useModule('ti.osal.Settings');
+Osal.osType = osType;
+Osal.socType = socType;
+/* Load the MMCSD package */
+var Mmcsd = xdc.loadPackage('ti.drv.mmcsd');
+var Fatfs = xdc.loadPackage('ti.fs.fatfs');
+
+/* Load the GPIO package */
+var GPIO = xdc.loadPackage('ti.drv.gpio');
+
+/* Load the UART package */
+var UART = xdc.loadPackage('ti.drv.uart');    
+
+/* Load the I2C package */
+var I2C = xdc.loadPackage('ti.drv.i2c');    
+
+/* Load the Board package and set the board name */
+var Board = xdc.loadPackage('ti.board');
+Board.Settings.boardName = "evmAM572x";
+
+/* ================ Memory sections configuration ================ */
+Program.sectMap[".text"] = "EXT_RAM";
+Program.sectMap[".const"] = "EXT_RAM";
+Program.sectMap[".plt"] = "EXT_RAM";
+Program.sectMap["BOARD_IO_DELAY_DATA"] = "OCMC_RAM1";
+Program.sectMap["BOARD_IO_DELAY_CODE"] = "OCMC_RAM1";
diff --git a/packages/ti/fs/fatfs/example/console/am572x/c66/bios/fatfs_idk.cfg b/packages/ti/fs/fatfs/example/console/am572x/c66/bios/fatfs_idk.cfg
new file mode 100644 (file)
index 0000000..b72deab
--- /dev/null
@@ -0,0 +1,122 @@
+/**
+ *  \file   fatfs_idk.cfg
+ *
+ *  \brief  Sysbios config file for fatfs C66X test project on AM572X IDK EVM.
+ *
+ */
+
+/*
+ * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of Texas Instruments Incorporated nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+/* ================ General configuration ================ */
+var Memory                      =   xdc.useModule('xdc.runtime.Memory');
+var HeapMem                     =   xdc.useModule('ti.sysbios.heaps.HeapMem');
+var HeapBuf                     =   xdc.useModule('ti.sysbios.heaps.HeapBuf');
+var Log                         =   xdc.useModule('xdc.runtime.Log');
+var Task                        =   xdc.useModule('ti.sysbios.knl.Task');
+var Semaphore                   =   xdc.useModule('ti.sysbios.knl.Semaphore');
+var Hwi                         =   xdc.useModule('ti.sysbios.family.c64p.Hwi');
+var ECM                         =   xdc.useModule('ti.sysbios.family.c64p.EventCombiner');
+var System                      =   xdc.useModule('xdc.runtime.System');
+SysStd                          =   xdc.useModule('xdc.runtime.SysStd');
+var IntXbar                     =   xdc.useModule('ti.sysbios.family.shared.vayu.IntXbar');
+
+System.SupportProxy             =   SysStd;
+
+/* Create a default system heap using ti.bios.HeapMem. */
+var heapMemParams1              =   new HeapMem.Params;
+heapMemParams1.size             =   8192 * 25;
+heapMemParams1.sectionName      =   "systemHeap";
+Program.global.heap0            =   HeapMem.create(heapMemParams1);
+
+/* This is the default memory heap. */
+Memory.defaultHeapInstance      =   Program.global.heap0;
+Program.sectMap["systemHeap"]   =   Program.platform.stackMemory;
+
+/*
+ * Enable Event Groups here and registering of ISR for specific GEM INTC is done
+ * using EventCombiner_dispatchPlug() and Hwi_eventMap() APIs
+ */
+var exception            =     xdc.useModule('ti.sysbios.family.c64p.Exception');
+exception.enablePrint = true;
+
+/* ================ BIOS configuration ================ */
+
+var BIOS                        =   xdc.useModule('ti.sysbios.BIOS'); 
+
+/* Enable BIOS Task Scheduler */
+BIOS.taskEnabled                       =   true;
+
+/* ================ Task configuration ================ */
+
+/* No runtime stack checking is performed */
+Task.checkStackFlag = false;
+
+
+/* Reduce the number of task priorities */
+Task.numPriorities = 4;
+
+
+/* ================ Driver configuration ================ */
+var socType           = "am572x";
+/*use CSL package*/
+var Csl = xdc.loadPackage('ti.csl');
+Csl.Settings.deviceType = socType;
+
+/* Load the OSAL package */
+var osType = "tirtos"
+var Osal = xdc.useModule('ti.osal.Settings');
+Osal.osType = osType;
+Osal.socType = socType;
+/* Load the MMCSD package */
+var Mmcsd = xdc.loadPackage('ti.drv.mmcsd');
+var Fatfs = xdc.loadPackage('ti.fs.fatfs');
+
+/* Load the GPIO package */
+var GPIO = xdc.loadPackage('ti.drv.gpio');
+
+/* Load the UART package */
+var UART = xdc.loadPackage('ti.drv.uart');    
+
+/* Load the I2C package */
+var I2C = xdc.loadPackage('ti.drv.i2c');    
+
+/* Load the Board package and set the board name */
+var Board = xdc.loadPackage('ti.board');
+Board.Settings.boardName = "idkAM572x";
+
+/* ================ Memory sections configuration ================ */
+Program.sectMap[".text"] = "EXT_RAM";
+Program.sectMap[".const"] = "EXT_RAM";
+Program.sectMap[".plt"] = "EXT_RAM";
+Program.sectMap["BOARD_IO_DELAY_DATA"] = "OCMC_RAM1";
+Program.sectMap["BOARD_IO_DELAY_CODE"] = "OCMC_RAM1";
diff --git a/packages/ti/fs/fatfs/example/console/am574x/armv7/bios/FATFS_Console_idkAM574x_armExampleProject.txt b/packages/ti/fs/fatfs/example/console/am574x/armv7/bios/FATFS_Console_idkAM574x_armExampleProject.txt
new file mode 100644 (file)
index 0000000..662d142
--- /dev/null
@@ -0,0 +1,9 @@
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/mmcsd/soc/am57xx/MMCSD_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/fs_shell_app_utils.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/main_console.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/FATFS_log.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/uart/soc/am574x/UART_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/gpio/soc/am574x/GPIO_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/am574x/armv7/bios/fatfs_idk.cfg"
+-ccs.setCompilerOptions "-c -mcpu=cortex-a15 -mtune=cortex-a15 -marm -mfloat-abi=hard -DDRA7xx -DSOC_AM574x -DidkAM574x -g -gstrict-dwarf -Wall -MMD -MP -I${PDK_INSTALL_PATH}/ti/fs/fatfs "  -rtsc.enableRtsc
+-ccs.setLinkerOptions " -lrdimon -lgcc -lm -lnosys -nostartfiles -static -Wl,--gc-sections -L$(BIOS_INSTALL_PATH)/packages/gnu/targets/arm/libs/install-native/arm-none-eabi/lib/fpu "
diff --git a/packages/ti/fs/fatfs/example/console/am574x/armv7/bios/fatfs_idk.cfg b/packages/ti/fs/fatfs/example/console/am574x/armv7/bios/fatfs_idk.cfg
new file mode 100644 (file)
index 0000000..a00ad71
--- /dev/null
@@ -0,0 +1,229 @@
+/**
+ *  \file   fatfs_idk.cfg
+ *
+ *  \brief  Sysbios config file for fatfs example project on AM574X IDK EVM.
+ *
+ */
+
+/*
+ * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of Texas Instruments Incorporated nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+/* ================ General configuration ================ */
+var Defaults = xdc.useModule('xdc.runtime.Defaults');
+var Diags = xdc.useModule('xdc.runtime.Diags');
+var Error = xdc.useModule('xdc.runtime.Error');
+var Log = xdc.useModule('xdc.runtime.Log');
+var LoggerBuf = xdc.useModule('xdc.runtime.LoggerBuf');
+var Main = xdc.useModule('xdc.runtime.Main');
+var Memory = xdc.useModule('xdc.runtime.Memory')
+var SysMin = xdc.useModule('xdc.runtime.SysMin');
+var System = xdc.useModule('xdc.runtime.System');
+var Text = xdc.useModule('xdc.runtime.Text');
+var Clock = xdc.useModule('ti.sysbios.knl.Clock');
+var Swi = xdc.useModule('ti.sysbios.knl.Swi');
+var Task = xdc.useModule('ti.sysbios.knl.Task');
+var Semaphore = xdc.useModule('ti.sysbios.knl.Semaphore');
+var Hwi = xdc.useModule('ti.sysbios.hal.Hwi');
+var ti_sysbios_family_arm_gic_Hwi = xdc.useModule('ti.sysbios.family.arm.gic.Hwi');
+var Cache = xdc.useModule('ti.sysbios.hal.Cache');
+var IntXbar    = xdc.useModule('ti.sysbios.family.shared.vayu.IntXbar');
+
+/*
+ * Program.argSize sets the size of the .args section.
+ * The examples don't use command line args so argSize is set to 0.
+ */
+Program.argSize = 0x0;
+
+/* System stack size (used by ISRs and Swis) */
+Program.stack = 0x20000;
+
+/*
+ * Uncomment this line to globally disable Asserts.
+ * All modules inherit the default from the 'Defaults' module.  You
+ * can override these defaults on a per-module basis using Module.common$.
+ * Disabling Asserts will save code space and improve runtime performance.
+Defaults.common$.diags_ASSERT = Diags.ALWAYS_OFF;
+ */
+
+/*
+ * Uncomment this line to keep module names from being loaded on the target.
+ * The module name strings are placed in the .const section. Setting this
+ * parameter to false will save space in the .const section.  Error and
+ * Assert messages will contain an "unknown module" prefix instead
+ * of the actual module name.
+Defaults.common$.namedModule = false;
+ */
+
+/*
+ * Minimize exit handler array in System.  The System module includes
+ * an array of functions that are registered with System_atexit() to be
+ * called by System_exit().
+ */
+System.maxAtexitHandlers = 4;
+
+/*
+ * Uncomment this line to disable the Error print function.
+ * We lose error information when this is disabled since the errors are
+ * not printed.  Disabling the raiseHook will save some code space if
+ * your app is not using System_printf() since the Error_print() function
+ * calls System_printf().
+Error.raiseHook = null;
+ */
+
+/*
+ * Uncomment this line to keep Error, Assert, and Log strings from being
+ * loaded on the target.  These strings are placed in the .const section.
+ * Setting this parameter to false will save space in the .const section.
+ * Error, Assert and Log message will print raw ids and args instead of
+ * a formatted message.
+Text.isLoaded = false;
+ */
+
+/*
+ * Uncomment this line to disable the output of characters by SysMin
+ * when the program exits.  SysMin writes characters to a circular buffer.
+ * This buffer can be viewed using the SysMin Output view in ROV.
+SysMin.flushAtExit = false;
+ */
+
+/* Circular buffer size for System_printf() */
+SysMin.bufSize = 0x200;
+System.SupportProxy = SysMin;
+
+/*
+ * Create and install logger for the whole system
+ */
+var loggerBufParams = new LoggerBuf.Params();
+loggerBufParams.numEntries = 16;
+var logger0 = LoggerBuf.create(loggerBufParams);
+Defaults.common$.logger = logger0;
+Main.common$.diags_INFO = Diags.ALWAYS_ON;
+
+if (Program.build.target.$name.match(/gnu/)) {
+    if (Program.build.target.$name.match(/A8F/) ||
+        Program.build.target.$name.match(/A9F/) ||
+        Program.build.target.$name.match(/A15F/)) {
+        var SemiHost = xdc.useModule('ti.sysbios.rts.gnu.SemiHostSupport');
+    }
+}
+
+/* ================ BIOS configuration ================ */
+
+var BIOS = xdc.useModule('ti.sysbios.BIOS');
+/*
+ * Build a custom SYS/BIOS library from sources.
+ */
+BIOS.libType = BIOS.LibType_Custom;
+
+/*
+ * The BIOS module will create the default heap for the system.
+ * Specify the size of this default heap.
+ */
+BIOS.heapSize = 0x1000;
+
+
+/* No runtime stack checking is performed */
+Task.checkStackFlag = false;
+
+/* Reduce the number of task priorities */
+Task.numPriorities = 4;
+
+/* ================ Driver configuration ================ */
+var socType           = "am574x";
+
+/*use CSL package*/
+var Csl = xdc.loadPackage('ti.csl');
+Csl.Settings.deviceType = socType;
+
+/* Load the OSAL package */
+var osType = "tirtos"
+var Osal = xdc.useModule('ti.osal.Settings');
+Osal.osType = osType;
+Osal.socType = socType;
+/* Load the MMCSD package */
+var Mmcsd = xdc.loadPackage('ti.drv.mmcsd');
+var Fatfs = xdc.loadPackage('ti.fs.fatfs');
+
+/* Load the GPIO package */
+var GPIO = xdc.loadPackage('ti.drv.gpio');
+
+/* Load the UART package */
+var UART = xdc.loadPackage('ti.drv.uart');    
+
+/* Load the I2C package */
+var I2C = xdc.loadPackage('ti.drv.i2c');    
+
+/* Load the Board package and set the board name */
+var Board = xdc.loadPackage('ti.board');
+Board.Settings.boardName = "idkAM574x";
+
+/* ================ Cache and MMU configuration ================ */
+
+var Cache1  = xdc.useModule('ti.sysbios.family.arm.a15.Cache');
+var Mmu = xdc.useModule('ti.sysbios.family.arm.a15.Mmu');
+
+/* Enable the cache */
+Cache1.enableCache = true;
+
+/* Enable the MMU (Required for L1 data caching) */
+Mmu.enableMMU = true;
+
+/* Map MMC1 regs in MMU */
+var peripheralAttrs = new Mmu.DescriptorAttrs();
+Mmu.initDescAttrsMeta(peripheralAttrs);
+peripheralAttrs.type = Mmu.DescriptorType_BLOCK;  // BLOCK descriptor
+peripheralAttrs.noExecute = true;                 // not executable
+peripheralAttrs.accPerm = 0;                      // read/write at PL1
+peripheralAttrs.attrIndx = 1;                     // MAIR0 Byte1 describes
+                                                  // memory attributes for
+                                                  // each BLOCK MMU entry
+var peripheralBaseAddr = 0x4ae00000;
+// Configure the corresponding MMU page descriptor accordingly
+Mmu.setSecondLevelDescMeta(peripheralBaseAddr,
+                           peripheralBaseAddr,
+                           peripheralAttrs);
+
+var attrs = new Mmu.DescriptorAttrs();
+Mmu.initDescAttrsMeta(attrs);
+attrs.type = Mmu.DescriptorType_BLOCK;
+attrs.noExecute = true;
+attrs.accPerm = 0;
+attrs.attrIndx = 1;
+
+/* Set IO Delay configuration areas as non-cache */
+Mmu.setSecondLevelDescMeta(0x4844a000, 0x4844a000, attrs);
+Mmu.setSecondLevelDescMeta(0x4ae07d00, 0x4ae07d00, attrs);
+
+
+/* ================ Memory sections configuration ================ */
+Program.sectMap["BOARD_IO_DELAY_DATA"] = "OCMC_RAM1";
+Program.sectMap["BOARD_IO_DELAY_CODE"] = "OCMC_RAM1";
diff --git a/packages/ti/fs/fatfs/example/console/am574x/c66/bios/FATFS_Console_idkAM574x_c66xExampleProject.txt b/packages/ti/fs/fatfs/example/console/am574x/c66/bios/FATFS_Console_idkAM574x_c66xExampleProject.txt
new file mode 100644 (file)
index 0000000..cd8878a
--- /dev/null
@@ -0,0 +1,8 @@
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/mmcsd/soc/am57xx/MMCSD_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/fs_shell_app_utils.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/main_console.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/FATFS_log.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/uart/soc/am574x/UART_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/drv/gpio/soc/am574x/GPIO_soc.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/am574x/c66/bios/fatfs_idk.cfg"
+-ccs.setCompilerOptions "-D -mv6600 -g -dSOC_AM574x -didkAM574x -dUSE_BIOS -dC66X -dNSS_GEN2  --diag_warning=225 --diag_warning=994 --diag_warning=262 --diag_suppress=1111 --diag_suppress=827  --diag_suppress=824  --diag_suppress=837  --diag_suppress=1037 --diag_suppress=195 --diag_suppress=77  --diag_suppress=232 -I${PDK_INSTALL_PATH}/ti/fs/fatfs"  -rtsc.enableRtsc
diff --git a/packages/ti/fs/fatfs/example/console/am574x/c66/bios/fatfs_idk.cfg b/packages/ti/fs/fatfs/example/console/am574x/c66/bios/fatfs_idk.cfg
new file mode 100644 (file)
index 0000000..ce9ae26
--- /dev/null
@@ -0,0 +1,122 @@
+/**
+ *  \file   fatfs_idk.cfg
+ *
+ *  \brief  Sysbios config file for fatfs C66X test project on AM574X IDK EVM.
+ *
+ */
+
+/*
+ * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of Texas Instruments Incorporated nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+/* ================ General configuration ================ */
+var Memory                      =   xdc.useModule('xdc.runtime.Memory');
+var HeapMem                     =   xdc.useModule('ti.sysbios.heaps.HeapMem');
+var HeapBuf                     =   xdc.useModule('ti.sysbios.heaps.HeapBuf');
+var Log                         =   xdc.useModule('xdc.runtime.Log');
+var Task                        =   xdc.useModule('ti.sysbios.knl.Task');
+var Semaphore                   =   xdc.useModule('ti.sysbios.knl.Semaphore');
+var Hwi                         =   xdc.useModule('ti.sysbios.family.c64p.Hwi');
+var ECM                         =   xdc.useModule('ti.sysbios.family.c64p.EventCombiner');
+var System                      =   xdc.useModule('xdc.runtime.System');
+SysStd                          =   xdc.useModule('xdc.runtime.SysStd');
+var IntXbar                     =   xdc.useModule('ti.sysbios.family.shared.vayu.IntXbar');
+
+System.SupportProxy             =   SysStd;
+
+/* Create a default system heap using ti.bios.HeapMem. */
+var heapMemParams1              =   new HeapMem.Params;
+heapMemParams1.size             =   8192 * 25;
+heapMemParams1.sectionName      =   "systemHeap";
+Program.global.heap0            =   HeapMem.create(heapMemParams1);
+
+/* This is the default memory heap. */
+Memory.defaultHeapInstance      =   Program.global.heap0;
+Program.sectMap["systemHeap"]   =   Program.platform.stackMemory;
+
+/*
+ * Enable Event Groups here and registering of ISR for specific GEM INTC is done
+ * using EventCombiner_dispatchPlug() and Hwi_eventMap() APIs
+ */
+var exception            =     xdc.useModule('ti.sysbios.family.c64p.Exception');
+exception.enablePrint = true;
+
+/* ================ BIOS configuration ================ */
+
+var BIOS                        =   xdc.useModule('ti.sysbios.BIOS'); 
+
+/* Enable BIOS Task Scheduler */
+BIOS.taskEnabled                       =   true;
+
+/* ================ Task configuration ================ */
+
+/* No runtime stack checking is performed */
+Task.checkStackFlag = false;
+
+
+/* Reduce the number of task priorities */
+Task.numPriorities = 4;
+
+
+/* ================ Driver configuration ================ */
+var socType           = "am574x";
+/*use CSL package*/
+var Csl = xdc.loadPackage('ti.csl');
+Csl.Settings.deviceType = socType;
+
+/* Load the OSAL package */
+var osType = "tirtos"
+var Osal = xdc.useModule('ti.osal.Settings');
+Osal.osType = osType;
+Osal.socType = socType;
+/* Load the MMCSD package */
+var Mmcsd = xdc.loadPackage('ti.drv.mmcsd');
+var Fatfs = xdc.loadPackage('ti.fs.fatfs');
+
+/* Load the GPIO package */
+var GPIO = xdc.loadPackage('ti.drv.gpio');
+
+/* Load the UART package */
+var UART = xdc.loadPackage('ti.drv.uart');    
+
+/* Load the I2C package */
+var I2C = xdc.loadPackage('ti.drv.i2c');    
+
+/* Load the Board package and set the board name */
+var Board = xdc.loadPackage('ti.board');
+Board.Settings.boardName = "idkAM574x";
+
+/* ================ Memory sections configuration ================ */
+Program.sectMap[".text"] = "EXT_RAM";
+Program.sectMap[".const"] = "EXT_RAM";
+Program.sectMap[".plt"] = "EXT_RAM";
+Program.sectMap["BOARD_IO_DELAY_DATA"] = "OCMC_RAM1";
+Program.sectMap["BOARD_IO_DELAY_CODE"] = "OCMC_RAM1";
diff --git a/packages/ti/fs/fatfs/example/console/am65xx/a53/fatfsConsole_a53.cfg b/packages/ti/fs/fatfs/example/console/am65xx/a53/fatfsConsole_a53.cfg
new file mode 100644 (file)
index 0000000..b994cdc
--- /dev/null
@@ -0,0 +1,211 @@
+
+/* =============================================================================
+ *   Copyright (c) Texas Instruments Incorporated 2018-Present
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *
+ *    Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the
+ *    distribution.
+ *
+ *    Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+var Defaults = xdc.useModule('xdc.runtime.Defaults');
+var Diags = xdc.useModule('xdc.runtime.Diags');
+var Error = xdc.useModule('xdc.runtime.Error');
+var Log = xdc.useModule('xdc.runtime.Log');
+var LoggerBuf = xdc.useModule('xdc.runtime.LoggerBuf');
+var Main = xdc.useModule('xdc.runtime.Main');
+var Memory = xdc.useModule('xdc.runtime.Memory')
+var System = xdc.useModule('xdc.runtime.System');
+var Text = xdc.useModule('xdc.runtime.Text');
+var Clock = xdc.useModule('ti.sysbios.knl.Clock');
+var Task = xdc.useModule('ti.sysbios.knl.Task');
+var Semaphore = xdc.useModule('ti.sysbios.knl.Semaphore');
+var HeapMem     = xdc.useModule ("ti.sysbios.heaps.HeapMem");
+
+var BIOS = xdc.useModule('ti.sysbios.BIOS');
+var Hwi = xdc.useModule('ti.sysbios.family.arm.gicv3.Hwi');
+
+var HeapMem = xdc.useModule('ti.sysbios.heaps.HeapMem');
+var SysMin = xdc.useModule('xdc.runtime.SysMin');
+BIOS.clockEnabled = true;
+
+/* Enable SMP mode in BIOS if SMP is enabled from makefile */
+var smp = java.lang.System.getenv("SMP")
+if(smp == 'enable')
+{
+    xdc.print("Enabling BIOS SMP mode");
+       BIOS.smpEnabled = true;
+}
+
+/* Enable cache */
+var Cache = xdc.module("ti.sysbios.hal.Cache");
+if(smp == null || smp == '')
+{
+    Cache.CacheProxy = xdc.useModule("ti.sysbios.family.arm.v8a.Cache");
+}
+
+/*
+ * Direct CIO to UART
+ */
+/* System.SupportProxy = SysUart; */
+System.SupportProxy = SysMin;
+
+/*
+ * Program.argSize sets the size of the .args section.
+ * The examples don't use command line args so argSize is set to 0.
+ */
+Program.argSize = 0x0;
+
+/*
+ * Uncomment this line to globally disable Asserts.
+ * All modules inherit the default from the 'Defaults' module.  You
+ * can override these defaults on a per-module basis using Module.common$.
+ * Disabling Asserts will save code space and improve runtime performance.
+Defaults.common$.diags_ASSERT = Diags.ALWAYS_OFF;
+ */
+
+/*
+ * Uncomment this line to keep module names from being loaded on the target.
+ * The module name strings are placed in the .const section. Setting this
+ * parameter to false will save space in the .const section.  Error and
+ * Assert messages will contain an "unknown module" prefix instead
+ * of the actual module name.
+Defaults.common$.namedModule = false;
+ */
+
+/* Create default heap and hook it into Memory */
+var heapMemParams = new HeapMem.Params;
+heapMemParams.size = 16384*3;
+var heap0 = HeapMem.create(heapMemParams);
+
+Memory.defaultHeapInstance = heap0;
+
+/*
+ * Minimize exit handler array in System.  The System module includes
+ * an array of functions that are registered with System_atexit() to be
+ * called by System_exit().
+ */
+System.maxAtexitHandlers = 4;
+
+/*
+ * Uncomment this line to disable the Error print function.
+ * We lose error information when this is disabled since the errors are
+ * not printed.  Disabling the raiseHook will save some code space if
+ * your app is not using System_printf() since the Error_print() function
+ * calls System_printf().
+Error.raiseHook = null;
+ */
+
+/*
+ * Uncomment this line to keep Error, Assert, and Log strings from being
+ * loaded on the target.  These strings are placed in the .const section.
+ * Setting this parameter to false will save space in the .const section.
+ * Error, Assert and Log message will print raw ids and args instead of
+ * a formatted message.
+Text.isLoaded = false;
+ */
+
+/*
+ * Uncomment this line to disable the output of characters by SysMin
+ * when the program exits.  SysMin writes characters to a circular buffer.
+ * This buffer can be viewed using the SysMin Output view in ROV.
+SysMin.flushAtExit = false;
+ */
+
+/*
+ * The BIOS module will create the default heap for the system.
+ * Specify the size of this default heap.
+ *
+ * BIOS.heapSize = 0x2000; */
+
+/* System stack size (used by ISRs and Swis) */
+Program.stack = 0x4000;
+
+Task.defaultStackSize = 0x4000;
+
+/*
+ * Create and install logger for the whole system
+ */
+var loggerBufParams = new LoggerBuf.Params();
+loggerBufParams.numEntries = 32;
+var logger0 = LoggerBuf.create(loggerBufParams);
+Defaults.common$.logger = logger0;
+Main.common$.diags_INFO = Diags.ALWAYS_ON;
+
+BIOS.libType = BIOS.LibType_Custom;
+BIOS.cpuFreq.lo = 800000000;
+BIOS.cpuFreq.hi = 0;
+
+
+var Timer = xdc.useModule('ti.sysbios.family.arm.v8a.Timer');
+Timer.intFreq.lo = 200000000;
+Timer.intFreq.hi = 0;
+
+var dmTimer = xdc.useModule('ti.sysbios.timers.dmtimer.Timer');
+for (var i = 0; i < 12; i++) {
+    dmTimer.intFreqs[i].lo = 25000000;
+    dmTimer.intFreqs[i].hi = 0;
+}
+
+var Mmu = xdc.useModule("ti.sysbios.family.arm.v8a.Mmu");
+Mmu.enableMMU = true;
+
+Mmu.initFunc = "&InitMmu";
+Mmu.tableArrayLen = 24;
+
+/* ================ Driver configuration ================ */
+
+var task0Params = new Task.Params();
+task0Params.priority = 5;
+task0Params.instance.name = "task0";
+task0Params.stackSize = 16*1024;
+
+var Clock = xdc.useModule('ti.sysbios.knl.Clock');
+Clock.tickPeriod = 1000;
+
+var Load = xdc.useModule('ti.sysbios.utils.Load');
+ // Load.common$.logger = loggerBuf0;
+var Diags = xdc.useModule('xdc.runtime.Diags');
+Load.common$.diags_USER4 = Diags.ALWAYS_ON;
+
+/* allocate a config-params object */
+var HeapParam = new HeapMem.Params;
+
+/* optionally assign per-instance configs */
+HeapParam.size = 200000;
+
+/* create an instance-object */
+Program.global.myHeap = HeapMem.create(HeapParam);
+
+
+var Load = xdc.useModule('ti.sysbios.utils.Load');
+ // Load.common$.logger = loggerBuf0;
+var Diags = xdc.useModule('xdc.runtime.Diags');
+Load.common$.diags_USER4 = Diags.ALWAYS_ON;
+
+// Program.sectMap[".text"] = "DDR";
+// Program.sectMap[".ti_sysbios_family_arm_v8a_Mmu_tableArray"] = "DDR";
+Program.sectMap[".ti_sysbios_family_arm_v8a_Mmu_tableArray"] = "MSMC_SRAM";
+//Program.sectMap[".c_int00"] = "MSMC_SRAM";
diff --git a/packages/ti/fs/fatfs/example/console/am65xx/r5/fatfsConsole_r5.cfg b/packages/ti/fs/fatfs/example/console/am65xx/r5/fatfsConsole_r5.cfg
new file mode 100644 (file)
index 0000000..db66b20
--- /dev/null
@@ -0,0 +1,154 @@
+
+/* =============================================================================
+ *   Copyright (c) Texas Instruments Incorporated 2018-Present
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *
+ *    Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the
+ *    distribution.
+ *
+ *    Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+var Defaults = xdc.useModule('xdc.runtime.Defaults');
+var Diags = xdc.useModule('xdc.runtime.Diags');
+var Error = xdc.useModule('xdc.runtime.Error');
+var Log = xdc.useModule('xdc.runtime.Log');
+var LoggerBuf = xdc.useModule('xdc.runtime.LoggerBuf');
+var Main = xdc.useModule('xdc.runtime.Main');
+var Memory = xdc.useModule('xdc.runtime.Memory')
+var System = xdc.useModule('xdc.runtime.System');
+var Text = xdc.useModule('xdc.runtime.Text');
+var Clock = xdc.useModule('ti.sysbios.knl.Clock');
+var Task = xdc.useModule('ti.sysbios.knl.Task');
+var Semaphore = xdc.useModule('ti.sysbios.knl.Semaphore');
+var HeapMem     = xdc.useModule ("ti.sysbios.heaps.HeapMem");
+
+var BIOS = xdc.useModule('ti.sysbios.BIOS');
+var Hwi = xdc.useModule('ti.sysbios.family.arm.v7r.keystone3.Hwi');
+var HeapMem = xdc.useModule('ti.sysbios.heaps.HeapMem');
+var SysMin = xdc.useModule('xdc.runtime.SysMin');
+BIOS.clockEnabled = true;
+/* Enable cache */
+var Cache = xdc.useModule('ti.sysbios.family.arm.v7r.Cache');
+Cache.enableCache = true;
+/*
+ * Direct CIO to UART
+ */
+/* System.SupportProxy = SysUart; */
+System.SupportProxy = SysMin;
+/* 
+ * Program.argSize sets the size of the .args section. 
+ * The examples don't use command line args so argSize is set to 0.
+ */
+Program.argSize = 0x0;
+
+/*
+ * Uncomment this line to globally disable Asserts.
+ * All modules inherit the default from the 'Defaults' module.  You
+ * can override these defaults on a per-module basis using Module.common$. 
+ * Disabling Asserts will save code space and improve runtime performance.
+Defaults.common$.diags_ASSERT = Diags.ALWAYS_OFF;
+ */
+
+/*
+ * Uncomment this line to keep module names from being loaded on the target.
+ * The module name strings are placed in the .const section. Setting this
+ * parameter to false will save space in the .const section.  Error and
+ * Assert messages will contain an "unknown module" prefix instead
+ * of the actual module name.
+Defaults.common$.namedModule = false;
+ */
+
+/* Create default heap and hook it into Memory */
+var heapMemParams = new HeapMem.Params;
+heapMemParams.size = 16384*3;
+var heap0 = HeapMem.create(heapMemParams);
+
+Memory.defaultHeapInstance = heap0;
+
+/*
+ * Minimize exit handler array in System.  The System module includes
+ * an array of functions that are registered with System_atexit() to be
+ * called by System_exit().
+ */
+System.maxAtexitHandlers = 4;       
+
+/* 
+ * Uncomment this line to disable the Error print function.  
+ * We lose error information when this is disabled since the errors are
+ * not printed.  Disabling the raiseHook will save some code space if
+ * your app is not using System_printf() since the Error_print() function
+ * calls System_printf().
+Error.raiseHook = null;
+ */
+
+/* 
+ * Uncomment this line to keep Error, Assert, and Log strings from being
+ * loaded on the target.  These strings are placed in the .const section.
+ * Setting this parameter to false will save space in the .const section.
+ * Error, Assert and Log message will print raw ids and args instead of
+ * a formatted message.
+Text.isLoaded = false;
+ */
+
+/*
+ * Uncomment this line to disable the output of characters by SysMin
+ * when the program exits.  SysMin writes characters to a circular buffer.
+ * This buffer can be viewed using the SysMin Output view in ROV.
+SysMin.flushAtExit = false;
+ */
+
+/* 
+ * The BIOS module will create the default heap for the system.
+ * Specify the size of this default heap.
+ *
+ * BIOS.heapSize = 0x2000; */
+
+/* System stack size (used by ISRs and Swis) */
+Program.stack = 0x4000;
+
+Task.defaultStackSize = 0x4000;
+
+/* 
+ * Create and install logger for the whole system
+ */
+var loggerBufParams = new LoggerBuf.Params();
+loggerBufParams.numEntries = 32;
+var logger0 = LoggerBuf.create(loggerBufParams);
+Defaults.common$.logger = logger0;
+Main.common$.diags_INFO = Diags.ALWAYS_ON;
+
+BIOS.libType = BIOS.LibType_Custom;
+
+/* Disable Timer frequency check */
+var Timer = xdc.useModule('ti.sysbios.timers.dmtimer.Timer');
+Timer.checkFrequency = false;
+
+/*
+ * Initialize MPU and enable it
+ *
+ * Note: MPU must be enabled and properly configured for caching to work.
+ */
+xdc.loadCapsule("mpu.xs");
+
diff --git a/packages/ti/fs/fatfs/example/console/am65xx/r5/mpu.xs b/packages/ti/fs/fatfs/example/console/am65xx/r5/mpu.xs
new file mode 100644 (file)
index 0000000..bd89bbe
--- /dev/null
@@ -0,0 +1,146 @@
+/*
+ * Copyright (c) 2018, Texas Instruments Incorporated
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * *  Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * *  Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * *  Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+/*
+ *  ======== event_MPU.xs ========
+ *  MPU Settings for SIMMAXWELL device's Cortex-R5F
+ */
+
+/*
+ *  -------------------------------------------------------------------------------------------------------------
+ * | Id | Base Address | Size | En | Cacheable                                 | XN | AccPerm             | Mask |
+ * |-------------------------------------------------------------------------------------------------------------|
+ * | 0  | 0x00000000   | 4GB  | T  | Strongly Ordered, Shareable               | T  | RW at PL 1          | 0x0  |
+ * |----|--------------|------|----|-------------------------------------------|----|---------------------|------|
+ * | 1  | 0x00000000   | 1K   | T  | Write-Back, Write-Allocate, Non-Shareable | F  | RW at PL 1          | 0x0  |
+ * |----|--------------|------|----|-------------------------------------------|----|---------------------|------|
+ * | 2  | 0x41000000   | 32K  | T  | Write-Back, Write-Allocate, Non-Shareable | F  | RW at PL 1          | 0x0  |
+ * |----|--------------|------|----|-------------------------------------------|----|---------------------|------|
+ * | 3  | 0x41010000   | 32K  | T  | Write-Back, Write-Allocate, Non-Shareable | F  | RW at PL 1          | 0x0  |
+ * |----|--------------|------|----|-------------------------------------------|----|---------------------|------|
+ * | 4  | 0x41C00000   | 512K | T  | Write-Back, Write-Allocate, Non-Shareable | F  | RW at PL 1          | 0x0  |
+ *  -------------------------------------------------------------------------------------------------------------
+ */
+
+/*
+ * Note: Marking a region as shareable will cause the region to behave as outer shareable with write through
+ *       no write-allocate caching policy irrespective of the actual cache policy set. Therefore, only select
+ *       regions that are actually shared outside the R5 CPUSS must be marked as shared.
+ */
+
+var MPU = xdc.useModule('ti.sysbios.family.arm.MPU');
+MPU.enableMPU = true;
+MPU.enableBackgroundRegion = true;
+
+var attrs = new MPU.RegionAttrs();
+MPU.initRegionAttrsMeta(attrs);
+
+attrs.enable = true;
+attrs.bufferable = false;
+attrs.cacheable = false;
+attrs.shareable = true;
+attrs.noExecute = true;
+attrs.accPerm = 1;          /* RW at PL1 */
+attrs.tex = 0;
+attrs.subregionDisableMask = 0;
+MPU.setRegionMeta(0, 0x00000000, MPU.RegionSize_4G, attrs);
+
+attrs.enable = true;
+attrs.bufferable = true;
+attrs.cacheable = true;
+attrs.shareable = false;
+attrs.noExecute = false;
+attrs.accPerm = 1;          /* RW at PL1 */
+attrs.tex = 1;
+attrs.subregionDisableMask = 0;
+MPU.setRegionMeta(1, 0x00000000, MPU.RegionSize_32K, attrs);
+
+attrs.enable = true;
+attrs.bufferable = true;
+attrs.cacheable = true;
+attrs.shareable = false;
+attrs.noExecute = false;
+attrs.accPerm = 1;          /* RW at PL1 */
+attrs.tex = 1;
+attrs.subregionDisableMask = 0;
+MPU.setRegionMeta(2, 0x41000000, MPU.RegionSize_32K, attrs);
+
+attrs.enable = true;
+attrs.bufferable = true;
+attrs.cacheable = true;
+attrs.shareable = false;
+attrs.noExecute = false;
+attrs.accPerm = 1;          /* RW at PL1 */
+attrs.tex = 1;
+attrs.subregionDisableMask = 0x0;
+MPU.setRegionMeta(3, 0x41010000, MPU.RegionSize_32K, attrs);
+
+attrs.enable = true;
+attrs.bufferable = true;
+attrs.cacheable = true;
+attrs.shareable = false;
+attrs.noExecute = false;
+attrs.accPerm = 1;          /* RW at PL1 */
+attrs.tex = 1;
+attrs.subregionDisableMask = 0;
+MPU.setRegionMeta(4, 0x41C00000, MPU.RegionSize_512K, attrs);
+
+attrs.enable = true;
+attrs.bufferable = true;
+attrs.cacheable = true;
+attrs.shareable = false;
+attrs.noExecute = false;
+attrs.accPerm = 1;          /* RW at PL1 */
+attrs.tex = 1;
+attrs.subregionDisableMask = 0;
+MPU.setRegionMeta(4, 0x4F800000, MPU.RegionSize_512K, attrs);
+
+
+attrs.enable = true;
+attrs.bufferable = true;
+attrs.cacheable = true;
+attrs.shareable = false;
+attrs.noExecute = false;
+attrs.accPerm = 1;          /* RW at PL1 */
+attrs.tex = 1;
+attrs.subregionDisableMask = 0;
+MPU.setRegionMeta(5, 0x70000000, MPU.RegionSize_2M, attrs);
+
+
+attrs.enable = true;
+attrs.bufferable = true;
+attrs.cacheable = true;
+attrs.shareable = false;
+attrs.noExecute = false;
+attrs.accPerm = 1;          /* RW at PL1 */
+attrs.tex = 1;
+attrs.subregionDisableMask = 0;
+MPU.setRegionMeta(6, 0x04000000, MPU.RegionSize_2M, attrs);
diff --git a/packages/ti/fs/fatfs/example/console/dra7xx/armv7/bios/FATFS_Console_evmDRA72x_armExampleProject.txt b/packages/ti/fs/fatfs/example/console/dra7xx/armv7/bios/FATFS_Console_evmDRA72x_armExampleProject.txt
new file mode 100644 (file)
index 0000000..bb0fd93
--- /dev/null
@@ -0,0 +1,7 @@
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/fs_shell_app_utils.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/main_console.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/FATFS_log.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/dra7xx/armv7/bios/fatfs.cfg"
+-ccs.setCompilerOptions "-c -mcpu=cortex-a15 -mtune=cortex-a15 -marm -mfloat-abi=hard -DSOC_DRA72x -DevmDRA72x -g -gstrict-dwarf -Wall -MMD -MP -I${PDK_INSTALL_PATH}/ti/fs/fatfs "  -rtsc.enableRtsc
+-ccs.setLinkerOptions " -lrdimon -lgcc -lm -lnosys -nostartfiles -static -Wl,--gc-sections -L$(BIOS_INSTALL_PATH)/packages/gnu/targets/arm/libs/install-native/arm-none-eabi/lib/fpu "
+-rtsc.setConfiguroOptions "--cfgArgs {SOC:\"dra72x\", BOARD:\"evmDRA72x\"}"
diff --git a/packages/ti/fs/fatfs/example/console/dra7xx/armv7/bios/FATFS_Console_evmDRA75x_armExampleProject.txt b/packages/ti/fs/fatfs/example/console/dra7xx/armv7/bios/FATFS_Console_evmDRA75x_armExampleProject.txt
new file mode 100644 (file)
index 0000000..48d0cdb
--- /dev/null
@@ -0,0 +1,7 @@
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/fs_shell_app_utils.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/main_console.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/FATFS_log.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/dra7xx/armv7/bios/fatfs.cfg"
+-ccs.setCompilerOptions "-c -mcpu=cortex-a15 -mtune=cortex-a15 -marm -mfloat-abi=hard -DSOC_DRA75x -DevmDRA75x -g -gstrict-dwarf -Wall -MMD -MP -I${PDK_INSTALL_PATH}/ti/fs/fatfs "  -rtsc.enableRtsc
+-ccs.setLinkerOptions " -lrdimon -lgcc -lm -lnosys -nostartfiles -static -Wl,--gc-sections -L$(BIOS_INSTALL_PATH)/packages/gnu/targets/arm/libs/install-native/arm-none-eabi/lib/fpu "
+-rtsc.setConfiguroOptions "--cfgArgs {SOC:\"dra75x\", BOARD:\"evmDRA75x\"}"
diff --git a/packages/ti/fs/fatfs/example/console/dra7xx/armv7/bios/fatfs.cfg b/packages/ti/fs/fatfs/example/console/dra7xx/armv7/bios/fatfs.cfg
new file mode 100644 (file)
index 0000000..ad9bf30
--- /dev/null
@@ -0,0 +1,241 @@
+/**
+ *  \file   fatfs.cfg
+ *
+ *  \brief  Sysbios config file for fatfs example project on DRA7xx EVMs.
+ *
+ */
+
+/*
+ * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of Texas Instruments Incorporated nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+/* ================ General configuration ================ */
+var Defaults  = xdc.useModule('xdc.runtime.Defaults');
+var Diags     = xdc.useModule('xdc.runtime.Diags');
+var Error     = xdc.useModule('xdc.runtime.Error');
+var Log       = xdc.useModule('xdc.runtime.Log');
+var LoggerBuf = xdc.useModule('xdc.runtime.LoggerBuf');
+var Main      = xdc.useModule('xdc.runtime.Main');
+var Memory    = xdc.useModule('xdc.runtime.Memory');
+var SysMin    = xdc.useModule('xdc.runtime.SysMin');
+var System    = xdc.useModule('xdc.runtime.System');
+var Text      = xdc.useModule('xdc.runtime.Text');
+var Clock     = xdc.useModule('ti.sysbios.knl.Clock');
+var Swi       = xdc.useModule('ti.sysbios.knl.Swi');
+var Task      = xdc.useModule('ti.sysbios.knl.Task');
+var Semaphore = xdc.useModule('ti.sysbios.knl.Semaphore');
+var Hwi       = xdc.useModule('ti.sysbios.hal.Hwi');
+var ti_sysbios_family_arm_gic_Hwi = xdc.useModule('ti.sysbios.family.arm.gic.Hwi');
+var Cache     = xdc.useModule('ti.sysbios.hal.Cache');
+var IntXbar   = xdc.useModule('ti.sysbios.family.shared.vayu.IntXbar');
+
+var SourceDir = xdc.useModule('xdc.cfg.SourceDir');
+SourceDir.outputDir = "src";
+
+/*
+ * Program.argSize sets the size of the .args section.
+ * The examples don't use command line args so argSize is set to 0.
+ */
+Program.argSize = 0x0;
+
+/* System stack size (used by ISRs and Swis) */
+Program.stack = 0x20000;
+
+/*
+ * Uncomment this line to globally disable Asserts.
+ * All modules inherit the default from the 'Defaults' module.  You
+ * can override these defaults on a per-module basis using Module.common$.
+ * Disabling Asserts will save code space and improve runtime performance.
+Defaults.common$.diags_ASSERT = Diags.ALWAYS_OFF;
+ */
+
+/*
+ * Uncomment this line to keep module names from being loaded on the target.
+ * The module name strings are placed in the .const section. Setting this
+ * parameter to false will save space in the .const section.  Error and
+ * Assert messages will contain an "unknown module" prefix instead
+ * of the actual module name.
+Defaults.common$.namedModule = false;
+ */
+
+/*
+ * Minimize exit handler array in System.  The System module includes
+ * an array of functions that are registered with System_atexit() to be
+ * called by System_exit().
+ */
+System.maxAtexitHandlers = 4;
+
+/*
+ * Uncomment this line to disable the Error print function.
+ * We lose error information when this is disabled since the errors are
+ * not printed.  Disabling the raiseHook will save some code space if
+ * your app is not using System_printf() since the Error_print() function
+ * calls System_printf().
+Error.raiseHook = null;
+ */
+
+/*
+ * Uncomment this line to keep Error, Assert, and Log strings from being
+ * loaded on the target.  These strings are placed in the .const section.
+ * Setting this parameter to false will save space in the .const section.
+ * Error, Assert and Log message will print raw ids and args instead of
+ * a formatted message.
+Text.isLoaded = false;
+ */
+
+/*
+ * Uncomment this line to disable the output of characters by SysMin
+ * when the program exits.  SysMin writes characters to a circular buffer.
+ * This buffer can be viewed using the SysMin Output view in ROV.
+SysMin.flushAtExit = false;
+ */
+
+/* Circular buffer size for System_printf() */
+SysMin.bufSize      = 0x200;
+System.SupportProxy = SysMin;
+
+/*
+ * Create and install logger for the whole system
+ */
+var loggerBufParams = new LoggerBuf.Params();
+loggerBufParams.numEntries = 16;
+var logger0         = LoggerBuf.create(loggerBufParams);
+Defaults.common$.logger    = logger0;
+Main.common$.diags_INFO    = Diags.ALWAYS_ON;
+
+if (Program.build.target.$name.match(/ gnu /))
+{
+    if (Program.build.target.$name.match(/ A8F /) ||
+        Program.build.target.$name.match(/ A9F /) ||
+        Program.build.target.$name.match(/ A15F /))
+    {
+        var SemiHost = xdc.useModule('ti.sysbios.rts.gnu.SemiHostSupport');
+    }
+}
+
+/* ================ BIOS configuration ================ */
+
+var BIOS = xdc.useModule('ti.sysbios.BIOS');
+/*
+ * Build a custom SYS/BIOS library from sources.
+ */
+BIOS.libType = BIOS.LibType_Custom;
+
+/*
+ * The BIOS module will create the default heap for the system.
+ * Specify the size of this default heap.
+ */
+BIOS.heapSize = 0x1000;
+
+/* No runtime stack checking is performed */
+Task.checkStackFlag = false;
+
+/* Reduce the number of task priorities */
+Task.numPriorities = 4;
+
+/* ================ Driver configuration ================ */
+var soc   = Program.build.cfgArgs.SOC.toLowerCase();
+var board = Program.build.cfgArgs.BOARD;
+xdc.print("# !!!  Current soc is [" + soc + "] !!!");
+xdc.print("# !!!  Current board is [" + board + "] !!!");
+
+/*use CSL package*/
+var Csl = xdc.loadPackage('ti.csl');
+Csl.Settings.deviceType = soc;
+
+/* Load the OSAL package */
+var osType = "tirtos";
+var Osal   = xdc.useModule('ti.osal.Settings');
+Osal.osType  = osType;
+Osal.socType = soc;
+
+/* Load the MMCSD package */
+var Mmcsd = xdc.loadPackage('ti.drv.mmcsd');
+Mmcsd.Settings.socType = soc;
+
+var Fatfs = xdc.loadPackage('ti.fs.fatfs');
+
+/* Load the GPIO package */
+var GPIO = xdc.loadPackage('ti.drv.gpio');
+GPIO.Settings.socType = soc;
+
+/* Load the UART package */
+var UART = xdc.loadPackage('ti.drv.uart');
+UART.Settings.socType = soc;
+
+/* Load the I2C package */
+var I2C = xdc.loadPackage('ti.drv.i2c');
+I2C.Settings.socType = soc;
+
+/* Load the Board package and set the board name */
+var Board = xdc.loadPackage('ti.board');
+Board.Settings.boardName = board;
+
+/* ================ Cache and MMU configuration ================ */
+
+var Cache1 = xdc.useModule('ti.sysbios.family.arm.a15.Cache');
+var Mmu    = xdc.useModule('ti.sysbios.family.arm.a15.Mmu');
+
+/* Enable the cache */
+Cache1.enableCache = true;
+
+/* Enable the MMU (Required for L1 data caching) */
+Mmu.enableMMU = true;
+
+/* Map MMC1 regs in MMU */
+var peripheralAttrs = new Mmu.DescriptorAttrs();
+Mmu.initDescAttrsMeta(peripheralAttrs);
+peripheralAttrs.type      = Mmu.DescriptorType_BLOCK; /* BLOCK descriptor */
+peripheralAttrs.noExecute = true;                     /* not executable */
+peripheralAttrs.accPerm   = 0;                        /* read/write at PL1 */
+peripheralAttrs.attrIndx  = 1;                        /* MAIR0 Byte1 describes */
+                                                      /* memory attributes for */
+                                                      /* each BLOCK MMU entry */
+var peripheralBaseAddr = 0x4ae00000;
+/* Configure the corresponding MMU page descriptor accordingly */
+Mmu.setSecondLevelDescMeta(peripheralBaseAddr,
+                           peripheralBaseAddr,
+                           peripheralAttrs);
+
+var attrs = new Mmu.DescriptorAttrs();
+Mmu.initDescAttrsMeta(attrs);
+attrs.type      = Mmu.DescriptorType_BLOCK;
+attrs.noExecute = true;
+attrs.accPerm   = 0;
+attrs.attrIndx  = 1;
+
+/* Set IO Delay configuration areas as non-cache */
+Mmu.setSecondLevelDescMeta(0x4844a000, 0x4844a000, attrs);
+Mmu.setSecondLevelDescMeta(0x4ae07d00, 0x4ae07d00, attrs);
+
+/* ================ Memory sections configuration ================ */
+Program.sectMap["BOARD_IO_DELAY_DATA"] = "OCMC_RAM1";
+Program.sectMap["BOARD_IO_DELAY_CODE"] = "OCMC_RAM1";
diff --git a/packages/ti/fs/fatfs/example/console/dra7xx/c66/bios/FATFS_Console_evmDRA72x_c66xExampleProject.txt b/packages/ti/fs/fatfs/example/console/dra7xx/c66/bios/FATFS_Console_evmDRA72x_c66xExampleProject.txt
new file mode 100644 (file)
index 0000000..f74869d
--- /dev/null
@@ -0,0 +1,6 @@
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/fs_shell_app_utils.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/main_console.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/FATFS_log.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/dra7xx/c66/bios/fatfs.cfg"
+-ccs.setCompilerOptions "-D -mv6600 -g -dSOC_DRA72x -devmDRA72x --diag_warning=225 --diag_warning=994 --diag_warning=262 --diag_suppress=1111 --diag_suppress=827  --diag_suppress=824  --diag_suppress=837  --diag_suppress=1037 --diag_suppress=195 --diag_suppress=77  --diag_suppress=232 -I${PDK_INSTALL_PATH}/ti/fs/fatfs"  -rtsc.enableRtsc
+-rtsc.setConfiguroOptions "--cfgArgs {SOC:\"dra72x\", BOARD:\"evmDRA72x\"}"
diff --git a/packages/ti/fs/fatfs/example/console/dra7xx/c66/bios/FATFS_Console_evmDRA75x_c66xExampleProject.txt b/packages/ti/fs/fatfs/example/console/dra7xx/c66/bios/FATFS_Console_evmDRA75x_c66xExampleProject.txt
new file mode 100644 (file)
index 0000000..2bf33a1
--- /dev/null
@@ -0,0 +1,6 @@
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/fs_shell_app_utils.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/main_console.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/FATFS_log.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/dra7xx/c66/bios/fatfs.cfg"
+-ccs.setCompilerOptions "-D -mv6600 -g -dSOC_DRA75x -devmDRA75x --diag_warning=225 --diag_warning=994 --diag_warning=262 --diag_suppress=1111 --diag_suppress=827  --diag_suppress=824  --diag_suppress=837  --diag_suppress=1037 --diag_suppress=195 --diag_suppress=77  --diag_suppress=232 -I${PDK_INSTALL_PATH}/ti/fs/fatfs"  -rtsc.enableRtsc
+-rtsc.setConfiguroOptions "--cfgArgs {SOC:\"dra75x\", BOARD:\"evmDRA75x\"}"
diff --git a/packages/ti/fs/fatfs/example/console/dra7xx/c66/bios/FATFS_Console_evmDRA78x_c66xExampleProject.txt b/packages/ti/fs/fatfs/example/console/dra7xx/c66/bios/FATFS_Console_evmDRA78x_c66xExampleProject.txt
new file mode 100644 (file)
index 0000000..7d3ea3c
--- /dev/null
@@ -0,0 +1,6 @@
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/fs_shell_app_utils.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/main_console.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/FATFS_log.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/dra7xx/c66/bios/fatfs.cfg"
+-ccs.setCompilerOptions "-D -mv6600 -g -dSOC_DRA78x -devmDRA78x --diag_warning=225 --diag_warning=994 --diag_warning=262 --diag_suppress=1111 --diag_suppress=827  --diag_suppress=824  --diag_suppress=837  --diag_suppress=1037 --diag_suppress=195 --diag_suppress=77  --diag_suppress=232 -I${PDK_INSTALL_PATH}/ti/fs/fatfs"  -rtsc.enableRtsc
+-rtsc.setConfiguroOptions "--cfgArgs {SOC:\"dra78x\", BOARD:\"evmDRA78x\"}"
diff --git a/packages/ti/fs/fatfs/example/console/dra7xx/c66/bios/fatfs.cfg b/packages/ti/fs/fatfs/example/console/dra7xx/c66/bios/fatfs.cfg
new file mode 100644 (file)
index 0000000..c43ac5d
--- /dev/null
@@ -0,0 +1,144 @@
+/**\r
+ *  \file   fatfs.cfg\r
+ *\r
+ *  \brief  Sysbios config file for fatfs C66X test project on DRA7xx EVMs.\r
+ *\r
+ */\r
+\r
+/*\r
+ * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * Redistributions of source code must retain the above copyright\r
+ * notice, this list of conditions and the following disclaimer.\r
+ *\r
+ * Redistributions in binary form must reproduce the above copyright\r
+ * notice, this list of conditions and the following disclaimer in the\r
+ * documentation and/or other materials provided with the\r
+ * distribution.\r
+ *\r
+ * Neither the name of Texas Instruments Incorporated nor the names of\r
+ * its contributors may be used to endorse or promote products derived\r
+ * from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ *\r
+ */\r
+/* ================ General configuration ================ */\r
+var Memory    = xdc.useModule('xdc.runtime.Memory');\r
+var HeapMem   = xdc.useModule('ti.sysbios.heaps.HeapMem');\r
+var HeapBuf   = xdc.useModule('ti.sysbios.heaps.HeapBuf');\r
+var Log       = xdc.useModule('xdc.runtime.Log');\r
+var Task      = xdc.useModule('ti.sysbios.knl.Task');\r
+var Semaphore = xdc.useModule('ti.sysbios.knl.Semaphore');\r
+var ECM       = xdc.useModule('ti.sysbios.family.c64p.EventCombiner');\r
+var Hwi       = xdc.useModule('ti.sysbios.hal.Hwi');\r
+var System    = xdc.useModule('xdc.runtime.System');\r
+var SysStd    = xdc.useModule('xdc.runtime.SysStd');\r
+var IntXbar   = xdc.useModule('ti.sysbios.family.shared.vayu.IntXbar');\r
+System.SupportProxy = SysStd;\r
+\r
+var SourceDir = xdc.useModule('xdc.cfg.SourceDir');\r
+SourceDir.outputDir = "src";\r
+\r
+/* Create a default system heap using ti.bios.HeapMem. */\r
+var heapMemParams1         = new HeapMem.Params;\r
+heapMemParams1.size        = 8192 * 25;\r
+heapMemParams1.sectionName = "systemHeap";\r
+Program.global.heap0       = HeapMem.create(heapMemParams1);\r
+\r
+/* This is the default memory heap. */\r
+Memory.defaultHeapInstance    = Program.global.heap0;\r
+Program.sectMap["systemHeap"] = Program.platform.stackMemory;\r
+\r
+/*\r
+ * Enable Event Groups here and registering of ISR for specific GEM INTC is done\r
+ * using EventCombiner_dispatchPlug() and Hwi_eventMap() APIs\r
+ */\r
+var exception         = xdc.useModule('ti.sysbios.family.c64p.Exception');\r
+exception.enablePrint = true;\r
+\r
+/* ================ BIOS configuration ================ */\r
+\r
+var BIOS = xdc.useModule('ti.sysbios.BIOS');\r
+\r
+/* Enable BIOS Task Scheduler */\r
+BIOS.taskEnabled = true;\r
+\r
+/* ================ Task configuration ================ */\r
+\r
+/* No runtime stack checking is performed */\r
+Task.checkStackFlag = false;\r
+\r
+/* Reduce the number of task priorities */\r
+Task.numPriorities = 4;\r
+\r
+/* ================ Driver configuration ================ */\r
+var soc   = Program.build.cfgArgs.SOC.toLowerCase();\r
+var board = Program.build.cfgArgs.BOARD;\r
+xdc.print("# !!!  Current soc is [" + soc + "] !!!");\r
+xdc.print("# !!!  Current board is [" + board + "] !!!");\r
+\r
+/*use CSL package*/\r
+var Csl = xdc.loadPackage('ti.csl');\r
+Csl.Settings.deviceType = soc;\r
+\r
+/* Load the OSAL package */\r
+var osType = "tirtos";\r
+var Osal = xdc.useModule('ti.osal.Settings');\r
+Osal.osType = osType;\r
+Osal.socType = soc;\r
+\r
+/* Load the MMCSD package */\r
+var Mmcsd = xdc.loadPackage('ti.drv.mmcsd');\r
+Mmcsd.Settings.socType = soc;\r
+\r
+var Fatfs = xdc.loadPackage('ti.fs.fatfs');\r
+\r
+/* Load the GPIO package */\r
+var GPIO = xdc.loadPackage('ti.drv.gpio');\r
+GPIO.Settings.socType = soc;\r
+\r
+/* Load the UART package */\r
+var UART = xdc.loadPackage('ti.drv.uart');\r
+UART.Settings.socType = soc;\r
+\r
+/* Load the I2C package */\r
+var I2C = xdc.loadPackage('ti.drv.i2c');\r
+I2C.Settings.socType = soc;\r
+\r
+/* Load the Board package and set the board name */\r
+var Board = xdc.loadPackage('ti.board');\r
+Board.Settings.boardName = board;\r
+\r
+/* ================ Memory sections configuration ================ */\r
+Program.sectMap[".text"] = "EXT_RAM";\r
+Program.sectMap[".const"] = "EXT_RAM";\r
+Program.sectMap[".plt"] = "EXT_RAM";\r
+\r
+if (soc == "dra72x" || soc == "dra75x")\r
+{\r
+    /* Place IODELAY code in OCMC_RAM1 as DDR exeuction of this code will lead to\r
+     * failures.\r
+     */\r
+    Program.sectMap["BOARD_IO_DELAY_DATA"] = "OCMC_RAM1";\r
+    Program.sectMap["BOARD_IO_DELAY_CODE"] = "OCMC_RAM1";\r
+}\r
+\r
+/* Align DSP entry point address according to the SBL requirements */\r
+Program.sectMap[".text:_c_int00"] = new Program.SectionSpec();\r
+Program.sectMap[".text:_c_int00"].loadSegment = "EXT_RAM";\r
+Program.sectMap[".text:_c_int00"].loadAlign = 0x400;\r
diff --git a/packages/ti/fs/fatfs/example/console/dra7xx/m4/bios/FATFS_Console_evmDRA72x_m4ExampleProject.txt b/packages/ti/fs/fatfs/example/console/dra7xx/m4/bios/FATFS_Console_evmDRA72x_m4ExampleProject.txt
new file mode 100644 (file)
index 0000000..b0b8e7d
--- /dev/null
@@ -0,0 +1,7 @@
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/fs_shell_app_utils.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/main_console.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/FATFS_log.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/dra7xx/m4/bios/fatfs.cfg"
+-ccs.setCompilerOptions "-qq -pdsw255 -mv7M4 --float_support=vfplib --abi=eabi -g -DSOC_DRA72x -DevmDRA72x -Dti_targets_arm_elf_M4 -I${PDK_INSTALL_PATH}/ti/drv/mmcsd "  -rtsc.enableRtsc
+-ccs.setLinkerOptions "--strict_compatibility=on"
+-rtsc.setConfiguroOptions "--cfgArgs {SOC:\"dra72x\", BOARD:\"evmDRA72x\"}"
diff --git a/packages/ti/fs/fatfs/example/console/dra7xx/m4/bios/FATFS_Console_evmDRA75x_m4ExampleProject.txt b/packages/ti/fs/fatfs/example/console/dra7xx/m4/bios/FATFS_Console_evmDRA75x_m4ExampleProject.txt
new file mode 100644 (file)
index 0000000..32f025c
--- /dev/null
@@ -0,0 +1,7 @@
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/fs_shell_app_utils.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/main_console.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/FATFS_log.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/dra7xx/m4/bios/fatfs.cfg"
+-ccs.setCompilerOptions "-qq -pdsw255 -mv7M4 --float_support=vfplib --abi=eabi -g -DSOC_DRA75x -DevmDRA75x -Dti_targets_arm_elf_M4 -I${PDK_INSTALL_PATH}/ti/drv/mmcsd "  -rtsc.enableRtsc
+-ccs.setLinkerOptions "--strict_compatibility=on"
+-rtsc.setConfiguroOptions "--cfgArgs {SOC:\"dra75x\", BOARD:\"evmDRA75x\"}"
diff --git a/packages/ti/fs/fatfs/example/console/dra7xx/m4/bios/FATFS_Console_evmDRA78x_m4ExampleProject.txt b/packages/ti/fs/fatfs/example/console/dra7xx/m4/bios/FATFS_Console_evmDRA78x_m4ExampleProject.txt
new file mode 100644 (file)
index 0000000..d21265b
--- /dev/null
@@ -0,0 +1,7 @@
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/fs_shell_app_utils.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/main_console.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/src/FATFS_log.c"
+-ccs.linkFile "PDK_INSTALL_PATH/ti/fs/fatfs/example/console/dra7xx/m4/bios/fatfs.cfg"
+-ccs.setCompilerOptions "-qq -pdsw255 -mv7M4 --float_support=vfplib --abi=eabi -g -DSOC_DRA78x -DevmDRA78x -Dti_targets_arm_elf_M4 -I${PDK_INSTALL_PATH}/ti/drv/mmcsd "  -rtsc.enableRtsc
+-ccs.setLinkerOptions "--strict_compatibility=on"
+-rtsc.setConfiguroOptions "--cfgArgs {SOC:\"dra78x\", BOARD:\"evmDRA78x\"}"
diff --git a/packages/ti/fs/fatfs/example/console/dra7xx/m4/bios/fatfs.cfg b/packages/ti/fs/fatfs/example/console/dra7xx/m4/bios/fatfs.cfg
new file mode 100644 (file)
index 0000000..d0da2e0
--- /dev/null
@@ -0,0 +1,233 @@
+/**\r
+ *  \file   fatfs.cfg\r
+ *\r
+ *  \brief  Sysbios config file for mmcsd M4 example project on DRA7x EVMs.\r
+ *\r
+ */\r
+\r
+/*\r
+ * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * Redistributions of source code must retain the above copyright\r
+ * notice, this list of conditions and the following disclaimer.\r
+ *\r
+ * Redistributions in binary form must reproduce the above copyright\r
+ * notice, this list of conditions and the following disclaimer in the\r
+ * documentation and/or other materials provided with the\r
+ * distribution.\r
+ *\r
+ * Neither the name of Texas Instruments Incorporated nor the names of\r
+ * its contributors may be used to endorse or promote products derived\r
+ * from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ *\r
+ */\r
+/* ================ General configuration ================ */\r
+var Main      = xdc.useModule('xdc.runtime.Main');\r
+var System    = xdc.useModule('xdc.runtime.System');\r
+var Task      = xdc.useModule('ti.sysbios.knl.Task');\r
+var Mailbox   = xdc.useModule('ti.sysbios.knl.Mailbox');\r
+var Semaphore = xdc.useModule('ti.sysbios.knl.Semaphore');\r
+var Timer     = xdc.useModule('ti.sysbios.hal.Timer');\r
+var IntXbar   = xdc.useModule('ti.sysbios.family.shared.vayu.IntXbar');\r
+\r
+var SourceDir = xdc.useModule('xdc.cfg.SourceDir');\r
+SourceDir.outputDir = "src";\r
+\r
+/* ================ BIOS configuration ================ */\r
+\r
+var BIOS = xdc.useModule('ti.sysbios.BIOS');\r
+\r
+/*\r
+ * Create and install logger for the whole system\r
+ */\r
+BIOS.libType = BIOS.LibType_Custom;\r
+/*\r
+ * The BIOS module will create the default heap for the system.\r
+ * Specify the size of this default heap.\r
+ */\r
+BIOS.heapSize = 0xA0000;\r
+\r
+/* ================ Driver configuration ================ */\r
+var soc   = Program.build.cfgArgs.SOC.toLowerCase();\r
+var board = Program.build.cfgArgs.BOARD;\r
+xdc.print("# !!!  Current soc is [" + soc + "] !!!");\r
+xdc.print("# !!!  Current board is [" + board + "] !!!");\r
+\r
+/*use CSL package*/\r
+var Csl = xdc.loadPackage('ti.csl');\r
+Csl.Settings.deviceType = soc;\r
+\r
+/* Load the Osal package */\r
+var osType           = "tirtos";\r
+var Osal             = xdc.loadPackage('ti.osal');\r
+Osal.Settings.osType  = osType;\r
+Osal.Settings.socType = soc;\r
+\r
+/* Load the mmcsd package */\r
+var Mmcsd             = xdc.loadPackage('ti.drv.mmcsd');\r
+Mmcsd.Settings.socType = soc;\r
+\r
+/* Load the fatfs package */\r
+var Fatfs = xdc.loadPackage('ti.fs.fatfs');\r
+\r
+/* Load the GPIO package */\r
+var GPIO = xdc.loadPackage('ti.drv.gpio');\r
+GPIO.Settings.socType = soc;\r
+\r
+/* Load the UART package */\r
+var UART = xdc.loadPackage('ti.drv.uart');\r
+UART.Settings.socType = soc;\r
+\r
+/* Load the I2C package */\r
+var I2C = xdc.loadPackage('ti.drv.i2c');\r
+I2C.Settings.socType = soc;\r
+\r
+/* Load the Board package and set the board name */\r
+var Board = xdc.loadPackage('ti.board');\r
+Board.Settings.boardName = board;\r
+\r
+/* ================ Cache and MMU configuration ================ */\r
+\r
+/* Enable cache */\r
+var Cache = xdc.useModule('ti.sysbios.hal.unicache.Cache');\r
+Cache.enableCache = true;\r
+\r
+/* Use AMMU module */\r
+var AMMU = xdc.useModule('ti.sysbios.hal.ammu.AMMU');\r
+\r
+/* Large PAGE */\r
+AMMU.largePages[0].pageEnabled = AMMU.Enable_YES;\r
+AMMU.largePages[0].logicalAddress = 0x40000000;\r
+AMMU.largePages[0].translatedAddress = 0x40000000;\r
+AMMU.largePages[0].translationEnabled = AMMU.Enable_YES;\r
+AMMU.largePages[0].size = AMMU.Large_512M;\r
+AMMU.largePages[0].L1_cacheable = AMMU.CachePolicy_NON_CACHEABLE;\r
+AMMU.largePages[0].L1_posted = AMMU.PostedPolicy_NON_POSTED;\r
+AMMU.largePages[0].L2_cacheable = AMMU.CachePolicy_NON_CACHEABLE;\r
+AMMU.largePages[0].L2_posted = AMMU.PostedPolicy_NON_POSTED;\r
+\r
+AMMU.largePages[1].pageEnabled = AMMU.Enable_YES;\r
+AMMU.largePages[1].logicalAddress = 0x80000000;\r
+AMMU.largePages[1].translatedAddress = 0x80000000;\r
+AMMU.largePages[1].translationEnabled = AMMU.Enable_YES;\r
+AMMU.largePages[1].size = AMMU.Large_512M;\r
+AMMU.largePages[1].L1_writePolicy = AMMU.WritePolicy_WRITE_BACK;\r
+AMMU.largePages[1].L1_allocate = AMMU.AllocatePolicy_ALLOCATE;\r
+AMMU.largePages[1].L1_cacheable = AMMU.CachePolicy_CACHEABLE;\r
+AMMU.largePages[1].L1_posted = AMMU.PostedPolicy_POSTED;\r
+AMMU.largePages[1].L2_cacheable = AMMU.CachePolicy_NON_CACHEABLE;\r
+AMMU.largePages[1].L2_posted = AMMU.PostedPolicy_NON_POSTED;\r
+\r
+AMMU.largePages[2].pageEnabled = AMMU.Enable_YES;\r
+AMMU.largePages[2].logicalAddress = 0xA0000000;\r
+AMMU.largePages[2].translatedAddress = 0xA0000000;\r
+AMMU.largePages[2].translationEnabled = AMMU.Enable_YES;\r
+AMMU.largePages[2].size = AMMU.Large_512M;\r
+AMMU.largePages[2].L1_cacheable = AMMU.CachePolicy_NON_CACHEABLE;\r
+AMMU.largePages[2].L1_posted = AMMU.PostedPolicy_NON_POSTED;\r
+AMMU.largePages[2].L2_cacheable = AMMU.CachePolicy_NON_CACHEABLE;\r
+AMMU.largePages[2].L2_posted = AMMU.PostedPolicy_NON_POSTED;\r
+\r
+AMMU.largePages[3].pageEnabled = AMMU.Enable_YES;\r
+AMMU.largePages[3].logicalAddress = 0x60000000;\r
+AMMU.largePages[3].translatedAddress = 0x40000000;\r
+AMMU.largePages[3].translationEnabled = AMMU.Enable_YES;\r
+AMMU.largePages[3].size = AMMU.Large_512M;\r
+AMMU.largePages[3].L1_cacheable = AMMU.CachePolicy_NON_CACHEABLE;\r
+AMMU.largePages[3].L1_posted = AMMU.PostedPolicy_NON_POSTED;\r
+AMMU.largePages[3].L2_cacheable = AMMU.CachePolicy_NON_CACHEABLE;\r
+AMMU.largePages[3].L2_posted = AMMU.PostedPolicy_NON_POSTED;\r
+\r
+/* Medium Page */\r
+AMMU.mediumPages[0].pageEnabled = AMMU.Enable_YES;\r
+AMMU.mediumPages[0].logicalAddress = 0x00300000;\r
+AMMU.mediumPages[0].translatedAddress = 0x40300000;\r
+AMMU.mediumPages[0].translationEnabled = AMMU.Enable_YES;\r
+AMMU.mediumPages[0].size = AMMU.Medium_256K;\r
+\r
+AMMU.mediumPages[1].pageEnabled = AMMU.Enable_YES;\r
+AMMU.mediumPages[1].logicalAddress = 0x00400000;\r
+AMMU.mediumPages[1].translatedAddress = 0x40400000;\r
+AMMU.mediumPages[1].translationEnabled = AMMU.Enable_YES;\r
+AMMU.mediumPages[1].size = AMMU.Medium_256K;\r
+AMMU.mediumPages[1].L1_cacheable = AMMU.CachePolicy_NON_CACHEABLE;\r
+AMMU.mediumPages[1].L1_posted = AMMU.PostedPolicy_POSTED;\r
+AMMU.mediumPages[1].L2_cacheable = AMMU.CachePolicy_NON_CACHEABLE;\r
+AMMU.mediumPages[1].L2_posted = AMMU.PostedPolicy_NON_POSTED;\r
+\r
+/* Small Page */\r
+AMMU.smallPages[0].pageEnabled = AMMU.Enable_YES;\r
+AMMU.smallPages[0].logicalAddress = 0x00000000;\r
+AMMU.smallPages[0].translatedAddress = 0x55020000;\r
+AMMU.smallPages[0].translationEnabled = AMMU.Enable_YES;\r
+AMMU.smallPages[0].size = AMMU.Small_16K;\r
+AMMU.smallPages[0].volatileQualifier = AMMU.Volatile_FOLLOW;\r
+AMMU.smallPages[0].L1_cacheable = AMMU.CachePolicy_CACHEABLE;\r
+AMMU.smallPages[0].L1_posted = AMMU.PostedPolicy_NON_POSTED;\r
+AMMU.smallPages[0].L2_cacheable = AMMU.CachePolicy_NON_CACHEABLE;\r
+AMMU.smallPages[0].L2_posted = AMMU.PostedPolicy_NON_POSTED;\r
+\r
+AMMU.smallPages[1].pageEnabled = AMMU.Enable_YES;\r
+AMMU.smallPages[1].logicalAddress = 0x40000000;\r
+AMMU.smallPages[1].translatedAddress = 0x55080000;\r
+AMMU.smallPages[1].translationEnabled = AMMU.Enable_YES;\r
+AMMU.smallPages[1].size = AMMU.Small_16K;\r
+AMMU.smallPages[1].volatileQualifier = AMMU.Volatile_FOLLOW;\r
+AMMU.smallPages[1].L1_cacheable = AMMU.CachePolicy_NON_CACHEABLE;\r
+AMMU.smallPages[1].L1_posted = AMMU.PostedPolicy_NON_POSTED;\r
+AMMU.smallPages[1].L2_cacheable = AMMU.CachePolicy_NON_CACHEABLE;\r
+AMMU.smallPages[1].L2_posted = AMMU.PostedPolicy_NON_POSTED;\r
+\r
+AMMU.smallPages[2].pageEnabled = AMMU.Enable_YES;\r
+AMMU.smallPages[2].logicalAddress = 0x00004000;\r
+AMMU.smallPages[2].translatedAddress = 0x55024000;\r
+AMMU.smallPages[2].translationEnabled = AMMU.Enable_YES;\r
+AMMU.smallPages[2].size = AMMU.Small_16K;\r
+AMMU.smallPages[2].L1_cacheable = AMMU.CachePolicy_CACHEABLE;\r
+AMMU.smallPages[2].L1_posted = AMMU.PostedPolicy_NON_POSTED;\r
+AMMU.smallPages[2].L2_cacheable = AMMU.CachePolicy_NON_CACHEABLE;\r
+AMMU.smallPages[2].L2_posted = AMMU.PostedPolicy_NON_POSTED;\r
+\r
+AMMU.smallPages[3].pageEnabled = AMMU.Enable_YES;\r
+AMMU.smallPages[3].logicalAddress = 0x00008000;\r
+AMMU.smallPages[3].translatedAddress = 0x55028000;\r
+AMMU.smallPages[3].translationEnabled = AMMU.Enable_YES;\r
+AMMU.smallPages[3].size = AMMU.Small_16K;\r
+AMMU.smallPages[3].L1_cacheable = AMMU.CachePolicy_NON_CACHEABLE;\r
+AMMU.smallPages[3].L1_posted = AMMU.PostedPolicy_NON_POSTED;\r
+AMMU.smallPages[3].L2_cacheable = AMMU.CachePolicy_NON_CACHEABLE;\r
+AMMU.smallPages[3].L2_posted = AMMU.PostedPolicy_NON_POSTED;\r
+\r
+AMMU.smallPages[4].pageEnabled = AMMU.Enable_YES;\r
+AMMU.smallPages[4].logicalAddress = 0x20000000;\r
+AMMU.smallPages[4].translatedAddress = 0x55020000;\r
+AMMU.smallPages[4].translationEnabled = AMMU.Enable_YES;\r
+AMMU.smallPages[4].size = AMMU.Small_16K;\r
+AMMU.smallPages[4].L1_cacheable = AMMU.CachePolicy_NON_CACHEABLE;\r
+AMMU.smallPages[4].L1_posted = AMMU.PostedPolicy_NON_POSTED;\r
+AMMU.smallPages[4].L2_cacheable = AMMU.CachePolicy_NON_CACHEABLE;\r
+AMMU.smallPages[4].L2_posted = AMMU.PostedPolicy_NON_POSTED;\r
+\r
+/* ================ Memory sections configuration ================ */\r
+if (soc == "dra72x" || soc == "dra75x")\r
+{\r
+    Program.linkTemplate = xdc.findFile("ti/build/dra7xx/linkcmd.xdt");\r
+    Program.sectMap["BOARD_IO_DELAY_DATA"] = "OCMC_RAM1_VIRT";\r
+    Program.sectMap["BOARD_IO_DELAY_CODE"] = "OCMC_RAM1_VIRT";\r
+}\r
diff --git a/packages/ti/fs/fatfs/example/console/makefile b/packages/ti/fs/fatfs/example/console/makefile
new file mode 100755 (executable)
index 0000000..3e3cfac
--- /dev/null
@@ -0,0 +1,87 @@
+# Makefile for FATFS unit test app
+include $(PDK_INSTALL_PATH)/ti/build/Rules.make
+export DISABLE_RECURSE_DEPS
+
+ifeq ($(SMP), enable)
+    #Name of the directory created under packages/ti/binary/
+    APP_NAME = FATFS_Console_SMP_TestApp
+    # Name of the binary if different from the default (APP_NAME)_$(BOARD_$(CORE)_<build_profile>
+    LOCAL_APP_NAME = FATFS_Console_$(BOARD)_$(CORE)_SMP_TestApp
+else
+    #Name of the directory created under packages/ti/binary/
+    APP_NAME = FATFS_Console_TestApp
+    # Name of the binary if different from the default (APP_NAME)_$(BOARD_$(CORE)_<build_profile>
+    LOCAL_APP_NAME = FATFS_Console_$(BOARD)_$(CORE)TestApp
+endif
+
+ifeq ($(SOC),$(filter $(SOC), am65xx))
+SRCDIR = ./src ../
+INCDIR = ./src
+# Common source files across all platforms and cores
+SRCS_COMMON += main_console.c FATFS_log.c fs_shell_app_utils.c
+
+ifeq ($(CORE),$(filter $(CORE), mpu1_0))
+# Enable XDC build for application by providing XDC CFG File per core
+XDC_CFG_FILE_$(CORE) = ./am65xx/a53/fatfsConsole_a53.cfg
+endif
+
+ifeq ($(CORE),$(filter $(CORE), mcu1_0))
+# Enable XDC build for application by providing XDC CFG File per core
+XDC_CFG_FILE_$(CORE) = ./am65xx/r5/fatfsConsole_r5.cfg
+endif
+
+endif
+
+ifeq ($(SOC),$(filter $(SOC), j721e))
+SRCDIR = ./src ../
+INCDIR = ./src
+# Common source files across all platforms and cores
+SRCS_COMMON += main_console.c FATFS_log.c fs_shell_app_utils.c
+
+XDC_CFG_FILE_$(CORE) = $(PDK_INSTALL_PATH)/ti/build/$(SOC)/sysbios_$(ISA).cfg
+endif
+
+# List all the external components/interfaces, whose interface header files
+# need to be included for this component
+INCLUDE_EXTERNAL_INTERFACES = bios xdc pdk
+
+# List all the components required by the application
+COMP_LIST_COMMON = csl osal_tirtos mmcsd gpio uart board fatfs_indp
+
+ifeq ($(SOC),$(filter $(SOC), am65xx j721e))
+COMP_LIST_COMMON += sciclient i2c
+endif
+
+CFLAGS_FATFS_UT =
+
+
+# EVM build
+ifeq ($(BOARD),$(filter $(BOARD), am65xx-evm))
+CFLAGS_FATFS_UT += -Dam65xx_evm
+endif
+
+# am65xx build
+ifeq ($(BOARD),$(filter $(BOARD), am65xx-sim))
+CFLAGS_FATFS_UT    += -Dam65xx_sim
+endif
+
+PACKAGE_SRCS_COMMON = ../
+CFLAGS_LOCAL_COMMON = $(PDK_CFLAGS) $(CFLAGS_FATFS_UT)
+
+# Core/SoC/platform specific source files and CFLAGS
+# Example:
+#   SRCS_<core/SoC/platform-name> =
+#   CFLAGS_LOCAL_<core/SoC/platform-name> =
+
+# Include common make files
+ifeq ($(MAKERULEDIR), )
+#Makerule path not defined, define this and assume relative path from ROOTDIR
+  MAKERULEDIR := $(ROOTDIR)/ti/build/makerules
+  export MAKERULEDIR
+endif
+include $(MAKERULEDIR)/common.mk
+
+# OBJs and libraries are built by using rule defined in rules_<target>.mk
+#     and need not be explicitly specified here
+
+# Nothing beyond this point
diff --git a/packages/ti/fs/fatfs/example/console/src/FATFS_log.c b/packages/ti/fs/fatfs/example/console/src/FATFS_log.c
new file mode 100644 (file)
index 0000000..b1d4f60
--- /dev/null
@@ -0,0 +1,115 @@
+/**
+ *  \file   I2C_log.c
+ *
+ *  \brief  This file contains the uart console print specific functions and
+ *          macros.
+ *
+ */
+
+/*
+ * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of Texas Instruments Incorporated nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+
+/* XDCtools Header files */
+#include <xdc/std.h>
+#include <xdc/runtime/System.h>
+#include <stdio.h>
+
+/* BIOS Header files */
+#include <ti/sysbios/BIOS.h>
+#include <ti/sysbios/family/arm/a15/Cache.h>
+#include <ti/csl/hw_types.h>
+/* TI-RTOS Header files */
+#include <ti/drv/uart/UART.h>
+#include <ti/drv/uart/UART_stdio.h>
+#if !defined(SOC_AM65XX) && !defined(SOC_J721E)
+#include <ti/csl/soc/am572x/src/cslr_control_core_pad_io.h>
+#endif
+
+/**********************************************************************
+ ************************** Macros ************************************
+ **********************************************************************/
+#define SOC_CORE_PAD_IO_REGISTERS_BASE                     (0x4a003400U)
+
+
+/**********************************************************************
+ ************************** Internal functions ************************
+ **********************************************************************/
+/* board init function */
+void Board_initUART(void);
+
+/**********************************************************************
+ ************************** Global Variables **************************
+ **********************************************************************/
+
+
+/*
+ *  ======== ConsoleUtilsInit ========
+ */
+void ConsoleUtilsInit(void)
+{
+    /* Call board init functions */
+    Board_initUART();
+
+    UART_stdioInit(0);
+}
+
+/*
+ *  ======== Board_initUART ========
+ */
+void Board_initUART(void) {
+#if !defined(SOC_AM65XX) && !defined(SOC_J721E)
+          HW_WR_REG32((SOC_CORE_PAD_IO_REGISTERS_BASE + CSL_CONTROL_CORE_PAD_IO_PAD_UART1_RXD),
+            (CSL_CONTROL_CORE_PAD_IO_PAD_UART1_RXD_UART1_RXD_INPUTENABLE_MASK |
+                    CSL_CONTROL_CORE_PAD_IO_PAD_UART1_RXD_UART1_RXD_SLEWCONTROL_MASK |
+                    CSL_CONTROL_CORE_PAD_IO_PAD_UART1_RXD_UART1_RXD_PULLTYPESELECT_MASK));
+
+        /* TXD */
+        HW_WR_REG32((SOC_CORE_PAD_IO_REGISTERS_BASE + CSL_CONTROL_CORE_PAD_IO_PAD_UART1_TXD),
+            (CSL_CONTROL_CORE_PAD_IO_PAD_UART1_TXD_UART1_TXD_INPUTENABLE_MASK |
+                    CSL_CONTROL_CORE_PAD_IO_PAD_UART1_TXD_UART1_TXD_SLEWCONTROL_MASK |
+                    CSL_CONTROL_CORE_PAD_IO_PAD_UART1_TXD_UART1_TXD_PULLTYPESELECT_MASK));
+
+        /* RTSN */
+        HW_WR_REG32((SOC_CORE_PAD_IO_REGISTERS_BASE + CSL_CONTROL_CORE_PAD_IO_PAD_UART1_RTSN),
+            (CSL_CONTROL_CORE_PAD_IO_PAD_UART1_RTSN_UART1_RTSN_INPUTENABLE_MASK |
+                    CSL_CONTROL_CORE_PAD_IO_PAD_UART1_RTSN_UART1_RTSN_PULLTYPESELECT_MASK));
+
+        /* CTSN */
+        HW_WR_REG32((SOC_CORE_PAD_IO_REGISTERS_BASE + CSL_CONTROL_CORE_PAD_IO_PAD_UART1_CTSN),
+            (CSL_CONTROL_CORE_PAD_IO_PAD_UART1_CTSN_UART1_CTSN_INPUTENABLE_MASK |
+                    CSL_CONTROL_CORE_PAD_IO_PAD_UART1_CTSN_UART1_CTSN_PULLTYPESELECT_MASK));
+#endif
+}
+
+
diff --git a/packages/ti/fs/fatfs/example/console/src/FATFS_log.h b/packages/ti/fs/fatfs/example/console/src/FATFS_log.h
new file mode 100644 (file)
index 0000000..ea3614d
--- /dev/null
@@ -0,0 +1,80 @@
+/**
+ *  \file   FATFS_log.h
+ *
+ *  \brief  This file contains the prototypes for the log print functions. By
+            default the prints will be directed to serial console using UART.
+ *
+ */
+
+/*
+ * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of Texas Instruments Incorporated nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef _FATFS_LOG_H
+#define _FATFS_LOG_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdio.h>
+
+/* UART Header files */
+#include <ti/drv/uart/UART.h>
+#include <ti/drv/uart/UART_stdio.h>
+#if !defined(SOC_AM65XX) && !defined(SOC_J721E)
+#include <ti/csl/soc/am572x/src/cslr_control_core_pad_io.h>
+#endif
+
+/**********************************************************************
+ ************************** Global Variables **************************
+ **********************************************************************/
+extern void UART_printf(const char *pcString, ...);
+extern void ConsoleUtilsInit(void);
+
+/**********************************************************************
+ ************************** Macros ************************************
+ **********************************************************************/
+/* Enable the below macro to have prints on the IO Console */
+//#define IO_CONSOLE
+
+#ifndef IO_CONSOLE
+#define FATFS_log                UART_printf
+#else
+#define FATFS_log                printf
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _FATFS_LOG_H */
diff --git a/packages/ti/fs/fatfs/example/console/src/fs_shell_app_utils.c b/packages/ti/fs/fatfs/example/console/src/fs_shell_app_utils.c
new file mode 100644 (file)
index 0000000..0004f3f
--- /dev/null
@@ -0,0 +1,1121 @@
+/**
+ *  \file  fs_shell_app_utils.c
+ *
+ *  \brief This file implements file system shell interface.
+ *
+ *  \copyright Copyright (C) 2013-2018 Texas Instruments Incorporated -
+ *             http://www.ti.com/
+ */
+
+/*
+
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *
+ *    Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the
+ *    distribution.
+ *
+ *    Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/* ========================================================================== */
+/*                             Include Files                                  */
+/* ========================================================================== */
+
+#include <ti/csl/tistdtypes.h>
+#include "string.h"
+#include "stdio.h"
+#include <ti/csl/csl_error.h>
+#include <ti/fs/fatfs/ff.h>
+#include "FATFS_log.h"
+#include "fs_shell_app_utils.h"
+
+/* ========================================================================== */
+/*                           Macros & Typedefs                                */
+/* ========================================================================== */
+
+/*****************************************************************************
+Defines the size of the buffers that hold the path, or temporary data from
+the memory card.  There are two buffers allocated of this size.  The buffer
+size must be large enough to hold the longest expected full path name,
+including the file name, and a trailing null character.
+******************************************************************************/
+#define FS_SHELL_APP_UTILS_PATH_BUF_SIZE   512
+
+/* Defines size of the buffers that hold temporary data. */
+#define FS_SHELL_APP_UTILS_DATA_BUF_SIZE   512
+/*****************************************************************************
+Defines the size of the buffer that holds the command line.
+******************************************************************************/
+#define FS_SHELL_APP_UTILS_CMD_CMD_BUF_SIZE    512
+
+/*****************************************************************************
+Defines the help message for cat.
+******************************************************************************/
+#define FS_SHELL_APP_UTILS_CMD_INFO_CAT                                            \
+        "  : Show contents of a text file : cat <FILENAME> \n"                 \
+                  "       Write to a file : cat <INPUTFILE> > <OUTPUTFILE> \n" \
+                   "       Read from UART : cat dev.UART \n"                   \
+                  "       Write from UART : cat dev.UART > <OUTPUTFILE>"
+#define FS_SHELL_APP_UTILS_CMD_INFO_HELP  " : Display list of commands"
+#define FS_SHELL_APP_UTILS_CMD_INFO_LS  "   : Display list of files"
+#define FS_SHELL_APP_UTILS_CMD_INFO_CD     ": Change directory"
+#define FS_SHELL_APP_UTILS_CMD_INFO_MKDIR  ": Create directory"
+#define FS_SHELL_APP_UTILS_CMD_INFO_PWD  "  : Show current working directory"
+#define FS_SHELL_APP_UTILS_CMD_INFO_RM  "   : Delete a file or an empty directory"
+#ifdef MULTI_PARTITION
+#define FS_SHELL_APP_UTILS_CMD_INFO_EXIT    ": Exit the shell/console"
+#endif
+
+/* ========================================================================== */
+/*                         Structures and Enums                               */
+/* ========================================================================== */
+
+
+/* ========================================================================== */
+/*                 Internal Function Declarations                             */
+/* ========================================================================== */
+
+/**
+ *  \brief  Process a command line string into arguments and execute the command.
+ *          This function will take the supplied command line string and break it
+ *          up into individual arguments.  The first argument is treated as a
+ *          command and is searched for in the command table. If the command is
+ *          found, then the command function is called and all of the command line
+ *          arguments are passed in the normal argc, argv form.
+ *
+ *  \param  pCmdLine points to a string that contains a command line that was
+ *                  obtained by an application by some means.
+ *
+ *  \param  pCmdList points to a list of command entries used to process command
+ *                  line that was obtained by an application by some means.
+ *
+ *  \return Returns the status of execution of command line.
+ *          Following are possible values.
+ *          - CMDLINE_BAD_CMD if the command is not found,
+ *          - CMDLINE_TOO_MANY_ARGS if there are more arguments than can be parsed.
+ *          Otherwise it returns the code that was returned by the command function.
+ *
+ */
+int32_t FSShellAppUtilsCmdExecute(uint8_t *pCmdLine,
+                                         fsShellAppUtilsCmdEntry_t *pCmdList);
+
+/**
+ *  \brief   This function implements the "ls" command.
+ *
+ *  \param   argc   Number of arguments.
+ *  \param   argv   Arguments required to execute "ls" command.
+ *                  - First argument shall be "ls".
+ *                  - Ignore other arguments.
+ *
+ *  \return  CSL_SOK on success else error code.
+ *
+ **/
+int32_t FSShellAppUtilsCmdLs(int32_t argc, char *argv[]);
+
+/**
+ *  \brief   This function implements the "cd"/"chdir" command.
+ *
+ *  \param   argc   Number of arguments.
+ *  \param   argv   Arguments required to execute "cd"/"chdir" command.
+ *                  - First argument shall be "cd"/"chdir".
+ *                  - Second argument specifies the directory to be changed as
+ *                    current working directory.
+ *                    It shall be in one of the following format
+ *                      - file or directory name that is in current directory
+ *                        ("mydir").
+ *                      - file or directory name that is in current drive
+ *                        ("/my/path/to/my-dir").
+ *                      - fully specified path of file or directory with drive
+ *                        number/name ("drive:/my/path/to/my-dir").
+ *                  - Ignore other arguments.
+ *
+ *  \return  CSL_SOK on success else error code.
+ *
+ **/
+int32_t FSShellAppUtilsCmdCd(int32_t argc, char *argv[]);
+
+/**
+ *  \brief   This function implements the "pwd" command. It prints the current
+ *           working directory.
+ *
+ *  \param   argc   Number of arguments.
+ *  \param   argv   Arguments required to execute "pwd" command.
+ *                  - First argument shall be "pwd".
+ *                  - Ignore other arguments.
+ *
+ *  \return  CSL_SOK on success else error code.
+ *
+ **/
+int32_t FSShellAppUtilsCmdPwd(int32_t argc, char *argv[]);
+
+/**
+ *  \brief   This function implements the "mkdir" command.
+ *
+ *  \param   argc   Number of arguments.
+ *  \param   argv   Arguments required to execute "mkdir" command.
+ *                  - First argument shall be "mkdir".
+ *                  - Second argument specifies the new directory to be created.
+ *                    It shall be in one of the following format
+ *                      - file or directory name that is in current directory
+ *                        ("mydir").
+ *                      - file or directory name that is in current drive
+ *                        ("/my/path/to/my-dir").
+ *                      - fully specified path of file or directory with drive
+ *                        number/name ("drive:/my/path/to/my-dir").
+ *                  - Ignore other arguments.
+ *
+ *  \return  CSL_SOK on success else error code.
+ *
+ **/
+int32_t FSShellAppUtilsCmdMkDir(int32_t argc, char *argv[]);
+
+/**
+ *  \brief   This function implements the "rm" command.
+ *
+ *  \param   argc   Number of arguments.
+ *  \param   argv   Arguments required to execute "rm" command.
+ *                  - First argument shall be "rm".
+ *                  - Second argument specifies the file or working directory to
+ *                    be deleted. It shall be in one of the following format
+ *                      - file or directory name that is in current directory
+ *                        ("my-dir-file").
+ *                      - file or directory name that is in current drive
+ *                        ("/my/path/to/my-dir-file").
+ *                      - fully specified path of file or directory with drive
+ *                        number/name ("drive:/my/path/to/my-dir-file").
+ *                  - Ignore other arguments.
+ *
+ *  \return  CSL_SOK on success else error code.
+ *
+ **/
+int32_t FSShellAppUtilsCmdRm(int32_t argc, char *argv[]);
+
+/**
+ *  \brief   This function implements the "cat" command.
+ *
+ *  \param   argc   Number of arguments.
+ *  \param   argv   Arguments required to execute "cat" command.
+ *                  - First argument shall be "cat".
+ *                  - Second argument specifies the source of data or file to be
+ *                    read from.
+ *                    It shall be in one of the following format
+ *                      - file name that is in current directory ("myfile").
+ *                      - file that is in current drive ("/my/path/to/my-file").
+ *                      - fully specified path of file with drive number/name
+ *                        ("drive:/my/path/to/my-file").
+ *                      - "dev.UART" to read input from UART through xmodem
+ *                        protocol.
+ *                  - Third argument shall be ">" to perform write operation else
+ *                    read operation is performed.
+ *                  - Fouth argument specifies the file to which the data read
+ *                    shall be written.
+ *                    It shall be in one of the following format
+ *                      - file name that is in current directory ("myfile").
+ *                      - file that is in current drive ("/my/path/to/my-file").
+ *                      - fully specified path of file with drive number/name
+ *                        ("drive:/my/path/to/my-file").
+ *                  - Ignore other arguments.
+ *
+ *  \return  CSL_SOK on success else error code.
+ *
+ **/
+int32_t FSShellAppUtilsCmdCat(int32_t argc, char *argv[]);
+
+/**
+ *  \brief   This function provides help information on supported commands.
+ *
+ *  \param   argc   Number of arguments.
+ *  \param   argv   Arguments required provide help info on supported commands.
+ *                  - First argument shall be "help"/"h"/"?".
+ *                  - Ignore other arguments.
+ *
+ *  \return  CSL_SOK on success else error code.
+ *
+ **/
+int32_t FSShellAppUtilsCmdHelp(int32_t argc, char *argv[]);
+
+#ifdef MULTI_PARTITION
+/**
+ *  \brief   This function exits from the console and return to main menu.
+ *
+ *  \param   argc   Number of arguments.
+ *  \param   argv   Arguments required to execute "exit" command.
+ *                  - First argument shall be "exit".
+ *                  - Ignore other arguments.
+ *
+ *  \return  CSL_SOK on success else error code.
+ *
+ **/
+int32_t FSShellAppUtilsCmdExit(int32_t argc, char *argv[]);
+#endif
+
+/* ========================================================================== */
+/*                            Global Variables Declarations                   */
+/* ========================================================================== */
+#ifdef MULTI_PARTITION
+uint32_t gFsExitStatus = 0;
+#endif
+
+static DIR gFsShellAppUtilsDirObj;
+
+static FILINFO gFsShellAppUtilsFileInfo;
+
+volatile uint32_t gFsShellAppUtilsCurState = FS_SHELL_APP_UTILS_STATE_MAX;
+
+/*****************************************************************************
+A temporary data buffer used when manipulating file paths, or reading data
+from the memory card.
+******************************************************************************/
+static FIL gFsShellAppUtilsReadFileObj  __attribute__ ((aligned (SOC_CACHELINE_SIZE)));
+
+/*****************************************************************************
+A temporary data buffer used when manipulating file paths, or reading data
+from the memory card.
+******************************************************************************/
+static FIL gFsShellAppUtilsWriteFileObj  __attribute__ ((aligned (SOC_CACHELINE_SIZE)));
+
+/*****************************************************************************
+A temporary data buffer used when manipulating file paths, or reading data
+from the memory card.
+******************************************************************************/
+static char gFsShellAppUtilsTempPath[FS_SHELL_APP_UTILS_PATH_BUF_SIZE]
+                      __attribute__ ((aligned (SOC_CACHELINE_SIZE)));
+
+/*****************************************************************************
+A temporary data buffer used for reading data from or writing data
+to the memory card.
+******************************************************************************/
+static char gFsShellAppUtilsCwd[FS_SHELL_APP_UTILS_DATA_BUF_SIZE]
+                             __attribute__ ((aligned (SOC_CACHELINE_SIZE)));
+
+/*****************************************************************************
+A temporary data buffer used for reading data from or writing data
+to the memory card.
+******************************************************************************/
+static char gFsShellAppUtilsDataBuf[FS_SHELL_APP_UTILS_DATA_BUF_SIZE]
+                             __attribute__ ((aligned (SOC_CACHELINE_SIZE)));
+
+/*******************************************************************************
+**
+** This is the table that holds the command names, implementing functions, and
+** brief description.
+**
+*******************************************************************************/
+fsShellAppUtilsCmdEntry_t gFsShellAppUtilsCmdTable[] =
+{
+    { "help",     &FSShellAppUtilsCmdHelp,  FS_SHELL_APP_UTILS_CMD_INFO_HELP},
+    { "ls",       &FSShellAppUtilsCmdLs,    FS_SHELL_APP_UTILS_CMD_INFO_LS},
+    { "cd",       &FSShellAppUtilsCmdCd,    FS_SHELL_APP_UTILS_CMD_INFO_CD},
+    { "mkdir",    &FSShellAppUtilsCmdMkDir, FS_SHELL_APP_UTILS_CMD_INFO_MKDIR},
+    { "rm",       &FSShellAppUtilsCmdRm,    FS_SHELL_APP_UTILS_CMD_INFO_RM},
+    { "pwd",      &FSShellAppUtilsCmdPwd,   FS_SHELL_APP_UTILS_CMD_INFO_PWD},
+    { "cat",      &FSShellAppUtilsCmdCat,   FS_SHELL_APP_UTILS_CMD_INFO_CAT},
+#ifdef MULTI_PARTITION
+    { "exit",     &FSShellAppUtilsCmdExit,  FS_SHELL_APP_UTILS_CMD_INFO_EXIT},
+#endif
+    { 0, 0, 0 }
+};
+
+uint8_t gFsShellAppUtilsRxBuf[80U];
+
+/* ========================================================================== */
+/*                          Function Declarations                             */
+/* ========================================================================== */
+
+int32_t FSShellAppUtilsInit(void)
+{
+
+    return(FS_SHELL_APP_UTILS_CMD_STATUS_INVALID);
+}
+
+/* For checking if the media is still inserted */
+volatile uint8_t fs_is_media_inserted=1;
+
+#ifdef MULTI_PARTITION
+int32_t FSShellAppUtilsProcess(char *path)
+#else
+int32_t FSShellAppUtilsProcess(void)
+#endif
+{
+    uint32_t spinProcess = TRUE;
+    int32_t retStat = CSL_ESYS_FAIL;
+    uint8_t inputChar = 0U;
+    uint8_t inputCharIdx = 0U;
+
+    do
+    {
+        switch(gFsShellAppUtilsCurState)
+        {
+            case FS_SHELL_APP_UTILS_STATE_HELP:
+            {
+                /* On completion jump to next state. */
+                if(FR_OK == f_opendir(&gFsShellAppUtilsDirObj, gFsShellAppUtilsCwd))
+                {
+                    FATFS_log("TEST PASS.\n");
+                    FATFS_log("%s>", gFsShellAppUtilsCwd);
+                    gFsShellAppUtilsCurState = FS_SHELL_APP_UTILS_STATE_READ_COMMAND;
+                    spinProcess = TRUE;
+                    retStat = CSL_SOK;
+                }
+                /* Exit on error. */
+                else
+                {
+                    FATFS_log("%s>", "UNKNOWN");
+                    gFsShellAppUtilsCurState = FS_SHELL_APP_UTILS_STATE_MAX;
+                    spinProcess = TRUE;
+                    retStat = CSL_ESYS_FAIL;
+                }
+                break;
+            }
+
+            case FS_SHELL_APP_UTILS_STATE_READ_COMMAND:
+            {
+                if(FR_OK == f_opendir(&gFsShellAppUtilsDirObj, gFsShellAppUtilsCwd))
+                {
+                    //scanf("%s", gFsShellAppUtilsRxBuf);
+                    //UART_gets(gFsShellAppUtilsRxBuf, 80U);
+                    //gets(gFsShellAppUtilsRxBuf);
+                    //fflush(stdin);
+                   inputCharIdx = 0U;
+
+                    do
+                    {
+                        /*
+                        ** Read the next character from the UART.
+                        */
+                        inputChar = UART_getc();
+
+                        /*
+                        ** See if this character is a backspace and there is at least one
+                        ** character in the input line.
+                        */
+                        if((inputChar == '\b') && (inputCharIdx != 0))
+                        {
+                            /*
+                            ** Erase the last character from the input line.
+                            */
+                            UART_printf("\b \b");
+                            inputCharIdx--;
+                            gFsShellAppUtilsRxBuf[inputCharIdx] = '\0';
+                        }
+
+                        /*
+                        ** See if this character is a newline.
+                        */
+                        else if((inputChar == '\r') || (inputChar == '\n'))
+                        {
+                            /*
+                            ** Return to the caller.
+                            */
+                            UART_printf("\n");
+                            break;
+                        }
+
+                        /*
+                        ** See if this is a printable ASCII character.
+                        */
+                        else if((inputChar >= ' ') && (inputChar <= '~') &&
+                                (inputCharIdx < (sizeof(gFsShellAppUtilsRxBuf) - 1)))
+                        {
+                            /*
+                            ** Add this character to the input buffer.
+                            */
+                            gFsShellAppUtilsRxBuf[inputCharIdx++] = inputChar;
+                            gFsShellAppUtilsRxBuf[inputCharIdx] = '\0';
+                            UART_printf("%c", inputChar);
+                        }
+                    } while (1);
+
+                    gFsShellAppUtilsCurState = FS_SHELL_APP_UTILS_STATE_EXECUTE_COMMAND;
+                    spinProcess = TRUE;
+                    retStat = CSL_SOK;
+                }
+                /* Exit on error. */
+                else
+                {
+                    FATFS_log("%s>", "UNKNOWN");
+                    gFsShellAppUtilsCurState = FS_SHELL_APP_UTILS_STATE_MAX;
+                    spinProcess = TRUE;
+                    retStat = CSL_ESYS_FAIL;
+                }
+                break;
+            }
+
+            case FS_SHELL_APP_UTILS_STATE_EXECUTE_COMMAND:
+            {
+                /* On completion jump to next state. */
+                if(FR_OK == f_opendir(&gFsShellAppUtilsDirObj, gFsShellAppUtilsCwd))
+                {
+                    FSShellAppUtilsCmdExecute(gFsShellAppUtilsRxBuf, gFsShellAppUtilsCmdTable);
+                    gFsShellAppUtilsCurState = FS_SHELL_APP_UTILS_STATE_HELP;
+#ifdef MULTI_PARTITION
+                    if(gFsExitStatus)
+                    {
+                        gFsShellAppUtilsCurState = FS_SHELL_APP_UTILS_STATE_MAX;
+                        spinProcess = FALSE;
+                        gFsExitStatus = 0;
+                    }
+#else
+                    spinProcess = TRUE;
+#endif
+                    retStat = CSL_SOK;
+                }
+                /* Exit on error. */
+                else
+                {
+                    FATFS_log("%s>", "UNKNOWN");
+                    gFsShellAppUtilsCurState = FS_SHELL_APP_UTILS_STATE_MAX;
+                    spinProcess = TRUE;
+                    retStat = CSL_ESYS_FAIL;
+                }
+                break;
+            }
+
+            case FS_SHELL_APP_UTILS_STATE_MAX:
+            default:
+            {
+#ifdef MULTI_PARTITION
+                strcpy(gFsShellAppUtilsCwd, path);
+#else
+                strcpy(gFsShellAppUtilsCwd, "0:");
+#endif
+
+                if(FR_OK == f_opendir(&gFsShellAppUtilsDirObj, gFsShellAppUtilsCwd))
+                {
+                    gFsShellAppUtilsCurState = FS_SHELL_APP_UTILS_STATE_HELP;
+                    spinProcess = TRUE;
+                    retStat = CSL_SOK;
+                }
+                else
+                {
+                    spinProcess = TRUE;
+                    gFsShellAppUtilsCurState = FS_SHELL_APP_UTILS_STATE_MAX;
+                    retStat = CSL_ESYS_FAIL;
+                    break;
+                }
+            }
+        }
+
+    } while( (TRUE == spinProcess) && (fs_is_media_inserted == 1) );
+
+    return retStat;
+}
+
+/* -------------------------------------------------------------------------- */
+/*                 Internal Function Definitions                              */
+/* -------------------------------------------------------------------------- */
+
+int32_t FSShellAppUtilsCmdExecute(uint8_t *pCmdLine,
+                                         fsShellAppUtilsCmdEntry_t *pCmdList)
+{
+    int32_t retStatus = CSL_ESYS_FAIL;
+    static uint8_t *argv[FSSHELLAPPUTILS_CMDLINE_MAX_ARGS + 1U];
+    uint8_t *pChar;
+    int32_t argc;
+    uint32_t findArg = TRUE;
+
+    /*
+        * Initialize the argument counter, and point to the beginning of the
+     * command line string.
+        */
+    argc = 0U;
+    pChar = pCmdLine;
+
+    /* Advance through the command line until a zero character is found. */
+    while(*pChar)
+    {
+        /*
+                * If there is a space, then replace it with a zero, and set the flag
+         * to search for the next argument.
+                */
+        if(*pChar == ' ')
+        {
+            *pChar = 0;
+            findArg = TRUE;
+        }
+
+        /*
+         * Otherwise it is not a space, so it must be a character that is part
+         * of an argument.
+                */
+        else
+        {
+            /*
+                        * If findArg is set, then that means we are looking for the start
+             * of the next argument.
+                        */
+            if(TRUE == findArg)
+            {
+                /*
+                                * As long as the maximum number of arguments has not been
+                 * reached, then save the pointer to the start of this new arg
+                 * in the argv array, and increment the count of args, argc.
+                                */
+                if(argc < FSSHELLAPPUTILS_CMDLINE_MAX_ARGS)
+                {
+                    argv[argc] = pChar;
+                    argc++;
+                    findArg = FALSE;
+                    retStatus = CSL_SOK;
+                }
+
+                /*
+                                * The maximum number of arguments has been reached so return
+                 * the error.
+                                */
+                else
+                {
+                    FATFS_log("Too many arguments for command processor!\n");
+                    retStatus = CSL_ESYS_FAIL;
+                    break;
+                }
+            }
+        }
+
+        /* Advance to the next character in the command line. */
+        pChar++;
+    }
+
+    /* If one or more arguments was found, then process the command. */
+    if((CSL_SOK == retStatus) && (0U != argc))
+    {
+        /*
+                * Search through the command table until a null command string is
+         * found, which marks the end of the table.
+                */
+        while(pCmdList->pCmd)
+        {
+            /*
+                        * If this command entry command string matches argv[0], then call
+             * the function for this command, passing the command line
+             * arguments.
+                        */
+            if(!strcmp((const char *)argv[0], (const char *)pCmdList->pCmd))
+            {
+                retStatus = pCmdList->pfnCmd(argc, (char **)argv);
+            }
+
+            /* Not found, so advance to the next entry. */
+            pCmdList++;
+        }
+    }
+
+    /*
+        * Fall through to here means that no matching command was found, so return
+     * an error.
+        */
+    return retStatus;
+}
+
+static int32_t FSShellAppUtilsFrmtPath(char* inputPath, char* outputPath)
+{
+    int32_t retStat = CSL_ESYS_FAIL;
+    uint32_t drvLen = 0U; /* relative path */
+
+    /* Append the input path. */
+    strcpy(outputPath, "");
+
+    /* Look for drive separator. */
+    drvLen = strcspn(inputPath, ":");
+
+    /*
+     * If path contains driver name.
+     */
+    if (drvLen < strlen(inputPath))
+    {
+        /* Append the input path. */
+        strcpy(outputPath, inputPath);
+
+        retStat = CSL_SOK;
+    }
+    /*
+     * If the first character is /, then this is a fully specified path, and it
+     * should just be used as-is.
+     */
+    else
+    {
+        /* Look for drive separator. */
+        drvLen = strcspn(gFsShellAppUtilsCwd, ":");
+
+        /*
+         * If path contains driver name.
+         */
+        if (drvLen < strlen(gFsShellAppUtilsCwd))
+        {
+            if('/' == *inputPath)
+            {
+                /*
+                 * Make sure the new path with drive number [X:] is not bigger than the
+                 * cwd buffer. It need to include a drive number, separator and a
+                 * trailing null character.
+                 */
+                if((strlen(inputPath) + drvLen + 1U + 1U) <= sizeof(gFsShellAppUtilsCwd))
+                {
+                    if(0U != strlen(gFsShellAppUtilsCwd))
+                    {
+                        /* Copy the current drive into the output buffer. */
+                        strncpy(outputPath, gFsShellAppUtilsCwd, drvLen + 1U);
+
+                        outputPath[drvLen + 1U] = '\0';
+
+                        if(strlen(inputPath) > 1U)
+                        {
+                            /* Append the input path. */
+                            strcat(outputPath, inputPath);
+                        }
+
+                        retStat = CSL_SOK;
+                    }
+                }
+                else
+                {
+                    retStat = CSL_ESYS_FAIL;
+                }
+            }
+            else
+            {
+                /*
+                 * Test to make sure that when the new additional path is added on to
+                 * the current path, there is room in the buffer for the full new path.
+                 * It needs to include a new separator, and a trailing null character.
+                 */
+                if((strlen(gFsShellAppUtilsCwd) + strlen(inputPath) + 1U + 1U) <= sizeof(gFsShellAppUtilsCwd))
+                {
+                    /*
+                     * Append the current working directory to relative path.
+                     */
+                    strcat(outputPath, gFsShellAppUtilsCwd);
+                    strcat(outputPath, "/");
+                    strcat(outputPath, inputPath);
+
+                    retStat = CSL_SOK;
+                }
+                else
+                {
+                    retStat = CSL_ESYS_FAIL;
+                }
+            }
+        }
+        else
+        {
+            retStat = FALSE;
+        }
+    }
+
+    return retStat;
+}
+
+int32_t FSShellAppUtilsCmdLs(int32_t argc, char *argv[])
+{
+    uint32_t totalSize = 0U;
+    uint32_t fileCount = 0U;
+    uint32_t dirCount = 0U;
+    FRESULT fresult;
+    FATFS *pFatFs;
+
+    /* Open the current directory for access. */
+    fresult = f_opendir(&gFsShellAppUtilsDirObj, gFsShellAppUtilsCwd);
+
+    /* Enter loop to enumerate through all directory entries. */
+    while(FR_OK == fresult)
+    {
+        /* Read an entry from the directory. */
+        fresult = f_readdir(&gFsShellAppUtilsDirObj, &gFsShellAppUtilsFileInfo);
+
+        /* Check for error and return if there is a problem. */
+        if(FR_OK == fresult)
+        {
+            /* If the file name is blank, then this is the end of the listing. */
+            if('\0' == gFsShellAppUtilsFileInfo.fname[0])
+            {
+                break;
+            }
+
+            /* If the attribute is directory, then increment the directory count. */
+            if(AM_DIR == (gFsShellAppUtilsFileInfo.fattrib & AM_DIR))
+            {
+                dirCount++;
+            }
+
+            /*
+             * Otherwise, it is a file.  Increment the file count, and add in the
+             * file size to the total.
+             */
+            else
+            {
+                fileCount++;
+                totalSize += gFsShellAppUtilsFileInfo.fsize;
+            }
+
+            /*
+             * Print the entry information on a single line with formatting to show
+             * the attributes, date, time, size, and name.
+             */
+            FATFS_log("%c%c%c%c%c %u/%02u/%02u %02u:%02u %9u  %s\n",
+                               (gFsShellAppUtilsFileInfo.fattrib & AM_DIR) ? 'D' : '-',
+                               (gFsShellAppUtilsFileInfo.fattrib & AM_RDO) ? 'R' : '-',
+                               (gFsShellAppUtilsFileInfo.fattrib & AM_HID) ? 'H' : '-',
+                               (gFsShellAppUtilsFileInfo.fattrib & AM_SYS) ? 'S' : '-',
+                               (gFsShellAppUtilsFileInfo.fattrib & AM_ARC) ? 'A' : '-',
+                               (gFsShellAppUtilsFileInfo.fdate >> 9) + 1980,
+                               (gFsShellAppUtilsFileInfo.fdate >> 5) & 15,
+                                gFsShellAppUtilsFileInfo.fdate & 31,
+                               (gFsShellAppUtilsFileInfo.ftime >> 11),
+                               (gFsShellAppUtilsFileInfo.ftime >> 5) & 63,
+                                gFsShellAppUtilsFileInfo.fsize,
+                                gFsShellAppUtilsFileInfo.fname);
+        }
+    }
+
+    /* Check for error and return if there is a problem. */
+    if(FR_OK == fresult)
+    {
+        /* Print summary lines showing the file, dir, and size totals. */
+        FATFS_log("\n%4u File(s),%10u bytes total\n%4u Dir(s)",
+                           fileCount, totalSize, dirCount);
+
+        /* Get the free space. */
+        fresult = f_getfree("/", (DWORD *)&totalSize, &pFatFs);
+
+        /* Check for error and return if there is a problem. */
+        if(FR_OK == fresult)
+        {
+            /* Display the amount of free space that was calculated. */
+            FATFS_log(", %10uK bytes free\n", totalSize * pFatFs->csize / 2);
+        }
+    }
+
+    /* Return status. */
+    return fresult;
+}
+
+int32_t FSShellAppUtilsCmdRm(int32_t argc, char *argv[])
+{
+    int32_t retStat = CSL_ESYS_FAIL;
+    FRESULT fresult;
+
+    /*
+     * Format the path of file/folder to be removed with drive and absolute path.
+     */
+    retStat = FSShellAppUtilsFrmtPath(argv[1U], gFsShellAppUtilsTempPath);
+
+    if (CSL_SOK == retStat)
+    {
+        /* Remove file or directory path is in gFsShellAppUtilsTempPath. */
+        fresult = f_unlink(gFsShellAppUtilsTempPath);
+
+        /* Check status. Inform user and return. */
+        if(fresult != FR_OK)
+        {
+            retStat = CSL_ESYS_FAIL;
+        }
+    }
+
+    /* Return status. */
+    return retStat;
+}
+
+int32_t FSShellAppUtilsCmdMkDir(int32_t argc, char *argv[])
+{
+    int32_t retStat = CSL_ESYS_FAIL;
+    FRESULT fresult;
+
+    /*
+     * Format the path of folder to be created with drive and absolute path.
+     */
+    retStat = FSShellAppUtilsFrmtPath(argv[1U], gFsShellAppUtilsTempPath);
+
+    if (CSL_SOK == retStat)
+    {
+        /* Create new directory at the path in chTmpBuf. */
+        fresult = f_mkdir(gFsShellAppUtilsTempPath);
+
+        /* Check for the status of create directory.  Inform user and return. */
+        if(FR_OK != fresult)
+        {
+            FATFS_log("mkdir: %s\n", gFsShellAppUtilsTempPath);
+            retStat = CSL_ESYS_FAIL;
+        }
+    }
+
+    /* Return status. */
+    return retStat;
+}
+
+int32_t FSShellAppUtilsCmdCd(int32_t argc, char *argv[])
+{
+    int32_t retStat = CSL_ESYS_FAIL;
+    FRESULT fresult;
+
+    /*
+     * Format the path of folder to be created with drive and absolute path.
+     */
+    retStat = FSShellAppUtilsFrmtPath(argv[1U], gFsShellAppUtilsTempPath);
+
+    if (CSL_SOK == retStat)
+    {
+        /*
+         * At this point, a candidate new directory path is in chTmpBuf.  Try to
+         * open it to make sure it is valid.
+         */
+        fresult = f_opendir(&gFsShellAppUtilsDirObj, gFsShellAppUtilsTempPath);
+
+        /* If it can't be opened, then it is a bad path.  Inform user and return. */
+        if(FR_OK != fresult)
+        {
+            FATFS_log("cd: %s\n", gFsShellAppUtilsTempPath);
+            retStat = CSL_ESYS_FAIL;
+        }
+
+        /* Otherwise, it is a valid new path, so copy it into the CWD. */
+        else
+        {
+            strncpy(gFsShellAppUtilsCwd, gFsShellAppUtilsTempPath, sizeof(gFsShellAppUtilsCwd));
+        }
+    }
+
+    /* Return status. */
+    return retStat;
+}
+
+int32_t FSShellAppUtilsCmdPwd(int32_t argc, char *argv[])
+{
+    /* Print the CWD to the console. */
+    FATFS_log("%s\n", gFsShellAppUtilsCwd);
+
+    return CSL_SOK;
+}
+
+int32_t FSShellAppUtilsCmdCat(int32_t argc, char *argv[])
+{
+    FRESULT fresultRead = FR_NOT_READY;
+    FRESULT fresultWrite = FR_NOT_READY;
+    uint32_t bytesWrite = 0;
+    uint32_t flagWrite = FALSE;
+    uint32_t usBytesRead = 0;
+    uint32_t flagRead = FALSE;
+    int32_t retStat = CSL_ESYS_FAIL;
+
+    strcpy(gFsShellAppUtilsTempPath, "");
+
+    /*
+     * Format the path of folder to be created with drive and absolute path.
+     */
+    retStat = FSShellAppUtilsFrmtPath(argv[1U], gFsShellAppUtilsTempPath);
+
+    if (CSL_SOK == retStat)
+    {
+        /* Open the file for reading. */
+        fresultRead = f_open(&gFsShellAppUtilsReadFileObj, gFsShellAppUtilsTempPath, FA_READ);
+
+        /* If there was some problem opening the file, then return an error. */
+        if(fresultRead != FR_OK)
+        {
+            FATFS_log("Fail to open file for read !!!!\n");
+            retStat = CSL_ESYS_FAIL;
+        }
+        else
+        {
+            flagRead = TRUE;
+        }
+    }
+
+    if (CSL_SOK == retStat)
+    {
+        /*
+         * Check for arguments if requested for copy to another file.
+         * Copy the current path to the temporary buffer for new file creation.
+         */
+        if(argc >= 4)
+        {
+            if(0U == strcmp(argv[2], ">"))
+            {
+                strcpy(gFsShellAppUtilsTempPath, "");
+
+                /*
+                 * Format the path of folder to be created with drive and absolute path.
+                 */
+                retStat = FSShellAppUtilsFrmtPath(argv[3U], gFsShellAppUtilsTempPath);
+
+                if (CSL_SOK == retStat)
+                {
+                    fresultWrite = f_open(&gFsShellAppUtilsWriteFileObj, gFsShellAppUtilsTempPath,
+                                                               FA_WRITE|FA_OPEN_ALWAYS);
+
+                    if(fresultWrite != FR_OK)
+                    {
+                        FATFS_log("Fail to open file for write !!!!\n");
+                        retStat = CSL_ESYS_FAIL;
+                    }
+                    else
+                    {
+                        flagWrite = TRUE;
+                    }
+                }
+            }
+        }
+    }
+
+    if (CSL_SOK == retStat)
+    {
+        /*
+         * Enter a loop to repeatedly read data from the file and display it,
+         * until the end of the file is reached.
+         */
+        do
+        {
+            /*
+             * Read a block of data from the file.  Read as much as can fit in
+             * temporary buffer, including a space for the trailing null.
+             */
+            fresultRead = f_read(&gFsShellAppUtilsReadFileObj, gFsShellAppUtilsDataBuf,
+                                 sizeof(gFsShellAppUtilsDataBuf) - 1, &usBytesRead);
+
+            /*
+             * If there was an error reading, then print a newline and return
+             * error to the user.
+             */
+            if(fresultRead != FR_OK)
+            {
+                FATFS_log("Fail to read from file !!!!\n");
+                retStat = CSL_ESYS_FAIL;
+            }
+
+            /*
+             * Write the data to the destination file user has selected.
+             * If there was an error writing, then print a newline and return
+             * error to the user.
+             */
+            if(TRUE == flagWrite)
+            {
+                fresultWrite = f_write(&gFsShellAppUtilsWriteFileObj, gFsShellAppUtilsDataBuf,
+                                       usBytesRead, &bytesWrite);
+
+                if(fresultWrite != FR_OK)
+                {
+                    FATFS_log("Fail to write into file !!!!\n");
+                    retStat = CSL_ESYS_FAIL;
+                }
+            }
+            else
+
+            {
+                /*
+                 * Null terminate the last block that was read to make it a null
+                 * terminated string that can be used with FATFS_log.
+                 */
+                gFsShellAppUtilsDataBuf[usBytesRead] = 0;
+
+                /* Print the last chunk of the file that was received. */
+                FATFS_log("%s",gFsShellAppUtilsDataBuf);
+            }
+
+            /*
+             * Continue reading until less than the full number of bytes are
+             * read. That means the end of the buffer was reached.
+             */
+        }
+        while(usBytesRead == (sizeof(gFsShellAppUtilsDataBuf) - 1));
+    }
+
+       /*
+        * Close the Read file.
+        * If there was an error writing, then print a newline and return the
+        * error to the user.
+        */
+       if(TRUE == flagRead)
+       {
+               fresultRead = f_close(&gFsShellAppUtilsReadFileObj);
+
+               if(fresultRead != FR_OK)
+               {
+            FATFS_log("Fail to close read file !!!!\n");
+            retStat = CSL_ESYS_FAIL;
+               }
+       }
+
+       /*
+        * Close the Write file.
+        * If there was an error writing, then print a newline and return the
+        * error to the user.
+        */
+       if(TRUE == flagWrite)
+       {
+               fresultWrite = f_close(&gFsShellAppUtilsWriteFileObj);
+
+               if(fresultWrite != FR_OK)
+               {
+            FATFS_log("Fail to close write file !!!!\n");
+            retStat = CSL_ESYS_FAIL;
+               }
+       }
+
+    /* Return success. */
+    return retStat;
+}
+
+int32_t FSShellAppUtilsCmdHelp(int32_t argc, char *argv[])
+{
+    fsShellAppUtilsCmdEntry_t *pEntry;
+
+    /*
+    ** Print some header text.
+    */
+    FATFS_log("\nAvailable commands\n");
+    FATFS_log("------------------\n");
+
+    /*
+    ** Point at the beginning of the command table.
+    */
+    pEntry = &gFsShellAppUtilsCmdTable[0];
+
+    /*
+    ** Enter a loop to read each entry from the command table.  The end of the
+    ** table has been reached when the command name is NULL.
+    */
+    while(pEntry->pCmd)
+    {
+        /*
+        ** Print the command name and the brief description.
+        */
+        FATFS_log("%s%s\n", pEntry->pCmd, pEntry->pHelp);
+
+        /*
+        ** Advance to the next entry in the table.
+        */
+        pEntry++;
+    }
+
+    /* Return success. */
+    return(0);
+}
+
+#ifdef MULTI_PARTITION
+int32_t FSShellAppUtilsCmdExit(int32_t argc, char *argv[])
+{
+       gFsExitStatus =1;
+    return CSL_SOK;
+}
+#endif
diff --git a/packages/ti/fs/fatfs/example/console/src/fs_shell_app_utils.h b/packages/ti/fs/fatfs/example/console/src/fs_shell_app_utils.h
new file mode 100644 (file)
index 0000000..09df7d0
--- /dev/null
@@ -0,0 +1,211 @@
+/**
+ *  \file  app_utils_fs_shell.h
+ *
+ *  \brief This file provides structure, api, variable and macro required to
+ *         use user interface example utils.
+ *
+ *  \copyright Copyright (C) 2013-2018 Texas Instruments Incorporated -
+ *             http://www.ti.com/
+ */
+
+/*
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *
+ *    Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the
+ *    distribution.
+ *
+ *    Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef APP_UTILS_FS_SHELL_H_
+#define APP_UTILS_FS_SHELL_H_
+
+/* ========================================================================== */
+/*                             Include Files                                  */
+/* ========================================================================== */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* ========================================================================== */
+/*                           Macros & Typedefs                                */
+/* ========================================================================== */
+
+#define SOC_CACHELINE_SIZE                             (64U)
+
+/** \brief Maximum number of characters user can input. */
+#define UI_APP_UTILS_MAX_INPUT_SIZE                      (80U)
+
+/** \brief Help message to navigate to parent page or home page. */
+#define UI_APP_UTILS_PAGE_HELP       (" 0 - Home; (carriage return) - Back")
+
+/** \brief Defines maximum number of arguments that can be parsed in command line. */
+#define FSSHELLAPPUTILS_CMDLINE_MAX_ARGS               (8U)
+
+/** \brief Defines the value that is returned if the command is not found. */
+#define FSSHELLAPPUTILS_CMDLINE_BAD_CMD                (-1)
+
+/** \brief Defines the value that is returned if there are too many arguments. */
+#define FSSHELLAPPUTILS_CMDLINE_TOO_MANY_ARGS          (-2)
+
+#define FS_SHELL_APP_UTILS_CACHELINE_SIZE 32
+
+/* ========================================================================== */
+/*                         Structures and Enums                               */
+/* ========================================================================== */
+
+/**
+ *  \brief Enumerates execution status user interface.
+ */
+typedef enum fsShellAppUtilsStatus
+{
+    FS_SHELL_APP_UTILS_STATUS_MIN,
+    /**< Maximum configurations for type of page item. */
+    FS_SHELL_APP_UTILS_STATUS_COMPLETE = FS_SHELL_APP_UTILS_STATUS_MIN,
+    /**< Page entry is execute type. */
+    FS_SHELL_APP_UTILS_STATUS_INPROGRESS,
+    /**< Page entry is of navigation type. */
+    FS_SHELL_APP_UTILS_STATUS_ERROR,
+    /**< Page entry is of navigation type. */
+    FS_SHELL_APP_UTILS_STATUS_MAX = FS_SHELL_APP_UTILS_STATUS_ERROR
+    /**< Maximum configurations for type of page item. */
+} fsShellAppUtilsStatus_t;
+
+/**
+ *  \brief Structure defining application console interface.
+ *
+ *  These parameters are used to navigate, configure and execute the application
+ *  on console interface.
+ */
+typedef struct fsShellAppUtilsConsoleInterface
+{
+    uint32_t opMode;
+    /**< User interface operating mode. #fsShellAppUtilsConsoleMode_t. */
+    uint8_t* pRxConsoleBuf;
+    /**< Buffer to store the user input. */
+    uint32_t readStatus;
+    /**< Buffer to store the user input. */
+} fsShellAppUtilsConsoleInterface_t;
+
+/**
+ *  \brief Enumerates configurations for type of page item.
+ */
+typedef enum fsShellAppUtilsState
+{
+    FS_SHELL_APP_UTILS_STATE_HELP,
+    /**< Page entry is execute type. */
+    FS_SHELL_APP_UTILS_STATE_READ_COMMAND,
+    /**< Page entry is of configuration type. */
+    FS_SHELL_APP_UTILS_STATE_EXECUTE_COMMAND,
+    /**< Page entry is of configuration type. */
+    FS_SHELL_APP_UTILS_STATE_MAX
+    /**< Maximum configurations for type of page item. */
+} fsShellAppUtilsState_t;
+
+/**
+ *  \brief Enumerates configurations for type of page item.
+ */
+typedef enum fsShellAppUtilsCmdStatus
+{
+    FS_SHELL_APP_UTILS_CMD_STATUS_PASS,
+    /**< Page entry is execute type. */
+    FS_SHELL_APP_UTILS_CMD_STATUS_TOO_MANY_ARG,
+    /**< Page entry is of configuration type. */
+    FS_SHELL_APP_UTILS_CMD_STATUS_FAIL,
+    /**< Page entry is of configuration type. */
+    FS_SHELL_APP_UTILS_CMD_STATUS_INVALID
+    /**< Maximum configurations for type of page item. */
+} fsShellAppUtilsCmdStatus_t;
+
+/**
+ *  \brief Structure defining the commands supported for command line operation.
+ *
+ *  These parameters are used to decode and execute command line entry.
+ */
+typedef struct fsShellAppUtilsCmdEntry
+{
+    const char *pCmd;
+    /**< A pointer to a string containing the name of the command. */
+    int32_t (*pfnCmd) (int32_t argc, char *argv[]);
+    /**< A function pointer to the implementation of the command. */
+    const char *pHelp;
+    /**< A pointer to a string of brief help text for the command. */
+} fsShellAppUtilsCmdEntry_t;
+
+/* ========================================================================== */
+/*                            Global Variables Declarations                   */
+/* ========================================================================== */
+extern volatile uint8_t fs_is_media_inserted;
+
+/* ========================================================================== */
+/*                          Function Declarations                             */
+/* ========================================================================== */
+
+/**
+ *  \brief   This API configures mode of operation for user interface application utils.
+ *
+ *  \param   configType Index for Page to be displayed.
+ *           Following are possible values.
+ *           - FSSHELLAPPUTILSCONFIGTYPE_BLOCKING - Blocking type
+ *           - FSSHELLAPPUTILSCONFIGTYPE_NON_BLOCKING - Non blocking type
+ *
+ *  \return  S_PASS on success else error code.
+ *
+ **/
+int32_t FSShellAppUtilsInit(void);
+
+/**
+ *  \brief  Process a command line string into arguments and execute the command.
+ *          This function will take the supplied command line string and break it
+ *          up into individual arguments.  The first argument is treated as a
+ *          command and is searched for in the command table. If the command is
+ *          found, then the command function is called and all of the command line
+ *          arguments are passed in the normal argc, argv form.
+ *
+ *  \param  pCmdLine points to a string that contains a command line that was
+ *                  obtained by an application by some means.
+ *
+ *  \param  pCmdList points to a list of command entries used to process command
+ *                  line that was obtained by an application by some means.
+ *
+ *  \return Returns the status of execution of command line.
+ *          Following are possible values.
+ *          - FSSHELLAPPUTILS_CMDLINE_BAD_CMD if the command is not found,
+ *          - FSSHELLAPPUTILS_CMDLINE_TOO_MANY_ARGS if there are more arguments than can be parsed.
+ *          Otherwise it returns the code that was returned by the command function.
+ *
+ */
+#ifdef MULTI_PARTITION
+int32_t FSShellAppUtilsProcess(char *path);
+#else
+int32_t FSShellAppUtilsProcess(void);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* #ifndef APP_UTILS_FS_SHELL_H_ */
diff --git a/packages/ti/fs/fatfs/example/console/src/main_console.c b/packages/ti/fs/fatfs/example/console/src/main_console.c
new file mode 100644 (file)
index 0000000..042463d
--- /dev/null
@@ -0,0 +1,440 @@
+/**
+ *  \file   main_console.c
+ *
+ *  \brief  Example application main file. This application demonstrates
+ *          the file operations on FAT formatted MMCSD device.
+ *
+ */
+
+/*
+ * Copyright (C) 2014-2018 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of Texas Instruments Incorporated nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+
+/* XDCtools Header files */
+#include <xdc/std.h>
+#include <xdc/runtime/System.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <ti/sysbios/knl/Task.h>
+
+/* BIOS Header files */
+#include <ti/sysbios/BIOS.h>
+#include <xdc/runtime/Error.h>
+
+/* TI-RTOS Header files */
+#include <ti/csl/cslr_device.h>
+#include "FATFS_log.h"
+#include <ti/fs/fatfs/diskio.h>
+#include <ti/fs/fatfs/FATFS.h>
+#include <ti/drv/mmcsd/MMCSD.h>
+#include <ti/fs/fatfs/example/console/src/fs_shell_app_utils.h>
+
+#include <ti/board/board.h>
+#ifndef SIMULATOR
+#include <ti/drv/gpio/GPIO.h>
+#include <ti/drv/gpio/soc/GPIO_soc.h>
+#endif
+
+/* GPIO is used to check the pin (SDCD) whether the SD Card is inserted
+ * or not. However in case of AM65XX there is no GPIO pin to check the
+ * SDCD. Hence this feature , i.e using GPIO to check the SD card insert
+ * is disabled. Same is the case with J7 and Simulator (J7). Here the demo
+ * assumes that the SD card is inserted */
+#if !(defined(SOC_AM65XX) || defined(SOC_J721E) || defined(SIMULATOR))
+#define FATFS_GPIO_ENABLED 1
+#endif
+
+#ifndef FATFS_GPIO_ENABLED
+#ifndef GPIO_PIN_MMC_SDCD_ACTIVE_STATE
+#define GPIO_PIN_MMC_SDCD_ACTIVE_STATE 1
+#endif
+#endif
+
+/**********************************************************************
+ ************************** Macros ************************************
+ **********************************************************************/
+#define MMCSD_INSTANCE_MMCSD            (0U)
+#ifdef CONSOLE_EMMC
+#define MMCSD_INSTANCE_EMMC             (1U)
+
+#define GPIO_PIN_VAL_LOW                (0U)
+#define GPIO_PIN_VAL_HIGH               (1U)
+#endif
+
+/**********************************************************************
+ ************************** Internal functions ************************
+ **********************************************************************/
+#ifdef MULTI_PARTITION
+#ifdef CONSOLE_EMMC
+static void EmmcsReset(void);
+static void delay(unsigned int delayValue);
+#endif
+
+static int16_t mainMenu();
+#endif
+/**********************************************************************
+ ************************** Global Variables **************************
+ **********************************************************************/
+
+#ifdef MULTI_PARTITION
+extern PARTITION VolToPart[];
+#endif
+
+/* ON Board LED pins which are connected to GPIO pins. */
+typedef enum GPIO_PIN {
+    GPIO_PIN_MMC_SDCD      = 0U,
+#ifdef CONSOLE_EMMC
+    GPIO_PIN_EMMC_RST,
+#endif
+    GPIO_PIN_COUNT
+}GPIO_PIN;
+
+#ifdef FATFS_GPIO_ENABLED
+/* GPIO Driver board specific pin configuration structure */
+GPIO_PinConfig gpioPinConfigs[] = {
+    /* Output pin : AM335X_ICE V2_LD_PIN */
+    GPIO_DEVICE_CONFIG(GPIO_MMC_SDCD_PORT_NUM, GPIO_MMC_SDCD_PIN_NUM) |
+    GPIO_CFG_IN_INT_BOTH_EDGES | GPIO_CFG_INPUT,
+#ifdef CONSOLE_EMMC
+    GPIO_DEVICE_CONFIG(GPIO_EMMC_RST_PORT_NUM, GPIO_EMMC_RST_PIN_NUM) | GPIO_CFG_OUTPUT,
+#endif
+};
+
+/* GPIO Driver call back functions */
+GPIO_CallbackFxn gpioCallbackFunctions[] = {
+    NULL,
+};
+
+#if (defined(SOC_AM65XX)||defined(SOC_J721E))
+GPIO_v0_Config GPIO_v0_config = {
+    gpioPinConfigs,
+    gpioCallbackFunctions,
+    sizeof(gpioPinConfigs) / sizeof(GPIO_PinConfig),
+    sizeof(gpioCallbackFunctions) / sizeof(GPIO_CallbackFxn),
+    0,
+};
+#else
+/* GPIO Driver configuration structure */
+GPIO_v1_Config GPIO_v1_config = {
+    gpioPinConfigs,
+    gpioCallbackFunctions,
+    sizeof(gpioPinConfigs) / sizeof(GPIO_PinConfig),
+    sizeof(gpioCallbackFunctions) / sizeof(GPIO_CallbackFxn),
+    0,
+};
+#endif
+#endif
+
+/* MMCSD function table for MMCSD implementation */
+FATFS_DrvFxnTable FATFS_drvFxnTable = {
+    MMCSD_close,
+    MMCSD_control,
+    MMCSD_init,
+    MMCSD_open,
+    MMCSD_write,
+    MMCSD_read
+};
+
+/* FATFS configuration structure */
+FATFS_HwAttrs FATFS_initCfg[_VOLUMES] =
+{
+#if defined (SOC_AM65XX) || defined (SOC_J721E)
+    {  /* MMC1 is SD card  for AM65xx GP EVM */
+        1U
+    },
+#else
+    {
+        0U
+    },
+#endif
+    {
+        1U
+    },
+    {
+        2U
+    },
+    {
+        3U
+    }
+};
+
+/* FATFS objects */
+FATFS_Object FATFS_objects[_VOLUMES];
+
+/* FATFS configuration structure */
+const FATFSConfigList FATFS_config = {
+    {
+        &FATFS_drvFxnTable,
+        &FATFS_objects[0],
+        &FATFS_initCfg[0]
+    },
+
+    {
+         &FATFS_drvFxnTable,
+         &FATFS_objects[1],
+         &FATFS_initCfg[1]
+    },
+
+    {
+         &FATFS_drvFxnTable,
+         &FATFS_objects[2],
+         &FATFS_initCfg[2]
+    },
+
+    {NULL, NULL, NULL},
+
+    {NULL, NULL, NULL}
+};
+
+FATFS_Handle fatfsHandle = NULL;
+
+#ifdef CONSOLE_EMMC
+FATFS_Handle eMMCFatfsHandle = NULL;
+#endif
+
+Uint32 fatfsShellProcessFlag = 0;
+Uint32 fs_media_needs_initialization=0;
+Uint32 fs_media_needs_close=0;
+
+#ifdef MULTI_PARTITION
+/* Main Menu Function */
+static int16_t mainMenu()
+{
+    int16_t i=0,drive_partition=5;
+    while(1)
+    {
+        for(i=0;(VolToPart[i].pd != FATFS_DFLT_VOLUME_PD) && i < FATFS_NUM_OF_PARTITIONS; i++)
+        {
+            FATFS_log("\n%x:/",i);
+        }
+
+        FATFS_log("\r\nSelect drive : ");
+        /* Get drive_partition */
+        UART_scanFmt("%d\n",&drive_partition);
+
+        if (drive_partition < 4)
+        {
+            return drive_partition;
+        }
+        else
+        {
+            FATFS_log("\r\nEnter Valid drive_partition\r\n");
+        }
+   }
+}
+#endif
+
+/* Callback function */
+void AppGpioCallbackFxn(void);
+
+/*
+ *  ======== test function ========
+ */
+void fatfs_console(UArg arg0, UArg arg1)
+{
+#ifdef MULTI_PARTITION
+    int16_t option = 0;
+    char drivePath[3];
+#endif
+
+#ifdef FATFS_GPIO_ENABLED
+    /* GPIO initialization */
+    GPIO_init();
+
+    /* Set the callback function */
+    GPIO_setCallback(GPIO_PIN_MMC_SDCD, AppGpioCallbackFxn);
+
+    /* Enable GPIO interrupt on the specific gpio pin */
+    GPIO_enableInt(GPIO_PIN_MMC_SDCD);
+#endif
+
+#ifdef CONSOLE_EMMC
+    EmmcsReset();
+#endif
+
+    /* MMCSD FATFS initialization */
+    FATFS_init();
+
+#if !defined(FATFS_GPIO_ENABLED)
+    FATFS_log ("\nPlease ensure SD card is inserted before running this demo\r\n");
+    fs_is_media_inserted = 1;
+    if(1)
+#else
+    if (GPIO_PIN_MMC_SDCD_ACTIVE_STATE == GPIO_read(GPIO_PIN_MMC_SDCD))
+#endif
+    {
+        FATFS_open(MMCSD_INSTANCE_MMCSD, NULL, &fatfsHandle);
+        fatfsShellProcessFlag = 1;
+        fs_is_media_inserted = 1;
+
+    }
+    else
+    {
+        FATFS_log ("\nPlease insert card.\r\n");
+        fs_is_media_inserted = 0;
+    }
+
+#ifdef CONSOLE_EMMC
+    if(FATFS_OK != FATFS_open(MMCSD_INSTANCE_EMMC, NULL, &eMMCFatfsHandle))
+    {
+        FATFS_log("\n eMMC Fails to open \n");
+    }
+#endif
+    while(1)
+    {
+        /* Check for any media state changes and initialize/close FATFS accordingly.
+         * Please note that this is checked*/
+
+        if(fs_media_needs_initialization) {
+
+            FATFS_log("\nMedia Inserted..Initializing..\n");
+            FATFS_open(MMCSD_INSTANCE_MMCSD, NULL, &fatfsHandle);
+            fatfsShellProcessFlag = 1;
+            fs_media_needs_initialization=0;
+        }
+
+        if(fs_media_needs_close) {
+            FATFS_close(fatfsHandle);
+            fatfsShellProcessFlag = 0;
+            fs_media_needs_close=0;
+            FATFS_log("\nMedia Removed..Please insert media..\n");
+        }
+
+        if (0 != fatfsShellProcessFlag)
+        {
+#ifdef MULTI_PARTITION
+            option = mainMenu();
+            snprintf(drivePath, 3, "%d:", option);
+            FSShellAppUtilsProcess(drivePath);
+#else
+            FSShellAppUtilsProcess();
+            fatfsShellProcessFlag = 0;
+#endif
+
+        }
+    }
+}
+
+
+#ifndef BARE_METAL
+#if (defined(SOC_AM65XX) || defined(SOC_J721E)) && (defined(BUILD_MPU) || defined (__C7100__))
+extern void Osal_initMmuDefault(void);
+void InitMmu(void)
+{
+    Osal_initMmuDefault();
+}
+#endif
+#endif
+
+
+/*
+ *  ======== main ========
+ */
+int main(void)
+{
+       Task_Handle task;
+       Error_Block eb;
+    /* Call board init functions */
+    Board_initCfg boardCfg;
+    boardCfg = BOARD_INIT_PINMUX_CONFIG | BOARD_INIT_UART_STDIO | BOARD_INIT_MODULE_CLOCK;
+
+#if (defined(SOC_AM65XX)||defined(SOC_J721E)) &&  defined(__TI_ARM_V7R4__)
+    /* Clear it until the issue is resolved */
+    boardCfg &= ~(BOARD_INIT_MODULE_CLOCK);
+#endif
+
+    Board_init(boardCfg);
+
+    Error_init(&eb);
+    task = Task_create(fatfs_console, NULL, &eb);
+    if (task == NULL) {
+        System_printf("Task_create() failed!\n");
+        BIOS_exit(0);
+    }
+
+    /* Start BIOS */
+    BIOS_start();
+
+    return (0);
+}
+
+
+void media_open()
+{
+    FATFS_open(MMCSD_INSTANCE_MMCSD, NULL, &fatfsHandle);
+    fatfsShellProcessFlag = 1;
+}
+void media_close()
+{
+    FATFS_close(fatfsHandle);
+    fatfsShellProcessFlag = 0;
+}
+
+#ifdef FATFS_GPIO_ENABLED
+/*
+ *  ======== Callback function ========
+ */
+void AppGpioCallbackFxn(void)
+{
+    if (GPIO_PIN_MMC_SDCD_ACTIVE_STATE == GPIO_read(GPIO_PIN_MMC_SDCD))
+    {
+        fs_is_media_inserted=1; /* The media has been inserted now */
+        fs_media_needs_initialization=1; /* Need to initialize FATFS with the media */
+    }
+    else
+    {
+        fs_is_media_inserted=0;/*  The media has been ejected now */
+        fs_media_needs_close=1; /* Need to close FATFS with the media */
+    }
+}
+#endif
+
+#ifdef CONSOLE_EMMC
+static void EmmcsReset(void)
+{
+    /* EMMC reset */
+    GPIO_write(GPIO_PIN_EMMC_RST, GPIO_PIN_VAL_LOW);
+    delay(100);
+    GPIO_write(GPIO_PIN_EMMC_RST, GPIO_PIN_VAL_HIGH);
+    delay(100);
+}
+
+/*
+ *  ======== Delay function ========
+ */
+static void delay(unsigned int delayValue)
+{
+    volatile uint32_t delay1 = delayValue*10000;
+    while (delay1--) ;
+}
+#endif
diff --git a/packages/ti/fs/fatfs/fatfs_component.mk b/packages/ti/fs/fatfs/fatfs_component.mk
new file mode 100644 (file)
index 0000000..9d4915a
--- /dev/null
@@ -0,0 +1,201 @@
+#
+# Copyright (c) 2016 - 2019, Texas Instruments Incorporated
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# *  Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+#
+# *  Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# *  Neither the name of Texas Instruments Incorporated nor the names of
+#    its contributors may be used to endorse or promote products derived
+#    from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+# File: fatfs_component.mk
+#       This file is component include make file of FATFS library.
+# List of variables set in this file and their purpose:
+# <mod>_RELPATH        - This is the relative path of the module, typically from
+#                        top-level directory of the package
+# <mod>_PATH           - This is the absolute path of the module. It derives from
+#                        absolute path of the top-level directory (set in env.mk)
+#                        and relative path set above
+# <mod>_INCLUDE        - This is the path that has interface header files of the
+#                        module. This can be multiple directories (space separated)
+# <mod>_PKG_LIST       - Names of the modules (and sub-modules) that are a part
+#                        part of this module, including itself.
+# <mod>_BOARD_DEPENDENCY - "yes": means the code for this module depends on
+#                             board and the compiled obj/lib has to be kept
+#                             under <board> directory
+#                             "no" or "" or if this variable is not defined: means
+#                             this module has no board dependent code and hence
+#                             the obj/libs are not kept under <board> dir.
+# <mod>_CORE_DEPENDENCY     - "yes": means the code for this module depends on
+#                             core and the compiled obj/lib has to be kept
+#                             under <core> directory
+#                             "no" or "" or if this variable is not defined: means
+#                             this module has no core dependent code and hence
+#                             the obj/libs are not kept under <core> dir.
+# <mod>_APP_STAGE_FILES     - List of source files that belongs to the module
+#                             <mod>, but that needs to be compiled at application
+#                             build stage (in the context of the app). This is
+#                             primarily for link time configurations or if the
+#                             source file is dependent on options/defines that are
+#                             application dependent. This can be left blank or
+#                             not defined at all, in which case, it means there
+#                             no source files in the module <mod> that are required
+#                             to be compiled in the application build stage.
+#
+ifeq ($(fatfs_component_make_include), )
+
+# under other list
+drvfatfs_BOARDLIST       = am65xx_evm am65xx_idk j721e_sim j721e_evm
+drvfatfs_SOCLIST           = am574x am572x am571x am437x am335x dra72x dra75x dra78x k2g omapl137 omapl138 am65xx j721e
+drvfatfs_am574x_CORELIST   = c66x a15_0 ipu1_0
+drvfatfs_am572x_CORELIST   = c66x a15_0 ipu1_0
+drvfatfs_am571x_CORELIST   = c66x a15_0 ipu1_0
+drvfatfs_dra72x_CORELIST   = c66x a15_0 ipu1_0
+drvfatfs_dra75x_CORELIST   = c66x a15_0 ipu1_0
+drvfatfs_dra78x_CORELIST   = c66x ipu1_0
+drvfatfs_am437x_CORELIST   = a9host
+drvfatfs_am335x_CORELIST   = a8host
+drvfatfs_k2g_CORELIST      = c66x a15_0
+drvfatfs_omapl137_CORELIST = arm9_0 c674x
+drvfatfs_omapl138_CORELIST = arm9_0 c674x
+drvfatfs_am65xx_CORELIST   = mpu1_0 mcu1_0
+drvfatfs_j721e_CORELIST   = $(DEFAULT_j721e_CORELIST)
+############################
+# uart package
+# List of components included under uart lib
+# The components included here are built and will be part of uart lib
+############################
+fatfs_LIB_LIST = fatfs_indp fatfs_multi_indp fatfs_profile_indp
+drvfatfs_LIB_LIST = $(fatfs_LIB_LIST)
+fatfs_EXAMPLE_LIST = 
+
+#
+# FATFS Modules
+#
+
+# FATFS LIB DEVICE INDEPENDENT
+fatfs_indp_COMP_LIST = fatfs_indp
+fatfs_indp_RELPATH = ti/fs/fatfs
+fatfs_indp_PATH = $(PDK_FATFS_COMP_PATH)
+fatfs_indp_LIBNAME = ti.fs.fatfs
+export fatfs_indp_LIBNAME
+fatfs_indp_LIBPATH = $(fatfs_indp_PATH)/lib
+export fatfs_indp_LIBPATH
+fatfs_indp_OBJPATH = $(fatfs_indp_RELPATH)/fatfs_indp
+export fatfs_indp_OBJPATH
+fatfs_indp_MAKEFILE = -f build/makefile_indp.mk
+export fatfs_indp_MAKEFILE
+fatfs_indp_BOARD_DEPENDENCY = no
+fatfs_indp_CORE_DEPENDENCY = no
+fatfs_indp_SOC_DEPENDENCY = no
+export fatfs_indp_COMP_LIST
+export fatfs_indp_BOARD_DEPENDENCY
+export fatfs_indp_CORE_DEPENDENCY
+export fatfs_indp_SOC_DEPENDENCY
+fatfs_indp_PKG_LIST = fatfs_indp
+export fatfs_indp_PKG_LIST
+fatfs_indp_INCLUDE = $(fatfs_indp_PATH)
+fatfs_indp_SOCLIST = $(drvfatfs_SOCLIST)
+export fatfs_indp_SOCLIST
+fatfs_indp_$(SOC)_CORELIST = $(drvfatfs_$(SOC)_CORELIST)
+export fatfs_indp_$(SOC)_CORELIST
+
+# FATFS PROFILING SOC INDEPENDENT LIB
+fatfs_profile_indp_COMP_LIST = fatfs_profile_indp
+fatfs_profile_indp_RELPATH = ti/fs/fatfs
+fatfs_profile_indp_PATH = $(PDK_FATFS_COMP_PATH)
+fatfs_profile_indp_LIBNAME = ti.fs.fatfs.profiling
+export fatfs_profile_indp_LIBNAME
+fatfs_profile_indp_LIBPATH = $(fatfs_profile_indp_PATH)/lib
+export fatfs_profile_indp_LIBPATH
+fatfs_profile_indp_OBJPATH = $(fatfs_profile_indp_RELPATH)/fatfs_profile_indp
+export fatfs_profile_indp_OBJPATH
+fatfs_profile_indp_MAKEFILE = -f build/makefile_profile_indp.mk
+export fatfs_profile_indp_MAKEFILE
+fatfs_profile_indp_BOARD_DEPENDENCY = no
+fatfs_profile_indp_CORE_DEPENDENCY = no
+fatfs_profile_indp_SOC_DEPENDENCY = no
+export fatfs_profile_indp_COMP_LIST
+export fatfs_profile_indp_BOARD_DEPENDENCY
+export fatfs_profile_indp_CORE_DEPENDENCY
+export fatfs_profile_indp_SOC_DEPENDENCY
+fatfs_profile_indp_PKG_LIST = fatfs_profile_indp
+export fatfs_profile_indp_PKG_LIST
+fatfs_profile_indp_INCLUDE = $(fatfs_profile_indp_PATH)
+fatfs_profile_indp_SOCLIST = am574x am572x am571x am437x am335x dra72x dra75x dra78x k2g omapl137 omapl138
+export fatfs_profile_indp_SOCLIST
+fatfs_profile_indp_$(SOC)_CORELIST = $(drvfatfs_$(SOC)_CORELIST)
+export fatfs_profile_indp_$(SOC)_CORELIST
+
+# EMMC Readwrite test
+FATFS_Console_TestApp_COMP_LIST = FATFS_Console_TestApp
+FATFS_Console_TestApp_RELPATH = ti/fs/fatfs/example/console
+FATFS_Console_TestApp_PATH = $(PDK_FATFS_COMP_PATH)/example/console
+FATFS_Console_TestApp_BOARD_DEPENDENCY = yes
+FATFS_Console_TestApp_CORE_DEPENDENCY = no
+FATFS_Console_TestApp_XDC_CONFIGURO = yes
+export FATFS_Console_TestApp_COMP_LIST
+export FATFS_Console_TestApp_BOARD_DEPENDENCY
+export FATFS_Console_TestApp_CORE_DEPENDENCY
+export FATFS_Console_TestApp_XDC_CONFIGURO
+FATFS_Console_TestApp_PKG_LIST = FATFS_Console_TestApp
+FATFS_Console_TestApp_INCLUDE = $(FATFS_Console_TestApp_PATH)
+FATFS_Console_TestApp_BOARDLIST = $(drvfatfs_BOARDLIST)
+export FATFS_Console_TestApp_BOARDLIST
+FATFS_Console_TestApp_$(SOC)_CORELIST = $(drvfatfs_$(SOC)_CORELIST)
+export FATFS_Console_TestApp_$(SOC)_CORELIST
+
+fatfs_EXAMPLE_LIST += FATFS_Console_TestApp
+
+# EMMC Readwrite test with SMP enabled
+FATFS_Console_SMP_TestApp_COMP_LIST = FATFS_Console_SMP_TestApp
+FATFS_Console_SMP_TestApp_RELPATH = ti/fs/fatfs/example/console
+FATFS_Console_SMP_TestApp_PATH = $(PDK_FATFS_COMP_PATH)/example/console
+FATFS_Console_SMP_TestApp_MAKEFILE = -f makefile SMP=enable
+FATFS_Console_SMP_TestApp_BOARD_DEPENDENCY = yes
+FATFS_Console_SMP_TestApp_CORE_DEPENDENCY = no
+FATFS_Console_SMP_TestApp_XDC_CONFIGURO = yes
+export FATFS_Console_SMP_TestApp_COMP_LIST
+export FATFS_Console_SMP_TestApp_BOARD_DEPENDENCY
+export FATFS_Console_SMP_TestApp_CORE_DEPENDENCY
+export FATFS_Console_SMP_TestApp_XDC_CONFIGURO
+FATFS_Console_SMP_TestApp_PKG_LIST = FATFS_Console_SMP_TestApp
+FATFS_Console_SMP_TestApp_INCLUDE = $(FATFS_Console_SMP_TestApp_PATH)
+FATFS_Console_SMP_TestApp_BOARDLIST = am65xx_idk
+export FATFS_Console_SMP_TestApp_BOARDLIST
+FATFS_Console_SMP_TestApp_$(SOC)_CORELIST = mpu1_0
+export FATFS_Console_SMP_TestApp_$(SOC)_CORELIST
+
+fatfs_EXAMPLE_LIST += FATFS_Console_SMP_TestApp
+
+export drvfatfs_LIB_LIST
+export fatfs_LIB_LIST
+export fatfs_EXAMPLE_LIST
+
+drvfatfs_EXAMPLE_LIST = $(fatfs_EXAMPLE_LIST)
+export drvfatfs_EXAMPLE_LIST
+
+fatfs_component_make_include := 1
+endif
diff --git a/packages/ti/fs/fatfs/ff.h b/packages/ti/fs/fatfs/ff.h
new file mode 100644 (file)
index 0000000..5fbb379
--- /dev/null
@@ -0,0 +1,386 @@
+/*---------------------------------------------------------------------------/\r
+/  FatFs - FAT file system module include R0.12     (C)ChaN, 2016\r
+/----------------------------------------------------------------------------/\r
+/ FatFs module is a free software that opened under license policy of\r
+/ following conditions.\r
+/\r
+/ Copyright (C) 2016, ChaN, all right reserved.\r
+/\r
+/ 1. Redistributions of source code must retain the above copyright notice,\r
+/    this condition and the following disclaimer.\r
+/\r
+/ This software is provided by the copyright holder and contributors "AS IS"\r
+/ and any warranties related to this software are DISCLAIMED.\r
+/ The copyright owner or contributors be NOT LIABLE for any damages caused\r
+/ by use of this software.\r
+/---------------------------------------------------------------------------*/\r
+\r
+\r
+#ifndef _FATFS\r
+#define _FATFS 88100   /* Revision ID */\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#include "integer.h"   /* Basic integer types */\r
+#include "ffconf.h"            /* FatFs configuration options */\r
+#if _FATFS != _FFCONF\r
+#error Wrong configuration file (ffconf.h).\r
+#endif\r
+\r
+\r
+\r
+/* Definitions of volume management */\r
+\r
+#if _MULTI_PARTITION           /* Multiple partition configuration */\r
+typedef struct {\r
+       BYTE pd;        /* Physical drive number */\r
+       BYTE pt;        /* Partition: 0:Auto detect, 1-4:Forced partition) */\r
+} PARTITION;\r
+extern PARTITION VolToPart[];  /* Volume - Partition resolution table */\r
+#define LD2PD(vol) (VolToPart[vol].pd) /* Get physical drive number */\r
+#define LD2PT(vol) (VolToPart[vol].pt) /* Get partition index */\r
+\r
+#else                                                  /* Single partition configuration */\r
+#define LD2PD(vol) (BYTE)(vol) /* Each logical drive is bound to the same physical drive number */\r
+#define LD2PT(vol) 0                   /* Find first valid partition or in SFD */\r
+\r
+#endif\r
+\r
+\r
+\r
+/* Type of path name strings on FatFs API */\r
+\r
+#if _LFN_UNICODE                       /* Unicode string */\r
+#if _USE_LFN == 0\r
+#error _LFN_UNICODE must be 0 at non-LFN cfg.\r
+#endif\r
+#ifndef _INC_TCHAR\r
+typedef WCHAR TCHAR;\r
+#define _T(x) L ## x\r
+#define _TEXT(x) L ## x\r
+#endif\r
+\r
+#else                                          /* ANSI/OEM string */\r
+#ifndef _INC_TCHAR\r
+typedef char TCHAR;\r
+#define _T(x) x\r
+#define _TEXT(x) x\r
+#endif\r
+\r
+#endif\r
+\r
+\r
+\r
+/* File system object structure (FATFS) */\r
+\r
+typedef struct {\r
+       BYTE    fs_type;                /* File system type (0:N/A) */\r
+       BYTE    drv;                    /* Physical drive number */\r
+       BYTE    n_fats;                 /* Number of FATs (1 or 2) */\r
+       BYTE    wflag;                  /* win[] flag (b0:dirty) */\r
+       BYTE    fsi_flag;               /* FSINFO flags (b7:disabled, b0:dirty) */\r
+       WORD    id;                             /* File system mount ID */\r
+       WORD    n_rootdir;              /* Number of root directory entries (FAT12/16) */\r
+       WORD    csize;                  /* Cluster size [sectors] */\r
+#if _MAX_SS != _MIN_SS\r
+       WORD    ssize;                  /* Sector size (512, 1024, 2048 or 4096) */\r
+#endif\r
+#if _FS_EXFAT\r
+       BYTE*   dirbuf;                 /* Directory entry block scratchpad buffer */\r
+#endif\r
+#if _FS_REENTRANT\r
+       _SYNC_t sobj;                   /* Identifier of sync object */\r
+#endif\r
+#if !_FS_READONLY\r
+       DWORD   last_clst;              /* Last allocated cluster */\r
+       DWORD   free_clst;              /* Number of free clusters */\r
+#endif\r
+#if _FS_RPATH != 0\r
+       DWORD   cdir;                   /* Current directory start cluster (0:root) */\r
+#if _FS_EXFAT\r
+       DWORD   cdc_scl;                /* Containing directory start cluster (invalid when cdir is 0) */\r
+       DWORD   cdc_size;               /* b31-b8:Size of containing directory, b7-b0: Chain status */\r
+       DWORD   cdc_ofs;                /* Offset in the containing directory (invalid when cdir is 0) */\r
+#endif\r
+#endif\r
+       DWORD   n_fatent;               /* Number of FAT entries (number of clusters + 2) */\r
+       DWORD   fsize;                  /* Size of an FAT [sectors] */\r
+       DWORD   volbase;                /* Volume base sector */\r
+       DWORD   fatbase;                /* FAT base sector */\r
+       DWORD   dirbase;                /* Root directory base sector/cluster */\r
+       DWORD   database;               /* Data base sector */\r
+       DWORD   winsect;                /* Current sector appearing in the win[] */\r
+\r
+#if defined(__GNUC__) || defined(gcc) || \\r
+    defined(__aarch64__) || defined (__TI_ARM_V7R4__) || defined(__ARM_ARCH_7A__) || defined (__TI_ARM_V7M4__) || defined (__TI_ARM_V5__)\r
+    BYTE    win[_MAX_SS] __attribute__ ((aligned (128U)));  /* Disk access window for Directory, \r
+                                                            FAT (and file data at tiny cfg) */\r
+#else\r
+    BYTE    win[_MAX_SS];  /* Disk access window for Directory,\r
+                              FAT (and file data at tiny cfg) */\r
+#if !(defined(_TMS320C6X) || defined(__C7100__))\r
+    #warning this win buffer needs to be cache-line aligned\r
+#endif\r
+\r
+#endif\r
+\r
+} FATFS;\r
+\r
+\r
+\r
+/* Type of file size variables and object identifier */\r
+\r
+#if _FS_EXFAT\r
+#if _USE_LFN == 0\r
+#error LFN must be enabled when enable exFAT\r
+#endif\r
+typedef QWORD FSIZE_t;\r
+#else\r
+typedef DWORD FSIZE_t;\r
+#endif\r
+\r
+\r
+\r
+/* Object ID and allocation information (_FDID) */\r
+\r
+typedef struct {\r
+       FATFS*  fs;                     /* Pointer to the owner file system object */\r
+       WORD    id;                     /* Owner file system mount ID */\r
+       BYTE    attr;           /* Object attribute */\r
+       BYTE    stat;           /* Object chain status (b1-0: =0:not contiguous, =2:contiguous (no data on FAT), =3:got flagmented, b2:sub-directory stretched) */\r
+       DWORD   sclust;         /* Object start cluster (0:no cluster or root directory) */\r
+       FSIZE_t objsize;        /* Object size (valid when sclust != 0) */\r
+#if _FS_EXFAT\r
+       DWORD   n_cont;         /* Size of coutiguous part, clusters - 1 (valid when stat == 3) */\r
+       DWORD   c_scl;          /* Containing directory start cluster (valid when sclust != 0) */\r
+       DWORD   c_size;         /* b31-b8:Size of containing directory, b7-b0: Chain status (valid when c_scl != 0) */\r
+       DWORD   c_ofs;          /* Offset in the containing directory (valid when sclust != 0) */\r
+#endif\r
+#if _FS_LOCK != 0\r
+       UINT    lockid;         /* File lock ID origin from 1 (index of file semaphore table Files[]) */\r
+#endif\r
+} _FDID;\r
+\r
+\r
+\r
+/* File object structure (FIL) */\r
+\r
+typedef struct {\r
+       _FDID   obj;                    /* Object identifier */\r
+       BYTE    flag;                   /* File status flags */\r
+       BYTE    err;                    /* Abort flag (error code) */\r
+       FSIZE_t fptr;                   /* File read/write pointer (Zeroed on file open) */\r
+       DWORD   clust;                  /* Current cluster of fpter (not valid when fprt is 0) */\r
+       DWORD   sect;                   /* Sector number appearing in buf[] (0:invalid) */\r
+#if !_FS_READONLY\r
+       DWORD   dir_sect;               /* Sector number containing the directory entry */\r
+       BYTE*   dir_ptr;                /* Pointer to the directory entry in the win[] */\r
+#endif\r
+#if _USE_FASTSEEK\r
+       DWORD*  cltbl;                  /* Pointer to the cluster link map table (Nulled on file open) */\r
+#endif\r
+#if !_FS_TINY\r
+    /* File private data read/write window */\r
+#if defined(__GNUC__) || defined(gcc) || \\r
+    defined(__aarch64__) || defined (__TI_ARM_V7R4__) || defined(__ARM_ARCH_7A__) || defined (__TI_ARM_V7M4__) || defined (__TI_ARM_V5__)\r
+    BYTE    buf[_MAX_SS] __attribute__ ((aligned (128U)));\r
+#else\r
+    BYTE    buf[_MAX_SS];\r
+#endif\r
+#endif\r
+} FIL;\r
+\r
+\r
+\r
+/* Directory object structure (DIR) */\r
+\r
+typedef struct {\r
+       _FDID   obj;                    /* Object identifier */\r
+       DWORD   dptr;                   /* Current read/write offset */\r
+       DWORD   clust;                  /* Current cluster */\r
+       DWORD   sect;                   /* Current sector */\r
+       BYTE*   dir;                    /* Pointer to the directory item in the win[] */\r
+       BYTE*   fn;                             /* Pointer to the SFN (in/out) {body[8],ext[3],status[1]} */\r
+#if _USE_LFN != 0\r
+       DWORD   blk_ofs;                /* Offset of current entry block being processed (0xFFFFFFFF:Invalid) */\r
+       WCHAR*  lfn;                    /* Pointer to the LFN working buffer */\r
+#endif\r
+#if _USE_FIND\r
+       const TCHAR* pat;               /* Pointer to the name matching pattern */\r
+#endif\r
+} DIR;\r
+\r
+\r
+\r
+/* File information structure (FILINFO) */\r
+\r
+typedef struct {\r
+       FSIZE_t fsize;                  /* File size */\r
+       WORD    fdate;                  /* Modified date */\r
+       WORD    ftime;                  /* Modified time */\r
+       BYTE    fattrib;                /* File attribute */\r
+#if _USE_LFN != 0\r
+       TCHAR   altname[13];                    /* Altenative file name */\r
+       TCHAR   fname[_MAX_LFN + 1];    /* Primary file name */\r
+#else\r
+       TCHAR   fname[13];              /* File name */\r
+#endif\r
+} FILINFO;\r
+\r
+\r
+\r
+/* File function return code (FRESULT) */\r
+\r
+typedef enum {\r
+       FR_OK = 0,                              /* (0) Succeeded */\r
+       FR_DISK_ERR,                    /* (1) A hard error occurred in the low level disk I/O layer */\r
+       FR_INT_ERR,                             /* (2) Assertion failed */\r
+       FR_NOT_READY,                   /* (3) The physical drive cannot work */\r
+       FR_NO_FILE,                             /* (4) Could not find the file */\r
+       FR_NO_PATH,                             /* (5) Could not find the path */\r
+       FR_INVALID_NAME,                /* (6) The path name format is invalid */\r
+       FR_DENIED,                              /* (7) Access denied due to prohibited access or directory full */\r
+       FR_EXIST,                               /* (8) Access denied due to prohibited access */\r
+       FR_INVALID_OBJECT,              /* (9) The file/directory object is invalid */\r
+       FR_WRITE_PROTECTED,             /* (10) The physical drive is write protected */\r
+       FR_INVALID_DRIVE,               /* (11) The logical drive number is invalid */\r
+       FR_NOT_ENABLED,                 /* (12) The volume has no work area */\r
+       FR_NO_FILESYSTEM,               /* (13) There is no valid FAT volume */\r
+       FR_MKFS_ABORTED,                /* (14) The f_mkfs() aborted due to any parameter error */\r
+       FR_TIMEOUT,                             /* (15) Could not get a grant to access the volume within defined period */\r
+       FR_LOCKED,                              /* (16) The operation is rejected according to the file sharing policy */\r
+       FR_NOT_ENOUGH_CORE,             /* (17) LFN working buffer could not be allocated */\r
+       FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > _FS_LOCK */\r
+       FR_INVALID_PARAMETER,   /* (19) Given parameter is invalid */\r
+    FR_MAX\r
+} FRESULT;\r
+\r
+\r
+\r
+/*--------------------------------------------------------------*/\r
+/* FatFs module application interface                           */\r
+\r
+FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode);                                /* Open or create a file */\r
+FRESULT f_close (FIL* fp);                                                                                     /* Close an open file object */\r
+FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br);                      /* Read data from a file */\r
+FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw);       /* Write data to a file */\r
+FRESULT f_lseek (FIL* fp, FSIZE_t ofs);                                                                /* Move file pointer of a file object */\r
+FRESULT f_truncate (FIL* fp);                                                                          /* Truncate file */\r
+FRESULT f_sync (FIL* fp);                                                                                      /* Flush cached data of a writing file */\r
+FRESULT f_opendir (DIR* dp, const TCHAR* path);                                                /* Open a directory */\r
+FRESULT f_closedir (DIR* dp);                                                                          /* Close an open directory */\r
+FRESULT f_readdir (DIR* dp, FILINFO* fno);                                                     /* Read a directory item */\r
+FRESULT f_findfirst (DIR* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern);  /* Find first file */\r
+FRESULT f_findnext (DIR* dp, FILINFO* fno);                                                    /* Find next file */\r
+FRESULT f_mkdir (const TCHAR* path);                                                           /* Create a sub directory */\r
+FRESULT f_unlink (const TCHAR* path);                                                          /* Delete an existing file or directory */\r
+FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new);       /* Rename/Move a file or directory */\r
+FRESULT f_stat (const TCHAR* path, FILINFO* fno);                                      /* Get file status */\r
+FRESULT f_chmod (const TCHAR* path, BYTE attr, BYTE mask);                     /* Change attribute of the file/dir */\r
+FRESULT f_utime (const TCHAR* path, const FILINFO* fno);                       /* Change timestamp of the file/dir */\r
+FRESULT f_chdir (const TCHAR* path);                                                           /* Change current directory */\r
+FRESULT f_chdrive (const TCHAR* path);                                                         /* Change current drive */\r
+FRESULT f_getcwd (TCHAR* buff, UINT len);                                                      /* Get current directory */\r
+FRESULT f_getfree (const TCHAR* path, DWORD* nclst, FATFS** fatfs);    /* Get number of free clusters on the drive */\r
+FRESULT f_getlabel (const TCHAR* path, TCHAR* label, DWORD* vsn);      /* Get volume label */\r
+FRESULT f_setlabel (const TCHAR* label);                                                       /* Set volume label */\r
+FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf);        /* Forward data to the stream */\r
+FRESULT f_expand (FIL* fp, FSIZE_t szf, BYTE opt);                                     /* Allocate a contiguous block to the file */\r
+FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt);                      /* Mount/Unmount a logical drive */\r
+FRESULT f_mkfs (const TCHAR* path, BYTE sfd, UINT au);                         /* Create a file system on the volume */\r
+FRESULT f_fdisk (BYTE pdrv, const DWORD szt[], void* work);                    /* Divide a physical drive into some partitions */\r
+int f_putc (TCHAR c, FIL* fp);                                                                         /* Put a character to the file */\r
+int f_puts (const TCHAR* str, FIL* cp);                                                                /* Put a string to the file */\r
+int f_printf (FIL* fp, const TCHAR* str, ...);                                         /* Put a formatted string to the file */\r
+TCHAR* f_gets (TCHAR* buff, int len, FIL* fp);                                         /* Get a string from the file */\r
+\r
+#define f_eof(fp) ((int)((fp)->fptr == (fp)->obj.objsize))\r
+#define f_error(fp) ((fp)->err)\r
+#define f_tell(fp) ((fp)->fptr)\r
+#define f_size(fp) ((fp)->obj.objsize)\r
+#define f_rewind(fp) f_lseek((fp), 0)\r
+#define f_rewinddir(dp) f_readdir((dp), 0)\r
+\r
+#ifndef EOF\r
+#define EOF (-1)\r
+#endif\r
+\r
+\r
+\r
+\r
+/*--------------------------------------------------------------*/\r
+/* Additional user defined functions                            */\r
+\r
+/* RTC function */\r
+#if !_FS_READONLY && !_FS_NORTC\r
+DWORD get_fattime (void);\r
+#endif\r
+\r
+/* Unicode support functions */\r
+#if _USE_LFN != 0                                              /* Unicode - OEM code conversion */\r
+WCHAR ff_convert (WCHAR chr, UINT dir);        /* OEM-Unicode bidirectional conversion */\r
+WCHAR ff_wtoupper (WCHAR chr);                 /* Unicode upper-case conversion */\r
+#if _USE_LFN == 3                                              /* Memory functions */\r
+void* ff_memalloc (UINT msize);                        /* Allocate memory block */\r
+void ff_memfree (void* mblock);                        /* Free memory block */\r
+#endif\r
+#endif\r
+\r
+/* Sync functions */\r
+#if _FS_REENTRANT\r
+int ff_cre_syncobj (BYTE vol, _SYNC_t* sobj);  /* Create a sync object */\r
+int ff_req_grant (_SYNC_t sobj);                               /* Lock sync object */\r
+void ff_rel_grant (_SYNC_t sobj);                              /* Unlock sync object */\r
+int ff_del_syncobj (_SYNC_t sobj);                             /* Delete a sync object */\r
+#endif\r
+\r
+\r
+\r
+\r
+/*--------------------------------------------------------------*/\r
+/* Flags and offset address                                     */\r
+\r
+\r
+/* File access control and file status flags (FIL.flag) */\r
+\r
+#define        FA_READ                         0x01\r
+#define        FA_WRITE                        0x02\r
+#define        FA_OPEN_EXISTING        0x00\r
+#define        FA_CREATE_NEW           0x04\r
+#define        FA_CREATE_ALWAYS        0x08\r
+#define        FA_OPEN_ALWAYS          0x10\r
+#define _FA_MODIFIED           0x20\r
+#define _FA_DIRTY                      0x40\r
+\r
+\r
+/* FAT sub type (FATFS.fs_type) */\r
+\r
+#define FS_FAT12       1\r
+#define FS_FAT16       2\r
+#define FS_FAT32       3\r
+#define FS_EXFAT       4\r
+\r
+\r
+/* File attribute bits for directory entry */\r
+\r
+#define        AM_RDO  0x01    /* Read only */\r
+#define        AM_HID  0x02    /* Hidden */\r
+#define        AM_SYS  0x04    /* System */\r
+#define        AM_VOL  0x08    /* Volume label */\r
+#define AM_LFN 0x0F    /* LFN entry */\r
+#define AM_DIR 0x10    /* Directory */\r
+#define AM_ARC 0x20    /* Archive */\r
+#define AM_MASK        0x3F    /* Mask of defined bits */\r
+\r
+\r
+/* Fast seek controls */\r
+#define CREATE_LINKMAP ((FSIZE_t)0 - 1)\r
+\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /* _FATFS */\r
diff --git a/packages/ti/fs/fatfs/ffconf.h b/packages/ti/fs/fatfs/ffconf.h
new file mode 100644 (file)
index 0000000..80c7d3e
--- /dev/null
@@ -0,0 +1,266 @@
+/*---------------------------------------------------------------------------/\r
+/  FatFs - FAT file system module configuration file  R0.12  (C)ChaN, 2016\r
+/---------------------------------------------------------------------------*/\r
+\r
+#define _FFCONF 88100  /* Revision ID */\r
+\r
+/*---------------------------------------------------------------------------/\r
+/ Function Configurations\r
+/---------------------------------------------------------------------------*/\r
+\r
+#define _FS_READONLY   0\r
+/* This option switches read-only configuration. (0:Read/Write or 1:Read-only)\r
+/  Read-only configuration removes writing API functions, f_write(), f_sync(),\r
+/  f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree()\r
+/  and optional writing functions as well. */\r
+\r
+\r
+#define _FS_MINIMIZE   0\r
+/* This option defines minimization level to remove some basic API functions.\r
+/\r
+/   0: All basic functions are enabled.\r
+/   1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_truncate() and f_rename()\r
+/      are removed.\r
+/   2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1.\r
+/   3: f_lseek() function is removed in addition to 2. */\r
+\r
+\r
+#define        _USE_STRFUNC    1       /* 0:Disable or 1-2:Enable */\r
+/* This option switches string functions, f_gets(), f_putc(), f_puts() and\r
+/  f_printf().\r
+/\r
+/  0: Disable string functions.\r
+/  1: Enable without LF-CRLF conversion.\r
+/  2: Enable with LF-CRLF conversion. */\r
+\r
+\r
+#define _USE_FIND              0\r
+/* This option switches filtered directory read functions, f_findfirst() and\r
+/  f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */\r
+\r
+\r
+#define        _USE_MKFS               0\r
+/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */\r
+\r
+\r
+#define        _USE_FASTSEEK   0\r
+/* This option switches fast seek function. (0:Disable or 1:Enable) */\r
+\r
+\r
+#define        _USE_EXPAND             0\r
+/* This option switches f_expand function. (0:Disable or 1:Enable) */\r
+\r
+\r
+#define _USE_CHMOD             0\r
+/* This option switches attribute manipulation functions, f_chmod() and f_utime().\r
+/  (0:Disable or 1:Enable) Also _FS_READONLY needs to be 0 to enable this option. */\r
+\r
+\r
+#define _USE_LABEL             0\r
+/* This option switches volume label functions, f_getlabel() and f_setlabel().\r
+/  (0:Disable or 1:Enable) */\r
+\r
+\r
+#define        _USE_FORWARD    0\r
+/* This option switches f_forward() function. (0:Disable or 1:Enable)\r
+/  To enable it, also _FS_TINY need to be 1. */\r
+\r
+\r
+/*---------------------------------------------------------------------------/\r
+/ Locale and Namespace Configurations\r
+/---------------------------------------------------------------------------*/\r
+\r
+#define _CODE_PAGE     932\r
+/* This option specifies the OEM code page to be used on the target system.\r
+/  Incorrect setting of the code page can cause a file open failure.\r
+/\r
+/   1   - ASCII (No extended character. Non-LFN cfg. only)\r
+/   437 - U.S.\r
+/   720 - Arabic\r
+/   737 - Greek\r
+/   771 - KBL\r
+/   775 - Baltic\r
+/   850 - Latin 1\r
+/   852 - Latin 2\r
+/   855 - Cyrillic\r
+/   857 - Turkish\r
+/   860 - Portuguese\r
+/   861 - Icelandic\r
+/   862 - Hebrew\r
+/   863 - Canadian French\r
+/   864 - Arabic\r
+/   865 - Nordic\r
+/   866 - Russian\r
+/   869 - Greek 2\r
+/   932 - Japanese (DBCS)\r
+/   936 - Simplified Chinese (DBCS)\r
+/   949 - Korean (DBCS)\r
+/   950 - Traditional Chinese (DBCS)\r
+*/\r
+\r
+\r
+#define        _USE_LFN        1               /* 0 to 3 */\r
+#define        _MAX_LFN        255\r
+/* The _USE_LFN switches the support of long file name (LFN).\r
+/\r
+/   0: Disable support of LFN. _MAX_LFN has no effect.\r
+/   1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe.\r
+/   2: Enable LFN with dynamic working buffer on the STACK.\r
+/   3: Enable LFN with dynamic working buffer on the HEAP.\r
+/\r
+/  To enable the LFN, Unicode handling functions (option/unicode.c) must be added\r
+/  to the project. The working buffer occupies (_MAX_LFN + 1) * 2 bytes and\r
+/  additional 608 bytes at exFAT enabled. _MAX_LFN can be in range from 12 to 255.\r
+/  It should be set 255 to support full featured LFN operations.\r
+/  When use stack for the working buffer, take care on stack overflow. When use heap\r
+/  memory for the working buffer, memory management functions, ff_memalloc() and\r
+/  ff_memfree(), must be added to the project. */\r
+\r
+\r
+#define        _LFN_UNICODE    0\r
+/* This option switches character encoding on the API. (0:ANSI/OEM or 1:Unicode)\r
+/  To use Unicode string for the path name, enable LFN and set _LFN_UNICODE = 1.\r
+/  This option also affects behavior of string I/O functions. */\r
+\r
+\r
+#define _STRF_ENCODE   3\r
+/* When _LFN_UNICODE == 1, this option selects the character encoding on the file to\r
+/  be read/written via string I/O functions, f_gets(), f_putc(), f_puts and f_printf().\r
+/\r
+/  0: ANSI/OEM\r
+/  1: UTF-16LE\r
+/  2: UTF-16BE\r
+/  3: UTF-8\r
+/\r
+/  This option has no effect when _LFN_UNICODE == 0. */\r
+\r
+\r
+#define _FS_RPATH      0\r
+/* This option configures support of relative path.\r
+/\r
+/   0: Disable relative path and remove related functions.\r
+/   1: Enable relative path. f_chdir() and f_chdrive() are available.\r
+/   2: f_getcwd() function is available in addition to 1.\r
+*/\r
+\r
+\r
+/*---------------------------------------------------------------------------/\r
+/ Drive/Volume Configurations\r
+/---------------------------------------------------------------------------*/\r
+\r
+#define _VOLUMES       4\r
+/* Number of volumes (logical drives) to be used. */\r
+\r
+\r
+#define _STR_VOLUME_ID 0\r
+#define _VOLUME_STRS   "RAM","NAND","CF","SD1","SD2","USB1","USB2","USB3"\r
+/* _STR_VOLUME_ID switches string support of volume ID.\r
+/  When _STR_VOLUME_ID is set to 1, also pre-defined strings can be used as drive\r
+/  number in the path name. _VOLUME_STRS defines the drive ID strings for each\r
+/  logical drives. Number of items must be equal to _VOLUMES. Valid characters for\r
+/  the drive ID strings are: A-Z and 0-9. */\r
+\r
+\r
+#define        _MULTI_PARTITION        1\r
+/* This option switches support of multi-partition on a physical drive.\r
+/  By default (0), each logical drive number is bound to the same physical drive\r
+/  number and only an FAT volume found on the physical drive will be mounted.\r
+/  When multi-partition is enabled (1), each logical drive number can be bound to\r
+/  arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk()\r
+/  funciton will be available. */\r
+\r
+\r
+#define        _MIN_SS         512\r
+#define        _MAX_SS         512\r
+/* These options configure the range of sector size to be supported. (512, 1024,\r
+/  2048 or 4096) Always set both 512 for most systems, all type of memory cards and\r
+/  harddisk. But a larger value may be required for on-board flash memory and some\r
+/  type of optical media. When _MAX_SS is larger than _MIN_SS, FatFs is configured\r
+/  to variable sector size and GET_SECTOR_SIZE command must be implemented to the\r
+/  disk_ioctl() function. */\r
+\r
+\r
+#define        _USE_TRIM       0\r
+/* This option switches support of ATA-TRIM. (0:Disable or 1:Enable)\r
+/  To enable Trim function, also CTRL_TRIM command should be implemented to the\r
+/  disk_ioctl() function. */\r
+\r
+\r
+#define _FS_NOFSINFO   0\r
+/* If you need to know correct free space on the FAT32 volume, set bit 0 of this\r
+/  option, and f_getfree() function at first time after volume mount will force\r
+/  a full FAT scan. Bit 1 controls the use of last allocated cluster number.\r
+/\r
+/  bit0=0: Use free cluster count in the FSINFO if available.\r
+/  bit0=1: Do not trust free cluster count in the FSINFO.\r
+/  bit1=0: Use last allocated cluster number in the FSINFO if available.\r
+/  bit1=1: Do not trust last allocated cluster number in the FSINFO.\r
+*/\r
+\r
+\r
+\r
+/*---------------------------------------------------------------------------/\r
+/ System Configurations\r
+/---------------------------------------------------------------------------*/\r
+\r
+#define        _FS_TINY        0\r
+/* This option switches tiny buffer configuration. (0:Normal or 1:Tiny)\r
+/  At the tiny configuration, size of the file object (FIL) is reduced _MAX_SS bytes.\r
+/  Instead of private sector buffer eliminated from the file object, common sector\r
+/  buffer in the file system object (FATFS) is used for the file data transfer. */\r
+\r
+\r
+#define _FS_EXFAT      0\r
+/* This option switches support of exFAT file system in addition to the traditional\r
+/  FAT file system. (0:Disable or 1:Enable) To enable exFAT, also LFN must be enabled.\r
+/  Note that enabling exFAT discards C89 compatibility. */\r
+\r
+\r
+#define _FS_NORTC      0\r
+#define _NORTC_MON     3\r
+#define _NORTC_MDAY    1\r
+#define _NORTC_YEAR    2016\r
+/* The option _FS_NORTC switches timestamp functiton. If the system does not have\r
+/  any RTC function or valid timestamp is not needed, set _FS_NORTC = 1 to disable\r
+/  the timestamp function. All objects modified by FatFs will have a fixed timestamp\r
+/  defined by _NORTC_MON, _NORTC_MDAY and _NORTC_YEAR in local time.\r
+/  To enable timestamp function (_FS_NORTC = 0), get_fattime() function need to be\r
+/  added to the project to get current time form real-time clock. _NORTC_MON,\r
+/  _NORTC_MDAY and _NORTC_YEAR have no effect. \r
+/  These options have no effect at read-only configuration (_FS_READONLY = 1). */\r
+\r
+\r
+#define        _FS_LOCK        0\r
+/* The option _FS_LOCK switches file lock function to control duplicated file open\r
+/  and illegal operation to open objects. This option must be 0 when _FS_READONLY\r
+/  is 1.\r
+/\r
+/  0:  Disable file lock function. To avoid volume corruption, application program\r
+/      should avoid illegal open, remove and rename to the open objects.\r
+/  >0: Enable file lock function. The value defines how many files/sub-directories\r
+/      can be opened simultaneously under file lock control. Note that the file\r
+/      lock control is independent of re-entrancy. */\r
+\r
+\r
+#define _FS_REENTRANT  0\r
+#define _FS_TIMEOUT            1000\r
+#define        _SYNC_t                 HANDLE\r
+/* The option _FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs\r
+/  module itself. Note that regardless of this option, file access to different\r
+/  volume is always re-entrant and volume control functions, f_mount(), f_mkfs()\r
+/  and f_fdisk() function, are always not re-entrant. Only file/directory access\r
+/  to the same volume is under control of this function.\r
+/\r
+/   0: Disable re-entrancy. _FS_TIMEOUT and _SYNC_t have no effect.\r
+/   1: Enable re-entrancy. Also user provided synchronization handlers,\r
+/      ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj()\r
+/      function, must be added to the project. Samples are available in\r
+/      option/syscall.c.\r
+/\r
+/  The _FS_TIMEOUT defines timeout period in unit of time tick.\r
+/  The _SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*,\r
+/  SemaphoreHandle_t and etc.. A header file for O/S definitions needs to be\r
+/  included somewhere in the scope of ff.c. */\r
+\r
+\r
+/*--- End of configuration options ---*/\r
diff --git a/packages/ti/fs/fatfs/integer.h b/packages/ti/fs/fatfs/integer.h
new file mode 100644 (file)
index 0000000..5c1d106
--- /dev/null
@@ -0,0 +1,42 @@
+/*-------------------------------------------*/\r
+/* Integer type definitions for FatFs module */\r
+/*-------------------------------------------*/\r
+\r
+#ifndef _FF_INTEGER\r
+#define _FF_INTEGER\r
+\r
+#ifdef _WIN32  /* FatFs development platform */\r
+\r
+#include <windows.h>\r
+#include <tchar.h>\r
+typedef uint64_t QWORD;\r
+\r
+\r
+#else                  /* Embedded platform */\r
+\r
+#include <ti/csl/tistdtypes.h>\r
+/* These types must be 16-bit, 32-bit or larger integer */\r
+typedef int32_t INT;\r
+typedef uint32_t UINT;\r
+\r
+/* These types must be 8-bit integer */\r
+typedef char CHAR;\r
+typedef unsigned char UCHAR;\r
+typedef uint8_t BYTE;\r
+\r
+/* These types must be 16-bit integer */\r
+typedef int16_t SHORT;\r
+typedef uint16_t USHORT;\r
+typedef uint16_t WORD;\r
+typedef uint16_t WCHAR;\r
+\r
+/* These types must be 32-bit integer */\r
+typedef int32_t LONG;\r
+typedef uint32_t ULONG;\r
+typedef uint32_t DWORD;\r
+/* This type MUST be 64-bit (Remove this for C89 compatibility) */\r
+typedef unsigned long long QWORD;\r
+\r
+#endif\r
+\r
+#endif\r
diff --git a/packages/ti/fs/fatfs/makefile b/packages/ti/fs/fatfs/makefile
new file mode 100644 (file)
index 0000000..0f8e614
--- /dev/null
@@ -0,0 +1,46 @@
+#
+# Copyright (c) 2016, Texas Instruments Incorporated
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# *  Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+#
+# *  Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# *  Neither the name of Texas Instruments Incorporated nor the names of
+#    its contributors may be used to endorse or promote products derived
+#    from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+ifeq ($(RULES_MAKE), )
+include $(PDK_INSTALL_PATH)/ti/build/Rules.make
+else
+include $(RULES_MAKE)
+endif
+
+COMP = drvfatfs
+
+lib_$(COMP)_BUILD_DEPENDENCY = soc
+
+$(COMP)_DOXYGEN_SUPPORT = yes
+
+include $(PDK_INSTALL_PATH)/ti/build/comp_top.mk
+
diff --git a/packages/ti/fs/fatfs/package.bld b/packages/ti/fs/fatfs/package.bld
new file mode 100644 (file)
index 0000000..c2cfec6
--- /dev/null
@@ -0,0 +1,187 @@
+/******************************************************************************
+ * FILE PURPOSE: Build description for the fatfs Driver
+ ******************************************************************************
+ * FILE NAME: package.bld
+ *
+ * DESCRIPTION: 
+ *  This file contains the build specification and description for the fatfs driver
+ *  
+ *  The file takes the following parameters from the command line through the
+ *  XDCARGS variable.
+ *      XDCARGS[0] = fatfs Driver Install Type
+ *      Valid Values are "TAR" or "SETUP"
+ *      DEFAULT is "SETUP"
+ *
+ *  Example for a valid command:
+ *      xdc XDCARGS="SETUP" release   
+ *
+ * Copyright (C) 2014-2016, Texas Instruments, Inc.
+ *****************************************************************************/
+
+/* List of all subdirectories that combine to make the fatfs Socket Driver Package. */
+var subDirectories = [ "src", "docs", "example" ];
+
+var driverInstallType;
+
+/* Determine if we need to create the InstallJammer Application or not? 
+ * fatfs LLD Deliverables be either of the following formats:
+ *  - TAR Ball Package
+ *  - Setup Executable 
+ * DEFAULT is a SETUP Executable. */
+
+if ((arguments[0] != "TAR") && (arguments[0] != "SETUP"))
+    driverInstallType = "TAR";
+else
+    driverInstallType = arguments[0];
+
+/* Irrespective of the InstallType we always create a TAR Ball Package as a part
+ * of the RTSC Build. Here we determine the name of the TAR Ball Package
+ *  Format is as follows:
+ *      fatfs_<version> */
+var fatfsRTSCFileName = "fatfs" + "_" + LLDPartNumber + "_" +
+                      driverReleaseVersion[0] + "_" +  driverReleaseVersion[1] + "_" +
+                      driverReleaseVersion[2]  + "_" + driverReleaseVersion[3];
+
+/******************************************************************
+ ************************ Release Banner **************************
+ ******************************************************************/
+
+print ("************* fatfs Socket Driver Build Information *************");
+print ("fatfs Socket Driver Install     : " + driverInstallType);
+print ("fatfs Socket Driver LLD Version : " + driverReleaseVersion);
+print ("C66 Tools Directory             : " + c66ToolsBaseDir);
+print ("M4 Tools Directory              : " + m4ToolsBaseDir);
+print ("A15 Tools Directory             : " + a15ToolsBaseDir);
+print ("RTSC File Name                 : " + fatfsRTSCFileName);
+print ("fatfs Socket Driver LLD Path    : " + driverPath);
+if (pOpts == 1) 
+{
+    print ("CC LE opts                      : " + C66LE.ccOpts.prefix);
+    print ("M4 LE opts                      : " + M4LE.ccOpts.prefix);
+    print ("A15 basic opts                  : " + A15LE.ccOpts.prefix);
+}
+print ("****************************************************************");
+
+/* Create the release package for the fatfs LLD */
+Pkg.defaultRelease = Pkg.addRelease (fatfsRTSCFileName, {prefix: "./packages/"});
+
+/* Moving forward we need to set the Archiver of the package to be ZIP. This is currently
+ * not supported in the XDC tools being used. Currenly builds need to be done with the 
+ * following options:-
+ *   xdc MK_FIXLISTOPTS=-t release 
+ * ZIP is a better option as it works natively with INSTALL Jammer and we can remove the
+ * uncompression into a temporary directory. XDC Tools with xdc-rXX support the ZIP archiver. */
+//Pkg.attrs = {archiver : "zip"};
+
+/* Cycle through all the sub-directories and build all the files */
+for (var i = 0; i < subDirectories.length; i++) 
+{
+    /* Load the capsule in the sub directory. */
+    var caps = xdc.loadCapsule (subDirectories[i]+"/Module.xs");
+
+    print ("Building directory " + subDirectories[i]);
+
+    /* Build the capsule. */
+    caps.modBuild();
+
+    /* Package the module.xs files for building via package */
+    Pkg.otherFiles[Pkg.otherFiles.length++] = subDirectories[i]+"/Module.xs";
+}
+
+/* Package the remaining files */
+Pkg.otherFiles[Pkg.otherFiles.length++] = "config.bld";
+Pkg.otherFiles[Pkg.otherFiles.length++] = "config_mk.bld";
+Pkg.otherFiles[Pkg.otherFiles.length++] = "package.bld";
+Pkg.otherFiles[Pkg.otherFiles.length++] = "Settings.xdc";
+Pkg.otherFiles[Pkg.otherFiles.length++] = "Settings.xdc.xdt";
+Pkg.otherFiles[Pkg.otherFiles.length++] = "ff.h";
+Pkg.otherFiles[Pkg.otherFiles.length++] = "ffconf.h";
+Pkg.otherFiles[Pkg.otherFiles.length++] = "integer.h";
+Pkg.otherFiles[Pkg.otherFiles.length++] = "diskio.h";
+Pkg.otherFiles[Pkg.otherFiles.length++] = "FATFS.h";
+Pkg.otherFiles[Pkg.otherFiles.length++] = "FATFSver.h";
+Pkg.otherFiles[Pkg.otherFiles.length++] = "FATFSver.h.xdt";
+Pkg.otherFiles[Pkg.otherFiles.length++] = "docs/Doxyfile";
+Pkg.otherFiles[Pkg.otherFiles.length++] = "docs/doxyfile.xdt";
+Pkg.otherFiles[Pkg.otherFiles.length++] = "build/buildlib.xs";
+Pkg.otherFiles[Pkg.otherFiles.length++] = "makefile";
+Pkg.otherFiles[Pkg.otherFiles.length++] = "build/makefile_indp.mk";
+Pkg.otherFiles[Pkg.otherFiles.length++] = "build/makefile_mp_indp.mk";
+Pkg.otherFiles[Pkg.otherFiles.length++] = "build/makefile_profile_indp.mk";
+Pkg.otherFiles[Pkg.otherFiles.length++] = "src/src_files_common.mk";
+Pkg.otherFiles[Pkg.otherFiles.length++] = "fatfs_component.mk";
+Pkg.otherFiles[Pkg.otherFiles.length++] = "./lib";
+
+/* Generate Users Manual Doxyfile */
+var tplt = xdc.loadTemplate("./docs/doxyfile.xdt");
+tplt.genFile("./docs/Doxyfile",driverReleaseVersion);
+
+/* Generate Settings.xdc */
+var tplt = xdc.loadTemplate("./Settings.xdc.xdt");
+tplt.genFile("./Settings.xdc",driverReleaseVersion);
+
+/* Generate paver.h */
+var tplt = xdc.loadTemplate("./FATFSver.h.xdt");
+tplt.genFile("./FATFSver.h",driverReleaseVersion);
+
+/********************************************************************* 
+ *********************** INSTALL-JAMMER Support **********************
+ * In order to create the InstallJammer Application; we need to UNTAR
+ * the package into a temporary directory. This is required because 
+ * currently the InstallJammer does not support the TAR Files and thus
+ * creating an UNTAR of the file. So to work-around the problem we will
+ * do the following in the EPILOGUE Section:-
+ *  (a) Create a temporary directory called 'tmp'
+ *  (b) UNTAR the package into 'tmp'
+ *  (c) Run the INSTALL Jammer on 'tmp'
+ *  (d) Remove the 'tmp' directory.
+ *
+ * This can be done only after the 'release' package has been created.
+ * Thus all of this work is being done in the EPILOGUE.
+ *********************************************************************/
+if (driverInstallType == "SETUP")
+{
+    /* Create the Install Jammer Version Variable. This is used inside the 
+     * MPI File to create the Final executable. 
+     *  The format supported is as follows:-
+     *   - setupwin32_fatfs_<device>_<version>.exe
+     */
+    var InstallJammerVersion = "-DVersion " + LLDPartNumber + "_" +
+                               driverReleaseVersion[0] + "_" + driverReleaseVersion[1] + "_" +
+                               driverReleaseVersion[2] + "_" + driverReleaseVersion[3];
+
+    /* This is the location where the tmp directory is located; this is used as 
+     * the input directory for the Install Jammer. */ 
+    var PackageBaseDir = " -DPackageBaseDir " + driverPath + "./tmp";
+
+    /* This is the location where the fatfs LLD will be installed by default. */
+    var WinInstallDir = " -DWinInstallDir C:/Program Files/Texas Instruments/fatfs" + "_" +
+                            LLDPartNumber + "_" +
+                            driverReleaseVersion[0] + "_" +  driverReleaseVersion[1] + "_" +
+                            driverReleaseVersion[2]  + "_" + driverReleaseVersion[3];
+
+    /* Create the actual EPILOGUE Section for the INSTALLER */
+    Pkg.makeEpilogue += "release: install_application\n";
+    Pkg.makeEpilogue += "install_application:\n";
+    Pkg.makeEpilogue += "\t @echo -------------------------------------------------------\n";
+    Pkg.makeEpilogue += "\t @echo Creating the Install\n";
+    Pkg.makeEpilogue += "\t @echo -------------------------------------------------------\n";
+    Pkg.makeEpilogue += "\t -$(MKDIR) tmp\n";
+    Pkg.makeEpilogue += "\t -$(MKDIR) tmp/packages\n";
+    Pkg.makeEpilogue += "\t -$(MKDIR) tmp/eclipse\n";
+    Pkg.makeEpilogue += "\t -$(CP) -R eclipse tmp\n";
+    Pkg.makeEpilogue += "\t tar -xf ./packages/" + fatfsRTSCFileName + ".tar" + " -Ctmp/packages \n";
+    Pkg.makeEpilogue += "\t installjammer " + InstallJammerVersion + PackageBaseDir + WinInstallDir + 
+                        " --output-dir packages/ --build install/fatfslld.mpi\n";
+    Pkg.makeEpilogue += "\t -$(RMDIR) /S /Q tmp\n\n";
+
+    /* We need to clean after ourselves; extend the 'clean' target to take care of this. */
+    Pkg.makeEpilogue += "clean::\n";
+    Pkg.makeEpilogue += "\t -$(RM) docs/Doxyfile Settings.xdc FATFSver.h\n";
+    Pkg.makeEpilogue += "\t -$(RM) makefile\n";
+    Pkg.makeEpilogue += "\t -$(RMDIR) docs/doxygen\n";
+    Pkg.makeEpilogue += "\t $(RM) packages/*.exe\n";
+    Pkg.makeEpilogue += "\t $(RM) packages/*.bin\n";
+    Pkg.makeEpilogue += "\t -$(RMDIR) eclipse\n\n";
+}
+    
diff --git a/packages/ti/fs/fatfs/package.xdc b/packages/ti/fs/fatfs/package.xdc
new file mode 100644 (file)
index 0000000..e8e1b1b
--- /dev/null
@@ -0,0 +1,16 @@
+/******************************************************************************\r
+ * FILE PURPOSE: Package specification file \r
+ ******************************************************************************\r
+ * FILE NAME: package.xdc\r
+ *\r
+ * DESCRIPTION: \r
+ *  This file contains the package specification for the fatfs Driver\r
+ *\r
+ * Copyright (C) 2018-2019, Texas Instruments, Inc.\r
+ *****************************************************************************/\r
+\r
+\r
+package ti.fs.fatfs[1, 0, 0, 15] {\r
+    module Settings;\r
+}\r
+\r
diff --git a/packages/ti/fs/fatfs/package.xs b/packages/ti/fs/fatfs/package.xs
new file mode 100644 (file)
index 0000000..8979444
--- /dev/null
@@ -0,0 +1,88 @@
+/*\r
+ *  ======== package.xs ========\r
+ *\r
+ */\r
+\r
+\r
+/*\r
+ *  ======== Package.getLibs ========\r
+ *  This function is called when a program's configuration files are\r
+ *  being generated and it returns the name of a library appropriate\r
+ *  for the program's configuration.\r
+ */\r
+\r
+function getLibs(prog)\r
+{\r
+    var suffix = prog.build.target.suffix;\r
+\r
+    var name = this.$name + ".a" + suffix;\r
+\r
+    /* Read LIBDIR variable */\r
+    var lib = java.lang.System.getenv("LIBDIR");\r
+\r
+    /* If NULL, default to "lib" folder */\r
+    if (lib == null)\r
+    {\r
+        lib = "./lib";\r
+    } else {\r
+        print ("\tSystem environment LIBDIR variable defined : " + lib);\r
+    }\r
+\r
+    /* Get target folder, if applicable */\r
+    if ( java.lang.String(suffix).contains('66') )\r
+        lib = lib + "/c66";\r
+    else if ( java.lang.String(suffix).contains('674') )\r
+        lib = lib + "/c674";\r
+    else if (java.lang.String(suffix).contains('a15') )\r
+        lib = lib + "/a15";\r
+    else if (java.lang.String(suffix).contains('m4') )\r
+        lib = lib + "/m4";\r
+    else if (java.lang.String(suffix).contains('a9') )\r
+        lib = lib + "/a9";\r
+    else if (java.lang.String(suffix).contains('e9') )\r
+        lib = lib + "/arm9";\r
+    else if (java.lang.String(suffix).contains('a8') )\r
+        lib = lib + "/a8";        \r
+    else if (java.lang.String(suffix).contains('a53'))\r
+           lib = lib + "/a53";        \r
+       else if (java.lang.String(suffix).contains('r5f'))\r
+           lib = lib + "/r5f";\r
+    else\r
+        throw new Error("\tUnknown target for: " + this.packageBase + lib);\r
+    \r
+\r
+    var libProfiles = ["debug", "release"];\r
+    /* get the configured library profile */\r
+    for each(var profile in libProfiles)\r
+    {\r
+        if (this.Settings.libProfile.equals(profile))\r
+        {\r
+            lib = lib + "/" + profile;\r
+            break;\r
+        }\r
+    }  \r
+\r
+    /* Get library name with path */\r
+    lib = lib + "/" + name;\r
+    if (java.io.File(this.packageBase + lib).exists()) {\r
+       return lib;\r
+    }\r
+\r
+    /* Could not find any library, throw exception */\r
+    throw new Error("\tLibrary not found: " + this.packageBase + lib);\r
+}\r
+\r
+function init() {\r
+xdc.loadPackage("ti.osal");\r
+xdc.loadPackage("ti.csl");\r
+}\r
+\r
+/*\r
+ *  ======== package.close ========\r
+ */\r
+function close()\r
+{    \r
+    if (xdc.om.$name != 'cfg') {\r
+        return;\r
+    }\r
+}\r
diff --git a/packages/ti/fs/fatfs/src/FATFS_drv.c b/packages/ti/fs/fatfs/src/FATFS_drv.c
new file mode 100644 (file)
index 0000000..28ed261
--- /dev/null
@@ -0,0 +1,790 @@
+/**
+ *  \file   FATFS_drv.c
+ *
+ *  \brief  SD Driver high level APIs implementation.
+ *
+ *   This file contains the driver APIs for SD controller.
+ */
+
+/*
+ * Copyright (C) 2014 - 2018 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of Texas Instruments Incorporated nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <ti/fs/fatfs/src/FATFS_drv_log.h>
+#include <ti/fs/fatfs/FATFS.h>
+#include <ti/fs/fatfs/src/FATFS_osal.h>
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define DRIVE_NOT_MOUNTED           (~((uint32_t)0U))
+
+/* Table to map multi-partition with multi-storage device*/
+PARTITION VolToPart[FATFS_NUM_OF_PARTITIONS] = {
+                          {FATFS_DFLT_VOLUME_PD /*pd */,FATFS_DFLT_VOLUME_PT /* pt */},
+                          {FATFS_DFLT_VOLUME_PD /*pd */,FATFS_DFLT_VOLUME_PT /* pt */},
+                          {FATFS_DFLT_VOLUME_PD /*pd */,FATFS_DFLT_VOLUME_PT /* pt */},
+                          {FATFS_DFLT_VOLUME_PD /*pd */,FATFS_DFLT_VOLUME_PT /* pt */},
+};
+
+/* Function prototypes */
+
+/* FatFs disk I/O functions */
+static DSTATUS  FATFS_diskInitialize(BYTE drv);
+static DRESULT  FATFS_diskIOctrl(BYTE drv, BYTE ctrl, void *buf);
+static DRESULT  FATFS_diskRead(BYTE drv, BYTE *buf, DWORD sector, BYTE count);
+static DSTATUS  FATFS_diskStatus(BYTE drv);
+static DRESULT  FATFS_diskWrite(BYTE drv, const BYTE *buf, DWORD sector,
+                                BYTE count);
+static FATFS_Error FATFS_readBootSector(BYTE drv);
+static int32_t FATFS_getFreeVolIndex();
+
+/* Externs */
+extern const FATFSConfigList FATFS_config;
+
+/* Used to check status and initialization */
+static int32_t FATFS_count = -1;
+
+/* Used to check the status of the VolToPart table availability */
+static int32_t FATFS_volumeStatus = 0;
+
+/* Default SD parameters structure */
+const FATFS_ConfigParams FATFS_defaultParams = {
+    NULL,
+    NULL,
+    NULL,                /* Custom argument used by driver implementation */
+    NULL
+};
+
+/*
+ *  ======== FATFS_close ========
+ */
+FATFS_Error FATFS_close(FATFS_Handle handle)
+{
+    DRESULT                dresult;
+    FRESULT                fresult;
+    uint32_t               volIndex = 0;
+    FATFS_Object          *object = NULL;
+#ifdef LOG_EN
+    FATFS_HwAttrs const   *hwAttrs = NULL;
+#endif
+    TCHAR drive_path[5];
+    FATFS_Error ret;
+    /* Input parameter validation */
+    if(handle != NULL)
+    {
+
+    /* Get the pointer to the object and hwAttrs */
+    object = ((FATFS_Config *) handle)->object;
+#ifdef LOG_EN
+    hwAttrs = ((FATFS_Config *) handle)->hwAttrs;
+#endif
+
+    /* Clear Driver handle only when it is opened */
+    if(1 == object->isOpen)
+    {
+        ((FATFS_Config *) handle)->drvFxnTablePtr->closeDrvFxn(object->drvHandle);
+    }
+
+    /*Reset */
+    for(volIndex = 0; volIndex < FATFS_NUM_OF_PARTITIONS; volIndex++)
+    {
+        if(VolToPart[volIndex].pd == object->driveNumber)
+        {
+            /* Unmount the FatFs drive partition(s)*/
+            snprintf(drive_path,sizeof(drive_path),"%d:",(int)volIndex);
+            /* The FATFS drive partition will be unmounted based on the first argument of the
+             * of f_mount function and the third argument as not mount.
+             */
+            fresult = f_mount(NULL,drive_path,FATFS_MOUNT_LATER);
+
+            if (fresult != FR_OK) {
+#ifdef LOG_EN
+                Log_print2(Diags_USER1,
+                    "SDFATFS:(%p) Could not unmount FatFs volume @ drive number %d @ partition %d",
+                    hwAttrs->baseAddr,
+                    object->driveNumber,
+                    volIndex);
+#endif
+            }
+            else
+            {
+                /*Reset the VolToPart index to default value */
+                VolToPart[volIndex].pd = FATFS_DFLT_VOLUME_PD;
+                VolToPart[volIndex].pt = FATFS_DFLT_VOLUME_PT;
+            }
+        }
+    }
+
+    /* Set Volume status for availability */
+    FATFS_volumeStatus = FATFS_VOLUME_DISK_AVL;
+
+    /* Unregister the disk_*() functions */
+    dresult = disk_unregister(object->driveNumber);
+    if (dresult != RES_OK) {
+#ifdef LOG_EN
+        Log_print2(Diags_USER1,
+                   "SDFATFS:(%p) Error unregistering disk functions @ drive number %d",
+                   hwAttrs->baseAddr,
+                   object->driveNumber);
+#endif
+    }
+
+#ifdef LOG_EN
+    Log_print1(Diags_USER1, "SDFATFS:(%p) closed", hwAttrs->baseAddr);
+#endif
+
+    object->driveNumber = DRIVE_NOT_MOUNTED;
+
+    ((FATFS_Config *) handle)->object->isOpen = 0;
+    ret = FATFS_OK;
+    } 
+    else
+    {
+               ret = FATFS_ERR;
+       }
+    return (ret);
+}
+
+/*
+ *  ======== FATFS_control ========
+ */
+FATFS_Error FATFS_control(FATFS_Handle handle, uint32_t cmd, void *arg); /*for misra warnings*/
+FATFS_Error FATFS_control(FATFS_Handle handle, uint32_t cmd, void *arg)
+{
+   (void)handle;
+   (void)cmd;
+   (void)arg;
+       /* No implementation yet */
+       return (FATFS_ERR);
+}
+
+/*
+ *  ======== FATFS_init ========
+ */
+FATFS_Error FATFS_init(void)
+{
+    if (FATFS_count == -1) {
+        /* Call each driver's init function */
+        for (FATFS_count = 0; FATFS_config[FATFS_count].object != NULL; FATFS_count++) {
+            /* Mark the object as available */
+            FATFS_config[FATFS_count].object->isOpen = 0;
+            FATFS_config[FATFS_count].object->driveNumber = DRIVE_NOT_MOUNTED;
+            FATFS_config[FATFS_count].object->diskState = STA_NOINIT;
+        }
+    }
+   
+    return (FATFS_OK);
+}
+
+/*
+ *  ======== FATFS_open ========
+ */
+FATFS_Error FATFS_open(uint32_t index,
+                       FATFS_Params  params,
+                       FATFS_Handle *handle)
+{
+    FATFS_Error                 ret = FATFS_ERR;
+    DRESULT                     dresult;
+    FRESULT                     fresult;
+    FATFS_Object               *object = NULL;
+    FATFS_HwAttrs const        *hwAttrs = NULL;
+    TCHAR drive_path[5];
+    int32_t                    volIndex = 0;
+       
+    /* Input parameter validation */
+    FATFS_osalAssert((FATFS_Handle)&(FATFS_config[index]) == NULL);
+
+    /*Verify there is free index available in VolToPart for mapping this disk partitions */
+    volIndex = FATFS_getFreeVolIndex();
+    if(volIndex < 0)
+    {
+        return FATFS_VOLUME_FULL_ERR;
+    }
+
+    /* Get handle for this driver instance */
+    *handle = (FATFS_Config *)&(FATFS_config[index]);
+
+    /* Get the pointer to the object and hwAttrs */
+    object = ((FATFS_Config *)&(FATFS_config[index]))->object;
+    hwAttrs = ((FATFS_Config *)&(FATFS_config[index]))->hwAttrs;
+
+    /* Store the FATFS parameters */
+    if (params == NULL) {
+        /* No params passed in, so use the defaults */
+        FATFS_Params_init(&(object->FATFSConfigParams));
+    }
+    else {
+        /* Copy the params contents */
+        object->FATFSConfigParams.drvHandle = ((FATFS_ConfigParams *) params)->drvHandle;
+        object->FATFSConfigParams.drvParams = ((FATFS_ConfigParams *) params)->drvParams;
+        object->FATFSConfigParams.drvFxnTablePtr = ((FATFS_ConfigParams *) params)->drvFxnTablePtr;
+        object->FATFSConfigParams.custom = ((FATFS_ConfigParams *) params)->custom;
+    }
+
+    if(0 != object->isOpen)
+    {
+        ret = FATFS_ERR;
+    }
+    else
+    {
+        object->drvInst = hwAttrs->drvInst;
+        object->driveNumber = index;
+        ret = FATFS_OK;
+    }
+
+    if(FATFS_OK == ret)
+    {
+        /* Register the new disk_*() functions */
+        dresult = disk_register(object->driveNumber,
+                                FATFS_diskInitialize,
+                                FATFS_diskStatus,
+                                FATFS_diskRead,
+                                FATFS_diskWrite,
+                                FATFS_diskIOctrl);
+
+        /* Check for drive errors */
+        if (dresult != RES_OK) {
+#ifdef LOG_EN
+            FATFS_drv_log(Diags_USER1, "SDFATFS:(%p) disk functions not registered",
+                        hwAttrs->baseAddr);
+#endif
+            FATFS_close(*handle);
+
+            /*Restore VolToPart to remove the entry*/
+            VolToPart[volIndex].pt = FATFS_DFLT_VOLUME_PD;
+            VolToPart[volIndex].pd = FATFS_DFLT_VOLUME_PT;
+            ret = FATFS_ERR;
+        }
+        else
+        {
+            /*Add a new entry for the first default partition*/
+            VolToPart[volIndex].pd = object->driveNumber;
+        }
+
+    }
+
+    if(FATFS_OK == ret)
+    {
+        /*
+         * Register the filesystem with FatFs.
+         */
+        {
+            snprintf(drive_path,sizeof(drive_path),"%d:",(int)volIndex);
+            /*Mount First partition of device to read the MBR*/
+            fresult = f_mount(&(object->filesystem[0]),drive_path,FATFS_MOUNT_IMMEDIATE);
+
+               if (fresult != FR_OK) {
+#ifdef LOG_EN
+                FATFS_drv_log(Diags_USER1, "SDFATFS:(%p) drive %d not mounted",
+                        hwAttrs->baseAddr, object->driveNumber);
+#endif
+                FATFS_close(*handle);
+
+                /*Restore VolToPart to remove the entry*/
+                VolToPart[volIndex].pt = FATFS_DFLT_VOLUME_PD;
+                VolToPart[volIndex].pd = FATFS_DFLT_VOLUME_PT;
+
+                if(FATFS_volumeStatus == FATFS_VOLUME_FULL_ERR)
+                {
+                    ret = FATFS_VOLUME_FULL_ERR;
+                }
+                else
+                {
+                    ret = FATFS_ERR;
+                }
+            }
+
+        }
+    }
+
+    if(FATFS_OK == ret)
+    {
+        object->isOpen = 1;
+
+#ifdef LOG_EN
+        FATFS_drv_log(Diags_USER1, "SDFATFS:(%p) opened", hwAttrs->baseAddr);
+#endif
+    }
+
+    if((FATFS_OK != ret) && (0 != object->isOpen))
+    {
+        ret = FATFS_OK;
+    }
+
+    return (ret);
+}
+
+/*
+ *  ======== FATFS_Params_init =======
+ */
+FATFS_Error FATFS_Params_init(FATFS_Params params)
+{
+    FATFS_Error ret;
+    /* Input parameter validation */
+    if(params != NULL)
+    {
+      ((FATFS_ConfigParams *) params)->drvHandle = FATFS_defaultParams.drvHandle;
+      ((FATFS_ConfigParams *) params)->drvParams = FATFS_defaultParams.drvParams;
+      ((FATFS_ConfigParams *) params)->drvFxnTablePtr = FATFS_defaultParams.drvFxnTablePtr;
+      ((FATFS_ConfigParams *) params)->custom = FATFS_defaultParams.custom;
+      ret = FATFS_OK;
+    }
+    else
+    {
+               ret = FATFS_ERR;
+       }
+    return (ret);
+}
+
+/*
+ *  ======== FATFS_diskInitialize ========
+ *  Function to initialize the SD Card.  This function is called by the FatFs
+ *  module and must not be called by the application!
+ *
+ *  @param  drv         Drive Number
+ */
+static DSTATUS FATFS_diskInitialize(BYTE drv)
+{
+    uint32_t              res = STA_NOINIT;
+    int32_t               readSectorStatus = FATFS_OK;
+    FATFS_Object         *object = NULL;
+#ifdef LOG_EN
+    FATFS_HwAttrs const  *hwAttrs = NULL;
+#endif
+    FATFS_Handle          handle;
+    FATFS_DrvHandle       drvHandle = NULL;
+
+    /* Get handle for this driver instance */
+    handle = (FATFS_Handle)&(FATFS_config[drv]);
+
+    /* Get the pointer to the object and hwAttrs */
+    object = ((FATFS_Config *) handle)->object;
+       
+    if(object == NULL)
+    {
+        return STA_NOINIT;
+    }
+
+    if (object->isOpen)
+    {
+        return RES_OK;
+    }
+
+#ifdef LOG_EN
+    hwAttrs = ((FATFS_Config *) handle)->hwAttrs;
+#endif
+
+    ((FATFS_Config *) handle)->drvFxnTablePtr->initDrvFxn();
+
+    if (FATFS_OK != ((FATFS_Config *) handle)->drvFxnTablePtr->openDrvFxn(object->drvInst, object->FATFSConfigParams.drvParams, &drvHandle))
+    {
+#ifdef LOG_EN
+        FATFS_drv_log("\r\nCard Init Failed \r\n");
+#endif
+    }
+    else
+    {
+        object->drvHandle = drvHandle;
+        object->diskState &= ~STA_NOINIT;
+        res = RES_OK;
+    }
+
+    readSectorStatus = FATFS_readBootSector(drv);
+    if (FATFS_OK != readSectorStatus && FATFS_VOLUME_FULL_ERR != readSectorStatus)
+    {
+#ifdef LOG_EN
+        FATFS_drv_log("\r\nReading MBR failed \r\n");
+#endif
+        res = STA_NOINIT;
+
+    }
+    else
+    {
+        if (FATFS_VOLUME_FULL_ERR == readSectorStatus)
+        {
+            /* To indicate the the FATFS_open function about the VolToPart table full */
+            FATFS_volumeStatus = FATFS_VOLUME_FULL_ERR;
+        }
+        res = RES_OK;
+    }
+
+    return ((DSTATUS)res);
+}
+
+/*
+ *  ======== FATFS_diskIOctrl ========
+ *  Function to perform specifed disk operations. This function is called by the
+ *  FatFs module and must not be called by the application!
+ *
+ *  @param  drv         Drive Number
+ *
+ *  @param  ctrl        Control code
+ *
+ *  @param  buf         Buffer to send/receive control data
+ */
+static DRESULT FATFS_diskIOctrl(BYTE drv, BYTE ctrl, void *buf)
+{
+    DRESULT               res = RES_ERROR;
+    FATFS_Handle          handle;
+    FATFS_Object         *object = NULL;
+#ifdef LOG_EN
+    FATFS_HwAttrs const  *hwAttrs = NULL;
+#endif
+
+    /* Get handle for this driver instance */
+    handle = (FATFS_Handle)&(FATFS_config[drv]);
+
+    /* Get the pointer to the object and hwAttrs */
+    object = ((FATFS_Config *) handle)->object;
+#ifdef LOG_EN
+    hwAttrs = ((FATFS_Config *) handle)->hwAttrs;
+#endif
+
+    if (object->diskState & STA_NOINIT) {
+#ifdef LOG_EN
+        FATFS_drv_log(Diags_USER1, "SDFATFS:(%p) disk IO control: disk not initialized",
+                    hwAttrs->baseAddr);
+#endif
+        res = RES_NOTRDY;
+    }
+
+    res = RES_OK;
+
+    return (res);
+}
+
+/*
+ *  ======== FATFS_diskRead ========
+ *  Function to perform a disk read from the SDCard. This function is called by
+ *  the FatFs module and must not be called by the application!
+ *
+ *  @param  drv         Drive Number
+ *
+ *  @param  buf         Pointer to a buffer on which to store data
+ *
+ *  @param  sector      Starting sector number (LBA)
+ *
+ *  @param  count       Sector count (1...255)
+ */
+static DRESULT FATFS_diskRead(BYTE drv, BYTE *buf, DWORD sector, BYTE count)
+{
+    DRESULT               res = RES_ERROR;
+    FATFS_Handle          handle;
+    FATFS_Object          *object = NULL;
+#ifdef LOG_EN
+    FATFS_HwAttrs const   *hwAttrs = NULL;
+#endif
+
+    /* Get handle for this driver instance */
+    handle = (FATFS_Handle)&(FATFS_config[drv]);
+
+    /* Get the pointer to the object and hwAttrs */
+    object = ((FATFS_Config *) handle)->object;
+#ifdef LOG_EN
+    hwAttrs = ((FATFS_Config *) handle)->hwAttrs;
+#endif
+
+    if (count == 0U) {
+#ifdef LOG_EN
+        FATFS_drv_log(Diags_USER1, "SDFATFS:(%p) disk read: 0 sectors to read",
+                                 hwAttrs->baseAddr);
+#endif
+        res= RES_PARERR;
+    }
+    else if (object->diskState & STA_NOINIT) {
+#ifdef LOG_EN
+        FATFS_drv_log(Diags_USER1, "SDFATFS:(%p) disk read: disk not initialized",
+                    hwAttrs->baseAddr);
+#endif
+        res = RES_NOTRDY;
+    }
+    /* READ BLOCK */
+    else 
+    {
+        if (FATFS_OK == ((FATFS_Config *) handle)->drvFxnTablePtr->readDrvFxn(object->drvHandle, buf, sector, count))
+        {
+            res = RES_OK;
+        }
+    }
+
+    return res;
+}
+
+/*
+ *  ======== FATFS_diskStatus ========
+ *  Function to return the current disk status. This function is called by
+ *  the FatFs module and must not be called by the application!
+ *
+ *  @param(drv)         Drive Number
+ */
+static DSTATUS FATFS_diskStatus(BYTE drv)
+{
+    DRESULT               res = RES_ERROR;
+    FATFS_Handle          handle;
+    FATFS_Object         *object = NULL;
+#ifdef LOG_EN
+    FATFS_HwAttrs const  *hwAttrs = NULL;
+#endif
+
+    /* Get handle for this driver instance */
+    handle = (FATFS_Handle)&(FATFS_config[drv]);
+
+    /* Get the pointer to the object and hwAttrs */
+    object = ((FATFS_Config *) handle)->object;
+#ifdef LOG_EN
+    hwAttrs = ((FATFS_Config *) handle)->hwAttrs;
+#endif
+
+    /* Use Diags_USER1 to reduce noise in the logs */
+#ifdef LOG_EN
+    FATFS_drv_log(Diags_USER1, "SDFATFS:(%p) disk status: diskState: %d",
+               (hwAttrs->baseAddr, object->diskState);
+#endif
+    res = (DRESULT) object->diskState;
+
+    return res;
+}
+
+/*
+ *  ======== FATFS_diskWrite ========
+ *  Function to perform a disk write from the SDCard. This function is called by
+ *  the FatFs module and must not be called by the application!
+ *
+ *  @param  drv         Drive Number
+ *
+ *  @param  buf         Pointer to a buffer from which to read data
+ *
+ *  @param  sector      Starting sector number (LBA)
+ *
+ *  @param  count       Sector count (1...255)
+ */
+static DRESULT FATFS_diskWrite(BYTE drv, const BYTE *buf,
+                            DWORD sector, BYTE count)
+{
+    DRESULT                res = RES_ERROR;
+    FATFS_Handle           handle;
+    FATFS_Object          *object = NULL;
+#ifdef LOG_EN
+    FATFS_HwAttrs const   *hwAttrs = NULL;
+#endif
+
+    /* Get handle for this driver instance */
+    handle = (FATFS_Handle)&(FATFS_config[drv]);
+
+    /* Get the pointer to the object and hwAttrs */
+    object = ((FATFS_Config *) handle)->object;
+#ifdef LOG_EN
+    hwAttrs = ((FATFS_Config *) handle)->hwAttrs;
+#endif
+
+    if (count == 0U) {
+#ifdef LOG_EN
+        FATFS_drv_log(Diags_USER1, "SDFATFS:(%p) disk write: 0 sectors to write",
+                                 hwAttrs->baseAddr);
+#endif
+        res = RES_PARERR;
+    }
+    else
+    {
+        if (object->diskState & STA_NOINIT) {
+    #ifdef LOG_EN
+            FATFS_drv_log(Diags_USER1, "SDFATFS:(%p) disk write: disk not initialized",
+                        hwAttrs->baseAddr);
+    #endif
+            res = RES_NOTRDY;
+        }
+        else if (object->diskState & STA_PROTECT) {
+    #ifdef LOG_EN
+            FATFS_drv_log(Diags_USER1, "SDFATFS:(%p) disk write: disk protected",
+                        hwAttrs->baseAddr);
+    #endif
+            res = RES_WRPRT;
+        }
+        /* WRITE BLOCK */
+        else
+        {
+            if(FATFS_OK == ((FATFS_Config *) handle)->drvFxnTablePtr->writeDrvFxn(object->drvHandle,(BYTE*) buf, sector, count))
+            {
+                res = RES_OK;
+            }
+        }
+    }
+    return res;
+}
+
+/*
+ *  ======== FATFS_readBootSector ========
+ *  Function to perform a disk read from the storage device to read MBR.
+ *  This function is called by the FatFs diskInitialize and must not be
+ *  called by the application!
+ *
+ *  @param  drv         Drive Number
+ *
+*/
+#define CACHE_LINE_SIZE (128)
+
+static FATFS_Error FATFS_readBootSector(BYTE drv)
+{
+    BYTE          *pt;
+    uint32_t      ptOffset, ptIndex =1;
+       int32_t       index = 0;
+    FRESULT       fresult;
+    FATFS_Error   res = FATFS_OK;
+
+    TCHAR         drive_path[5];
+    DWORD         sector =0;
+    FATFS_Object  *object = NULL;
+
+    BYTE          bufferAlloc[_MAX_SS + CACHE_LINE_SIZE-1];
+    BYTE*         buffer;
+    uintptr_t     bufAddr;
+    uint32_t      offset;
+
+    /* allign buffer to cache-line size manually since some compilers don't 
+       support alignment in stack variables */
+    bufAddr = (uintptr_t)&bufferAlloc;
+    offset = (CACHE_LINE_SIZE - (bufAddr & (CACHE_LINE_SIZE-1)));
+    if (offset == CACHE_LINE_SIZE) 
+    {
+        offset = 0;
+    }
+    buffer = &bufferAlloc[offset];
+
+    object = ((FATFS_Config *)&(FATFS_config[drv]))->object;
+
+    /*Read MBR from the given storage device*/
+    if ((FATFS_diskRead(drv,buffer,sector,1))!= RES_OK)
+    {
+        return FR_DISK_ERR;
+    }
+
+    index = FATFS_getFreeVolIndex();
+    if(index < 0)
+    {
+        return FATFS_VOLUME_FULL_ERR;
+    }
+    pt = buffer;
+
+    /* By default assume the card is a valid MBR + BR card */
+    VolToPart[index].pt = 1;
+
+    /* Following is the check to determine a storage card which is a valid MBR
+     * with Boot Record card or a card with Boot Record only.
+     */
+
+    /* Determines the card is formatted following the MS DOS standard format */
+    if((pt[FATFS_JUMP_BOOT_SEC_OFFSET] == FATFS_JUMP_BOOT_SEC_JMP_INS_0) || \
+                    (pt[FATFS_JUMP_BOOT_SEC_OFFSET] == FATFS_JUMP_BOOT_SEC_JMP_INS_1))
+    {
+        /* Verifies the media type value has the legal values for either removable or
+         * non removable device types.
+         * Only a card with boot record can be a MS DOS based formatted and has a valid media
+         * type value
+         */
+        if((pt[FATFS_MEDIA_BOOT_SEC_OFFSET] == FATFS_BOOT_MEDIA_TYPE_NON_REM) || \
+             ((pt[FATFS_MEDIA_BOOT_SEC_OFFSET] >= FATFS_BOOT_MEDIA_REM_TYPE_MIN) && \
+                  (pt[FATFS_MEDIA_BOOT_SEC_OFFSET] <= FATFS_BOOT_MEDIA_REM_TYPE_MAX)))
+        {
+            VolToPart[index].pt = 0;
+        }
+    }
+
+    /* Parse the MBR to find the number of partition that are available
+     * and map each partition with its instance/index number.
+     */
+    for (ptOffset = 1; ptOffset < FATFS_NUM_OF_PARTITIONS; ptOffset++)
+    {
+        /*Obtain Free index in VolToPart */
+        index = FATFS_getFreeVolIndex();
+
+        /*Read the partition entry indexed by ptOffset in MBR */
+        pt = buffer + FATFS_MBR_TABLE + ptOffset * FATFS_SZ_PTE;
+        if(pt[FATFS_MBR_PT_TYPE_OFFSET])
+        {
+            if(index >= 0)
+            {
+                /*Mount the partition(s) */
+                snprintf(drive_path,sizeof(drive_path),"%d:",(int)index);
+                fresult = f_mount(&(object->filesystem[ptIndex]),drive_path,FATFS_MOUNT_LATER);
+
+                if(fresult != FR_OK && fresult != FR_NO_FILESYSTEM) {
+#ifdef LOG_EN
+                    FATFS_drv_log(Diags_USER1, "SDFATFS: drive %d not mounted",
+                            object->driveNumber);
+#endif
+                }
+                else
+                {
+                    if(fresult != FR_NO_FILESYSTEM) {
+                        VolToPart[index].pt = ++ptIndex;
+                        VolToPart[index].pd = object->driveNumber;
+                    }
+                }
+            }
+            else
+            {
+                res = FATFS_VOLUME_FULL_ERR;
+                break;
+            }
+        }
+        else
+        {
+            /*Stop looking for next partition as this will be the last partition of the disk */
+            break;
+        }
+    }
+
+    return res;
+}
+
+/*
+ *  ======== FATFS_getFreeVolIndex ========
+ *  Function is to find a free space in VolToPart structure.
+ *
+*/
+static int32_t FATFS_getFreeVolIndex()
+{
+    uint32_t index = 0;
+
+    for (index = 0; index < FATFS_NUM_OF_PARTITIONS; index++)
+    {
+        if(VolToPart[index].pt == FATFS_DFLT_VOLUME_PD)
+        {
+            return index;
+        }
+    }
+
+    return FATFS_VOLUME_FULL_ERR;
+}
diff --git a/packages/ti/fs/fatfs/src/FATFS_drv_log.h b/packages/ti/fs/fatfs/src/FATFS_drv_log.h
new file mode 100644 (file)
index 0000000..09f1644
--- /dev/null
@@ -0,0 +1,76 @@
+/**
+ *  \file   FATFS_drv_log.h
+ *
+ *  \brief  This file contains the prototypes for the log print functions. By
+            default the prints will be directed to serial console using UART.
+ *
+ */
+
+/*
+ * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of Texas Instruments Incorporated nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef FATFS_DRV_LOG_H
+#define FATFS_DRV_LOG_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdio.h>
+
+/**********************************************************************
+ ************************** Global Variables **************************
+ **********************************************************************/
+
+/**********************************************************************
+ ************************** Macros ************************************
+ **********************************************************************/
+/* Enable the below macro to have prints on the IO Console */
+
+#ifdef CIO_DRV_CONSOLE
+#define FATFS_drv_log            printf
+#define FATFS_drv_log1           printf
+#define FATFS_drv_log2           printf
+#define FATFS_drv_log3           printf
+#else
+#define FATFS_drv_log(x)
+#define FATFS_drv_log1(x,y)
+#define FATFS_drv_log2(x,y,z)
+#define FATFS_drv_log3(x,y,z,l)
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* FATFS_DRV_LOG_H */
diff --git a/packages/ti/fs/fatfs/src/FATFS_osal.h b/packages/ti/fs/fatfs/src/FATFS_osal.h
new file mode 100644 (file)
index 0000000..a4d16dc
--- /dev/null
@@ -0,0 +1,300 @@
+/**
+ *   @file  FATFS_osal.h
+ *
+ *   @brief
+ *      This is the sample OS Adaptation layer which is used by the MMC
+ *      driver. The OSAL layer can be ported in either of the following
+ *      manners to a native OS:
+ *
+ *      <b> Approach 1: </b>
+ *      @n  Use Prebuilt Libraries
+ *           - Ensure that the provide an implementation of all
+ *             Osal_XXX API for their native OS.
+ *           - Link the prebuilt libraries with their application.
+ *           - Refer to the "example" directory for an example of this
+ *       @n <b> Pros: </b>
+ *           - Customers can reuse prebuilt TI provided libraries
+ *       @n <b> Cons: </b>
+ *           - Level of indirection in the API to get to the actual OS call
+ *
+ *      <b> Approach 2: </b>
+ *      @n  Rebuilt Library
+ *           - Create a copy of this file and modify it to directly
+ *             inline the native OS calls
+ *           - Rebuild the MMC Driver library; ensure that the Include
+ *             path points to the directory where the copy of this file
+ *             has been provided.
+ *           - Please refer to the "test" directory for an example of this
+ *       @n <b> Pros: </b>
+ *           - Optimizations can be done to remove the level of indirection
+ *       @n <b> Cons: </b>
+ *           - MMC Libraries need to be rebuilt by the customer.
+ *
+ */
+
+/*
+ * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of Texas Instruments Incorporated nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef FATFS_OSAL_H
+#define FATFS_OSAL_H
+
+#include <ti/osal/osal.h>
+#include <string.h>
+/**
+ * @brief   Assert API. If expression is true then it will stay in the while
+ *          loop.
+ *
+ * @param   expr  Expression which need to be evaluated.
+ *
+ */
+#define FATFS_osalAssert(expr)         OSAL_Assert(expr)
+
+/**
+ * @brief   The macro is used by the I2C driver to create a semaphore for
+ * each I2C  opened in blocking mode. Semaphores created should
+ * *initially* be created with a count of 0 i.e. unavailable.
+ *
+*  @param  count  Initial count of the semaphore. For binary semaphores,
+ *                 only values of 0 or 1 are valid.
+ *
+ *  @param  params  Pointer to the instance configuration parameters. NULL
+ *                  denotes to use the default parameters (SemOSAL default
+ *                  parameters as noted in SemaphoreP_Params).
+ *
+ *  @return A void* on success or a NULL on an error
+ */
+
+#define FATFS_osalCreateBlockingLock(count,params)   \
+                                                 (SemaphoreP_create(count,params))
+
+/**
+ * @brief   The macro is used by the I2C driver to delete a previously
+ * created semaphore. This is called when a I2C  opened in blocking mode
+ * is being closed.
+ *
+ * <b> Prototype: </b>
+ *  The following is the C prototype for the expected OSAL API.
+ *
+ *  @verbatim
+       void SemOSAL_delete(void* semHandle)
+    @endverbatim
+
+ *  <b> Parameter </b>
+ *  @n  Semaphore Handle returned by the create semaphore
+ *
+ *  <b> Return Value </b>
+ *  @n  Not Applicable
+ */
+#define FATFS_osalDeleteBlockingLock(X)       (SemaphoreP_delete(X))
+
+
+/*!
+ *  @brief  Initialize params structure to default values.
+ *
+ *  The default parameters are:
+ *   - mode: SemOSAL_Mode_COUNTING
+ *   - name: NULL
+ *
+ *  @param params  Pointer to the instance configuration parameters.
+ */
+#define FATFS_osalSemParamsInit(params)  (SemaphoreP_Params_init(params))
+
+
+/**
+ * @brief   The macro is used by the I2C driver to pend on a semaphore
+ * This is called when an application tries to receive data on a blocking
+ *  when there is no data available. Since all semaphores are initially
+ * created to be unavailable; this will cause the application to block.
+ *
+ * <b> Prototype: </b>
+ *  The following is the C prototype for the expected OSAL API.
+ *
+ *  @verbatim
+       void SemOSAL_pend(void* semHandle)
+    @endverbatim
+ *
+ *  <b> Parameter </b>
+ *  @n  Semaphore Handle
+ *
+ *  <b> Return Value </b>
+ *  @n  Not Applicable
+ */
+#define FATFS_osalPendLock(X,Y)        (SemaphoreP_pend((X),(Y)))
+
+/**
+ * @brief   The macro is used by the I2C driver to post the semaphore
+ * The driver posts the semaphore once data is received on a specific
+ *
+ *
+ * <b> Prototype: </b>
+ *  The following is the C prototype for the expected OSAL API.
+ *
+ *  @verbatim
+       void SemOSAL_post(void* semHandle)
+    @endverbatim
+ *
+ *  <b> Parameter </b>
+ *  @n  Semaphore Handle
+ *
+ *  <b> Return Value </b>
+ *  @n  Not Applicable
+ */
+#define FATFS_osalPostLock(X)     (SemaphoreP_post(X))
+
+/**
+ * @brief   Function to disable interrupts to enter a critical region
+ *
+ * <b> Prototype: </b>
+ *  The following is the C prototype for the expected OSAL API.
+ *
+ *  @verbatim
+       void HwiOSAL_enterCritical()
+    @endverbatim
+ *
+ *  <b> Parameter </b>
+ *  @n  Not Applicable
+ *
+ *  <b> Return Value </b>
+ *  @n  Interrupt key
+ */
+#define FATFS_osalHardwareIntDisable() (HwiP_disable())
+
+/**
+ * @brief   Function to restore interrupts to exit a critical region
+ *
+ * <b> Prototype: </b>
+ *  The following is the C prototype for the expected OSAL API.
+ *
+ *  @verbatim
+       void HwiOSAL_exitCritical(int key)
+    @endverbatim
+ *
+ *  <b> Parameter </b>
+ *  @n  Interrupt key
+ *
+ *  <b> Return Value </b>
+ *  @n  Not Applicable
+ */
+#define FATFS_osalHardwareIntRestore(X) (HwiP_restore(X))
+
+/**
+ * @brief  Function to deregister a interrupt
+ *
+ * <b> Prototype: </b>
+ *  The following is the C prototype for the expected OSAL API.
+ *
+ *  @verbatim
+       int HwiOSAL_deregisterInterrupt(void* hwiPtr)
+    @endverbatim
+ *
+ *  <b> Parameter </b>
+ *  @n  Interrupt handler
+ *
+ *  <b> Return Value </b>
+ *  @n  status of operation
+ */
+#define FATFS_osalHardwareIntDestruct(X)  (HwiP_delete(X))
+
+/**
+ * @brief  Function to register an interrupt
+ *
+ * <b> Prototype: </b>
+ *  The following is the C prototype for the expected OSAL API.
+ *
+ *  @verbatim
+       HwiP_Handle HwiP_create(X, Y, Z);
+    @endverbatim
+ *
+ *  <b> Parameter </b>
+ *  @n  Interrupt number
+ *
+ *  <b> Parameter </b>
+ *  @n  hwiFxn entry function of the hardware interrupt
+ *
+ *  <b> Parameter </b>
+ *  @n  params  argument passed into the entry function
+ *
+ *  <b> Return Value </b>
+ *  @n  Interrupt handle
+ */
+#define FATFS_osalRegisterInterrupt(X,Y,Z)     (HwiP_create((X),(Y),(Z)))
+
+/**
+ * @brief  Function to initialize hardware interrupt parameters.
+ *
+ * <b> Prototype: </b>
+ *  The following is the C prototype for the expected OSAL API.
+ *
+ *  @verbatim
+       void HwiP_Params_init(HwiP_Params *params)
+    @endverbatim
+ *
+ *  <b> Parameter </b>
+ *  @n  Parameters   Pointer to the hardware interrupt's parameter structure.
+ *
+ */
+#define FATFS_osalHwiParamsInit(X)             (HwiP_Params_init(X))
+
+/**
+ * @brief  Function to disable specific hardware interrupt
+ *
+ * <b> Prototype: </b>
+ *  The following is the C prototype for the expected OSAL API.
+ *
+ *  @verbatim
+       void HwiOSAL_disableInterrupt(unsigned int intrNum)
+    @endverbatim
+ *
+ *  <b> Parameter </b>
+ *  @n  Interrupt number
+ *
+ */
+#define FATFS_osalHardwareIntrDisable(X)    (HwiP_disableInterrupt(X))
+
+/**
+ * @brief  Function to enable specific hardware interrupt
+ *
+ * <b> Prototype: </b>
+ *  The following is the C prototype for the expected OSAL API.
+ *
+ *  @verbatim
+       void HwiOSAL_enableInterrupt(unsigned int intrNum)
+    @endverbatim
+ *
+ *  <b> Parameter </b>
+ *  @n  Interrupt number
+ *
+ */
+#define FATFS_osalHardwareIntrEnable(X)     (HwiP_enableInterrupt(X))
+
+#endif /* FATFS_OSAL_H */
diff --git a/packages/ti/fs/fatfs/src/Module.xs b/packages/ti/fs/fatfs/src/Module.xs
new file mode 100644 (file)
index 0000000..ba1a7b8
--- /dev/null
@@ -0,0 +1,60 @@
+/******************************************************************************
+ * FILE PURPOSE: FATFS Driver Source Module specification file.
+ ******************************************************************************
+ * FILE NAME: module.xs
+ *
+ * DESCRIPTION: 
+ *  This file contains the module specification for the FATFS Driver
+ *
+ * Copyright (C) 2015 Texas Instruments, Inc.
+ *****************************************************************************/
+
+/* Load the library utility. */
+var libUtility = xdc.loadCapsule ("../build/buildlib.xs");
+
+/* List of all the FATFS Driver Files */
+var fatfsSockLibFiles = [
+    "src/diskio.c",
+    "src/ff.c",
+    "src/FATFS_drv.c",
+    
+];
+
+/**************************************************************************
+ * FUNCTION NAME : modBuild
+ **************************************************************************
+ * DESCRIPTION   :
+ *  The function is used to build the MMC LLD Driver and to add the core
+ *  driver files to the package. 
+ **************************************************************************/
+function modBuild() 
+{
+    if (Build.targets.length != 0)
+    {
+        /* Build the libraries for all the targets specified. */
+        for (var targets=0; targets < Build.targets.length; targets++)
+        {
+                var libOptions = {
+                    incs: lldIncludePath,
+                };
+                
+                libUtility.buildLibrary (libOptions, Pkg.name, Build.targets[targets], fatfsSockLibFiles);
+        }
+    }
+    /* Add all the .c files to the release package. */
+    var testFiles = libUtility.listAllFiles (".c", "src", true);
+    for (var k = 0 ; k < testFiles.length; k++)
+        Pkg.otherFiles[Pkg.otherFiles.length++] = testFiles[k];
+
+    /* Add all the .h files to the release package. */
+    var testFiles = libUtility.listAllFiles (".h", "src", true);
+    for (var k = 0 ; k < testFiles.length; k++)
+        Pkg.otherFiles[Pkg.otherFiles.length++] = testFiles[k];
+
+    /* Add all the .mk files to the release package. */
+    var mkFiles = libUtility.listAllFiles (".mk", "src", true);
+    for (var k = 0 ; k < mkFiles.length; k++)
+        Pkg.otherFiles[Pkg.otherFiles.length++] = mkFiles[k];
+
+}
+
diff --git a/packages/ti/fs/fatfs/src/diskio.c b/packages/ti/fs/fatfs/src/diskio.c
new file mode 100644 (file)
index 0000000..0dd9619
--- /dev/null
@@ -0,0 +1,194 @@
+/*\r
+ * Copyright (c) 2013, Texas Instruments Incorporated\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * *  Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ *\r
+ * *  Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ *\r
+ * *  Neither the name of Texas Instruments Incorporated nor the names of\r
+ *    its contributors may be used to endorse or promote products derived\r
+ *    from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\r
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\r
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;\r
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\r
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+/*\r
+ * ======== diskio.c ========\r
+ * Generic definition of all disk APIs.  This should be shared amongst all media\r
+ *\r
+ */\r
+/*-----------------------------------------------------------------------*/\r
+/* Low level disk I/O module skeleton for FatFs     (C)ChaN, 2016        */\r
+/*-----------------------------------------------------------------------*/\r
+/* If a working storage control module is available, it should be        */\r
+/* attached to the FatFs via a glue function rather than modifying it.   */\r
+/* This is an example of glue functions to attach various exsisting      */\r
+/* storage control modules to the FatFs module with a defined API.       */\r
+/*-----------------------------------------------------------------------*/\r
+/* Definitions of physical drive number for each drive */\r
+#define ATA            0       /* Example: Map ATA harddisk to physical drive 0 */\r
+#define MMC            1       /* Example: Map MMC/SD card to physical drive 1 */\r
+#define USB            2       /* Example: Map USB MSD to physical drive 2 */\r
+\r
+#include <stdio.h>\r
+#include <ffconf.h>\r
+#include <diskio.h>\r
+\r
+static diskio_fxns drive_fxn_table[_VOLUMES] = {\r
+    {NULL, NULL, NULL, NULL, NULL},\r
+    {NULL, NULL, NULL, NULL, NULL},\r
+    {NULL, NULL, NULL, NULL, NULL},\r
+    {NULL, NULL, NULL, NULL, NULL}\r
+};\r
+\r
+extern Int32 ti_sysbios_fatfs_getFatTime(void);\r
+/*\r
+ * ======== disk_register ========\r
+ */\r
+DRESULT disk_register(\r
+        BYTE drive,\r
+        DSTATUS (*d_init)   (BYTE drive),\r
+        DSTATUS (*d_status) (BYTE drive),\r
+        DRESULT (*d_read)  (BYTE drive, BYTE *buf, DWORD start, BYTE num),\r
+        DRESULT (*d_write) (BYTE drive, const BYTE *buf, DWORD start, BYTE num),\r
+        DRESULT (*d_ioctl) (BYTE drive, BYTE cmd, void * buf))\r
+{\r
+\r
+    if (drive >= _VOLUMES) {\r
+        return RES_PARERR;\r
+    }\r
+\r
+    drive_fxn_table[drive].d_init   = d_init;\r
+    drive_fxn_table[drive].d_status = d_status;\r
+    drive_fxn_table[drive].d_read   = d_read;\r
+    drive_fxn_table[drive].d_write  = d_write;\r
+    drive_fxn_table[drive].d_ioctl  = d_ioctl;\r
+\r
+    return RES_OK;\r
+}\r
+\r
+/*\r
+ * ======== disk_unregister ========\r
+ */\r
+DRESULT disk_unregister(BYTE drive)\r
+{\r
+\r
+    if (drive >= _VOLUMES) {\r
+        return RES_PARERR;\r
+    }\r
+\r
+    drive_fxn_table[drive].d_init   = NULL;\r
+    drive_fxn_table[drive].d_status = NULL;\r
+    drive_fxn_table[drive].d_read   = NULL;\r
+    drive_fxn_table[drive].d_write  = NULL;\r
+    drive_fxn_table[drive].d_ioctl  = NULL;\r
+\r
+    return RES_OK;\r
+}\r
+\r
+/*\r
+ * ======== disk_initialize ========\r
+ */\r
+DSTATUS disk_initialize(BYTE drive)\r
+{\r
+    if (drive_fxn_table[drive].d_init == NULL) {\r
+        return RES_PARERR;\r
+    }\r
+    else {\r
+        /* call registered init function */\r
+        return ( (*(drive_fxn_table[drive].d_init)) (drive) );\r
+    }\r
+}\r
+\r
+/*\r
+ * ======== disk_status ========\r
+ */\r
+DSTATUS disk_status(BYTE drive)\r
+{\r
+    if (drive_fxn_table[drive].d_status == NULL) {\r
+        return RES_PARERR;\r
+    }\r
+    else {\r
+        /* call registered status function */\r
+        return ( (*(drive_fxn_table[drive].d_status)) (drive) );\r
+    }\r
+}\r
+\r
+/*\r
+ * ======== disk_read ========\r
+ */\r
+DRESULT disk_read(BYTE drive, BYTE * buf, DWORD start, UINT num)\r
+{\r
+    if (drive_fxn_table[drive].d_read == NULL) {\r
+        return RES_PARERR;\r
+    }\r
+    else {\r
+        /* call registered read function */\r
+        return ( (*(drive_fxn_table[drive].d_read)) (drive, buf, start, num) );\r
+    }\r
+}\r
+\r
+/*\r
+ * ======== disk_write ========\r
+ */\r
+#if     _READONLY == 0\r
+DRESULT disk_write(BYTE drive, const BYTE * buf, DWORD start, UINT num)\r
+{\r
+    if (drive_fxn_table[drive].d_write == NULL) {\r
+        return RES_PARERR;\r
+    }\r
+    else {\r
+        /* call registered write function */\r
+        return ( (*(drive_fxn_table[drive].d_write)) (drive, buf, start, num) );\r
+    }\r
+}\r
+#endif\r
+\r
+/*\r
+ * ======== disk_ioctl ========\r
+ */\r
+DRESULT disk_ioctl(BYTE drive, BYTE cmd, void * buf)\r
+{\r
+    if (drive_fxn_table[drive].d_ioctl == NULL) {\r
+        return RES_PARERR;\r
+    }\r
+    else {\r
+        /* call registered write function */\r
+        return ( (*(drive_fxn_table[drive].d_ioctl)) (drive, cmd, buf) );\r
+    }\r
+}\r
+\r
+/*---------------------------------------------------------*/\r
+/* User Provided Timer Function for FatFs module           */\r
+/*---------------------------------------------------------*/\r
+/* This is a real time clock service to be called from     */\r
+/* FatFs module. Any valid time must be returned even if   */\r
+/* the system does not support a real time clock.          */\r
+\r
+DWORD get_fattime (void)\r
+{\r
+    return    ((2007UL-1980) << 25) // Year = 2007\r
+            | (6UL << 21)           // Month = June\r
+            | (5UL << 16)           // Day = 5\r
+            | (11U << 11)           // Hour = 11\r
+            | (38U << 5)            // Min = 38\r
+            | (0U >> 1)             // Sec = 0\r
+            ;\r
+}\r
diff --git a/packages/ti/fs/fatfs/src/ff.c b/packages/ti/fs/fatfs/src/ff.c
new file mode 100644 (file)
index 0000000..c89142a
--- /dev/null
@@ -0,0 +1,5794 @@
+/*----------------------------------------------------------------------------/\r
+/  FatFs - FAT file system module  R0.12                 (C)ChaN, 2016        /\r
+/-----------------------------------------------------------------------------/\r
+/ FatFs module is a free software that opened under license policy of\r
+/ following conditions.\r
+/\r
+/ Copyright (C) 2016, ChaN, all right reserved.\r
+/\r
+/ 1. Redistributions of source code must retain the above copyright notice,\r
+/    this condition and the following disclaimer.\r
+/\r
+/ This software is provided by the copyright holder and contributors "AS IS"\r
+/ and any warranties related to this software are DISCLAIMED.\r
+/ The copyright owner or contributors be NOT LIABLE for any damages caused\r
+/ by use of this software.\r
+/----------------------------------------------------------------------------*/\r
+\r
+\r
+#include <ti/csl/tistdtypes.h>\r
+#include "ff.h"                        /* Declarations of FatFs API */\r
+#include "diskio.h"            /* Declarations of disk I/O functions */\r
+\r
+\r
+/*--------------------------------------------------------------------------\r
+\r
+   Module Private Definitions\r
+\r
+---------------------------------------------------------------------------*/\r
+\r
+#if _FATFS != 88100    /* Revision ID */\r
+#error Wrong include file (ff.h).\r
+#endif\r
+\r
+\r
+/* Reentrancy related */\r
+#if _FS_REENTRANT\r
+#if _USE_LFN == 1\r
+#error Static LFN work area cannot be used at thread-safe configuration\r
+#endif\r
+#define        ENTER_FF(fs)            { if (!lock_fs(fs)) return FR_TIMEOUT; }\r
+#define        LEAVE_FF(fs, res)       { unlock_fs(fs, res); return res; }\r
+#else\r
+#define        ENTER_FF(fs)\r
+#define LEAVE_FF(fs, res)      return res\r
+#endif\r
+\r
+#define        ABORT(fs, res)          { fp->err = (BYTE)(res); LEAVE_FF(fs, res); }\r
+\r
+\r
+/* Definitions of sector size */\r
+#if (_MAX_SS < _MIN_SS) || (_MAX_SS != 512 && _MAX_SS != 1024 && _MAX_SS != 2048 && _MAX_SS != 4096) || (_MIN_SS != 512 && _MIN_SS != 1024 && _MIN_SS != 2048 && _MIN_SS != 4096)\r
+#error Wrong sector size configuration\r
+#endif\r
+#if _MAX_SS == _MIN_SS\r
+#define        SS(fs)  ((UINT)_MAX_SS) /* Fixed sector size */\r
+#else\r
+#define        SS(fs)  ((fs)->ssize)   /* Variable sector size */\r
+#endif\r
+\r
+\r
+/* Timestamp */\r
+#if _FS_NORTC == 1\r
+#if _NORTC_YEAR < 1980 || _NORTC_YEAR > 2107 || _NORTC_MON < 1 || _NORTC_MON > 12 || _NORTC_MDAY < 1 || _NORTC_MDAY > 31\r
+#error Invalid _FS_NORTC settings\r
+#endif\r
+#define GET_FATTIME()  ((DWORD)(_NORTC_YEAR - 1980) << 25 | (DWORD)_NORTC_MON << 21 | (DWORD)_NORTC_MDAY << 16)\r
+#else\r
+#define GET_FATTIME()  get_fattime()\r
+#endif\r
+\r
+\r
+/* File lock controls */\r
+#if _FS_LOCK != 0\r
+#if _FS_READONLY\r
+#error _FS_LOCK must be 0 at read-only configuration\r
+#endif\r
+typedef struct {\r
+       FATFS *fs;              /* Object ID 1, volume (NULL:blank entry) */\r
+       DWORD clu;              /* Object ID 2, directory (0:root) */\r
+       DWORD ofs;              /* Object ID 3, directory offset */\r
+       WORD ctr;               /* Object open counter, 0:none, 0x01..0xFF:read mode open count, 0x100:write mode */\r
+} FILESEM;\r
+#endif\r
+\r
+\r
+\r
+/* DBCS code ranges and SBCS upper conversion tables */\r
+\r
+#if _CODE_PAGE == 932  /* Japanese Shift-JIS */\r
+#define _DF1S  0x81    /* DBC 1st byte range 1 start */\r
+#define _DF1E  0x9F    /* DBC 1st byte range 1 end */\r
+#define _DF2S  0xE0    /* DBC 1st byte range 2 start */\r
+#define _DF2E  0xFC    /* DBC 1st byte range 2 end */\r
+#define _DS1S  0x40    /* DBC 2nd byte range 1 start */\r
+#define _DS1E  0x7E    /* DBC 2nd byte range 1 end */\r
+#define _DS2S  0x80    /* DBC 2nd byte range 2 start */\r
+#define _DS2E  0xFC    /* DBC 2nd byte range 2 end */\r
+\r
+#elif _CODE_PAGE == 936        /* Simplified Chinese GBK */\r
+#define _DF1S  0x81\r
+#define _DF1E  0xFE\r
+#define _DS1S  0x40\r
+#define _DS1E  0x7E\r
+#define _DS2S  0x80\r
+#define _DS2E  0xFE\r
+\r
+#elif _CODE_PAGE == 949        /* Korean */\r
+#define _DF1S  0x81\r
+#define _DF1E  0xFE\r
+#define _DS1S  0x41\r
+#define _DS1E  0x5A\r
+#define _DS2S  0x61\r
+#define _DS2E  0x7A\r
+#define _DS3S  0x81\r
+#define _DS3E  0xFE\r
+\r
+#elif _CODE_PAGE == 950        /* Traditional Chinese Big5 */\r
+#define _DF1S  0x81\r
+#define _DF1E  0xFE\r
+#define _DS1S  0x40\r
+#define _DS1E  0x7E\r
+#define _DS2S  0xA1\r
+#define _DS2E  0xFE\r
+\r
+#elif _CODE_PAGE == 437        /* U.S. */\r
+#define _DF1S  0\r
+#define _EXCVT {0x80,0x9A,0x45,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F, \\r
+                               0x90,0x92,0x92,0x4F,0x99,0x4F,0x55,0x55,0x59,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \\r
+                               0x41,0x49,0x4F,0x55,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \\r
+                               0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \\r
+                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \\r
+                               0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \\r
+                               0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \\r
+                               0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}\r
+\r
+#elif _CODE_PAGE == 720        /* Arabic */\r
+#define _DF1S  0\r
+#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \\r
+                               0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \\r
+                               0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \\r
+                               0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \\r
+                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \\r
+                               0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \\r
+                               0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \\r
+                               0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}\r
+\r
+#elif _CODE_PAGE == 737        /* Greek */\r
+#define _DF1S  0\r
+#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \\r
+                               0x90,0x92,0x92,0x93,0x94,0x95,0x96,0x97,0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87, \\r
+                               0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0xAA,0x92,0x93,0x94,0x95,0x96, \\r
+                               0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \\r
+                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \\r
+                               0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \\r
+                               0x97,0xEA,0xEB,0xEC,0xE4,0xED,0xEE,0xEF,0xF5,0xF0,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \\r
+                               0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}\r
+\r
+#elif _CODE_PAGE == 771        /* KBL */\r
+#define _DF1S  0\r
+#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \\r
+                               0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \\r
+                               0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \\r
+                               0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \\r
+                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \\r
+                               0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDC,0xDE,0xDE, \\r
+                               0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \\r
+                               0xF0,0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF8,0xFA,0xFA,0xFC,0xFC,0xFE,0xFF}\r
+\r
+#elif _CODE_PAGE == 775        /* Baltic */\r
+#define _DF1S  0\r
+#define _EXCVT {0x80,0x9A,0x91,0xA0,0x8E,0x95,0x8F,0x80,0xAD,0xED,0x8A,0x8A,0xA1,0x8D,0x8E,0x8F, \\r
+                               0x90,0x92,0x92,0xE2,0x99,0x95,0x96,0x97,0x97,0x99,0x9A,0x9D,0x9C,0x9D,0x9E,0x9F, \\r
+                               0xA0,0xA1,0xE0,0xA3,0xA3,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \\r
+                               0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \\r
+                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \\r
+                               0xB5,0xB6,0xB7,0xB8,0xBD,0xBE,0xC6,0xC7,0xA5,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \\r
+                               0xE0,0xE1,0xE2,0xE3,0xE5,0xE5,0xE6,0xE3,0xE8,0xE8,0xEA,0xEA,0xEE,0xED,0xEE,0xEF, \\r
+                               0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}\r
+\r
+#elif _CODE_PAGE == 850        /* Latin 1 */\r
+#define _DF1S  0\r
+#define _EXCVT {0x43,0x55,0x45,0x41,0x41,0x41,0x41,0x43,0x45,0x45,0x45,0x49,0x49,0x49,0x41,0x41, \\r
+                               0x45,0x92,0x92,0x4F,0x4F,0x4F,0x55,0x55,0x59,0x4F,0x55,0x4F,0x9C,0x4F,0x9E,0x9F, \\r
+                               0x41,0x49,0x4F,0x55,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \\r
+                               0xB0,0xB1,0xB2,0xB3,0xB4,0x41,0x41,0x41,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \\r
+                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0x41,0x41,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \\r
+                               0xD1,0xD1,0x45,0x45,0x45,0x49,0x49,0x49,0x49,0xD9,0xDA,0xDB,0xDC,0xDD,0x49,0xDF, \\r
+                               0x4F,0xE1,0x4F,0x4F,0x4F,0x4F,0xE6,0xE8,0xE8,0x55,0x55,0x55,0x59,0x59,0xEE,0xEF, \\r
+                               0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}\r
+\r
+#elif _CODE_PAGE == 852        /* Latin 2 */\r
+#define _DF1S  0\r
+#define _EXCVT {0x80,0x9A,0x90,0xB6,0x8E,0xDE,0x8F,0x80,0x9D,0xD3,0x8A,0x8A,0xD7,0x8D,0x8E,0x8F, \\r
+                               0x90,0x91,0x91,0xE2,0x99,0x95,0x95,0x97,0x97,0x99,0x9A,0x9B,0x9B,0x9D,0x9E,0xAC, \\r
+                               0xB5,0xD6,0xE0,0xE9,0xA4,0xA4,0xA6,0xA6,0xA8,0xA8,0xAA,0x8D,0xAC,0xB8,0xAE,0xAF, \\r
+                               0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBD,0xBF, \\r
+                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC6,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \\r
+                               0xD1,0xD1,0xD2,0xD3,0xD2,0xD5,0xD6,0xD7,0xB7,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \\r
+                               0xE0,0xE1,0xE2,0xE3,0xE3,0xD5,0xE6,0xE6,0xE8,0xE9,0xE8,0xEB,0xED,0xED,0xDD,0xEF, \\r
+                               0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xEB,0xFC,0xFC,0xFE,0xFF}\r
+\r
+#elif _CODE_PAGE == 855        /* Cyrillic */\r
+#define _DF1S  0\r
+#define _EXCVT {0x81,0x81,0x83,0x83,0x85,0x85,0x87,0x87,0x89,0x89,0x8B,0x8B,0x8D,0x8D,0x8F,0x8F, \\r
+                               0x91,0x91,0x93,0x93,0x95,0x95,0x97,0x97,0x99,0x99,0x9B,0x9B,0x9D,0x9D,0x9F,0x9F, \\r
+                               0xA1,0xA1,0xA3,0xA3,0xA5,0xA5,0xA7,0xA7,0xA9,0xA9,0xAB,0xAB,0xAD,0xAD,0xAE,0xAF, \\r
+                               0xB0,0xB1,0xB2,0xB3,0xB4,0xB6,0xB6,0xB8,0xB8,0xB9,0xBA,0xBB,0xBC,0xBE,0xBE,0xBF, \\r
+                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC7,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \\r
+                               0xD1,0xD1,0xD3,0xD3,0xD5,0xD5,0xD7,0xD7,0xDD,0xD9,0xDA,0xDB,0xDC,0xDD,0xE0,0xDF, \\r
+                               0xE0,0xE2,0xE2,0xE4,0xE4,0xE6,0xE6,0xE8,0xE8,0xEA,0xEA,0xEC,0xEC,0xEE,0xEE,0xEF, \\r
+                               0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF8,0xFA,0xFA,0xFC,0xFC,0xFD,0xFE,0xFF}\r
+\r
+#elif _CODE_PAGE == 857        /* Turkish */\r
+#define _DF1S  0\r
+#define _EXCVT {0x80,0x9A,0x90,0xB6,0x8E,0xB7,0x8F,0x80,0xD2,0xD3,0xD4,0xD8,0xD7,0x49,0x8E,0x8F, \\r
+                               0x90,0x92,0x92,0xE2,0x99,0xE3,0xEA,0xEB,0x98,0x99,0x9A,0x9D,0x9C,0x9D,0x9E,0x9E, \\r
+                               0xB5,0xD6,0xE0,0xE9,0xA5,0xA5,0xA6,0xA6,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \\r
+                               0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \\r
+                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC7,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \\r
+                               0xD0,0xD1,0xD2,0xD3,0xD4,0x49,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \\r
+                               0xE0,0xE1,0xE2,0xE3,0xE5,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xDE,0xED,0xEE,0xEF, \\r
+                               0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}\r
+\r
+#elif _CODE_PAGE == 860        /* Portuguese */\r
+#define _DF1S  0\r
+#define _EXCVT {0x80,0x9A,0x90,0x8F,0x8E,0x91,0x86,0x80,0x89,0x89,0x92,0x8B,0x8C,0x98,0x8E,0x8F, \\r
+                               0x90,0x91,0x92,0x8C,0x99,0xA9,0x96,0x9D,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \\r
+                               0x86,0x8B,0x9F,0x96,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \\r
+                               0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \\r
+                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \\r
+                               0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \\r
+                               0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \\r
+                               0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}\r
+\r
+#elif _CODE_PAGE == 861        /* Icelandic */\r
+#define _DF1S  0\r
+#define _EXCVT {0x80,0x9A,0x90,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x8B,0x8B,0x8D,0x8E,0x8F, \\r
+                               0x90,0x92,0x92,0x4F,0x99,0x8D,0x55,0x97,0x97,0x99,0x9A,0x9D,0x9C,0x9D,0x9E,0x9F, \\r
+                               0xA4,0xA5,0xA6,0xA7,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \\r
+                               0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \\r
+                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \\r
+                               0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \\r
+                               0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \\r
+                               0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}\r
+\r
+#elif _CODE_PAGE == 862        /* Hebrew */\r
+#define _DF1S  0\r
+#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \\r
+                               0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \\r
+                               0x41,0x49,0x4F,0x55,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \\r
+                               0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \\r
+                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \\r
+                               0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \\r
+                               0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \\r
+                               0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}\r
+\r
+#elif _CODE_PAGE == 863        /* Canadian-French */\r
+#define _DF1S  0\r
+#define _EXCVT {0x43,0x55,0x45,0x41,0x41,0x41,0x86,0x43,0x45,0x45,0x45,0x49,0x49,0x8D,0x41,0x8F, \\r
+                               0x45,0x45,0x45,0x4F,0x45,0x49,0x55,0x55,0x98,0x4F,0x55,0x9B,0x9C,0x55,0x55,0x9F, \\r
+                               0xA0,0xA1,0x4F,0x55,0xA4,0xA5,0xA6,0xA7,0x49,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \\r
+                               0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \\r
+                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \\r
+                               0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \\r
+                               0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \\r
+                               0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}\r
+\r
+#elif _CODE_PAGE == 864        /* Arabic */\r
+#define _DF1S  0\r
+#define _EXCVT {0x80,0x9A,0x45,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F, \\r
+                               0x90,0x92,0x92,0x4F,0x99,0x4F,0x55,0x55,0x59,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \\r
+                               0x41,0x49,0x4F,0x55,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \\r
+                               0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \\r
+                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \\r
+                               0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \\r
+                               0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \\r
+                               0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}\r
+\r
+#elif _CODE_PAGE == 865        /* Nordic */\r
+#define _DF1S  0\r
+#define _EXCVT {0x80,0x9A,0x90,0x41,0x8E,0x41,0x8F,0x80,0x45,0x45,0x45,0x49,0x49,0x49,0x8E,0x8F, \\r
+                               0x90,0x92,0x92,0x4F,0x99,0x4F,0x55,0x55,0x59,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \\r
+                               0x41,0x49,0x4F,0x55,0xA5,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \\r
+                               0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \\r
+                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \\r
+                               0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \\r
+                               0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, \\r
+                               0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}\r
+\r
+#elif _CODE_PAGE == 866        /* Russian */\r
+#define _DF1S  0\r
+#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \\r
+                               0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \\r
+                               0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \\r
+                               0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \\r
+                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \\r
+                               0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, \\r
+                               0x90,0x91,0x92,0x93,0x9d,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, \\r
+                               0xF0,0xF0,0xF2,0xF2,0xF4,0xF4,0xF6,0xF6,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF}\r
+\r
+#elif _CODE_PAGE == 869        /* Greek 2 */\r
+#define _DF1S  0\r
+#define _EXCVT {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, \\r
+                               0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x86,0x9C,0x8D,0x8F,0x90, \\r
+                               0x91,0x90,0x92,0x95,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, \\r
+                               0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, \\r
+                               0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, \\r
+                               0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xA4,0xA5,0xA6,0xD9,0xDA,0xDB,0xDC,0xA7,0xA8,0xDF, \\r
+                               0xA9,0xAA,0xAC,0xAD,0xB5,0xB6,0xB7,0xB8,0xBD,0xBE,0xC6,0xC7,0xCF,0xCF,0xD0,0xEF, \\r
+                               0xF0,0xF1,0xD1,0xD2,0xD3,0xF5,0xD4,0xF7,0xF8,0xF9,0xD5,0x96,0x95,0x98,0xFE,0xFF}\r
+\r
+#elif _CODE_PAGE == 1  /* ASCII (for only non-LFN cfg) */\r
+#if _USE_LFN != 0\r
+#error Cannot enable LFN without valid code page.\r
+#endif\r
+#define _DF1S  0\r
+\r
+#else\r
+#error Unknown code page\r
+\r
+#endif\r
+\r
+\r
+/* Character code support macros */\r
+#define IsUpper(c)     (((c)>='A')&&((c)<='Z'))\r
+#define IsLower(c)     (((c)>='a')&&((c)<='z'))\r
+#define IsDigit(c)     (((c)>='0')&&((c)<='9'))\r
+\r
+#if _DF1S != 0 /* Code page is DBCS */\r
+\r
+#ifdef _DF2S   /* Two 1st byte areas */\r
+#define IsDBCS1(c)     (((BYTE)(c) >= _DF1S && (BYTE)(c) <= _DF1E) || ((BYTE)(c) >= _DF2S && (BYTE)(c) <= _DF2E))\r
+#else                  /* One 1st byte area */\r
+#define IsDBCS1(c)     ((BYTE)(c) >= _DF1S && (BYTE)(c) <= _DF1E)\r
+#endif\r
+\r
+#ifdef _DS3S   /* Three 2nd byte areas */\r
+#define IsDBCS2(c)     (((BYTE)(c) >= _DS1S && (BYTE)(c) <= _DS1E) || ((BYTE)(c) >= _DS2S && (BYTE)(c) <= _DS2E) || ((BYTE)(c) >= _DS3S && (BYTE)(c) <= _DS3E))\r
+#else                  /* Two 2nd byte areas */\r
+#define IsDBCS2(c)     (((BYTE)(c) >= _DS1S && (BYTE)(c) <= _DS1E) || ((BYTE)(c) >= _DS2S && (BYTE)(c) <= _DS2E))\r
+#endif\r
+\r
+#else                  /* Code page is SBCS */\r
+\r
+#define IsDBCS1(c)     0\r
+#define IsDBCS2(c)     0\r
+\r
+#endif /* _DF1S */\r
+\r
+\r
+/* Name status flags */\r
+#define NSFLAG         11              /* Index of name status byte in fn[] */\r
+#define NS_LOSS                0x01    /* Out of 8.3 format */\r
+#define NS_LFN         0x02    /* Force to create LFN entry */\r
+#define NS_LAST                0x04    /* Last segment */\r
+#define NS_BODY                0x08    /* Lower case flag (body) */\r
+#define NS_EXT         0x10    /* Lower case flag (ext) */\r
+#define NS_DOT         0x20    /* Dot entry */\r
+#define NS_NONAME      0x80    /* Not followed */\r
+\r
+\r
+/* Limits and Boundaries (Differ from specs but correct for real DOS/Windows) */\r
+#define MIN_FAT16      4086U                   /* Minimum number of clusters of FAT16 */\r
+#define        MIN_FAT32       65526U                  /* Minimum number of clusters of FAT32 */\r
+#define MAX_DIR                0x200000                /* Maximum size of FAT directory */\r
+#define MAX_DIR_EX     0x10000000              /* Maximum size of exFAT directory */\r
+\r
+\r
+/* FatFs refers the members in the FAT structures as byte array instead of\r
+/ structure members because the structure is not binary compatible between\r
+/ different platforms */\r
+\r
+#define BS_jmpBoot                     0               /* x86 jump instruction (3-byte) */\r
+#define BS_OEMName                     3               /* OEM name (8-byte) */\r
+#define BPB_BytsPerSec         11              /* Sector size [byte] (WORD) */\r
+#define BPB_SecPerClus         13              /* Cluster size [sector] (BYTE) */\r
+#define BPB_RsvdSecCnt         14              /* Size of reserved area [sector] (WORD) */\r
+#define BPB_NumFATs                    16              /* Number of FATs (BYTE) */\r
+#define BPB_RootEntCnt         17              /* Size of root directory area for FAT12/16 [entry] (WORD) */\r
+#define BPB_TotSec16           19              /* Volume size (16-bit) [sector] (WORD) */\r
+#define BPB_Media                      21              /* Media descriptor (BYTE) */\r
+#define BPB_FATSz16                    22              /* FAT size (16-bit) [sector] (WORD) */\r
+#define BPB_SecPerTrk          24              /* Track size for int13h [sector] (WORD) */\r
+#define BPB_NumHeads           26              /* Number of heads for int13h (WORD) */\r
+#define BPB_HiddSec                    28              /* Volume offset from top of the drive (DWORD) */\r
+#define BPB_TotSec32           32              /* Volume size (32-bit) [sector] (DWORD) */\r
+#define BS_DrvNum                      36              /* Physical drive number for int13h (BYTE) */\r
+#define BS_NTres                       37              /* Error flag (BYTE) */\r
+#define BS_BootSig                     38              /* Extended boot signature (BYTE) */\r
+#define BS_VolID                       39              /* Volume serial number (DWORD) */\r
+#define BS_VolLab                      43              /* Volume label string (8-byte) */\r
+#define BS_FilSysType          54              /* File system type string (8-byte) */\r
+#define BPB_FATSz32                    36              /* FAT size (32-bit) [sector] (DWORD) */\r
+#define BPB_ExtFlags           40              /* Extended flags (WORD) */\r
+\r
+#define BPB_FSVer32                    42              /* FAT32: File system version (WORD) */\r
+#define BPB_RootClus32         44              /* FAT32: Root directory cluster (DWORD) */\r
+#define BPB_FSInfo32           48              /* FAT32: Offset of FSINFO sector (WORD) */\r
+#define BPB_BkBootSec32                50              /* FAT32: Offset of backup boot sector (WORD) */\r
+#define BS_DrvNum32                    64              /* FAT32: Physical drive number for int13h (BYTE) */\r
+#define BS_NTres32                     65              /* FAT32: Error flag (BYTE) */\r
+#define BS_BootSig32           66              /* FAT32: Extended boot signature (BYTE) */\r
+#define BS_VolID32                     67              /* FAT32: Volume serial number (DWORD) */\r
+#define BS_VolLab32                    71              /* FAT32: Volume label string (8-byte) */\r
+#define BS_FilSysType32                82              /* FAT32: File system type string (8-byte) */\r
+\r
+#define BPB_ZeroedEx           11              /* exFAT: Must be zero (35-byte) */\r
+#define BPB_VolOfsEx           64              /* exFAT: Volume offset from top of the drive [sector] (QWORD) */\r
+#define BPB_TotSecEx           72              /* exFAT: Volume size [sector] (QWORD) */\r
+#define BPB_FatOfsEx           80              /* exFAT: FAT offset from top of the volume [sector] (DWORD) */\r
+#define BPB_FatSzEx                    84              /* exFAT: FAT size [sector] (DWORD) */\r
+#define BPB_DataOfsEx          88              /* exFAT: Data offset from top of the volume [sector] (DWORD) */\r
+#define BPB_NumClusEx          92              /* exFAT: Number of clusters (DWORD) */\r
+#define BPB_RootClusEx         96              /* exFAT: Root directory cluster (DWORD) */\r
+#define BPB_VolIDEx                    100             /* exFAT: Volume serial number (DWORD) */\r
+#define BPB_FSVerEx                    104             /* exFAT: File system version (WORD) */\r
+#define BPB_VolFlagEx          106             /* exFAT: Volume flags (BYTE) */\r
+#define BPB_ActFatEx           107             /* exFAT: Active FAT flags (BYTE) */\r
+#define BPB_BytsPerSecEx       108             /* exFAT: Log2 of sector size in byte (BYTE) */\r
+#define BPB_SecPerClusEx       109             /* exFAT: Log2 of cluster size in sector (BYTE) */\r
+#define BPB_NumFATsEx          110             /* exFAT: Number of FATs (BYTE) */\r
+#define BPB_DrvNumEx           111             /* exFAT: Physical drive number for int13h (BYTE) */\r
+#define BPB_PercInUseEx                112             /* exFAT: Percent in use (BYTE) */\r
+\r
+#define        FSI_LeadSig                     0               /* FAT32 FSI: Leading signature (DWORD) */\r
+#define        FSI_StrucSig            484             /* FAT32 FSI: Structure signature (DWORD) */\r
+#define        FSI_Free_Count          488             /* FAT32 FSI: Number of free clusters (DWORD) */\r
+#define        FSI_Nxt_Free            492             /* FAT32 FSI: Last allocated cluster (DWORD) */\r
+\r
+#define MBR_Table                      446             /* MBR: Partition table offset */\r
+#define        SZ_PTE                          16              /* MBR: Size of a partition table entry */\r
+\r
+#define BS_55AA                                510             /* Signature word (WORD) */\r
+\r
+#define        DIR_Name                        0               /* Short file name (11) */\r
+#define        DIR_Attr                        11              /* Attribute (1) */\r
+#define        DIR_NTres                       12              /* Lower case flag (1) */\r
+#define DIR_CrtTime10          13              /* Created time sub-second (1) */\r
+#define        DIR_CrtTime                     14              /* Created time (2) */\r
+#define        DIR_CrtDate                     16              /* Created date (2) */\r
+#define DIR_LstAccDate         18              /* Last accessed date (2) */\r
+#define        DIR_FstClusHI           20              /* Higher 16-bit of first cluster (WORD) */\r
+#define        DIR_WrtTime                     22              /* Modified time (2) */\r
+#define        DIR_WrtDate                     24              /* Modified date (2) */\r
+#define        DIR_FstClusLO           26              /* Lower 16-bit of first cluster (WORD) */\r
+#define        DIR_FileSize            28              /* File size (DWORD) */\r
+#define        LDIR_Ord                        0               /* LFN entry order and LLE flag (1) */\r
+#define        LDIR_Attr                       11              /* LFN attribute (1) */\r
+#define        LDIR_Type                       12              /* LFN type (1) */\r
+#define        LDIR_Chksum                     13              /* Checksum of the SFN entry */\r
+#define        LDIR_FstClusLO          26              /* Must be zero (WORD) */\r
+#define        XDIR_Type                       0               /* Type of exFAT directory entry (BYTE) */\r
+#define        XDIR_NumLabel           1               /* Number of volume label characters (BYTE) */\r
+#define        XDIR_Label                      2               /* Volume label (11-WORD) */\r
+#define        XDIR_CaseSum            4               /* Sum of case conversion table (DWORD) */\r
+#define        XDIR_NumSec                     1               /* Number of secondary entries (BYTE) */\r
+#define        XDIR_SetSum                     2               /* Sum of the set of directory entries (WORD) */\r
+#define        XDIR_Attr                       4               /* File attribute (WORD) */\r
+#define        XDIR_CrtTime            8               /* Created time (4) */\r
+#define        XDIR_ModTime            12              /* Modified time (4) */\r
+#define        XDIR_AccTime            16              /* Last accessed time (4) */\r
+#define        XDIR_CrtTime10          20              /* Created time subsecond (1) */\r
+#define        XDIR_ModTime10          21              /* Modified time subsecond (1) */\r
+#define        XDIR_CrtTZ                      22              /* Created timezone (1) */\r
+#define        XDIR_ModTZ                      23              /* Modified timezone (1) */\r
+#define        XDIR_AccTZ                      24              /* Last accessed timezone (1) */\r
+#define        XDIR_GenFlags           33              /* Gneral flags (1) */\r
+#define        XDIR_NumName            35              /* Number of file name characters (BYTE) */\r
+#define        XDIR_NameHash           36              /* Hash of file name (WORD) */\r
+#define XDIR_ValidFileSize     40              /* Valid file size (QWORD) */\r
+#define        XDIR_FstClus            52              /* First cluster of the File/Directory (DWORD) */\r
+#define        XDIR_FileSize           56              /* File/Directory size (QWORD) */\r
+\r
+#define        SZDIRE                          32              /* Size of a directory entry */\r
+#define        LLEF                            0x40    /* Last long entry flag in LDIR_Ord */\r
+#define        DDEM                            0xE5    /* Deleted directory entry mark at DIR_Name[0] */\r
+#define        RDDEM                           0x05    /* Replacement of the character collides with DDEM */\r
+\r
+\r
+\r
+\r
+\r
+/*--------------------------------------------------------------------------\r
+\r
+   Module Private Work Area\r
+\r
+---------------------------------------------------------------------------*/\r
+\r
+/* Remark: Variables here without initial value shall be guaranteed zero/null\r
+/  at start-up. If not, either the linker or start-up routine being used is\r
+/  not compliance with C standard. */\r
+\r
+#if _VOLUMES < 1 || _VOLUMES > 9\r
+#error Wrong _VOLUMES setting\r
+#endif\r
+static FATFS *FatFs[_VOLUMES]; /* Pointer to the file system objects (logical drives) */\r
+static WORD Fsid;                              /* File system mount ID */\r
+\r
+#if _FS_RPATH != 0 && _VOLUMES >= 2\r
+static BYTE CurrVol;                   /* Current drive */\r
+#endif\r
+\r
+#if _FS_LOCK != 0\r
+static FILESEM Files[_FS_LOCK];        /* Open object lock semaphores */\r
+#endif\r
+\r
+#if _USE_LFN == 0                      /* Non-LFN configuration */\r
+#define        DEF_NAMBUF                      BYTE sfn[12]\r
+#define INIT_NAMBUF(dobj)      (dobj).fn = sfn\r
+#define        FREE_NAMBUF()\r
+#define        DEF_DIRBUF\r
+#define INIT_DIRBUF(fs)\r
+#define        FREE_DIRBUF()\r
+#else\r
+#if _MAX_LFN < 12 || _MAX_LFN > 255\r
+#error Wrong _MAX_LFN setting\r
+#endif\r
+\r
+#if _USE_LFN == 1              /* LFN enabled with static working buffer */\r
+#if _FS_EXFAT\r
+static BYTE    DirBuf[SZDIRE*19];      /* Directory entry block scratchpad buffer (19 entries in size) */\r
+#endif\r
+static WCHAR LfnBuf[_MAX_LFN+1];       /* LFN enabled with static working buffer */\r
+#define        DEF_NAMBUF              BYTE sfn[12]\r
+#define INIT_NAMBUF(dj)        { (dj).fn = sfn; (dj).lfn = LfnBuf; }\r
+#define        FREE_NAMBUF()\r
+#define        DEF_DIRBUF\r
+#define INIT_DIRBUF(fs)\r
+#define        FREE_DIRBUF()\r
+\r
+#elif _USE_LFN == 2    /* LFN enabled with dynamic working buffer on the stack */\r
+#if _FS_EXFAT\r
+#define        DEF_NAMBUF              BYTE sfn[12]; WCHAR lbuf[_MAX_LFN+1]; BYTE dbuf[SZDIRE*19]\r
+#define INIT_NAMBUF(dj)        { (dj).fn = sfn; (dj).lfn = lbuf; (dj).obj.fs->dirbuf = dbuf; }\r
+#define        FREE_NAMBUF()\r
+#define        DEF_DIRBUF              BYTE dbuf[SZDIRE*19]\r
+#define INIT_DIRBUF(fs)        fs->dirbuf = dbuf\r
+#define        FREE_DIRBUF()\r
+#else\r
+#define        DEF_NAMBUF              BYTE sfn[12]; WCHAR lbuf[_MAX_LFN+1]\r
+#define INIT_NAMBUF(dj)        { (dj).fn = sfn; (dj).lfn = lbuf; }\r
+#define        FREE_NAMBUF()\r
+#define        DEF_DIRBUF\r
+#define INIT_DIRBUF(fs)\r
+#define        FREE_DIRBUF()\r
+#endif\r
+\r
+#elif _USE_LFN == 3    /* LFN enabled with dynamic working buffer on the heap */\r
+#if _FS_EXFAT\r
+#define        DEF_NAMBUF              BYTE sfn[12]; WCHAR *lfn\r
+#define INIT_NAMBUF(dj)        { lfn = ff_memalloc((_MAX_LFN+1)*2 + SZDIRE*19); if (!lfn) LEAVE_FF((dj).obj.fs, FR_NOT_ENOUGH_CORE); (dj).fn = sfn; (dj).lfn = lfn; (dj).obj.fs->dirbuf = (BYTE*)(lfn+_MAX_LFN+1); }\r
+#define        FREE_NAMBUF()   ff_memfree(lfn)\r
+#define        DEF_DIRBUF              BYTE *dirb\r
+#define INIT_DIRBUF(fs)        { dirb = ff_memalloc(SZDIRE*19); if (!dirb) LEAVE_FF(fs, FR_NOT_ENOUGH_CORE); fs->dirbuf = dirb; }\r
+#define        FREE_DIRBUF()   ff_memfree(dirb)\r
+#else\r
+#define        DEF_NAMBUF              BYTE sfn[12]; WCHAR *lfn\r
+#define INIT_NAMBUF(dj)        { lfn = ff_memalloc((_MAX_LFN+1)*2); if (!lfn) LEAVE_FF((dj).obj.fs, FR_NOT_ENOUGH_CORE); (dj).fn = sfn; (dj).lfn = lfn; }\r
+#define        FREE_NAMBUF()   ff_memfree(lfn)\r
+#define        DEF_DIRBUF\r
+#define INIT_DIRBUF(fs)\r
+#define        FREE_DIRBUF()\r
+#endif\r
+\r
+#else\r
+#error Wrong _USE_LFN setting\r
+#endif\r
+#endif\r
+\r
+#ifdef _EXCVT\r
+static const BYTE ExCvt[] = _EXCVT;    /* Upper conversion table for SBCS extended characters */\r
+#endif\r
+\r
+\r
+\r
+\r
+\r
+\r
+/*--------------------------------------------------------------------------\r
+\r
+   Module Private Functions\r
+\r
+---------------------------------------------------------------------------*/\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Load/Store multi-byte word in the FAT structure                       */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+static\r
+WORD ld_word (const BYTE* ptr) /*       Load a 2-byte little-endian word */\r
+{\r
+       WORD rv;\r
+\r
+       rv = ptr[1];\r
+       rv = rv << 8 | ptr[0];\r
+       return rv;\r
+}\r
+\r
+static\r
+DWORD ld_dword (const BYTE* ptr)       /* Load a 4-byte little-endian word */\r
+{\r
+       DWORD rv;\r
+\r
+       rv = ptr[3];\r
+       rv = rv << 8 | ptr[2];\r
+       rv = rv << 8 | ptr[1];\r
+       rv = rv << 8 | ptr[0];\r
+       return rv;\r
+}\r
+\r
+#if _FS_EXFAT\r
+static\r
+QWORD ld_qword (const BYTE* ptr)       /* Load an 8-byte little-endian word */\r
+{\r
+       QWORD rv;\r
+\r
+       rv = ptr[7];\r
+       rv = rv << 8 | ptr[6];\r
+       rv = rv << 8 | ptr[5];\r
+       rv = rv << 8 | ptr[4];\r
+       rv = rv << 8 | ptr[3];\r
+       rv = rv << 8 | ptr[2];\r
+       rv = rv << 8 | ptr[1];\r
+       rv = rv << 8 | ptr[0];\r
+       return rv;\r
+}\r
+#endif\r
+\r
+#if !_FS_READONLY\r
+static\r
+void st_word (BYTE* ptr, WORD val)     /* Store a 2-byte word in little-endian */\r
+{\r
+       *ptr++ = (BYTE)val; val >>= 8;\r
+       *ptr++ = (BYTE)val;\r
+}\r
+\r
+static\r
+void st_dword (BYTE* ptr, DWORD val)   /* Store a 4-byte word in little-endian */\r
+{\r
+       *ptr++ = (BYTE)val; val >>= 8;\r
+       *ptr++ = (BYTE)val; val >>= 8;\r
+       *ptr++ = (BYTE)val; val >>= 8;\r
+       *ptr++ = (BYTE)val;\r
+}\r
+\r
+#if _FS_EXFAT\r
+static\r
+void st_qword (BYTE* ptr, QWORD val)   /* Store an 8-byte word in little-endian */\r
+{\r
+       *ptr++ = (BYTE)val; val >>= 8;\r
+       *ptr++ = (BYTE)val; val >>= 8;\r
+       *ptr++ = (BYTE)val; val >>= 8;\r
+       *ptr++ = (BYTE)val; val >>= 8;\r
+       *ptr++ = (BYTE)val; val >>= 8;\r
+       *ptr++ = (BYTE)val; val >>= 8;\r
+       *ptr++ = (BYTE)val; val >>= 8;\r
+       *ptr++ = (BYTE)val;\r
+}\r
+#endif\r
+#endif /* !_FS_READONLY */\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* String functions                                                      */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+/* Copy memory to memory */\r
+static\r
+void mem_cpy (void* dst, const void* src, UINT cnt) {\r
+       BYTE *d = (BYTE*)dst;\r
+       const BYTE *s = (const BYTE*)src;\r
+\r
+       if (cnt) {\r
+               do *d++ = *s++; while (--cnt);\r
+       }\r
+}\r
+\r
+/* Fill memory block */\r
+static\r
+void mem_set (void* dst, int val, UINT cnt) {\r
+       BYTE *d = (BYTE*)dst;\r
+\r
+       do *d++ = (BYTE)val; while (--cnt);\r
+}\r
+\r
+/* Compare memory block */\r
+static\r
+int mem_cmp (const void* dst, const void* src, UINT cnt) {     /* ZR:same, NZ:different */\r
+       const BYTE *d = (const BYTE *)dst, *s = (const BYTE *)src;\r
+       int r = 0;\r
+\r
+       do {\r
+               r = *d++ - *s++;\r
+       } while (--cnt && r == 0);\r
+\r
+       return r;\r
+}\r
+\r
+/* Check if chr is contained in the string */\r
+static\r
+int chk_chr (const char* str, int chr) {       /* NZ:contained, ZR:not contained */\r
+       while (*str && *str != chr) str++;\r
+       return *str;\r
+}\r
+\r
+WCHAR ff_convert (WCHAR wch, UINT dir)\r
+{\r
+    if (wch < 0x80) {\r
+        return wch;\r
+    }\r
+    return 0;\r
+}\r
+\r
+WCHAR ff_wtoupper (WCHAR wch)\r
+{\r
+    if (wch < 0x80) {\r
+        if (wch >= 'a' && wch <= 'z') {\r
+            wch &= ~0x20;\r
+        }\r
+        return wch;\r
+    }\r
+    else\r
+        return 0;\r
+}\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Request/Release grant to access the volume                            */\r
+/*-----------------------------------------------------------------------*/\r
+#if _FS_REENTRANT\r
+static\r
+int lock_fs (\r
+       FATFS* fs               /* File system object */\r
+)\r
+{\r
+       return ff_req_grant(fs->sobj);\r
+}\r
+\r
+\r
+static\r
+void unlock_fs (\r
+       FATFS* fs,              /* File system object */\r
+       FRESULT res             /* Result code to be returned */\r
+)\r
+{\r
+       if (fs && res != FR_NOT_ENABLED && res != FR_INVALID_DRIVE && res != FR_TIMEOUT) {\r
+               ff_rel_grant(fs->sobj);\r
+       }\r
+}\r
+#endif\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* File lock control functions                                           */\r
+/*-----------------------------------------------------------------------*/\r
+#if _FS_LOCK != 0\r
+\r
+static\r
+FRESULT chk_lock (     /* Check if the file can be accessed */\r
+       DIR* dp,                /* Directory object pointing the file to be checked */\r
+       int acc                 /* Desired access type (0:Read, 1:Write, 2:Delete/Rename) */\r
+)\r
+{\r
+       UINT i, be;\r
+\r
+       /* Search file semaphore table */\r
+       for (i = be = 0; i < _FS_LOCK; i++) {\r
+               if (Files[i].fs) {      /* Existing entry */\r
+                       if (Files[i].fs == dp->obj.fs &&                /* Check if the object matched with an open object */\r
+                               Files[i].clu == dp->obj.sclust &&\r
+                               Files[i].ofs == dp->dptr) break;\r
+               } else {                        /* Blank entry */\r
+                       be = 1;\r
+               }\r
+       }\r
+       if (i == _FS_LOCK) {    /* The object is not opened */\r
+               return (be || acc == 2) ? FR_OK : FR_TOO_MANY_OPEN_FILES;       /* Is there a blank entry for new object? */\r
+       }\r
+\r
+       /* The object has been opened. Reject any open against writing file and all write mode open */\r
+       return (acc || Files[i].ctr == 0x100) ? FR_LOCKED : FR_OK;\r
+}\r
+\r
+\r
+static\r
+int enq_lock (void)    /* Check if an entry is available for a new object */\r
+{\r
+       UINT i;\r
+\r
+       for (i = 0; i < _FS_LOCK && Files[i].fs; i++) ;\r
+       return (i == _FS_LOCK) ? 0 : 1;\r
+}\r
+\r
+\r
+static\r
+UINT inc_lock (        /* Increment object open counter and returns its index (0:Internal error) */\r
+       DIR* dp,        /* Directory object pointing the file to register or increment */\r
+       int acc         /* Desired access (0:Read, 1:Write, 2:Delete/Rename) */\r
+)\r
+{\r
+       UINT i;\r
+\r
+\r
+       for (i = 0; i < _FS_LOCK; i++) {        /* Find the object */\r
+               if (Files[i].fs == dp->obj.fs &&\r
+                       Files[i].clu == dp->obj.sclust &&\r
+                       Files[i].ofs == dp->dptr) break;\r
+       }\r
+\r
+       if (i == _FS_LOCK) {                            /* Not opened. Register it as new. */\r
+               for (i = 0; i < _FS_LOCK && Files[i].fs; i++) ;\r
+               if (i == _FS_LOCK) return 0;    /* No free entry to register (int err) */\r
+               Files[i].fs = dp->obj.fs;\r
+               Files[i].clu = dp->obj.sclust;\r
+               Files[i].ofs = dp->dptr;\r
+               Files[i].ctr = 0;\r
+       }\r
+\r
+       if (acc && Files[i].ctr) return 0;      /* Access violation (int err) */\r
+\r
+       Files[i].ctr = acc ? 0x100 : Files[i].ctr + 1;  /* Set semaphore value */\r
+\r
+       return i + 1;\r
+}\r
+\r
+\r
+static\r
+FRESULT dec_lock (     /* Decrement object open counter */\r
+       UINT i                  /* Semaphore index (1..) */\r
+)\r
+{\r
+       WORD n;\r
+       FRESULT res;\r
+\r
+\r
+       if (--i < _FS_LOCK) {   /* Shift index number origin from 0 */\r
+               n = Files[i].ctr;\r
+               if (n == 0x100) n = 0;          /* If write mode open, delete the entry */\r
+               if (n > 0) n--;                         /* Decrement read mode open count */\r
+               Files[i].ctr = n;\r
+               if (n == 0) Files[i].fs = 0;    /* Delete the entry if open count gets zero */\r
+               res = FR_OK;\r
+       } else {\r
+               res = FR_INT_ERR;                       /* Invalid index nunber */\r
+       }\r
+       return res;\r
+}\r
+\r
+\r
+static\r
+void clear_lock (      /* Clear lock entries of the volume */\r
+       FATFS *fs\r
+)\r
+{\r
+       UINT i;\r
+\r
+       for (i = 0; i < _FS_LOCK; i++) {\r
+               if (Files[i].fs == fs) Files[i].fs = 0;\r
+       }\r
+}\r
+#endif\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Move/Flush disk access window in the file system object               */\r
+/*-----------------------------------------------------------------------*/\r
+#if !_FS_READONLY\r
+static\r
+FRESULT sync_window (  /* Returns FR_OK or FR_DISK_ERROR */\r
+       FATFS* fs                       /* File system object */\r
+)\r
+{\r
+       DWORD wsect;\r
+       UINT nf;\r
+       FRESULT res = FR_OK;\r
+\r
+\r
+       if (fs->wflag) {        /* Write back the sector if it is dirty */\r
+               wsect = fs->winsect;    /* Current sector number */\r
+               if (disk_write(fs->drv, fs->win, wsect, 1) != RES_OK) {\r
+                       res = FR_DISK_ERR;\r
+               } else {\r
+                       fs->wflag = 0;\r
+                       if (wsect - fs->fatbase < fs->fsize) {          /* Is it in the FAT area? */\r
+                               for (nf = fs->n_fats; nf >= 2; nf--) {  /* Reflect the change to all FAT copies */\r
+                                       wsect += fs->fsize;\r
+                                       disk_write(fs->drv, fs->win, wsect, 1);\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       return res;\r
+}\r
+#endif\r
+\r
+\r
+static\r
+FRESULT move_window (  /* Returns FR_OK or FR_DISK_ERROR */\r
+       FATFS* fs,                      /* File system object */\r
+       DWORD sector            /* Sector number to make appearance in the fs->win[] */\r
+)\r
+{\r
+       FRESULT res = FR_OK;\r
+\r
+\r
+       if (sector != fs->winsect) {    /* Window offset changed? */\r
+#if !_FS_READONLY\r
+               res = sync_window(fs);          /* Write-back changes */\r
+#endif\r
+               if (res == FR_OK) {                     /* Fill sector window with new data */\r
+                       if (disk_read(fs->drv, fs->win, sector, 1) != RES_OK) {\r
+                               sector = 0xFFFFFFFF;    /* Invalidate window if data is not reliable */\r
+                               res = FR_DISK_ERR;\r
+                       }\r
+                       fs->winsect = sector;\r
+               }\r
+       }\r
+       return res;\r
+}\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Synchronize file system and strage device                             */\r
+/*-----------------------------------------------------------------------*/\r
+#if !_FS_READONLY\r
+static\r
+FRESULT sync_fs (      /* FR_OK:succeeded, !=0:error */\r
+       FATFS* fs               /* File system object */\r
+)\r
+{\r
+       FRESULT res;\r
+\r
+\r
+       res = sync_window(fs);\r
+       if (res == FR_OK) {\r
+               /* Update FSInfo sector if needed */\r
+               if (fs->fs_type == FS_FAT32 && fs->fsi_flag == 1) {\r
+                       /* Create FSInfo structure */\r
+                       mem_set(fs->win, 0, SS(fs));\r
+                       st_word(fs->win + BS_55AA, 0xAA55);\r
+                       st_dword(fs->win + FSI_LeadSig, 0x41615252);\r
+                       st_dword(fs->win + FSI_StrucSig, 0x61417272);\r
+                       st_dword(fs->win + FSI_Free_Count, fs->free_clst);\r
+                       st_dword(fs->win + FSI_Nxt_Free, fs->last_clst);\r
+                       /* Write it into the FSInfo sector */\r
+                       fs->winsect = fs->volbase + 1;\r
+                       disk_write(fs->drv, fs->win, fs->winsect, 1);\r
+                       fs->fsi_flag = 0;\r
+               }\r
+               /* Make sure that no pending write process in the physical drive */\r
+               if (disk_ioctl(fs->drv, CTRL_SYNC, 0) != RES_OK) res = FR_DISK_ERR;\r
+       }\r
+\r
+       return res;\r
+}\r
+#endif\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Get sector# from cluster#                                             */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+static\r
+DWORD clust2sect (     /* !=0:Sector number, 0:Failed (invalid cluster#) */\r
+       FATFS* fs,              /* File system object */\r
+       DWORD clst              /* Cluster# to be converted */\r
+)\r
+{\r
+       clst -= 2;\r
+       if (clst >= fs->n_fatent - 2) return 0;         /* Invalid cluster# */\r
+       return clst * fs->csize + fs->database;\r
+}\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* FAT access - Read value of a FAT entry                                */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+static\r
+DWORD get_fat (        /* 0xFFFFFFFF:Disk error, 1:Internal error, 2..0x7FFFFFFF:Cluster status */\r
+       _FDID* obj,     /* Corresponding object */\r
+       DWORD clst      /* Cluster number to get the value */\r
+)\r
+{\r
+       UINT wc, bc;\r
+       DWORD val;\r
+       FATFS *fs = obj->fs;\r
+\r
+\r
+       if (clst < 2 || clst >= fs->n_fatent) { /* Check if in valid range */\r
+               val = 1;        /* Internal error */\r
+\r
+       } else {\r
+               val = 0xFFFFFFFF;       /* Default value falls on disk error */\r
+\r
+               switch (fs->fs_type) {\r
+               case FS_FAT12 :\r
+                       bc = (UINT)clst; bc += bc / 2;\r
+                       if (move_window(fs, fs->fatbase + (bc / SS(fs))) != FR_OK) break;\r
+                       wc = fs->win[bc++ % SS(fs)];\r
+                       if (move_window(fs, fs->fatbase + (bc / SS(fs))) != FR_OK) break;\r
+                       wc |= fs->win[bc % SS(fs)] << 8;\r
+                       val = clst & 1 ? wc >> 4 : (wc & 0xFFF);\r
+                       break;\r
+\r
+               case FS_FAT16 :\r
+                       if (move_window(fs, fs->fatbase + (clst / (SS(fs) / 2))) != FR_OK) break;\r
+                       val = ld_word(&fs->win[clst * 2 % SS(fs)]);\r
+                       break;\r
+\r
+               case FS_FAT32 :\r
+                       if (move_window(fs, fs->fatbase + (clst / (SS(fs) / 4))) != FR_OK) break;\r
+                       val = ld_dword(&fs->win[clst * 4 % SS(fs)]) & 0x0FFFFFFF;\r
+                       break;\r
+#if _FS_EXFAT\r
+               case FS_EXFAT :\r
+                       if (obj->objsize) {\r
+                               DWORD cofs = clst - obj->sclust;        /* Offset from start cluster */\r
+                               DWORD clen = (DWORD)((obj->objsize - 1) / SS(fs)) / fs->csize;  /* Number of clusters - 1 */\r
+\r
+                               if (obj->stat == 2) {   /* Is there no valid chain on the FAT? */\r
+                                       if (cofs <= clen) {\r
+                                               val = (cofs == clen) ? 0x7FFFFFFF : clst + 1;   /* Generate the value */\r
+                                               break;\r
+                                       }\r
+                               }\r
+                               if (obj->stat == 3 && cofs < obj->n_cont) {     /* Is it in the contiguous part? */\r
+                                       val = clst + 1;         /* Generate the value */\r
+                                       break;\r
+                               }\r
+                               if (obj->stat != 2) {   /* Get value from FAT if FAT chain is valid */\r
+                                       if (move_window(fs, fs->fatbase + (clst / (SS(fs) / 4))) != FR_OK) break;\r
+                                       val = ld_dword(&fs->win[clst * 4 % SS(fs)]) & 0x7FFFFFFF;\r
+                                       break;\r
+                               }\r
+                       }\r
+                       /* Go default */\r
+#endif\r
+               default:\r
+                       val = 1;        /* Internal error */\r
+               }\r
+       }\r
+\r
+       return val;\r
+}\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* FAT access - Change value of a FAT entry                              */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+#if !_FS_READONLY\r
+static\r
+FRESULT put_fat (      /* FR_OK(0):succeeded, !=0:error */\r
+       FATFS* fs,              /* Corresponding object */\r
+       DWORD clst,             /* FAT index number (cluster number) to be changed */\r
+       DWORD val               /* New value to be set to the entry */\r
+)\r
+{\r
+       UINT bc;\r
+       BYTE *p;\r
+       FRESULT res = FR_INT_ERR;\r
+\r
+\r
+       if (clst >= 2 && clst < fs->n_fatent) { /* Check if in valid range */\r
+               switch (fs->fs_type) {\r
+               case FS_FAT12 : /* Bitfield items */\r
+                       bc = (UINT)clst; bc += bc / 2;\r
+                       res = move_window(fs, fs->fatbase + (bc / SS(fs)));\r
+                       if (res != FR_OK) break;\r
+                       p = &fs->win[bc++ % SS(fs)];\r
+                       *p = (clst & 1) ? ((*p & 0x0F) | ((BYTE)val << 4)) : (BYTE)val;\r
+                       fs->wflag = 1;\r
+                       res = move_window(fs, fs->fatbase + (bc / SS(fs)));\r
+                       if (res != FR_OK) break;\r
+                       p = &fs->win[bc % SS(fs)];\r
+                       *p = (clst & 1) ? (BYTE)(val >> 4) : ((*p & 0xF0) | ((BYTE)(val >> 8) & 0x0F));\r
+                       fs->wflag = 1;\r
+                       break;\r
+\r
+               case FS_FAT16 : /* WORD aligned items */\r
+                       res = move_window(fs, fs->fatbase + (clst / (SS(fs) / 2)));\r
+                       if (res != FR_OK) break;\r
+                       st_word(&fs->win[clst * 2 % SS(fs)], (WORD)val);\r
+                       fs->wflag = 1;\r
+                       break;\r
+\r
+               case FS_FAT32 : /* DWORD aligned items */\r
+#if _FS_EXFAT\r
+               case FS_EXFAT :\r
+#endif\r
+                       res = move_window(fs, fs->fatbase + (clst / (SS(fs) / 4)));\r
+                       if (res != FR_OK) break;\r
+                       if (!_FS_EXFAT || fs->fs_type != FS_EXFAT) {\r
+                               val = (val & 0x0FFFFFFF) | (ld_dword(&fs->win[clst * 4 % SS(fs)]) & 0xF0000000);\r
+                       }\r
+                       st_dword(&fs->win[clst * 4 % SS(fs)], val);\r
+                       fs->wflag = 1;\r
+                       break;\r
+               }\r
+       }\r
+       return res;\r
+}\r
+#endif /* !_FS_READONLY */\r
+\r
+\r
+\r
+\r
+#if _FS_EXFAT && !_FS_READONLY\r
+/*-----------------------------------------------------------------------*/\r
+/* exFAT: Accessing FAT and Allocation Bitmap                            */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+/*---------------------------------------------*/\r
+/* exFAT: Find a contiguous free cluster block */\r
+/*---------------------------------------------*/\r
+static\r
+DWORD find_bitmap (    /* 0:No free cluster, 2..:Free cluster found, 0xFFFFFFFF:Disk error */\r
+       FATFS* fs,      /* File system object */\r
+       DWORD clst,     /* Cluster number to scan from */\r
+       DWORD ncl       /* Number of contiguous clusters to find (1..) */\r
+)\r
+{\r
+       BYTE bm, bv;\r
+       UINT i;\r
+       DWORD val, scl, ctr;\r
+\r
+\r
+       clst -= 2;      /* The first bit in the bitmap corresponds to cluster #2 */\r
+       if (clst >= fs->n_fatent - 2) clst = 0;\r
+       scl = val = clst; ctr = 0;\r
+       for (;;) {\r
+               if (move_window(fs, fs->database + val / 8 / SS(fs)) != FR_OK) return 0xFFFFFFFF;\r
+               i = val / 8 & (SS(fs) - 1); bm = 1 << (val % 8);\r
+               do {\r
+                       do {\r
+                               bv = fs->win[i] & bm; bm <<= 1;         /* Get bit value */\r
+                               if (++val >= fs->n_fatent - 2) {        /* Next cluster (with wrap-around) */\r
+                                       val = 0; bm = 0; i = 4096;\r
+                               }\r
+                               if (!bv) {      /* Is it a free cluster? */\r
+                                       if (++ctr == ncl) return scl + 2;       /* Check run length */\r
+                               } else {\r
+                                       scl = val; ctr = 0;             /* Encountered a live cluster, restart to scan */\r
+                               }\r
+                               if (val == clst) return 0;      /* All cluster scanned? */\r
+                       } while (bm);\r
+                       bm = 1;\r
+               } while (++i < SS(fs));\r
+       }\r
+}\r
+\r
+/*------------------------------------*/\r
+/* exFAT: Set/Clear a block of bitmap */\r
+/*------------------------------------*/\r
+static\r
+FRESULT change_bitmap (\r
+       FATFS* fs,      /* File system object */\r
+       DWORD clst,     /* Cluster number to change from */\r
+       DWORD ncl,      /* Number of clusters to be changed */\r
+       int bv          /* bit value to be set (0 or 1) */\r
+)\r
+{\r
+       BYTE bm;\r
+       UINT i;\r
+       DWORD sect;\r
+\r
+\r
+       clst -= 2;      /* The first bit corresponds to cluster #2 */\r
+       sect = fs->database + clst / 8 / SS(fs);        /* Sector address */\r
+       i = clst / 8 & (SS(fs) - 1);                            /* Byte offset in the sector */\r
+       bm = 1 << (clst % 8);                                           /* Bit mask in the byte */\r
+       for (;;) {\r
+               if (move_window(fs, sect++) != FR_OK) return FR_DISK_ERR;\r
+               do {\r
+                       do {\r
+                               if (bv == (int)((fs->win[i] & bm) != 0)) return FR_INT_ERR;     /* Is the bit expected value? */\r
+                               fs->win[i] ^= bm;       /* Flip the bit */\r
+                               fs->wflag = 1;\r
+                               if (--ncl == 0) return FR_OK;   /* All bits processed? */\r
+                       } while (bm <<= 1);             /* Next bit */\r
+                       bm = 1;\r
+               } while (++i < SS(fs));         /* Next byte */\r
+       }\r
+}\r
+\r
+\r
+/*---------------------------------------------*/\r
+/* Complement contiguous part of the FAT chain */\r
+/*---------------------------------------------*/\r
+static\r
+FRESULT fill_fat_chain (\r
+       _FDID* obj      /* Pointer to the corresponding object */\r
+)\r
+{\r
+       FRESULT res;\r
+       DWORD cl, n;\r
+\r
+       if (obj->stat == 3) {   /* Has the object got fragmented? */\r
+               for (cl = obj->sclust, n = obj->n_cont; n; cl++, n--) { /* Create cluster chain on the FAT */\r
+                       res = put_fat(obj->fs, cl, cl + 1);\r
+                       if (res != FR_OK) return res;\r
+               }\r
+               obj->stat = 0;  /* Change status 'FAT chain is valid' */\r
+       }\r
+       return FR_OK;\r
+}\r
+\r
+#endif\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* FAT handling - Remove a cluster chain                                 */\r
+/*-----------------------------------------------------------------------*/\r
+#if !_FS_READONLY\r
+static\r
+FRESULT remove_chain ( /* FR_OK(0):succeeded, !=0:error */\r
+       _FDID* obj,                     /* Corresponding object */\r
+       DWORD clst,                     /* Cluster to remove a chain from */\r
+       DWORD pclst                     /* Previous cluster of clst (0:an entire chain) */\r
+)\r
+{\r
+       FRESULT res = FR_OK;\r
+       DWORD nxt;\r
+       FATFS *fs = obj->fs;\r
+#if _FS_EXFAT || _USE_TRIM\r
+       DWORD scl = clst, ecl = clst;\r
+#endif\r
+#if _USE_TRIM\r
+       DWORD rt[2];\r
+#endif\r
+\r
+       if (clst < 2 || clst >= fs->n_fatent) return FR_INT_ERR;        /* Check if in valid range */\r
+\r
+       /* Mark the previous cluster 'EOC' on the FAT if it exists */\r
+       if (pclst && (!_FS_EXFAT || fs->fs_type != FS_EXFAT || obj->stat != 2)) {\r
+               res = put_fat(fs, pclst, 0xFFFFFFFF);\r
+               if (res != FR_OK) return res;\r
+       }\r
+\r
+       /* Remove the chain */\r
+       do {\r
+               nxt = get_fat(obj, clst);                       /* Get cluster status */\r
+               if (nxt == 0) break;                            /* Empty cluster? */\r
+               if (nxt == 1) return FR_INT_ERR;        /* Internal error? */\r
+               if (nxt == 0xFFFFFFFF) return FR_DISK_ERR;      /* Disk error? */\r
+               if (!_FS_EXFAT || fs->fs_type != FS_EXFAT) {\r
+                       res = put_fat(fs, clst, 0);             /* Mark the cluster 'free' on the FAT */\r
+                       if (res != FR_OK) return res;\r
+               }\r
+               if (fs->free_clst != 0xFFFFFFFF) {      /* Update FSINFO */\r
+                       fs->free_clst++;\r
+                       fs->fsi_flag |= 1;\r
+               }\r
+#if _FS_EXFAT || _USE_TRIM\r
+               if (ecl + 1 == nxt) {   /* Is next cluster contiguous? */\r
+                       ecl = nxt;\r
+               } else {                                /* End of contiguous cluster block */ \r
+#if _FS_EXFAT\r
+                       if (fs->fs_type == FS_EXFAT) {\r
+                               res = change_bitmap(fs, scl, ecl - scl + 1, 0); /* Mark the cluster block 'free' on the bitmap */\r
+                               if (res != FR_OK) return res;\r
+                       }\r
+#endif\r
+#if _USE_TRIM\r
+                       rt[0] = clust2sect(fs, scl);                                    /* Start sector */\r
+                       rt[1] = clust2sect(fs, ecl) + fs->csize - 1;    /* End sector */\r
+                       disk_ioctl(fs->drv, CTRL_TRIM, rt);                             /* Inform device the block can be erased */\r
+#endif\r
+                       scl = ecl = nxt;\r
+               }\r
+#endif\r
+               clst = nxt;                                     /* Next cluster */\r
+       } while (clst < fs->n_fatent);  /* Repeat while not the last link */\r
+\r
+#if _FS_EXFAT\r
+       if (fs->fs_type == FS_EXFAT) {\r
+               if (pclst == 0) {       /* Does object have no chain? */\r
+                       obj->stat = 0;          /* Change the object status 'initial' */\r
+               } else {\r
+                       if (obj->stat == 3 && pclst >= obj->sclust && pclst <= obj->sclust + obj->n_cont) {     /* Did the chain got contiguous? */\r
+                               obj->stat = 2;  /* Change the object status 'contiguous' */\r
+                       }\r
+               }\r
+       }\r
+#endif\r
+       return FR_OK;\r
+}\r
+#endif\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* FAT handling - Stretch a chain or Create a new chain                  */\r
+/*-----------------------------------------------------------------------*/\r
+#if !_FS_READONLY\r
+static\r
+DWORD create_chain (   /* 0:No free cluster, 1:Internal error, 0xFFFFFFFF:Disk error, >=2:New cluster# */\r
+       _FDID* obj,                     /* Corresponding object */\r
+       DWORD clst                      /* Cluster# to stretch, 0:Create a new chain */\r
+)\r
+{\r
+       DWORD cs, ncl, scl;\r
+       FRESULT res;\r
+       FATFS *fs = obj->fs;\r
+\r
+\r
+       if (clst == 0) {        /* Create a new chain */\r
+               scl = fs->last_clst;                            /* Get suggested cluster to start at */\r
+               if (scl == 0 || scl >= fs->n_fatent) scl = 1;\r
+       }\r
+       else {                          /* Stretch current chain */\r
+               cs = get_fat(obj, clst);                        /* Check the cluster status */\r
+               if (cs < 2) return 1;                           /* Invalid value */\r
+               if (cs == 0xFFFFFFFF) return cs;        /* A disk error occurred */\r
+               if (cs < fs->n_fatent) return cs;       /* It is already followed by next cluster */\r
+               scl = clst;\r
+       }\r
+\r
+#if _FS_EXFAT\r
+       if (fs->fs_type == FS_EXFAT) {  /* At the exFAT */\r
+               ncl = find_bitmap(fs, scl, 1);                          /* Find a free cluster */\r
+               if (ncl == 0 || ncl == 0xFFFFFFFF) return ncl;  /* No free cluster or hard error? */\r
+               res = change_bitmap(fs, ncl, 1, 1);                     /* Mark the cluster 'in use' */\r
+               if (res == FR_INT_ERR) return 1;\r
+               if (res == FR_DISK_ERR) return 0xFFFFFFFF;\r
+               if (clst == 0) {                                                        /* Is it a new chain? */\r
+                       obj->stat = 2;                                                  /* Set status 'contiguous chain' */\r
+               } else {                                                                        /* This is a stretched chain */\r
+                       if (obj->stat == 2 && ncl != scl + 1) { /* Is the chain got fragmented? */\r
+                               obj->n_cont = scl - obj->sclust;        /* Set size of the contiguous part */\r
+                               obj->stat = 3;                                          /* Change status 'just fragmented' */\r
+                       }\r
+               }\r
+       } else\r
+#endif\r
+       {       /* At the FAT12/16/32 */\r
+               ncl = scl;      /* Start cluster */\r
+               for (;;) {\r
+                       ncl++;                                                  /* Next cluster */\r
+                       if (ncl >= fs->n_fatent) {              /* Check wrap-around */\r
+                               ncl = 2;\r
+                               if (ncl > scl) return 0;        /* No free cluster */\r
+                       }\r
+                       cs = get_fat(obj, ncl);                 /* Get the cluster status */\r
+                       if (cs == 0) break;                             /* Found a free cluster */\r
+                       if (cs == 1 || cs == 0xFFFFFFFF) return cs;     /* An error occurred */\r
+                       if (ncl == scl) return 0;               /* No free cluster */\r
+               }\r
+       }\r
+\r
+       if (_FS_EXFAT && fs->fs_type == FS_EXFAT && obj->stat == 2) {   /* Is it a contiguous chain? */\r
+               res = FR_OK;                                            /* FAT does not need to be written */\r
+       } else {\r
+               res = put_fat(fs, ncl, 0xFFFFFFFF);     /* Mark the new cluster 'EOC' */\r
+               if (res == FR_OK && clst) {\r
+                       res = put_fat(fs, clst, ncl);   /* Link it from the previous one if needed */\r
+               }\r
+       }\r
+\r
+       if (res == FR_OK) {                     /* Update FSINFO if function succeeded. */\r
+               fs->last_clst = ncl;\r
+               if (fs->free_clst < fs->n_fatent - 2) fs->free_clst--;\r
+               fs->fsi_flag |= 1;\r
+       } else {\r
+               ncl = (res == FR_DISK_ERR) ? 0xFFFFFFFF : 1;    /* Failed. Create error status */\r
+       }\r
+\r
+       return ncl;             /* Return new cluster number or error status */\r
+}\r
+#endif /* !_FS_READONLY */\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* FAT handling - Convert offset into cluster with link map table        */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+#if _USE_FASTSEEK\r
+static\r
+DWORD clmt_clust (     /* <2:Error, >=2:Cluster number */\r
+       FIL* fp,                /* Pointer to the file object */\r
+       DWORD ofs               /* File offset to be converted to cluster# */\r
+)\r
+{\r
+       DWORD cl, ncl, *tbl;\r
+       FATFS *fs = fp->obj.fs;\r
+\r
+\r
+       tbl = fp->cltbl + 1;    /* Top of CLMT */\r
+       cl = ofs / SS(fs) / fs->csize;  /* Cluster order from top of the file */\r
+       for (;;) {\r
+               ncl = *tbl++;                   /* Number of cluters in the fragment */\r
+               if (ncl == 0) return 0; /* End of table? (error) */\r
+               if (cl < ncl) break;    /* In this fragment? */\r
+               cl -= ncl; tbl++;               /* Next fragment */\r
+       }\r
+       return cl + *tbl;       /* Return the cluster number */\r
+}\r
+#endif /* _USE_FASTSEEK */\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Directory handling - Set directory index                              */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+static\r
+FRESULT dir_sdi (      /* FR_OK(0):succeeded, !=0:error */\r
+       DIR* dp,                /* Pointer to directory object */\r
+       DWORD ofs               /* Offset of directory table */\r
+)\r
+{\r
+       DWORD csz, clst;\r
+       FATFS *fs = dp->obj.fs;\r
+\r
+\r
+       if (ofs >= (DWORD)((_FS_EXFAT && fs->fs_type == FS_EXFAT) ? MAX_DIR_EX : MAX_DIR) || ofs % SZDIRE) {    /* Check range of offset and alignment */\r
+               return FR_INT_ERR;\r
+       }\r
+       dp->dptr = ofs;                         /* Set current offset */\r
+       clst = dp->obj.sclust;          /* Table start cluster (0:root) */\r
+       if (clst == 0 && fs->fs_type >= FS_FAT32) {     /* Replace cluster# 0 with root cluster# */\r
+               clst = fs->dirbase;\r
+               if (_FS_EXFAT) dp->obj.stat = 0;        /* exFAT: Root dir has an FAT chain */\r
+       }\r
+\r
+       if (clst == 0) {        /* Static table (root-directory in FAT12/16) */\r
+               if (ofs / SZDIRE >= fs->n_rootdir)      return FR_INT_ERR;      /* Is index out of range? */\r
+               dp->sect = fs->dirbase;\r
+\r
+       } else {                        /* Dynamic table (sub-directory or root-directory in FAT32+) */\r
+               csz = (DWORD)fs->csize * SS(fs);        /* Bytes per cluster */\r
+               while (ofs >= csz) {                            /* Follow cluster chain */\r
+                       clst = get_fat(&dp->obj, clst);                         /* Get next cluster */\r
+                       if (clst == 0xFFFFFFFF) return FR_DISK_ERR;     /* Disk error */\r
+                       if (clst < 2 || clst >= fs->n_fatent) return FR_INT_ERR;        /* Reached to end of table or internal error */\r
+                       ofs -= csz;\r
+               }\r
+               dp->sect = clust2sect(fs, clst);\r
+       }\r
+       dp->clust = clst;                                       /* Current cluster# */\r
+       if (!dp->sect) return FR_INT_ERR;\r
+       dp->sect += ofs / SS(fs);                       /* Sector# of the directory entry */\r
+       dp->dir = fs->win + (ofs % SS(fs));     /* Pointer to the entry in the win[] */\r
+\r
+       return FR_OK;\r
+}\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Directory handling - Move directory table index next                  */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+static\r
+FRESULT dir_next (     /* FR_OK(0):succeeded, FR_NO_FILE:End of table, FR_DENIED:Could not stretch */\r
+       DIR* dp,                /* Pointer to the directory object */\r
+       int stretch             /* 0: Do not stretch table, 1: Stretch table if needed */\r
+)\r
+{\r
+       DWORD ofs, clst;\r
+       FATFS *fs = dp->obj.fs;\r
+#if !_FS_READONLY\r
+       UINT n;\r
+#endif\r
+\r
+       ofs = dp->dptr + SZDIRE;        /* Next entry */\r
+       if (!dp->sect || ofs >= (DWORD)((_FS_EXFAT && fs->fs_type == FS_EXFAT) ? MAX_DIR_EX : MAX_DIR)) return FR_NO_FILE;      /* Report EOT when offset has reached max value */\r
+\r
+       if (ofs % SS(fs) == 0) {        /* Sector changed? */\r
+               dp->sect++;                             /* Next sector */\r
+\r
+               if (!dp->clust) {               /* Static table */\r
+                       if (ofs / SZDIRE >= fs->n_rootdir) {    /* Report EOT if it reached end of static table */\r
+                               dp->sect = 0; return FR_NO_FILE;\r
+                       }\r
+               }\r
+               else {                                  /* Dynamic table */\r
+                       if ((ofs / SS(fs) & (fs->csize - 1)) == 0) {            /* Cluster changed? */\r
+                               clst = get_fat(&dp->obj, dp->clust);                    /* Get next cluster */\r
+                               if (clst <= 1) return FR_INT_ERR;                               /* Internal error */\r
+                               if (clst == 0xFFFFFFFF) return FR_DISK_ERR;             /* Disk error */\r
+                               if (clst >= fs->n_fatent) {                                             /* Reached end of dynamic table */\r
+#if !_FS_READONLY\r
+                                       if (!stretch) {                                                         /* If no stretch, report EOT */\r
+                                               dp->sect = 0; return FR_NO_FILE;\r
+                                       }\r
+                                       clst = create_chain(&dp->obj, dp->clust);       /* Allocate a cluster */\r
+                                       if (clst == 0) return FR_DENIED;                        /* No free cluster */\r
+                                       if (clst == 1) return FR_INT_ERR;                       /* Internal error */\r
+                                       if (clst == 0xFFFFFFFF) return FR_DISK_ERR;     /* Disk error */\r
+                                       /* Clean-up the stretched table */\r
+                                       if (_FS_EXFAT) dp->obj.stat |= 4;                       /* The directory needs to be updated */\r
+                                       if (sync_window(fs) != FR_OK) return FR_DISK_ERR;       /* Flush disk access window */\r
+                                       mem_set(fs->win, 0, SS(fs));                            /* Clear window buffer */\r
+                                       for (n = 0, fs->winsect = clust2sect(fs, clst); n < fs->csize; n++, fs->winsect++) {    /* Fill the new cluster with 0 */\r
+                                               fs->wflag = 1;\r
+                                               if (sync_window(fs) != FR_OK) return FR_DISK_ERR;\r
+                                       }\r
+                                       fs->winsect -= n;                                                       /* Restore window offset */\r
+#else\r
+                                       if (!stretch) dp->sect = 0;                                     /* If no stretch, report EOT (this is to suppress warning) */\r
+                                       dp->sect = 0; return FR_NO_FILE;                        /* Report EOT */\r
+#endif\r
+                               }\r
+                               dp->clust = clst;               /* Initialize data for new cluster */\r
+                               dp->sect = clust2sect(fs, clst);\r
+                       }\r
+               }\r
+       }\r
+       dp->dptr = ofs;                                         /* Current entry */\r
+       dp->dir = &fs->win[ofs % SS(fs)];       /* Pointer to the entry in the win[] */\r
+\r
+       return FR_OK;\r
+}\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Directory handling - Reserve a block of directory entries             */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+#if !_FS_READONLY\r
+static\r
+FRESULT dir_alloc (    /* FR_OK(0):succeeded, !=0:error */\r
+       DIR* dp,                /* Pointer to the directory object */\r
+       UINT nent               /* Number of contiguous entries to allocate */\r
+)\r
+{\r
+       FRESULT res;\r
+       UINT n;\r
+       FATFS *fs = dp->obj.fs;\r
+\r
+\r
+       res = dir_sdi(dp, 0);\r
+       if (res == FR_OK) {\r
+               n = 0;\r
+               do {\r
+                       res = move_window(fs, dp->sect);\r
+                       if (res != FR_OK) break;\r
+#if _FS_EXFAT\r
+                       if (fs->fs_type == FS_EXFAT ? (int)((dp->dir[XDIR_Type] & 0x80) == 0) : (int)(dp->dir[DIR_Name] == DDEM || dp->dir[DIR_Name] == 0)) {\r
+#else\r
+                       if (dp->dir[DIR_Name] == DDEM || dp->dir[DIR_Name] == 0) {\r
+#endif\r
+                               if (++n == nent) break; /* A block of contiguous free entries is found */\r
+                       } else {\r
+                               n = 0;                                  /* Not a blank entry. Restart to search */\r
+                       }\r
+                       res = dir_next(dp, 1);\r
+               } while (res == FR_OK); /* Next entry with table stretch enabled */\r
+       }\r
+\r
+       if (res == FR_NO_FILE) res = FR_DENIED; /* No directory entry to allocate */\r
+       return res;\r
+}\r
+#endif\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* FAT: Directory handling - Load/Store start cluster number             */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+static\r
+DWORD ld_clust (       /* Returns the top cluster value of the SFN entry */\r
+       FATFS* fs,              /* Pointer to the fs object */\r
+       const BYTE* dir /* Pointer to the key entry */\r
+)\r
+{\r
+       DWORD cl;\r
+\r
+       cl = ld_word(dir + DIR_FstClusLO);\r
+       if (fs->fs_type == FS_FAT32) {\r
+               cl |= (DWORD)ld_word(dir + DIR_FstClusHI) << 16;\r
+       }\r
+\r
+       return cl;\r
+}\r
+\r
+\r
+#if !_FS_READONLY\r
+static\r
+void st_clust (\r
+       FATFS* fs,      /* Pointer to the fs object */\r
+       BYTE* dir,      /* Pointer to the key entry */\r
+       DWORD cl        /* Value to be set */\r
+)\r
+{\r
+       st_word(dir + DIR_FstClusLO, (WORD)cl);\r
+       if (fs->fs_type == FS_FAT32) {\r
+               st_word(dir + DIR_FstClusHI, (WORD)(cl >> 16));\r
+       }\r
+}\r
+#endif\r
+\r
+\r
+\r
+\r
+/*------------------------------------------------------------------------*/\r
+/* FAT-LFN: LFN handling                                                  */\r
+/*------------------------------------------------------------------------*/\r
+#if _USE_LFN != 0\r
+static\r
+const BYTE LfnOfs[] = {1,3,5,7,9,14,16,18,20,22,24,28,30};     /* Offset of LFN characters in the directory entry */\r
+\r
+/*--------------------------------------------------------*/\r
+/* FAT-LFN: Compare a part of file name with an LFN entry */\r
+/*--------------------------------------------------------*/\r
+static\r
+int cmp_lfn (                          /* 1:matched, 0:not matched */\r
+       const WCHAR* lfnbuf,    /* Pointer to the LFN working buffer to be compared */\r
+       BYTE* dir                               /* Pointer to the directory entry containing the part of LFN */\r
+)\r
+{\r
+       UINT i, s;\r
+       WCHAR wc, uc;\r
+\r
+\r
+       if (ld_word(dir + LDIR_FstClusLO) != 0) return 0;       /* Check LDIR_FstClusLO */\r
+\r
+       i = ((dir[LDIR_Ord] & 0x3F) - 1) * 13;  /* Offset in the LFN buffer */\r
+\r
+       for (wc = 1, s = 0; s < 13; s++) {              /* Process all characters in the entry */\r
+               uc = ld_word(dir + LfnOfs[s]);          /* Pick an LFN character */\r
+               if (wc) {\r
+                       if (i >= _MAX_LFN || ff_wtoupper(uc) != ff_wtoupper(lfnbuf[i++])) {     /* Compare it */\r
+                               return 0;                                       /* Not matched */\r
+                       }\r
+                       wc = uc;\r
+               } else {\r
+                       if (uc != 0xFFFF) return 0;             /* Check filler */\r
+               }\r
+       }\r
+\r
+       if ((dir[LDIR_Ord] & LLEF) && wc && lfnbuf[i]) return 0;        /* Last segment matched but different length */\r
+\r
+       return 1;               /* The part of LFN matched */\r
+}\r
+\r
+\r
+\r
+#if _FS_MINIMIZE <= 1 || _FS_EXFAT\r
+/*-----------------------------------------------------*/\r
+/* FAT-LFN: Pick a part of file name from an LFN entry */\r
+/*-----------------------------------------------------*/\r
+static\r
+int pick_lfn (                 /* 1:succeeded, 0:buffer overflow or invalid LFN entry */\r
+       WCHAR* lfnbuf,          /* Pointer to the LFN working buffer */\r
+       BYTE* dir                       /* Pointer to the LFN entry */\r
+)\r
+{\r
+       UINT i, s;\r
+       WCHAR wc, uc;\r
+\r
+\r
+       if (ld_word(dir + LDIR_FstClusLO) != 0) return 0;       /* Check LDIR_FstClusLO */\r
+\r
+       i = ((dir[LDIR_Ord] & 0x3F) - 1) * 13;  /* Offset in the LFN buffer */\r
+\r
+       for (wc = 1, s = 0; s < 13; s++) {              /* Process all characters in the entry */\r
+               uc = ld_word(dir + LfnOfs[s]);          /* Pick an LFN character */\r
+               if (wc) {\r
+                       if (i >= _MAX_LFN) return 0;    /* Buffer overflow? */\r
+                       lfnbuf[i++] = wc = uc;                  /* Store it */\r
+               } else {\r
+                       if (uc != 0xFFFF) return 0;             /* Check filler */\r
+               }\r
+       }\r
+\r
+       if (dir[LDIR_Ord] & LLEF) {                             /* Put terminator if it is the last LFN part */\r
+               if (i >= _MAX_LFN) return 0;            /* Buffer overflow? */\r
+               lfnbuf[i] = 0;\r
+       }\r
+\r
+       return 1;               /* The part of LFN is valid */\r
+}\r
+#endif\r
+\r
+#if !_FS_READONLY\r
+/*-----------------------------------------*/\r
+/* FAT-LFN: Create an entry of LFN entries */\r
+/*-----------------------------------------*/\r
+static\r
+void put_lfn (\r
+       const WCHAR* lfn,       /* Pointer to the LFN */\r
+       BYTE* dir,                      /* Pointer to the LFN entry to be created */\r
+       BYTE ord,                       /* LFN order (1-20) */\r
+       BYTE sum                        /* Checksum of the corresponding SFN */\r
+)\r
+{\r
+       UINT i, s;\r
+       WCHAR wc;\r
+\r
+\r
+       dir[LDIR_Chksum] = sum;                 /* Set checksum */\r
+       dir[LDIR_Attr] = AM_LFN;                /* Set attribute. LFN entry */\r
+       dir[LDIR_Type] = 0;\r
+       st_word(dir + LDIR_FstClusLO, 0);\r
+\r
+       i = (ord - 1) * 13;                             /* Get offset in the LFN working buffer */\r
+       s = wc = 0;\r
+       do {\r
+               if (wc != 0xFFFF) wc = lfn[i++];        /* Get an effective character */\r
+               st_word(dir + LfnOfs[s], wc);           /* Put it */\r
+               if (wc == 0) wc = 0xFFFF;               /* Padding characters for left locations */\r
+       } while (++s < 13);\r
+       if (wc == 0xFFFF || !lfn[i]) ord |= LLEF;       /* Last LFN part is the start of LFN sequence */\r
+       dir[LDIR_Ord] = ord;                    /* Set the LFN order */\r
+}\r
+\r
+#endif\r
+#endif\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* FAT-LFN: Create a Numbered SFN                                        */\r
+/*-----------------------------------------------------------------------*/\r
+#if _USE_LFN != 0 && !_FS_READONLY\r
+static\r
+void gen_numname (\r
+       BYTE* dst,                      /* Pointer to the buffer to store numbered SFN */\r
+       const BYTE* src,        /* Pointer to SFN */\r
+       const WCHAR* lfn,       /* Pointer to LFN */\r
+       UINT seq                        /* Sequence number */\r
+)\r
+{\r
+       BYTE ns[8], c;\r
+       UINT i, j;\r
+       WCHAR wc;\r
+       DWORD sr;\r
+\r
+\r
+       mem_cpy(dst, src, 11);\r
+\r
+       if (seq > 5) {  /* In case of many collisions, generate a hash number instead of sequential number */\r
+               sr = seq;\r
+               while (*lfn) {  /* Create a CRC */\r
+                       wc = *lfn++;\r
+                       for (i = 0; i < 16; i++) {\r
+                               sr = (sr << 1) + (wc & 1);\r
+                               wc >>= 1;\r
+                               if (sr & 0x10000) sr ^= 0x11021;\r
+                       }\r
+               }\r
+               seq = (UINT)sr;\r
+       }\r
+\r
+       /* itoa (hexdecimal) */\r
+       i = 7;\r
+       do {\r
+               c = (seq % 16) + '0';\r
+               if (c > '9') c += 7;\r
+               ns[i--] = c;\r
+               seq /= 16;\r
+       } while (seq);\r
+       ns[i] = '~';\r
+\r
+       /* Append the number */\r
+       for (j = 0; j < i && dst[j] != ' '; j++) {\r
+               if (IsDBCS1(dst[j])) {\r
+                       if (j == i - 1) break;\r
+                       j++;\r
+               }\r
+       }\r
+       do {\r
+               dst[j++] = (i < 8) ? ns[i++] : ' ';\r
+       } while (j < 8);\r
+}\r
+#endif\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* FAT-LFN: Calculate checksum of an SFN entry                           */\r
+/*-----------------------------------------------------------------------*/\r
+#if _USE_LFN != 0\r
+static\r
+BYTE sum_sfn (\r
+       const BYTE* dir         /* Pointer to the SFN entry */\r
+)\r
+{\r
+       BYTE sum = 0;\r
+       UINT n = 11;\r
+\r
+       do sum = (sum >> 1) + (sum << 7) + *dir++; while (--n);\r
+       return sum;\r
+}\r
+#endif\r
+\r
+\r
+\r
+\r
+#if _FS_EXFAT\r
+/*-----------------------------------------------------------------------*/\r
+/* exFAT: Directory handling - Load/Store a block of directory entries   */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+static\r
+WORD xdir_sum (                        /* Get checksum of the directoly block */\r
+       const BYTE* dir         /* Directory entry block to be calculated */\r
+)\r
+{\r
+       UINT i, szblk;\r
+       WORD sum;\r
+\r
+\r
+       szblk = (dir[XDIR_NumSec] + 1) * SZDIRE;\r
+       for (i = sum = 0; i < szblk; i++) {\r
+               if (i == XDIR_SetSum) { /* Skip sum field */\r
+                       i++;\r
+               } else {\r
+                       sum = ((sum & 1) ? 0x8000 : 0) + (sum >> 1) + dir[i];\r
+               }\r
+       }\r
+       return sum;\r
+}\r
+\r
+\r
+\r
+static\r
+WORD xname_sum (               /* Get check sum (to be used as hash) of the name */\r
+       const WCHAR* name       /* File name to be calculated */\r
+)\r
+{\r
+       WCHAR chr;\r
+       WORD sum = 0;\r
+\r
+\r
+       while ((chr = *name++) != 0) {\r
+               chr = ff_wtoupper(chr);         /* File name needs to be ignored case */\r
+               sum = ((sum & 1) ? 0x8000 : 0) + (sum >> 1) + (chr & 0xFF);\r
+               sum = ((sum & 1) ? 0x8000 : 0) + (sum >> 1) + (chr >> 8);\r
+       }\r
+       return sum;\r
+}\r
+\r
+\r
+/*------------------------------------------------------*/\r
+/* exFAT: Get object information from a directory block */\r
+/*------------------------------------------------------*/\r
+static\r
+void get_xdir_info (\r
+       BYTE* dirb,                     /* Pointer to the direcotry entry block 85+C0+C1s */\r
+       FILINFO* fno            /* Buffer to store the extracted file information */\r
+)\r
+{\r
+       UINT di, si, nc;\r
+       WCHAR w;\r
+\r
+       /* Get file name */\r
+#if _LFN_UNICODE\r
+       if (dirb[XDIR_NumName] <= _MAX_LFN) {\r
+               for (si = SZDIRE * 2, di = 0; di < dirb[XDIR_NumName]; si += 2, di++) {\r
+                       if ((si % SZDIRE) == 0) si += 2;        /* Skip entry type field */\r
+                       w = ld_word(dirb + si);                         /* Get a character */\r
+                       fno->fname[di] = w;                                     /* Store it */\r
+               }\r
+       } else {\r
+               di = 0; /* Buffer overflow and inaccessible object */\r
+       }\r
+#else\r
+       for (si = SZDIRE * 2, di = nc = 0; nc < dirb[XDIR_NumName]; si += 2, nc++) {\r
+               if ((si % SZDIRE) == 0) si += 2;        /* Skip entry type field */\r
+               w = ld_word(dirb + si);                         /* Get a character */\r
+               w = ff_convert(w, 0);                           /* Unicode -> OEM */\r
+               if (w == 0) { di = 0; break; }          /* Could not be converted and inaccessible object */\r
+               if (_DF1S && w >= 0x100) {                      /* Put 1st byte if it is a DBC (always false at SBCS cfg) */\r
+                       fno->fname[di++] = (char)(w >> 8);\r
+               }\r
+               if (di >= _MAX_LFN) { di = 0; break; }  /* Buffer overflow and inaccessible object */\r
+               fno->fname[di++] = (char)w;\r
+       }\r
+#endif\r
+       if (di == 0) fno->fname[di++] = '?';    /* Inaccessible object? */\r
+       fno->fname[di] = 0;                                             /* Terminate file name */\r
+\r
+       fno->altname[0] = 0;                                                    /* No SFN */\r
+       fno->fattrib = dirb[XDIR_Attr];                                 /* Attribute */\r
+       fno->fsize = (fno->fattrib & AM_DIR) ? 0 : ld_qword(dirb + XDIR_FileSize);      /* Size */\r
+       fno->ftime = ld_word(dirb + XDIR_ModTime + 0);  /* Time */\r
+       fno->fdate = ld_word(dirb + XDIR_ModTime + 2);  /* Date */\r
+}\r
+\r
+\r
+/*-----------------------------------*/\r
+/* exFAT: Get a directry entry block */\r
+/*-----------------------------------*/\r
+static\r
+FRESULT load_xdir (    /* FR_INT_ERR: invalid entry block */\r
+       DIR* dp                 /* Pointer to the reading direcotry object pointing the 85 entry */\r
+)\r
+{\r
+       FRESULT res;\r
+       UINT i, nent;\r
+       BYTE* dirb = dp->obj.fs->dirbuf;        /* Pointer to the on-memory direcotry entry block 85+C0+C1s */\r
+\r
+\r
+       /* Load 85 entry */\r
+       res = move_window(dp->obj.fs, dp->sect);\r
+       if (res != FR_OK) return res;\r
+       if (dp->dir[XDIR_Type] != 0x85) return FR_INT_ERR;\r
+       mem_cpy(&dirb[0], dp->dir, SZDIRE);\r
+       nent = dirb[XDIR_NumSec] + 1;\r
+\r
+       /* Load C0 entry */\r
+       res = dir_next(dp, 0);\r
+       if (res != FR_OK) return res;\r
+       res = move_window(dp->obj.fs, dp->sect);\r
+       if (res != FR_OK) return res;\r
+       if (dp->dir[XDIR_Type] != 0xC0) return FR_INT_ERR;\r
+       mem_cpy(dirb + SZDIRE, dp->dir, SZDIRE);\r
+\r
+       /* Load C1 entries */\r
+       if (nent < 3 || nent > 19) return FR_NO_FILE;\r
+       i = SZDIRE * 2; nent *= SZDIRE;\r
+       do {\r
+               res = dir_next(dp, 0);\r
+               if (res != FR_OK) return res;\r
+               res = move_window(dp->obj.fs, dp->sect);\r
+               if (res != FR_OK) return res;\r
+               if (dp->dir[XDIR_Type] != 0xC1) return FR_INT_ERR;\r
+               mem_cpy(dirb + i, dp->dir, SZDIRE);\r
+               i += SZDIRE;\r
+       } while (i < nent);\r
+\r
+       /* Sanity check */\r
+       if (xdir_sum(dirb) != ld_word(dirb + XDIR_SetSum)) return FR_INT_ERR;\r
+\r
+       return FR_OK;\r
+}\r
+\r
+\r
+#if !_FS_READONLY || _FS_RPATH != 0 \r
+/*------------------------------------------------*/\r
+/* exFAT: Load the object's directory entry block */\r
+/*------------------------------------------------*/\r
+static\r
+FRESULT load_obj_dir ( \r
+       DIR* dp,                        /* Blank directory object to be used to access containing direcotry */\r
+       const _FDID* obj        /* Object with containing directory information */\r
+)\r
+{\r
+       FRESULT res;\r
+\r
+\r
+       /* Open object containing directory */\r
+       dp->obj.fs = obj->fs;\r
+       dp->obj.sclust = obj->c_scl;\r
+       dp->obj.stat = (BYTE)obj->c_size;\r
+       dp->obj.objsize = obj->c_size & 0xFFFFFF00;\r
+       dp->blk_ofs = obj->c_ofs;\r
+\r
+       res = dir_sdi(dp, dp->blk_ofs); /* Goto the block location */\r
+       if (res == FR_OK) {\r
+               res = load_xdir(dp);            /* Load the object's entry block */\r
+       }\r
+       return res;\r
+}\r
+#endif\r
+\r
+\r
+#if !_FS_READONLY\r
+/*-----------------------------------------------*/\r
+/* exFAT: Store the directory block to the media */\r
+/*-----------------------------------------------*/\r
+static\r
+FRESULT store_xdir (\r
+       DIR* dp                         /* Pointer to the direcotry object */\r
+)\r
+{\r
+       FRESULT res;\r
+       UINT nent;\r
+       WORD sum;\r
+       BYTE* dirb = dp->obj.fs->dirbuf;        /* Pointer to the direcotry entry block 85+C0+C1s */\r
+\r
+       /* Create set sum */\r
+       sum = xdir_sum(dirb);\r
+       st_word(dirb + XDIR_SetSum, sum);\r
+       nent = dirb[XDIR_NumSec] + 1;\r
+\r
+       res = dir_sdi(dp, dp->blk_ofs);\r
+       while (res == FR_OK && (res = move_window(dp->obj.fs, dp->sect)) == FR_OK) {\r
+               mem_cpy(dp->dir, dirb, SZDIRE);\r
+               dp->obj.fs->wflag = 1;\r
+               if (--nent == 0) break;\r
+               dirb += SZDIRE;\r
+               res = dir_next(dp, 0);\r
+       }\r
+       return (res == FR_OK || res == FR_DISK_ERR) ? res : FR_INT_ERR;\r
+}\r
+\r
+\r
+/*-------------------------------------------*/\r
+/* exFAT: Create a new directory enrty block */\r
+/*-------------------------------------------*/\r
+static\r
+void create_xdir (\r
+       BYTE* dirb,                     /* Pointer to the direcotry entry block buffer */\r
+       const WCHAR* lfn        /* Pointer to the nul terminated file name */\r
+)\r
+{\r
+       UINT i;\r
+       BYTE nb, nc;\r
+       WCHAR chr;\r
+       WORD hash;\r
+\r
+\r
+       mem_set(dirb, 0, 2 * SZDIRE);                   /* Initialize 85+C0 entry */\r
+       dirb[XDIR_Type] = 0x85;\r
+       dirb[XDIR_Type + SZDIRE] = 0xC0;\r
+       hash = xname_sum(lfn);\r
+       st_word(dirb + XDIR_NameHash, hash);    /* Set name hash */\r
+\r
+       i = SZDIRE * 2; /* C1 offset */\r
+       nc = 0; nb = 1; chr = 1;\r
+       do {\r
+               dirb[i++] = 0xC1; dirb[i++] = 0;        /* Entry type C1 */\r
+               do {    /* Fill name field */\r
+                       if (chr && (chr = lfn[nc]) != 0) nc++;  /* Get a character if exist */\r
+                       st_word(dirb + i, chr); i += 2; /* Store it */\r
+               } while (i % SZDIRE);\r
+               nb++;\r
+       } while (lfn[nc]);      /* Fill next entry if any char follows */\r
+\r
+       dirb[XDIR_NumName] = nc;        /* Set name length */\r
+       dirb[XDIR_NumSec] = nb;         /* Set number of C0+C1s */\r
+}\r
+#endif\r
+#endif\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Read an object from the directory                                     */\r
+/*-----------------------------------------------------------------------*/\r
+#if _FS_MINIMIZE <= 1 || _FS_RPATH >= 2 || _USE_LABEL || _FS_EXFAT\r
+static\r
+FRESULT dir_read (\r
+       DIR* dp,                /* Pointer to the directory object */\r
+       int vol                 /* Filtered by 0:file/directory or 1:volume label */\r
+)\r
+{\r
+       FRESULT res = FR_NO_FILE;\r
+       FATFS *fs = dp->obj.fs;\r
+       BYTE a, c;\r
+#if _USE_LFN != 0\r
+       BYTE ord = 0xFF, sum = 0xFF;\r
+#endif\r
+\r
+       while (dp->sect) {\r
+               res = move_window(fs, dp->sect);\r
+               if (res != FR_OK) break;\r
+               c = dp->dir[DIR_Name];  /* Test for the entry type */\r
+               if (c == 0) { res = FR_NO_FILE; break; }        /* Reached to end of the directory */\r
+#if _FS_EXFAT\r
+               if (fs->fs_type == FS_EXFAT) {  /* At the exFAT */\r
+                       if (_USE_LABEL && vol) {\r
+                               if (c == 0x83) break;   /* Volume label entry? */\r
+                       } else {\r
+                               if (c == 0x85) {                /* Start of the entry block? */\r
+                                       dp->blk_ofs = dp->dptr; /* Set location of block */\r
+                                       res = load_xdir(dp);    /* Load the entry block */\r
+                                       if (res == FR_OK) {\r
+                                               dp->obj.attr = fs->dirbuf[XDIR_Attr] & AM_MASK; /* Get attribute */\r
+                                       }\r
+                                       break;\r
+                               }\r
+                       }\r
+               } else\r
+#endif\r
+               {       /* At the FAT12/16/32 */\r
+                       dp->obj.attr = a = dp->dir[DIR_Attr] & AM_MASK; /* Get attribute */\r
+#if _USE_LFN != 0      /* LFN configuration */\r
+                       if (c == DDEM || c == '.' || (int)((a & ~AM_ARC) == AM_VOL) != vol) {   /* An entry without valid data */\r
+                               ord = 0xFF;\r
+                       } else {\r
+                               if (a == AM_LFN) {                      /* An LFN entry is found */\r
+                                       if (c & LLEF) {                 /* Is it start of an LFN sequence? */\r
+                                               sum = dp->dir[LDIR_Chksum];\r
+                                               c &= ~LLEF; ord = c;\r
+                                               dp->blk_ofs = dp->dptr;\r
+                                       }\r
+                                       /* Check LFN validity and capture it */\r
+                                       ord = (c == ord && sum == dp->dir[LDIR_Chksum] && pick_lfn(dp->lfn, dp->dir)) ? ord - 1 : 0xFF;\r
+                               } else {                                        /* An SFN entry is found */\r
+                                       if (ord || sum != sum_sfn(dp->dir)) {   /* Is there a valid LFN? */\r
+                                               dp->blk_ofs = 0xFFFFFFFF;                       /* It has no LFN. */\r
+                                       }\r
+                                       break;\r
+                               }\r
+                       }\r
+#else          /* Non LFN configuration */\r
+                       if (c != DDEM && c != '.' && a != AM_LFN && (int)((a & ~AM_ARC) == AM_VOL) == vol) {    /* Is it a valid entry? */\r
+                               break;\r
+                       }\r
+#endif\r
+               }\r
+               res = dir_next(dp, 0);          /* Next entry */\r
+               if (res != FR_OK) break;\r
+       }\r
+\r
+       if (res != FR_OK) dp->sect = 0;         /* Terminate the read operation on error or EOT */\r
+       return res;\r
+}\r
+#endif /* _FS_MINIMIZE <= 1 || _USE_LABEL || _FS_RPATH >= 2 */\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Directory handling - Find an object in the directory                  */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+static\r
+FRESULT dir_find (     /* FR_OK(0):succeeded, !=0:error */\r
+       DIR* dp                 /* Pointer to the directory object with the file name */\r
+)\r
+{\r
+       FRESULT res;\r
+       FATFS *fs = dp->obj.fs;\r
+       BYTE c;\r
+#if _USE_LFN != 0\r
+       BYTE a, ord, sum;\r
+#endif\r
+\r
+       res = dir_sdi(dp, 0);                   /* Rewind directory object */\r
+       if (res != FR_OK) return res;\r
+#if _FS_EXFAT\r
+       if (fs->fs_type == FS_EXFAT) {  /* At the exFAT */\r
+               BYTE nc;\r
+               UINT di, ni;\r
+               WORD hash = xname_sum(dp->lfn);         /* Hash value of the name to find */\r
+\r
+               while ((res = dir_read(dp, 0)) == FR_OK) {      /* Read an item */\r
+                       if (ld_word(fs->dirbuf + XDIR_NameHash) != hash) continue;      /* Skip the comparison if hash value mismatched */\r
+                       for (nc = fs->dirbuf[XDIR_NumName], di = SZDIRE * 2, ni = 0; nc; nc--, di += 2, ni++) { /* Compare the name */\r
+                               if ((di % SZDIRE) == 0) di += 2;\r
+                               if (ff_wtoupper(ld_word(fs->dirbuf + di)) != ff_wtoupper(dp->lfn[ni])) break;\r
+                       }\r
+                       if (nc == 0 && !dp->lfn[ni]) break;     /* Name matched? */\r
+               }\r
+               return res;\r
+       }\r
+#endif\r
+       /* At the FAT12/16/32 */\r
+#if _USE_LFN != 0\r
+       ord = sum = 0xFF; dp->blk_ofs = 0xFFFFFFFF;     /* Reset LFN sequence */\r
+#endif\r
+       do {\r
+               res = move_window(fs, dp->sect);\r
+               if (res != FR_OK) break;\r
+               c = dp->dir[DIR_Name];\r
+               if (c == 0) { res = FR_NO_FILE; break; }        /* Reached to end of table */\r
+#if _USE_LFN != 0      /* LFN configuration */\r
+               dp->obj.attr = a = dp->dir[DIR_Attr] & AM_MASK;\r
+               if (c == DDEM || ((a & AM_VOL) && a != AM_LFN)) {       /* An entry without valid data */\r
+                       ord = 0xFF; dp->blk_ofs = 0xFFFFFFFF;   /* Reset LFN sequence */\r
+               } else {\r
+                       if (a == AM_LFN) {                      /* An LFN entry is found */\r
+                               if (dp->lfn) {\r
+                                       if (c & LLEF) {         /* Is it start of LFN sequence? */\r
+                                               sum = dp->dir[LDIR_Chksum];\r
+                                               c &= ~LLEF; ord = c;    /* LFN start order */\r
+                                               dp->blk_ofs = dp->dptr; /* Start offset of LFN */\r
+                                       }\r
+                                       /* Check validity of the LFN entry and compare it with given name */\r
+                                       ord = (c == ord && sum == dp->dir[LDIR_Chksum] && cmp_lfn(dp->lfn, dp->dir)) ? ord - 1 : 0xFF;\r
+                               }\r
+                       } else {                                        /* An SFN entry is found */\r
+                               if (!ord && sum == sum_sfn(dp->dir)) break;     /* LFN matched? */\r
+                               if (!(dp->fn[NSFLAG] & NS_LOSS) && !mem_cmp(dp->dir, dp->fn, 11)) break;        /* SFN matched? */\r
+                               ord = 0xFF; dp->blk_ofs = 0xFFFFFFFF;   /* Reset LFN sequence */\r
+                       }\r
+               }\r
+#else          /* Non LFN configuration */\r
+               dp->obj.attr = dp->dir[DIR_Attr] & AM_MASK;\r
+               if (!(dp->dir[DIR_Attr] & AM_VOL) && !mem_cmp(dp->dir, dp->fn, 11)) break;      /* Is it a valid entry? */\r
+#endif\r
+               res = dir_next(dp, 0);  /* Next entry */\r
+       } while (res == FR_OK);\r
+\r
+       return res;\r
+}\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Register an object to the directory                                   */\r
+/*-----------------------------------------------------------------------*/\r
+#if !_FS_READONLY\r
+static\r
+FRESULT dir_register ( /* FR_OK:succeeded, FR_DENIED:no free entry or too many SFN collision, FR_DISK_ERR:disk error */\r
+       DIR* dp                         /* Target directory with object name to be created */\r
+)\r
+{\r
+       FRESULT res;\r
+       FATFS *fs = dp->obj.fs;\r
+#if _USE_LFN != 0      /* LFN configuration */\r
+       UINT n, nlen, nent;\r
+       BYTE sn[12], *fn, sum;\r
+       WCHAR *lfn;\r
+\r
+\r
+       fn = dp->fn; lfn = dp->lfn;\r
+       if (fn[NSFLAG] & (NS_DOT | NS_NONAME)) return FR_INVALID_NAME;  /* Check name validity */\r
+       for (nlen = 0; lfn[nlen]; nlen++) ;     /* Get lfn length */\r
+\r
+#if _FS_EXFAT\r
+       if (fs->fs_type == FS_EXFAT) {  /* At the exFAT */\r
+               DIR dj;\r
+\r
+               nent = (nlen + 14) / 15 + 2;    /* Number of entries to allocate (85+C0+C1s) */\r
+               res = dir_alloc(dp, nent);              /* Allocate entries */\r
+               if (res != FR_OK) return res;\r
+               dp->blk_ofs = dp->dptr - SZDIRE * (nent - 1);                   /* Set block position */\r
+\r
+               if (dp->obj.stat & 4) {                 /* Has the sub-directory been stretched? */\r
+                       dp->obj.stat &= 3;\r
+                       dp->obj.objsize += (DWORD)fs->csize * SS(fs);   /* Increase object size by cluster size */\r
+                       res = fill_fat_chain(&dp->obj); /* Complement FAT chain if needed */\r
+                       if (res != FR_OK) return res;\r
+                       res = load_obj_dir(&dj, &dp->obj);\r
+                       if (res != FR_OK) return res;   /* Load the object status */\r
+                       st_qword(fs->dirbuf + XDIR_FileSize, dp->obj.objsize);          /* Update the allocation status */\r
+                       st_qword(fs->dirbuf + XDIR_ValidFileSize, dp->obj.objsize);\r
+                       fs->dirbuf[XDIR_GenFlags] = dp->obj.stat | 1;\r
+                       res = store_xdir(&dj);                  /* Store the object status */\r
+                       if (res != FR_OK) return res;\r
+               }\r
+\r
+               create_xdir(fs->dirbuf, lfn);   /* Create on-memory directory block to be written later */\r
+               return FR_OK;\r
+       }\r
+#endif\r
+       /* At the FAT12/16/32 */\r
+       mem_cpy(sn, fn, 12);\r
+       if (sn[NSFLAG] & NS_LOSS) {                     /* When LFN is out of 8.3 format, generate a numbered name */\r
+               fn[NSFLAG] = 0; dp->lfn = 0;            /* Find only SFN */\r
+               for (n = 1; n < 100; n++) {\r
+                       gen_numname(fn, sn, lfn, n);    /* Generate a numbered name */\r
+                       res = dir_find(dp);                             /* Check if the name collides with existing SFN */\r
+                       if (res != FR_OK) break;\r
+               }\r
+               if (n == 100) return FR_DENIED;         /* Abort if too many collisions */\r
+               if (res != FR_NO_FILE) return res;      /* Abort if the result is other than 'not collided' */\r
+               fn[NSFLAG] = sn[NSFLAG]; dp->lfn = lfn;\r
+       }\r
+\r
+       /* Create an SFN with/without LFNs. */\r
+       nent = (sn[NSFLAG] & NS_LFN) ? (nlen + 12) / 13 + 1 : 1;        /* Number of entries to allocate */\r
+       res = dir_alloc(dp, nent);              /* Allocate entries */\r
+       if (res == FR_OK && --nent) {   /* Set LFN entry if needed */\r
+               res = dir_sdi(dp, dp->dptr - nent * SZDIRE);\r
+               if (res == FR_OK) {\r
+                       sum = sum_sfn(dp->fn);  /* Checksum value of the SFN tied to the LFN */\r
+                       do {                                    /* Store LFN entries in bottom first */\r
+                               res = move_window(fs, dp->sect);\r
+                               if (res != FR_OK) break;\r
+                               put_lfn(dp->lfn, dp->dir, (BYTE)nent, sum);\r
+                               fs->wflag = 1;\r
+                               res = dir_next(dp, 0);  /* Next entry */\r
+                       } while (res == FR_OK && --nent);\r
+               }\r
+       }\r
+\r
+#else  /* Non LFN configuration */\r
+       res = dir_alloc(dp, 1);         /* Allocate an entry for SFN */\r
+\r
+#endif\r
+\r
+       /* Set SFN entry */\r
+       if (res == FR_OK) {\r
+               res = move_window(fs, dp->sect);\r
+               if (res == FR_OK) {\r
+                       mem_set(dp->dir, 0, SZDIRE);    /* Clean the entry */\r
+                       mem_cpy(dp->dir + DIR_Name, dp->fn, 11);        /* Put SFN */\r
+#if _USE_LFN != 0\r
+                       dp->dir[DIR_NTres] = dp->fn[NSFLAG] & (NS_BODY | NS_EXT);       /* Put NT flag */\r
+#endif\r
+                       fs->wflag = 1;\r
+               }\r
+       }\r
+\r
+       return res;\r
+}\r
+#endif /* !_FS_READONLY */\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Remove an object from the directory                                   */\r
+/*-----------------------------------------------------------------------*/\r
+#if !_FS_READONLY && !_FS_MINIMIZE\r
+static\r
+FRESULT dir_remove (   /* FR_OK:Succeeded, FR_DISK_ERR:A disk error */\r
+       DIR* dp                         /* Directory object pointing the entry to be removed */\r
+)\r
+{\r
+       FRESULT res;\r
+       FATFS *fs = dp->obj.fs;\r
+#if _USE_LFN != 0      /* LFN configuration */\r
+       DWORD last = dp->dptr;\r
+\r
+       res = dp->blk_ofs == 0xFFFFFFFF ? FR_OK : dir_sdi(dp, dp->blk_ofs);     /* Goto top of the entry block if LFN is exist */\r
+       if (res == FR_OK) {\r
+               do {\r
+                       res = move_window(fs, dp->sect);\r
+                       if (res != FR_OK) break;\r
+                       /* Mark an entry 'deleted' */\r
+                       if (_FS_EXFAT && fs->fs_type == FS_EXFAT) {     /* At the exFAT */\r
+                               dp->dir[XDIR_Type] &= 0x7F;\r
+                       } else {                                                                        /* At the FAT12/16/32 */\r
+                               dp->dir[DIR_Name] = DDEM;\r
+                       }\r
+                       fs->wflag = 1;\r
+                       if (dp->dptr >= last) break;    /* If reached last entry then all entries of the object has been deleted. */\r
+                       res = dir_next(dp, 0);  /* Next entry */\r
+               } while (res == FR_OK);\r
+               if (res == FR_NO_FILE) res = FR_INT_ERR;\r
+       }\r
+#else                  /* Non LFN configuration */\r
+\r
+       res = move_window(fs, dp->sect);\r
+       if (res == FR_OK) {\r
+               dp->dir[DIR_Name] = DDEM;\r
+               fs->wflag = 1;\r
+       }\r
+#endif\r
+\r
+       return res;\r
+}\r
+#endif /* !_FS_READONLY */\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Get file information from directory entry                             */\r
+/*-----------------------------------------------------------------------*/\r
+#if _FS_MINIMIZE <= 1 || _FS_RPATH >= 2\r
+static\r
+void get_fileinfo (            /* No return code */\r
+       DIR* dp,                        /* Pointer to the directory object */\r
+       FILINFO* fno            /* Pointer to the file information to be filled */\r
+)\r
+{\r
+       UINT i, j;\r
+       TCHAR c;\r
+#if _USE_LFN != 0\r
+       WCHAR w, *lfn;\r
+       WCHAR lfv;\r
+#endif\r
+\r
+\r
+       fno->fname[0] = 0;              /* Invaidate file info */\r
+       if (!dp->sect) return;  /* Exit if read pointer has reached end of directory */\r
+\r
+#if _USE_LFN != 0      /* LFN configuration */\r
+#if _FS_EXFAT\r
+       if (dp->obj.fs->fs_type == FS_EXFAT) {  /* At the exFAT */\r
+               get_xdir_info(dp->obj.fs->dirbuf, fno);\r
+               return;\r
+       } else\r
+#endif\r
+       {       /* At the FAT12/16/32 */\r
+               if (dp->blk_ofs != 0xFFFFFFFF) {        /* Get LFN if available */\r
+                       i = 0; lfn = dp->lfn;\r
+                       while ((w = *lfn++) != 0) {             /* Get an LFN character */\r
+#if !_LFN_UNICODE\r
+                               w = ff_convert(w, 0);           /* Unicode -> OEM */\r
+                               if (w == 0) { i = 0; break; }   /* No LFN if it could not be converted */\r
+                               if (_DF1S && w >= 0x100) {      /* Put 1st byte if it is a DBC (always false at SBCS cfg) */\r
+                                       fno->fname[i++] = (char)(w >> 8);\r
+                               }\r
+#endif\r
+                               if (i >= _MAX_LFN) { i = 0; break; }    /* No LFN if buffer overflow */\r
+                               fno->fname[i++] = (char)w;\r
+                       }\r
+                       fno->fname[i] = 0;      /* Terminate the LFN */\r
+               }\r
+       }\r
+\r
+       i = j = 0;\r
+       lfv = fno->fname[i];    /* LFN is exist if non-zero */\r
+       while (i < 11) {                /* Copy name body and extension */\r
+               c = (TCHAR)dp->dir[i++];\r
+               if (c == ' ') continue;                         /* Skip padding spaces */\r
+               if (c == RDDEM) c = (TCHAR)DDEM;        /* Restore replaced DDEM character */\r
+               if (i == 9) {                                           /* Insert a . if extension is exist */\r
+                       if (!lfv) fno->fname[j] = '.';\r
+                       fno->altname[j++] = '.';\r
+               }\r
+#if _LFN_UNICODE\r
+               if (IsDBCS1(c) && i != 8 && i != 11 && IsDBCS2(dp->dir[i])) {\r
+                       c = c << 8 | dp->dir[i++];\r
+               }\r
+               c = ff_convert(c, 1);   /* OEM -> Unicode */\r
+               if (!c) c = '?';\r
+#endif\r
+               fno->altname[j] = c;\r
+               if (!lfv) {\r
+                       if (IsUpper(c) && (dp->dir[DIR_NTres] & (i >= 9 ? NS_EXT : NS_BODY))) {\r
+                               c += 0x20;                      /* To lower */\r
+                       }\r
+                       fno->fname[j] = c;\r
+               }\r
+               j++;\r
+       }\r
+       if (!lfv) {\r
+               fno->fname[j] = 0;\r
+               if (!dp->dir[DIR_NTres]) j = 0; /* Altname is no longer needed if neither LFN nor case info is exist. */\r
+       }\r
+       fno->altname[j] = 0;    /* Terminate the SFN */\r
+\r
+#else  /* Non-LFN configuration */\r
+       i = j = 0;\r
+       while (i < 11) {                /* Copy name body and extension */\r
+               c = (TCHAR)dp->dir[i++];\r
+               if (c == ' ') continue;                         /* Skip padding spaces */\r
+               if (c == RDDEM) c = (TCHAR)DDEM;        /* Restore replaced DDEM character */\r
+               if (i == 9) fno->fname[j++] = '.';      /* Insert a . if extension is exist */\r
+               fno->fname[j++] = c;\r
+       }\r
+       fno->fname[j] = 0;\r
+#endif\r
+\r
+       fno->fattrib = dp->dir[DIR_Attr];                               /* Attribute */\r
+       fno->fsize = ld_dword(dp->dir + DIR_FileSize);  /* Size */\r
+       fno->fdate = ld_word(dp->dir + DIR_WrtDate);    /* Date */\r
+       fno->ftime = ld_word(dp->dir + DIR_WrtTime);    /* Time */\r
+}\r
+#endif /* _FS_MINIMIZE <= 1 || _FS_RPATH >= 2 */\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Pattern matching                                                      */\r
+/*-----------------------------------------------------------------------*/\r
+#if _USE_FIND && _FS_MINIMIZE <= 1\r
+static\r
+WCHAR get_achar (              /* Get a character and advances ptr 1 or 2 */\r
+       const TCHAR** ptr       /* Pointer to pointer to the SBCS/DBCS/Unicode string */\r
+)\r
+{\r
+#if !_LFN_UNICODE\r
+       WCHAR chr;\r
+\r
+       chr = (BYTE)*(*ptr)++;                                  /* Get a byte */\r
+       if (IsLower(chr)) chr -= 0x20;                  /* To upper ASCII char */\r
+#ifdef _EXCVT\r
+       if (chr >= 0x80) chr = ExCvt[chr - 0x80];       /* To upper SBCS extended char */\r
+#else\r
+       if (IsDBCS1(chr) && IsDBCS2(**ptr)) {           /* Get DBC 2nd byte if needed */\r
+               chr = chr << 8 | (BYTE)*(*ptr)++;\r
+       }\r
+#endif\r
+       return chr;\r
+#else\r
+       return ff_wtoupper(*(*ptr)++);                  /* Get a word and to upper */\r
+#endif\r
+}\r
+\r
+\r
+static\r
+int pattern_matching ( /* 0:not matched, 1:matched */\r
+       const TCHAR* pat,       /* Matching pattern */\r
+       const TCHAR* nam,       /* String to be tested */\r
+       int skip,                       /* Number of pre-skip chars (number of ?s) */\r
+       int inf                         /* Infinite search (* specified) */\r
+)\r
+{\r
+       const TCHAR *pp, *np;\r
+       WCHAR pc, nc;\r
+       int nm, nx;\r
+\r
+\r
+       while (skip--) {                                /* Pre-skip name chars */\r
+               if (!get_achar(&nam)) return 0; /* Branch mismatched if less name chars */\r
+       }\r
+       if (!*pat && inf) return 1;             /* (short circuit) */\r
+\r
+       do {\r
+               pp = pat; np = nam;                     /* Top of pattern and name to match */\r
+               for (;;) {\r
+                       if (*pp == '?' || *pp == '*') { /* Wildcard? */\r
+                               nm = nx = 0;\r
+                               do {                            /* Analyze the wildcard chars */\r
+                                       if (*pp++ == '?') nm++; else nx = 1;\r
+                               } while (*pp == '?' || *pp == '*');\r
+                               if (pattern_matching(pp, np, nm, nx)) return 1; /* Test new branch (recursions upto number of wildcard blocks in the pattern) */\r
+                               nc = *np; break;        /* Branch mismatched */\r
+                       }\r
+                       pc = get_achar(&pp);    /* Get a pattern char */\r
+                       nc = get_achar(&np);    /* Get a name char */\r
+                       if (pc != nc) break;    /* Branch mismatched? */\r
+                       if (pc == 0) return 1;  /* Branch matched? (matched at end of both strings) */\r
+               }\r
+               get_achar(&nam);                        /* nam++ */\r
+       } while (inf && nc);                    /* Retry until end of name if infinite search is specified */\r
+\r
+       return 0;\r
+}\r
+#endif /* _USE_FIND && _FS_MINIMIZE <= 1 */\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Pick a top segment and create the object name in directory form       */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+static\r
+FRESULT create_name (  /* FR_OK: successful, FR_INVALID_NAME: could not create */\r
+       DIR* dp,                        /* Pointer to the directory object */\r
+       const TCHAR** path      /* Pointer to pointer to the segment in the path string */\r
+)\r
+{\r
+#if _USE_LFN != 0      /* LFN configuration */\r
+       BYTE b, cf;\r
+       WCHAR w, *lfn;\r
+       UINT i, ni, si, di;\r
+       const TCHAR *p;\r
+\r
+       /* Create LFN in Unicode */\r
+       p = *path; lfn = dp->lfn; si = di = 0;\r
+       for (;;) {\r
+               w = p[si++];                                    /* Get a character */\r
+               if (w < ' ' || w == '/' || w == '\\') {         /* Break on end of segment */\r
+                       while (p[si] == '/' || p[si] == '\\') si++;     /* Skip duplicated separator */\r
+                       break;\r
+               }\r
+               if (di >= _MAX_LFN) return FR_INVALID_NAME;     /* Reject too long name */\r
+#if !_LFN_UNICODE\r
+               w &= 0xFF;\r
+               if (IsDBCS1(w)) {                               /* Check if it is a DBC 1st byte (always false on SBCS cfg) */\r
+                       b = (BYTE)p[si++];                      /* Get 2nd byte */\r
+                       w = (w << 8) + b;                       /* Create a DBC */\r
+                       if (!IsDBCS2(b)) return FR_INVALID_NAME;        /* Reject invalid sequence */\r
+               }\r
+               w = ff_convert(w, 1);                   /* Convert ANSI/OEM to Unicode */\r
+               if (!w) return FR_INVALID_NAME; /* Reject invalid code */\r
+#endif\r
+               if (w < 0x80 && chk_chr("\"*:<>\?|\x7F", w)) return FR_INVALID_NAME;    /* Reject illegal characters for LFN */\r
+               lfn[di++] = w;                                  /* Store the Unicode character */\r
+       }\r
+       *path = &p[si];                                         /* Return pointer to the next segment */\r
+       cf = (w < ' ') ? NS_LAST : 0;           /* Set last segment flag if end of path */\r
+#if _FS_RPATH != 0\r
+       if ((di == 1 && lfn[di - 1] == '.') ||\r
+               (di == 2 && lfn[di - 1] == '.' && lfn[di - 2] == '.')) {        /* Is this segment a dot name? */\r
+               lfn[di] = 0;\r
+               for (i = 0; i < 11; i++)                /* Create dot name for SFN entry */\r
+                       dp->fn[i] = (i < di) ? '.' : ' ';\r
+               dp->fn[i] = cf | NS_DOT;                /* This is a dot entry */\r
+               return FR_OK;\r
+       }\r
+#endif\r
+       while (di) {                                            /* Snip off trailing spaces and dots if exist */\r
+               w = lfn[di - 1];\r
+               if (w != ' ' && w != '.') break;\r
+               di--;\r
+       }\r
+       lfn[di] = 0;                                            /* LFN is created */\r
+       if (di == 0) return FR_INVALID_NAME;    /* Reject nul name */\r
+\r
+       /* Create SFN in directory form */\r
+       mem_set(dp->fn, ' ', 11);\r
+       for (si = 0; lfn[si] == ' ' || lfn[si] == '.'; si++) ;  /* Strip leading spaces and dots */\r
+       if (si) cf |= NS_LOSS | NS_LFN;\r
+       while (di && lfn[di - 1] != '.') di--;  /* Find extension (di<=si: no extension) */\r
+\r
+       b = i = 0; ni = 8;\r
+       for (;;) {\r
+               w = lfn[si++];                                  /* Get an LFN character */\r
+               if (!w) break;                                  /* Break on end of the LFN */\r
+               if (w == ' ' || (w == '.' && si != di)) {       /* Remove spaces and dots */\r
+                       cf |= NS_LOSS | NS_LFN; continue;\r
+               }\r
+\r
+               if (i >= ni || si == di) {              /* Extension or end of SFN */\r
+                       if (ni == 11) {                         /* Long extension */\r
+                               cf |= NS_LOSS | NS_LFN; break;\r
+                       }\r
+                       if (si != di) cf |= NS_LOSS | NS_LFN;   /* Out of 8.3 format */\r
+                       if (si > di) break;                     /* No extension */\r
+                       si = di; i = 8; ni = 11;        /* Enter extension section */\r
+                       b <<= 2; continue;\r
+               }\r
+\r
+               if (w >= 0x80) {                                /* Non ASCII character */\r
+#ifdef _EXCVT\r
+                       w = ff_convert(w, 0);           /* Unicode -> OEM code */\r
+                       if (w) w = ExCvt[w - 0x80];     /* Convert extended character to upper (SBCS) */\r
+#else\r
+                       w = ff_convert(ff_wtoupper(w), 0);      /* Upper converted Unicode -> OEM code */\r
+#endif\r
+                       cf |= NS_LFN;                           /* Force create LFN entry */\r
+               }\r
+\r
+               if (_DF1S && w >= 0x100) {              /* Is this DBC? (always false at SBCS cfg) */\r
+                       if (i >= ni - 1) {\r
+                               cf |= NS_LOSS | NS_LFN; i = ni; continue;\r
+                       }\r
+                       dp->fn[i++] = (BYTE)(w >> 8);\r
+               } else {                                                /* SBC */\r
+                       if (!w || chk_chr("+,;=[]", w)) {       /* Replace illegal characters for SFN */\r
+                               w = '_'; cf |= NS_LOSS | NS_LFN;/* Lossy conversion */\r
+                       } else {\r
+                               if (IsUpper(w)) {               /* ASCII large capital */\r
+                                       b |= 2;\r
+                               } else {\r
+                                       if (IsLower(w)) {       /* ASCII small capital */\r
+                                               b |= 1; w -= 0x20;\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+               dp->fn[i++] = (BYTE)w;\r
+       }\r
+\r
+       if (dp->fn[0] == DDEM) dp->fn[0] = RDDEM;       /* If the first character collides with DDEM, replace it with RDDEM */\r
+\r
+       if (ni == 8) b <<= 2;\r
+       if ((b & 0x0C) == 0x0C || (b & 0x03) == 0x03) cf |= NS_LFN;     /* Create LFN entry when there are composite capitals */\r
+       if (!(cf & NS_LFN)) {                                           /* When LFN is in 8.3 format without extended character, NT flags are created */\r
+               if ((b & 0x03) == 0x01) cf |= NS_EXT;   /* NT flag (Extension has only small capital) */\r
+               if ((b & 0x0C) == 0x04) cf |= NS_BODY;  /* NT flag (Filename has only small capital) */\r
+       }\r
+\r
+       dp->fn[NSFLAG] = cf;    /* SFN is created */\r
+\r
+       return FR_OK;\r
+\r
+\r
+#else  /* Non-LFN configuration */\r
+       BYTE b, c, d, *sfn;\r
+       UINT ni, si, i;\r
+       const char *p;\r
+\r
+       /* Create file name in directory form */\r
+       p = *path; sfn = dp->fn;\r
+       mem_set(sfn, ' ', 11);\r
+       si = i = b = 0; ni = 8;\r
+#if _FS_RPATH != 0\r
+       if (p[si] == '.') { /* Is this a dot entry? */\r
+               for (;;) {\r
+                       c = (BYTE)p[si++];\r
+                       if (c != '.' || si >= 3) break;\r
+                       sfn[i++] = c;\r
+               }\r
+               if (c != '/' && c != '\\' && c > ' ') return FR_INVALID_NAME;\r
+               *path = &p[si];                                                                 /* Return pointer to the next segment */\r
+               sfn[NSFLAG] = (c <= ' ') ? NS_LAST | NS_DOT : NS_DOT;   /* Set last segment flag if end of path */\r
+               return FR_OK;\r
+       }\r
+#endif\r
+       for (;;) {\r
+               c = (BYTE)p[si++];\r
+               if (c <= ' ' || c == '/' || c == '\\') {        /* Break on end of segment */\r
+                       while (p[si] == '/' || p[si] == '\\') si++;     /* Skip duplicated separator */\r
+                       break;\r
+               }\r
+               if (c == '.' || i >= ni) {\r
+                       if (ni != 8 || c != '.') return FR_INVALID_NAME;\r
+                       i = 8; ni = 11;\r
+                       b <<= 2; continue;\r
+               }\r
+               if (c >= 0x80) {                                /* Extended character? */\r
+                       b |= 3;                                         /* Eliminate NT flag */\r
+#ifdef _EXCVT\r
+                       c = ExCvt[c - 0x80];            /* To upper extended characters (SBCS cfg) */\r
+#else\r
+#if !_DF1S\r
+                       return FR_INVALID_NAME;         /* Reject extended characters (ASCII cfg) */\r
+#endif\r
+#endif\r
+               }\r
+               if (IsDBCS1(c)) {                               /* Check if it is a DBC 1st byte (always false at SBCS cfg.) */\r
+                       d = (BYTE)p[si++];                      /* Get 2nd byte */\r
+                       if (!IsDBCS2(d) || i >= ni - 1) return FR_INVALID_NAME; /* Reject invalid DBC */\r
+                       sfn[i++] = c;\r
+                       sfn[i++] = d;\r
+               } else {                                                /* SBC */\r
+                       if (chk_chr("\"*+,:;<=>\?[]|\x7F", c)) return FR_INVALID_NAME;  /* Reject illegal chrs for SFN */\r
+                       if (IsUpper(c)) {                       /* ASCII large capital? */\r
+                               b |= 2;\r
+                       } else {\r
+                               if (IsLower(c)) {               /* ASCII small capital? */\r
+                                       b |= 1; c -= 0x20;\r
+                               }\r
+                       }\r
+                       sfn[i++] = c;\r
+               }\r
+       }\r
+       *path = &p[si];                                         /* Return pointer to the next segment */\r
+       c = (c <= ' ') ? NS_LAST : 0;           /* Set last segment flag if end of path */\r
+\r
+       if (i == 0) return FR_INVALID_NAME;     /* Reject nul string */\r
+       if (sfn[0] == DDEM) sfn[0] = RDDEM;     /* When first character collides with DDEM, replace it with RDDEM */\r
+\r
+       if (ni == 8) b <<= 2;\r
+       if ((b & 0x03) == 0x01) c |= NS_EXT;    /* NT flag (Name extension has only small capital) */\r
+       if ((b & 0x0C) == 0x04) c |= NS_BODY;   /* NT flag (Name body has only small capital) */\r
+\r
+       sfn[NSFLAG] = c;                /* Store NT flag, File name is created */\r
+\r
+       return FR_OK;\r
+#endif\r
+}\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Follow a file path                                                    */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+static\r
+FRESULT follow_path (  /* FR_OK(0): successful, !=0: error code */\r
+       DIR* dp,                        /* Directory object to return last directory and found object */\r
+       const TCHAR* path       /* Full-path string to find a file or directory */\r
+)\r
+{\r
+       FRESULT res;\r
+       BYTE ns;\r
+       _FDID *obj = &dp->obj;\r
+       FATFS *fs = obj->fs;\r
+\r
+\r
+#if _FS_RPATH != 0\r
+       if (*path != '/' && *path != '\\') {    /* Without heading separator */\r
+               obj->sclust = fs->cdir;                         /* Start from the current directory */\r
+       } else\r
+#endif\r
+       {                                                                               /* With heading separator */\r
+               while (*path == '/' || *path == '\\') path++;   /* Strip heading separator */\r
+               obj->sclust = 0;                                        /* Start from the root directory */\r
+       }\r
+#if _FS_EXFAT && _FS_RPATH != 0\r
+       if (fs->fs_type == FS_EXFAT && obj->sclust) {   /* Retrieve the sub-directory status if needed */\r
+               DIR dj;\r
+\r
+               obj->c_scl = fs->cdc_scl;\r
+               obj->c_size = fs->cdc_size;\r
+               obj->c_ofs = fs->cdc_ofs;\r
+               res = load_obj_dir(&dj, obj);\r
+               if (res != FR_OK) return res;\r
+               obj->objsize = ld_dword(fs->dirbuf + XDIR_FileSize);\r
+               obj->stat = fs->dirbuf[XDIR_GenFlags] & 2;\r
+       }\r
+#endif\r
+\r
+       if ((UINT)*path < ' ') {                                /* Null path name is the origin directory itself */\r
+               dp->fn[NSFLAG] = NS_NONAME;\r
+               res = dir_sdi(dp, 0);\r
+\r
+       } else {                                                                /* Follow path */\r
+               for (;;) {\r
+                       res = create_name(dp, &path);   /* Get a segment name of the path */\r
+                       if (res != FR_OK) break;\r
+                       res = dir_find(dp);                             /* Find an object with the segment name */\r
+                       ns = dp->fn[NSFLAG];\r
+                       if (res != FR_OK) {                             /* Failed to find the object */\r
+                               if (res == FR_NO_FILE) {        /* Object is not found */\r
+                                       if (_FS_RPATH && (ns & NS_DOT)) {       /* If dot entry is not exist, stay there */\r
+                                               if (!(ns & NS_LAST)) continue;  /* Continue to follow if not last segment */\r
+                                               dp->fn[NSFLAG] = NS_NONAME;\r
+                                               res = FR_OK;\r
+                                       } else {                                                        /* Could not find the object */\r
+                                               if (!(ns & NS_LAST)) res = FR_NO_PATH;  /* Adjust error code if not last segment */\r
+                                       }\r
+                               }\r
+                               break;\r
+                       }\r
+                       if (ns & NS_LAST) break;                        /* Last segment matched. Function completed. */\r
+                       /* Get into the sub-directory */\r
+                       if (!(obj->attr & AM_DIR)) {            /* It is not a sub-directory and cannot follow */\r
+                               res = FR_NO_PATH; break;\r
+                       }\r
+#if _FS_EXFAT\r
+                       if (fs->fs_type == FS_EXFAT) {\r
+                               obj->c_scl = obj->sclust;               /* Save containing directory information for next dir */\r
+                               obj->c_size = ((DWORD)obj->objsize & 0xFFFFFF00) | obj->stat;\r
+                               obj->c_ofs = dp->blk_ofs;\r
+                               obj->sclust = ld_dword(fs->dirbuf + XDIR_FstClus);      /* Open next directory */\r
+                               obj->stat = fs->dirbuf[XDIR_GenFlags] & 2;\r
+                               obj->objsize = ld_qword(fs->dirbuf + XDIR_FileSize);\r
+                       } else\r
+#endif\r
+                       {\r
+                               obj->sclust = ld_clust(fs, &fs->win[dp->dptr % SS(fs)]);        /* Open next directory */\r
+                       }\r
+               }\r
+       }\r
+\r
+       return res;\r
+}\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Get logical drive number from path name                               */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+static\r
+int get_ldnumber (             /* Returns logical drive number (-1:invalid drive) */\r
+       const TCHAR** path      /* Pointer to pointer to the path name */\r
+)\r
+{\r
+       const TCHAR *tp, *tt;\r
+       UINT i;\r
+       int vol = -1;\r
+#if _STR_VOLUME_ID             /* Find string drive id */\r
+       static const char* const str[] = {_VOLUME_STRS};\r
+       const char *sp;\r
+       char c;\r
+       TCHAR tc;\r
+#endif\r
+\r
+\r
+       if (*path) {    /* If the pointer is not a null */\r
+               for (tt = *path; (UINT)*tt >= (_USE_LFN ? ' ' : '!') && *tt != ':'; tt++) ;     /* Find ':' in the path */\r
+               if (*tt == ':') {       /* If a ':' is exist in the path name */\r
+                       tp = *path;\r
+                       i = *tp++ - '0'; \r
+                       if (i < 10 && tp == tt) {       /* Is there a numeric drive id? */\r
+                               if (i < _VOLUMES) {     /* If a drive id is found, get the value and strip it */\r
+                                       vol = (int)i;\r
+                                       *path = ++tt;\r
+                               }\r
+                       }\r
+#if _STR_VOLUME_ID\r
+                        else { /* No numeric drive number, find string drive id */\r
+                               i = 0; tt++;\r
+                               do {\r
+                                       sp = str[i]; tp = *path;\r
+                                       do {    /* Compare a string drive id with path name */\r
+                                               c = *sp++; tc = *tp++;\r
+                                               if (IsLower(tc)) tc -= 0x20;\r
+                                       } while (c && (TCHAR)c == tc);\r
+                               } while ((c || tp != tt) && ++i < _VOLUMES);    /* Repeat for each id until pattern match */\r
+                               if (i < _VOLUMES) {     /* If a drive id is found, get the value and strip it */\r
+                                       vol = (int)i;\r
+                                       *path = tt;\r
+                               }\r
+                       }\r
+#endif\r
+                       return vol;\r
+               }\r
+#if _FS_RPATH != 0 && _VOLUMES >= 2\r
+               vol = CurrVol;  /* Current drive */\r
+#else\r
+               vol = 0;                /* Drive 0 */\r
+#endif\r
+       }\r
+       return vol;\r
+}\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Load a sector and check if it is an FAT boot sector                   */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+static\r
+BYTE check_fs (        /* 0:FAT, 1:exFAT, 2:Valid BS but not FAT, 3:Not a BS, 4:Disk error */\r
+       FATFS* fs,      /* File system object */\r
+       DWORD sect      /* Sector# (lba) to check if it is an FAT boot record or not */\r
+)\r
+{\r
+       fs->wflag = 0; fs->winsect = 0xFFFFFFFF;                /* Invaidate window */\r
+       if (move_window(fs, sect) != FR_OK) return 4;   /* Load boot record */\r
+\r
+       if (ld_word(&fs->win[BS_55AA]) != 0xAA55) return 3;     /* Check boot record signature (always placed at offset 510 even if the sector size is >512) */\r
+\r
+       if ((ld_dword(&fs->win[BS_FilSysType]) & 0xFFFFFF) == 0x544146) return 0;       /* Check "FAT" string */\r
+       if ((ld_dword(&fs->win[BS_FilSysType32]) & 0xFFFFFF) == 0x544146) return 0;     /* Check "FAT" string */\r
+#if _FS_EXFAT\r
+       if (!mem_cmp(&fs->win[BS_OEMName], "EXFAT   ", 8)) return 1;\r
+#endif\r
+       return 2;\r
+}\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Find logical drive and check if the volume is mounted                 */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+static\r
+FRESULT find_volume (  /* FR_OK(0): successful, !=0: any error occurred */\r
+       const TCHAR** path,     /* Pointer to pointer to the path name (drive number) */\r
+       FATFS** rfs,            /* Pointer to pointer to the found file system object */\r
+       BYTE mode                       /* !=0: Check write protection for write access */\r
+)\r
+{\r
+       BYTE fmt, *pt;\r
+       int vol;\r
+       DSTATUS stat;\r
+       DWORD bsect, fasize, tsect, sysect, nclst, szbfat, br[4];\r
+       WORD nrsv;\r
+       FATFS *fs;\r
+       UINT i;\r
+\r
+\r
+       /* Get logical drive number from the path name */\r
+       *rfs = 0;\r
+       vol = get_ldnumber(path);\r
+       if (vol < 0) return FR_INVALID_DRIVE;\r
+\r
+       /* Check if the file system object is valid or not */\r
+       fs = FatFs[vol];                                        /* Get pointer to the file system object */\r
+       if (!fs) return FR_NOT_ENABLED;         /* Is the file system object available? */\r
+\r
+       ENTER_FF(fs);                                           /* Lock the volume */\r
+       *rfs = fs;                                                      /* Return pointer to the file system object */\r
+\r
+       mode &= ~FA_READ;                                       /* Desired access mode, write access or not */\r
+       if (fs->fs_type) {                                      /* If the volume has been mounted */\r
+               stat = disk_status(fs->drv);\r
+               if (!(stat & STA_NOINIT)) {             /* and the physical drive is kept initialized */\r
+                       if (!_FS_READONLY && mode && (stat & STA_PROTECT)) {    /* Check write protection if needed */\r
+                               return FR_WRITE_PROTECTED;\r
+                       }\r
+                       return FR_OK;                           /* The file system object is valid */\r
+               }\r
+       }\r
+\r
+       /* The file system object is not valid. */\r
+       /* Following code attempts to mount the volume. (analyze BPB and initialize the fs object) */\r
+\r
+       fs->fs_type = 0;                                        /* Clear the file system object */\r
+       fs->drv = LD2PD(vol);                           /* Bind the logical drive and a physical drive */\r
+       stat = disk_initialize(fs->drv);        /* Initialize the physical drive */\r
+       if (stat & STA_NOINIT) {                        /* Check if the initialization succeeded */\r
+               return FR_NOT_READY;                    /* Failed to initialize due to no medium or hard error */\r
+       }\r
+       if (!_FS_READONLY && mode && (stat & STA_PROTECT)) { /* Check disk write protection if needed */\r
+               return FR_WRITE_PROTECTED;\r
+       }\r
+#if _MAX_SS != _MIN_SS                                         /* Get sector size (multiple sector size cfg only) */\r
+       if (disk_ioctl(fs->drv, GET_SECTOR_SIZE, &SS(fs)) != RES_OK\r
+               || SS(fs) < _MIN_SS || SS(fs) > _MAX_SS) return FR_DISK_ERR;\r
+#endif\r
+       /* Find an FAT partition on the drive. Supports only generic partitioning, FDISK and SFD. */\r
+       bsect = 0;\r
+       fmt = check_fs(fs, bsect);                      /* Load sector 0 and check if it is an FAT boot sector as SFD */\r
+       if (fmt == 2 || (fmt < 2 && LD2PT(vol))) {      /* Not an FAT boot sector or forced partition number */\r
+               for (i = 0; i < 4; i++) {                       /* Get partition offset */\r
+                       pt = fs->win + MBR_Table + i * SZ_PTE;\r
+                       br[i] = pt[4] ? ld_dword(&pt[8]) : 0;\r
+               }\r
+               i = LD2PT(vol);                                         /* Partition number: 0:auto, 1-4:forced */\r
+               if (i) i--;\r
+               do {                                                            /* Find an FAT volume */\r
+                       bsect = br[i];\r
+                       fmt = bsect ? check_fs(fs, bsect) : 3;  /* Check the partition */\r
+               } while (!LD2PT(vol) && fmt >= 2 && ++i < 4);\r
+       }\r
+       if (fmt == 4) return FR_DISK_ERR;               /* An error occured in the disk I/O layer */\r
+       if (fmt >= 2) return FR_NO_FILESYSTEM;  /* No FAT volume is found */\r
+\r
+       /* An FAT volume is found. Following code initializes the file system object */\r
+\r
+#if _FS_EXFAT\r
+       if (fmt == 1) {\r
+               QWORD maxlba;\r
+\r
+               for (i = BPB_ZeroedEx; i < BPB_ZeroedEx + 53 && !fs->win[i]; i++) ;     /* Check zero filler */\r
+               if (i < BPB_ZeroedEx + 53) return FR_NO_FILESYSTEM;\r
+\r
+               if (ld_word(fs->win + BPB_FSVerEx) != 0x100) return FR_NO_FILESYSTEM;   /* Check exFAT revision (Must be 1.0) */\r
+\r
+               if (1 << fs->win[BPB_BytsPerSecEx] != SS(fs))   /* (BPB_BytsPerSecEx must be equal to the physical sector size) */\r
+                       return FR_NO_FILESYSTEM;\r
+\r
+               maxlba = ld_qword(fs->win + BPB_TotSecEx) + bsect;      /* Number of sectors on the volume */\r
+               if (maxlba >= 0x100000000) return FR_NO_FILESYSTEM;     /* (It cannot be handled in 32-bit LBA) */\r
+\r
+               fs->fsize = ld_dword(fs->win + BPB_FatSzEx);    /* Number of sectors per FAT */\r
+\r
+               fs->n_fats = fs->win[BPB_NumFATsEx];                    /* Number of FATs */\r
+               if (fs->n_fats != 1) return FR_NO_FILESYSTEM;   /* (Must be 1) */\r
+\r
+               fs->csize = 1 << fs->win[BPB_SecPerClusEx];             /* Cluster size */\r
+               if (fs->csize == 0)     return FR_NO_FILESYSTEM;        /* (Must be 1..32768) */\r
+\r
+               nclst = ld_dword(fs->win + BPB_NumClusEx);              /* Number of clusters */\r
+               fs->n_fatent = nclst + 2;\r
+               if (fs->n_fatent >= 0x80000000) return FR_NO_FILESYSTEM;        /* (Must be <= 0x7FFFFFFF) */\r
+\r
+               /* Boundaries and Limits */\r
+               fs->volbase = bsect;\r
+               fs->database = bsect + ld_dword(fs->win + BPB_DataOfsEx);\r
+               fs->fatbase = bsect + ld_dword(fs->win + BPB_FatOfsEx);\r
+               if (maxlba < fs->database + nclst * fs->csize) return FR_NO_FILESYSTEM; /* (Volume size must not be smaller than the size requiered) */\r
+               fs->dirbase = ld_dword(fs->win + BPB_RootClusEx);\r
+\r
+               /* Check if bitmap location is in assumption (at the first cluster) */\r
+               if (move_window(fs, clust2sect(fs, fs->dirbase)) != FR_OK) return FR_DISK_ERR;\r
+               for (i = 0; i < SS(fs); i += SZDIRE) {\r
+                       if (fs->win[i] == 0x81 && ld_dword(fs->win + i + 20) == 2) break;       /* 81 entry with cluster #2? */\r
+               }\r
+               if (i == SS(fs)) return FR_NO_FILESYSTEM;\r
+#if !_FS_READONLY\r
+               fs->last_clst = fs->free_clst = 0xFFFFFFFF;             /* Initialize cluster allocation information */\r
+#endif\r
+#if _USE_LFN == 1\r
+               fs->dirbuf = DirBuf;    /* Static directory block working buuffer */\r
+#endif\r
+               fmt = FS_EXFAT;                 /* FAT sub-type */\r
+       } else\r
+#endif\r
+       {\r
+               if (ld_word(fs->win + BPB_BytsPerSec) != SS(fs)) return FR_NO_FILESYSTEM;       /* (BPB_BytsPerSec must be equal to the physical sector size) */\r
+\r
+               fasize = ld_word(fs->win + BPB_FATSz16);                        /* Number of sectors per FAT */\r
+               if (fasize == 0) fasize = ld_dword(fs->win + BPB_FATSz32);\r
+               fs->fsize = fasize;\r
+\r
+               fs->n_fats = fs->win[BPB_NumFATs];                                      /* Number of FATs */\r
+               if (fs->n_fats != 1 && fs->n_fats != 2) return FR_NO_FILESYSTEM;        /* (Must be 1 or 2) */\r
+               fasize *= fs->n_fats;                                                           /* Number of sectors for FAT area */\r
+\r
+               fs->csize = fs->win[BPB_SecPerClus];                            /* Cluster size */\r
+               if (fs->csize == 0 || (fs->csize & (fs->csize - 1))) return FR_NO_FILESYSTEM;   /* (Must be power of 2) */\r
+\r
+               fs->n_rootdir = ld_word(fs->win + BPB_RootEntCnt);      /* Number of root directory entries */\r
+               if (fs->n_rootdir % (SS(fs) / SZDIRE)) return FR_NO_FILESYSTEM; /* (Must be sector aligned) */\r
+\r
+               tsect = ld_word(fs->win + BPB_TotSec16);                        /* Number of sectors on the volume */\r
+               if (tsect == 0) tsect = ld_dword(fs->win + BPB_TotSec32);\r
+\r
+               nrsv = ld_word(fs->win + BPB_RsvdSecCnt);                       /* Number of reserved sectors */\r
+               if (nrsv == 0) return FR_NO_FILESYSTEM;                         /* (Must not be 0) */\r
+\r
+               /* Determine the FAT sub type */\r
+               sysect = nrsv + fasize + fs->n_rootdir / (SS(fs) / SZDIRE);     /* RSV + FAT + DIR */\r
+               if (tsect < sysect) return FR_NO_FILESYSTEM;            /* (Invalid volume size) */\r
+               nclst = (tsect - sysect) / fs->csize;                           /* Number of clusters */\r
+               if (nclst == 0) return FR_NO_FILESYSTEM;                        /* (Invalid volume size) */\r
+               fmt = FS_FAT12;\r
+               if (nclst >= MIN_FAT16) fmt = FS_FAT16;\r
+               if (nclst >= MIN_FAT32) fmt = FS_FAT32;\r
+\r
+               /* Boundaries and Limits */\r
+               fs->n_fatent = nclst + 2;                                                       /* Number of FAT entries */\r
+               fs->volbase = bsect;                                                            /* Volume start sector */\r
+               fs->fatbase = bsect + nrsv;                                             /* FAT start sector */\r
+               fs->database = bsect + sysect;                                          /* Data start sector */\r
+               if (fmt == FS_FAT32) {\r
+                       if (ld_word(fs->win + BPB_FSVer32) != 0) return FR_NO_FILESYSTEM;       /* (Must be FAT32 revision 0.0) */\r
+                       if (fs->n_rootdir) return FR_NO_FILESYSTEM;             /* (BPB_RootEntCnt must be 0) */\r
+                       fs->dirbase = ld_dword(fs->win + BPB_RootClus32);       /* Root directory start cluster */\r
+                       szbfat = fs->n_fatent * 4;                                              /* (Needed FAT size) */\r
+               } else {\r
+                       if (fs->n_rootdir == 0) return FR_NO_FILESYSTEM;/* (BPB_RootEntCnt must not be 0) */\r
+                       fs->dirbase = fs->fatbase + fasize;                             /* Root directory start sector */\r
+                       szbfat = (fmt == FS_FAT16) ?                                    /* (Needed FAT size) */\r
+                               fs->n_fatent * 2 : fs->n_fatent * 3 / 2 + (fs->n_fatent & 1);\r
+               }\r
+               if (fs->fsize < (szbfat + (SS(fs) - 1)) / SS(fs)) return FR_NO_FILESYSTEM;      /* (BPB_FATSz must not be less than the size needed) */\r
+\r
+#if !_FS_READONLY\r
+               /* Initialize cluster allocation information */\r
+               fs->last_clst = fs->free_clst = 0xFFFFFFFF;\r
+\r
+               /* Get FSINFO if available */\r
+               fs->fsi_flag = 0x80;\r
+#if (_FS_NOFSINFO & 3) != 3\r
+               if (fmt == FS_FAT32                             /* Enable FSINFO only if FAT32 and BPB_FSInfo32 == 1 */\r
+                       && ld_word(fs->win + BPB_FSInfo32) == 1\r
+                       && move_window(fs, bsect + 1) == FR_OK)\r
+               {\r
+                       fs->fsi_flag = 0;\r
+                       if (ld_word(fs->win + BS_55AA) == 0xAA55        /* Load FSINFO data if available */\r
+                               && ld_dword(fs->win + FSI_LeadSig) == 0x41615252\r
+                               && ld_dword(fs->win + FSI_StrucSig) == 0x61417272)\r
+                       {\r
+#if (_FS_NOFSINFO & 1) == 0\r
+                               fs->free_clst = ld_dword(fs->win + FSI_Free_Count);\r
+#endif\r
+#if (_FS_NOFSINFO & 2) == 0\r
+                               fs->last_clst = ld_dword(fs->win + FSI_Nxt_Free);\r
+#endif\r
+                       }\r
+               }\r
+#endif\r
+#endif\r
+       }\r
+\r
+       fs->fs_type = fmt;      /* FAT sub-type */\r
+       fs->id = ++Fsid;        /* File system mount ID */\r
+#if _FS_RPATH != 0\r
+       fs->cdir = 0;           /* Initialize current directory */\r
+#endif\r
+#if _FS_LOCK != 0              /* Clear file lock semaphores */\r
+       clear_lock(fs);\r
+#endif\r
+       return FR_OK;\r
+}\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Check if the file/directory object is valid or not                    */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+static\r
+FRESULT validate (     /* Returns FR_OK or FR_INVALID_OBJECT */\r
+       void* dfp,              /* Pointer to the FIL/DIR object to check validity */\r
+       FATFS** fs              /* Pointer to pointer to the owner file system object to return */\r
+)\r
+{\r
+       _FDID *obj = (_FDID*)dfp;       /* Assuming .obj in the FIL/DIR is the first member */\r
+       FRESULT res;\r
+\r
+\r
+       if (!dfp || !obj->fs || !obj->fs->fs_type || obj->fs->id != obj->id || (disk_status(obj->fs->drv) & STA_NOINIT)) {\r
+               *fs = 0;                                /* The object is invalid */\r
+               res = FR_INVALID_OBJECT;\r
+       } else {\r
+               *fs = obj->fs;                  /* Owner file sytem object */\r
+               ENTER_FF(obj->fs);              /* Lock file system */\r
+               res = FR_OK;\r
+       }\r
+       return res;\r
+}\r
+\r
+\r
+\r
+\r
+/*---------------------------------------------------------------------------\r
+\r
+   Public Functions (FatFs API)\r
+\r
+----------------------------------------------------------------------------*/\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Mount/Unmount a Logical Drive                                         */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+FRESULT f_mount (\r
+       FATFS* fs,                      /* Pointer to the file system object (NULL:unmount)*/\r
+       const TCHAR* path,      /* Logical drive number to be mounted/unmounted */\r
+       BYTE opt                        /* Mode option 0:Do not mount (delayed mount), 1:Mount immediately */\r
+)\r
+{\r
+       FATFS *cfs;\r
+       int vol;\r
+       FRESULT res;\r
+       const TCHAR *rp = path;\r
+\r
+\r
+       vol = get_ldnumber(&rp);\r
+       if (vol < 0) return FR_INVALID_DRIVE;\r
+       cfs = FatFs[vol];                                       /* Pointer to fs object */\r
+\r
+       if (cfs) {\r
+#if _FS_LOCK != 0\r
+               clear_lock(cfs);\r
+#endif\r
+#if _FS_REENTRANT                                              /* Discard sync object of the current volume */\r
+               if (!ff_del_syncobj(cfs->sobj)) return FR_INT_ERR;\r
+#endif\r
+               cfs->fs_type = 0;                               /* Clear old fs object */\r
+       }\r
+\r
+       if (fs) {\r
+               fs->fs_type = 0;                                /* Clear new fs object */\r
+#if _FS_REENTRANT                                              /* Create sync object for the new volume */\r
+               if (!ff_cre_syncobj((BYTE)vol, &fs->sobj)) return FR_INT_ERR;\r
+#endif\r
+       }\r
+       FatFs[vol] = fs;                                        /* Register new fs object */\r
+\r
+       if (!fs || opt != 1) return FR_OK;      /* Do not mount now, it will be mounted later */\r
+\r
+       res = find_volume(&path, &fs, 0);       /* Force mounted the volume */\r
+       LEAVE_FF(fs, res);\r
+}\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Open or Create a File                                                 */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+FRESULT f_open (\r
+       FIL* fp,                        /* Pointer to the blank file object */\r
+       const TCHAR* path,      /* Pointer to the file name */\r
+       BYTE mode                       /* Access mode and file open mode flags */\r
+)\r
+{\r
+       FRESULT res;\r
+       DIR dj;\r
+       FATFS *fs;\r
+#if !_FS_READONLY\r
+       DWORD dw, cl;\r
+#endif\r
+       DEF_NAMBUF;\r
+\r
+\r
+       if (!fp) return FR_INVALID_OBJECT;\r
+       fp->obj.fs = 0;         /* Clear file object */\r
+\r
+       /* Get logical drive number */\r
+       mode &= _FS_READONLY ? FA_READ : FA_READ | FA_WRITE | FA_CREATE_ALWAYS | FA_OPEN_ALWAYS | FA_CREATE_NEW;\r
+       res = find_volume(&path, &fs, mode);\r
+       if (res == FR_OK) {\r
+               dj.obj.fs = fs;\r
+               INIT_NAMBUF(dj);\r
+               res = follow_path(&dj, path);   /* Follow the file path */\r
+#if !_FS_READONLY      /* R/W configuration */\r
+               if (res == FR_OK) {\r
+                       if (dj.fn[NSFLAG] & NS_NONAME) {        /* Origin directory itself? */\r
+                               res = FR_INVALID_NAME;\r
+                       }\r
+#if _FS_LOCK != 0\r
+                       else {\r
+                               res = chk_lock(&dj, (mode & ~FA_READ) ? 1 : 0);\r
+                       }\r
+#endif\r
+               }\r
+               /* Create or Open a file */\r
+               if (mode & (FA_CREATE_ALWAYS | FA_OPEN_ALWAYS | FA_CREATE_NEW)) {\r
+                       if (res != FR_OK) {                                     /* No file, create new */\r
+                               if (res == FR_NO_FILE)                  /* There is no file to open, create a new entry */\r
+#if _FS_LOCK != 0\r
+                                       res = enq_lock() ? dir_register(&dj) : FR_TOO_MANY_OPEN_FILES;\r
+#else\r
+                                       res = dir_register(&dj);\r
+#endif\r
+                               mode |= FA_CREATE_ALWAYS;               /* File is created */\r
+                       }\r
+                       else {                                                          /* Any object is already existing */\r
+                               if (dj.obj.attr & (AM_RDO | AM_DIR)) {  /* Cannot overwrite it (R/O or DIR) */\r
+                                       res = FR_DENIED;\r
+                               } else {\r
+                                       if (mode & FA_CREATE_NEW) res = FR_EXIST;       /* Cannot create as new file */\r
+                               }\r
+                       }\r
+                       if (res == FR_OK && (mode & FA_CREATE_ALWAYS)) {        /* Truncate it if overwrite mode */\r
+                               dw = GET_FATTIME();\r
+#if _FS_EXFAT\r
+                               if (fs->fs_type == FS_EXFAT) {\r
+                                       /* Get current allocation info */\r
+                                       fp->obj.fs = fs;\r
+                                       fp->obj.sclust = ld_dword(fs->dirbuf + XDIR_FstClus);\r
+                                       fp->obj.objsize = ld_qword(fs->dirbuf + XDIR_FileSize);\r
+                                       fp->obj.stat = fs->dirbuf[XDIR_GenFlags] & 2;\r
+                                       /* Initialize directory entry block */\r
+                                       st_dword(fs->dirbuf + XDIR_CrtTime, dw);        /* Set created time */\r
+                                       fs->dirbuf[XDIR_CrtTime10] = 0;\r
+                                       st_dword(fs->dirbuf + XDIR_ModTime, dw);        /* Set modified time */\r
+                                       fs->dirbuf[XDIR_ModTime10] = 0;\r
+                                       fs->dirbuf[XDIR_Attr] = AM_ARC;                         /* Reset attribute */\r
+                                       st_dword(fs->dirbuf + XDIR_FstClus, 0);         /* Reset file allocation info */\r
+                                       st_qword(fs->dirbuf + XDIR_FileSize, 0);\r
+                                       st_qword(fs->dirbuf + XDIR_ValidFileSize, 0);\r
+                                       fs->dirbuf[XDIR_GenFlags] = 1;\r
+                                       res = store_xdir(&dj);\r
+                                       if (res == FR_OK && fp->obj.sclust) {           /* Remove the cluster chain if exist */\r
+                                               res = remove_chain(&fp->obj, fp->obj.sclust, 0);\r
+                                               fs->last_clst = fp->obj.sclust - 1;             /* Reuse the cluster hole */\r
+                                       }\r
+                               } else\r
+#endif\r
+                               {\r
+                                       /* Clean directory info */\r
+                                       st_dword(dj.dir + DIR_CrtTime, dw);     /* Set created time */\r
+                                       st_dword(dj.dir + DIR_WrtTime, dw);     /* Set modified time */\r
+                                       dj.dir[DIR_Attr] = AM_ARC;                      /* Reset attribute */\r
+                                       cl = ld_clust(fs, dj.dir);                      /* Get cluster chain */\r
+                                       st_clust(fs, dj.dir, 0);                        /* Reset file allocation info */\r
+                                       st_dword(dj.dir + DIR_FileSize, 0);\r
+                                       fs->wflag = 1;\r
+\r
+                                       if (cl) {                                                       /* Remove the cluster chain if exist */\r
+                                               dw = fs->winsect;\r
+                                               res = remove_chain(&dj.obj, cl, 0);\r
+                                               if (res == FR_OK) {\r
+                                                       res = move_window(fs, dw);\r
+                                                       fs->last_clst = cl - 1;         /* Reuse the cluster hole */\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+               else {  /* Open an existing file */\r
+                       if (res == FR_OK) {                                     /* Following succeeded */\r
+                               if (dj.obj.attr & AM_DIR) {             /* It is a directory */\r
+                                       res = FR_NO_FILE;\r
+                               } else {\r
+                                       if ((mode & FA_WRITE) && (dj.obj.attr & AM_RDO)) { /* R/O violation */\r
+                                               res = FR_DENIED;\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+               if (res == FR_OK) {\r
+                       if (mode & FA_CREATE_ALWAYS)            /* Set file change flag if created or overwritten */\r
+                               mode |= _FA_MODIFIED;\r
+                       fp->dir_sect = fs->winsect;                     /* Pointer to the directory entry */\r
+                       fp->dir_ptr = dj.dir;\r
+#if _FS_LOCK != 0\r
+                       fp->obj.lockid = inc_lock(&dj, (mode & ~FA_READ) ? 1 : 0);\r
+                       if (!fp->obj.lockid) res = FR_INT_ERR;\r
+#endif\r
+               }\r
+#else          /* R/O configuration */\r
+               if (res == FR_OK) {\r
+                       if (dj.fn[NSFLAG] & NS_NONAME) {        /* Origin directory itself? */\r
+                               res = FR_INVALID_NAME;\r
+                       } else {\r
+                               if (dj.obj.attr & AM_DIR) {             /* It is a directory */\r
+                                       res = FR_NO_FILE;\r
+                               }\r
+                       }\r
+               }\r
+#endif\r
+\r
+               if (res == FR_OK) {\r
+#if _FS_EXFAT\r
+                       if (fs->fs_type == FS_EXFAT) {\r
+                               fp->obj.sclust = ld_dword(fs->dirbuf + XDIR_FstClus);           /* Get allocation info */\r
+                               fp->obj.objsize = ld_qword(fs->dirbuf + XDIR_FileSize);\r
+                               fp->obj.stat = fs->dirbuf[XDIR_GenFlags] & 2;\r
+                               fp->obj.c_scl = dj.obj.sclust;\r
+                               fp->obj.c_size = ((DWORD)dj.obj.objsize & 0xFFFFFF00) | dj.obj.stat;\r
+                               fp->obj.c_ofs = dj.blk_ofs;\r
+                       } else\r
+#endif\r
+                       {\r
+                               fp->obj.sclust = ld_clust(fs, dj.dir);                          /* Get allocation info */\r
+                               fp->obj.objsize = ld_dword(dj.dir + DIR_FileSize);\r
+                       }\r
+#if _USE_FASTSEEK\r
+                       fp->cltbl = 0;                  /* Normal seek mode */\r
+#endif\r
+                       fp->err = 0;                    /* Clear error flag */\r
+                       fp->fptr = 0;                   /* Set file pointer */\r
+                       fp->sect = 0;                   /* Invalidate current data sector */\r
+                       fp->flag = mode;                /* File access mode */\r
+                       fp->obj.fs = fs;                /* Validate the file object */\r
+                       fp->obj.id = fs->id;\r
+               }\r
+\r
+               FREE_NAMBUF();\r
+       }\r
+\r
+       LEAVE_FF(dj.obj.fs, res);\r
+}\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Read File                                                             */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+FRESULT f_read (\r
+       FIL* fp,        /* Pointer to the file object */\r
+       void* buff,     /* Pointer to data buffer */\r
+       UINT btr,       /* Number of bytes to read */\r
+       UINT* br        /* Pointer to number of bytes read */\r
+)\r
+{\r
+       FRESULT res;\r
+       FATFS *fs;\r
+       DWORD clst, sect;\r
+       FSIZE_t remain;\r
+       UINT rcnt, cc, csect;\r
+       BYTE *rbuff = (BYTE*)buff;\r
+\r
+\r
+       *br = 0;        /* Clear read byte counter */\r
+       res = validate(fp, &fs);\r
+       if (res != FR_OK || (res = (FRESULT)fp->err) != FR_OK) LEAVE_FF(fs, res);       /* Check validity */\r
+       if (!(fp->flag & FA_READ)) LEAVE_FF(fs, FR_DENIED); /* Check access mode */\r
+       remain = fp->obj.objsize - fp->fptr;\r
+       if (btr > remain) btr = (UINT)remain;           /* Truncate btr by remaining bytes */\r
+\r
+       for ( ;  btr;                                                           /* Repeat until all data read */\r
+               rbuff += rcnt, fp->fptr += rcnt, *br += rcnt, btr -= rcnt) {\r
+               if ((fp->fptr % SS(fs)) == 0) {                 /* On the sector boundary? */\r
+                       csect = (UINT)(fp->fptr / SS(fs) & (fs->csize - 1));    /* Sector offset in the cluster */\r
+                       if (csect == 0) {                                       /* On the cluster boundary? */\r
+                               if (fp->fptr == 0) {                    /* On the top of the file? */\r
+                                       clst = fp->obj.sclust;          /* Follow cluster chain from the origin */\r
+                               } else {                                                /* Middle or end of the file */\r
+#if _USE_FASTSEEK\r
+                                       if (fp->cltbl) {\r
+                                               clst = clmt_clust(fp, fp->fptr);        /* Get cluster# from the CLMT */\r
+                                       } else\r
+#endif\r
+                                       {\r
+                                               clst = get_fat(&fp->obj, fp->clust);    /* Follow cluster chain on the FAT */\r
+                                       }\r
+                               }\r
+                               if (clst < 2) ABORT(fs, FR_INT_ERR);\r
+                               if (clst == 0xFFFFFFFF) ABORT(fs, FR_DISK_ERR);\r
+                               fp->clust = clst;                               /* Update current cluster */\r
+                       }\r
+                       sect = clust2sect(fs, fp->clust);       /* Get current sector */\r
+                       if (!sect) ABORT(fs, FR_INT_ERR);\r
+                       sect += csect;\r
+                       cc = btr / SS(fs);                                      /* When remaining bytes >= sector size, */\r
+                       if (cc) {                                                       /* Read maximum contiguous sectors directly */\r
+                               if (csect + cc > fs->csize) {   /* Clip at cluster boundary */\r
+                                       cc = fs->csize - csect;\r
+                               }\r
+                               if (disk_read(fs->drv, rbuff, sect, cc) != RES_OK) {\r
+                                       ABORT(fs, FR_DISK_ERR);\r
+                               }\r
+#if !_FS_READONLY && _FS_MINIMIZE <= 2                 /* Replace one of the read sectors with cached data if it contains a dirty sector */\r
+#if _FS_TINY\r
+                               if (fs->wflag && fs->winsect - sect < cc) {\r
+                                       mem_cpy(rbuff + ((fs->winsect - sect) * SS(fs)), fs->win, SS(fs));\r
+                               }\r
+#else\r
+                               if ((fp->flag & _FA_DIRTY) && fp->sect - sect < cc) {\r
+                                       mem_cpy(rbuff + ((fp->sect - sect) * SS(fs)), fp->buf, SS(fs));\r
+                               }\r
+#endif\r
+#endif\r
+                               rcnt = SS(fs) * cc;                             /* Number of bytes transferred */\r
+                               continue;\r
+                       }\r
+#if !_FS_TINY\r
+                       if (fp->sect != sect) {                 /* Load data sector if not in cache */\r
+#if !_FS_READONLY\r
+                               if (fp->flag & _FA_DIRTY) {             /* Write-back dirty sector cache */\r
+                                       if (disk_write(fs->drv, fp->buf, fp->sect, 1) != RES_OK) {\r
+                                               ABORT(fs, FR_DISK_ERR);\r
+                                       }\r
+                                       fp->flag &= ~_FA_DIRTY;\r
+                               }\r
+#endif\r
+                               if (disk_read(fs->drv, fp->buf, sect, 1) != RES_OK)     {       /* Fill sector cache */\r
+                                       ABORT(fs, FR_DISK_ERR);\r
+                               }\r
+                       }\r
+#endif\r
+                       fp->sect = sect;\r
+               }\r
+               rcnt = SS(fs) - ((UINT)fp->fptr % SS(fs));      /* Get partial sector data from sector buffer */\r
+               if (rcnt > btr) rcnt = btr;\r
+#if _FS_TINY\r
+               if (move_window(fs, fp->sect) != FR_OK) {       /* Move sector window */\r
+                       ABORT(fs, FR_DISK_ERR);\r
+               }\r
+               mem_cpy(rbuff, &fs->win[fp->fptr % SS(fs)], rcnt);      /* Pick partial sector */\r
+#else\r
+               mem_cpy(rbuff, &fp->buf[fp->fptr % SS(fs)], rcnt);      /* Pick partial sector */\r
+#endif\r
+       }\r
+\r
+       LEAVE_FF(fs, FR_OK);\r
+}\r
+\r
+\r
+\r
+\r
+#if !_FS_READONLY\r
+/*-----------------------------------------------------------------------*/\r
+/* Write File                                                            */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+FRESULT f_write (\r
+       FIL* fp,                        /* Pointer to the file object */\r
+       const void* buff,       /* Pointer to the data to be written */\r
+       UINT btw,                       /* Number of bytes to write */\r
+       UINT* bw                        /* Pointer to number of bytes written */\r
+)\r
+{\r
+       FRESULT res;\r
+       FATFS *fs;\r
+       DWORD clst, sect;\r
+       UINT wcnt, cc, csect;\r
+       const BYTE *wbuff = (const BYTE*)buff;\r
+\r
+\r
+       *bw = 0;        /* Clear write byte counter */\r
+       res = validate(fp, &fs);\r
+       if (res != FR_OK || (res = (FRESULT)fp->err) != FR_OK) LEAVE_FF(fs, res);       /* Check validity */\r
+       if (!(fp->flag & FA_WRITE)) LEAVE_FF(fs, FR_DENIED);    /* Check access mode */\r
+\r
+       /* Check fptr wrap-around (file size cannot exceed the limit on each FAT specs) */\r
+       if ((_FS_EXFAT && fs->fs_type == FS_EXFAT && fp->fptr + btw < fp->fptr)\r
+               || (DWORD)fp->fptr + btw < (DWORD)fp->fptr) {\r
+               btw = (UINT)(0xFFFFFFFF - (DWORD)fp->fptr);\r
+       }\r
+\r
+       for ( ;  btw;                                                   /* Repeat until all data written */\r
+               wbuff += wcnt, fp->fptr += wcnt, fp->obj.objsize = (fp->fptr > fp->obj.objsize) ? fp->fptr : fp->obj.objsize, *bw += wcnt, btw -= wcnt) {\r
+               if ((fp->fptr % SS(fs)) == 0) {         /* On the sector boundary? */\r
+                       csect = (UINT)(fp->fptr / SS(fs)) & (fs->csize - 1);    /* Sector offset in the cluster */\r
+                       if (csect == 0) {                               /* On the cluster boundary? */\r
+                               if (fp->fptr == 0) {            /* On the top of the file? */\r
+                                       clst = fp->obj.sclust;  /* Follow from the origin */\r
+                                       if (clst == 0) {                /* If no cluster is allocated, */\r
+                                               clst = create_chain(&fp->obj, 0);       /* create a new cluster chain */\r
+                                       }\r
+                               } else {                                        /* On the middle or end of the file */\r
+#if _USE_FASTSEEK\r
+                                       if (fp->cltbl) {\r
+                                               clst = clmt_clust(fp, fp->fptr);        /* Get cluster# from the CLMT */\r
+                                       } else\r
+#endif\r
+                                       {\r
+                                               clst = create_chain(&fp->obj, fp->clust);       /* Follow or stretch cluster chain on the FAT */\r
+                                       }\r
+                               }\r
+                               if (clst == 0) break;           /* Could not allocate a new cluster (disk full) */\r
+                               if (clst == 1) ABORT(fs, FR_INT_ERR);\r
+                               if (clst == 0xFFFFFFFF) ABORT(fs, FR_DISK_ERR);\r
+                               fp->clust = clst;                       /* Update current cluster */\r
+                               if (fp->obj.sclust == 0) fp->obj.sclust = clst; /* Set start cluster if the first write */\r
+                       }\r
+#if _FS_TINY\r
+                       if (fs->winsect == fp->sect && sync_window(fs) != FR_OK)        {       /* Write-back sector cache */\r
+                               ABORT(fs, FR_DISK_ERR);\r
+                       }\r
+#else\r
+                       if (fp->flag & _FA_DIRTY) {             /* Write-back sector cache */\r
+                               if (disk_write(fs->drv, fp->buf, fp->sect, 1) != RES_OK) {\r
+                                       ABORT(fs, FR_DISK_ERR);\r
+                               }\r
+                               fp->flag &= ~_FA_DIRTY;\r
+                       }\r
+#endif\r
+                       sect = clust2sect(fs, fp->clust);       /* Get current sector */\r
+                       if (!sect) ABORT(fs, FR_INT_ERR);\r
+                       sect += csect;\r
+                       cc = btw / SS(fs);                              /* When remaining bytes >= sector size, */\r
+                       if (cc) {                                               /* Write maximum contiguous sectors directly */\r
+                               if (csect + cc > fs->csize) {   /* Clip at cluster boundary */\r
+                                       cc = fs->csize - csect;\r
+                               }\r
+                               if (disk_write(fs->drv, wbuff, sect, cc) != RES_OK) {\r
+                                       ABORT(fs, FR_DISK_ERR);\r
+                               }\r
+#if _FS_MINIMIZE <= 2\r
+#if _FS_TINY\r
+                               if (fs->winsect - sect < cc) {  /* Refill sector cache if it gets invalidated by the direct write */\r
+                                       mem_cpy(fs->win, wbuff + ((fs->winsect - sect) * SS(fs)), SS(fs));\r
+                                       fs->wflag = 0;\r
+                               }\r
+#else\r
+                               if (fp->sect - sect < cc) { /* Refill sector cache if it gets invalidated by the direct write */\r
+                                       mem_cpy(fp->buf, wbuff + ((fp->sect - sect) * SS(fs)), SS(fs));\r
+                                       fp->flag &= ~_FA_DIRTY;\r
+                               }\r
+#endif\r
+#endif\r
+                               wcnt = SS(fs) * cc;             /* Number of bytes transferred */\r
+                               continue;\r
+                       }\r
+#if _FS_TINY\r
+                       if (fp->fptr >= fp->obj.objsize) {      /* Avoid silly cache filling at growing edge */\r
+                               if (sync_window(fs) != FR_OK) ABORT(fs, FR_DISK_ERR);\r
+                               fs->winsect = sect;\r
+                       }\r
+#else\r
+                       if (fp->sect != sect) {         /* Fill sector cache with file data */\r
+                               if (fp->fptr < fp->obj.objsize &&\r
+                                       disk_read(fs->drv, fp->buf, sect, 1) != RES_OK) {\r
+                                               ABORT(fs, FR_DISK_ERR);\r
+                               }\r
+                       }\r
+#endif\r
+                       fp->sect = sect;\r
+               }\r
+               wcnt = SS(fs) - ((UINT)fp->fptr % SS(fs));      /* Put partial sector into file I/O buffer */\r
+               if (wcnt > btw) wcnt = btw;\r
+#if _FS_TINY\r
+               if (move_window(fs, fp->sect) != FR_OK) {       /* Move sector window */\r
+                       ABORT(fs, FR_DISK_ERR);\r
+               }\r
+               mem_cpy(&fs->win[fp->fptr % SS(fs)], wbuff, wcnt);      /* Fit partial sector */\r
+               fs->wflag = 1;\r
+#else\r
+               mem_cpy(&fp->buf[fp->fptr % SS(fs)], wbuff, wcnt);      /* Fit partial sector */\r
+               fp->flag |= _FA_DIRTY;\r
+#endif\r
+       }\r
+\r
+       fp->flag |= _FA_MODIFIED;                                               /* Set file change flag */\r
+\r
+       LEAVE_FF(fs, FR_OK);\r
+}\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Synchronize the File                                                  */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+FRESULT f_sync (\r
+       FIL* fp         /* Pointer to the file object */\r
+)\r
+{\r
+       FRESULT res;\r
+       FATFS *fs;\r
+       DWORD tm;\r
+       BYTE *dir;\r
+       DEF_DIRBUF;\r
+\r
+\r
+       res = validate(fp, &fs);        /* Check validity of the object */\r
+       if (res == FR_OK) {\r
+               if (fp->flag & _FA_MODIFIED) {  /* Is there any change to the file? */\r
+#if !_FS_TINY\r
+                       if (fp->flag & _FA_DIRTY) {     /* Write-back cached data if needed */\r
+                               if (disk_write(fs->drv, fp->buf, fp->sect, 1) != RES_OK) {\r
+                                       LEAVE_FF(fs, FR_DISK_ERR);\r
+                               }\r
+                               fp->flag &= ~_FA_DIRTY;\r
+                       }\r
+#endif\r
+                       /* Update the directory entry */\r
+                       tm = GET_FATTIME();                             /* Modified time */\r
+#if _FS_EXFAT\r
+                       if (fs->fs_type == FS_EXFAT) {\r
+                               res = fill_fat_chain(&fp->obj); /* Create FAT chain if needed */\r
+                               if (res == FR_OK) {\r
+                                       DIR dj;\r
+\r
+                                       INIT_DIRBUF(fs);\r
+                                       res = load_obj_dir(&dj, &fp->obj);      /* Load directory entry block */\r
+                                       if (res == FR_OK) {\r
+                                               fs->dirbuf[XDIR_Attr] |= AM_ARC;                                        /* Set archive bit */\r
+                                               fs->dirbuf[XDIR_GenFlags] = fp->obj.stat | 1;           /* Update file allocation info */\r
+                                               st_dword(fs->dirbuf + XDIR_FstClus, fp->obj.sclust);\r
+                                               st_qword(fs->dirbuf + XDIR_FileSize, fp->obj.objsize);\r
+                                               st_qword(fs->dirbuf + XDIR_ValidFileSize, fp->obj.objsize);\r
+                                               st_dword(fs->dirbuf + XDIR_ModTime, tm);                        /* Update modified time */\r
+                                               fs->dirbuf[XDIR_ModTime10] = 0;\r
+                                               st_dword(fs->dirbuf + XDIR_AccTime, 0);\r
+                                               res = store_xdir(&dj);  /* Restore it to the directory */\r
+                                               if (res == FR_OK) {\r
+                                                       res = sync_fs(fs);\r
+                                                       fp->flag &= ~_FA_MODIFIED;\r
+                                               }\r
+                                       }\r
+                                       FREE_DIRBUF();\r
+                               }\r
+                       } else\r
+#endif\r
+                       {\r
+                               res = move_window(fs, fp->dir_sect);\r
+                               if (res == FR_OK) {\r
+                                       dir = fp->dir_ptr;\r
+                                       dir[DIR_Attr] |= AM_ARC;                                                /* Set archive bit */\r
+                                       st_clust(fp->obj.fs, dir, fp->obj.sclust);              /* Update file allocation info  */\r
+                                       st_dword(dir + DIR_FileSize, (DWORD)fp->obj.objsize);   /* Update file size */\r
+                                       st_dword(dir + DIR_WrtTime, tm);                                /* Update modified time */\r
+                                       st_word(dir + DIR_LstAccDate, 0);\r
+                                       fs->wflag = 1;\r
+                                       res = sync_fs(fs);                                      /* Restore it to the directory */\r
+                                       fp->flag &= ~_FA_MODIFIED;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       LEAVE_FF(fs, res);\r
+}\r
+\r
+#endif /* !_FS_READONLY */\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Close File                                                            */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+FRESULT f_close (\r
+       FIL* fp         /* Pointer to the file object to be closed */\r
+)\r
+{\r
+       FRESULT res;\r
+       FATFS *fs;\r
+\r
+#if !_FS_READONLY\r
+       res = f_sync(fp);                                       /* Flush cached data */\r
+       if (res == FR_OK)\r
+#endif\r
+       {\r
+               res = validate(fp, &fs);        /* Lock volume */\r
+               if (res == FR_OK) {\r
+#if _FS_LOCK != 0\r
+                       res = dec_lock(fp->obj.lockid); /* Decrement file open counter */\r
+                       if (res == FR_OK)\r
+#endif\r
+                       {\r
+                               fp->obj.fs = 0;                 /* Invalidate file object */\r
+                       }\r
+#if _FS_REENTRANT\r
+                       unlock_fs(fs, FR_OK);           /* Unlock volume */\r
+#endif\r
+               }\r
+       }\r
+       return res;\r
+}\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Change Current Directory or Current Drive, Get Current Directory      */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+#if _FS_RPATH >= 1\r
+#if _VOLUMES >= 2\r
+FRESULT f_chdrive (\r
+       const TCHAR* path               /* Drive number */\r
+)\r
+{\r
+       int vol;\r
+\r
+\r
+       vol = get_ldnumber(&path);\r
+       if (vol < 0) return FR_INVALID_DRIVE;\r
+\r
+       CurrVol = (BYTE)vol;\r
+\r
+       return FR_OK;\r
+}\r
+#endif\r
+\r
+\r
+FRESULT f_chdir (\r
+       const TCHAR* path       /* Pointer to the directory path */\r
+)\r
+{\r
+       FRESULT res;\r
+       DIR dj;\r
+       FATFS *fs;\r
+       DEF_NAMBUF;\r
+\r
+       /* Get logical drive number */\r
+       res = find_volume(&path, &fs, 0);\r
+       if (res == FR_OK) {\r
+               dj.obj.fs = fs;\r
+               INIT_NAMBUF(dj);\r
+               res = follow_path(&dj, path);           /* Follow the path */\r
+               if (res == FR_OK) {                                     /* Follow completed */\r
+                       if (dj.fn[NSFLAG] & NS_NONAME) {\r
+                               fs->cdir = dj.obj.sclust;       /* It is the start directory itself */\r
+#if _FS_EXFAT\r
+                               if (fs->fs_type == FS_EXFAT) {\r
+                                       fs->cdc_scl = dj.obj.c_scl;\r
+                                       fs->cdc_size = dj.obj.c_size;\r
+                                       fs->cdc_ofs = dj.obj.c_ofs;\r
+                               }\r
+#endif\r
+                       } else {\r
+                               if (dj.obj.attr & AM_DIR) {     /* It is a sub-directory */\r
+#if _FS_EXFAT\r
+                                       if (fs->fs_type == FS_EXFAT) {\r
+                                               fs->cdir = ld_dword(fs->dirbuf + XDIR_FstClus);         /* Sub-directory cluster */\r
+                                               fs->cdc_scl = dj.obj.sclust;                                            /* Save containing directory information */\r
+                                               fs->cdc_size = ((DWORD)dj.obj.objsize & 0xFFFFFF00) | dj.obj.stat;\r
+                                               fs->cdc_ofs = dj.blk_ofs;\r
+                                       } else\r
+#endif\r
+                                       {\r
+                                               fs->cdir = ld_clust(fs, dj.dir);                                        /* Sub-directory cluster */\r
+                                       }\r
+                               } else {\r
+                                       res = FR_NO_PATH;               /* Reached but a file */\r
+                               }\r
+                       }\r
+               }\r
+               FREE_NAMBUF();\r
+               if (res == FR_NO_FILE) res = FR_NO_PATH;\r
+       }\r
+\r
+       LEAVE_FF(fs, res);\r
+}\r
+\r
+\r
+#if _FS_RPATH >= 2\r
+FRESULT f_getcwd (\r
+       TCHAR* buff,    /* Pointer to the directory path */\r
+       UINT len                /* Size of path */\r
+)\r
+{\r
+       FRESULT res;\r
+       DIR dj;\r
+       FATFS *fs;\r
+       UINT i, n;\r
+       DWORD ccl;\r
+       TCHAR *tp;\r
+       FILINFO fno;\r
+       DEF_NAMBUF;\r
+\r
+\r
+       *buff = 0;\r
+       /* Get logical drive number */\r
+       res = find_volume((const TCHAR**)&buff, &fs, 0);        /* Get current volume */\r
+       if (res == FR_OK) {\r
+               dj.obj.fs = fs;\r
+               INIT_NAMBUF(dj);\r
+               i = len;                        /* Bottom of buffer (directory stack base) */\r
+               if (!_FS_EXFAT || fs->fs_type != FS_EXFAT) {    /* (Cannot do getcwd on exFAT and returns root path) */\r
+                       dj.obj.sclust = fs->cdir;                               /* Start to follow upper directory from current directory */\r
+                       while ((ccl = dj.obj.sclust) != 0) {    /* Repeat while current directory is a sub-directory */\r
+                               res = dir_sdi(&dj, 1 * SZDIRE); /* Get parent directory */\r
+                               if (res != FR_OK) break;\r
+                               res = move_window(fs, dj.sect);\r
+                               if (res != FR_OK) break;\r
+                               dj.obj.sclust = ld_clust(fs, dj.dir);   /* Goto parent directory */\r
+                               res = dir_sdi(&dj, 0);\r
+                               if (res != FR_OK) break;\r
+                               do {                                                    /* Find the entry links to the child directory */\r
+                                       res = dir_read(&dj, 0);\r
+                                       if (res != FR_OK) break;\r
+                                       if (ccl == ld_clust(fs, dj.dir)) break; /* Found the entry */\r
+                                       res = dir_next(&dj, 0);\r
+                               } while (res == FR_OK);\r
+                               if (res == FR_NO_FILE) res = FR_INT_ERR;/* It cannot be 'not found'. */\r
+                               if (res != FR_OK) break;\r
+                               get_fileinfo(&dj, &fno);                /* Get the directory name and push it to the buffer */\r
+                               for (n = 0; fno.fname[n]; n++) ;\r
+                               if (i < n + 3) {\r
+                                       res = FR_NOT_ENOUGH_CORE; break;\r
+                               }\r
+                               while (n) buff[--i] = fno.fname[--n];\r
+                               buff[--i] = '/';\r
+                       }\r
+               }\r
+               tp = buff;\r
+               if (res == FR_OK) {\r
+#if _VOLUMES >= 2\r
+                       *tp++ = '0' + CurrVol;                  /* Put drive number */\r
+                       *tp++ = ':';\r
+#endif\r
+                       if (i == len) {                                 /* Root-directory */\r
+                               *tp++ = '/';\r
+                       } else {                                                /* Sub-directroy */\r
+                               do              /* Add stacked path str */\r
+                                       *tp++ = buff[i++];\r
+                               while (i < len);\r
+                       }\r
+               }\r
+               *tp = 0;\r
+               FREE_NAMBUF();\r
+       }\r
+\r
+       LEAVE_FF(fs, res);\r
+}\r
+#endif /* _FS_RPATH >= 2 */\r
+#endif /* _FS_RPATH >= 1 */\r
+\r
+\r
+\r
+#if _FS_MINIMIZE <= 2\r
+/*-----------------------------------------------------------------------*/\r
+/* Seek File R/W Pointer                                                 */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+FRESULT f_lseek (\r
+       FIL* fp,                /* Pointer to the file object */\r
+       FSIZE_t ofs             /* File pointer from top of file */\r
+)\r
+{\r
+       FRESULT res;\r
+       FATFS *fs;\r
+       DWORD clst, bcs, nsect;\r
+       FSIZE_t ifptr;\r
+#if _USE_FASTSEEK\r
+       DWORD cl, pcl, ncl, tcl, dsc, tlen, ulen, *tbl;\r
+#endif\r
+\r
+       res = validate(fp, &fs);                /* Check validity of the object */\r
+       if (res != FR_OK || (res = (FRESULT)fp->err) != FR_OK) LEAVE_FF(fs, res);       /* Check validity */\r
+#if _USE_FASTSEEK\r
+       if (fp->cltbl) {        /* Fast seek */\r
+               if (ofs == CREATE_LINKMAP) {    /* Create CLMT */\r
+                       tbl = fp->cltbl;\r
+                       tlen = *tbl++; ulen = 2;        /* Given table size and required table size */\r
+                       cl = fp->sclust;                        /* Top of the chain */\r
+                       if (cl) {\r
+                               do {\r
+                                       /* Get a fragment */\r
+                                       tcl = cl; ncl = 0; ulen += 2;   /* Top, length and used items */\r
+                                       do {\r
+                                               pcl = cl; ncl++;\r
+                                               cl = get_fat(fs, cl);\r
+                                               if (cl <= 1) ABORT(fs, FR_INT_ERR);\r
+                                               if (cl == 0xFFFFFFFF) ABORT(fs, FR_DISK_ERR);\r
+                                       } while (cl == pcl + 1);\r
+                                       if (ulen <= tlen) {             /* Store the length and top of the fragment */\r
+                                               *tbl++ = ncl; *tbl++ = tcl;\r
+                                       }\r
+                               } while (cl < fs->n_fatent);    /* Repeat until end of chain */\r
+                       }\r
+                       *fp->cltbl = ulen;      /* Number of items used */\r
+                       if (ulen <= tlen) {\r
+                               *tbl = 0;               /* Terminate table */\r
+                       } else {\r
+                               res = FR_NOT_ENOUGH_CORE;       /* Given table size is smaller than required */\r
+                       }\r
+               } else {                                                /* Fast seek */\r
+                       if (ofs > fp->fsize) {          /* Clip offset at the file size */\r
+                               ofs = fp->fsize;\r
+                       }\r
+                       fp->fptr = ofs;                         /* Set file pointer */\r
+                       if (ofs) {\r
+                               fp->clust = clmt_clust(fp, ofs - 1);\r
+                               dsc = clust2sect(fs, fp->clust);\r
+                               if (!dsc) ABORT(fs, FR_INT_ERR);\r
+                               dsc += (ofs - 1) / SS(fs) & (fs->csize - 1);\r
+                               if (fp->fptr % SS(fs) && dsc != fp->sect) {     /* Refill sector cache if needed */\r
+#if !_FS_TINY\r
+#if !_FS_READONLY\r
+                                       if (fp->flag & _FA_DIRTY) {             /* Write-back dirty sector cache */\r
+                                               if (disk_write(fs->drv, fp->buf, fp->sect, 1) != RES_OK) {\r
+                                                       ABORT(fp, FR_DISK_ERR);\r
+                                               }\r
+                                               fp->flag &= ~_FA_DIRTY;\r
+                                       }\r
+#endif\r
+                                       if (disk_read(fs->drv, fp->buf, dsc, 1) != RES_OK) {    /* Load current sector */\r
+                                               ABORT(fs, FR_DISK_ERR);\r
+                                       }\r
+#endif\r
+                                       fp->sect = dsc;\r
+                               }\r
+                       }\r
+               }\r
+       } else\r
+#endif\r
+\r
+       /* Normal Seek */\r
+       {\r
+               if (ofs > fp->obj.objsize                               /* In read-only mode, clip offset with the file size */\r
+#if !_FS_READONLY\r
+                        && !(fp->flag & FA_WRITE)\r
+#endif\r
+                       ) ofs = fp->obj.objsize;\r
+\r
+               ifptr = fp->fptr;\r
+               fp->fptr = nsect = 0;\r
+               if (ofs) {\r
+                       bcs = (DWORD)fs->csize * SS(fs);        /* Cluster size (byte) */\r
+                       if (ifptr > 0 &&\r
+                               (ofs - 1) / bcs >= (ifptr - 1) / bcs) { /* When seek to same or following cluster, */\r
+                               fp->fptr = (ifptr - 1) & ~(bcs - 1);    /* start from the current cluster */\r
+                               ofs -= fp->fptr;\r
+                               clst = fp->clust;\r
+                       } else {                                                                        /* When seek to back cluster, */\r
+                               clst = fp->obj.sclust;                                  /* start from the first cluster */\r
+#if !_FS_READONLY\r
+                               if (clst == 0) {                                                /* If no cluster chain, create a new chain */\r
+                                       clst = create_chain(&fp->obj, 0);\r
+                                       if (clst == 1) ABORT(fs, FR_INT_ERR);\r
+                                       if (clst == 0xFFFFFFFF) ABORT(fs, FR_DISK_ERR);\r
+                                       fp->obj.sclust = clst;\r
+                               }\r
+#endif\r
+                               fp->clust = clst;\r
+                       }\r
+                       if (clst != 0) {\r
+                               while (ofs > bcs) {                                             /* Cluster following loop */\r
+#if !_FS_READONLY\r
+                                       if (fp->flag & FA_WRITE) {                      /* Check if in write mode or not */\r
+                                               clst = create_chain(&fp->obj, clst);    /* Force stretch if in write mode */\r
+                                               if (clst == 0) {                                /* When disk gets full, clip file size */\r
+                                                       ofs = bcs; break;\r
+                                               }\r
+                                       } else\r
+#endif\r
+                                               clst = get_fat(&fp->obj, clst); /* Follow cluster chain if not in write mode */\r
+                                       if (clst == 0xFFFFFFFF) ABORT(fs, FR_DISK_ERR);\r
+                                       if (clst <= 1 || clst >= fs->n_fatent) ABORT(fs, FR_INT_ERR);\r
+                                       fp->clust = clst;\r
+                                       fp->fptr += bcs;\r
+                                       ofs -= bcs;\r
+                               }\r
+                               fp->fptr += ofs;\r
+                               if (ofs % SS(fs)) {\r
+                                       nsect = clust2sect(fs, clst);   /* Current sector */\r
+                                       if (!nsect) ABORT(fs, FR_INT_ERR);\r
+                                       nsect += (DWORD)(ofs / SS(fs));\r
+                               }\r
+                       }\r
+               }\r
+               if (fp->fptr % SS(fs) && nsect != fp->sect) {   /* Fill sector cache if needed */\r
+#if !_FS_TINY\r
+#if !_FS_READONLY\r
+                       if (fp->flag & _FA_DIRTY) {                     /* Write-back dirty sector cache */\r
+                               if (disk_write(fs->drv, fp->buf, fp->sect, 1) != RES_OK) {\r
+                                       ABORT(fs, FR_DISK_ERR);\r
+                               }\r
+                               fp->flag &= ~_FA_DIRTY;\r
+                       }\r
+#endif\r
+                       if (disk_read(fs->drv, fp->buf, nsect, 1) != RES_OK) {  /* Fill sector cache */\r
+                               ABORT(fs, FR_DISK_ERR);\r
+                       }\r
+#endif\r
+                       fp->sect = nsect;\r
+               }\r
+#if !_FS_READONLY\r
+               if (fp->fptr > fp->obj.objsize) {               /* Set file change flag if the file size is extended */\r
+                       fp->obj.objsize = fp->fptr;\r
+                       fp->flag |= _FA_MODIFIED;\r
+               }\r
+#endif\r
+       }\r
+\r
+       LEAVE_FF(fs, res);\r
+}\r
+\r
+\r
+\r
+#if _FS_MINIMIZE <= 1\r
+/*-----------------------------------------------------------------------*/\r
+/* Create a Directory Object                                             */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+FRESULT f_opendir (\r
+       DIR* dp,                        /* Pointer to directory object to create */\r
+       const TCHAR* path       /* Pointer to the directory path */\r
+)\r
+{\r
+       FRESULT res;\r
+       FATFS *fs;\r
+       _FDID *obj;\r
+       DEF_NAMBUF;\r
+\r
+\r
+       if (!dp) return FR_INVALID_OBJECT;\r
+\r
+       /* Get logical drive number */\r
+       obj = &dp->obj;\r
+       res = find_volume(&path, &fs, 0);\r
+       if (res == FR_OK) {\r
+               obj->fs = fs;\r
+               INIT_NAMBUF(*dp);\r
+               res = follow_path(dp, path);                    /* Follow the path to the directory */\r
+               if (res == FR_OK) {                                             /* Follow completed */\r
+                       if (!(dp->fn[NSFLAG] & NS_NONAME)) {    /* It is not the origin directory itself */\r
+                               if (obj->attr & AM_DIR) {               /* This object is a sub-directory */\r
+#if _FS_EXFAT\r
+                                       if (fs->fs_type == FS_EXFAT) {\r
+                                               obj->c_scl = obj->sclust;       /* Save containing directory inforamation */\r
+                                               obj->c_size = ((DWORD)obj->objsize & 0xFFFFFF00) | obj->stat;\r
+                                               obj->c_ofs = dp->blk_ofs;\r
+                                               obj->sclust = ld_dword(fs->dirbuf + XDIR_FstClus);      /* Get object location and status */\r
+                                               obj->objsize = ld_qword(fs->dirbuf + XDIR_FileSize);\r
+                                               obj->stat = fs->dirbuf[XDIR_GenFlags] & 2;\r
+                                       } else\r
+#endif\r
+                                       {\r
+                                               obj->sclust = ld_clust(fs, dp->dir);    /* Get object location */\r
+                                       }\r
+                               } else {                                                /* This object is a file */\r
+                                       res = FR_NO_PATH;\r
+                               }\r
+                       }\r
+                       if (res == FR_OK) {\r
+                               obj->id = fs->id;\r
+                               res = dir_sdi(dp, 0);                   /* Rewind directory */\r
+#if _FS_LOCK != 0\r
+                               if (res == FR_OK) {\r
+                                       if (obj->sclust) {\r
+                                               obj->lockid = inc_lock(dp, 0);  /* Lock the sub directory */\r
+                                               if (!obj->lockid) res = FR_TOO_MANY_OPEN_FILES;\r
+                                       } else {\r
+                                               obj->lockid = 0;        /* Root directory need not to be locked */\r
+                                       }\r
+                               }\r
+#endif\r
+                       }\r
+               }\r
+               FREE_NAMBUF();\r
+               if (res == FR_NO_FILE) res = FR_NO_PATH;\r
+       }\r
+       if (res != FR_OK) obj->fs = 0;          /* Invalidate the directory object if function faild */\r
+\r
+       LEAVE_FF(fs, res);\r
+}\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Close Directory                                                       */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+FRESULT f_closedir (\r
+       DIR *dp         /* Pointer to the directory object to be closed */\r
+)\r
+{\r
+       FRESULT res;\r
+       FATFS *fs;\r
+\r
+\r
+       res = validate(dp, &fs);\r
+       if (res == FR_OK) {\r
+#if _FS_LOCK != 0\r
+               if (dp->obj.lockid) {                           /* Decrement sub-directory open counter */\r
+                       res = dec_lock(dp->obj.lockid);\r
+               }\r
+               if (res == FR_OK)\r
+#endif\r
+               {\r
+                       dp->obj.fs = 0;                 /* Invalidate directory object */\r
+               }\r
+#if _FS_REENTRANT\r
+               unlock_fs(fs, FR_OK);           /* Unlock volume */\r
+#endif\r
+       }\r
+       return res;\r
+}\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Read Directory Entries in Sequence                                    */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+FRESULT f_readdir (\r
+       DIR* dp,                        /* Pointer to the open directory object */\r
+       FILINFO* fno            /* Pointer to file information to return */\r
+)\r
+{\r
+       FRESULT res;\r
+       FATFS *fs;\r
+       DEF_NAMBUF;\r
+\r
+\r
+       res = validate(dp, &fs);        /* Check validity of the object */\r
+       if (res == FR_OK) {\r
+               if (!fno) {\r
+                       res = dir_sdi(dp, 0);                   /* Rewind the directory object */\r
+               } else {\r
+                       INIT_NAMBUF(*dp);\r
+                       res = dir_read(dp, 0);                  /* Read an item */\r
+                       if (res == FR_NO_FILE) res = FR_OK;     /* Ignore end of directory */\r
+                       if (res == FR_OK) {                             /* A valid entry is found */\r
+                               get_fileinfo(dp, fno);          /* Get the object information */\r
+                               res = dir_next(dp, 0);          /* Increment index for next */\r
+                               if (res == FR_NO_FILE) res = FR_OK;     /* Ignore end of directory now */\r
+                       }\r
+                       FREE_NAMBUF();\r
+               }\r
+       }\r
+       LEAVE_FF(fs, res);\r
+}\r
+\r
+\r
+\r
+#if _USE_FIND\r
+/*-----------------------------------------------------------------------*/\r
+/* Find Next File                                                        */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+FRESULT f_findnext (\r
+       DIR* dp,                /* Pointer to the open directory object */\r
+       FILINFO* fno    /* Pointer to the file information structure */\r
+)\r
+{\r
+       FRESULT res;\r
+\r
+\r
+       for (;;) {\r
+               res = f_readdir(dp, fno);               /* Get a directory item */\r
+               if (res != FR_OK || !fno || !fno->fname[0]) break;      /* Terminate if any error or end of directory */\r
+               if (pattern_matching(dp->pat, fno->fname, 0, 0)) break;         /* Test for the file name */\r
+#if _USE_LFN != 0 && _USE_FIND == 2\r
+               if (pattern_matching(dp->pat, fno->altname, 0, 0)) break;       /* Test for alternative name if exist */\r
+#endif\r
+       }\r
+       return res;\r
+}\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Find First File                                                       */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+FRESULT f_findfirst (\r
+       DIR* dp,                                /* Pointer to the blank directory object */\r
+       FILINFO* fno,                   /* Pointer to the file information structure */\r
+       const TCHAR* path,              /* Pointer to the directory to open */\r
+       const TCHAR* pattern    /* Pointer to the matching pattern */\r
+)\r
+{\r
+       FRESULT res;\r
+\r
+\r
+       dp->pat = pattern;              /* Save pointer to pattern string */\r
+       res = f_opendir(dp, path);              /* Open the target directory */\r
+       if (res == FR_OK) {\r
+               res = f_findnext(dp, fno);      /* Find the first item */\r
+       }\r
+       return res;\r
+}\r
+\r
+#endif /* _USE_FIND */\r
+\r
+\r
+\r
+#if _FS_MINIMIZE == 0\r
+/*-----------------------------------------------------------------------*/\r
+/* Get File Status                                                       */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+FRESULT f_stat (\r
+       const TCHAR* path,      /* Pointer to the file path */\r
+       FILINFO* fno            /* Pointer to file information to return */\r
+)\r
+{\r
+       FRESULT res;\r
+       DIR dj;\r
+       DEF_NAMBUF;\r
+\r
+\r
+       /* Get logical drive number */\r
+       res = find_volume(&path, &dj.obj.fs, 0);\r
+       if (res == FR_OK) {\r
+               INIT_NAMBUF(dj);\r
+               res = follow_path(&dj, path);   /* Follow the file path */\r
+               if (res == FR_OK) {                             /* Follow completed */\r
+                       if (dj.fn[NSFLAG] & NS_NONAME) {        /* It is origin directory */\r
+                               res = FR_INVALID_NAME;\r
+                       } else {                                                        /* Found an object */\r
+                               if (fno) get_fileinfo(&dj, fno);\r
+                       }\r
+               }\r
+               FREE_NAMBUF();\r
+       }\r
+\r
+       LEAVE_FF(dj.obj.fs, res);\r
+}\r
+\r
+\r
+\r
+#if !_FS_READONLY\r
+/*-----------------------------------------------------------------------*/\r
+/* Get Number of Free Clusters                                           */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+FRESULT f_getfree (\r
+       const TCHAR* path,      /* Path name of the logical drive number */\r
+       DWORD* nclst,           /* Pointer to a variable to return number of free clusters */\r
+       FATFS** fatfs           /* Pointer to return pointer to corresponding file system object */\r
+)\r
+{\r
+       FRESULT res;\r
+       FATFS *fs;\r
+       DWORD nfree, clst, sect, stat;\r
+       UINT i;\r
+       BYTE *p;\r
+       _FDID obj;\r
+\r
+\r
+       /* Get logical drive number */\r
+       res = find_volume(&path, &fs, 0);\r
+       if (res == FR_OK) {\r
+               *fatfs = fs;                            /* Return ptr to the fs object */\r
+               /* If free_clst is valid, return it without full cluster scan */\r
+               if (fs->free_clst <= fs->n_fatent - 2) {\r
+                       *nclst = fs->free_clst;\r
+               } else {\r
+                       /* Get number of free clusters */\r
+                       nfree = 0;\r
+                       if (fs->fs_type == FS_FAT12) {  /* FAT12: Sector unalighed FAT entries */\r
+                               clst = 2; obj.fs = fs;\r
+                               do {\r
+                                       stat = get_fat(&obj, clst);\r
+                                       if (stat == 0xFFFFFFFF) { res = FR_DISK_ERR; break; }\r
+                                       if (stat == 1) { res = FR_INT_ERR; break; }\r
+                                       if (stat == 0) nfree++;\r
+                               } while (++clst < fs->n_fatent);\r
+                       } else {\r
+#if _FS_EXFAT\r
+                               if (fs->fs_type == FS_EXFAT) {  /* exFAT: Scan bitmap table */\r
+                                       BYTE bm;\r
+                                       UINT b;\r
+\r
+                                       clst = fs->n_fatent - 2;\r
+                                       sect = fs->database;\r
+                                       i = 0;\r
+                                       do {\r
+                                               if (i == 0 && (res = move_window(fs, sect++)) != FR_OK) break;\r
+                                               for (b = 8, bm = fs->win[i]; b && clst; b--, clst--) {\r
+                                                       if (!(bm & 1)) nfree++;\r
+                                                       bm >>= 1;\r
+                                               }\r
+                                               i = (i + 1) & (SS(fs) - 1);\r
+                                       } while (clst);\r
+                               } else\r
+#endif\r
+                               {       /* FAT16/32: Sector alighed FAT entries */\r
+                                       clst = fs->n_fatent; sect = fs->fatbase;\r
+                                       i = 0; p = 0;\r
+                                       do {\r
+                                               if (i == 0) {\r
+                                                       res = move_window(fs, sect++);\r
+                                                       if (res != FR_OK) break;\r
+                                                       p = fs->win;\r
+                                                       i = SS(fs);\r
+                                               }\r
+                                               if (fs->fs_type == FS_FAT16) {\r
+                                                       if (ld_word(p) == 0) nfree++;\r
+                                                       p += 2; i -= 2;\r
+                                               } else {\r
+                                                       if ((ld_dword(p) & 0x0FFFFFFF) == 0) nfree++;\r
+                                                       p += 4; i -= 4;\r
+                                               }\r
+                                       } while (--clst);\r
+                               }\r
+                       }\r
+                       *nclst = nfree;                 /* Return the free clusters */\r
+                       fs->free_clst = nfree;  /* Now free_clst is valid */\r
+                       fs->fsi_flag |= 1;              /* FSInfo is to be updated */\r
+               }\r
+       }\r
+\r
+       LEAVE_FF(fs, res);\r
+}\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Truncate File                                                         */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+FRESULT f_truncate (\r
+       FIL* fp         /* Pointer to the file object */\r
+)\r
+{\r
+       FRESULT res;\r
+       FATFS *fs;\r
+       DWORD ncl;\r
+\r
+\r
+       res = validate(fp, &fs);        /* Check validity of the object */\r
+       if (res != FR_OK || (res = (FRESULT)fp->err) != FR_OK) LEAVE_FF(fs, res);       /* Check validity */\r
+       if (!(fp->flag & FA_WRITE)) LEAVE_FF(fs, FR_DENIED);    /* Check access mode */\r
+\r
+       if (fp->obj.objsize > fp->fptr) {\r
+               if (fp->fptr == 0) {    /* When set file size to zero, remove entire cluster chain */\r
+                       res = remove_chain(&fp->obj, fp->obj.sclust, 0);\r
+                       fp->obj.sclust = 0;\r
+               } else {                                /* When truncate a part of the file, remove remaining clusters */\r
+                       ncl = get_fat(&fp->obj, fp->clust);\r
+                       res = FR_OK;\r
+                       if (ncl == 0xFFFFFFFF) res = FR_DISK_ERR;\r
+                       if (ncl == 1) res = FR_INT_ERR;\r
+                       if (res == FR_OK && ncl < fs->n_fatent) {\r
+                               res = remove_chain(&fp->obj, ncl, fp->clust);\r
+                       }\r
+               }\r
+               fp->obj.objsize = fp->fptr;     /* Set file size to current R/W point */\r
+               fp->flag |= _FA_MODIFIED;\r
+#if !_FS_TINY\r
+               if (res == FR_OK && (fp->flag & _FA_DIRTY)) {\r
+                       if (disk_write(fs->drv, fp->buf, fp->sect, 1) != RES_OK) {\r
+                               res = FR_DISK_ERR;\r
+                       } else {\r
+                               fp->flag &= ~_FA_DIRTY;\r
+                       }\r
+               }\r
+#endif\r
+               if (res != FR_OK) ABORT(fs, res);\r
+       }\r
+\r
+       LEAVE_FF(fs, res);\r
+}\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Delete a File/Directory                                               */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+FRESULT f_unlink (\r
+       const TCHAR* path               /* Pointer to the file or directory path */\r
+)\r
+{\r
+       FRESULT res;\r
+       DIR dj, sdj;\r
+       DWORD dclst = 0;\r
+       FATFS *fs;\r
+#if _FS_EXFAT\r
+       _FDID obj;\r
+#endif\r
+       DEF_NAMBUF;\r
+\r
+\r
+       /* Get logical drive number */\r
+       res = find_volume(&path, &fs, FA_WRITE);\r
+       dj.obj.fs = fs;\r
+       if (res == FR_OK) {\r
+               INIT_NAMBUF(dj);\r
+               res = follow_path(&dj, path);           /* Follow the file path */\r
+               if (_FS_RPATH && res == FR_OK && (dj.fn[NSFLAG] & NS_DOT)) {\r
+                       res = FR_INVALID_NAME;                  /* Cannot remove dot entry */\r
+               }\r
+#if _FS_LOCK != 0\r
+               if (res == FR_OK) res = chk_lock(&dj, 2);       /* Check if it is an open object */\r
+#endif\r
+               if (res == FR_OK) {                                     /* The object is accessible */\r
+                       if (dj.fn[NSFLAG] & NS_NONAME) {\r
+                               res = FR_INVALID_NAME;          /* Cannot remove the origin directory */\r
+                       } else {\r
+                               if (dj.obj.attr & AM_RDO) {\r
+                                       res = FR_DENIED;                /* Cannot remove R/O object */\r
+                               }\r
+                       }\r
+                       if (res == FR_OK) {\r
+#if _FS_EXFAT\r
+                               obj.fs = fs;\r
+                               if (fs->fs_type == FS_EXFAT) {\r
+                                       obj.sclust = dclst = ld_dword(fs->dirbuf + XDIR_FstClus);\r
+                                       obj.objsize = ld_qword(fs->dirbuf + XDIR_FileSize);\r
+                                       obj.stat = fs->dirbuf[XDIR_GenFlags] & 2;\r
+                               } else\r
+#endif\r
+                               {\r
+                                       dclst = ld_clust(fs, dj.dir);\r
+                               }\r
+                               if (dj.obj.attr & AM_DIR) {                     /* Is it a sub-directory ? */\r
+#if _FS_RPATH != 0\r
+                                       if (dclst == fs->cdir) {                                /* Is it the current directory? */\r
+                                               res = FR_DENIED;\r
+                                       } else\r
+#endif\r
+                                       {\r
+                                               sdj.obj.fs = fs;                                                /* Open the sub-directory */\r
+                                               sdj.obj.sclust = dclst;\r
+#if _FS_EXFAT\r
+                                               if (fs->fs_type == FS_EXFAT) {\r
+                                                       sdj.obj.objsize = obj.objsize;\r
+                                                       sdj.obj.stat = obj.stat;\r
+                                               }\r
+#endif\r
+                                               res = dir_sdi(&sdj, 0);\r
+                                               if (res == FR_OK) {\r
+                                                       res = dir_read(&sdj, 0);                        /* Read an item */\r
+                                                       if (res == FR_OK) res = FR_DENIED;      /* Not empty? */\r
+                                                       if (res == FR_NO_FILE) res = FR_OK;     /* Empty? */\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+                       if (res == FR_OK) {\r
+                               res = dir_remove(&dj);                  /* Remove the directory entry */\r
+                               if (res == FR_OK && dclst) {    /* Remove the cluster chain if exist */\r
+#if _FS_EXFAT\r
+                                       res = remove_chain(&obj, dclst, 0);\r
+#else\r
+                                       res = remove_chain(&dj.obj, dclst, 0);\r
+#endif\r
+                               }\r
+                               if (res == FR_OK) res = sync_fs(fs);\r
+                       }\r
+               }\r
+               FREE_NAMBUF();\r
+       }\r
+\r
+       LEAVE_FF(fs, res);\r
+}\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Create a Directory                                                    */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+FRESULT f_mkdir (\r
+       const TCHAR* path               /* Pointer to the directory path */\r
+)\r
+{\r
+       FRESULT res;\r
+       DIR dj;\r
+       FATFS *fs;\r
+       BYTE *dir;\r
+       UINT n;\r
+       DWORD dsc, dcl, pcl, tm;\r
+       DEF_NAMBUF;\r
+\r
+\r
+       /* Get logical drive number */\r
+       res = find_volume(&path, &fs, FA_WRITE);\r
+       dj.obj.fs = fs;\r
+       if (res == FR_OK) {\r
+               INIT_NAMBUF(dj);\r
+               res = follow_path(&dj, path);                   /* Follow the file path */\r
+               if (res == FR_OK) res = FR_EXIST;               /* Any object with same name is already existing */\r
+               if (_FS_RPATH && res == FR_NO_FILE && (dj.fn[NSFLAG] & NS_DOT)) {\r
+                       res = FR_INVALID_NAME;\r
+               }\r
+               if (res == FR_NO_FILE) {                                /* Can create a new directory */\r
+                       dcl = create_chain(&dj.obj, 0);         /* Allocate a cluster for the new directory table */\r
+                       dj.obj.objsize = (DWORD)fs->csize * SS(fs);\r
+                       res = FR_OK;\r
+                       if (dcl == 0) res = FR_DENIED;          /* No space to allocate a new cluster */\r
+                       if (dcl == 1) res = FR_INT_ERR;\r
+                       if (dcl == 0xFFFFFFFF) res = FR_DISK_ERR;\r
+                       if (res == FR_OK) res = sync_window(fs);        /* Flush FAT */\r
+                       tm = GET_FATTIME();\r
+                       if (res == FR_OK) {                                     /* Initialize the new directory table */\r
+                               dsc = clust2sect(fs, dcl);\r
+                               dir = fs->win;\r
+                               mem_set(dir, 0, SS(fs));\r
+                               if (!_FS_EXFAT || fs->fs_type != FS_EXFAT) {\r
+                                       mem_set(dir + DIR_Name, ' ', 11);       /* Create "." entry */\r
+                                       dir[DIR_Name] = '.';\r
+                                       dir[DIR_Attr] = AM_DIR;\r
+                                       st_dword(dir + DIR_WrtTime, tm);\r
+                                       st_clust(fs, dir, dcl);\r
+                                       mem_cpy(dir + SZDIRE, dir, SZDIRE);     /* Create ".." entry */\r
+                                       dir[SZDIRE + 1] = '.'; pcl = dj.obj.sclust;\r
+                                       if (fs->fs_type == FS_FAT32 && pcl == fs->dirbase)\r
+                                               pcl = 0;\r
+                                       st_clust(fs, dir + SZDIRE, pcl);\r
+                               }\r
+                               for (n = fs->csize; n; n--) {   /* Write dot entries and clear following sectors */\r
+                                       fs->winsect = dsc++;\r
+                                       fs->wflag = 1;\r
+                                       res = sync_window(fs);\r
+                                       if (res != FR_OK) break;\r
+                                       mem_set(dir, 0, SS(fs));\r
+                               }\r
+                       }\r
+                       if (res == FR_OK) res = dir_register(&dj);      /* Register the object to the directoy */\r
+                       if (res == FR_OK) {\r
+#if _FS_EXFAT\r
+                               if (fs->fs_type == FS_EXFAT) {\r
+                                       st_dword(fs->dirbuf + XDIR_ModTime, tm);\r
+                                       st_dword(fs->dirbuf + XDIR_FstClus, dcl);\r
+                                       st_dword(fs->dirbuf + XDIR_FileSize, (DWORD)dj.obj.objsize);\r
+                                       st_dword(fs->dirbuf + XDIR_ValidFileSize, (DWORD)dj.obj.objsize);\r
+                                       fs->dirbuf[XDIR_GenFlags] = 3;\r
+                                       fs->dirbuf[XDIR_Attr] = AM_DIR;\r
+                                       res = store_xdir(&dj);\r
+                               } else\r
+#endif\r
+                               {\r
+                                       dir = dj.dir;\r
+                                       st_dword(dir + DIR_WrtTime, tm);        /* Created time */\r
+                                       st_clust(fs, dir, dcl);                         /* Table start cluster */\r
+                                       dir[DIR_Attr] = AM_DIR;                         /* Attribute */\r
+                                       fs->wflag = 1;\r
+                               }\r
+                               res = sync_fs(fs);\r
+                       } else {\r
+                               remove_chain(&dj.obj, dcl, 0);          /* Could not register, remove cluster chain */\r
+                       }\r
+               }\r
+               FREE_NAMBUF();\r
+       }\r
+\r
+       LEAVE_FF(fs, res);\r
+}\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Rename a File/Directory                                               */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+FRESULT f_rename (\r
+       const TCHAR* path_old,  /* Pointer to the object name to be renamed */\r
+       const TCHAR* path_new   /* Pointer to the new name */\r
+)\r
+{\r
+       FRESULT res;\r
+       DIR djo, djn;\r
+       FATFS *fs;\r
+       BYTE buf[_FS_EXFAT ? SZDIRE * 2 : 24], *dir;\r
+       DWORD dw;\r
+       DEF_NAMBUF;\r
+\r
+\r
+       get_ldnumber(&path_new);                                                /* Ignore drive number of new name */\r
+       res = find_volume(&path_old, &fs, FA_WRITE);    /* Get logical drive number of the old object */\r
+       if (res == FR_OK) {\r
+               djo.obj.fs = fs;\r
+               INIT_NAMBUF(djo);\r
+               res = follow_path(&djo, path_old);              /* Check old object */\r
+               if (res == FR_OK && (djo.fn[NSFLAG] & (NS_DOT | NS_NONAME))) res = FR_INVALID_NAME;     /* Check validity of name */\r
+#if _FS_LOCK != 0\r
+               if (res == FR_OK) res = chk_lock(&djo, 2);\r
+#endif\r
+               if (res == FR_OK) {                                             /* Object to be renamed is found */\r
+#if _FS_EXFAT\r
+                       if (fs->fs_type == FS_EXFAT) {  /* At exFAT */\r
+                               BYTE nf, nn;\r
+                               WORD nh;\r
+\r
+                               mem_cpy(buf, fs->dirbuf, SZDIRE * 2);   /* Save 85+C0 entry of old object */\r
+                               mem_cpy(&djn, &djo, sizeof djo);\r
+                               res = follow_path(&djn, path_new);      /* Make sure if new object name is not in use */\r
+                               if (res == FR_OK) res = FR_EXIST;       /* Is new name already in use? */\r
+                               if (res == FR_NO_FILE) {                        /* It is a valid path and no name collision */\r
+                                       res = dir_register(&djn);               /* Register the new entry */\r
+                                       if (res == FR_OK) {\r
+                                               nf = fs->dirbuf[XDIR_NumSec]; nn = fs->dirbuf[XDIR_NumName];\r
+                                               nh = ld_word(fs->dirbuf + XDIR_NameHash);\r
+                                               mem_cpy(fs->dirbuf, buf, SZDIRE * 2);\r
+                                               fs->dirbuf[XDIR_NumSec] = nf; fs->dirbuf[XDIR_NumName] = nn;\r
+                                               st_word(fs->dirbuf + XDIR_NameHash, nh);\r
+/* Start of critical section where any interruption can cause a cross-link */\r
+                                               res = store_xdir(&djn);\r
+                                       }\r
+                               }\r
+                       } else\r
+#endif\r
+                       {       /* At FAT12/FAT16/FAT32 */\r
+                               mem_cpy(buf, djo.dir + DIR_Attr, 21);   /* Save information about the object except name */\r
+                               mem_cpy(&djn, &djo, sizeof (DIR));              /* Duplicate the directory object */\r
+                               res = follow_path(&djn, path_new);              /* Make sure if new object name is not in use */\r
+                               if (res == FR_OK) res = FR_EXIST;               /* Is new name already in use? */\r
+                               if (res == FR_NO_FILE) {                                /* It is a valid path and no name collision */\r
+                                       res = dir_register(&djn);                       /* Register the new entry */\r
+                                       if (res == FR_OK) {\r
+                                               dir = djn.dir;                                  /* Copy information about object except name */\r
+                                               mem_cpy(dir + 13, buf + 2, 19);\r
+                                               dir[DIR_Attr] = buf[0] | AM_ARC;\r
+                                               fs->wflag = 1;\r
+                                               if ((dir[DIR_Attr] & AM_DIR) && djo.obj.sclust != djn.obj.sclust) {     /* Update .. entry in the sub-directory if needed */\r
+                                                       dw = clust2sect(fs, ld_clust(fs, dir));\r
+                                                       if (!dw) {\r
+                                                               res = FR_INT_ERR;\r
+                                                       } else {\r
+/* Start of critical section where any interruption can cause a cross-link */\r
+                                                               res = move_window(fs, dw);\r
+                                                               dir = fs->win + SZDIRE * 1;     /* Ptr to .. entry */\r
+                                                               if (res == FR_OK && dir[1] == '.') {\r
+                                                                       st_clust(fs, dir, djn.obj.sclust);\r
+                                                                       fs->wflag = 1;\r
+                                                               }\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+                       if (res == FR_OK) {\r
+                               res = dir_remove(&djo);         /* Remove old entry */\r
+                               if (res == FR_OK) {\r
+                                       res = sync_fs(fs);\r
+                               }\r
+                       }\r
+/* End of critical section */\r
+               }\r
+               FREE_NAMBUF();\r
+       }\r
+\r
+       LEAVE_FF(fs, res);\r
+}\r
+\r
+\r
+\r
+#endif /* !_FS_READONLY */\r
+#endif /* _FS_MINIMIZE == 0 */\r
+#endif /* _FS_MINIMIZE <= 1 */\r
+#endif /* _FS_MINIMIZE <= 2 */\r
+\r
+\r
+\r
+#if _USE_CHMOD && !_FS_READONLY\r
+/*-----------------------------------------------------------------------*/\r
+/* Change Attribute                                                      */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+FRESULT f_chmod (\r
+       const TCHAR* path,      /* Pointer to the file path */\r
+       BYTE attr,                      /* Attribute bits */\r
+       BYTE mask                       /* Attribute mask to change */\r
+)\r
+{\r
+       FRESULT res;\r
+       DIR dj;\r
+       FATFS *fs;\r
+       DEF_NAMBUF;\r
+\r
+\r
+       res = find_volume(&path, &fs, FA_WRITE);        /* Get logical drive number */\r
+       dj.obj.fs = fs;\r
+       if (res == FR_OK) {\r
+               INIT_NAMBUF(dj);\r
+               res = follow_path(&dj, path);   /* Follow the file path */\r
+               if (res == FR_OK && (dj.fn[NSFLAG] & (NS_DOT | NS_NONAME))) res = FR_INVALID_NAME;      /* Check object validity */\r
+               if (res == FR_OK) {\r
+                       mask &= AM_RDO|AM_HID|AM_SYS|AM_ARC;    /* Valid attribute mask */\r
+#if _FS_EXFAT\r
+                       if (fs->fs_type == FS_EXFAT) {\r
+                               fs->dirbuf[XDIR_Attr] = (attr & mask) | (fs->dirbuf[XDIR_Attr] & (BYTE)~mask);  /* Apply attribute change */\r
+                               res = store_xdir(&dj);\r
+                       } else\r
+#endif\r
+                       {\r
+                               dj.dir[DIR_Attr] = (attr & mask) | (dj.dir[DIR_Attr] & (BYTE)~mask);    /* Apply attribute change */\r
+                               fs->wflag = 1;\r
+                       }\r
+                       res = sync_fs(fs);\r
+               }\r
+               FREE_NAMBUF();\r
+       }\r
+\r
+       LEAVE_FF(fs, res);\r
+}\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Change Timestamp                                                      */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+FRESULT f_utime (\r
+       const TCHAR* path,      /* Pointer to the file/directory name */\r
+       const FILINFO* fno      /* Pointer to the time stamp to be set */\r
+)\r
+{\r
+       FRESULT res;\r
+       DIR dj;\r
+       FATFS *fs;\r
+       DEF_NAMBUF;\r
+\r
+\r
+       res = find_volume(&path, &fs, FA_WRITE);        /* Get logical drive number */\r
+       dj.obj.fs = fs;\r
+       if (res == FR_OK) {\r
+               INIT_NAMBUF(dj);\r
+               res = follow_path(&dj, path);   /* Follow the file path */\r
+               if (res == FR_OK && (dj.fn[NSFLAG] & (NS_DOT | NS_NONAME))) res = FR_INVALID_NAME;      /* Check object validity */\r
+               if (res == FR_OK) {\r
+#if _FS_EXFAT\r
+                       if (fs->fs_type == FS_EXFAT) {\r
+                               st_word(fs->dirbuf + XDIR_ModTime, fno->ftime);\r
+                               st_word(fs->dirbuf + XDIR_ModTime + 2, fno->fdate);\r
+                               res = store_xdir(&dj);\r
+                       } else\r
+#endif\r
+                       {\r
+                               st_word(dj.dir + DIR_WrtTime, fno->ftime);\r
+                               st_word(dj.dir + DIR_WrtDate, fno->fdate);\r
+                               fs->wflag = 1;\r
+                       }\r
+                       if (res == FR_OK) res = sync_fs(fs);\r
+               }\r
+               FREE_NAMBUF();\r
+       }\r
+\r
+       LEAVE_FF(fs, res);\r
+}\r
+\r
+#endif /* _USE_CHMOD && !_FS_READONLY */\r
+\r
+\r
+\r
+#if _USE_LABEL\r
+/*-----------------------------------------------------------------------*/\r
+/* Get Volume Label                                                      */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+FRESULT f_getlabel (\r
+       const TCHAR* path,      /* Path name of the logical drive number */\r
+       TCHAR* label,           /* Pointer to a buffer to return the volume label */\r
+       DWORD* vsn                      /* Pointer to a variable to return the volume serial number */\r
+)\r
+{\r
+       FRESULT res;\r
+       DIR dj;\r
+       FATFS *fs;\r
+       UINT si, di;\r
+#if _LFN_UNICODE || _FS_EXFAT\r
+       WCHAR w;\r
+#endif\r
+\r
+       /* Get logical drive number */\r
+       res = find_volume(&path, &fs, 0);\r
+\r
+       /* Get volume label */\r
+       if (res == FR_OK && label) {\r
+               dj.obj.fs = fs; dj.obj.sclust = 0;      /* Open root directory */\r
+               res = dir_sdi(&dj, 0);\r
+               if (res == FR_OK) {\r
+                       res = dir_read(&dj, 1);                 /* Find a volume label entry */\r
+                       if (res == FR_OK) {\r
+#if _FS_EXFAT\r
+                               if (fs->fs_type == FS_EXFAT) {\r
+                                       for (si = di = 0; si < dj.dir[XDIR_NumLabel]; si++) {   /* Extract volume label from 83 entry */\r
+                                               w = ld_word(dj.dir + XDIR_Label + si * 2);\r
+#if _LFN_UNICODE\r
+                                               label[di++] = w;\r
+#else\r
+                                               w = ff_convert(w, 0);   /* Unicode -> OEM */\r
+                                               if (w == 0) w = '?';    /* Replace wrong character */\r
+                                               if (_DF1S && w >= 0x100) label[di++] = (char)(w >> 8);\r
+                                               label[di++] = (char)w;\r
+#endif\r
+                                       }\r
+                                       label[di] = 0;\r
+                               } else\r
+#endif\r
+                               {\r
+                                       si = di = 0;            /* Extract volume label from AM_VOL entry with code comversion */\r
+                                       do {\r
+#if _LFN_UNICODE\r
+                                               w = (si < 11) ? dj.dir[si++] : ' ';\r
+                                               if (IsDBCS1(w) && si < 11 && IsDBCS2(dj.dir[si])) {\r
+                                                       w = w << 8 | dj.dir[si++];\r
+                                               }\r
+                                               label[di++] = ff_convert(w, 1); /* OEM -> Unicode */\r
+#else\r
+                                               label[di++] = dj.dir[si++];\r
+#endif\r
+                                       } while (di < 11);\r
+                                       do {                            /* Truncate trailing spaces */\r
+                                               label[di] = 0;\r
+                                               if (di == 0) break;\r
+                                       } while (label[--di] == ' ');\r
+                               }\r
+                       }\r
+               }\r
+               if (res == FR_NO_FILE) {        /* No label entry and return nul string */\r
+                       label[0] = 0;\r
+                       res = FR_OK;\r
+               }\r
+       }\r
+\r
+       /* Get volume serial number */\r
+       if (res == FR_OK && vsn) {\r
+               res = move_window(fs, fs->volbase);\r
+               if (res == FR_OK) {\r
+                       switch (fs->fs_type) {\r
+                       case FS_EXFAT: di = BPB_VolIDEx; break;\r
+                       case FS_FAT32: di = BS_VolID32; break;\r
+                       default:       di = BS_VolID;\r
+                       }\r
+                       *vsn = ld_dword(&fs->win[di]);\r
+               }\r
+       }\r
+\r
+       LEAVE_FF(fs, res);\r
+}\r
+\r
+\r
+\r
+#if !_FS_READONLY\r
+/*-----------------------------------------------------------------------*/\r
+/* Set Volume Label                                                      */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+FRESULT f_setlabel (\r
+       const TCHAR* label      /* Pointer to the volume label to set */\r
+)\r
+{\r
+       FRESULT res;\r
+       DIR dj;\r
+       FATFS *fs;\r
+       BYTE dirvn[22];\r
+       UINT i, j, slen;\r
+       WCHAR w;\r
+       static const char badchr[] = "\"*+,.:;<=>\?[]|\x7F";\r
+\r
+\r
+       /* Get logical drive number */\r
+       res = find_volume(&label, &fs, FA_WRITE);\r
+       if (res != FR_OK) LEAVE_FF(fs, res);\r
+       dj.obj.fs = fs;\r
+\r
+       /* Get length of given volume label */\r
+       for (slen = 0; (UINT)label[slen] >= ' '; slen++) ;      /* Get name length */\r
+\r
+#if _FS_EXFAT\r
+       if (fs->fs_type == FS_EXFAT) {  /* At the exFAT */\r
+               for (i = j = 0; i < slen; ) {   /* Create volume label in directory form */\r
+                       w = label[i++];\r
+#if !_LFN_UNICODE\r
+                       if (IsDBCS1(w)) {\r
+                               w = (i < slen && IsDBCS2(label[i])) ? w << 8 | (BYTE)label[i++] : 0;\r
+                       }\r
+                       w = ff_convert(w, 1);\r
+#endif\r
+                       if (w == 0 || chk_chr(badchr, w) || j == 22) {  /* Check validity check validity of the volume label */\r
+                               LEAVE_FF(fs, FR_INVALID_NAME);\r
+                       }\r
+                       st_word(dirvn + j, w); j += 2;\r
+               }\r
+               slen = j;\r
+       } else\r
+#endif\r
+       {       /* At the FAT12/16/32 */\r
+               for ( ; slen && label[slen - 1] == ' '; slen--) ;       /* Remove trailing spaces */\r
+               if (slen) {             /* Is there a volume label to be set? */\r
+                       dirvn[0] = 0; i = j = 0;        /* Create volume label in directory form */\r
+                       do {\r
+#if _LFN_UNICODE\r
+                               w = ff_convert(ff_wtoupper(label[i++]), 0);\r
+#else\r
+                               w = (BYTE)label[i++];\r
+                               if (IsDBCS1(w)) {\r
+                                       w = (j < 10 && i < slen && IsDBCS2(label[i])) ? w << 8 | (BYTE)label[i++] : 0;\r
+                               }\r
+#if _USE_LFN != 0\r
+                               w = ff_convert(ff_wtoupper(ff_convert(w, 1)), 0);\r
+#else\r
+                               if (IsLower(w)) w -= 0x20;                      /* To upper ASCII characters */\r
+#ifdef _EXCVT\r
+                               if (w >= 0x80) w = ExCvt[w - 0x80];     /* To upper extended characters (SBCS cfg) */\r
+#else\r
+                               if (!_DF1S && w >= 0x80) w = 0;         /* Reject extended characters (ASCII cfg) */\r
+#endif\r
+#endif\r
+#endif\r
+                               if (w == 0 || chk_chr(badchr, w) || j >= (UINT)((w >= 0x100) ? 10 : 11)) {      /* Reject invalid characters for volume label */\r
+                                       LEAVE_FF(fs, FR_INVALID_NAME);\r
+                               }\r
+                               if (w >= 0x100) dirvn[j++] = (BYTE)(w >> 8);\r
+                               dirvn[j++] = (BYTE)w;\r
+                       } while (i < slen);\r
+                       while (j < 11) dirvn[j++] = ' ';        /* Fill remaining name field */\r
+                       if (dirvn[0] == DDEM) LEAVE_FF(fs, FR_INVALID_NAME);    /* Reject illegal name (heading DDEM) */\r
+               }\r
+       }\r
+\r
+       /* Set volume label */\r
+       dj.obj.sclust = 0;              /* Open root directory */\r
+       res = dir_sdi(&dj, 0);\r
+       if (res == FR_OK) {\r
+               res = dir_read(&dj, 1); /* Get volume label entry */\r
+               if (res == FR_OK) {\r
+                       if (_FS_EXFAT && fs->fs_type == FS_EXFAT) {\r
+                               dj.dir[XDIR_NumLabel] = slen / 2;       /* Change the volume label */\r
+                               mem_cpy(dj.dir + XDIR_Label, dirvn, slen);\r
+                       } else {\r
+                               if (slen) {\r
+                                       mem_cpy(dj.dir, dirvn, 11);     /* Change the volume label */\r
+                               } else {\r
+                                       dj.dir[DIR_Name] = DDEM;        /* Remove the volume label */\r
+                               }\r
+                       }\r
+                       fs->wflag = 1;\r
+                       res = sync_fs(fs);\r
+               } else {                        /* No volume label entry is found or error */\r
+                       if (res == FR_NO_FILE) {\r
+                               res = FR_OK;\r
+                               if (slen) {     /* Create a volume label entry */\r
+                                       res = dir_alloc(&dj, 1);        /* Allocate an entry */\r
+                                       if (res == FR_OK) {\r
+                                               mem_set(dj.dir, 0, SZDIRE);     /* Clear the entry */\r
+                                               if (_FS_EXFAT && fs->fs_type == FS_EXFAT) {\r
+                                                       dj.dir[XDIR_Type] = 0x83;               /* Create 83 entry */\r
+                                                       dj.dir[XDIR_NumLabel] = slen / 2;\r
+                                                       mem_cpy(dj.dir + XDIR_Label, dirvn, slen);\r
+                                               } else {\r
+                                                       dj.dir[DIR_Attr] = AM_VOL;              /* Create volume label entry */\r
+                                                       mem_cpy(dj.dir, dirvn, 11);\r
+                                               }\r
+                                               fs->wflag = 1;\r
+                                               res = sync_fs(fs);\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       LEAVE_FF(fs, res);\r
+}\r
+\r
+#endif /* !_FS_READONLY */\r
+#endif /* _USE_LABEL */\r
+\r
+\r
+\r
+#if _USE_EXPAND && !_FS_READONLY\r
+/*-----------------------------------------------------------------------*/\r
+/* Allocate a Contiguous Blocks to the File                              */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+FRESULT f_expand (\r
+       FIL* fp,                /* Pointer to the file object */\r
+       FSIZE_t fsz,    /* File size to be expanded to */\r
+       BYTE opt                /* Operation mode 0:Find and prepare or 1:Find and allocate */\r
+)\r
+{\r
+       FRESULT res;\r
+       FATFS *fs;\r
+       DWORD val, clst, csz, stcl, scl, ncl, tcl;\r
+\r
+\r
+       res = validate(fp, &fs);                /* Check validity of the object */\r
+       if (res != FR_OK || (res = (FRESULT)fp->err) != FR_OK) LEAVE_FF(fs, res);       /* Check validity */\r
+       if (fsz == 0 || fp->obj.objsize != 0 || !(fp->flag & FA_WRITE)) LEAVE_FF(fs, FR_DENIED);\r
+#if _FS_EXFAT\r
+       if (fs->fs_type != FS_EXFAT && fsz >= 0x100000000) LEAVE_FF(fs, FR_DENIED);     /* Check if in size limit */\r
+#endif\r
+       csz = (DWORD)fs->csize * SS(fs);        /* Cluster size */\r
+       tcl = (DWORD)(fsz / csz) + ((fsz & (csz - 1)) ? 1 : 0); /* Number of clusters required */\r
+       stcl = fs->last_clst;\r
+       if (stcl < 2 || stcl >= fs->n_fatent) stcl = 2;\r
+\r
+#if _FS_EXFAT\r
+       if (fs->fs_type == FS_EXFAT) {\r
+               scl = find_bitmap(fs, stcl, tcl);                       /* Find a contiguous cluster block */\r
+               if (scl == 0) res = FR_DENIED;                          /* No contiguous cluster block was found */\r
+               if (scl == 1) res = FR_INT_ERR;\r
+               if (scl == 0xFFFFFFFF) res = FR_DISK_ERR;\r
+               if (res == FR_OK) {\r
+                       if (opt) {\r
+                               res = change_bitmap(fs, scl, tcl, 1);   /* Mark the cluster block 'in use' */\r
+                               fs->last_clst = scl + tcl - 1;\r
+                       } else {\r
+                               fs->last_clst = scl - 1;                                /* Set suggested cluster to start next */\r
+                       }\r
+               }\r
+       } else\r
+#endif\r
+       {\r
+               scl = clst = stcl; ncl = 0;\r
+               for (;;) {      /* Find a contiguous cluster block */\r
+                       val = get_fat(&fp->obj, clst);\r
+                       if (++clst >= fs->n_fatent) clst = 2;\r
+                       if (val == 1) { res = FR_INT_ERR; break; }\r
+                       if (val == 0xFFFFFFFF) { res = FR_DISK_ERR; break; }\r
+                       if (val == 0) { /* Is it a free cluster? */\r
+                               if (++ncl == tcl) break;        /* Break if a contiguous cluster block was found */\r
+                       } else {\r
+                               scl = clst; ncl = 0;            /* Not a free cluster */\r
+                       }\r
+                       if (clst == stcl) { res = FR_DENIED; break; }   /* All cluster scanned? */\r
+               }\r
+               if (res == FR_OK) {\r
+                       if (opt) {\r
+                               for (clst = scl; tcl; clst++, tcl--) {  /* Create a cluster chain on the FAT */\r
+                                       val = (tcl == 1) ? 0xFFFFFFFF : clst + 1;\r
+                                       res = put_fat(fs, clst, val);\r
+                                       if (res != FR_OK) break;\r
+                                       fs->last_clst = clst;\r
+                               }\r
+                       } else {\r
+                               fs->last_clst = scl - 1;                                /* Set suggested cluster to start next */\r
+                       }\r
+               }\r
+       }\r
+\r
+       if (opt && res == FR_OK) {\r
+               fp->obj.sclust = scl;           /* Update allocation information */\r
+               fp->obj.objsize = fsz;\r
+               if (_FS_EXFAT) fp->obj.stat = 2;\r
+               fp->flag |= _FA_MODIFIED;\r
+       }\r
+\r
+       LEAVE_FF(fs, res);\r
+}\r
+\r
+#endif /* _USE_EXPAND && !_FS_READONLY */\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Forward data to the stream directly (available on only tiny cfg)      */\r
+/*-----------------------------------------------------------------------*/\r
+#if _USE_FORWARD && _FS_TINY\r
+\r
+FRESULT f_forward (\r
+       FIL* fp,                                                /* Pointer to the file object */\r
+       UINT (*func)(const BYTE*,UINT), /* Pointer to the streaming function */\r
+       UINT btf,                                               /* Number of bytes to forward */\r
+       UINT* bf                                                /* Pointer to number of bytes forwarded */\r
+)\r
+{\r
+       FRESULT res;\r
+       FATFS *fs;\r
+       DWORD clst, sect;\r
+       FSIZE_t remain;\r
+       UINT rcnt, csect;\r
+\r
+\r
+       *bf = 0;        /* Clear transfer byte counter */\r
+       res = validate(fp, &fs);                /* Check validity of the object */\r
+       if (res != FR_OK || (res = (FRESULT)fp->err) != FR_OK) LEAVE_FF(fs, res);       /* Check validity */\r
+       if (!(fp->flag & FA_READ)) LEAVE_FF(fs, FR_DENIED);     /* Check access mode */\r
+\r
+       remain = fp->fsize - fp->fptr;\r
+       if (btf > remain) btf = (UINT)remain;                   /* Truncate btf by remaining bytes */\r
+\r
+       for ( ;  btf && (*func)(0, 0);                                  /* Repeat until all data transferred or stream becomes busy */\r
+               fp->fptr += rcnt, *bf += rcnt, btf -= rcnt) {\r
+               csect = (UINT)(fp->fptr / SS(fs) & (fs->csize - 1));    /* Sector offset in the cluster */\r
+               if ((fp->fptr % SS(fs)) == 0) {                         /* On the sector boundary? */\r
+                       if (csect == 0) {                                               /* On the cluster boundary? */\r
+                               clst = (fp->fptr == 0) ?                        /* On the top of the file? */\r
+                                       fp->sclust : get_fat(fs, fp->clust);\r
+                               if (clst <= 1) ABORT(fs, FR_INT_ERR);\r
+                               if (clst == 0xFFFFFFFF) ABORT(fs, FR_DISK_ERR);\r
+                               fp->clust = clst;                                       /* Update current cluster */\r
+                       }\r
+               }\r
+               sect = clust2sect(fs, fp->clust);                       /* Get current data sector */\r
+               if (!sect) ABORT(fs, FR_INT_ERR);\r
+               sect += csect;\r
+               if (move_window(fs, sect) != FR_OK) {           /* Move sector window */\r
+                       ABORT(fs, FR_DISK_ERR);\r
+               }\r
+               fp->sect = sect;\r
+               rcnt = SS(fs) - (WORD)(fp->fptr % SS(fs));      /* Forward data from sector window */\r
+               if (rcnt > btf) rcnt = btf;\r
+               rcnt = (*func)(&fs->win[(WORD)fp->fptr % SS(fs)], rcnt);\r
+               if (!rcnt) ABORT(fs, FR_INT_ERR);\r
+       }\r
+\r
+       LEAVE_FF(fs, FR_OK);\r
+}\r
+#endif /* _USE_FORWARD */\r
+\r
+\r
+\r
+#if _USE_MKFS && !_FS_READONLY\r
+/*-----------------------------------------------------------------------*/\r
+/* Create file system on the logical drive                               */\r
+/*-----------------------------------------------------------------------*/\r
+#define N_ROOTDIR      512             /* Number of root directory entries for FAT12/16 */\r
+#define N_FATS         1               /* Number of FATs (1 or 2) */\r
+\r
+\r
+FRESULT f_mkfs (\r
+       const TCHAR* path,      /* Logical drive number */\r
+       BYTE sfd,                       /* Partitioning rule 0:FDISK, 1:SFD */\r
+       UINT au                         /* Size of allocation unit in unit of byte or sector */\r
+)\r
+{\r
+       static const WORD vst[] = { 1024,   512,  256,  128,   64,    32,   16,    8,    4,    2,   0};\r
+       static const WORD cst[] = {32768, 16384, 8192, 4096, 2048, 16384, 8192, 4096, 2048, 1024, 512};\r
+       int vol;\r
+       BYTE fmt, md, sys, *tbl, pdrv, part;\r
+       DWORD n_clst, vs, n, wsect;\r
+       UINT i;\r
+       DWORD b_vol, b_fat, b_dir, b_data;      /* LBA */\r
+       DWORD n_vol, n_rsv, n_fat, n_dir;       /* Size */\r
+       FATFS *fs;\r
+       DSTATUS stat;\r
+#if _USE_TRIM\r
+       DWORD eb[2];\r
+#endif\r
+\r
+\r
+       /* Check mounted drive and clear work area */\r
+       if (sfd > 1) return FR_INVALID_PARAMETER;\r
+       vol = get_ldnumber(&path);                              /* Get target volume */\r
+       if (vol < 0) return FR_INVALID_DRIVE;\r
+       fs = FatFs[vol];                                                /* Check if the volume has work area */\r
+       if (!fs) return FR_NOT_ENABLED;\r
+       fs->fs_type = 0;\r
+       pdrv = LD2PD(vol);      /* Physical drive */\r
+       part = LD2PT(vol);      /* Partition (0:auto detect, 1-4:get from partition table)*/\r
+\r
+       /* Get disk statics */\r
+       stat = disk_initialize(pdrv);\r
+       if (stat & STA_NOINIT) return FR_NOT_READY;\r
+       if (stat & STA_PROTECT) return FR_WRITE_PROTECTED;\r
+#if _MAX_SS != _MIN_SS         /* Get disk sector size */\r
+       if (disk_ioctl(pdrv, GET_SECTOR_SIZE, &SS(fs)) != RES_OK || SS(fs) > _MAX_SS || SS(fs) < _MIN_SS) {\r
+               return FR_DISK_ERR;\r
+       }\r
+#endif\r
+       if (_MULTI_PARTITION && part) {\r
+               /* Get partition information from partition table in the MBR */\r
+               if (disk_read(pdrv, fs->win, 0, 1) != RES_OK) return FR_DISK_ERR;\r
+               if (ld_word(fs->win + BS_55AA) != 0xAA55) return FR_MKFS_ABORTED;\r
+               tbl = &fs->win[MBR_Table + (part - 1) * SZ_PTE];\r
+               if (!tbl[4]) return FR_MKFS_ABORTED;    /* No partition? */\r
+               b_vol = ld_dword(tbl + 8);      /* Volume start sector */\r
+               n_vol = ld_dword(tbl + 12);     /* Volume size */\r
+       } else {\r
+               /* Create a single-partition in this function */\r
+               if (disk_ioctl(pdrv, GET_SECTOR_COUNT, &n_vol) != RES_OK || n_vol < 128) {\r
+                       return FR_DISK_ERR;\r
+               }\r
+               b_vol = (sfd) ? 0 : 63;         /* Volume start sector */\r
+               n_vol -= b_vol;                         /* Volume size */\r
+       }\r
+\r
+       if (au & (au - 1)) au = 0;\r
+       if (!au) {                                              /* AU auto selection */\r
+               vs = n_vol / (2000 / (SS(fs) / 512));\r
+               for (i = 0; vs < vst[i]; i++) ;\r
+               au = cst[i];\r
+       }\r
+       if (au >= _MIN_SS) au /= SS(fs);        /* Number of sectors per cluster */\r
+       if (!au) au = 1;\r
+       if (au > 128) au = 128;\r
+\r
+       /* Pre-compute number of clusters and FAT sub-type */\r
+       n_clst = n_vol / au;\r
+       fmt = FS_FAT12;\r
+       if (n_clst >= MIN_FAT16) fmt = FS_FAT16;\r
+       if (n_clst >= MIN_FAT32) fmt = FS_FAT32;\r
+\r
+       /* Determine offset and size of FAT structure */\r
+       if (fmt == FS_FAT32) {\r
+               n_fat = ((n_clst * 4) + 8 + SS(fs) - 1) / SS(fs);\r
+               n_rsv = 32;\r
+               n_dir = 0;\r
+       } else {\r
+               n_fat = (fmt == FS_FAT12) ? (n_clst * 3 + 1) / 2 + 3 : (n_clst * 2) + 4;\r
+               n_fat = (n_fat + SS(fs) - 1) / SS(fs);\r
+               n_rsv = 1;\r
+               n_dir = (DWORD)N_ROOTDIR * SZDIRE / SS(fs);\r
+       }\r
+       b_fat = b_vol + n_rsv;                          /* FAT area start sector */\r
+       b_dir = b_fat + n_fat * N_FATS;         /* Directory area start sector */\r
+       b_data = b_dir + n_dir;                         /* Data area start sector */\r
+       if (n_vol < b_data + au - b_vol) return FR_MKFS_ABORTED;        /* Too small volume */\r
+\r
+       /* Align data start sector to erase block boundary (for flash memory media) */\r
+       if (disk_ioctl(pdrv, GET_BLOCK_SIZE, &n) != RES_OK || !n || n > 32768) n = 1;\r
+       n = (b_data + n - 1) & ~(n - 1);        /* Next nearest erase block from current data start */\r
+       n = (n - b_data) / N_FATS;\r
+       if (fmt == FS_FAT32) {          /* FAT32: Move FAT offset */\r
+               n_rsv += n;\r
+               b_fat += n;\r
+       } else {                                        /* FAT12/16: Expand FAT size */\r
+               n_fat += n;\r
+       }\r
+\r
+       /* Determine number of clusters and final check of validity of the FAT sub-type */\r
+       n_clst = (n_vol - n_rsv - n_fat * N_FATS - n_dir) / au;\r
+       if (   (fmt == FS_FAT16 && n_clst < MIN_FAT16)\r
+               || (fmt == FS_FAT32 && n_clst < MIN_FAT32)) {\r
+               return FR_MKFS_ABORTED;\r
+       }\r
+\r
+       /* Determine system ID in the partition table */\r
+       if (fmt == FS_FAT32) {\r
+               sys = 0x0C;             /* FAT32X */\r
+       } else {\r
+               if (fmt == FS_FAT12 && n_vol < 0x10000) {\r
+                       sys = 0x01;     /* FAT12(<65536) */\r
+               } else {\r
+                       sys = (n_vol < 0x10000) ? 0x04 : 0x06;  /* FAT16(<65536) : FAT12/16(>=65536) */\r
+               }\r
+       }\r
+\r
+       if (_MULTI_PARTITION && part) {\r
+               /* Update system ID in the partition table */\r
+               tbl = &fs->win[MBR_Table + (part - 1) * SZ_PTE];\r
+               tbl[4] = sys;\r
+               if (disk_write(pdrv, fs->win, 0, 1) != RES_OK) {        /* Write it to teh MBR */\r
+                       return FR_DISK_ERR;\r
+               }\r
+               md = 0xF8;\r
+       } else {\r
+               if (sfd) {      /* No partition table (SFD) */\r
+                       md = 0xF0;\r
+               } else {        /* Create partition table (FDISK) */\r
+                       mem_set(fs->win, 0, SS(fs));\r
+                       tbl = fs->win + MBR_Table;      /* Create partition table for single partition in the drive */\r
+                       tbl[1] = 1;                                             /* Partition start head */\r
+                       tbl[2] = 1;                                             /* Partition start sector */\r
+                       tbl[3] = 0;                                             /* Partition start cylinder */\r
+                       tbl[4] = sys;                                   /* System type */\r
+                       tbl[5] = 254;                                   /* Partition end head */\r
+                       n = (b_vol + n_vol) / 63 / 255;\r
+                       tbl[6] = (BYTE)(n >> 2 | 63);   /* Partition end sector */\r
+                       tbl[7] = (BYTE)n;                               /* End cylinder */\r
+                       st_dword(tbl + 8, 63);                  /* Partition start in LBA */\r
+                       st_dword(tbl + 12, n_vol);              /* Partition size in LBA */\r
+                       st_word(fs->win + BS_55AA, 0xAA55);     /* MBR signature */\r
+                       if (disk_write(pdrv, fs->win, 0, 1) != RES_OK) {        /* Write it to the MBR */\r
+                               return FR_DISK_ERR;\r
+                       }\r
+                       md = 0xF8;\r
+               }\r
+       }\r
+\r
+       /* Create BPB in the VBR */\r
+       tbl = fs->win;                                                  /* Clear sector */\r
+       mem_set(tbl, 0, SS(fs));\r
+       mem_cpy(tbl, "\xEB\xFE\x90" "MSDOS5.0", 11);/* Boot jump code, OEM name */\r
+       i = SS(fs);                                                             /* Sector size */\r
+       st_word(tbl + BPB_BytsPerSec, (WORD)i);\r
+       tbl[BPB_SecPerClus] = (BYTE)au;                 /* Sectors per cluster */\r
+       st_word(tbl + BPB_RsvdSecCnt, (WORD)n_rsv);     /* Reserved sectors */\r
+       tbl[BPB_NumFATs] = N_FATS;                              /* Number of FATs */\r
+       i = (fmt == FS_FAT32) ? 0 : N_ROOTDIR;  /* Number of root directory entries */\r
+       st_word(tbl + BPB_RootEntCnt, (WORD)i);\r
+       if (n_vol < 0x10000) {                                  /* Number of total sectors */\r
+               st_word(tbl + BPB_TotSec16, (WORD)n_vol);\r
+       } else {\r
+               st_dword(tbl + BPB_TotSec32, (WORD)n_vol);\r
+       }\r
+       tbl[BPB_Media] = md;                                    /* Media descriptor */\r
+       st_word(tbl + BPB_SecPerTrk, 63);               /* Number of sectors per track */\r
+       st_word(tbl + BPB_NumHeads, 255);               /* Number of heads */\r
+       st_dword(tbl + BPB_HiddSec, b_vol);             /* Volume offset */\r
+       n = GET_FATTIME();                                              /* Use current time as VSN */\r
+       if (fmt == FS_FAT32) {\r
+               st_dword(tbl + BS_VolID32, n);          /* VSN */\r
+               st_dword(tbl + BPB_FATSz32, n_fat);     /* Number of sectors per FAT */\r
+               st_dword(tbl + BPB_RootClus32, 2);      /* Root directory start cluster (2) */\r
+               st_word(tbl + BPB_FSInfo32, 1);         /* FSINFO record offset (VBR + 1) */\r
+               st_word(tbl + BPB_BkBootSec32, 6);      /* Backup boot record offset (VBR + 6) */\r
+               tbl[BS_DrvNum32] = 0x80;                        /* Drive number */\r
+               tbl[BS_BootSig32] = 0x29;                       /* Extended boot signature */\r
+               mem_cpy(tbl + BS_VolLab32, "NO NAME    " "FAT32   ", 19);       /* Volume label, FAT signature */\r
+       } else {\r
+               st_dword(tbl + BS_VolID, n);            /* VSN */\r
+               st_word(tbl + BPB_FATSz16, (WORD)n_fat);        /* Number of sectors per FAT */\r
+               tbl[BS_DrvNum] = 0x80;                          /* Drive number */\r
+               tbl[BS_BootSig] = 0x29;                         /* Extended boot signature */\r
+               mem_cpy(tbl + BS_VolLab, "NO NAME    " "FAT     ", 19); /* Volume label, FAT signature */\r
+       }\r
+       st_word(tbl + BS_55AA, 0xAA55);                 /* Signature (Offset is fixed here regardless of sector size) */\r
+       if (disk_write(pdrv, tbl, b_vol, 1) != RES_OK) {        /* Write it to the VBR sector */\r
+               return FR_DISK_ERR;\r
+       }\r
+       if (fmt == FS_FAT32) {                                  /* Write it to the backup VBR if needed (VBR + 6) */\r
+               disk_write(pdrv, tbl, b_vol + 6, 1);\r
+       }\r
+\r
+       /* Initialize FAT area */\r
+       wsect = b_fat;\r
+       for (i = 0; i < N_FATS; i++) {          /* Initialize each FAT copy */\r
+               mem_set(tbl, 0, SS(fs));                        /* 1st sector of the FAT  */\r
+               n = md;                                                         /* Media descriptor byte */\r
+               if (fmt != FS_FAT32) {\r
+                       n |= (fmt == FS_FAT12) ? 0x00FFFF00 : 0xFFFFFF00;\r
+                       st_dword(tbl + 0, n);                   /* Reserve cluster #0-1 (FAT12/16) */\r
+               } else {\r
+                       n |= 0xFFFFFF00;\r
+                       st_dword(tbl + 0, n);                   /* Reserve cluster #0-1 (FAT32) */\r
+                       st_dword(tbl + 4, 0xFFFFFFFF);\r
+                       st_dword(tbl + 8, 0x0FFFFFFF);  /* Reserve cluster #2 for root directory */\r
+               }\r
+               if (disk_write(pdrv, tbl, wsect++, 1) != RES_OK) {\r
+                       return FR_DISK_ERR;\r
+               }\r
+               mem_set(tbl, 0, SS(fs));                        /* Fill following FAT entries with zero */\r
+               for (n = 1; n < n_fat; n++) {           /* This loop may take a time on FAT32 volume due to many single sector writes */\r
+                       if (disk_write(pdrv, tbl, wsect++, 1) != RES_OK) {\r
+                               return FR_DISK_ERR;\r
+                       }\r
+               }\r
+       }\r
+\r
+       /* Initialize root directory */\r
+       i = (fmt == FS_FAT32) ? au : (UINT)n_dir;\r
+       do {\r
+               if (disk_write(pdrv, tbl, wsect++, 1) != RES_OK) {\r
+                       return FR_DISK_ERR;\r
+               }\r
+       } while (--i);\r
+\r
+#if _USE_TRIM  /* Erase data area if needed */\r
+       {\r
+               eb[0] = wsect; eb[1] = wsect + (n_clst - ((fmt == FS_FAT32) ? 1 : 0)) * au - 1;\r
+               disk_ioctl(pdrv, CTRL_TRIM, eb);\r
+       }\r
+#endif\r
+\r
+       /* Create FSINFO if needed */\r
+       if (fmt == FS_FAT32) {\r
+               st_dword(tbl + FSI_LeadSig, 0x41615252);\r
+               st_dword(tbl + FSI_StrucSig, 0x61417272);\r
+               st_dword(tbl + FSI_Free_Count, n_clst - 1);     /* Number of free clusters */\r
+               st_dword(tbl + FSI_Nxt_Free, 2);                        /* Last allocated cluster# */\r
+               st_word(tbl + BS_55AA, 0xAA55);\r
+               disk_write(pdrv, tbl, b_vol + 1, 1);    /* Write original (VBR + 1) */\r
+               disk_write(pdrv, tbl, b_vol + 7, 1);    /* Write backup (VBR + 7) */\r
+       }\r
+\r
+       return (disk_ioctl(pdrv, CTRL_SYNC, 0) == RES_OK) ? FR_OK : FR_DISK_ERR;\r
+}\r
+\r
+\r
+\r
+#if _MULTI_PARTITION\r
+/*-----------------------------------------------------------------------*/\r
+/* Create partition table on the physical drive                          */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+FRESULT f_fdisk (\r
+       BYTE pdrv,                      /* Physical drive number */\r
+       const DWORD szt[],      /* Pointer to the size table for each partitions */\r
+       void* work                      /* Pointer to the working buffer */\r
+)\r
+{\r
+       UINT i, n, sz_cyl, tot_cyl, b_cyl, e_cyl, p_cyl;\r
+       BYTE s_hd, e_hd, *p, *buf = (BYTE*)work;\r
+       DSTATUS stat;\r
+       DWORD sz_disk, sz_part, s_part;\r
+\r
+\r
+       stat = disk_initialize(pdrv);\r
+       if (stat & STA_NOINIT) return FR_NOT_READY;\r
+       if (stat & STA_PROTECT) return FR_WRITE_PROTECTED;\r
+       if (disk_ioctl(pdrv, GET_SECTOR_COUNT, &sz_disk)) return FR_DISK_ERR;\r
+\r
+       /* Determine CHS in the table regardless of the drive geometry */\r
+       for (n = 16; n < 256 && sz_disk / n / 63 > 1024; n *= 2) ;\r
+       if (n == 256) n--;\r
+       e_hd = n - 1;\r
+       sz_cyl = 63 * n;\r
+       tot_cyl = sz_disk / sz_cyl;\r
+\r
+       /* Create partition table */\r
+       mem_set(buf, 0, _MAX_SS);\r
+       p = buf + MBR_Table; b_cyl = 0;\r
+       for (i = 0; i < 4; i++, p += SZ_PTE) {\r
+               p_cyl = (szt[i] <= 100U) ? (DWORD)tot_cyl * szt[i] / 100 : szt[i] / sz_cyl;\r
+               if (!p_cyl) continue;\r
+               s_part = (DWORD)sz_cyl * b_cyl;\r
+               sz_part = (DWORD)sz_cyl * p_cyl;\r
+               if (i == 0) {   /* Exclude first track of cylinder 0 */\r
+                       s_hd = 1;\r
+                       s_part += 63; sz_part -= 63;\r
+               } else {\r
+                       s_hd = 0;\r
+               }\r
+               e_cyl = b_cyl + p_cyl - 1;\r
+               if (e_cyl >= tot_cyl) return FR_INVALID_PARAMETER;\r
+\r
+               /* Set partition table */\r
+               p[1] = s_hd;                                            /* Start head */\r
+               p[2] = (BYTE)((b_cyl >> 2) + 1);        /* Start sector */\r
+               p[3] = (BYTE)b_cyl;                                     /* Start cylinder */\r
+               p[4] = 0x06;                                            /* System type (temporary setting) */\r
+               p[5] = e_hd;                                            /* End head */\r
+               p[6] = (BYTE)((e_cyl >> 2) + 63);       /* End sector */\r
+               p[7] = (BYTE)e_cyl;                                     /* End cylinder */\r
+               st_dword(p + 8, s_part);                        /* Start sector in LBA */\r
+               st_dword(p + 12, sz_part);                      /* Partition size */\r
+\r
+               /* Next partition */\r
+               b_cyl += p_cyl;\r
+       }\r
+       st_word(p, 0xAA55);\r
+\r
+       /* Write it to the MBR */\r
+       return (disk_write(pdrv, buf, 0, 1) != RES_OK || disk_ioctl(pdrv, CTRL_SYNC, 0) != RES_OK) ? FR_DISK_ERR : FR_OK;\r
+}\r
+\r
+\r
+#endif /* _MULTI_PARTITION */\r
+#endif /* _USE_MKFS && !_FS_READONLY */\r
+\r
+\r
+\r
+\r
+#if _USE_STRFUNC\r
+/*-----------------------------------------------------------------------*/\r
+/* Get a string from the file                                            */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+TCHAR* f_gets (\r
+       TCHAR* buff,    /* Pointer to the string buffer to read */\r
+       int len,                /* Size of string buffer (characters) */\r
+       FIL* fp                 /* Pointer to the file object */\r
+)\r
+{\r
+       int n = 0;\r
+       TCHAR c, *p = buff;\r
+       BYTE s[2];\r
+       UINT rc;\r
+\r
+\r
+       while (n < len - 1) {   /* Read characters until buffer gets filled */\r
+#if _LFN_UNICODE\r
+#if _STRF_ENCODE == 3          /* Read a character in UTF-8 */\r
+               f_read(fp, s, 1, &rc);\r
+               if (rc != 1) break;\r
+               c = s[0];\r
+               if (c >= 0x80) {\r
+                       if (c < 0xC0) continue; /* Skip stray trailer */\r
+                       if (c < 0xE0) {                 /* Two-byte sequence */\r
+                               f_read(fp, s, 1, &rc);\r
+                               if (rc != 1) break;\r
+                               c = (c & 0x1F) << 6 | (s[0] & 0x3F);\r
+                               if (c < 0x80) c = '?';\r
+                       } else {\r
+                               if (c < 0xF0) {         /* Three-byte sequence */\r
+                                       f_read(fp, s, 2, &rc);\r
+                                       if (rc != 2) break;\r
+                                       c = c << 12 | (s[0] & 0x3F) << 6 | (s[1] & 0x3F);\r
+                                       if (c < 0x800) c = '?';\r
+                               } else {                        /* Reject four-byte sequence */\r
+                                       c = '?';\r
+                               }\r
+                       }\r
+               }\r
+#elif _STRF_ENCODE == 2                /* Read a character in UTF-16BE */\r
+               f_read(fp, s, 2, &rc);\r
+               if (rc != 2) break;\r
+               c = s[1] + (s[0] << 8);\r
+#elif _STRF_ENCODE == 1                /* Read a character in UTF-16LE */\r
+               f_read(fp, s, 2, &rc);\r
+               if (rc != 2) break;\r
+               c = s[0] + (s[1] << 8);\r
+#else                                          /* Read a character in ANSI/OEM */\r
+               f_read(fp, s, 1, &rc);\r
+               if (rc != 1) break;\r
+               c = s[0];\r
+               if (IsDBCS1(c)) {\r
+                       f_read(fp, s, 1, &rc);\r
+                       if (rc != 1) break;\r
+                       c = (c << 8) + s[0];\r
+               }\r
+               c = ff_convert(c, 1);   /* OEM -> Unicode */\r
+               if (!c) c = '?';\r
+#endif\r
+#else                                          /* Read a character without conversion */\r
+               f_read(fp, s, 1, &rc);\r
+               if (rc != 1) break;\r
+               c = s[0];\r
+#endif\r
+               if (_USE_STRFUNC == 2 && c == '\r') continue;   /* Strip '\r' */\r
+               *p++ = c;\r
+               n++;\r
+               if (c == '\n') break;           /* Break on EOL */\r
+       }\r
+       *p = 0;\r
+       return n ? buff : 0;                    /* When no data read (eof or error), return with error. */\r
+}\r
+\r
+\r
+\r
+\r
+#if !_FS_READONLY\r
+#include <stdarg.h>\r
+/*-----------------------------------------------------------------------*/\r
+/* Put a character to the file                                           */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+typedef struct {\r
+       FIL* fp;\r
+       int idx, nchr;\r
+       BYTE buf[64];\r
+} putbuff;\r
+\r
+\r
+static\r
+void putc_bfd (\r
+       putbuff* pb,\r
+       TCHAR c\r
+)\r
+{\r
+       UINT bw;\r
+       int i;\r
+\r
+\r
+       if (_USE_STRFUNC == 2 && c == '\n') {    /* LF -> CRLF conversion */\r
+               putc_bfd(pb, '\r');\r
+       }\r
+\r
+       i = pb->idx;    /* Buffer write index (-1:error) */\r
+       if (i < 0) return;\r
+\r
+#if _LFN_UNICODE\r
+#if _STRF_ENCODE == 3                  /* Write a character in UTF-8 */\r
+       if (c < 0x80) {                         /* 7-bit */\r
+               pb->buf[i++] = (BYTE)c;\r
+       } else {\r
+               if (c < 0x800) {                /* 11-bit */\r
+                       pb->buf[i++] = (BYTE)(0xC0 | c >> 6);\r
+               } else {                                /* 16-bit */\r
+                       pb->buf[i++] = (BYTE)(0xE0 | c >> 12);\r
+                       pb->buf[i++] = (BYTE)(0x80 | (c >> 6 & 0x3F));\r
+               }\r
+               pb->buf[i++] = (BYTE)(0x80 | (c & 0x3F));\r
+       }\r
+#elif _STRF_ENCODE == 2                        /* Write a character in UTF-16BE */\r
+       pb->buf[i++] = (BYTE)(c >> 8);\r
+       pb->buf[i++] = (BYTE)c;\r
+#elif _STRF_ENCODE == 1                        /* Write a character in UTF-16LE */\r
+       pb->buf[i++] = (BYTE)c;\r
+       pb->buf[i++] = (BYTE)(c >> 8);\r
+#else                                                  /* Write a character in ANSI/OEM */\r
+       c = ff_convert(c, 0);   /* Unicode -> OEM */\r
+       if (!c) c = '?';\r
+       if (c >= 0x100)\r
+               pb->buf[i++] = (BYTE)(c >> 8);\r
+       pb->buf[i++] = (BYTE)c;\r
+#endif\r
+#else                                                  /* Write a character without conversion */\r
+       pb->buf[i++] = (BYTE)c;\r
+#endif\r
+\r
+       if (i >= (int)(sizeof pb->buf) - 3) {   /* Write buffered characters to the file */\r
+               f_write(pb->fp, pb->buf, (UINT)i, &bw);\r
+               i = (bw == (UINT)i) ? 0 : -1;\r
+       }\r
+       pb->idx = i;\r
+       pb->nchr++;\r
+}\r
+\r
+\r
+\r
+int f_putc (\r
+       TCHAR c,        /* A character to be output */\r
+       FIL* fp         /* Pointer to the file object */\r
+)\r
+{\r
+       putbuff pb;\r
+       UINT nw;\r
+\r
+\r
+       pb.fp = fp;                     /* Initialize output buffer */\r
+       pb.nchr = pb.idx = 0;\r
+\r
+       putc_bfd(&pb, c);       /* Put a character */\r
+\r
+       if (   pb.idx >= 0      /* Flush buffered characters to the file */\r
+               && f_write(pb.fp, pb.buf, (UINT)pb.idx, &nw) == FR_OK\r
+               && (UINT)pb.idx == nw) return pb.nchr;\r
+       return EOF;\r
+}\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Put a string to the file                                              */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+int f_puts (\r
+       const TCHAR* str,       /* Pointer to the string to be output */\r
+       FIL* fp                         /* Pointer to the file object */\r
+)\r
+{\r
+       putbuff pb;\r
+       UINT nw;\r
+\r
+\r
+       pb.fp = fp;                             /* Initialize output buffer */\r
+       pb.nchr = pb.idx = 0;\r
+\r
+       while (*str)                    /* Put the string */\r
+               putc_bfd(&pb, *str++);\r
+\r
+       if (   pb.idx >= 0              /* Flush buffered characters to the file */\r
+               && f_write(pb.fp, pb.buf, (UINT)pb.idx, &nw) == FR_OK\r
+               && (UINT)pb.idx == nw) return pb.nchr;\r
+       return EOF;\r
+}\r
+\r
+\r
+\r
+\r
+/*-----------------------------------------------------------------------*/\r
+/* Put a formatted string to the file                                    */\r
+/*-----------------------------------------------------------------------*/\r
+\r
+int f_printf (\r
+       FIL* fp,                        /* Pointer to the file object */\r
+       const TCHAR* fmt,       /* Pointer to the format string */\r
+       ...                                     /* Optional arguments... */\r
+)\r
+{\r
+       va_list arp;\r
+       BYTE f, r;\r
+       UINT nw, i, j, w;\r
+       DWORD v;\r
+       TCHAR c, d, str[32], *p;\r
+       putbuff pb;\r
+\r
+\r
+       pb.fp = fp;                             /* Initialize output buffer */\r
+       pb.nchr = pb.idx = 0;\r
+\r
+       va_start(arp, fmt);\r
+\r
+       for (;;) {\r
+               c = *fmt++;\r
+               if (c == 0) break;                      /* End of string */\r
+               if (c != '%') {                         /* Non escape character */\r
+                       putc_bfd(&pb, c);\r
+                       continue;\r
+               }\r
+               w = f = 0;\r
+               c = *fmt++;\r
+               if (c == '0') {                         /* Flag: '0' padding */\r
+                       f = 1; c = *fmt++;\r
+               } else {\r
+                       if (c == '-') {                 /* Flag: left justified */\r
+                               f = 2; c = *fmt++;\r
+                       }\r
+               }\r
+               while (IsDigit(c)) {            /* Precision */\r
+                       w = w * 10 + c - '0';\r
+                       c = *fmt++;\r
+               }\r
+               if (c == 'l' || c == 'L') {     /* Prefix: Size is long int */\r
+                       f |= 4; c = *fmt++;\r
+               }\r
+               if (!c) break;\r
+               d = c;\r
+               if (IsLower(d)) d -= 0x20;\r
+               switch (d) {                            /* Type is... */\r
+               case 'S' :                                      /* String */\r
+                       p = va_arg(arp, TCHAR*);\r
+                       for (j = 0; p[j]; j++) ;\r
+                       if (!(f & 2)) {\r
+                               while (j++ < w) putc_bfd(&pb, ' ');\r
+                       }\r
+                       while (*p) putc_bfd(&pb, *p++);\r
+                       while (j++ < w) putc_bfd(&pb, ' ');\r
+                       continue;\r
+               case 'C' :                                      /* Character */\r
+                       putc_bfd(&pb, (TCHAR)va_arg(arp, int)); continue;\r
+               case 'B' :                                      /* Binary */\r
+                       r = 2; break;\r
+               case 'O' :                                      /* Octal */\r
+                       r = 8; break;\r
+               case 'D' :                                      /* Signed decimal */\r
+               case 'U' :                                      /* Unsigned decimal */\r
+                       r = 10; break;\r
+               case 'X' :                                      /* Hexdecimal */\r
+                       r = 16; break;\r
+               default:                                        /* Unknown type (pass-through) */\r
+                       putc_bfd(&pb, c); continue;\r
+               }\r
+\r
+               /* Get an argument and put it in numeral */\r
+               v = (f & 4) ? (DWORD)va_arg(arp, long) : ((d == 'D') ? (DWORD)(long)va_arg(arp, int) : (DWORD)va_arg(arp, unsigned int));\r
+               if (d == 'D' && (v & 0x80000000)) {\r
+                       v = 0 - v;\r
+                       f |= 8;\r
+               }\r
+               i = 0;\r
+               do {\r
+                       d = (TCHAR)(v % r); v /= r;\r
+                       if (d > 9) d += (c == 'x') ? 0x27 : 0x07;\r
+                       str[i++] = d + '0';\r
+               } while (v && i < sizeof str / sizeof str[0]);\r
+               if (f & 8) str[i++] = '-';\r
+               j = i; d = (f & 1) ? '0' : ' ';\r
+               while (!(f & 2) && j++ < w) putc_bfd(&pb, d);\r
+               do putc_bfd(&pb, str[--i]); while (i);\r
+               while (j++ < w) putc_bfd(&pb, d);\r
+       }\r
+\r
+       va_end(arp);\r
+\r
+       if (   pb.idx >= 0              /* Flush buffered characters to the file */\r
+               && f_write(pb.fp, pb.buf, (UINT)pb.idx, &nw) == FR_OK\r
+               && (UINT)pb.idx == nw) return pb.nchr;\r
+       return EOF;\r
+}\r
+\r
+#endif /* !_FS_READONLY */\r
+#endif /* _USE_STRFUNC */\r
diff --git a/packages/ti/fs/fatfs/src/src_files_common.mk b/packages/ti/fs/fatfs/src/src_files_common.mk
new file mode 100644 (file)
index 0000000..f14b2a2
--- /dev/null
@@ -0,0 +1,12 @@
+
+SRCDIR = . src
+INCDIR = . src
+# Common source files across all platforms and cores
+SRCS_COMMON += diskio.c ff.c FATFS_drv.c
+
+PACKAGE_SRCS_COMMON = makefile FATFS.h fatfs_component.mk src/FATFS_osal.h \
+                      docs/ReleaseNotes_FATFS_LLD.pdf \
+                      ff.h ffconf.h src/FATFS_drv_log.h \
+                      diskio.h integer.h \
+                      build/makefile_profile_indp.mk build/makefile_indp.mk src/src_files_common.mk \
+                      src/diskio.c src/ff.c src/FATFS_drv.c .gitignore
diff --git a/packages/ti/fs/fatfs/temp.txt b/packages/ti/fs/fatfs/temp.txt
new file mode 100644 (file)
index 0000000..e69de29