Added FatFS.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
imi415 2021-02-10 01:49:45 +08:00
parent 205ef215dd
commit 3d353d5adc
Signed by: imi415
GPG Key ID: 17F01E106F9F5E0A
169 changed files with 60438 additions and 53 deletions

View File

@ -53,12 +53,15 @@ ${ProjDirPath}/CMSIS
${ProjDirPath}/component/lists
${ProjDirPath}/component/serial_manager
${ProjDirPath}/component/uart
${ProjDirPath}/component/osa
${ProjDirPath}/device
${ProjDirPath}/drivers
${ProjDirPath}/freertos
${ProjDirPath}/startup
${ProjDirPath}/utilities
${ProjDirPath}/xip
${ProjDirPath}/middleware/fatfs
${ProjDirPath}/middleware/sdmmc
)
# include modules
@ -84,8 +87,14 @@ include(driver_semc_MIMXRT1052)
include(driver_elcdif_MIMXRT1052)
include(driver_enet_MIMXRT1052)
include(driver_lpuart_MIMXRT1052)
include(driver_usdhc_MIMXRT1052)
include(driver_cache_armv7_m7_MIMXRT1052)
include(device_MIMXRT1052_startup_MIMXRT1052)
include(driver_iomuxc_MIMXRT1052)
@ -102,6 +111,22 @@ include(middleware_freertos-kernel_MIMXRT1052)
include(middleware_freertos-kernel_extension_MIMXRT1052)
include(component_osa_free_rtos_MIMXRT1052)
include(middleware_sdmmc_sd_MIMXRT1052)
include(middleware_sdmmc_common_MIMXRT1052)
include(middleware_sdmmc_host_usdhc_MIMXRT1052)
include(middleware_sdmmc_host_usdhc_freertos_MIMXRT1052)
include(middleware_sdmmc_osa_freertos_MIMXRT1052)
include(middleware_fatfs_MIMXRT1052)
include(middleware_fatfs_sd_MIMXRT1052)
include(utilities_misc_utilities_MIMXRT1052)
include(CMSIS_Include_core_cm7_MIMXRT1052)

View File

@ -58,9 +58,9 @@ outputs:
- {id: CLK_1M.outFreq, value: 1 MHz}
- {id: CLK_24M.outFreq, value: 24 MHz}
- {id: CSI_CLK_ROOT.outFreq, value: 12 MHz}
- {id: ENET1_TX_CLK.outFreq, value: 2.4 MHz}
- {id: ENET_125M_CLK.outFreq, value: 2.4 MHz}
- {id: ENET_25M_REF_CLK.outFreq, value: 1.2 MHz}
- {id: ENET1_TX_CLK.outFreq, value: 125 MHz}
- {id: ENET_125M_CLK.outFreq, value: 125 MHz}
- {id: ENET_25M_REF_CLK.outFreq, value: 25 MHz}
- {id: FLEXIO1_CLK_ROOT.outFreq, value: 30 MHz}
- {id: FLEXIO2_CLK_ROOT.outFreq, value: 30 MHz}
- {id: FLEXSPI_CLK_ROOT.outFreq, value: 160 MHz}
@ -102,6 +102,7 @@ settings:
- {id: CCM.SEMC_PODF.scale, value: '4', locked: true}
- {id: CCM.TRACE_CLK_SEL.sel, value: CCM_ANALOG.PLL2_MAIN_CLK}
- {id: CCM.TRACE_PODF.scale, value: '4', locked: true}
- {id: CCM_ANALOG.ENET_DIV.scale, value: '4', locked: true}
- {id: CCM_ANALOG.PLL1_BYPASS.sel, value: CCM_ANALOG.PLL1}
- {id: CCM_ANALOG.PLL1_PREDIV.scale, value: '1', locked: true}
- {id: CCM_ANALOG.PLL1_VDIV.scale, value: '50', locked: true}
@ -126,8 +127,8 @@ settings:
- {id: CCM_ANALOG.PLL5.num, value: '0'}
- {id: CCM_ANALOG.PLL5_BYPASS.sel, value: CCM_ANALOG.PLL5_POST_DIV}
- {id: CCM_ANALOG.PLL5_POST_DIV.scale, value: '2'}
- {id: CCM_ANALOG.PLL6_BYPASS.sel, value: CCM_ANALOG.PLL6}
- {id: CCM_ANALOG.VIDEO_DIV.scale, value: '4'}
- {id: CCM_ANALOG_PLL_ENET_POWERDOWN_CFG, value: 'Yes'}
- {id: CCM_ANALOG_PLL_USB1_POWER_CFG, value: 'Yes'}
- {id: CCM_ANALOG_PLL_VIDEO_POWERDOWN_CFG, value: 'No'}
sources:
@ -162,6 +163,13 @@ const clock_video_pll_config_t videoPllConfig_BOARD_BootClockRUN =
.denominator = 1, /* 30 bit denominator of fractional loop divider, Fout = Fin * ( loopDivider + numerator / denominator ) */
.src = 0, /* Bypass clock source, 0 - OSC 24M, 1 - CLK1_P and CLK1_N */
};
const clock_enet_pll_config_t enetPllConfig_BOARD_BootClockRUN =
{
.enableClkOutput = true, /* Enable the PLL providing the ENET 125MHz reference clock */
.enableClkOutput25M = true, /* Enable the PLL providing the ENET 25MHz reference clock */
.loopDivider = 3, /* Set frequency of ethernet reference clock to 125 MHz */
.src = 0, /* Bypass clock source, 0 - OSC 24M, 1 - CLK1_P and CLK1_N */
};
/*******************************************************************************
* Code for BOARD_BootClockRUN configuration
******************************************************************************/
@ -428,16 +436,10 @@ void BOARD_BootClockRUN(void)
CCM_ANALOG->PLL_VIDEO &= ~CCM_ANALOG_PLL_VIDEO_PFD_OFFSET_EN_MASK;
/* Disable bypass for Video PLL. */
CLOCK_SetPllBypass(CCM_ANALOG, kCLOCK_PllVideo, 0);
/* DeInit Enet PLL. */
CLOCK_DeinitEnetPll();
/* Bypass Enet PLL. */
CLOCK_SetPllBypass(CCM_ANALOG, kCLOCK_PllEnet, 1);
/* Set Enet output divider. */
CCM_ANALOG->PLL_ENET = (CCM_ANALOG->PLL_ENET & (~CCM_ANALOG_PLL_ENET_DIV_SELECT_MASK)) | CCM_ANALOG_PLL_ENET_DIV_SELECT(1);
/* Enable Enet output. */
CCM_ANALOG->PLL_ENET |= CCM_ANALOG_PLL_ENET_ENABLE_MASK;
/* Enable Enet25M output. */
CCM_ANALOG->PLL_ENET |= CCM_ANALOG_PLL_ENET_ENET_25M_REF_EN_MASK;
/* Init Enet PLL. */
CLOCK_InitEnetPll(&enetPllConfig_BOARD_BootClockRUN);
/* Disable pfd offset. */
CCM_ANALOG->PLL_ENET &= ~CCM_ANALOG_PLL_ENET_PFD_OFFSET_EN_MASK;
/* DeInit Usb2 PLL. */
CLOCK_DeinitUsb2Pll();
/* Bypass Usb2 PLL. */

View File

@ -67,7 +67,7 @@ outputs:
- {id: GPT1_ipg_clk_highfreq.outFreq, value: 75 MHz}
- {id: GPT2_ipg_clk_highfreq.outFreq, value: 75 MHz}
- {id: IPG_CLK_ROOT.outFreq, value: 150 MHz}
- {id: LCDIF_CLK_ROOT.outFreq, value: 27 MHz}
- {id: LCDIF_CLK_ROOT.outFreq, value: 33.75 MHz}
- {id: LPI2C_CLK_ROOT.outFreq, value: 60 MHz}
- {id: LPSPI_CLK_ROOT.outFreq, value: 105.6 MHz}
- {id: LVDS1_CLK.outFreq, value: 1.2 GHz}
@ -95,7 +95,7 @@ settings:
- {id: CCM.ARM_PODF.scale, value: '2', locked: true}
- {id: CCM.FLEXSPI_PODF.scale, value: '3', locked: true}
- {id: CCM.FLEXSPI_SEL.sel, value: CCM.PLL3_SW_CLK_SEL}
- {id: CCM.LCDIF_PODF.scale, value: '5', locked: true}
- {id: CCM.LCDIF_PODF.scale, value: '4', locked: true}
- {id: CCM.LCDIF_PRED.scale, value: '4', locked: true}
- {id: CCM.LPSPI_PODF.scale, value: '5', locked: true}
- {id: CCM.PERCLK_PODF.scale, value: '2', locked: true}
@ -330,7 +330,7 @@ void BOARD_BootClockRUN(void)
/* Set LCDIF_PRED. */
CLOCK_SetDiv(kCLOCK_LcdifPreDiv, 3);
/* Set LCDIF_CLK_PODF. */
CLOCK_SetDiv(kCLOCK_LcdifDiv, 4);
CLOCK_SetDiv(kCLOCK_LcdifDiv, 3);
/* Set Lcdif pre clock source. */
CLOCK_SetMux(kCLOCK_LcdifPreMux, 5);
/* Disable SPDIF clock gate. */

View File

@ -44,9 +44,9 @@ void BOARD_InitBootClocks(void);
#define BOARD_BOOTCLOCKRUN_CLK_1M 1000000UL
#define BOARD_BOOTCLOCKRUN_CLK_24M 24000000UL
#define BOARD_BOOTCLOCKRUN_CSI_CLK_ROOT 12000000UL
#define BOARD_BOOTCLOCKRUN_ENET1_TX_CLK 2400000UL
#define BOARD_BOOTCLOCKRUN_ENET_125M_CLK 2400000UL
#define BOARD_BOOTCLOCKRUN_ENET_25M_REF_CLK 1200000UL
#define BOARD_BOOTCLOCKRUN_ENET1_TX_CLK 125000000UL
#define BOARD_BOOTCLOCKRUN_ENET_125M_CLK 125000000UL
#define BOARD_BOOTCLOCKRUN_ENET_25M_REF_CLK 25000000UL
#define BOARD_BOOTCLOCKRUN_FLEXIO1_CLK_ROOT 30000000UL
#define BOARD_BOOTCLOCKRUN_FLEXIO2_CLK_ROOT 30000000UL
#define BOARD_BOOTCLOCKRUN_FLEXSPI_CLK_ROOT 160000000UL
@ -94,6 +94,9 @@ extern const clock_sys_pll_config_t sysPllConfig_BOARD_BootClockRUN;
/*! @brief Video PLL set for BOARD_BootClockRUN configuration.
*/
extern const clock_video_pll_config_t videoPllConfig_BOARD_BootClockRUN;
/*! @brief Enet PLL set for BOARD_BootClockRUN configuration.
*/
extern const clock_enet_pll_config_t enetPllConfig_BOARD_BootClockRUN;
/*******************************************************************************
* API for BOARD_BootClockRUN configuration

View File

@ -53,7 +53,7 @@ void BOARD_InitBootClocks(void);
#define BOARD_BOOTCLOCKRUN_GPT1_IPG_CLK_HIGHFREQ 75000000UL
#define BOARD_BOOTCLOCKRUN_GPT2_IPG_CLK_HIGHFREQ 75000000UL
#define BOARD_BOOTCLOCKRUN_IPG_CLK_ROOT 150000000UL
#define BOARD_BOOTCLOCKRUN_LCDIF_CLK_ROOT 27000000UL
#define BOARD_BOOTCLOCKRUN_LCDIF_CLK_ROOT 33750000UL
#define BOARD_BOOTCLOCKRUN_LPI2C_CLK_ROOT 60000000UL
#define BOARD_BOOTCLOCKRUN_LPSPI_CLK_ROOT 105600000UL
#define BOARD_BOOTCLOCKRUN_LVDS1_CLK 1200000000UL

View File

@ -295,6 +295,112 @@ static void LCDIF_init(void) {
ELCDIF_RgbModeStart(LCDIF_PERIPHERAL);
}
/***********************************************************************************************************************
* FATFS initialization code
**********************************************************************************************************************/
/* clang-format off */
/* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
instance:
- name: 'FATFS'
- type: 'fatfs'
- mode: 'general'
- custom_name_enabled: 'false'
- type_id: 'fatfs_2f85acf758668258920f70258052a088'
- functional_group: 'BOARD_InitPeripherals'
- config_sets:
- init_config:
- initConfig:
- initPartitionsStr: 'false'
- multiplePartitions:
- 0:
- Volume: '0'
- Partition: 'autoDetect'
- 1:
- Volume: '0'
- Partition: 'autoDetect'
- enablePhysicalLayerInit: 'false'
- diskConfig:
- initFunctionID: 'FATFS_DiskInit'
- initResultObject: 'false'
- resultName: 'FATFS_Result'
- fatfsObjects:
- 0:
- objID: 'FATFS_System_0'
- diskMount: 'false'
- mountPath: '0:'
- mountInitOpt: 'false'
- filObjects: []
- filInfoObjects: []
- dirObjects: []
- ff_config:
- revisionID: 'rev14_1'
- MSDKadaptation: 'SD_DISK_ENABLE'
- functionConfig:
- FF_FS_READONLY: 'false'
- FF_FS_MINIMIZE: 'level1'
- FF_USE_STRFUNC: 'enableWithoutConversion'
- FF_USE_FIND: 'disableDirRead'
- FF_USE_MKFS: 'true'
- FF_USE_FASTSEEK: 'false'
- FF_USE_EXPAND: 'false'
- FF_USE_CHMOD: 'false'
- FF_USE_LABEL: 'false'
- FF_USE_FORWARD: 'false'
- namespaceConfig:
- FF_USE_LFN: 'enableLfnStack'
- FF_MAX_LFN: '255'
- FF_LFN_BUF: 'LFNID'
- FF_SFN_BUF: 'SFNID'
- FF_LFN_UNICODE: 'ansiOEM'
- FF_STRF_ENCODE: 'ansiOEM'
- FF_CODE_PAGE: 'cpJapanese'
- FF_FS_RPATH: 'enableRP2'
- driveConfig:
- FF_VOLUMES: '6'
- FF_STR_VOLUME_ID: 'numericId'
- volumes:
- 0:
- volumeStr: 'RAM'
- 1:
- volumeStr: 'NAND'
- 2:
- volumeStr: 'CF'
- 3:
- volumeStr: 'SD'
- 4:
- volumeStr: 'SD2'
- 5:
- volumeStr: 'USB'
- FF_MULTI_PARTITION: 'false'
- FF_MIN_SS: 'value512'
- FF_MAX_SS: 'value512'
- FF_LBA64: 'false'
- FF_MIN_GPT: '0x100000000'
- FF_USE_TRIM: 'false'
- systemConfig:
- FF_FS_TINY: 'false'
- FF_FS_EXFAT: 'false'
- FF_FS_NORTC: 'false'
- FF_NORTC_MON: '1'
- FF_NORTC_MDAY: '1'
- FF_NORTC_YEAR: '2020'
- FF_FS_NOFSINFO: ''
- FF_FS_LOCK: '0'
- FF_FS_REENTRANT: 'false'
- FF_FS_TIMEOUT: '1000'
- FF_SYNC_t: 'HANDLE'
- includeOS: 'false'
- headerFileName: 'somertos.h'
- fatfs_codegenerator: []
* BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS **********/
/* clang-format on */
/* FATFS System object */
FATFS FATFS_System_0;
/* Empty initialization function (commented out)
static void FATFS_init(void) {
} */
/***********************************************************************************************************************
* Initialization functions
**********************************************************************************************************************/

View File

@ -246,8 +246,8 @@ instance:
- polarityFlags_st:
- vSyncActive: 'kELCDIF_VsyncActiveLow'
- hSyncActive: 'kELCDIF_HsyncActiveLow'
- dataEnableActive: 'kELCDIF_DataEnableActiveLow'
- driveDataClkEdge: 'kELCDIF_DriveDataOnFallingClkEdge'
- dataEnableActive: 'kELCDIF_DataEnableActiveHigh'
- driveDataClkEdge: 'kELCDIF_DriveDataOnRisingClkEdge'
- bufferName: 'defaultBuffer'
- bufferAlign: '64'
- pixelFormat: 'kELCDIF_PixelFormatRGB565'
@ -274,7 +274,7 @@ const elcdif_rgb_mode_config_t LCDIF_rgbConfig = {
.vsw = 10U,
.vfp = 22U,
.vbp = 23U,
.polarityFlags = (kELCDIF_VsyncActiveLow | kELCDIF_HsyncActiveLow | kELCDIF_DataEnableActiveLow | kELCDIF_DriveDataOnFallingClkEdge),
.polarityFlags = (kELCDIF_VsyncActiveLow | kELCDIF_HsyncActiveLow | kELCDIF_DataEnableActiveHigh | kELCDIF_DriveDataOnRisingClkEdge),
.bufferAddr = (uint32_t) LCDIF_Buffer[0],
.pixelFormat = kELCDIF_PixelFormatRGB565,
.dataBus = kELCDIF_DataBus16Bit

View File

@ -14,6 +14,8 @@
#include "fsl_clock.h"
#include "fsl_semc.h"
#include "fsl_elcdif.h"
#include "ff.h"
#include "diskio.h"
#if defined(__cplusplus)
extern "C" {
@ -57,6 +59,8 @@ extern semc_sdram_config_t SEMC_sdram_struct;
extern const elcdif_rgb_mode_config_t LCDIF_rgbConfig;
/* RGB buffer */
extern uint16_t LCDIF_Buffer[2][LCDIF_PANEL_HEIGHT][LCDIF_PANEL_WIDTH];
/* FATFS System object */
extern FATFS FATFS_System_0;
/***********************************************************************************************************************
* Initialization functions

View File

@ -56,7 +56,7 @@ extern semc_sdram_config_t SEMC_sdram_struct;
/* RGB mode configuration */
extern const elcdif_rgb_mode_config_t LCDIF_rgbConfig;
/* RGB buffer */
extern uint32_t LCDIF_Buffer[2][LCDIF_PANEL_HEIGHT][LCDIF_PANEL_WIDTH];
extern uint16_t LCDIF_Buffer[2][LCDIF_PANEL_HEIGHT][LCDIF_PANEL_WIDTH];
/***********************************************************************************************************************
* Initialization functions

View File

@ -16,7 +16,7 @@ pin_labels:
- {pin_num: M11, pin_signal: GPIO_AD_B0_02, label: LCDIF_RESET, identifier: LCDIF_RESEt;LCDIF_RESET}
- {pin_num: G13, pin_signal: GPIO_AD_B0_10, label: LED_BLUE, identifier: INT1_COMBO;LED_BLUE}
- {pin_num: L10, pin_signal: GPIO_AD_B0_15, label: LCDIF_BL, identifier: CAN2_RX;LCDIF_BL}
power_domains: {NVCC_GPIO: '3.3'}
power_domains: {NVCC_GPIO: '3.3', NVCC_SD0: '3.3'}
* BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS ***********
*/
@ -106,8 +106,25 @@ BOARD_InitPins:
- {pin_num: E8, peripheral: LCDIF, signal: lcdif_hsync, pin_signal: GPIO_B0_02}
- {pin_num: E7, peripheral: LCDIF, signal: lcdif_enable, pin_signal: GPIO_B0_01}
- {pin_num: M11, peripheral: GPIO1, signal: 'gpio_io, 02', pin_signal: GPIO_AD_B0_02, identifier: LCDIF_RESET, direction: OUTPUT, gpio_init_state: 'true'}
- {pin_num: L10, peripheral: GPIO1, signal: 'gpio_io, 15', pin_signal: GPIO_AD_B0_15, identifier: LCDIF_BL, direction: OUTPUT, gpio_init_state: 'true', pull_up_down_config: Pull_Up_100K_Ohm}
- {pin_num: G13, peripheral: GPIO1, signal: 'gpio_io, 10', pin_signal: GPIO_AD_B0_10, identifier: LED_BLUE, direction: OUTPUT, gpio_init_state: 'true'}
- {pin_num: L10, peripheral: GPIO1, signal: 'gpio_io, 15', pin_signal: GPIO_AD_B0_15, identifier: LCDIF_BL, direction: OUTPUT, gpio_init_state: 'true'}
- {pin_num: L12, peripheral: ENET, signal: enet_mdc, pin_signal: GPIO_AD_B1_04}
- {pin_num: B14, peripheral: ENET, signal: enet_mdio, pin_signal: GPIO_B1_15}
- {pin_num: B13, peripheral: ENET, signal: enet_tx_clk, pin_signal: GPIO_B1_10}
- {pin_num: B12, peripheral: ENET, signal: 'enet_tx_data, 0', pin_signal: GPIO_B1_07}
- {pin_num: A12, peripheral: ENET, signal: 'enet_tx_data, 1', pin_signal: GPIO_B1_08}
- {pin_num: C13, peripheral: ENET, signal: enet_rx_er, pin_signal: GPIO_B1_11}
- {pin_num: A13, peripheral: ENET, signal: enet_tx_en, pin_signal: GPIO_B1_09}
- {pin_num: E12, peripheral: ENET, signal: 'enet_rx_data, 0', pin_signal: GPIO_B1_04}
- {pin_num: D12, peripheral: ENET, signal: 'enet_rx_data, 1', pin_signal: GPIO_B1_05}
- {pin_num: C12, peripheral: ENET, signal: enet_rx_en, pin_signal: GPIO_B1_06}
- {pin_num: C14, peripheral: USDHC1, signal: usdhc_vselect, pin_signal: GPIO_B1_14}
- {pin_num: J3, peripheral: USDHC1, signal: usdhc_clk, pin_signal: GPIO_SD_B0_01}
- {pin_num: J4, peripheral: USDHC1, signal: usdhc_cmd, pin_signal: GPIO_SD_B0_00}
- {pin_num: K1, peripheral: USDHC1, signal: 'usdhc_data, 1', pin_signal: GPIO_SD_B0_03}
- {pin_num: H2, peripheral: USDHC1, signal: 'usdhc_data, 2', pin_signal: GPIO_SD_B0_04}
- {pin_num: J2, peripheral: USDHC1, signal: 'usdhc_data, 3', pin_signal: GPIO_SD_B0_05}
- {pin_num: J1, peripheral: USDHC1, signal: 'usdhc_data, 0', pin_signal: GPIO_SD_B0_02}
* BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS ***********
*/
@ -152,6 +169,7 @@ void BOARD_InitPins(void) {
IOMUXC_SetPinMux(IOMUXC_GPIO_AD_B0_12_LPUART1_TX, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_AD_B0_13_LPUART1_RX, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_AD_B0_15_GPIO1_IO15, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_AD_B1_04_ENET_MDC, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_B0_00_LCD_CLK, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_B0_01_LCD_ENABLE, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_B0_02_LCD_HSYNC, 0U);
@ -172,6 +190,16 @@ void BOARD_InitPins(void) {
IOMUXC_SetPinMux(IOMUXC_GPIO_B1_01_LCD_DATA13, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_B1_02_LCD_DATA14, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_B1_03_LCD_DATA15, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_B1_04_ENET_RX_DATA00, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_B1_05_ENET_RX_DATA01, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_B1_06_ENET_RX_EN, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_B1_07_ENET_TX_DATA00, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_B1_08_ENET_TX_DATA01, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_B1_09_ENET_TX_EN, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_B1_10_ENET_TX_CLK, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_B1_11_ENET_RX_ER, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_B1_14_USDHC1_VSELECT, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_B1_15_ENET_MDIO, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_EMC_00_SEMC_DATA00, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_EMC_01_SEMC_DATA01, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_EMC_02_SEMC_DATA02, 0U);
@ -213,9 +241,14 @@ void BOARD_InitPins(void) {
IOMUXC_SetPinMux(IOMUXC_GPIO_EMC_38_SEMC_DM01, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_EMC_40_SEMC_RDY, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_EMC_41_SEMC_CSX00, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_SD_B0_00_USDHC1_CMD, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_SD_B0_01_USDHC1_CLK, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_SD_B0_02_USDHC1_DATA0, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_SD_B0_03_USDHC1_DATA1, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_SD_B0_04_USDHC1_DATA2, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_SD_B0_05_USDHC1_DATA3, 0U);
IOMUXC_SetPinConfig(IOMUXC_GPIO_AD_B0_12_LPUART1_TX, 0x10B0U);
IOMUXC_SetPinConfig(IOMUXC_GPIO_AD_B0_13_LPUART1_RX, 0x10B0U);
IOMUXC_SetPinConfig(IOMUXC_GPIO_AD_B0_15_GPIO1_IO15, 0x90B0U);
}
/***********************************************************************************************************************

View File

@ -106,8 +106,18 @@ BOARD_InitPins:
- {pin_num: E8, peripheral: LCDIF, signal: lcdif_hsync, pin_signal: GPIO_B0_02}
- {pin_num: E7, peripheral: LCDIF, signal: lcdif_enable, pin_signal: GPIO_B0_01}
- {pin_num: M11, peripheral: GPIO1, signal: 'gpio_io, 02', pin_signal: GPIO_AD_B0_02, identifier: LCDIF_RESET, direction: OUTPUT, gpio_init_state: 'true'}
- {pin_num: L10, peripheral: GPIO1, signal: 'gpio_io, 15', pin_signal: GPIO_AD_B0_15, identifier: LCDIF_BL, direction: OUTPUT, gpio_init_state: 'true'}
- {pin_num: G13, peripheral: GPIO1, signal: 'gpio_io, 10', pin_signal: GPIO_AD_B0_10, identifier: LED_BLUE, direction: OUTPUT, gpio_init_state: 'true'}
- {pin_num: L10, peripheral: GPIO1, signal: 'gpio_io, 15', pin_signal: GPIO_AD_B0_15, identifier: LCDIF_BL, direction: OUTPUT, gpio_init_state: 'true'}
- {pin_num: L12, peripheral: ENET, signal: enet_mdc, pin_signal: GPIO_AD_B1_04}
- {pin_num: B14, peripheral: ENET, signal: enet_mdio, pin_signal: GPIO_B1_15}
- {pin_num: B13, peripheral: ENET, signal: enet_tx_clk, pin_signal: GPIO_B1_10}
- {pin_num: B12, peripheral: ENET, signal: 'enet_tx_data, 0', pin_signal: GPIO_B1_07}
- {pin_num: A12, peripheral: ENET, signal: 'enet_tx_data, 1', pin_signal: GPIO_B1_08}
- {pin_num: C13, peripheral: ENET, signal: enet_rx_er, pin_signal: GPIO_B1_11}
- {pin_num: A13, peripheral: ENET, signal: enet_tx_en, pin_signal: GPIO_B1_09}
- {pin_num: E12, peripheral: ENET, signal: 'enet_rx_data, 0', pin_signal: GPIO_B1_04}
- {pin_num: D12, peripheral: ENET, signal: 'enet_rx_data, 1', pin_signal: GPIO_B1_05}
- {pin_num: C12, peripheral: ENET, signal: enet_rx_en, pin_signal: GPIO_B1_06}
* BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS ***********
*/
@ -152,6 +162,7 @@ void BOARD_InitPins(void) {
IOMUXC_SetPinMux(IOMUXC_GPIO_AD_B0_12_LPUART1_TX, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_AD_B0_13_LPUART1_RX, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_AD_B0_15_GPIO1_IO15, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_AD_B1_04_ENET_MDC, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_B0_00_LCD_CLK, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_B0_01_LCD_ENABLE, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_B0_02_LCD_HSYNC, 0U);
@ -172,6 +183,15 @@ void BOARD_InitPins(void) {
IOMUXC_SetPinMux(IOMUXC_GPIO_B1_01_LCD_DATA13, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_B1_02_LCD_DATA14, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_B1_03_LCD_DATA15, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_B1_04_ENET_RX_DATA00, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_B1_05_ENET_RX_DATA01, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_B1_06_ENET_RX_EN, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_B1_07_ENET_TX_DATA00, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_B1_08_ENET_TX_DATA01, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_B1_09_ENET_TX_EN, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_B1_10_ENET_TX_CLK, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_B1_11_ENET_RX_ER, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_B1_15_ENET_MDIO, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_EMC_00_SEMC_DATA00, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_EMC_01_SEMC_DATA01, 0U);
IOMUXC_SetPinMux(IOMUXC_GPIO_EMC_02_SEMC_DATA02, 0U);

View File

@ -417,6 +417,20 @@ void BOARD_InitBootPins(void);
#define BOARD_INITPINS_LCDIF_RESET_PIN 2U /*!< PORT pin number */
#define BOARD_INITPINS_LCDIF_RESET_PIN_MASK (1U << 2U) /*!< PORT pin mask */
/* GPIO_AD_B0_10 (coord G13), LED_BLUE */
/* Routed pin properties */
#define BOARD_INITPINS_LED_BLUE_PERIPHERAL GPIO1 /*!< Peripheral name */
#define BOARD_INITPINS_LED_BLUE_SIGNAL gpio_io /*!< Signal name */
#define BOARD_INITPINS_LED_BLUE_CHANNEL 10U /*!< Signal channel */
/* Symbols to be used with GPIO driver */
#define BOARD_INITPINS_LED_BLUE_GPIO GPIO1 /*!< GPIO peripheral base pointer */
#define BOARD_INITPINS_LED_BLUE_GPIO_PIN 10U /*!< GPIO pin number */
#define BOARD_INITPINS_LED_BLUE_GPIO_PIN_MASK (1U << 10U) /*!< GPIO pin mask */
#define BOARD_INITPINS_LED_BLUE_PORT GPIO1 /*!< PORT peripheral base pointer */
#define BOARD_INITPINS_LED_BLUE_PIN 10U /*!< PORT pin number */
#define BOARD_INITPINS_LED_BLUE_PIN_MASK (1U << 10U) /*!< PORT pin mask */
/* GPIO_AD_B0_15 (coord L10), LCDIF_BL */
/* Routed pin properties */
#define BOARD_INITPINS_LCDIF_BL_PERIPHERAL GPIO1 /*!< Peripheral name */
@ -431,19 +445,98 @@ void BOARD_InitBootPins(void);
#define BOARD_INITPINS_LCDIF_BL_PIN 15U /*!< PORT pin number */
#define BOARD_INITPINS_LCDIF_BL_PIN_MASK (1U << 15U) /*!< PORT pin mask */
/* GPIO_AD_B0_10 (coord G13), LED_BLUE */
/* GPIO_AD_B1_04 (coord L12), CSI_PIXCLK/J35[8]/J23[3] */
/* Routed pin properties */
#define BOARD_INITPINS_LED_BLUE_PERIPHERAL GPIO1 /*!< Peripheral name */
#define BOARD_INITPINS_LED_BLUE_SIGNAL gpio_io /*!< Signal name */
#define BOARD_INITPINS_LED_BLUE_CHANNEL 10U /*!< Signal channel */
#define BOARD_INITPINS_CSI_PIXCLK_PERIPHERAL ENET /*!< Peripheral name */
#define BOARD_INITPINS_CSI_PIXCLK_SIGNAL enet_mdc /*!< Signal name */
/* Symbols to be used with GPIO driver */
#define BOARD_INITPINS_LED_BLUE_GPIO GPIO1 /*!< GPIO peripheral base pointer */
#define BOARD_INITPINS_LED_BLUE_GPIO_PIN 10U /*!< GPIO pin number */
#define BOARD_INITPINS_LED_BLUE_GPIO_PIN_MASK (1U << 10U) /*!< GPIO pin mask */
#define BOARD_INITPINS_LED_BLUE_PORT GPIO1 /*!< PORT peripheral base pointer */
#define BOARD_INITPINS_LED_BLUE_PIN 10U /*!< PORT pin number */
#define BOARD_INITPINS_LED_BLUE_PIN_MASK (1U << 10U) /*!< PORT pin mask */
/* GPIO_B1_15 (coord B14), USB_HOST_PWR/BACKLIGHT_CTL */
/* Routed pin properties */
#define BOARD_INITPINS_BACKLIGHT_CTL_PERIPHERAL ENET /*!< Peripheral name */
#define BOARD_INITPINS_BACKLIGHT_CTL_SIGNAL enet_mdio /*!< Signal name */
/* GPIO_B1_10 (coord B13), ENET_TX_CLK */
/* Routed pin properties */
#define BOARD_INITPINS_ENET_TX_CLK_PERIPHERAL ENET /*!< Peripheral name */
#define BOARD_INITPINS_ENET_TX_CLK_SIGNAL enet_tx_clk /*!< Signal name */
/* GPIO_B1_07 (coord B12), ENET_TXD0 */
/* Routed pin properties */
#define BOARD_INITPINS_ENET_TXD0_PERIPHERAL ENET /*!< Peripheral name */
#define BOARD_INITPINS_ENET_TXD0_SIGNAL enet_tx_data /*!< Signal name */
#define BOARD_INITPINS_ENET_TXD0_CHANNEL 0U /*!< Signal channel */
/* GPIO_B1_08 (coord A12), ENET_TXD1 */
/* Routed pin properties */
#define BOARD_INITPINS_ENET_TXD1_PERIPHERAL ENET /*!< Peripheral name */
#define BOARD_INITPINS_ENET_TXD1_SIGNAL enet_tx_data /*!< Signal name */
#define BOARD_INITPINS_ENET_TXD1_CHANNEL 1U /*!< Signal channel */
/* GPIO_B1_11 (coord C13), ENET_RXER */
/* Routed pin properties */
#define BOARD_INITPINS_ENET_RXER_PERIPHERAL ENET /*!< Peripheral name */
#define BOARD_INITPINS_ENET_RXER_SIGNAL enet_rx_er /*!< Signal name */
/* GPIO_B1_09 (coord A13), ENET_TXEN */
/* Routed pin properties */
#define BOARD_INITPINS_ENET_TXEN_PERIPHERAL ENET /*!< Peripheral name */
#define BOARD_INITPINS_ENET_TXEN_SIGNAL enet_tx_en /*!< Signal name */
/* GPIO_B1_04 (coord E12), ENET_RXD0 */
/* Routed pin properties */
#define BOARD_INITPINS_ENET_RXD0_PERIPHERAL ENET /*!< Peripheral name */
#define BOARD_INITPINS_ENET_RXD0_SIGNAL enet_rx_data /*!< Signal name */
#define BOARD_INITPINS_ENET_RXD0_CHANNEL 0U /*!< Signal channel */
/* GPIO_B1_05 (coord D12), ENET_RXD1 */
/* Routed pin properties */
#define BOARD_INITPINS_ENET_RXD1_PERIPHERAL ENET /*!< Peripheral name */
#define BOARD_INITPINS_ENET_RXD1_SIGNAL enet_rx_data /*!< Signal name */
#define BOARD_INITPINS_ENET_RXD1_CHANNEL 1U /*!< Signal channel */
/* GPIO_B1_06 (coord C12), ENET_CRS_DV */
/* Routed pin properties */
#define BOARD_INITPINS_ENET_CRS_DV_PERIPHERAL ENET /*!< Peripheral name */
#define BOARD_INITPINS_ENET_CRS_DV_SIGNAL enet_rx_en /*!< Signal name */
/* GPIO_B1_14 (coord C14), SD0_VSELECT */
/* Routed pin properties */
#define BOARD_INITPINS_SD0_VSELECT_PERIPHERAL USDHC1 /*!< Peripheral name */
#define BOARD_INITPINS_SD0_VSELECT_SIGNAL usdhc_vselect /*!< Signal name */
/* GPIO_SD_B0_01 (coord J3), SD1_CLK/J24[3] */
/* Routed pin properties */
#define BOARD_INITPINS_SD1_CLK_PERIPHERAL USDHC1 /*!< Peripheral name */
#define BOARD_INITPINS_SD1_CLK_SIGNAL usdhc_clk /*!< Signal name */
/* GPIO_SD_B0_00 (coord J4), SD1_CMD/J24[6] */
/* Routed pin properties */
#define BOARD_INITPINS_SD1_CMD_PERIPHERAL USDHC1 /*!< Peripheral name */
#define BOARD_INITPINS_SD1_CMD_SIGNAL usdhc_cmd /*!< Signal name */
/* GPIO_SD_B0_03 (coord K1), SD1_D1/J24[5]/SPI_MISO */
/* Routed pin properties */
#define BOARD_INITPINS_SD1_D1_PERIPHERAL USDHC1 /*!< Peripheral name */
#define BOARD_INITPINS_SD1_D1_SIGNAL usdhc_data /*!< Signal name */
#define BOARD_INITPINS_SD1_D1_CHANNEL 1U /*!< Signal channel */
/* GPIO_SD_B0_04 (coord H2), SD1_D2 */
/* Routed pin properties */
#define BOARD_INITPINS_SD1_D2_PERIPHERAL USDHC1 /*!< Peripheral name */
#define BOARD_INITPINS_SD1_D2_SIGNAL usdhc_data /*!< Signal name */
#define BOARD_INITPINS_SD1_D2_CHANNEL 2U /*!< Signal channel */
/* GPIO_SD_B0_05 (coord J2), SD1_D3 */
/* Routed pin properties */
#define BOARD_INITPINS_SD1_D3_PERIPHERAL USDHC1 /*!< Peripheral name */
#define BOARD_INITPINS_SD1_D3_SIGNAL usdhc_data /*!< Signal name */
#define BOARD_INITPINS_SD1_D3_CHANNEL 3U /*!< Signal channel */
/* GPIO_SD_B0_02 (coord J1), SD1_D0/J24[4]/SPI_MOSI/PWM */
/* Routed pin properties */
#define BOARD_INITPINS_SD1_D0_PERIPHERAL USDHC1 /*!< Peripheral name */
#define BOARD_INITPINS_SD1_D0_SIGNAL usdhc_data /*!< Signal name */
#define BOARD_INITPINS_SD1_D0_CHANNEL 0U /*!< Signal channel */
/*!

View File

@ -417,6 +417,20 @@ void BOARD_InitBootPins(void);
#define BOARD_INITPINS_LCDIF_RESET_PIN 2U /*!< PORT pin number */
#define BOARD_INITPINS_LCDIF_RESET_PIN_MASK (1U << 2U) /*!< PORT pin mask */
/* GPIO_AD_B0_10 (coord G13), LED_BLUE */
/* Routed pin properties */
#define BOARD_INITPINS_LED_BLUE_PERIPHERAL GPIO1 /*!< Peripheral name */
#define BOARD_INITPINS_LED_BLUE_SIGNAL gpio_io /*!< Signal name */
#define BOARD_INITPINS_LED_BLUE_CHANNEL 10U /*!< Signal channel */
/* Symbols to be used with GPIO driver */
#define BOARD_INITPINS_LED_BLUE_GPIO GPIO1 /*!< GPIO peripheral base pointer */
#define BOARD_INITPINS_LED_BLUE_GPIO_PIN 10U /*!< GPIO pin number */
#define BOARD_INITPINS_LED_BLUE_GPIO_PIN_MASK (1U << 10U) /*!< GPIO pin mask */
#define BOARD_INITPINS_LED_BLUE_PORT GPIO1 /*!< PORT peripheral base pointer */
#define BOARD_INITPINS_LED_BLUE_PIN 10U /*!< PORT pin number */
#define BOARD_INITPINS_LED_BLUE_PIN_MASK (1U << 10U) /*!< PORT pin mask */
/* GPIO_AD_B0_15 (coord L10), LCDIF_BL */
/* Routed pin properties */
#define BOARD_INITPINS_LCDIF_BL_PERIPHERAL GPIO1 /*!< Peripheral name */
@ -431,6 +445,60 @@ void BOARD_InitBootPins(void);
#define BOARD_INITPINS_LCDIF_BL_PIN 15U /*!< PORT pin number */
#define BOARD_INITPINS_LCDIF_BL_PIN_MASK (1U << 15U) /*!< PORT pin mask */
/* GPIO_AD_B1_04 (coord L12), CSI_PIXCLK/J35[8]/J23[3] */
/* Routed pin properties */
#define BOARD_INITPINS_CSI_PIXCLK_PERIPHERAL ENET /*!< Peripheral name */
#define BOARD_INITPINS_CSI_PIXCLK_SIGNAL enet_mdc /*!< Signal name */
/* GPIO_B1_15 (coord B14), USB_HOST_PWR/BACKLIGHT_CTL */
/* Routed pin properties */
#define BOARD_INITPINS_BACKLIGHT_CTL_PERIPHERAL ENET /*!< Peripheral name */
#define BOARD_INITPINS_BACKLIGHT_CTL_SIGNAL enet_mdio /*!< Signal name */
/* GPIO_B1_10 (coord B13), ENET_TX_CLK */
/* Routed pin properties */
#define BOARD_INITPINS_ENET_TX_CLK_PERIPHERAL ENET /*!< Peripheral name */
#define BOARD_INITPINS_ENET_TX_CLK_SIGNAL enet_tx_clk /*!< Signal name */
/* GPIO_B1_07 (coord B12), ENET_TXD0 */
/* Routed pin properties */
#define BOARD_INITPINS_ENET_TXD0_PERIPHERAL ENET /*!< Peripheral name */
#define BOARD_INITPINS_ENET_TXD0_SIGNAL enet_tx_data /*!< Signal name */
#define BOARD_INITPINS_ENET_TXD0_CHANNEL 0U /*!< Signal channel */
/* GPIO_B1_08 (coord A12), ENET_TXD1 */
/* Routed pin properties */
#define BOARD_INITPINS_ENET_TXD1_PERIPHERAL ENET /*!< Peripheral name */
#define BOARD_INITPINS_ENET_TXD1_SIGNAL enet_tx_data /*!< Signal name */
#define BOARD_INITPINS_ENET_TXD1_CHANNEL 1U /*!< Signal channel */
/* GPIO_B1_11 (coord C13), ENET_RXER */
/* Routed pin properties */
#define BOARD_INITPINS_ENET_RXER_PERIPHERAL ENET /*!< Peripheral name */
#define BOARD_INITPINS_ENET_RXER_SIGNAL enet_rx_er /*!< Signal name */
/* GPIO_B1_09 (coord A13), ENET_TXEN */
/* Routed pin properties */
#define BOARD_INITPINS_ENET_TXEN_PERIPHERAL ENET /*!< Peripheral name */
#define BOARD_INITPINS_ENET_TXEN_SIGNAL enet_tx_en /*!< Signal name */
/* GPIO_B1_04 (coord E12), ENET_RXD0 */
/* Routed pin properties */
#define BOARD_INITPINS_ENET_RXD0_PERIPHERAL ENET /*!< Peripheral name */
#define BOARD_INITPINS_ENET_RXD0_SIGNAL enet_rx_data /*!< Signal name */
#define BOARD_INITPINS_ENET_RXD0_CHANNEL 0U /*!< Signal channel */
/* GPIO_B1_05 (coord D12), ENET_RXD1 */
/* Routed pin properties */
#define BOARD_INITPINS_ENET_RXD1_PERIPHERAL ENET /*!< Peripheral name */
#define BOARD_INITPINS_ENET_RXD1_SIGNAL enet_rx_data /*!< Signal name */
#define BOARD_INITPINS_ENET_RXD1_CHANNEL 1U /*!< Signal channel */
/* GPIO_B1_06 (coord C12), ENET_CRS_DV */
/* Routed pin properties */
#define BOARD_INITPINS_ENET_CRS_DV_PERIPHERAL ENET /*!< Peripheral name */
#define BOARD_INITPINS_ENET_CRS_DV_SIGNAL enet_rx_en /*!< Signal name */
/*!
* @brief Configures pin routing and optionally pin electrical features.

View File

@ -0,0 +1,27 @@
if(NOT COMPONENT_OSA_MIMXRT1052_INCLUDED)
set(COMPONENT_OSA_MIMXRT1052_INCLUDED true CACHE BOOL "component_osa component is included.")
if(CONFIG_USE_middleware_baremetal_MIMXRT1052)
target_sources(${MCUX_SDK_PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/fsl_os_abstraction_bm.c
)
elseif(CONFIG_USE_middleware_freertos-kernel_MIMXRT1052)
target_sources(${MCUX_SDK_PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/fsl_os_abstraction_free_rtos.c
)
else()
message(WARNING "please config middleware.baremetal_MIMXRT1052 or middleware.freertos-kernel_MIMXRT1052 first.")
endif()
target_include_directories(${MCUX_SDK_PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/.
)
include(driver_common_MIMXRT1052)
include(component_lists_MIMXRT1052)
endif()

View File

@ -0,0 +1,19 @@
if(NOT COMPONENT_OSA_BM_MIMXRT1052_INCLUDED)
set(COMPONENT_OSA_BM_MIMXRT1052_INCLUDED true CACHE BOOL "component_osa_bm component is included.")
target_sources(${MCUX_SDK_PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/fsl_os_abstraction_bm.c
)
target_include_directories(${MCUX_SDK_PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/.
)
include(driver_common_MIMXRT1052)
include(component_lists_MIMXRT1052)
endif()

View File

@ -0,0 +1,21 @@
if(NOT COMPONENT_OSA_FREE_RTOS_MIMXRT1052_INCLUDED)
set(COMPONENT_OSA_FREE_RTOS_MIMXRT1052_INCLUDED true CACHE BOOL "component_osa_free_rtos component is included.")
target_sources(${MCUX_SDK_PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/fsl_os_abstraction_free_rtos.c
)
target_include_directories(${MCUX_SDK_PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/.
)
include(middleware_freertos-kernel_MIMXRT1052)
include(driver_common_MIMXRT1052)
include(component_lists_MIMXRT1052)
endif()

View File

@ -0,0 +1,863 @@
/*
* Copyright (c) 2015, Freescale Semiconductor, Inc.
* Copyright 2016-2020 NXP
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _FSL_OS_ABSTRACTION_H_
#define _FSL_OS_ABSTRACTION_H_
#include "fsl_common.h"
#include "fsl_os_abstraction_config.h"
#include "fsl_component_generic_list.h"
/*!
* @addtogroup osa_adapter
* @{
*/
#ifdef __cplusplus
extern "C" {
#endif
/*******************************************************************************
* Definitions
******************************************************************************/
/*! @brief Type for the Task Priority*/
typedef uint16_t osa_task_priority_t;
/*! @brief Type for a task handler */
typedef void *osa_task_handle_t;
/*! @brief Type for the parameter to be passed to the task at its creation */
typedef void *osa_task_param_t;
/*! @brief Type for task pointer. Task prototype declaration */
typedef void (*osa_task_ptr_t)(osa_task_param_t task_param);
/*! @brief Type for the semaphore handler */
typedef void *osa_semaphore_handle_t;
/*! @brief Type for the mutex handler */
typedef void *osa_mutex_handle_t;
/*! @brief Type for the event handler */
typedef void *osa_event_handle_t;
/*! @brief Type for an event flags group, bit 32 is reserved. */
typedef uint32_t osa_event_flags_t;
/*! @brief Message definition. */
typedef void *osa_msg_handle_t;
/*! @brief Type for the message queue handler */
typedef void *osa_msgq_handle_t;
/*! @brief Type for the Timer handler */
typedef void *osa_timer_handle_t;
/*! @brief Type for the Timer callback function pointer. */
typedef void (*osa_timer_fct_ptr_t)(void const *argument);
/*! @brief Thread Definition structure contains startup information of a thread.*/
typedef struct osa_task_def_tag
{
osa_task_ptr_t pthread; /*!< start address of thread function*/
uint32_t tpriority; /*!< initial thread priority*/
uint32_t instances; /*!< maximum number of instances of that thread function*/
uint32_t stacksize; /*!< stack size requirements in bytes; 0 is default stack size*/
uint32_t *tstack; /*!< stack pointer*/
void *tlink; /*!< link pointer*/
uint8_t *tname; /*!< name pointer*/
uint8_t useFloat; /*!< is use float*/
} osa_task_def_t;
/*! @brief Thread Link Definition structure .*/
typedef struct osa_thread_link_tag
{
uint8_t link[12]; /*!< link*/
osa_task_handle_t osThreadId; /*!< thread id*/
osa_task_def_t *osThreadDefHandle; /*!< pointer of thread define handle*/
uint32_t *osThreadStackHandle; /*!< pointer of thread stack handle*/
} osa_thread_link_t, *osa_thread_link_handle_t;
/*! @brief Definition structure contains timer parameters.*/
typedef struct osa_time_def_tag
{
osa_timer_fct_ptr_t pfCallback; /* < start address of a timer function */
void *argument; /* < argument of a timer function */
} osa_time_def_t;
/*! @brief Type for the timer definition*/
typedef enum _osa_timer
{
KOSA_TimerOnce = 0, /*!< one-shot timer*/
KOSA_TimerPeriodic = 1 /*!< repeating timer*/
} osa_timer_t;
/*! @brief Defines the return status of OSA's functions */
typedef enum _osa_status
{
KOSA_StatusSuccess = kStatus_Success, /*!< Success */
KOSA_StatusError = MAKE_STATUS(kStatusGroup_OSA, 1), /*!< Failed */
KOSA_StatusTimeout = MAKE_STATUS(kStatusGroup_OSA, 2), /*!< Timeout occurs while waiting */
KOSA_StatusIdle = MAKE_STATUS(kStatusGroup_OSA, 3), /*!< Used for bare metal only, the wait object is not ready
and timeout still not occur */
} osa_status_t;
#ifdef USE_RTOS
#undef USE_RTOS
#endif
#if defined(FSL_RTOS_MQX)
#define USE_RTOS (1)
#elif defined(FSL_RTOS_FREE_RTOS)
#define USE_RTOS (1)
#if (defined(GENERIC_LIST_LIGHT) && (GENERIC_LIST_LIGHT > 0U))
#define OSA_TASK_HANDLE_SIZE (12U)
#else
#define OSA_TASK_HANDLE_SIZE (16U)
#endif
#define OSA_EVENT_HANDLE_SIZE (8U)
#define OSA_SEM_HANDLE_SIZE (4U)
#define OSA_MUTEX_HANDLE_SIZE (4U)
#define OSA_MSGQ_HANDLE_SIZE (4U)
#define OSA_MSG_HANDLE_SIZE (0U)
#elif defined(FSL_RTOS_UCOSII)
#define USE_RTOS (1)
#elif defined(FSL_RTOS_UCOSIII)
#define USE_RTOS (1)
#else
#define USE_RTOS (0)
#if (defined(GENERIC_LIST_LIGHT) && (GENERIC_LIST_LIGHT > 0U))
#define OSA_TASK_HANDLE_SIZE (24U)
#else
#define OSA_TASK_HANDLE_SIZE (28U)
#endif
#if (defined(FSL_OSA_TASK_ENABLE) && (FSL_OSA_TASK_ENABLE > 0U))
#define OSA_EVENT_HANDLE_SIZE (20U)
#else
#define OSA_EVENT_HANDLE_SIZE (16U)
#endif /* FSL_OSA_TASK_ENABLE */
#define OSA_SEM_HANDLE_SIZE (12U)
#define OSA_MUTEX_HANDLE_SIZE (12U)
#if (defined(FSL_OSA_TASK_ENABLE) && (FSL_OSA_TASK_ENABLE > 0U))
#define OSA_MSGQ_HANDLE_SIZE (32U)
#else
#define OSA_MSGQ_HANDLE_SIZE (28U)
#endif /* FSL_OSA_TASK_ENABLE */
#define OSA_MSG_HANDLE_SIZE (4U)
#endif
/*! @brief Priority setting for OSA. */
#ifndef OSA_PRIORITY_IDLE
#define OSA_PRIORITY_IDLE (6)
#endif
#ifndef OSA_PRIORITY_LOW
#define OSA_PRIORITY_LOW (5)
#endif
#ifndef OSA_PRIORITY_BELOW_NORMAL
#define OSA_PRIORITY_BELOW_NORMAL (4)
#endif
#ifndef OSA_PRIORITY_NORMAL
#define OSA_PRIORITY_NORMAL (3)
#endif
#ifndef OSA_PRIORITY_ABOVE_NORMAL
#define OSA_PRIORITY_ABOVE_NORMAL (2)
#endif
#ifndef OSA_PRIORITY_HIGH
#define OSA_PRIORITY_HIGH (1)
#endif
#ifndef OSA_PRIORITY_REAL_TIME
#define OSA_PRIORITY_REAL_TIME (0)
#endif
#ifndef OSA_TASK_PRIORITY_MAX
#define OSA_TASK_PRIORITY_MAX (0)
#endif
#ifndef OSA_TASK_PRIORITY_MIN
#define OSA_TASK_PRIORITY_MIN (15)
#endif
#define SIZE_IN_UINT32_UNITS(size) (((size) + sizeof(uint32_t) - 1) / sizeof(uint32_t))
/*! @brief Constant to pass as timeout value in order to wait indefinitely. */
#define osaWaitForever_c ((uint32_t)(-1))
#define osaEventFlagsAll_c ((osa_event_flags_t)(0x00FFFFFF))
#define osThreadStackArray(name) osThread_##name##_stack
#define osThreadStackDef(name, stacksize, instances) \
const uint32_t osThreadStackArray(name)[SIZE_IN_UINT32_UNITS(stacksize) * (instances)];
/* ==== Thread Management ==== */
/* Create a Thread Definition with function, priority, and stack requirements.
* \param name name of the thread function.
* \param priority initial priority of the thread function.
* \param instances number of possible thread instances.
* \param stackSz stack size (in bytes) requirements for the thread function.
* \param useFloat
*/
#if defined(FSL_RTOS_MQX)
#define OSA_TASK_DEFINE(name, priority, instances, stackSz, useFloat) \
osa_thread_link_t osThreadLink_##name[instances] = {0}; \
osThreadStackDef(name, stackSz, instances) osa_task_def_t os_thread_def_##name = { \
(name), (priority), (instances), (stackSz), osThreadStackArray(name), osThreadLink_##name, \
(uint8_t *)#name, (useFloat)}
#elif defined(FSL_RTOS_UCOSII)
#if gTaskMultipleInstancesManagement_c
#define OSA_TASK_DEFINE(name, priority, instances, stackSz, useFloat) \
osa_thread_link_t osThreadLink_##name[instances] = {0}; \
osThreadStackDef(name, stackSz, instances) osa_task_def_t os_thread_def_##name = { \
(name), (priority), (instances), (stackSz), osThreadStackArray(name), osThreadLink_##name, \
(uint8_t *)#name, (useFloat)}
#else
#define OSA_TASK_DEFINE(name, priority, instances, stackSz, useFloat) \
osThreadStackDef(name, stackSz, instances) osa_task_def_t os_thread_def_##name = { \
(name), (priority), (instances), (stackSz), osThreadStackArray(name), NULL, (uint8_t *)#name, (useFloat)}
#endif
#else
#define OSA_TASK_DEFINE(name, priority, instances, stackSz, useFloat) \
const osa_task_def_t os_thread_def_##name = {(name), (priority), (instances), (stackSz), \
NULL, NULL, (uint8_t *)#name, (useFloat)}
#endif
/* Access a Thread defintion.
* \param name name of the thread definition object.
*/
#define OSA_TASK(name) (const osa_task_def_t *)&os_thread_def_##name
#define OSA_TASK_PROTO(name) externosa_task_def_t os_thread_def_##name
/* ==== Timer Management ====
* Define a Timer object.
* \param name name of the timer object.
* \param function name of the timer call back function.
*/
#define OSA_TIMER_DEF(name, function) osa_time_def_t os_timer_def_##name = {(function), NULL}
/* Access a Timer definition.
* \param name name of the timer object.
*/
#define OSA_TIMER(name) &os_timer_def_##name
/* ==== Buffer Definition ==== */
/*!
* @brief Defines the semaphore handle
*
* This macro is used to define a 4 byte aligned semaphore handle.
* Then use "(osa_semaphore_handle_t)name" to get the semaphore handle.
*
* The macro should be global and could be optional. You could also define semaphore handle by yourself.
*
* This is an example,
* @code
* OSA_SEMAPHORE_HANDLE_DEFINE(semaphoreHandle);
* @endcode
*
* @param name The name string of the semaphore handle.
*/
#define OSA_SEMAPHORE_HANDLE_DEFINE(name) \
uint32_t name[(OSA_SEM_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t)]
/*!
* @brief Defines the mutex handle
*
* This macro is used to define a 4 byte aligned mutex handle.
* Then use "(osa_mutex_handle_t)name" to get the mutex handle.
*
* The macro should be global and could be optional. You could also define mutex handle by yourself.
*
* This is an example,
* @code
* OSA_MUTEX_HANDLE_DEFINE(mutexHandle);
* @endcode
*
* @param name The name string of the mutex handle.
*/
#define OSA_MUTEX_HANDLE_DEFINE(name) uint32_t name[(OSA_MUTEX_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t)]
/*!
* @brief Defines the event handle
*
* This macro is used to define a 4 byte aligned event handle.
* Then use "(osa_event_handle_t)name" to get the event handle.
*
* The macro should be global and could be optional. You could also define event handle by yourself.
*
* This is an example,
* @code
* OSA_EVENT_HANDLE_DEFINE(eventHandle);
* @endcode
*
* @param name The name string of the event handle.
*/
#define OSA_EVENT_HANDLE_DEFINE(name) uint32_t name[(OSA_EVENT_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t)]
/*!
* @brief Defines the message queue handle
*
* This macro is used to define a 4 byte aligned message queue handle.
* Then use "(osa_msgq_handle_t)name" to get the message queue handle.
*
* The macro should be global and could be optional. You could also define message queue handle by yourself.
*
* This is an example,
* @code
* OSA_MSGQ_HANDLE_DEFINE(msgqHandle, 3, sizeof(msgStruct));
* @endcode
*
* @param name The name string of the message queue handle.
* @param numberOfMsgs Number of messages.
* @param msgSize Message size.
*
*/
#if defined(FSL_RTOS_FREE_RTOS)
/*< Macro For FREE_RTOS*/
#define OSA_MSGQ_HANDLE_DEFINE(name, numberOfMsgs, msgSize) \
uint32_t name[(OSA_MSGQ_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t)]
#else
/*< Macro For BARE_MATEL*/
#define OSA_MSGQ_HANDLE_DEFINE(name, numberOfMsgs, msgSize) \
uint32_t name[((OSA_MSGQ_HANDLE_SIZE + numberOfMsgs * msgSize) + sizeof(uint32_t) - 1U) / sizeof(uint32_t)]
#endif
/*!
* @brief Defines the TASK handle
*
* This macro is used to define a 4 byte aligned TASK handle.
* Then use "(osa_task_handle_t)name" to get the TASK handle.
*
* The macro should be global and could be optional. You could also define TASK handle by yourself.
*
* This is an example,
* @code
* OSA_TASK_HANDLE_DEFINE(taskHandle);
* @endcode
*
* @param name The name string of the TASK handle.
*/
#define OSA_TASK_HANDLE_DEFINE(name) uint32_t name[(OSA_TASK_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t)]
#if defined(FSL_RTOS_FREE_RTOS)
#include "fsl_os_abstraction_free_rtos.h"
#else
#include "fsl_os_abstraction_bm.h"
#endif
extern const uint8_t gUseRtos_c;
/*
* alloc the temporary memory to store the status
*/
#define OSA_SR_ALLOC() uint32_t osaCurrentSr;
/*
* Enter critical mode
*/
#define OSA_ENTER_CRITICAL() OSA_EnterCritical(&osaCurrentSr)
/*
* Exit critical mode and retore the previous mode
*/
#define OSA_EXIT_CRITICAL() OSA_ExitCritical(osaCurrentSr)
/*******************************************************************************
* API
******************************************************************************/
/*!
* @brief Reserves the requested amount of memory in bytes.
*
* The function is used to reserve the requested amount of memory in bytes and initializes it to 0.
*
* @param length Amount of bytes to reserve.
*
* @return Pointer to the reserved memory. NULL if memory can't be allocated.
*/
void *OSA_MemoryAllocate(uint32_t length);
/*!
* @brief Frees the memory previously reserved.
*
* The function is used to free the memory block previously reserved.
*
* @param p Pointer to the start of the memory block previously reserved.
*
*/
void OSA_MemoryFree(void *p);
/*!
* @brief Enter critical with nesting mode.
*
* @param sr Store current status and return to caller.
*/
void OSA_EnterCritical(uint32_t *sr);
/*!
* @brief Exit critical with nesting mode.
*
* @param sr Previous status to restore.
*/
void OSA_ExitCritical(uint32_t sr);
/*!
* @name Task management
* @{
*/
/*!
* @brief Creates a task.
*
* This function is used to create task based on the resources defined
* by the macro OSA_TASK_DEFINE.
*
* Example below shows how to use this API to create the task handle.
* @code
* OSA_TASK_HANDLE_DEFINE(taskHandle);
* OSA_TASK_DEFINE( Job1, OSA_PRIORITY_HIGH, 1, 800, 0);
* OSA_TaskCreate((osa_task_handle_t)taskHandle, OSA_TASK(Job1), (osa_task_param_t)NULL);
* @endcode
*
* @param taskHandle Pointer to a memory space of size OSA_TASK_HANDLE_SIZE allocated by the caller, task handle.
* The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices.
* You can define the handle in the following two ways:
* #OSA_TASK_HANDLE_DEFINE(taskHandle);
* or
* uint32_t taskHandle[((OSA_TASK_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))];
* @param thread_def pointer to theosa_task_def_t structure which defines the task.
* @param task_param Pointer to be passed to the task when it is created.
* @retval KOSA_StatusSuccess The task is successfully created.
* @retval KOSA_StatusError The task can not be created.
*/
#if ((defined(FSL_OSA_TASK_ENABLE)) && (FSL_OSA_TASK_ENABLE > 0U))
osa_status_t OSA_TaskCreate(osa_task_handle_t taskHandle,
const osa_task_def_t *thread_def,
osa_task_param_t task_param);
#endif /* FSL_OSA_TASK_ENABLE */
/*!
* @brief Gets the handler of active task.
*
* @return Handler to current active task.
*/
#if ((defined(FSL_OSA_TASK_ENABLE)) && (FSL_OSA_TASK_ENABLE > 0U))
osa_task_handle_t OSA_TaskGetCurrentHandle(void);
#endif /* FSL_OSA_TASK_ENABLE */
/*!
* @brief Puts the active task to the end of scheduler's queue.
*
* When a task calls this function, it gives up the CPU and puts itself to the
* end of a task ready list.
*
* @retval KOSA_StatusSuccess The function is called successfully.
* @retval KOSA_StatusError Error occurs with this function.
*/
#if ((defined(FSL_OSA_TASK_ENABLE)) && (FSL_OSA_TASK_ENABLE > 0U))
osa_status_t OSA_TaskYield(void);
#endif /* FSL_OSA_TASK_ENABLE */
/*!
* @brief Gets the priority of a task.
*
* @param taskHandle The handler of the task whose priority is received.
*
* @return Task's priority.
*/
#if ((defined(FSL_OSA_TASK_ENABLE)) && (FSL_OSA_TASK_ENABLE > 0U))
osa_task_priority_t OSA_TaskGetPriority(osa_task_handle_t taskHandle);
#endif /* FSL_OSA_TASK_ENABLE */
/*!
* @brief Sets the priority of a task.
*
* @param taskHandle The handler of the task whose priority is set.
* @param taskPriority The priority to set.
*
* @retval KOSA_StatusSuccess Task's priority is set successfully.
* @retval KOSA_StatusError Task's priority can not be set.
*/
#if ((defined(FSL_OSA_TASK_ENABLE)) && (FSL_OSA_TASK_ENABLE > 0U))
osa_status_t OSA_TaskSetPriority(osa_task_handle_t taskHandle, osa_task_priority_t taskPriority);
#endif /* FSL_OSA_TASK_ENABLE */
/*!
* @brief Destroys a previously created task.
*
* @param taskHandle The handler of the task to destroy.
*
* @retval KOSA_StatusSuccess The task was successfully destroyed.
* @retval KOSA_StatusError Task destruction failed or invalid parameter.
*/
#if ((defined(FSL_OSA_TASK_ENABLE)) && (FSL_OSA_TASK_ENABLE > 0U))
osa_status_t OSA_TaskDestroy(osa_task_handle_t taskHandle);
#endif /* FSL_OSA_TASK_ENABLE */
/*!
* @brief Creates a semaphore with a given value.
*
* This function creates a semaphore and sets the value to the parameter
* initValue.
*
* Example below shows how to use this API to create the semaphore handle.
* @code
* OSA_SEMAPHORE_HANDLE_DEFINE(semaphoreHandle);
* OSA_SemaphoreCreate((osa_semaphore_handle_t)semaphoreHandle, 0xff);
* @endcode
*
* @param semaphoreHandle Pointer to a memory space of size OSA_SEM_HANDLE_SIZE allocated by the caller.
* The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices.
* You can define the handle in the following two ways:
* #OSA_SEMAPHORE_HANDLE_DEFINE(semaphoreHandle);
* or
* uint32_t semaphoreHandle[((OSA_SEM_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))];
* @param initValue Initial value the semaphore will be set to.
*
* @retval KOSA_StatusSuccess the new semaphore if the semaphore is created successfully.
* @retval KOSA_StatusError if the semaphore can not be created.
*/
osa_status_t OSA_SemaphoreCreate(osa_semaphore_handle_t semaphoreHandle, uint32_t initValue);
/*!
* @brief Destroys a previously created semaphore.
*
* @param semaphoreHandle The semaphore handle.
* The macro SEMAPHORE_HANDLE_BUFFER_GET is used to get the semaphore buffer pointer,
* and should not be used before the macro SEMAPHORE_HANDLE_BUFFER_DEFINE is used.
*
* @retval KOSA_StatusSuccess The semaphore is successfully destroyed.
* @retval KOSA_StatusError The semaphore can not be destroyed.
*/
osa_status_t OSA_SemaphoreDestroy(osa_semaphore_handle_t semaphoreHandle);
/*!
* @brief Pending a semaphore with timeout.
*
* This function checks the semaphore's counting value. If it is positive,
* decreases it and returns KOSA_StatusSuccess. Otherwise, a timeout is used
* to wait.
*
* @param semaphoreHandle The semaphore handle.
* @param millisec The maximum number of milliseconds to wait if semaphore is not
* positive. Pass osaWaitForever_c to wait indefinitely, pass 0
* will return KOSA_StatusTimeout immediately.
*
* @retval KOSA_StatusSuccess The semaphore is received.
* @retval KOSA_StatusTimeout The semaphore is not received within the specified 'timeout'.
* @retval KOSA_StatusError An incorrect parameter was passed.
*/
osa_status_t OSA_SemaphoreWait(osa_semaphore_handle_t semaphoreHandle, uint32_t millisec);
/*!
* @brief Signals for someone waiting on the semaphore to wake up.
*
* Wakes up one task that is waiting on the semaphore. If no task is waiting, increases
* the semaphore's counting value.
*
* @param semaphoreHandle The semaphore handle to signal.
*
* @retval KOSA_StatusSuccess The semaphore is successfully signaled.
* @retval KOSA_StatusError The object can not be signaled or invalid parameter.
*
*/
osa_status_t OSA_SemaphorePost(osa_semaphore_handle_t semaphoreHandle);
/*!
* @brief Create an unlocked mutex.
*
* This function creates a non-recursive mutex and sets it to unlocked status.
*
* Example below shows how to use this API to create the mutex handle.
* @code
* OSA_MUTEX_HANDLE_DEFINE(mutexHandle);
* OSA_MutexCreate((osa_mutex_handle_t)mutexHandle);
* @endcode
*
* @param mutexHandle Pointer to a memory space of size OSA_MUTEX_HANDLE_SIZE allocated by the caller.
* The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices.
* You can define the handle in the following two ways:
* #OSA_MUTEX_HANDLE_DEFINE(mutexHandle);
* or
* uint32_t mutexHandle[((OSA_MUTEX_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))];
* @retval KOSA_StatusSuccess the new mutex if the mutex is created successfully.
* @retval KOSA_StatusError if the mutex can not be created.
*/
osa_status_t OSA_MutexCreate(osa_mutex_handle_t mutexHandle);
/*!
* @brief Waits for a mutex and locks it.
*
* This function checks the mutex's status. If it is unlocked, locks it and returns the
* KOSA_StatusSuccess. Otherwise, waits for a timeout in milliseconds to lock.
*
* @param mutexHandle The mutex handle.
* @param millisec The maximum number of milliseconds to wait for the mutex.
* If the mutex is locked, Pass the value osaWaitForever_c will
* wait indefinitely, pass 0 will return KOSA_StatusTimeout
* immediately.
*
* @retval KOSA_StatusSuccess The mutex is locked successfully.
* @retval KOSA_StatusTimeout Timeout occurred.
* @retval KOSA_StatusError Incorrect parameter was passed.
*
* @note This is non-recursive mutex, a task can not try to lock the mutex it has locked.
*/
osa_status_t OSA_MutexLock(osa_mutex_handle_t mutexHandle, uint32_t millisec);
/*!
* @brief Unlocks a previously locked mutex.
*
* @param mutexHandle The mutex handle.
*
* @retval KOSA_StatusSuccess The mutex is successfully unlocked.
* @retval KOSA_StatusError The mutex can not be unlocked or invalid parameter.
*/
osa_status_t OSA_MutexUnlock(osa_mutex_handle_t mutexHandle);
/*!
* @brief Destroys a previously created mutex.
*
* @param mutexHandle The mutex handle.
*
* @retval KOSA_StatusSuccess The mutex is successfully destroyed.
* @retval KOSA_StatusError The mutex can not be destroyed.
*
*/
osa_status_t OSA_MutexDestroy(osa_mutex_handle_t mutexHandle);
/*!
* @brief Initializes an event object with all flags cleared.
*
* This function creates an event object and set its clear mode. If autoClear
* is 1, when a task gets the event flags, these flags will be
* cleared automatically. Otherwise these flags must
* be cleared manually.
*
* Example below shows how to use this API to create the event handle.
* @code
* OSA_EVENT_HANDLE_DEFINE(eventHandle);
* OSA_EventCreate((osa_event_handle_t)eventHandle, 0);
* @endcode
*
* @param eventHandle Pointer to a memory space of size OSA_EVENT_HANDLE_SIZE allocated by the caller.
* The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices.
* You can define the handle in the following two ways:
* #OSA_EVENT_HANDLE_DEFINE(eventHandle);
* or
* uint32_t eventHandle[((OSA_EVENT_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))];
* @param autoClear 1 The event is auto-clear.
* 0 The event manual-clear
* @retval KOSA_StatusSuccess the new event if the event is created successfully.
* @retval KOSA_StatusError if the event can not be created.
*/
osa_status_t OSA_EventCreate(osa_event_handle_t eventHandle, uint8_t autoClear);
/*!
* @brief Sets one or more event flags.
*
* Sets specified flags of an event object.
*
* @param eventHandle The event handle.
* @param flagsToSet Flags to be set.
*
* @retval KOSA_StatusSuccess The flags were successfully set.
* @retval KOSA_StatusError An incorrect parameter was passed.
*/
osa_status_t OSA_EventSet(osa_event_handle_t eventHandle, osa_event_flags_t flagsToSet);
/*!
* @brief Clears one or more flags.
*
* Clears specified flags of an event object.
*
* @param eventHandle The event handle.
* @param flagsToClear Flags to be clear.
*
* @retval KOSA_StatusSuccess The flags were successfully cleared.
* @retval KOSA_StatusError An incorrect parameter was passed.
*/
osa_status_t OSA_EventClear(osa_event_handle_t eventHandle, osa_event_flags_t flagsToClear);
/*!
* @brief Get event's flags.
*
* Get specified flags of an event object.
*
* @param eventHandle The event handle.
* The macro EVENT_HANDLE_BUFFER_GET is used to get the event buffer pointer,
* and should not be used before the macro EVENT_HANDLE_BUFFER_DEFINE is used.
* @param flagsMask The flags user want to get are specified by this parameter.
* @param pFlagsOfEvent The event flags are obtained by this parameter.
*
* @retval KOSA_StatusSuccess The event flags were successfully got.
* @retval KOSA_StatusError An incorrect parameter was passed.
*/
osa_status_t OSA_EventGet(osa_event_handle_t eventHandle,
osa_event_flags_t flagsMask,
osa_event_flags_t *pFlagsOfEvent);
/*!
* @brief Waits for specified event flags to be set.
*
* This function waits for a combination of flags to be set in an event object.
* Applications can wait for any/all bits to be set. Also this function could
* obtain the flags who wakeup the waiting task.
*
* @param eventHandle The event handle.
* @param flagsToWait Flags that to wait.
* @param waitAll Wait all flags or any flag to be set.
* @param millisec The maximum number of milliseconds to wait for the event.
* If the wait condition is not met, pass osaWaitForever_c will
* wait indefinitely, pass 0 will return KOSA_StatusTimeout
* immediately.
* @param pSetFlags Flags that wakeup the waiting task are obtained by this parameter.
*
* @retval KOSA_StatusSuccess The wait condition met and function returns successfully.
* @retval KOSA_StatusTimeout Has not met wait condition within timeout.
* @retval KOSA_StatusError An incorrect parameter was passed.
*
* @note Please pay attention to the flags bit width, FreeRTOS uses the most
* significant 8 bis as control bits, so do not wait these bits while using
* FreeRTOS.
*
*/
osa_status_t OSA_EventWait(osa_event_handle_t eventHandle,
osa_event_flags_t flagsToWait,
uint8_t waitAll,
uint32_t millisec,
osa_event_flags_t *pSetFlags);
/*!
* @brief Destroys a previously created event object.
*
* @param eventHandle The event handle.
*
* @retval KOSA_StatusSuccess The event is successfully destroyed.
* @retval KOSA_StatusError Event destruction failed.
*/
osa_status_t OSA_EventDestroy(osa_event_handle_t eventHandle);
/*!
* @brief Initializes a message queue.
*
* This function allocates memory for and initializes a message queue. Message queue elements are hardcoded as void*.
*
* Example below shows how to use this API to create the massage queue handle.
* @code
* OSA_MSGQ_HANDLE_DEFINE(msgqHandle);
* OSA_MsgQCreate((osa_msgq_handle_t)msgqHandle, 5U, sizeof(msg));
* @endcode
*
* @param msgqHandle Pointer to a memory space of size #(OSA_MSGQ_HANDLE_SIZE + msgNo*msgSize) on bare-matel
* and #(OSA_MSGQ_HANDLE_SIZE) on FreeRTOS allocated by the caller, message queue handle.
* The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices.
* You can define the handle in the following two ways:
* #OSA_MSGQ_HANDLE_DEFINE(msgqHandle);
* or
* For bm: uint32_t msgqHandle[((OSA_MSGQ_HANDLE_SIZE + msgNo*msgSize + sizeof(uint32_t) - 1U) / sizeof(uint32_t))];
* For freertos: uint32_t msgqHandle[((OSA_MSGQ_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))];
* @param msgNo :number of messages the message queue should accommodate.
* @param msgSize :size of a single message structure.
*
* @retval KOSA_StatusSuccess Message queue successfully Create.
* @retval KOSA_StatusError Message queue create failure.
*/
osa_status_t OSA_MsgQCreate(osa_msgq_handle_t msgqHandle, uint32_t msgNo, uint32_t msgSize);
/*!
* @brief Puts a message at the end of the queue.
*
* This function puts a message to the end of the message queue. If the queue
* is full, this function returns the KOSA_StatusError;
*
* @param msgqHandle Message Queue handler.
* @param pMessage Pointer to the message to be put into the queue.
*
* @retval KOSA_StatusSuccess Message successfully put into the queue.
* @retval KOSA_StatusError The queue was full or an invalid parameter was passed.
*/
osa_status_t OSA_MsgQPut(osa_msgq_handle_t msgqHandle, osa_msg_handle_t pMessage);
/*!
* @brief Reads and remove a message at the head of the queue.
*
* This function gets a message from the head of the message queue. If the
* queue is empty, timeout is used to wait.
*
* @param msgqHandle Message Queue handler.
* @param pMessage Pointer to a memory to save the message.
* @param millisec The number of milliseconds to wait for a message. If the
* queue is empty, pass osaWaitForever_c will wait indefinitely,
* pass 0 will return KOSA_StatusTimeout immediately.
*
* @retval KOSA_StatusSuccess Message successfully obtained from the queue.
* @retval KOSA_StatusTimeout The queue remains empty after timeout.
* @retval KOSA_StatusError Invalid parameter.
*/
osa_status_t OSA_MsgQGet(osa_msgq_handle_t msgqHandle, osa_msg_handle_t pMessage, uint32_t millisec);
/*!
* @brief Get the available message
*
* This function is used to get the available message.
*
* @param msgqHandle Message Queue handler.
*
* @return Available message count
*/
int OSA_MsgQAvailableMsgs(osa_msgq_handle_t msgqHandle);
/*!
* @brief Destroys a previously created queue.
*
* @param msgqHandle Message Queue handler.
*
* @retval KOSA_StatusSuccess The queue was successfully destroyed.
* @retval KOSA_StatusError Message queue destruction failed.
*/
osa_status_t OSA_MsgQDestroy(osa_msgq_handle_t msgqHandle);
/*!
* @brief Enable all interrupts.
*/
void OSA_InterruptEnable(void);
/*!
* @brief Disable all interrupts.
*/
void OSA_InterruptDisable(void);
/*!
* @brief Enable all interrupts using PRIMASK.
*/
void OSA_EnableIRQGlobal(void);
/*!
* @brief Disable all interrupts using PRIMASK.
*/
void OSA_DisableIRQGlobal(void);
/*!
* @brief Delays execution for a number of milliseconds.
*
* @param millisec The time in milliseconds to wait.
*/
void OSA_TimeDelay(uint32_t millisec);
/*!
* @brief This function gets current time in milliseconds.
*
* @retval current time in milliseconds
*/
uint32_t OSA_TimeGetMsec(void);
/*!
* @brief Installs the interrupt handler.
*
* @param IRQNumber IRQ number of the interrupt.
* @param handler The interrupt handler to install.
*/
void OSA_InstallIntHandler(uint32_t IRQNumber, void (*handler)(void));
/*! @}*/
#ifdef __cplusplus
}
#endif
/*! @}*/
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,72 @@
/*
* Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
* Copyright 2016-2020 NXP
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#if !defined(__FSL_OS_ABSTRACTION_BM_H__)
#define __FSL_OS_ABSTRACTION_BM_H__
/*!
* @addtogroup os_abstraction_bm
* @{
*/
/*******************************************************************************
* Declarations
******************************************************************************/
/*! @brief Bare Metal does not use timer. */
#ifndef FSL_OSA_BM_TIMER_NONE
#define FSL_OSA_BM_TIMER_NONE 0U
#endif
/*! @brief Bare Metal uses SYSTICK as timer. */
#ifndef FSL_OSA_BM_TIMER_SYSTICK
#define FSL_OSA_BM_TIMER_SYSTICK 1U
#endif
/*! @brief Configure what timer is used in Bare Metal. */
#ifndef FSL_OSA_BM_TIMER_CONFIG
#define FSL_OSA_BM_TIMER_CONFIG FSL_OSA_BM_TIMER_NONE
#endif
/*! @brief Type for task parameter */
typedef void *task_param_t;
/*! @brief Type for an event flags group, bit 32 is reserved */
typedef uint32_t event_flags_t;
/*! @brief Constant to pass as timeout value in order to wait indefinitely. */
#define OSA_WAIT_FOREVER 0xFFFFFFFFU
/*! @brief How many tasks can the bare metal support. */
#ifndef TASK_MAX_NUM
#define TASK_MAX_NUM 7
#endif
/*! @brief OSA's time range in millisecond, OSA time wraps if exceeds this value. */
#define FSL_OSA_TIME_RANGE 0xFFFFFFFFU
/*! @brief The default interrupt handler installed in vector table. */
#define OSA_DEFAULT_INT_HANDLER ((osa_int_handler_t)(&DefaultISR))
/*! @brief The default interrupt handler installed in vector table. */
extern void DefaultISR(void);
/*!
* @name Thread management
* @{
*/
/*!
* @brief To provide unified priority for upper layer, OSA layer makes conversation.
*/
#define PRIORITY_OSA_TO_RTOS(osa_prio) (osa_prio)
#define PRIORITY_RTOS_TO_OSA(rtos_prio) (rtos_prio)
/*! @}*/
/*! @}*/
#endif /* __FSL_OS_ABSTRACTION_BM_H__ */
/*******************************************************************************
* EOF
******************************************************************************/

View File

@ -0,0 +1,40 @@
/*!
* Copyright (c) 2015, Freescale Semiconductor, Inc.
* Copyright 2016-2018 NXP
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _FSL_OS_ABSTRACTION_CONFIG_H_
#define _FSL_OS_ABSTRACTION_CONFIG_H_
#ifndef gMainThreadStackSize_c
#define gMainThreadStackSize_c 1024
#endif
#ifndef gMainThreadPriority_c
#define gMainThreadPriority_c 7
#endif
#ifndef gTaskMultipleInstancesManagement_c
#define gTaskMultipleInstancesManagement_c 0
#endif
/*! @brief Definition to determine whether enable OSA's TASK module. */
#ifndef OSA_USED
#ifndef FSL_OSA_TASK_ENABLE
#define FSL_OSA_TASK_ENABLE 0U
#endif
#else
#if defined(FSL_OSA_TASK_ENABLE)
#undef FSL_OSA_TASK_ENABLE
#endif
#define FSL_OSA_TASK_ENABLE 1U
#endif /* OSA_USED */
#ifndef FSL_OSA_MAIN_FUNC_ENABLE
#define FSL_OSA_MAIN_FUNC_ENABLE 1U
#endif
#endif /* _FSL_OS_ABSTRACTION_CONFIG_H_ */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,132 @@
/*! *********************************************************************************
* Copyright (c) 2013-2014, Freescale Semiconductor, Inc.
* Copyright 2016-2017 NXP
* All rights reserved.
*
* ile
*
* SPDX-License-Identifier: BSD-3-Clause
********************************************************************************** */
#if !defined(__FSL_OS_ABSTRACTION_FREERTOS_H__)
#define __FSL_OS_ABSTRACTION_FREERTOS_H__
#if defined(__IAR_SYSTEMS_ICC__)
/**
* Workaround to disable MISRA C message suppress warnings for IAR compiler.
*/
/* http://supp.iar.com/Support/?note=24725 */
#define MISRAC_DISABLE \
_Pragma( \
"diag_suppress= \
Pm001,Pm002,Pm003,Pm004,Pm005,Pm006,Pm007,Pm008,Pm009,Pm010,Pm011,\
Pm012,Pm013,Pm014,Pm015,Pm016,Pm017,Pm018,Pm019,Pm020,Pm021,Pm022,\
Pm023,Pm024,Pm025,Pm026,Pm027,Pm028,Pm029,Pm030,Pm031,Pm032,Pm033,\
Pm034,Pm035,Pm036,Pm037,Pm038,Pm039,Pm040,Pm041,Pm042,Pm043,Pm044,\
Pm045,Pm046,Pm047,Pm048,Pm049,Pm050,Pm051,Pm052,Pm053,Pm054,Pm055,\
Pm056,Pm057,Pm058,Pm059,Pm060,Pm061,Pm062,Pm063,Pm064,Pm065,Pm066,\
Pm067,Pm068,Pm069,Pm070,Pm071,Pm072,Pm073,Pm074,Pm075,Pm076,Pm077,\
Pm078,Pm079,Pm080,Pm081,Pm082,Pm083,Pm084,Pm085,Pm086,Pm087,Pm088,\
Pm089,Pm090,Pm091,Pm092,Pm093,Pm094,Pm095,Pm096,Pm097,Pm098,Pm099,\
Pm100,Pm101,Pm102,Pm103,Pm104,Pm105,Pm106,Pm107,Pm108,Pm109,Pm110,\
Pm111,Pm112,Pm113,Pm114,Pm115,Pm116,Pm117,Pm118,Pm119,Pm120,Pm121,\
Pm122,Pm123,Pm124,Pm125,Pm126,Pm127,Pm128,Pm129,Pm130,Pm131,Pm132,\
Pm133,Pm134,Pm135,Pm136,Pm137,Pm138,Pm139,Pm140,Pm141,Pm142,Pm143,\
Pm144,Pm145,Pm146,Pm147,Pm148,Pm149,Pm150,Pm151,Pm152,Pm153,Pm154,\
Pm155")
#define MISRAC_ENABLE \
_Pragma( \
"diag_default= \
Pm001,Pm002,Pm003,Pm004,Pm005,Pm006,Pm007,Pm008,Pm009,Pm010,Pm011,\
Pm012,Pm013,Pm014,Pm015,Pm016,Pm017,Pm018,Pm019,Pm020,Pm021,Pm022,\
Pm023,Pm024,Pm025,Pm026,Pm027,Pm028,Pm029,Pm030,Pm031,Pm032,Pm033,\
Pm034,Pm035,Pm036,Pm037,Pm038,Pm039,Pm040,Pm041,Pm042,Pm043,Pm044,\
Pm045,Pm046,Pm047,Pm048,Pm049,Pm050,Pm051,Pm052,Pm053,Pm054,Pm055,\
Pm056,Pm057,Pm058,Pm059,Pm060,Pm061,Pm062,Pm063,Pm064,Pm065,Pm066,\
Pm067,Pm068,Pm069,Pm070,Pm071,Pm072,Pm073,Pm074,Pm075,Pm076,Pm077,\
Pm078,Pm079,Pm080,Pm081,Pm082,Pm083,Pm084,Pm085,Pm086,Pm087,Pm088,\
Pm089,Pm090,Pm091,Pm092,Pm093,Pm094,Pm095,Pm096,Pm097,Pm098,Pm099,\
Pm100,Pm101,Pm102,Pm103,Pm104,Pm105,Pm106,Pm107,Pm108,Pm109,Pm110,\
Pm111,Pm112,Pm113,Pm114,Pm115,Pm116,Pm117,Pm118,Pm119,Pm120,Pm121,\
Pm122,Pm123,Pm124,Pm125,Pm126,Pm127,Pm128,Pm129,Pm130,Pm131,Pm132,\
Pm133,Pm134,Pm135,Pm136,Pm137,Pm138,Pm139,Pm140,Pm141,Pm142,Pm143,\
Pm144,Pm145,Pm146,Pm147,Pm148,Pm149,Pm150,Pm151,Pm152,Pm153,Pm154,\
Pm155")
#else
/* Empty MISRA C macros for other toolchains. */
#define MISRAC_DISABLE
#define MISRAC_ENABLE
#endif
MISRAC_DISABLE
#include "FreeRTOS.h"
#include "semphr.h"
#include "event_groups.h"
MISRAC_ENABLE
/*!
* @addtogroup os_abstraction_free_rtos
* @{
*/
/*******************************************************************************
* Declarations
******************************************************************************/
/*! @brief Type for a task handler, returned by the OSA_TaskCreate function. */
typedef TaskHandle_t task_handler_t;
/*! @brief Type for a task stack.*/
typedef portSTACK_TYPE task_stack_t;
/*! @brief Type for task parameter */
typedef void *task_param_t;
/*! @brief Type for an event flags object.*/
typedef EventBits_t event_flags_t;
/*! @brief Constant to pass as timeout value in order to wait indefinitely. */
#define OSA_WAIT_FOREVER 0xFFFFFFFFU
/*! @brief OSA's time range in millisecond, OSA time wraps if exceeds this value. */
#define FSL_OSA_TIME_RANGE 0xFFFFFFFFU
/*! @brief The default interrupt handler installed in vector table. */
#define OSA_DEFAULT_INT_HANDLER ((osa_int_handler_t)(&DefaultISR))
extern void DefaultISR(void);
/*!
* @name Thread management
* @{
*/
/*!
* @brief To provide unified task piority for upper layer, OSA layer makes conversion.
*/
#define PRIORITY_OSA_TO_RTOS(osa_prio) ((UBaseType_t)configMAX_PRIORITIES - (osa_prio)-2U)
#define PRIORITY_RTOS_TO_OSA(rtos_prio) ((UBaseType_t)configMAX_PRIORITIES - (rtos_prio)-2U)
/* @}*/
/*!
* @name Message queues
* @{
*/
/*!
* @brief This macro statically reserves the memory required for the queue.
*
* @param name Identifier for the memory region.
* @param number Number of elements in the queue.
* @param size Size of every elements in words.
*/
#define MSG_QUEUE_DECLARE(name, number, size) msg_queue_t *name = NULL
/* @}*/
/*! @}*/
/*! @}*/
/*! @}*/
#endif /* __FSL_OS_ABSTRACTION_FREERTOS_H__ */

View File

@ -1,3 +1,6 @@
# config to select component, the format is CONFIG_USE_${component}
set(CONFIG_USE_component_serial_manager_uart_MIMXRT1052 true)
set(CONFIG_USE_driver_lpuart_MIMXRT1052 true)
set(CONFIG_USE_middleware_sdmmc_host_usdhc_MIMXRT1052 true)
set(CONFIG_USE_middleware_sdmmc_host_usdhc_freertos_MIMXRT1052 true)
set(CONFIG_USE_middleware_fatfs_sd_MIMXRT1052 true)

View File

@ -0,0 +1,17 @@
if(NOT DRIVER_CACHE_ARMV7_M7_MIMXRT1052_INCLUDED)
set(DRIVER_CACHE_ARMV7_M7_MIMXRT1052_INCLUDED true CACHE BOOL "driver_cache_armv7_m7 component is included.")
target_sources(${MCUX_SDK_PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/fsl_cache.c
)
target_include_directories(${MCUX_SDK_PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/.
)
include(driver_common_MIMXRT1052)
endif()

View File

@ -0,0 +1,17 @@
if(NOT DRIVER_ENET_MIMXRT1052_INCLUDED)
set(DRIVER_ENET_MIMXRT1052_INCLUDED true CACHE BOOL "driver_enet component is included.")
target_sources(${MCUX_SDK_PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/fsl_enet.c
)
target_include_directories(${MCUX_SDK_PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/.
)
include(driver_common_MIMXRT1052)
endif()

View File

@ -0,0 +1,17 @@
if(NOT DRIVER_USDHC_MIMXRT1052_INCLUDED)
set(DRIVER_USDHC_MIMXRT1052_INCLUDED true CACHE BOOL "driver_usdhc component is included.")
target_sources(${MCUX_SDK_PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/fsl_usdhc.c
)
target_include_directories(${MCUX_SDK_PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/.
)
include(driver_common_MIMXRT1052)
endif()

602
drivers/fsl_cache.c Normal file
View File

@ -0,0 +1,602 @@
/*
* Copyright 2016-2019 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "fsl_cache.h"
/*******************************************************************************
* Definitions
******************************************************************************/
/* Component ID definition, used by tools. */
#ifndef FSL_COMPONENT_ID
#define FSL_COMPONENT_ID "platform.drivers.cache_armv7_m7"
#endif
#if defined(FSL_FEATURE_SOC_L2CACHEC_COUNT) && FSL_FEATURE_SOC_L2CACHEC_COUNT
#define L2CACHE_OPERATION_TIMEOUT 0xFFFFFU
#define L2CACHE_8WAYS_MASK 0xFFU
#define L2CACHE_16WAYS_MASK 0xFFFFU
#define L2CACHE_SMALLWAYS_NUM 8U
#define L2CACHE_1KBCOVERTOB 1024U
#define L2CACHE_SAMLLWAYS_SIZE 16U
#define L2CACHE_LOCKDOWN_REGNUM 8 /*!< Lock down register numbers.*/
/*******************************************************************************
* Prototypes
******************************************************************************/
/*!
* @brief Set for all ways and waiting for the operation finished.
* This is provided for all the background operations.
*
* @param auxCtlReg The auxiliary control register.
* @param regAddr The register address to be operated.
*/
static void L2CACHE_SetAndWaitBackGroundOperate(uint32_t auxCtlReg, uint32_t regAddr);
/*!
* @brief Invalidates the Level 2 cache line by physical address.
* This function invalidates a cache line by physcial address.
*
* @param address The physical addderss of the cache.
* The format of the address shall be :
* bit 31 ~ bit n+1 | bitn ~ bit5 | bit4 ~ bit0
* Tag | index | 0
* Note: the physical address shall be aligned to the line size - 32B (256 bit).
* so keep the last 5 bits (bit 4 ~ bit 0) of the physical address always be zero.
* If the input address is not aligned, it will be changed to 32-byte aligned address.
* The n is varies according to the index width.
* @return The actual 32-byte aligned physical address be operated.
*/
static uint32_t L2CACHE_InvalidateLineByAddr(uint32_t address);
/*!
* @brief Cleans the Level 2 cache line based on the physical address.
* This function cleans a cache line based on a physcial address.
*
* @param address The physical addderss of the cache.
* The format of the address shall be :
* bit 31 ~ bit n+1 | bitn ~ bit5 | bit4 ~ bit0
* Tag | index | 0
* Note: the physical address shall be aligned to the line size - 32B (256 bit).
* so keep the last 5 bits (bit 4 ~ bit 0) of the physical address always be zero.
* If the input address is not aligned, it will be changed to 32-byte aligned address.
* The n is varies according to the index width.
* @return The actual 32-byte aligned physical address be operated.
*/
static uint32_t L2CACHE_CleanLineByAddr(uint32_t address);
/*!
* @brief Cleans and invalidates the Level 2 cache line based on the physical address.
* This function cleans and invalidates a cache line based on a physcial address.
*
* @param address The physical addderss of the cache.
* The format of the address shall be :
* bit 31 ~ bit n+1 | bitn ~ bit5 | bit4 ~ bit0
* Tag | index | 0
* Note: the physical address shall be aligned to the line size - 32B (256 bit).
* so keep the last 5 bits (bit 4 ~ bit 0) of the physical address always be zero.
* If the input address is not aligned, it will be changed to 32-byte aligned address.
* The n is varies according to the index width.
* @return The actual 32-byte aligned physical address be operated.
*/
static uint32_t L2CACHE_CleanInvalidateLineByAddr(uint32_t address);
/*!
* @brief Gets the number of the Level 2 cache and the way size.
* This function cleans and invalidates a cache line based on a physcial address.
*
* @param num_ways The number of the cache way.
* @param size_way The way size.
*/
static void L2CACHE_GetWayNumSize(uint32_t *num_ways, uint32_t *size_way);
/*******************************************************************************
* Code
******************************************************************************/
static void L2CACHE_SetAndWaitBackGroundOperate(uint32_t auxCtlReg, uint32_t regAddr)
{
uint16_t mask = L2CACHE_8WAYS_MASK;
uint32_t timeout = L2CACHE_OPERATION_TIMEOUT;
/* Check the ways used at first. */
if (auxCtlReg & L2CACHEC_REG1_AUX_CONTROL_ASSOCIATIVITY_MASK)
{
mask = L2CACHE_16WAYS_MASK;
}
/* Set the opeartion for all ways/entries of the cache. */
*(uint32_t *)regAddr = mask;
/* Waiting for until the operation is complete. */
while ((*(volatile uint32_t *)regAddr & mask) && timeout)
{
__ASM("nop");
timeout--;
}
}
static uint32_t L2CACHE_InvalidateLineByAddr(uint32_t address)
{
/* Align the address first. */
address &= ~(uint32_t)(FSL_FEATURE_L2CACHE_LINESIZE_BYTE - 1);
/* Invalidate the cache line by physical address. */
L2CACHEC->REG7_INV_PA = address;
return address;
}
static uint32_t L2CACHE_CleanLineByAddr(uint32_t address)
{
/* Align the address first. */
address &= ~(uint32_t)(FSL_FEATURE_L2CACHE_LINESIZE_BYTE - 1);
/* Invalidate the cache line by physical address. */
L2CACHEC->REG7_CLEAN_PA = address;
return address;
}
static uint32_t L2CACHE_CleanInvalidateLineByAddr(uint32_t address)
{
/* Align the address first. */
address &= ~(uint32_t)(FSL_FEATURE_L2CACHE_LINESIZE_BYTE - 1);
/* Clean and invalidate the cache line by physical address. */
L2CACHEC->REG7_CLEAN_INV_PA = address;
return address;
}
static void L2CACHE_GetWayNumSize(uint32_t *num_ways, uint32_t *size_way)
{
assert(num_ways);
assert(size_way);
uint32_t number = (L2CACHEC->REG1_AUX_CONTROL & L2CACHEC_REG1_AUX_CONTROL_ASSOCIATIVITY_MASK) >>
L2CACHEC_REG1_AUX_CONTROL_ASSOCIATIVITY_SHIFT;
uint32_t size = (L2CACHEC->REG1_AUX_CONTROL & L2CACHEC_REG1_AUX_CONTROL_WAYSIZE_MASK) >>
L2CACHEC_REG1_AUX_CONTROL_WAYSIZE_SHIFT;
*num_ways = (number + 1) * L2CACHE_SMALLWAYS_NUM;
if (!size)
{
/* 0 internally mapped to the same size as 1 - 16KB.*/
size += 1;
}
*size_way = (1 << (size - 1)) * L2CACHE_SAMLLWAYS_SIZE * L2CACHE_1KBCOVERTOB;
}
/*!
* brief Initializes the level 2 cache controller module.
*
* param config Pointer to configuration structure. See "l2cache_config_t".
*/
void L2CACHE_Init(l2cache_config_t *config)
{
assert(config);
uint16_t waysNum = 0xFFU; /* Default use the 8-way mask. */
uint8_t count;
uint32_t auxReg = 0;
/*The aux register must be configured when the cachec is disabled
* So disable first if the cache controller is enabled.
*/
if (L2CACHEC->REG1_CONTROL & L2CACHEC_REG1_CONTROL_CE_MASK)
{
L2CACHE_Disable();
}
/* Unlock all entries. */
if (L2CACHEC->REG1_AUX_CONTROL & L2CACHEC_REG1_AUX_CONTROL_ASSOCIATIVITY_MASK)
{
waysNum = 0xFFFFU;
}
for (count = 0; count < L2CACHE_LOCKDOWN_REGNUM; count++)
{
L2CACHE_LockdownByWayEnable(count, waysNum, false);
}
/* Set the ways and way-size etc. */
auxReg = L2CACHEC_REG1_AUX_CONTROL_ASSOCIATIVITY(config->wayNum) |
L2CACHEC_REG1_AUX_CONTROL_WAYSIZE(config->waySize) | L2CACHEC_REG1_AUX_CONTROL_CRP(config->repacePolicy) |
L2CACHEC_REG1_AUX_CONTROL_IPE(config->istrPrefetchEnable) |
L2CACHEC_REG1_AUX_CONTROL_DPE(config->dataPrefetchEnable) |
L2CACHEC_REG1_AUX_CONTROL_NLE(config->nsLockdownEnable) |
L2CACHEC_REG1_AUX_CONTROL_FWA(config->writeAlloc) | L2CACHEC_REG1_AUX_CONTROL_HPSDRE(config->writeAlloc);
L2CACHEC->REG1_AUX_CONTROL = auxReg;
/* Set the tag/data ram latency. */
if (config->lateConfig)
{
uint32_t data = 0;
/* Tag latency. */
data = L2CACHEC_REG1_TAG_RAM_CONTROL_SL(config->lateConfig->tagSetupLate) |
L2CACHEC_REG1_TAG_RAM_CONTROL_SL(config->lateConfig->tagSetupLate) |
L2CACHEC_REG1_TAG_RAM_CONTROL_RAL(config->lateConfig->tagReadLate) |
L2CACHEC_REG1_TAG_RAM_CONTROL_WAL(config->lateConfig->dataWriteLate);
L2CACHEC->REG1_TAG_RAM_CONTROL = data;
/* Data latency. */
data = L2CACHEC_REG1_DATA_RAM_CONTROL_SL(config->lateConfig->dataSetupLate) |
L2CACHEC_REG1_DATA_RAM_CONTROL_SL(config->lateConfig->dataSetupLate) |
L2CACHEC_REG1_DATA_RAM_CONTROL_RAL(config->lateConfig->dataReadLate) |
L2CACHEC_REG1_DATA_RAM_CONTROL_WAL(config->lateConfig->dataWriteLate);
L2CACHEC->REG1_DATA_RAM_CONTROL = data;
}
}
/*!
* brief Gets an available default settings for the cache controller.
*
* This function initializes the cache controller configuration structure with default settings.
* The default values are:
* code
* config->waysNum = kL2CACHE_8ways;
* config->waySize = kL2CACHE_32KbSize;
* config->repacePolicy = kL2CACHE_Roundrobin;
* config->lateConfig = NULL;
* config->istrPrefetchEnable = false;
* config->dataPrefetchEnable = false;
* config->nsLockdownEnable = false;
* config->writeAlloc = kL2CACHE_UseAwcache;
* endcode
* param config Pointer to the configuration structure.
*/
void L2CACHE_GetDefaultConfig(l2cache_config_t *config)
{
assert(config);
/* Initializes the configure structure to zero. */
memset(config, 0, sizeof(*config));
uint32_t number = (L2CACHEC->REG1_AUX_CONTROL & L2CACHEC_REG1_AUX_CONTROL_ASSOCIATIVITY_MASK) >>
L2CACHEC_REG1_AUX_CONTROL_ASSOCIATIVITY_SHIFT;
uint32_t size = (L2CACHEC->REG1_AUX_CONTROL & L2CACHEC_REG1_AUX_CONTROL_WAYSIZE_MASK) >>
L2CACHEC_REG1_AUX_CONTROL_WAYSIZE_SHIFT;
/* Get the default value */
config->wayNum = (l2cache_way_num_t)number;
config->waySize = (l2cache_way_size)size;
config->repacePolicy = kL2CACHE_Roundrobin;
config->lateConfig = NULL;
config->istrPrefetchEnable = false;
config->dataPrefetchEnable = false;
config->nsLockdownEnable = false;
config->writeAlloc = kL2CACHE_UseAwcache;
}
/*!
* brief Enables the level 2 cache controller.
* This function enables the cache controller. Must be written using a secure access.
* If write with a Non-secure access will cause a DECERR response.
*
*/
void L2CACHE_Enable(void)
{
/* Invalidate first. */
L2CACHE_Invalidate();
/* Enable the level 2 cache controller. */
L2CACHEC->REG1_CONTROL = L2CACHEC_REG1_CONTROL_CE_MASK;
}
/*!
* brief Disables the level 2 cache controller.
* This function disables the cache controller. Must be written using a secure access.
* If write with a Non-secure access will cause a DECERR response.
*
*/
void L2CACHE_Disable(void)
{
/* First CleanInvalidate all enties in the cache. */
L2CACHE_CleanInvalidate();
/* Disable the level 2 cache controller. */
L2CACHEC->REG1_CONTROL &= ~L2CACHEC_REG1_CONTROL_CE_MASK;
/* DSB - data sync barrier.*/
__DSB();
}
/*!
* brief Invalidates the Level 2 cache.
* This function invalidates all entries in cache.
*
*/
void L2CACHE_Invalidate(void)
{
/* Invalidate all entries in cache. */
L2CACHE_SetAndWaitBackGroundOperate(L2CACHEC->REG1_AUX_CONTROL, (uint32_t)&L2CACHEC->REG7_INV_WAY);
/* Cache sync. */
L2CACHEC->REG7_CACHE_SYNC = 0;
}
/*!
* brief Cleans the level 2 cache controller.
* This function cleans all entries in the level 2 cache controller.
*
*/
void L2CACHE_Clean(void)
{
/* Clean all entries of the cache. */
L2CACHE_SetAndWaitBackGroundOperate(L2CACHEC->REG1_AUX_CONTROL, (uint32_t)&L2CACHEC->REG7_CLEAN_WAY);
/* Cache sync. */
L2CACHEC->REG7_CACHE_SYNC = 0;
}
/*!
* brief Cleans and invalidates the level 2 cache controller.
* This function cleans and invalidates all entries in the level 2 cache controller.
*
*/
void L2CACHE_CleanInvalidate(void)
{
/* Clean all entries of the cache. */
L2CACHE_SetAndWaitBackGroundOperate(L2CACHEC->REG1_AUX_CONTROL, (uint32_t)&L2CACHEC->REG7_CLEAN_INV_WAY);
/* Cache sync. */
L2CACHEC->REG7_CACHE_SYNC = 0;
}
/*!
* brief Invalidates the Level 2 cache lines in the range of two physical addresses.
* This function invalidates all cache lines between two physical addresses.
*
* param address The start address of the memory to be invalidated.
* param size_byte The memory size.
* note The start address and size_byte should be 32-byte(FSL_FEATURE_L2CACHE_LINESIZE_BYTE) aligned.
* The startAddr here will be forced to align to L2 line size if startAddr
* is not aligned. For the size_byte, application should make sure the
* alignment or make sure the right operation order if the size_byte is not aligned.
*/
void L2CACHE_InvalidateByRange(uint32_t address, uint32_t size_byte)
{
uint32_t endAddr = address + size_byte;
/* Invalidate addresses in the range. */
while (address < endAddr)
{
address = L2CACHE_InvalidateLineByAddr(address);
/* Update the size. */
address += FSL_FEATURE_L2CACHE_LINESIZE_BYTE;
}
/* Cache sync. */
L2CACHEC->REG7_CACHE_SYNC = 0;
}
/*!
* brief Cleans the Level 2 cache lines in the range of two physical addresses.
* This function cleans all cache lines between two physical addresses.
*
* param address The start address of the memory to be cleaned.
* param size_byte The memory size.
* note The start address and size_byte should be 32-byte(FSL_FEATURE_L2CACHE_LINESIZE_BYTE) aligned.
* The startAddr here will be forced to align to L2 line size if startAddr
* is not aligned. For the size_byte, application should make sure the
* alignment or make sure the right operation order if the size_byte is not aligned.
*/
void L2CACHE_CleanByRange(uint32_t address, uint32_t size_byte)
{
uint32_t num_ways = 0;
uint32_t size_way = 0;
uint32_t endAddr = address + size_byte;
/* Get the number and size of the cache way. */
L2CACHE_GetWayNumSize(&num_ways, &size_way);
/* Check if the clean size is over the cache size. */
if ((endAddr - address) > num_ways * size_way)
{
L2CACHE_Clean();
return;
}
/* Clean addresses in the range. */
while ((address & ~(uint32_t)(FSL_FEATURE_L2CACHE_LINESIZE_BYTE - 1)) < endAddr)
{
/* Clean the address in the range. */
address = L2CACHE_CleanLineByAddr(address);
address += FSL_FEATURE_L2CACHE_LINESIZE_BYTE;
}
L2CACHEC->REG7_CACHE_SYNC = 0;
}
/*!
* brief Cleans and invalidates the Level 2 cache lines in the range of two physical addresses.
* This function cleans and invalidates all cache lines between two physical addresses.
*
* param address The start address of the memory to be cleaned and invalidated.
* param size_byte The memory size.
* note The start address and size_byte should be 32-byte(FSL_FEATURE_L2CACHE_LINESIZE_BYTE) aligned.
* The startAddr here will be forced to align to L2 line size if startAddr
* is not aligned. For the size_byte, application should make sure the
* alignment or make sure the right operation order if the size_byte is not aligned.
*/
void L2CACHE_CleanInvalidateByRange(uint32_t address, uint32_t size_byte)
{
uint32_t num_ways = 0;
uint32_t size_way = 0;
uint32_t endAddr = address + size_byte;
/* Get the number and size of the cache way. */
L2CACHE_GetWayNumSize(&num_ways, &size_way);
/* Check if the clean size is over the cache size. */
if ((endAddr - address) > num_ways * size_way)
{
L2CACHE_CleanInvalidate();
return;
}
/* Clean addresses in the range. */
while ((address & ~(uint32_t)(FSL_FEATURE_L2CACHE_LINESIZE_BYTE - 1)) < endAddr)
{
/* Clean the address in the range. */
address = L2CACHE_CleanInvalidateLineByAddr(address);
address += FSL_FEATURE_L2CACHE_LINESIZE_BYTE;
}
L2CACHEC->REG7_CACHE_SYNC = 0;
}
/*!
* brief Enables or disables to lock down the data and instruction by way.
* This function locks down the cached instruction/data by way and prevent the adresses from
* being allocated and prevent dara from being evicted out of the level 2 cache.
* But the normal cache maintenance operations that invalidate, clean or clean
* and validate cache contents affect the locked-down cache lines as normal.
*
* param masterId The master id, range from 0 ~ 7.
* param mask The ways to be enabled or disabled to lockdown.
* each bit in value is related to each way of the cache. for example:
* value: bit 0 ------ way 0.
* value: bit 1 ------ way 1.
* --------------------------
* value: bit 15 ------ way 15.
* Note: please make sure the value setting is align with your supported ways.
* param enable True enable the lockdown, false to disable the lockdown.
*/
void L2CACHE_LockdownByWayEnable(uint32_t masterId, uint32_t mask, bool enable)
{
uint8_t num_ways = (L2CACHEC->REG1_AUX_CONTROL & L2CACHEC_REG1_AUX_CONTROL_ASSOCIATIVITY_MASK) >>
L2CACHEC_REG1_AUX_CONTROL_ASSOCIATIVITY_SHIFT;
num_ways = (num_ways + 1) * L2CACHE_SMALLWAYS_NUM;
assert(mask < (1U << num_ways));
assert(masterId < L2CACHE_LOCKDOWN_REGNUM);
uint32_t dataReg = L2CACHEC->LOCKDOWN[masterId].REG9_D_LOCKDOWN;
uint32_t istrReg = L2CACHEC->LOCKDOWN[masterId].REG9_I_LOCKDOWN;
if (enable)
{
/* Data lockdown. */
L2CACHEC->LOCKDOWN[masterId].REG9_D_LOCKDOWN = dataReg | mask;
/* Instruction lockdown. */
L2CACHEC->LOCKDOWN[masterId].REG9_I_LOCKDOWN = istrReg | mask;
}
else
{
/* Data lockdown. */
L2CACHEC->LOCKDOWN[masterId].REG9_D_LOCKDOWN = dataReg & ~mask;
/* Instruction lockdown. */
L2CACHEC->LOCKDOWN[masterId].REG9_I_LOCKDOWN = istrReg & ~mask;
}
}
#endif /* FSL_FEATURE_SOC_L2CACHEC_COUNT */
/*!
* brief Invalidate cortex-m7 L1 instruction cache by range.
*
* param address The start address of the memory to be invalidated.
* param size_byte The memory size.
* note The start address and size_byte should be 32-byte(FSL_FEATURE_L1ICACHE_LINESIZE_BYTE) aligned.
* The startAddr here will be forced to align to L1 I-cache line size if
* startAddr is not aligned. For the size_byte, application should make sure the
* alignment or make sure the right operation order if the size_byte is not aligned.
*/
void L1CACHE_InvalidateICacheByRange(uint32_t address, uint32_t size_byte)
{
#if (__DCACHE_PRESENT == 1U)
uint32_t addr = address & ~((uint32_t)FSL_FEATURE_L1ICACHE_LINESIZE_BYTE - 1U);
uint32_t align_len = address - addr;
int32_t size = (int32_t)size_byte + (int32_t)align_len;
__DSB();
while (size > 0)
{
SCB->ICIMVAU = addr;
addr += (uint32_t)FSL_FEATURE_L1ICACHE_LINESIZE_BYTE;
size -= (int32_t)FSL_FEATURE_L1ICACHE_LINESIZE_BYTE;
}
__DSB();
__ISB();
#endif
}
/*!
* brief Invalidates all instruction caches by range.
*
* Both cortex-m7 L1 cache line and L2 PL310 cache line length is 32-byte.
*
* param address The physical address.
* param size_byte size of the memory to be invalidated.
* note address and size should be aligned to cache line size
* 32-Byte due to the cache operation unit is one cache line. The startAddr here will be forced
* to align to the cache line size if startAddr is not aligned. For the size_byte, application should
* make sure the alignment or make sure the right operation order if the size_byte is not aligned.
*/
void ICACHE_InvalidateByRange(uint32_t address, uint32_t size_byte)
{
#if defined(FSL_FEATURE_SOC_L2CACHEC_COUNT) && FSL_FEATURE_SOC_L2CACHEC_COUNT
#if defined(FSL_SDK_DISBLE_L2CACHE_PRESENT) && !FSL_SDK_DISBLE_L2CACHE_PRESENT
L2CACHE_InvalidateByRange(address, size_byte);
#endif /* !FSL_SDK_DISBLE_L2CACHE_PRESENT */
#endif /* FSL_FEATURE_SOC_L2CACHEC_COUNT */
L1CACHE_InvalidateICacheByRange(address, size_byte);
}
/*!
* brief Invalidates all data caches by range.
*
* Both cortex-m7 L1 cache line and L2 PL310 cache line length is 32-byte.
*
* param address The physical address.
* param size_byte size of the memory to be invalidated.
* note address and size should be aligned to cache line size
* 32-Byte due to the cache operation unit is one cache line. The startAddr here will be forced
* to align to the cache line size if startAddr is not aligned. For the size_byte, application should
* make sure the alignment or make sure the right operation order if the size_byte is not aligned.
*/
void DCACHE_InvalidateByRange(uint32_t address, uint32_t size_byte)
{
#if defined(FSL_FEATURE_SOC_L2CACHEC_COUNT) && FSL_FEATURE_SOC_L2CACHEC_COUNT
#if defined(FSL_SDK_DISBLE_L2CACHE_PRESENT) && !FSL_SDK_DISBLE_L2CACHE_PRESENT
L2CACHE_InvalidateByRange(address, size_byte);
#endif /* !FSL_SDK_DISBLE_L2CACHE_PRESENT */
#endif /* FSL_FEATURE_SOC_L2CACHEC_COUNT */
L1CACHE_InvalidateDCacheByRange(address, size_byte);
}
/*!
* brief Cleans all data caches by range.
*
* Both cortex-m7 L1 cache line and L2 PL310 cache line length is 32-byte.
*
* param address The physical address.
* param size_byte size of the memory to be cleaned.
* note address and size should be aligned to cache line size
* 32-Byte due to the cache operation unit is one cache line. The startAddr here will be forced
* to align to the cache line size if startAddr is not aligned. For the size_byte, application should
* make sure the alignment or make sure the right operation order if the size_byte is not aligned.
*/
void DCACHE_CleanByRange(uint32_t address, uint32_t size_byte)
{
L1CACHE_CleanDCacheByRange(address, size_byte);
#if defined(FSL_FEATURE_SOC_L2CACHEC_COUNT) && FSL_FEATURE_SOC_L2CACHEC_COUNT
#if defined(FSL_SDK_DISBLE_L2CACHE_PRESENT) && !FSL_SDK_DISBLE_L2CACHE_PRESENT
L2CACHE_CleanByRange(address, size_byte);
#endif /* !FSL_SDK_DISBLE_L2CACHE_PRESENT */
#endif /* FSL_FEATURE_SOC_L2CACHEC_COUNT */
}
/*!
* brief Cleans and Invalidates all data caches by range.
*
* Both cortex-m7 L1 cache line and L2 PL310 cache line length is 32-byte.
*
* param address The physical address.
* param size_byte size of the memory to be cleaned and invalidated.
* note address and size should be aligned to cache line size
* 32-Byte due to the cache operation unit is one cache line. The startAddr here will be forced
* to align to the cache line size if startAddr is not aligned. For the size_byte, application should
* make sure the alignment or make sure the right operation order if the size_byte is not aligned.
*/
void DCACHE_CleanInvalidateByRange(uint32_t address, uint32_t size_byte)
{
L1CACHE_CleanInvalidateDCacheByRange(address, size_byte);
#if defined(FSL_FEATURE_SOC_L2CACHEC_COUNT) && FSL_FEATURE_SOC_L2CACHEC_COUNT
#if defined(FSL_SDK_DISBLE_L2CACHE_PRESENT) && !FSL_SDK_DISBLE_L2CACHE_PRESENT
L2CACHE_CleanInvalidateByRange(address, size_byte);
#endif /* !FSL_SDK_DISBLE_L2CACHE_PRESENT */
#endif /* FSL_FEATURE_SOC_L2CACHEC_COUNT */
}

457
drivers/fsl_cache.h Normal file
View File

@ -0,0 +1,457 @@
/*
* Copyright 2016-2019 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _FSL_CACHE_H_
#define _FSL_CACHE_H_
#include "fsl_common.h"
/*!
* @addtogroup cache
* @{
*/
/*******************************************************************************
* Definitions
******************************************************************************/
/*! @name Driver version */
/*@{*/
/*! @brief cache driver version 2.0.3. */
#define FSL_CACHE_DRIVER_VERSION (MAKE_VERSION(2, 0, 3))
/*@}*/
#if defined(FSL_FEATURE_SOC_L2CACHEC_COUNT) && FSL_FEATURE_SOC_L2CACHEC_COUNT
#ifndef FSL_SDK_DISBLE_L2CACHE_PRESENT
#define FSL_SDK_DISBLE_L2CACHE_PRESENT 0
#endif
#endif /* FSL_FEATURE_SOC_L2CACHEC_COUNT */
/*******************************************************************************
* Definitions
******************************************************************************/
#if defined(FSL_FEATURE_SOC_L2CACHEC_COUNT) && FSL_FEATURE_SOC_L2CACHEC_COUNT
/*! @brief Number of level 2 cache controller ways. */
typedef enum _l2cache_way_num
{
kL2CACHE_8ways = 0, /*!< 8 ways. */
#if defined(FSL_FEATURE_L2CACHE_SUPPORT_16_WAY_ASSOCIATIVITY) && FSL_FEATURE_L2CACHE_SUPPORT_16_WAY_ASSOCIATIVITY
kL2CACHE_16ways /*!< 16 ways. */
#endif /* FSL_FEATURE_L2CACHE_SUPPORT_16_WAY_ASSOCIATIVITY */
} l2cache_way_num_t;
/*! @brief Level 2 cache controller way size. */
typedef enum _l2cache_way_size
{
kL2CACHE_16KBSize = 1, /*!< 16 KB way size. */
kL2CACHE_32KBSize = 2, /*!< 32 KB way size. */
kL2CACHE_64KBSize = 3, /*!< 64 KB way size. */
kL2CACHE_128KBSize = 4, /*!< 128 KB way size. */
kL2CACHE_256KBSize = 5, /*!< 256 KB way size. */
kL2CACHE_512KBSize = 6 /*!< 512 KB way size. */
} l2cache_way_size;
/*! @brief Level 2 cache controller replacement policy. */
typedef enum _l2cache_replacement
{
kL2CACHE_Pseudorandom = 0U, /*!< Peseudo-random replacement policy using an lfsr. */
kL2CACHE_Roundrobin /*!< Round-robin replacemnt policy. */
} l2cache_replacement_t;
/*! @brief Level 2 cache controller force write allocate options. */
typedef enum _l2cache_writealloc
{
kL2CACHE_UseAwcache = 0, /*!< Use AWCAHE attribute for the write allocate. */
kL2CACHE_NoWriteallocate, /*!< Force no write allocate. */
kL2CACHE_forceWriteallocate /*!< Force write allocate when write misses. */
} l2cache_writealloc_t;
/*! @brief Level 2 cache controller tag/data ram latency. */
typedef enum _l2cache_latency
{
kL2CACHE_1CycleLate = 0, /*!< 1 cycle of latency. */
kL2CACHE_2CycleLate, /*!< 2 cycle of latency. */
kL2CACHE_3CycleLate, /*!< 3 cycle of latency. */
kL2CACHE_4CycleLate, /*!< 4 cycle of latency. */
kL2CACHE_5CycleLate, /*!< 5 cycle of latency. */
kL2CACHE_6CycleLate, /*!< 6 cycle of latency. */
kL2CACHE_7CycleLate, /*!< 7 cycle of latency. */
kL2CACHE_8CycleLate /*!< 8 cycle of latency. */
} l2cache_latency_t;
/*! @brief Level 2 cache controller tag/data ram latency configure structure. */
typedef struct _l2cache_latency_config
{
l2cache_latency_t tagWriteLate; /*!< Tag write latency. */
l2cache_latency_t tagReadLate; /*!< Tag Read latency. */
l2cache_latency_t tagSetupLate; /*!< Tag setup latency. */
l2cache_latency_t dataWriteLate; /*!< Data write latency. */
l2cache_latency_t dataReadLate; /*!< Data Read latency. */
l2cache_latency_t dataSetupLate; /*!< Data setup latency. */
} L2cache_latency_config_t;
/*! @brief Level 2 cache controller configure structure. */
typedef struct _l2cache_config
{
/* ------------------------ l2 cachec basic settings ---------------------------- */
l2cache_way_num_t wayNum; /*!< The number of ways. */
l2cache_way_size waySize; /*!< The way size = Cache Ram size / wayNum. */
l2cache_replacement_t repacePolicy; /*!< Replacemnet policy. */
/* ------------------------ tag/data ram latency settings ----------------------- */
L2cache_latency_config_t *lateConfig; /*!< Tag/data latency configure. Set NUll if not required. */
/* ------------------------ Prefetch enable settings ---------------------------- */
bool istrPrefetchEnable; /*!< Instruction prefetch enable. */
bool dataPrefetchEnable; /*!< Data prefetch enable. */
/* ------------------------ Non-secure access settings -------------------------- */
bool nsLockdownEnable; /*!< None-secure lockdown enable. */
/* ------------------------ other settings -------------------------------------- */
l2cache_writealloc_t writeAlloc; /*!< Write allcoate force option. */
} l2cache_config_t;
#endif /* FSL_FEATURE_SOC_L2CACHEC_COUNT */
/*******************************************************************************
* API
******************************************************************************/
#if defined(__cplusplus)
extern "C" {
#endif
/*!
* @name Control for cortex-m7 L1 cache
*@{
*/
/*!
* @brief Enables cortex-m7 L1 instruction cache.
*
*/
static inline void L1CACHE_EnableICache(void)
{
SCB_EnableICache();
}
/*!
* @brief Disables cortex-m7 L1 instruction cache.
*
*/
static inline void L1CACHE_DisableICache(void)
{
SCB_DisableICache();
}
/*!
* @brief Invalidate cortex-m7 L1 instruction cache.
*
*/
static inline void L1CACHE_InvalidateICache(void)
{
SCB_InvalidateICache();
}
/*!
* @brief Invalidate cortex-m7 L1 instruction cache by range.
*
* @param address The start address of the memory to be invalidated.
* @param size_byte The memory size.
* @note The start address and size_byte should be 32-byte(FSL_FEATURE_L1ICACHE_LINESIZE_BYTE) aligned.
* The startAddr here will be forced to align to L1 I-cache line size if
* startAddr is not aligned. For the size_byte, application should make sure the
* alignment or make sure the right operation order if the size_byte is not aligned.
*/
void L1CACHE_InvalidateICacheByRange(uint32_t address, uint32_t size_byte);
/*!
* @brief Enables cortex-m7 L1 data cache.
*
*/
static inline void L1CACHE_EnableDCache(void)
{
SCB_EnableDCache();
}
/*!
* @brief Disables cortex-m7 L1 data cache.
*
*/
static inline void L1CACHE_DisableDCache(void)
{
SCB_DisableDCache();
}
/*!
* @brief Invalidates cortex-m7 L1 data cache.
*
*/
static inline void L1CACHE_InvalidateDCache(void)
{
SCB_InvalidateDCache();
}
/*!
* @brief Cleans cortex-m7 L1 data cache.
*
*/
static inline void L1CACHE_CleanDCache(void)
{
SCB_CleanDCache();
}
/*!
* @brief Cleans and Invalidates cortex-m7 L1 data cache.
*
*/
static inline void L1CACHE_CleanInvalidateDCache(void)
{
SCB_CleanInvalidateDCache();
}
/*!
* @brief Invalidates cortex-m7 L1 data cache by range.
*
* @param address The start address of the memory to be invalidated.
* @param size_byte The memory size.
* @note The start address and size_byte should be 32-byte(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE) aligned.
* The startAddr here will be forced to align to L1 D-cache line size if
* startAddr is not aligned. For the size_byte, application should make sure the
* alignment or make sure the right operation order if the size_byte is not aligned.
*/
static inline void L1CACHE_InvalidateDCacheByRange(uint32_t address, uint32_t size_byte)
{
SCB_InvalidateDCache_by_Addr((uint32_t *)address, (int32_t)size_byte);
}
/*!
* @brief Cleans cortex-m7 L1 data cache by range.
*
* @param address The start address of the memory to be cleaned.
* @param size_byte The memory size.
* @note The start address and size_byte should be 32-byte(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE) aligned.
* The startAddr here will be forced to align to L1 D-cache line size if
* startAddr is not aligned. For the size_byte, application should make sure the
* alignment or make sure the right operation order if the size_byte is not aligned.
*/
static inline void L1CACHE_CleanDCacheByRange(uint32_t address, uint32_t size_byte)
{
SCB_CleanDCache_by_Addr((uint32_t *)address, (int32_t)size_byte);
}
/*!
* @brief Cleans and Invalidates cortex-m7 L1 data cache by range.
*
* @param address The start address of the memory to be clean and invalidated.
* @param size_byte The memory size.
* @note The start address and size_byte should be 32-byte(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE) aligned.
* The startAddr here will be forced to align to L1 D-cache line size if
* startAddr is not aligned. For the size_byte, application should make sure the
* alignment or make sure the right operation order if the size_byte is not aligned.
*/
static inline void L1CACHE_CleanInvalidateDCacheByRange(uint32_t address, uint32_t size_byte)
{
SCB_CleanInvalidateDCache_by_Addr((uint32_t *)address, (int32_t)size_byte);
}
/*@}*/
#if defined(FSL_FEATURE_SOC_L2CACHEC_COUNT) && FSL_FEATURE_SOC_L2CACHEC_COUNT
/*!
* @name Control for L2 pl310 cache
*@{
*/
/*!
* @brief Initializes the level 2 cache controller module.
*
* @param config Pointer to configuration structure. See "l2cache_config_t".
*/
void L2CACHE_Init(l2cache_config_t *config);
/*!
* @brief Gets an available default settings for the cache controller.
*
* This function initializes the cache controller configuration structure with default settings.
* The default values are:
* @code
* config->waysNum = kL2CACHE_8ways;
* config->waySize = kL2CACHE_32KbSize;
* config->repacePolicy = kL2CACHE_Roundrobin;
* config->lateConfig = NULL;
* config->istrPrefetchEnable = false;
* config->dataPrefetchEnable = false;
* config->nsLockdownEnable = false;
* config->writeAlloc = kL2CACHE_UseAwcache;
* @endcode
* @param config Pointer to the configuration structure.
*/
void L2CACHE_GetDefaultConfig(l2cache_config_t *config);
/*!
* @brief Enables the level 2 cache controller.
* This function enables the cache controller. Must be written using a secure access.
* If write with a Non-secure access will cause a DECERR response.
*
*/
void L2CACHE_Enable(void);
/*!
* @brief Disables the level 2 cache controller.
* This function disables the cache controller. Must be written using a secure access.
* If write with a Non-secure access will cause a DECERR response.
*
*/
void L2CACHE_Disable(void);
/*!
* @brief Invalidates the Level 2 cache.
* This function invalidates all entries in cache.
*
*/
void L2CACHE_Invalidate(void);
/*!
* @brief Invalidates the Level 2 cache lines in the range of two physical addresses.
* This function invalidates all cache lines between two physical addresses.
*
* @param address The start address of the memory to be invalidated.
* @param size_byte The memory size.
* @note The start address and size_byte should be 32-byte(FSL_FEATURE_L2CACHE_LINESIZE_BYTE) aligned.
* The startAddr here will be forced to align to L2 line size if startAddr
* is not aligned. For the size_byte, application should make sure the
* alignment or make sure the right operation order if the size_byte is not aligned.
*/
void L2CACHE_InvalidateByRange(uint32_t address, uint32_t size_byte);
/*!
* @brief Cleans the level 2 cache controller.
* This function cleans all entries in the level 2 cache controller.
*
*/
void L2CACHE_Clean(void);
/*!
* @brief Cleans the Level 2 cache lines in the range of two physical addresses.
* This function cleans all cache lines between two physical addresses.
*
* @param address The start address of the memory to be cleaned.
* @param size_byte The memory size.
* @note The start address and size_byte should be 32-byte(FSL_FEATURE_L2CACHE_LINESIZE_BYTE) aligned.
* The startAddr here will be forced to align to L2 line size if startAddr
* is not aligned. For the size_byte, application should make sure the
* alignment or make sure the right operation order if the size_byte is not aligned.
*/
void L2CACHE_CleanByRange(uint32_t address, uint32_t size_byte);
/*!
* @brief Cleans and invalidates the level 2 cache controller.
* This function cleans and invalidates all entries in the level 2 cache controller.
*
*/
void L2CACHE_CleanInvalidate(void);
/*!
* @brief Cleans and invalidates the Level 2 cache lines in the range of two physical addresses.
* This function cleans and invalidates all cache lines between two physical addresses.
*
* @param address The start address of the memory to be cleaned and invalidated.
* @param size_byte The memory size.
* @note The start address and size_byte should be 32-byte(FSL_FEATURE_L2CACHE_LINESIZE_BYTE) aligned.
* The startAddr here will be forced to align to L2 line size if startAddr
* is not aligned. For the size_byte, application should make sure the
* alignment or make sure the right operation order if the size_byte is not aligned.
*/
void L2CACHE_CleanInvalidateByRange(uint32_t address, uint32_t size_byte);
/*!
* @brief Enables or disables to lock down the data and instruction by way.
* This function locks down the cached instruction/data by way and prevent the adresses from
* being allocated and prevent dara from being evicted out of the level 2 cache.
* But the normal cache maintenance operations that invalidate, clean or clean
* and validate cache contents affect the locked-down cache lines as normal.
*
* @param masterId The master id, range from 0 ~ 7.
* @param mask The ways to be enabled or disabled to lockdown.
* each bit in value is related to each way of the cache. for example:
* value: bit 0 ------ way 0.
* value: bit 1 ------ way 1.
* --------------------------
* value: bit 15 ------ way 15.
* Note: please make sure the value setting is align with your supported ways.
* @param enable True enable the lockdown, false to disable the lockdown.
*/
void L2CACHE_LockdownByWayEnable(uint32_t masterId, uint32_t mask, bool enable);
/*@}*/
#endif /* FSL_FEATURE_SOC_L2CACHEC_COUNT */
/*!
* @name Unified Cache Control for all caches (cortex-m7 L1 cache + l2 pl310)
* Mainly used for many drivers for easy cache operation.
*@{
*/
/*!
* @brief Invalidates all instruction caches by range.
*
* Both cortex-m7 L1 cache line and L2 PL310 cache line length is 32-byte.
*
* @param address The physical address.
* @param size_byte size of the memory to be invalidated.
* @note address and size should be aligned to cache line size
* 32-Byte due to the cache operation unit is one cache line. The startAddr here will be forced
* to align to the cache line size if startAddr is not aligned. For the size_byte, application should
* make sure the alignment or make sure the right operation order if the size_byte is not aligned.
*/
void ICACHE_InvalidateByRange(uint32_t address, uint32_t size_byte);
/*!
* @brief Invalidates all data caches by range.
*
* Both cortex-m7 L1 cache line and L2 PL310 cache line length is 32-byte.
*
* @param address The physical address.
* @param size_byte size of the memory to be invalidated.
* @note address and size should be aligned to cache line size
* 32-Byte due to the cache operation unit is one cache line. The startAddr here will be forced
* to align to the cache line size if startAddr is not aligned. For the size_byte, application should
* make sure the alignment or make sure the right operation order if the size_byte is not aligned.
*/
void DCACHE_InvalidateByRange(uint32_t address, uint32_t size_byte);
/*!
* @brief Cleans all data caches by range.
*
* Both cortex-m7 L1 cache line and L2 PL310 cache line length is 32-byte.
*
* @param address The physical address.
* @param size_byte size of the memory to be cleaned.
* @note address and size should be aligned to cache line size
* 32-Byte due to the cache operation unit is one cache line. The startAddr here will be forced
* to align to the cache line size if startAddr is not aligned. For the size_byte, application should
* make sure the alignment or make sure the right operation order if the size_byte is not aligned.
*/
void DCACHE_CleanByRange(uint32_t address, uint32_t size_byte);
/*!
* @brief Cleans and Invalidates all data caches by range.
*
* Both cortex-m7 L1 cache line and L2 PL310 cache line length is 32-byte.
*
* @param address The physical address.
* @param size_byte size of the memory to be cleaned and invalidated.
* @note address and size should be aligned to cache line size
* 32-Byte due to the cache operation unit is one cache line. The startAddr here will be forced
* to align to the cache line size if startAddr is not aligned. For the size_byte, application should
* make sure the alignment or make sure the right operation order if the size_byte is not aligned.
*/
void DCACHE_CleanInvalidateByRange(uint32_t address, uint32_t size_byte);
/*@}*/
#if defined(__cplusplus)
}
#endif
/*! @}*/
#endif /* _FSL_CACHE_H_*/

3476
drivers/fsl_enet.c Normal file

File diff suppressed because it is too large Load Diff

1876
drivers/fsl_enet.h Normal file

File diff suppressed because it is too large Load Diff

2427
drivers/fsl_usdhc.c Normal file

File diff suppressed because it is too large Load Diff

1676
drivers/fsl_usdhc.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -31,4 +31,4 @@ cortex_m reset_config sysresetreq
gdb_breakpoint_override hard
adapter speed 8000
adapter speed 29000

View File

@ -0,0 +1,27 @@
/**
@page middleware_log Middleware Change Log
@section FatFs FatFs for MCUXpresso SDK
Current version is FatFs R0.14_rev0.
- R0.14_rev0
- Upgraded to version 0.14
- Applied patch ff14_p1.diff and ff14_p2.diff
- R0.13c_rev0
- Upgraded to version 0.13c
- Applied patches ff_13c_p1.diff,ff_13c_p2.diff, ff_13c_p3.diff and ff_13c_p4.diff.
- R0.13b_rev0
- Upgraded to version 0.13b
- R0.13a_rev0
- Upgraded to version 0.13a. Added patch ff_13a_p1.diff.
- R0.12c_rev1
- Add NAND disk support.
- R0.12c_rev0
- Upgraded to version 0.12c and applied patches ff_12c_p1.diff and ff_12c_p2.diff.
- R0.12b_rev0
- Upgraded to version 0.12b.
- R0.11a
- Added glue functions for low-level drivers (SDHC, SDSPI, RAM, MMC). Modified diskio.c.
- Added RTOS wrappers to make FatFs thread safe. Modified syscall.c.
- Renamed ffconf.h to ffconf_template.h. Each application should contain its own ffconf.h.
- Included ffconf.h into diskio.c to enable the selection of physical disk from ffconf.h by macro definition.
- Conditional compilation of physical disk interfaces in diskio.c.
*/

View File

@ -0,0 +1,24 @@
FatFs License
FatFs has being developped as a personal project of the author, ChaN. It is free from the code anyone else wrote at current release. Following code block shows a copy of the FatFs license document that heading the source files.
/*----------------------------------------------------------------------------/
/ FatFs - Generic FAT Filesystem Module Rx.xx /
/-----------------------------------------------------------------------------/
/
/ Copyright (C) 20xx, ChaN, all right reserved.
/
/ FatFs module is an open source software. Redistribution and use of FatFs in
/ source and binary forms, with or without modification, are permitted provided
/ that the following condition is met:
/
/ 1. Redistributions of source code must retain the above copyright notice,
/ this condition and the following disclaimer.
/
/ This software is provided by the copyright holder and contributors "AS IS"
/ and any warranties related to this software are DISCLAIMED.
/ The copyright owner or contributors be NOT LIABLE for any damages caused
/ by use of this software.
/----------------------------------------------------------------------------*/
Therefore FatFs license is one of the BSD-style licenses but there is a significant feature. FatFs is mainly intended for embedded systems. In order to extend the usability for commercial products, the redistributions of FatFs in binary form, such as embedded code, binary library and any forms without source code, does not need to include about FatFs in the documentations. This is equivalent to the 1-clause BSD license. Of course FatFs is compatible with the most of open source software licenses including GNU GPL. When you redistribute the FatFs source code with any changes or create a fork, the license can also be changed to GNU GPL, BSD-style license or any open source software license that not conflict with FatFs license.

View File

@ -0,0 +1,139 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="cache-control" content="no-cache">
<meta name="description" content="Open source FAT filesystem for embedded projects">
<link rel="start" title="Site Top" href="../../">
<link rel="up" title="Freewares" href="../../fsw_e.html">
<link rel="stylesheet" href="css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - Generic FAT Filesystem Module</title>
</head>
<body>
<h1>FatFs - Generic FAT Filesystem Module</h1>
<hr>
<div class="abst">
<img src="res/layers.png" class="rset" width="245" height="255" alt="layer">
<p>FatFs is a generic FAT/exFAT filesystem module for small embedded systems. The FatFs module is written in compliance with ANSI C (C89) and completely separated from the disk I/O layer. Therefore it is independent of the platform. It can be incorporated into small microcontrollers with limited resource, such as 8051, PIC, AVR, ARM, Z80, RX and etc. Also Petit FatFs module for tiny microcontrollers is available <a href="http://elm-chan.org/fsw/ff/00index_p.html">here</a>.</p>
<h4>Features</h4>
<ul>
<li>DOS/Windows compatible FAT/exFAT filesystem.</li>
<li>Platform independent. Easy to port.</li>
<li>Very small footprint for program code and work area.</li>
<li>Various <a href="doc/config.html">configuration options</a> to support for:
<ul>
<li>Long file name in ANSI/OEM or Unicode.</li>
<li>exFAT filesystem, 64-bit LBA and GPT for huge storeges.</li>
<li>Thread safe for RTOS.</li>
<li>Multiple volumes (physical drives and partitions).</li>
<li>Variable sector size.</li>
<li>Multiple code pages including DBCS.</li>
<li>Read-only, optional API, I/O buffer and etc...</li>
</ul>
</li>
</ul>
</div>
<div class="para">
<h3>Application Interface</h3>
<img src="res/layers1.png" class="rset" width="245" height="220" alt="layer">
<p>FatFs provides various filesystem functions for the applications as shown below.</p>
<ul>
<li>File Access
<ul>
<li><a href="doc/open.html">f_open</a> - Open/Create a file</li>
<li><a href="doc/close.html">f_close</a> - Close an open file</li>
<li><a href="doc/read.html">f_read</a> - Read data from the file</li>
<li><a href="doc/write.html">f_write</a> - Write data to the file</li>
<li><a href="doc/lseek.html">f_lseek</a> - Move read/write pointer, Expand size</li>
<li><a href="doc/truncate.html">f_truncate</a> - Truncate file size</li>
<li><a href="doc/sync.html">f_sync</a> - Flush cached data</li>
<li><a href="doc/forward.html">f_forward</a> - Forward data to the stream</li>
<li><a href="doc/expand.html">f_expand</a> - Allocate a contiguous block to the file</li>
<li><a href="doc/gets.html">f_gets</a> - Read a string</li>
<li><a href="doc/putc.html">f_putc</a> - Write a character</li>
<li><a href="doc/puts.html">f_puts</a> - Write a string</li>
<li><a href="doc/printf.html">f_printf</a> - Write a formatted string</li>
<li><a href="doc/tell.html">f_tell</a> - Get current read/write pointer</li>
<li><a href="doc/eof.html">f_eof</a> - Test for end-of-file</li>
<li><a href="doc/size.html">f_size</a> - Get size</li>
<li><a href="doc/error.html">f_error</a> - Test for an error</li>
</ul>
</li>
<li>Directory Access
<ul>
<li><a href="doc/opendir.html">f_opendir</a> - Open a directory</li>
<li><a href="doc/closedir.html">f_closedir</a> - Close an open directory</li>
<li><a href="doc/readdir.html">f_readdir</a> - Read a directory item</li>
<li><a href="doc/findfirst.html">f_findfirst</a> - Open a directory and read the first item matched</li>
<li><a href="doc/findnext.html">f_findnext</a> - Read a next item matched</li>
</ul>
</li>
<li>File and Directory Management
<ul>
<li><a href="doc/stat.html">f_stat</a> - Check existance of a file or sub-directory</li>
<li><a href="doc/unlink.html">f_unlink</a> - Remove a file or sub-directory</li>
<li><a href="doc/rename.html">f_rename</a> - Rename/Move a file or sub-directory</li>
<li><a href="doc/chmod.html">f_chmod</a> - Change attribute of a file or sub-directory</li>
<li><a href="doc/utime.html">f_utime</a> - Change timestamp of a file or sub-directory</li>
<li><a href="doc/mkdir.html">f_mkdir</a> - Create a sub-directory</li>
<li><a href="doc/chdir.html">f_chdir</a> - Change current directory</li>
<li><a href="doc/chdrive.html">f_chdrive</a> - Change current drive</li>
<li><a href="doc/getcwd.html">f_getcwd</a> - Retrieve the current directory and drive</li>
</ul>
</li>
<li>Volume Management and System Configuration
<ul>
<li><a href="doc/mount.html">f_mount</a> - Register/Unregister the work area of the volume</li>
<li><a href="doc/mkfs.html">f_mkfs</a> - Create an FAT volume on the logical drive</li>
<li><a href="doc/fdisk.html">f_fdisk</a> - Create partitions on the physical drive</li>
<li><a href="doc/getfree.html">f_getfree</a> - Get free space on the volume</li>
<li><a href="doc/getlabel.html">f_getlabel</a> - Get volume label</li>
<li><a href="doc/setlabel.html">f_setlabel</a> - Set volume label</li>
<li><a href="doc/setcp.html">f_setcp</a> - Set active code page</li>
</ul>
</li>
</ul>
</div>
<div class="para">
<h3>Media Access Interface</h3>
<img src="res/layers2.png" class="rset" width="245" height="220" alt="layer">
<p>Since FatFs module is the <em>filesystem layer</em> independent of platforms and storage media, it is completely separated from the physical devices, such as memory card, harddisk and any type of storage device. The low level device control module is <em>not any part of FatFs module</em> and it needs to be provided by implementer. FatFs accesses the storage devices via a simple media access interface shown below. Also sample implementations for some platforms are available in the downloads. A function checker for low level disk I/O module is available <a href="res/app4.c">here</a>.</p>
<ul>
<li><a href="doc/dstat.html">disk_status</a> - Get device status</li>
<li><a href="doc/dinit.html">disk_initialize</a> - Initialize device</li>
<li><a href="doc/dread.html">disk_read</a> - Read sector(s)</li>
<li><a href="doc/dwrite.html">disk_write</a> - Write sector(s)</li>
<li><a href="doc/dioctl.html">disk_ioctl</a> - Control device dependent functions</li>
<li><a href="doc/fattime.html">get_fattime</a> - Get current time</li>
</ul>
</div>
<div class="para">
<h3>Resources</h3>
<p>The FatFs module is a free software opened for education, research and development. You can use, modify and/or redistribute it for personal projects or commercial products without any restriction under your responsibility. For further information, refer to the application note.</p>
<ul>
<li><em>Read First: <a href="doc/appnote.html">FatFs module application note</a></em></li>
<li>Download: <a href="http://elm-chan.org/fsw/ff/archives.html">Archives</a></li>
<li>Community: <a href="http://elm-chan.org/fsw/ff/bd/">FatFs User Forum</a></li>
<li><a href="https://msdn.microsoft.com/en-us/windows/hardware/gg463080.aspx">FAT32 Specification by Microsoft</a>↗ (The authorized document on FAT filesystem)</li>
<li><a href="http://elm-chan.org/docs/fat_e.html">The basics of FAT filesystem</a></li>
<li><a href="http://elm-chan.org/docs/exfat_e.html">The basics of exFAT filesystem</a></li>
<li><a href="http://elm-chan.org/docs/mmc/mmc_e.html">How to use MMC/SDC</a></li>
<li><a href="http://elm-chan.org/junk/fa/faff.html">Playing with FlashAir and FatFs</a></li>
<li><a href="http://nemuisan.blog.bai.ne.jp/">Nemuisan's Blog</a>↗ (Well written implementations for STM32F/SPI &amp; SDIO and LPC4088/SDMMC)</li>
<li><a href="http://stm32f4-discovery.net/2014/07/library-21-read-sd-card-fatfs-stm32f4xx-devices/">Read SD card with FatFs on STM32F4xx devices by Tilen Majerle</a>↗ (Quick and easy implementation for STM32F4-Discovery)</li>
<li><a href="res/rwtest1.png">Benchmark 1</a> (ATmega1284/20MHz with MMC via USART in SPI, CFC via GPIO)</li>
<li><a href="res/rwtest2.png">Benchmark 2</a> (LPC2368/72MHz with MMC via MCI)</li>
</div>
</body>
</html>

View File

@ -0,0 +1,69 @@
* {margin: 0; padding: 0; border-width: 0;}
body {margin: 8px; background-color: #e0ffff; font-color: black; font-family: serif; line-height: 133%; max-width: 1024px;}
a:link {color: blue;}
a:visited {color: darkmagenta;}
a:hover {background-color: #a0ffff;}
a:active {color: darkmagenta; overflow: hidden; outline:none; position: relative; top: 1px; left: 1px;}
abbr {border-width: 1px;}
p {margin: 0 0 0.3em 1em;}
i {margin: 0 0.3em 0 0;}
b {margin: 0 0.1em;}
em {font-style: normal; font-weight: bold; margin: 0 0.1em;}
strong {}
pre {border: 1px dashed gray; margin: 0.5em 1em; padding: 0.5em; line-height: 1.2em; font-size: 85%; font-family: "Consolas", "Courier New", monospace; background-color: white;}
pre span.c {color: green;}
pre span.k {color: blue;}
pre span.b {font-weight: bold;}
pre span.arg {font-style: italic;}
tt {margin: 0 0.2em; font-size: 0.85em; font-family: "Consolas", "Courier New", monospace; }
tt.arg {font-style: italic;}
ol {margin: 0.5em 2.5em;}
ul {margin: 0.5em 2em;}
ul ul {margin: 0 2em 0.5em 1em;}
dl {margin: 0.5em 1em;}
dd {margin: 0 2em;}
dt {font-size: 0.85em; font-family: "Consolas", "Courier New", monospace;}
dl.par dt {margin: 0.5em 0 0 0 ; font-style: italic; }
dl.ret dt {margin: 0.5em 0 0 0 ; font-size: 0.85em; font-family: "Consolas", "Courier New", monospace; font-weight: bold; }
hr {border-width: 1px; margin: 1em;}
div.abst {font-family: sans-serif;}
div.para {clear: both; font-family: serif;}
div.ret a {font-size: 0.85em; font-family: "Consolas", "Courier New", monospace; }
.equ {text-indent: 0; margin: 1em 2em 1em;}
.indent {margin-left: 2em;}
.rset {float: right; margin: 0.3em 0 0.5em 0.5em;}
.lset {float: left; margin: 0.3em 0.5em 0.5em 0.5em;}
ul.flat li {list-style-type: none; margin: 0;}
a.imglnk img {border: 1px solid;}
.iequ {white-space: nowrap; font-weight: bold;}
.clr {clear: both;}
.it {font-style: italic;}
.mfd {font-size: 0.7em; padding: 0 1px; border: 1px solid; white-space : nowrap}
.ral {text-align: right; }
.lal {text-align: left; }
.cal {text-align: center; }
h1 {line-height: 1em; font-size: 2em; font-family: sans-serif; padding: 0.3em 0 0.3em;}
h2 {font-size: 2em; font-family: sans-serif; background-color: #d8d8FF; padding: 0.5em 0.5em; margin: 0 0 0.5em;}
h3 {font-size: 1.5em; font-family: sans-serif; margin: 1.5em 0 0.5em;}
div.doc h3 {border-color: #b0d8d8; border-style: solid; border-width: 0px 0px 4px 12px; padding: 4px; margin-top: 3em;}
h4 {font-size: 1.2em; font-family: sans-serif; margin: 2em 0 0.2em;}
h5 {font-size: 1em; font-family: sans-serif; margin: 1em 0 0em;}
p.hdd {float: right; text-align: right; margin-top: 0.5em;}
hr.hds {clear: both; margin-bottom: 1em;}
kbd {letter-spacing: 0;}
small {font-size: 80%;}
.indent {margin-left: 2em;}
/* Tables */
table {margin: 0.5em 1em; border-collapse: collapse; border: 2px solid black; }
th {background-color: white; border-style: solid; border-width: 1px 1px 2px; border-color: black; padding: 0 3px; vertical-align: top; white-space: nowrap;}
td {background-color: white; border: 1px solid black; padding: 0 3px; vertical-align: top; line-height: 1.3em;}
table.lst td:first-child {font-size: 0.85em; font-family: "Consolas", "Courier New", monospace; white-space: nowrap;}
table.lst2 td {font-size: 0.85em; font-family: "Consolas", "Courier New", monospace; white-space: nowrap;}
table.lst3 td {font-family: "Consolas", "Courier New", monospace; white-space: nowrap;}
table caption {font-family: sans-serif; font-weight: bold;}
tr.lst3 td { border-width: 2px 1px 1px; }
p.foot {clear: both; text-indent: 0; margin: 1em 0.5em 1em;}

View File

@ -0,0 +1,333 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/appnote.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs Module Application Note</title>
</head>
<body>
<h1>FatFs Module Application Note</h1>
<ol class="toc">
<li><a href="#port">How to Port</a></li>
<li><a href="#limits">Limits</a></li>
<li><a href="#memory">Memory Usage</a></li>
<li><a href="#reduce">Reducing Module Size</a></li>
<li><a href="#lfn">Long File Name</a></li>
<li><a href="#unicode">Unicode API</a></li>
<li><a href="#exfat">exFAT Filesystem</a></li>
<li><a href="#lba64">64-bit LBA</a></li>
<li><a href="#reentrant">Re-entrancy</a></li>
<li><a href="#dup">Duplicated File Access</a></li>
<li><a href="#fs1">Performance Effective File Access</a></li>
<li><a href="#fs2">Considerations on Flash Memory Media</a></li>
<li><a href="#critical">Critical Section</a></li>
<li><a href="#fs3">Extended Use of FatFs API</a></li>
<li><a href="#license">About FatFs License</a></li>
</ol>
<div class="para doc" id="port">
<h3>How to Port</h3>
<h4>Basic Considerations</h4>
<p>The FatFs module assumes following conditions on portability.</p>
<ul>
<li>ANSI C<br>
The FatFs module is a middleware written in ANSI C (C89). There is no platform dependence, so long as the compiler is in compliance with C89 or later. Only exFAT feature requires C99.</li>
<li>Size of integer types<br>
<ul>
<li>Size of <tt>char</tt> must be 8-bit.</li>
<li>Size of <tt>int</tt>, as well as integer promotion, must be 16-bit or 32-bit.</li>
<li>When the C standard is in C89, size of <tt>short</tt> and <tt>long</tt> must be 16-bit and 32-bit respectively.</li>
<li>When it is in C99 or later, <tt>stdint.h</tt> is used to obtain the integer sizes.</li>
</ul>
</ul>
<h4>Integer Types in FatFs API</h4>
<p>Integer types used in FatFs are defined in <tt>ff.h</tt> as described below. It is based on Win32 API (<tt>windef.h</tt>). This will not be a problem on most platform. When a conflict with existing definitions occured, you must resolve it with care.</p>
<dl>
<dt><tt>BYTE</tt></dt><dd>8-bit unsigned integer in range of 0 to 2<sup>8</sup> - 1.</dd>
<dt><tt>WORD</tt></dt><dd>16-bit unsigned integer in range of 0 to 2<sup>16</sup> - 1.</dd>
<dt><tt>DWORD</tt></dt><dd>32-bit unsigned integer in range of 0 to 2<sup>32</sup> - 1.</dd>
<dt><tt>QWORD</tt></dt><dd>64-bit unsigned integer in range of 0 to 2<sup>64</sup> - 1.</dd>
<dt><tt>UINT</tt></dt><dd>Alias of <tt>unsigned int</tt> used to specify any number.</dd>
<dt><tt>WCHAR</tt></dt><dd>Alias of <tt>WORD</tt> used to specify a UTF-16 encoding unit.</dd>
<dt><tt>TCHAR</tt></dt><dd>Alias of <tt>char</tt>, <tt>WCHAR</tt> or <tt>DWORD</tt> used to specify a character encoding unit.</dd>
<dt><tt>FSIZE_t</tt></dt><dd>Alias of <tt>DWORD</tt> or <tt>QWORD</tt> used to address file offset and to specify file size.</dd>
<dt><tt>LBA_t</tt></dt><dd>Alias of <tt>DWORD</tt> or <tt>QWORD</tt> used to address sectors in LBA and to specify number of sectors.</dd>
</dl>
<h4>System Organizations</h4>
<p>The dependency diagram shown below is a typical, but not specific, configuration of the embedded system with FatFs module.</p>
<p><img src="../res/modules.png" width="580" height="280" alt="dependency diagram"></p>
<p>(a) If a working disk module for FatFs is provided, nothing else will be needed. (b) To attach existing disk drivers with different interface, some glue functions are needed to translate the interfaces between FatFs and the driver.</p>
<p><img src="../res/funcs.png" width="750" height="420" alt="functional diagram"></p>
<h4>Required Functions</h4>
<p>You need to provide only low level disk I/O functions required by FatFs module and nothing else. If a working disk I/O module for the target system is already provided, you need to write only glue functions to attach it to the FatFs module. If not, you need to port another disk I/O module or write it from scratch. Most of defined functions are not that always required. For instance, any write function is not required at read-only configuration. Following table shows which function is required depends on the configuration options.</p>
<table class="lst2">
<tr><th>Function</th><th>Required when</th><th>Note</th></tr>
<tr><td>disk_status<br>disk_initialize<br>disk_read</td><td>Always</td><td rowspan="5">Disk I/O functions.<br>Samples available in ffsample.zip.<br>There are many implementations on the web.</td></tr>
<tr><td>disk_write<br>get_fattime<br>disk_ioctl (CTRL_SYNC)</td><td>FF_FS_READONLY == 0</td></tr>
<tr><td>disk_ioctl (GET_SECTOR_COUNT)<br>disk_ioctl (GET_BLOCK_SIZE)</td><td>FF_USE_MKFS == 1</td></tr>
<tr><td>disk_ioctl (GET_SECTOR_SIZE)</td><td>FF_MAX_SS != FF_MIN_SS</td></tr>
<tr><td>disk_ioctl (CTRL_TRIM)</td><td>FF_USE_TRIM == 1</td></tr>
<tr><td>ff_uni2oem<br>ff_oem2uni<br>ff_wtoupper</td><td>FF_USE_LFN != 0</td><td>Unicode support functions.<br>Add optional module ffunicode.c to the project.</td></tr>
<tr><td>ff_cre_syncobj<br>ff_del_syncobj<br>ff_req_grant<br>ff_rel_grant</td><td>FF_FS_REENTRANT == 1</td><td rowspan="2">O/S dependent functions.<br>Sample code is available in ffsystem.c.</td></tr>
<tr><td>ff_mem_alloc<br>ff_mem_free</td><td>FF_USE_LFN == 3</td></tr>
</table>
<p>FatFs cares about neither what kind of storage device is used nor how it is implemented. Only a requirement is that it is a block device read/written in fixed-size blocks that accessible via the disk I/O functions defined above.</p>
</div>
<div class="para doc" id="limits">
<h3>Limits</h3>
<ul>
<li>Filesystem type: FAT, FAT32(rev0.0) and exFAT(rev1.0).</li>
<li>Number of open files: Unlimited. (depends on available memory)</li>
<li>Number of volumes: Up to 10.</li>
<li>Sector size: 512, 1024, 2048 and 4096 bytes.</li>
<li>Minimum volume size: 128 sectors.</li>
<li>Maximum volume size: 2<sup>32</sup> - 1 sectors in 32-bit LBA, virtually unlimited in 64-bit LBA with exFAT.</li>
<li>Maximum file size: 2<sup>32</sup> - 1 bytes on FAT volume, virtually unlimited on exFAT volume.</li>
<li>Cluster size: Upto 128 sectors on FAT volume and up to 16 MB on exFAT volume.</li>
</ul>
</div>
<div class="para doc" id="memory">
<h3>Memory Usage</h3>
<p>The memory usage varies depends on the <a href="config.html">configuration options</a>.</p>
<table class="lst2">
<tr><th></th><th>ARM7<small><br>32bit</small></th><th>ARM7<small><br>Thumb</small></th><th>CM3<small><br>Thumb-2</small></th><th>AVR</th><th>H8/300H</th><th>PIC24</th><th>RL78</th><th>V850ES</th><th>SH-2A</th><th>RX600</th><th>IA-32</th></tr>
<tr class="cal"> <td>Compiler</td><td>GCC</td><td>GCC</td><td>GCC</td><td>GCC</td><td>CH38</td><td>C30</td><td>CC78K0R</td><td>CA850</td><td>SHC</td><td>RXC</td><td>MSC</td></tr>
<!-- ARM Thumb CM3 AVR H8 PIC24 RL78 V850ES SH-2A RX600 IA-32 -->
<tr class="ral"><td class="cal">text (Full, R/W)</td><td>10.4k</td><td>6.7k</td><td>6.3k</td><td>12.4k</td> <td>9.9k</td><td>11.2k</td><td>13.0k</td><td>8.7k</td><td>9.0k</td><td>6.5k</td><td>8.9k</td></tr>
<tr class="ral"><td class="cal">text (Min, R/W)</td> <td>7.0k</td><td>4.7k</td><td>4.4k</td> <td>8.4k</td> <td>6.9k</td> <td>7.8k</td> <td>9.4k</td><td>6.0k</td><td>6.2k</td><td>4.6k</td><td>6.3k</td></tr>
<tr class="ral"><td class="cal">text (Full, R/O)</td> <td>4.8k</td><td>3.1k</td><td>2.8k</td> <td>5.7k</td> <td>4.7k</td> <td>5.3k</td> <td>6.4k</td><td>4.2k</td><td>4.0k</td><td>3.1k</td><td>4.2k</td></tr>
<tr class="ral"><td class="cal">text (Min, R/O)</td> <td>3.6k</td><td>2.4k</td><td>2.2k</td> <td>4.4k</td> <td>3.6k</td> <td>4.1k</td> <td>5.0k</td><td>3.3k</td><td>3.1k</td><td>2.4k</td><td>3.3k</td></tr>
<tr class="ral"><td class="cal">bss</td><td>V*4 + 2</td><td>V*4 + 2</td><td>V*4 + 2</td><td>V*2 + 2</td><td>V*4 + 2</td><td>V*2 + 2</td><td>V*2 + 2</td><td>V*4 + 2</td><td>V*4 + 2</td><td>V*4 + 2</td><td>V*4 + 2</td></tr>
<tr class="ral"><td class="cal">Work area<br><small>(FF_FS_TINY == 0)</small></td><td>V*564<br>+ F*552</td><td>V*564<br>+ F*552</td><td>V*564<br>+ F*552</td><td>V*560<br>+ F*546</td><td>V*560<br>+ F*546</td><td>V*560<br>+ F*546</td><td>V*560<br>+ F*546</td><td>V*564<br>+ F*552</td><td>V*564<br>+ F*552</td><td>V*564<br>+ F*552</td><td>V*564<br>+ F*552</td></tr>
<tr class="ral"><td class="cal">Work area<br><small>(FF_FS_TINY == 1)</small></td><td>V*564<br>+ F*40</td><td>V*564<br>+ F*40</td><td>V*564<br>+ F*40</td><td>V*560<br>+ F*34</td><td>V*560<br>+ F*34</td><td>V*560<br>+ F*34</td><td>V*560<br>+ F*34</td><td>V*564<br>+ F*40</td><td>V*564<br>+ F*40</td><td>V*564<br>+ F*40</td><td>V*564<br>+ F*40</td></tr>
</table>
<p>These are the memory usage of FatFs module without lower layer on some target systems in following condition. <em>V</em> denotes number of mounted volumes and <em>F</em> denotes number of open files. Every samples here are optimezed in code size.</p>
<pre>
FatFs R0.13a options:
FF_FS_READONLY 0 (Read/Write) or 1 (Read only)
FF_FS_MINIMIZE 0 (Full, with all basic functions) or 3 (Min, with fully minimized)
FF_FS_TINY 0 (Default) or 1 (Tiny file object)
And any other options are left unchanged from original setting.
</pre>
</div>
<div class="para doc" id="reduce">
<h3>Reducing Module Size</h3>
<p>Follwing table shows which API function is removed by configuration options for the module size reduction. To use any API function, the row of the function must be clear.</p>
<table class="lst2">
<tr><td rowspan="2">Function</td><td colspan="4">FF_FS_<br>MINIMIZE</td><td colspan="2">FF_FS_<br>READONLY</td><td colspan="2">FF_USE_<br>STRFUNC</td><td colspan="3">FF_FS_<br>RPATH</td><td colspan="2">FF_USE_<br>FIND</td><td colspan="2">FF_USE_<br>CHMOD</td><td colspan="2">FF_USE_<br>EXPAND</td><td colspan="2">FF_USE_<br>LABEL</td><td colspan="2">FF_USE_<br>MKFS</td><td colspan="2">FF_USE_<br>FORWARD</td><td colspan="2">FF_MULTI_<br>PARTITION</td></tr>
<tr> <td>0</td><td>1</td><td>2</td><td>3</td><td>0</td><td>1</td><td>0</td><td>1</td><td>0</td><td>1</td><td>2</td><td>0</td><td>1</td><td>0</td><td>1</td><td>0</td><td>1</td><td>0</td><td>1</td><td>0</td><td>1</td><td>0</td><td>1</td><td>0</td><td>1</td></tr>
<tr class="lst3">
<td>f_mount</td> <td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
<tr><td>f_open</td> <td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
<tr><td>f_close</td> <td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
<tr><td>f_read</td> <td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
<tr><td>f_write</td> <td> </td><td> </td><td> </td><td> </td><td> </td><td>x</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
<tr><td>f_sync</td> <td> </td><td> </td><td> </td><td> </td><td> </td><td>x</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
<tr><td>f_lseek</td> <td> </td><td> </td><td> </td><td>x</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
<tr><td>f_opendir</td> <td> </td><td> </td><td>x</td><td>x</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
<tr><td>f_closedir</td> <td> </td><td> </td><td>x</td><td>x</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
<tr><td>f_readdir</td> <td> </td><td> </td><td>x</td><td>x</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
<tr><td>f_findfirst</td><td> </td><td> </td><td>x</td><td>x</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td>x</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
<tr><td>f_findnext</td> <td> </td><td> </td><td>x</td><td>x</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td>x</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
<tr><td>f_stat</td> <td> </td><td>x</td><td>x</td><td>x</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
<tr><td>f_getfree</td> <td> </td><td>x</td><td>x</td><td>x</td><td> </td><td>x</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
<tr><td>f_truncate</td> <td> </td><td>x</td><td>x</td><td>x</td><td> </td><td>x</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
<tr><td>f_unlink</td> <td> </td><td>x</td><td>x</td><td>x</td><td> </td><td>x</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
<tr><td>f_mkdir</td> <td> </td><td>x</td><td>x</td><td>x</td><td> </td><td>x</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
<tr><td>f_rename</td> <td> </td><td>x</td><td>x</td><td>x</td><td> </td><td>x</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
<tr><td>f_chdir</td> <td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td>x</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
<tr><td>f_chdrive</td> <td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td>x</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
<tr><td>f_getcwd</td> <td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td>x</td><td>x</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
<tr><td>f_chmod</td> <td> </td><td> </td><td> </td><td> </td><td> </td><td>x</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td>x</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
<tr><td>f_utime</td> <td> </td><td> </td><td> </td><td> </td><td> </td><td>x</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td>x</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
<tr><td>f_getlabel</td> <td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td>x</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
<tr><td>f_setlabel</td> <td> </td><td> </td><td> </td><td> </td><td> </td><td>x</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td>x</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
<tr><td>f_expand</td> <td> </td><td> </td><td> </td><td> </td><td> </td><td>x</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td>x</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
<tr><td>f_forward</td> <td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td>x</td><td> </td><td> </td><td> </td></tr>
<tr><td>f_mkfs</td> <td> </td><td> </td><td> </td><td> </td><td> </td><td>x</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td>x</td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
<tr><td>f_fdisk</td> <td> </td><td> </td><td> </td><td> </td><td> </td><td>x</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td>x</td><td> </td><td> </td><td> </td><td>x</td><td> </td></tr>
<tr><td>f_putc</td> <td> </td><td> </td><td> </td><td> </td><td> </td><td>x</td><td>x</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
<tr><td>f_puts</td> <td> </td><td> </td><td> </td><td> </td><td> </td><td>x</td><td>x</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
<tr><td>f_printf</td> <td> </td><td> </td><td> </td><td> </td><td> </td><td>x</td><td>x</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
<tr><td>f_gets</td> <td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td>x</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
</table>
</div>
<div class="para doc" id="lfn">
<h3>Long File Name</h3>
<p>FatFs module supports the long file name (LFN) extension of the FAT filesystem. The two different file names, short file name (SFN) and LFN, of a file is transparent on the API. The support for LFN feature is disabled by default. To enable the LFN, set <tt><a href="config.html#use_lfn">FF_USE_LFN</a></tt> to 1, 2 or 3, and add <tt>ffunicode.c</tt> to the project. The LFN feature requiers a certain working buffer. The buffer size can be configured by <tt><a href="config.html#max_lfn">FF_MAX_LFN</a></tt> according to the available memory. The length of an LFN can be up to 255 characters, so that the <tt>FF_MAX_LFN</tt> should be set to 255 for all existing file names. If the size of working buffer is insufficient for the input file name, the file function fails with <tt>FR_INVALID_NAME</tt>. When use any re-entry to the API with LFN feature, <tt>FF_USE_LFN</tt> must be set to 2 or 3. In this case, the file function allocates the working buffer on the stack or heap. The LFN working buffer occupies <tt>(FF_MAX_LFN + 1) * 2</tt> bytes and additional <tt>(FF_MAX_LFN + 44) / 15 * 32</tt> bytes when exFAT is enabled.</p>
<h4>Impact upon Module Size</h4>
<table class="lst2 rset">
<caption>With LFN at CM3 + gcc</caption>
<tr><th><tt>FF_CODE_PAGE</tt></th><th>Code size</th></tr>
<tr><td>437-869 (SBCS)</td><td>+3.3k</td></tr>
<tr><td>932 (Japanese)</td><td>+62k</td></tr>
<tr><td>936 (Simplified Chinese)</td><td>+177k</td></tr>
<tr><td>949 (Korean)</td><td>+140k</td></tr>
<tr><td>950 (Traditional Chinese)</td><td>+111k</td></tr>
<tr><td>0 (All code pages)</td><td>+486k</td></tr>
</table>
<p>When the LFN is enabled, the module size will be increased depends on the configured code page. Right table shows the increment of code size in some code pages. Especially, in the CJK region, tens of thousands of characters are being used. Unfortunately, it requires a huge OEM-Unicode bidirectional conversion table and the module size will be drastically increased as shown in the table.</p>
<p>As the result, the FatFs with LFN enabled with DBCS code pages will not able to be ported on the most 8-bit MCU systems. If the target system is in legacy-free, in only Unicode and any ANSI/OEM code is not used at all, the code page setting gets meaningless. You will able to reduce the code size by configureing FatFs for Unicode with any SBCS code page.</p>
<p>There ware some restrictions on using LFN for open source project because the LFN extension on the FAT filesystem was a patent of Microsoft Corporation. But the related patents all have expired and using the LFN feature has got free for any projects.</p>
</div>
<div class="para doc" id="unicode">
<h3>Unicode API</h3>
<p>By default, FatFs uses ANSI/OEM code set on the API even at LFN configuration. FatFs can also switch the character encoding on the API to Unicode by configuration option <tt><a href="config.html#lfn_unicode">FF_LFN_UNICODE</a></tt>. This means that FatFs is compliant with the full featured LFN specification. The data type <tt>TCHAR</tt> specifies path name strings on the API is an alias of either <tt>char</tt>(ANSI/OEM or UTF-8), <tt>WCHAR</tt>(UTF-16) or <tt>DWORD</tt>(UTF-32) depends on that option. For more information, refer to the description in the <a href="filename.html#uni">file name</a>.</p>
<p>Note that setting of code page, <tt><a href="config.html#code_page">FF_CODE_PAGE</a></tt>, has actually no meaning when FatFs is configured for the Unicode API. It should be set 437 anyway. However it still affects code conversion of string I/O functions at <tt><a href="config.html#strf_encode">FF_STRF_ENCODE</a> == 0</tt> and backward compatibility with legacy systems, so that code page may need to be configured properly if it is considered a problem.</p>
</div>
<div class="para doc" id="exfat">
<h3>exFAT Filesystem</h3>
<p>The exFAT (Microsoft's Extended File Allocation Table) filesystem is a succession of the FAT/FAT32 filesystem which has been widely used in embedded systems, consumer devices and portable storage media. It is adopted by SDA (SD Association) as the filesystem for SDXC card, 64 GB and larger, and they are being shipped with this format. Therefore the exFAT is one of the standard filesystems for removable media as well as FAT. The exFAT filesystem allows the file size beyond the 4 GB limit what FAT filesystem allows up to and some filesystem overhead, especially cluster allocation delay, are reduced as well. These features allow to record the large data without dividing into some files and improve the write throughput to the file.</p>
<p>Note that the exFAT filesystem is a patent of Microsoft Corporation. The exFAT feature of FatFs is an implementation based on <cite>US. Pat. App. Pub. No. 2009/0164440 A1</cite>. FatFs module can switch the exFAT on or off by a configuration option, <tt><a href="config.html#fs_exfat">FF_FS_EXFAT</a></tt>. When enable the exFAT for the commercial products, a license by Microsoft will be needed depends on the final destination of the products.</p>
<p><em>Remarks: Enabling exFAT discards C89 compatibility and it wants C99 because of need for 64-bit integer type.</em></p>
</div>
<div class="para doc" id="lba64">
<h3>64-bit LBA</h3>
<p>LBA (Logical Block Addressing) is an addressing method to specify the location of data block, called sector, on the storage media. It is a simple linear address beginning from 0 as the first block of data. The host system does not need to consider how the data block is located and managed in the storage device. FatFs supports only LBA for the media access. 32-bit LBA is a common size at the interface of the most storage devices. It can address up to 2<sup>32</sup> blocks, 2 TB in 512 bytes/sector. When a storage device beyond 2 TB is used, increasing sector size or 64-bit LBA will be needed to address the entire block of the storage device.</p>
<p>By default, FatFs uses 32-bit LBA for media access interface. FatFs can also switch it to 64-bit LBA by a configuration option <tt><a href="config.html#fs_lba64">FF_LBA64</a></tt>. It also enables GPT (GUID Partition Table) for partiotion management on the storage media. For further information about GPT, refer to <tt><a href="mkfs.html">f_mkfs</a></tt> and <tt><a href="fdisk.html">f_fdisk</a></tt> function.</p>
</div>
<div class="para doc" id="reentrant">
<h3>Re-entrancy</h3>
<p>The file operations of two tasks to the <em>different volumes</em> each other is always re-entrant regardless of the configurations except when LFN is enabled with static working buffer (<tt>FF_USE_LFN = 1</tt>). It can work concurrently without any mutual exclusion.</p>
<p>The file operations of two tasks to the <em>same volume</em> is not re-entrant in default. FatFs can also be configured to make it thread-safe by option <tt><a href="config.html#fs_reentrant">FF_FS_REENTRANT</a></tt>. In this case, also the OS dependent synchronization control functions, <tt>ff_cre_syncobj/ff_del_syncobj/ff_req_grant/ff_rel_grant</tt>, need to be added to the project. There are some examples in the <tt>ffsystem.c</tt>. When a file function is called while the volume is being accessed by another task, the file function to the volume will be suspended until that task leaves the file function. If the wait time exceeded a period defined by <tt>FF_TIMEOUT</tt>, the file function will abort with <tt>FR_TIMEOUT</tt>. The timeout feature might not be supported on the some RTOSs.</p>
<p>There is an exception on the re-entrancy for <tt>f_mount/f_mkfs</tt> function. These volume management functions are not re-entrant to the same volume. When use these functions, other tasks need to avoid to access the volume.</p>
<div class="rset">
<table class="lst2">
<tr><th><tt>Function</tt></th><th>Case 1</th><th>Case 2</th><th>Case 3</th></tr>
<tr><td>disk_status</td><td>Yes</td><td>Yes</td><td>Yes(*)</td></tr>
<tr><td>disk_initialize</td><td>No</td><td>Yes</td><td>Yes(*)</td></tr>
<tr><td>disk_read</td><td>No</td><td>Yes</td><td>Yes(*)</td></tr>
<tr><td>disk_write</td><td>No</td><td>Yes</td><td>Yes(*)</td></tr>
<tr><td>disk_ioctl</td><td>No</td><td>Yes</td><td>Yes(*)</td></tr>
<tr><td>get_fattime</td><td>No</td><td>Yes</td><td>Yes</td></tr>
</table>
<small>
Case 1: Same volume.<br>
Case 2: Different volume on the same drive.<br>
Case 3: Different volume on the different drive.<br>
(*) In only different drive number.
</small>
</div>
<p>Remarks: This section describes on the re-entrancy of the FatFs module itself. The <tt>FF_FS_REENTRANT</tt> option enables only exclusive use of each filesystem objects and FatFs does not that prevent to re-enter the low level disk functions. Thus the low level disk I/O layer needs to be always thread-safe when FatFs API is re-entered for different volumes. Right table shows which low level function can be re-entered when FatFs API is re-entered on some conditions.</p>
</div>
<div class="para doc" id="dup">
<h3>Duplicated File Open</h3>
<p>FatFs module does not support the read/write collision control of duplicated open to a file. The duplicated open is permitted only when each of open method to a file is read mode. The duplicated open with one or more write mode to a file is always prohibited, and also open file must not be renamed or deleted. A violation of these rules can cause data collaption.</p>
<p>The file lock control can be enabled by <tt><a href="config.html#fs_lock">FF_FS_LOCK</a></tt> option. The value of option defines the number of open objects to manage simultaneously. In this case, if any opening, renaming or removing against the file shareing rule that described above is attempted, the file function will be rejected with <tt>FR_LOCKED</tt>. If number of open objects, files and sub-directories, is equal to <tt>FF_FS_LOCK</tt>, an extra <tt>f_open/f_opendir</tt> function will fail with <tt>FR_TOO_MANY_OPEN_FILES</tt>.</p>
</div>
<div class="para doc" id="fs1">
<h3>Performance Effective File Access</h3>
<p>For good read/write throughput on the small embedded systems with limited size of memory, application programmer should consider what process is done in the FatFs module. The file data on the volume is transferred in following sequence by <tt>f_read</tt> function.</p>
<p>Figure 1. Sector unaligned read (short)<br>
<img src="../res/f1.png" width="490" height="110" alt="">
</p>
<p>Figure 2. Sector unaligned read (long)<br>
<img src="../res/f2.png" width="490" height="140" alt="">
</p>
<p>Figure 3. Fully sector aligned read<br>
<img src="../res/f3.png" width="490" height="119" alt="">
</p>
<p>The file I/O buffer is a sector buffer to read/write a part of data on the sector. The sector buffer is either file private sector buffer on each file object or shared sector buffer in the filesystem object. The buffer configuration option <tt><a href="config.html#fs_tiny">FF_FS_TINY</a></tt> determins which sector buffer is used for the file data transfer. When tiny buffer configuration (1) is selected, data memory consumption is reduced <tt>FF_MAX_SS</tt> bytes each file object. In this case, FatFs module uses only a sector buffer in the filesystem object for file data transfer and FAT/directory access. The disadvantage of the tiny buffer configuration is: the FAT data cached in the sector buffer will be lost by file data transfer and it must be reloaded at every cluster boundary. However it will be suitable for most application from view point of the decent performance and low memory comsumption.</p>
<p>Figure 1 shows that a partial sector, sector unaligned part of the file, is transferred via the file I/O buffer. At long data transfer shown in Figure 2, middle of transfer data that covers one or more sector is transferred to the application buffer directly. Figure 3 shows that the case of entier transfer data is aligned to the sector boundary. In this case, file I/O buffer is not used. On the direct transfer, the maximum extent of sectors are read with <tt>disk_read</tt> function at a time but the multiple sector transfer is divided at cluster boundary even if it is contiguous.</p>
<p>Therefore taking effort to sector aligned read/write accesss eliminates buffered data transfer and the read/write performance will be improved. Besides the effect, cached FAT data will not be flushed by file data transfer at the tiny configuration, so that it can achieve same performance as non-tiny configuration with small memory footprint.</p>
</div>
<div class="para doc" id="fs2">
<h3>Considerations on Flash Memory Media</h3>
<p>To maximize the write performance of flash memory media, such as SDC, CFC and U Disk, it must be controlled in consideration of its characteristitcs.</p>
<h4>Using Mutiple-Sector Write</h4>
<div class="rset">
Figure 6. Comparison between Multiple/Single Sector Write<br>
<img src="../res/f6.png" width="630" height="148" alt="fig.6">
</div>
<p>The write throughput of the flash memory media becomes the worst at single sector write transaction. The write throughput increases as the number of sectors per a write transaction as shown in Figure 6. This effect more appers at faster interface speed and the performance ratio often becomes grater than ten. <a href="../res/rwtest2.png">This result</a> is clearly explaining how fast is multiple block write (W:16K, 32 sectors) than single block write (W:100, 1 sector), and also larger card tends to be slow at single block write. Number of write transactions also affects life time of the flash memory media. When compared at same amount of write data, the single sector write in Figure 6 above wears flash memory media 16 times more than multiple sector write in Figure 6 below. Single sector write is pretty pain for the flash memory media.</p>
<p>Therefore the application program should write the data in large block as possible. The ideal write chunk size and alighment is size of sector, and size of cluster is the best. Of course all layers between the application and the storage device must have consideration on multiple sector write, however most of open-source memory card drivers lack it. Do not split a multiple sector write request into single sector write transactions or the write throughput gets poor. Note that FatFs module and its sample disk drivers supprt multiple sector read/write operation. </p>
<h4>Forcing Memory Erase</h4>
<p>When remove a file with <tt>f_unlink</tt> function, the data clusters occupied by the file are marked 'free' on the FAT. But the data sectors containing the file data are not that applied any process, so that the file data left occupies a part of the flash memory array as 'live block'. If the file data can be erased on removing the file, those data blocks will be turned into the free block pool. This may skip internal block erase operation to the data block on next write operation. As the result the write performance might be improved. FatFs can manage this function by setting <tt><a href="config.html#use_trim">FF_USE_TRIM</a></tt> to 1. Note that this is an expectation of internal process of the storage device and not that always effective. Most applications will not need this function. Also <tt>f_unlink</tt> function can take a time when remove a large file.</p>
</div>
<div class="para doc" id="critical">
<h3>Critical Section</h3>
<p>If a write operation to the FAT volume is interrupted due to an accidental failure, such as sudden blackout, wrong media removal and unrecoverable disk error, the FAT structure on the volume can be broken. Following images shows the critical section of the FatFs module.</p>
<div class="lset">
Figure 4. Long critical section<br>
<img src="../res/f4.png" width="320" height="436" alt="fig.4">
</div>
<div class="lset">
Figure 5. Minimized critical section<br>
<img src="../res/f5.png" width="320" height="436" alt="fig.5">
</div>
<br class="clr">
<p>An interruption in the red section can cause a cross link; as a result, the object being changed can be lost. If an interruption in the yellow section is occured, there is one or more possibility listed below.</p>
<ul>
<li>The file data being rewrited is collapsed.</li>
<li>The file being appended returns initial state.</li>
<li>The file created as new is gone.</li>
<li>The file created as new or overwritten remains but no content.</li>
<li>Efficiency of disk use gets worse due to lost clusters.</li>
</ul>
<p>Each case does not affect any file not opened in write mode. To minimize risk of data loss, the critical section can be minimized by minimizing the time that file is opened in write mode or using <tt>f_sync</tt> function as shown in Figure 5.</p>
</div>
<div class="para doc" id="fs3">
<h3>Extended Use of FatFs API</h3>
<p>These are examples of extended use of FatFs APIs. New item will be added when useful code example is found.</p>
<ol>
<li><a href="http://elm-chan.org/fsw/ff/res/app1.c">Open or create a file for append</a> (for R0.12 and earlier)</li>
<li><a href="http://elm-chan.org/fsw/ff/res/app2.c">Delete a non-empty sub-directory</a> (for R0.12 and later)</li>
<li><a href="http://elm-chan.org/fsw/ff/res/app3.c">Allocate contiguous area to the file</a> (for R0.11a and earlier)</li>
<li><a href="http://elm-chan.org/fsw/ff/res/app5.c">Test if the file is contiguous or not</a></li>
<li><a href="http://elm-chan.org/fsw/ff/res/app4.c">Compatibility checker for low level disk I/O module</a></li>
<li><a href="http://elm-chan.org/fsw/ff/res/app6.c">Performance checker for low level disk I/O module</a></li>
<li><a href="http://elm-chan.org/fsw/ff/res/mkfatimg.zip">FAT volume image creator</a></li>
<li>Virtual drive feature (refer to lpc176x/ in <a href="../ffsample.zip">ffsample.zip</a>)</li>
</ol>
</div>
<div class="para doc" id="license">
<h3>About FatFs License</h3>
<p>FatFs has being developped as a personal project of the author, ChaN. It is free from the code anyone else wrote at current release. Following code block shows a copy of the FatFs license document that included in the source files.</p>
<pre>
/*----------------------------------------------------------------------------/
/ FatFs - Generic FAT Filesystem Module Rx.xx /
/-----------------------------------------------------------------------------/
/
/ Copyright (C) 20xx, ChaN, all right reserved.
/
/ FatFs module is an open source software. Redistribution and use of FatFs in
/ source and binary forms, with or without modification, are permitted provided
/ that the following condition is met:
/
/ 1. Redistributions of source code must retain the above copyright notice,
/ this condition and the following disclaimer.
/
/ This software is provided by the copyright holder and contributors "AS IS"
/ and any warranties related to this software are DISCLAIMED.
/ The copyright owner or contributors be NOT LIABLE for any damages caused
/ by use of this software.
/----------------------------------------------------------------------------*/
</pre>
<p>Therefore FatFs license is one of the BSD-style licenses but there is a significant feature. FatFs is mainly intended for embedded systems. In order to extend the usability for commercial products, the redistributions of FatFs in binary form, such as embedded code, binary library and any forms without source code, does not need to include about FatFs in the documentations. This is equivalent to the 1-clause BSD license. Of course FatFs is compatible with the most of open source software licenses including GNU GPL. When you redistribute the FatFs source code with any changes or create a fork, the license can also be changed to GNU GPL, BSD-style license or any open source software license that not conflict with FatFs license.</p>
</div>
<p class="foot"><a href="../00index_e.html">Return Home</a></p>
</body>
</html>

View File

@ -0,0 +1,88 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/chdir.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_chdir</title>
</head>
<body>
<div class="para func">
<h2>f_chdir</h2>
<p>The <tt>f_chdir</tt> function changes the current directory of the logical drive.</p>
<pre>
FRESULT f_chdir (
const TCHAR* <span class="arg">path</span> <span class="c">/* [IN] Path name */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>path</dt>
<dd>Pointer to the null-terminated string that specifies the <a href="filename.html">directory</a> to go.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>
<a href="rc.html#ok">FR_OK</a>,
<a href="rc.html#de">FR_DISK_ERR</a>,
<a href="rc.html#ie">FR_INT_ERR</a>,
<a href="rc.html#nr">FR_NOT_READY</a>,
<a href="rc.html#np">FR_NO_PATH</a>,
<a href="rc.html#in">FR_INVALID_NAME</a>,
<a href="rc.html#id">FR_INVALID_DRIVE</a>,
<a href="rc.html#ne">FR_NOT_ENABLED</a>,
<a href="rc.html#ns">FR_NO_FILESYSTEM</a>,
<a href="rc.html#tm">FR_TIMEOUT</a>,
<a href="rc.html#nc">FR_NOT_ENOUGH_CORE</a>
</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>The <tt>f_chdir</tt> function changes the current directory of the logical drive. Also the current drive is changed at Unix style volume ID, <tt><a href="config.html#str_volume_id">FF_STR_VOLUME_ID</a> == 2</tt>. The current directory of each logical drive is initialized to the root directory on mount.</p>
<p>Note that the current directory is retained in the each file system object and the current drive is retained in a static variable, so that it also affects other tasks that use the file functions.</p>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>Available when <tt><a href="config.html#fs_rpath">FF_FS_RPATH</a> &gt;= 1</tt>.</p>
</div>
<div class="para use">
<h4>Example</h4>
<pre>
<span class="c">/* Change current direcoty of the current drive ("dir1" under root directory) */</span>
<em>f_chdir</em>("/dir1");
<span class="c">/* Change current direcoty of current drive (parent directory of drive 2) */</span>
<em>f_chdir</em>("2:..");
<span class="c">/* Change current direcoty of the drive "sdcard" (at DOS/Windows style volume ID) */</span>
<em>f_chdir</em>("sdcard:/dir1");
<span class="c">/* Change current direcoty of the drive "flash" and set it as current drive (at Unix style volume ID) */</span>
<em>f_chdir</em>("/flash/dir1");
</pre>
</div>
<div class="para ref">
<h4>See Also</h4>
<p><tt><a href="chdrive.html">f_chdrive</a>, <a href="getcwd.html">f_getcwd</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,72 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/chdrive.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_chdrive</title>
</head>
<body>
<div class="para func">
<h2>f_chdrive</h2>
<p>The f_chdrive function changes the current drive.</p>
<pre>
FRESULT f_chdrive (
const TCHAR* <span class="arg">path</span> <span class="c">/* [IN] Logical drive number */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>path</dt>
<dd>Specifies the <a href="filename.html">logical drive number</a> to be set as the current drive.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>
<a href="rc.html#ok">FR_OK</a>,
<a href="rc.html#id">FR_INVALID_DRIVE</a>
</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>The <tt>f_chdrive</tt> function changes only the current drive. The initial value of the current drive number is 0. Note that the current drive is retained in a static variable, so that it also affects other tasks that using the file functions.</p>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>Available when <tt><a href="config.html#fs_rpath">FF_FS_RPATH</a> &gt;= 1</tt>.</p>
</div>
<div class="para use">
<h4>Example</h4>
<pre>
<em>f_chdrive</em>("2:"); <span class="c">/* Set drive 2 as current drive */</span>
<em>f_chdrive</em>(""); <span class="c">/* No effect (set current drive as current drive) */</span>
<em>f_chdrive</em>("/flash"); <span class="c">/* Set drive "flash" as current drive (at Unix style volume ID) */</span>
</pre>
</div>
<div class="para ref">
<h4>See Also</h4>
<p><tt><a href="chdir.html">f_chdir</a>, <a href="getcwd.html">f_getcwd</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,89 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/chmod.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_chmod</title>
</head>
<body>
<div class="para func">
<h2>f_chmod</h2>
<p>The f_chmod function changes the attribute of a file or sub-directory.</p>
<pre>
FRESULT f_chmod (
const TCHAR* <span class="arg">path</span>, <span class="c">/* [IN] Object name */</span>
BYTE <span class="arg">attr</span>, <span class="c">/* [IN] Attribute flags */</span>
BYTE <span class="arg">mask</span> <span class="c">/* [IN] Attribute masks */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>path</dt>
<dd>Pointer to the null-terminated string that specifies an <a href="filename.html">object</a> to be changed</dd>
<dt>attr</dt>
<dd>Attribute flags to be set in one or more combination of the following flags. The specified flags are set and others are cleard.<br>
<table class="lst">
<tr><th>Attribute</th><th>Description</th></tr>
<tr><td>AM_RDO</td><td>Read only</td></tr>
<tr><td>AM_ARC</td><td>Archive</td></tr>
<tr><td>AM_SYS</td><td>System</td></tr>
<tr><td>AM_HID</td><td>Hidden</td></tr>
</table>
</dd>
<dt>mask</dt>
<dd>Attribute mask that specifies which attribute is changed. The specified attributes are set or cleard and others are left unchanged.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>
<a href="rc.html#ok">FR_OK</a>,
<a href="rc.html#de">FR_DISK_ERR</a>,
<a href="rc.html#ie">FR_INT_ERR</a>,
<a href="rc.html#nr">FR_NOT_READY</a>,
<a href="rc.html#ok">FR_NO_FILE</a>,
<a href="rc.html#np">FR_NO_PATH</a>,
<a href="rc.html#in">FR_INVALID_NAME</a>,
<a href="rc.html#wp">FR_WRITE_PROTECTED</a>,
<a href="rc.html#id">FR_INVALID_DRIVE</a>,
<a href="rc.html#ne">FR_NOT_ENABLED</a>,
<a href="rc.html#ns">FR_NO_FILESYSTEM</a>,
<a href="rc.html#tm">FR_TIMEOUT</a>,
<a href="rc.html#nc">FR_NOT_ENOUGH_CORE</a>
</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>The <tt>f_chmod</tt> function changes the attribute of a file or sub-directory.</p>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>Available when <tt><a href="config.html#fs_readonly">FF_FS_READONLY</a> == 0</tt> and <tt><a href="config.html#use_chmod">FF_USE_CHMOD</a> == 1</tt>.</p>
</div>
<div class="para use">
<h4>Example</h4>
<pre>
<span class="c">/* Set Read-only, clear Archive and others are left unchanged. */</span>
<em>f_chmod</em>("file.txt", AM_RDO, AM_RDO | AM_ARC);
</pre>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,65 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/close.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_close</title>
</head>
<body>
<div class="para func">
<h2>f_close</h2>
<p>The f_close function closes an open file.</p>
<pre>
FRESULT f_close (
FIL* <span class="arg">fp</span> <span class="c">/* [IN] Pointer to the file object */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameter</h4>
<dl class="par">
<dt>fp</dt>
<dd>Pointer to the open file object structure to be closed.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>
<a href="rc.html#ok">FR_OK</a>,
<a href="rc.html#de">FR_DISK_ERR</a>,
<a href="rc.html#ie">FR_INT_ERR</a>,
<a href="rc.html#io">FR_INVALID_OBJECT</a>,
<a href="rc.html#tm">FR_TIMEOUT</a>
</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>The <tt>f_close</tt> function closes an open file object. If the file has been changed, the cached information of the file is written back to the volume. After the function succeeded, the file object is no longer valid and it can be discarded.</p>
<p>Note that if the file object is in read-only mode and <tt>FF_FS_LOCK</tt> is not enabled, the file object can also be discarded without this procedure. However this is not recommended for future compatibility.</p>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>Always available.</p>
</div>
<div class="para ref">
<h4>See Also</h4>
<p><tt><a href="open.html">f_open</a>, <a href="read.html">f_read</a>, <a href="write.html">f_write</a>, <a href="sync.html">f_sync</a>, <a href="sfile.html">FIL</a>, <a href="sfatfs.html">FATFS</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,64 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/close.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_closedir</title>
</head>
<body>
<div class="para func">
<h2>f_closedir</h2>
<p>The f_closedir function closes an open directory.</p>
<pre>
FRESULT f_closedir (
DIR* <span class="arg">dp</span> <span class="c">/* [IN] Pointer to the directory object */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameter</h4>
<dl class="par">
<dt>dp</dt>
<dd>Pointer to the open directory object structure to be closed.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>
<a href="rc.html#ok">FR_OK</a>,
<a href="rc.html#ie">FR_INT_ERR</a>,
<a href="rc.html#io">FR_INVALID_OBJECT</a>,
<a href="rc.html#tm">FR_TIMEOUT</a>
</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>The <tt>f_closedir</tt> function closes an open directory object. After the function succeeded, the directory object is no longer valid and it can be discarded.</p>
<p>Note that the directory object can also be discarded without this procedure when option <tt>FF_FS_LOCK</tt> is not enabled. However this is not recommended for future compatibility.</p>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>Available when <tt><a href="config.html#fs_minimize">FF_FS_MINIMIZE</a> &lt;= 1</tt>.</p>
</div>
<div class="para ref">
<h4>See Also</h4>
<p><tt><a href="opendir.html">f_opendir</a>, <a href="readdir.html">f_readdir</a>, <a href="sdir.html">DIR</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,291 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/config.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - Configuration Options</title>
</head>
<body>
<h1>Configuration Options</h1>
<p>There are many options to configure the functions of FatFs for requirement of each project. The configuration options are defined in the <em><tt>ffconf.h</tt></em>.</p>
<ul>
<li>Function Configurations
<ul>
<li><a href="#fs_readonly">FF_FS_READONLY</a></li>
<li><a href="#fs_minimize">FF_FS_MINIMIZE</a></li>
<li><a href="#use_strfunc">FF_USE_STRFUNC</a></li>
<li><a href="#use_find">FF_USE_FIND</a></li>
<li><a href="#use_mkfs">FF_USE_MKFS</a></li>
<li><a href="#use_fastseek">FF_USE_FASTSEEK</a></li>
<li><a href="#use_expand">FF_USE_EXPAND</a></li>
<li><a href="#use_chmod">FF_USE_CHMOD</a></li>
<li><a href="#use_label">FF_USE_LABEL</a></li>
<li><a href="#use_forward">FF_USE_FORWARD</a></li>
</ul>
</li>
<li>Namespace and Locale Configurations
<ul>
<li><a href="#code_page">FF_CODE_PAGE</a></li>
<li><a href="#use_lfn">FF_USE_LFN</a></li>
<li><a href="#max_lfn">FF_MAX_LFN</a></li>
<li><a href="#lfn_unicode">FF_LFN_UNICODE</a></li>
<li><a href="#lfn_buf">FF_LFN_BUF, FF_SFN_BUF</a></li>
<li><a href="#strf_encode">FF_STRF_ENCODE</a></li>
<li><a href="#fs_rpath">FF_FS_RPATH</a></li>
</ul>
</li>
<li>Volume/Drive Configurations
<ul>
<li><a href="#volumes">FF_VOLUMES</a></li>
<li><a href="#str_volume_id">FF_STR_VOLUME_ID</a></li>
<li><a href="#volume_strs">FF_VOLUME_STRS</a></li>
<li><a href="#multi_partition">FF_MULTI_PARTITION</a></li>
<li><a href="#max_ss">FF_MIN_SS, FF_MAX_SS</a></li>
<li><a href="#fs_lba64">FF_LBA64</a></li>
<li><a href="#fs_gptmin">FF_GPT_MIN</a></li>
<li><a href="#use_trim">FF_USE_TRIM</a></li>
</ul>
</li>
<li>System Configurations
<ul>
<li><a href="#fs_tiny">FF_FS_TINY</a></li>
<li><a href="#fs_exfat">FF_FS_EXFAT</a></li>
<li><a href="#fs_nortc">FF_FS_NORTC</a></li>
<li><a href="#nortc_time">FF_NORTC_MON, FF_NORTC_MDAY, FF_NORTC_YEAR</a></li>
<li><a href="#fs_nofsinfo">FF_FS_NOFSINFO</a></li>
<li><a href="#fs_lock">FF_FS_LOCK</a></li>
<li><a href="#fs_reentrant">FF_FS_REENTRANT</a></li>
<li><a href="#fs_timeout">FF_FS_TIMEOUT</a></li>
<li><a href="#sync_t">FF_SYNC_t</a></li>
</ul>
</li>
</ul>
<div class="para doc" id="func">
<h3>Function Configurations</h3>
<h4 id="fs_readonly">FF_FS_READONLY</h4>
<p>Read/Write (0) or Read-only (1). Read-only configuration removes writing API functions, <tt>f_write</tt>, <tt>f_sync</tt>, <tt>f_unlink</tt>, <tt>f_mkdir</tt>, <tt>f_chmod</tt>, <tt>f_rename</tt>, <tt>f_truncate</tt>, <tt>f_getfree</tt> and optional writing functions as well.</p>
<h4 id="fs_minimize">FF_FS_MINIMIZE</h4>
<p>This option defines minimization level to remove some basic API functions as follows:</p>
<table class="lst1">
<tr><th>Value</th><th>Description</th></tr>
<tr><td>0</td><td>All basic API functions are available.</td></tr>
<tr><td>1</td><td><tt>f_stat</tt>, <tt>f_getfree</tt>, <tt>f_unlink</tt>, <tt>f_mkdir</tt>, <tt>f_chmod</tt>, <tt>f_utime</tt>, <tt>f_truncate</tt> and <tt>f_rename</tt> function are removed.</td></tr>
<tr><td>2</td><td><tt>f_opendir</tt>, <tt>f_readdir</tt> and <tt>f_closedir</tt> function are removed in addition to 1.</td></tr>
<tr><td>3</td><td><tt>f_lseek</tt> function is removed in addition to 2.</td></tr>
</table>
<h4 id="use_strfunc">FF_USE_STRFUNC</h4>
<p>This option switches string functions, <tt>f_gets</tt>, <tt>f_putc</tt>, <tt>f_puts</tt> and <tt>f_printf</tt>.</p>
<table class="lst1">
<tr><th>Value</th><th>Description</th></tr>
<tr><td>0</td><td>Disable string functions.</td></tr>
<tr><td>1</td><td>Enable string functions without LF-CRLF conversion.</td></tr>
<tr><td>2</td><td>Enable string functions with LF-CRLF conversion.</td></tr>
</table>
<h4 id="use_find">FF_USE_FIND</h4>
<p>Disable (0) or Enable (1) filtered directory read functions, <tt>f_findfirst</tt> and <tt>f_findnext</tt>. Also <tt>FF_FS_MINIMIZE</tt> needs to be 0 or 1.</p>
<h4 id="use_mkfs">FF_USE_MKFS</h4>
<p>Disable (0) or Enable (1) <tt>f_mkfs</tt> function.</p>
<h4 id="use_fastseek">FF_USE_FASTSEEK</h4>
<p>Disable (0) or Enable (1) fast seek function to enable accelerated mode for <tt>f_lseek</tt>, <tt>f_read</tt> and <tt>f_write</tt> function. For more information, read <a href="lseek.html">here</a>.</p>
<h4 id="use_expand">FF_USE_EXPAND</h4>
<p>Disable (0) or Enable (1) <tt>f_expand</tt> function.</p>
<h4 id="use_chmod">FF_USE_CHMOD</h4>
<p>Disable (0) or Enable (1) metadata control functions, <tt>f_chmod</tt> and <tt>f_utime</tt>. Also <tt>FF_FS_READONLY</tt> needs to be 0.</p>
<h4 id="use_label">FF_USE_LABEL</h4>
<p>Disable (0) or Enable (1) API functions for volume label, <tt>f_getlabel</tt> and <tt>f_setlabel</tt>.</p>
<h4 id="use_forward">FF_USE_FORWARD</h4>
<p>Disable (0) or Enable (1) <tt>f_forward</tt> function.</p>
</div>
<div class="para doc" id="name">
<h3>Namespace and Locale Configurations</h3>
<h4 id="code_page">FF_CODE_PAGE</h4>
<p>This option specifies the OEM code page to be used on the target system. Incorrect setting of the code page can cause a file open failure. If any non-ASCII character is not used for the path name, there is no difference between any code page settings. Set it 437 anyway.</p>
<table class="lst1">
<tr><th>Value</th><th>Code page</th></tr>
<tr><td>0</td><td>Includes all code pages below and set by <tt>f_setcp()</tt></td></tr>
<tr><td>437</td><td>U.S.</td></tr>
<tr><td>720</td><td>Arabic</td></tr>
<tr><td>737</td><td>Greek</td></tr>
<tr><td>771</td><td>KBL</td></tr>
<tr><td>775</td><td>Baltic</td></tr>
<tr><td>850</td><td>Latin 1</td></tr>
<tr><td>852</td><td>Latin 2</td></tr>
<tr><td>855</td><td>Cyrillic</td></tr>
<tr><td>857</td><td>Turkish</td></tr>
<tr><td>860</td><td>Portuguese</td></tr>
<tr><td>861</td><td>Icelandic</td></tr>
<tr><td>862</td><td>Hebrew</td></tr>
<tr><td>863</td><td>Canadian French</td></tr>
<tr><td>864</td><td>Arabic</td></tr>
<tr><td>865</td><td>Nordic</td></tr>
<tr><td>866</td><td>Russian</td></tr>
<tr><td>869</td><td>Greek 2</td></tr>
<tr><td>932</td><td>Japanese (DBCS)</td></tr>
<tr><td>936</td><td>Simplified Chinese (DBCS)</td></tr>
<tr><td>949</td><td>Korean (DBCS)</td></tr>
<tr><td>950</td><td>Traditional Chinese (DBCS)</td></tr>
</table>
<h4 id="use_lfn">FF_USE_LFN</h4>
<p>This option switches the support for long file name (LFN). When enable the LFN, Unicode support module <tt>ffunicode.c</tt> need to be added to the project. When use stack for the working buffer, take care on stack overflow. When use heap memory for the working buffer, memory management functions (<tt>ff_memalloc</tt> and <tt>ff_memfree</tt>) need to be added to the project.</p>
<table class="lst1">
<tr><th>Value</th><th>Description</th></tr>
<tr><td>0</td><td>Disable LFN. Path name in only 8.3 format can be used.</td></tr>
<tr><td>1</td><td>Enable LFN with static working buffer on the BSS. Always NOT thread-safe.</td></tr>
<tr><td>2</td><td>Enable LFN with dynamic working buffer on the STACK.</td></tr>
<tr><td>3</td><td>Enable LFN with dynamic working buffer on the HEAP.</td></tr>
</table>
<h4 id="max_lfn">FF_MAX_LFN</h4>
<p>LFN function requiers certain internal working buffer for the file name. This option defines size of the buffer and the value can be in range of 12 to 255 in UTF-16 encoding unit of the LFN. The buffer occupies <tt>(FF_MAX_LFN + 1) * 2</tt> bytes and additional <tt>(FF_MAX_LFN + 44) / 15 * 32</tt> bytes when exFAT is enabled. It is recommended to be set 255 to fully support the LFN specification. This option has no effect when LFN is not enabled.</p>
<h4 id="lfn_unicode">FF_LFN_UNICODE</h4>
<p>This option switches character encoding for the file name on the API. When Unicode is selected, <tt>FF_CODE_PAGE</tt> has actually no meaning except for compatibility with legacy systems, such as MS-DOS and any system without support for LFN. FatFs supports the code point up to U+10FFFF.</p>
<table class="lst2">
<tr><th>Value</th><th>Character Encoding</th><th><tt>TCHAR</tt></th></tr>
<tr><td>0</td><td>ANSI/OEM in current CP</td><td>char</td></tr>
<tr><td>1</td><td>Unicode in UTF-16</td><td>WCHAR</td></tr>
<tr><td>2</td><td>Unicode in UTF-8</td><td>char</td></tr>
<tr><td>3</td><td>Unicode in UTF-32</td><td>DWORD</td></tr>
</table>
<p>This option also affects behavior of string I/O functions (see <tt>FF_STRF_ENCODE</tt>). When LFN is not enabled, this option has no effect and FatFs works at ANSI/OEM code on the API. For more information, read <a href="filename.html#uni">here</a>.</p>
<h4 id="lfn_buf">FF_LFN_BUF, FF_SFN_BUF</h4>
<p>This set of options defines size of file name members, <tt>fname[]</tt> and <tt>altname[]</tt>, in the <tt><a href="sfileinfo.html">FILINFO</a></tt> structure which is used to read out the directory items. These values should be suffcient for the file names to read. The maximum possible length of read file name depends on the character encoding on the API as follows:</p>
<table class="lst2">
<tr><th>Encoding</th><th>LFN length</th><th>SFN length</th></tr>
<tr><td>ANSI/OEM at SBCS</td><td>255 items</td><td>12 items</td></tr>
<tr><td>ANSI/OEM at DBCS</td><td>510 items</td><td>12 items</td></tr>
<tr><td>Unicode in UTF-16/32</td><td>255 items</td><td>12 items</td></tr>
<tr><td>Unicode in UTF-8</td><td>765 items</td><td>34 items</td></tr>
</table>
<p>If the size of name member is insufficient for the LFN, the item is treated as without LFN. When LFN is not enabled, these options have no effect.</p>
<h4 id="strf_encode">FF_STRF_ENCODE</h4>
<p>When character encoding on the API is Unicode (<tt>FF_LFN_UNICODE &gt;= 1</tt>), string I/O functions, <tt>f_gets</tt>, <tt>f_putc</tt>, <tt>f_puts</tt> and <tt>f_printf</tt>, convert the character encoding in it. This option defines the assumption of character encoding <em>on the file</em> to be read/written via those functions. When LFN is not enabled or <tt>FF_LFN_UNICODE == 0</tt>, the string functions work without any encoding conversion and this option has no effect.</p>
<table class="lst2">
<tr><th>Value</th><th>Character encoding on the file</th></tr>
<tr><td>0</td><td>ANSI/OEM in current code page</td></tr>
<tr><td>1</td><td>Unicode in UTF-16LE</td></tr>
<tr><td>2</td><td>Unicode in UTF-16BE</td></tr>
<tr><td>3</td><td>Unicode in UTF-8</td></tr>
</table>
<h4 id="fs_rpath">FF_FS_RPATH</h4>
<p>This option configures relative path function. For more information, read <a href="filename.html#nam">here</a>.</p>
<table class="lst1">
<tr><th>Value</th><th>Description</th></tr>
<tr><td>0</td><td>Disable relative path function and remove related functions.</td></tr>
<tr><td>1</td><td>Enable relative path function. <tt>f_chdir</tt> and <tt>f_chdrive</tt> function is available.</td></tr>
<tr><td>2</td><td><tt>f_getcwd</tt> function is available in addition to 1</td></tr>
</table>
</div>
<div class="para doc" id="volume">
<h3>Volume/Drive Configurations</h3>
<h4 id="volumes">FF_VOLUMES</h4>
<p>This option configures number of volumes (logical drives up to 10) to be used.</p>
<h4 id="str_volume_id">FF_STR_VOLUME_ID</h4>
<p>This option switches the support for string volume ID. When arbitrary string for the volume ID is enabled for the drive prefix, also pre-defined strings by <tt>FF_VOLUME_STRS</tt> or user defined strings can be used as drive prefix in the path name. Numeric drive number is always valid regardless of this option, and also either format of drive prefix can be enabled by this option.</p>
<table class="lst2">
<tr><th>Value</th><th>Description</th><th>Example</th></tr>
<tr><td>0</td><td>Only DOS/Windows style drive prefix in numeric ID can be used.</td><td>0:/filename</td></tr>
<tr><td>1</td><td>Also DOS/Windows style drive prefix in string ID can be used.</td><td>flash:/filename</td></tr>
<tr><td>2</td><td>Also Unix style drive prefix in string ID can be used.</td><td>/flash/filename</td></tr>
</table>
<h4 id="volume_strs">FF_VOLUME_STRS</h4>
<p>This option defines the volume ID strings for each logical drives. Number of items must not be less than <tt>FF_VOLUMES</tt>. Valid characters for the volume ID string are A-Z, a-z and 0-9, however, they are compared in case-insensitive. If <tt>FF_STR_VOLUME_ID == 0</tt>, this option has no effect. If <tt>FF_STR_VOLUME_ID &gt;= 1</tt> and this option is not defined, a user defined volume string table needs to be defined as shown below. The table should not be modified on the fly.</p>
<pre>
<span class="c">/* User defined volume ID strings for 0: 1: 2: 3: ... */</span>
const char* VolumeStr[FF_VOLUMES] = {"ram","flash","sdc","usb"};
</pre>
<h4 id="multi_partition">FF_MULTI_PARTITION</h4>
<p>Disable (0) or Enable (1). This option switches multi-partition function. By default (0), each logical drive number is bound to the same physical drive number and only a volume in the physical drive is mounted. When enabled, each logical drive is bound to the partition on the physical drive listed in the user defined partition resolution table <tt>VolToPart[]</tt>. Also <tt>f_fdisk</tt> funciton will be available. For more information, read <a href="filename.html#vol">here</a>.</p>
<h4 id="max_ss">FF_MIN_SS, FF_MAX_SS</h4>
<p>This set of options defines the extent of sector size used for the low level disk I/O interface, <tt>disk_read</tt> and <tt>disk_write</tt> function. Valid values are 512, 1024, 2048 and 4096. <tt>FF_MIN_SS</tt> defines minimum sector size and <tt>FF_MAX_SS</tt> defines the maximum sector size. Always set both 512 for memory card and harddisk. But a larger value may be required for on-board flash memory and some type of optical media. When <tt>FF_MAX_SS &gt; FF_MIN_SS</tt>, support of variable sector size is enabled and <tt>GET_SECTOR_SIZE</tt> command needs to be implemented to the <tt>disk_ioctl</tt> function.</p>
<h4 id="fs_lba64">FF_LBA64</h4>
<p>This option switches media access interface to 64-bit LBA and enables GUID Partition Table (GPT) for partition management, Enabled (1) or Disabled (0). exFAT filesystem needs to be enabled to enable this feature.</p>
<h4 id="fs_gptmin">FF_MIN_GPT</h4>
<p>This option specifies the threshold of determination of partitioning format when create patitions on the drive in <tt>f_mkfs</tt> and <tt>f_fdisk</tt> function. When number of sectors on the drive is equal or larger than this value, the drive will be partitioned in GPT. This option has no effect when <tt>FF_LBA64 == 0</tt>.</p>
<h4 id="use_trim">FF_USE_TRIM</h4>
<p>Disable (0) or Enable (1). This option switches ATA-TRIM function. To enable Trim function, also <tt>CTRL_TRIM</tt> command should be implemented to the <tt>disk_ioctl</tt> function.</p>
</div>
<div class="para doc" id="system">
<h3>System Configurations</h3>
<h4 id="fs_tiny">FF_FS_TINY</h4>
<p>Normal (0) or Tiny (1). The tiny configuration reduces size of the <tt>FIL</tt> structure, file object, <tt>FF_MAX_SS</tt> bytes each. Instead of private sector buffer eliminated from the file object, common sector buffer in the <tt>FATFS</tt> structure, filesystem object, is used for the file data transfer.</p>
<h4 id="fs_exfat">FF_FS_EXFAT</h4>
<p>This option switches support for exFAT filesystem in addition to the FAT/FAT32 filesystem, Enabled (1) or Disabled (0). To enable exFAT, also LFN must be enabled and configureing <tt>FF_LFN_UNICODE &gt;= 1</tt> and <tt>FF_MAX_LFN == 255</tt> is recommended for full-featured exFAT function. Note that enabling exFAT discards ANSI C (C89) compatibility because of need for 64-bit integer type.</p>
<h4 id="fs_nortc">FF_FS_NORTC</h4>
<p>Use RTC (0) or Do not use RTC (1). This option controls timestamp function. If the system does not have any RTC function or valid timestamp is not needed, set <tt>FF_FS_NORTC</tt> to 1 to disable the timestamp function. Every objects modified by FatFs will have a fixed timestamp defined by <tt>FF_NORTC_MON</tt>, <tt>FF_NORTC_MDAY</tt> and <tt>FF_NORTC_YEAR</tt>. To use the timestamp function, set <tt>FF_FS_NORTC == 0</tt> and add <tt>get_fattime</tt> function to the project to get current time form the RTC. This option has no effect at read-only configuration.</p>
<h4 id="nortc_time">FF_NORTC_MON, FF_NORTC_MDAY, FF_NORTC_YEAR</h4>
<p>This set of options defines the time to be used at no RTC systems. This option has no effect at read-only configuration or <tt>FF_FS_NORTC == 0</tt>.</p>
<h4 id="fs_nofsinfo">FF_FS_NOFSINFO</h4>
<p>0 to 3. If you need to know correct free space on the FAT32 volume, set bit 0 of this option, and <tt>f_getfree</tt> function at first time after volume mount will force a full FAT scan. Bit 1 controls the use of last allocated cluster number.</p>
<table class="lst1">
<tr><th>Value</th><th>Description</th></tr>
<tr><td>bit0=0</td><td>Use free cluster count in the FSINFO if available.</td></tr>
<tr><td>bit0=1</td><td>Do not trust free cluster count in the FSINFO.</td></tr>
<tr><td>bit1=0</td><td>Use last allocated cluster number in the FSINFO to find a free cluster if available.</td></tr>
<tr><td>bit1=1</td><td>Do not trust last allocated cluster number in the FSINFO.</td></tr>
</table>
<h4 id="fs_lock">FF_FS_LOCK</h4>
<p>This option switches file lock function to control duplicated file open and illegal operations to open objects. Note that the file lock function is independent of re-entrancy. This option must be 0 at read-only configuration.</p>
<table class="lst1">
<tr><th>Value</th><th>Description</th></tr>
<tr><td>0</td><td>Disable file lock function. To avoid collapsing file by wrong file operation, application program needs to avoid illegal open, remove and rename to the open objects.</td></tr>
<tr><td>&gt;0</td><td>Enable file lock function. The value defines how many files/sub-directories can be opened simultaneously under the file lock control. Illigal operations to the open object will be rejected with <tt>FR_LOCKED</tt>.</td></tr>
</table>
<h4 id="fs_reentrant">FF_FS_REENTRANT</h4>
<p>Disable (0) or Enable (1). This option switches the re-entrancy (thread safe) of the FatFs module itself. Note that file/directory access to the different volume is always re-entrant and it can work simultaneously regardless of this option, however, volume management functions, <tt>f_mount</tt>, <tt>f_mkfs</tt> and <tt>f_fdisk</tt>, are always not re-entrant. Only file/directory access to the same volume, in other words, exclusive use of each filesystem object, is under control of this function. To enable this feature, also user provided synchronization handlers, <tt>ff_req_grant</tt>, <tt>ff_rel_grant</tt>, <tt>ff_del_syncobj</tt> and <tt>ff_cre_syncobj</tt>, need to be added to the project. Sample code is available in <tt>ffsystem.c</tt>.</p>
<h4 id="fs_timeout">FF_FS_TIMEOUT</h4>
<p>Number of time ticks to abort the file function with <tt>FR_TIMEOUT</tt> when wait time is too long. This option has no effect when <tt>FF_FS_REENTRANT == 0</tt>.</p>
<h4 id="sync_t">FF_SYNC_t</h4>
<p>This option defines O/S dependent sync object type. e.g. <tt>HANDLE</tt>, <tt>ID</tt>, <tt>OS_EVENT*</tt>, <tt>SemaphoreHandle_t</tt> and etc. A header file for O/S definitions needs to be included somewhere in the scope of <tt>ff.c</tt>. This option has no effect when <tt>FF_FS_REENTRANT == 0</tt>.</p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,46 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/dinit.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - disk_initialize</title>
</head>
<body>
<div class="para func">
<h2>disk_initialize</h2>
<p>The disk_initialize function is called to initializes the storage device.</p>
<pre>
DSTATUS disk_initialize (
BYTE <span class="arg">pdrv</span> <span class="c">/* [IN] Physical drive number */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameter</h4>
<dl class="par">
<dt>pdrv</dt>
<dd>Physical drive number to identify the target device. Always zero at single drive system.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>This function returns the current drive status flags as the result. For details of the drive status, refer to the <a href="dstat.html">disk_status</a> function.</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>This function initializes the storage device and put it ready to generic read/write. When the function succeeded, <tt>STA_NOINIT</tt> flag in the return value is cleared.</p>
<p><em>Remarks: This function needs to be under control of FatFs module. Application program MUST NOT call this function, or FAT structure on the volume can be broken. To re-initialize the filesystem, use <tt>f_mount</tt> function instead.</em></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,101 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/dioctl.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - disk_ioctl</title>
</head>
<body>
<div class="para func">
<h2>disk_ioctl</h2>
<p>The disk_ioctl function is called to control device specific features and miscellaneous functions other than generic read/write.</p>
<pre>
DRESULT disk_ioctl (
BYTE <span class="arg">pdrv</span>, <span class="c">/* [IN] Drive number */</span>
BYTE <span class="arg">cmd</span>, <span class="c">/* [IN] Control command code */</span>
void* <span class="arg">buff</span> <span class="c">/* [I/O] Parameter and data buffer */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>pdrv</dt>
<dd>Physical drive number to identify the target device.</dd>
<dt>cmd</dt>
<dd>Command code.</dd>
<dt>buff</dt>
<dd>Pointer to the parameter depends on the command code. Do not care if the command has no parameter to be passed.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Value</h4>
<dl class="ret">
<dt>RES_OK (0)</dt>
<dd>The function succeeded.</dd>
<dt>RES_ERROR</dt>
<dd>An error occured.</dd>
<dt>RES_PARERR</dt>
<dd>The command code or parameter is invalid.</dd>
<dt>RES_NOTRDY</dt>
<dd>The device has not been initialized.</dd>
</dl>
</div>
<div class="para desc">
<h4>Description</h4>
<p>The FatFs module requires only five device independent commands described below.</p>
<table class="lst">
<caption>Standard ioctl command used by FatFs</caption>
<tr><th>Command</th><th>Description</th></tr>
<tr><td>CTRL_SYNC</td><td>Makes sure that the device has finished pending write process. If the disk I/O layer or storage device has a write-back cache, the cached data not written back must be flushed to the media immediately. Nothing to do for this command if each write operation to the media is completed within the <tt>disk_write</tt> function.</td></tr>
<tr><td>GET_SECTOR_COUNT</td><td>Retrieves number of available sectors, the largest allowable LBA + 1, on the drive into the <tt>LBA_t</tt> variable pointed by <tt class="arg">buff</tt>. This command is used by <tt>f_mkfs</tt> and <tt>f_fdisk</tt> function to determine the size of volume/partition to be created. It is required when <tt>FF_USE_MKFS == 1</tt>.</td></tr>
<tr><td>GET_SECTOR_SIZE</td><td>Retrieves sector size used for read/write function into the <tt>WORD</tt> variable pointed by <tt class="arg">buff</tt>. Valid sector sizes are 512, 1024, 2048 and 4096. This command is required only if <tt>FF_MAX_SS &gt; FF_MIN_SS</tt>. When <tt>FF_MAX_SS == FF_MIN_SS</tt>, this command will be never used and the read/write function must work in <tt>FF_MAX_SS</tt> bytes/sector only.</td></tr>
<tr><td>GET_BLOCK_SIZE</td><td>Retrieves erase block size of the flash memory media in unit of sector into the <tt>DWORD</tt> variable pointed by <tt class="arg">buff</tt>. The allowable value is 1 to 32768 in power of 2. Return 1 if the erase block size is unknown or non flash memory media. This command is used by only <tt>f_mkfs</tt> function and it attempts to align data area on the erase block boundary. It is required when <tt>FF_USE_MKFS == 1</tt>.</td></tr>
<tr><td>CTRL_TRIM</td><td>Informs the device the data on the block of sectors is no longer needed and it can be erased. The sector block is specified in an <tt>LBA_t</tt> array {&lt;Start LBA&gt;, &lt;End LBA&gt;} pointed by <tt class="arg">buff</tt>. This is an identical command to Trim of ATA device. Nothing to do for this command if this funcion is not supported or not a flash memory device. FatFs does not check the result code and the file function is not affected even if the sector block was not erased well. This command is called on remove a cluster chain and in the <tt>f_mkfs</tt> function. It is required when <tt>FF_USE_TRIM == 1</tt>.</td></tr>
</table>
<p>FatFs never uses any device dependent command nor user defined command. Following table shows an example of non-standard commands which may be useful for some applications.</p>
<table class="lst">
<caption>Example of optional ioctl command</caption>
<tr><th>Command</th><th>Description</th></tr>
<tr><td>CTRL_FORMAT</td><td>Creates a physical format on the media. If <tt class="arg">buff</tt> is not null, it is pointer to the call-back function for progress notification.</td></tr>
<tr><td>CTRL_POWER_IDLE</td><td>Puts the device idle state. <tt>STA_NOINIT</tt> in the current status flags may not be set if the device goes active state by generic read/write function.</td></tr>
<tr><td>CTRL_POWER_OFF</td><td>Puts the device off state. Shut-down the power to the device and deinitialize the device interface if needed. <tt>STA_NOINIT</tt> in the current status flags must be set. The device goes active state by <tt>disk_initialize</tt> function.</td></tr>
<tr><td>CTRL_LOCK</td><td>Locks media eject mechanism.</td></tr>
<tr><td>CTRL_UNLOCK</td><td>Unlocks media eject mechanism.</td></tr>
<tr><td>CTRL_EJECT</td><td>Ejects media cartridge. <tt>STA_NOINIT</tt> and <tt>STA_NODISK</tt> in status flag are set after the function succeeded.</td></tr>
<tr><td>CTRL_GET_SMART</td><td>Reads SMART information.</td></tr>
<tr><td>MMC_GET_TYPE</td><td>Gets card type. The type flags, bit0:MMCv3, bit1:SDv1, bit2:SDv2+ and bit3:LBA, is stored to a BYTE variable pointed by <tt class="arg">buff</tt>. (MMC/SDC specific command)</td></tr>
<tr><td>MMC_GET_CSD</td><td>Reads CSD register into a 16-byte buffer pointed by <tt class="arg">buff</tt>. (MMC/SDC specific command)</td></tr>
<tr><td>MMC_GET_CID</td><td>Reads CID register into a 16-byte buffer pointed by <tt class="arg">buff</tt>. (MMC/SDC specific command)</td></tr>
<tr><td>MMC_GET_OCR</td><td>Reads OCR register into a 4-byte buffer pointed by <tt class="arg">buff</tt>. (MMC/SDC specific command)</td></tr>
<tr><td>MMC_GET_SDSTAT</td><td>Reads SDSTATUS register into a 64-byte buffer pointed by <tt class="arg">buff</tt>. (SDC specific command)</td></tr>
<tr><td>ATA_GET_REV</td><td>Gets the revision string into a 16-byte buffer pointed by <tt class="arg">buff</tt>. (ATA/CFC specific command)</td></tr>
<tr><td>ATA_GET_MODEL</td><td>Gets the model string into a 40-byte buffer pointed by <tt class="arg">buff</tt>. (ATA/CFC specific command)</td></tr>
<tr><td>ATA_GET_SN</td><td>Gets the serial number string into a 20-byte buffer pointed by <tt class="arg">buff</tt>. (ATA/CFC specific command)</td></tr>
<tr><td>ISDIO_READ</td><td>Reads a block of iSDIO registers specified by command structure pointed by <tt class="arg">buff</tt>. (FlashAir specific command)</td></tr>
<tr><td>ISDIO_WRITE</td><td>Writes a block of data to iSDIO registers specified by command structure pointed by <tt class="arg">buff</tt>. (FlashAir specific command)</td></tr>
<tr><td>ISDIO_MRITE</td><td>Changes bits in an iSDIO register specified by command structure pointed by <tt class="arg">buff</tt>. (FlashAir specific command)</td></tr>
</table>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>The disk_ioctl function is not needed when <tt><a href="config.html#fs_readonly">FF_FS_READONLY</a> == 1</tt> and <tt><a href="config.html#max_ss">FF_MAX_SS</a> == <a href="config.html#max_ss">FF_MIN_SS</a></tt>.</p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,73 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/dread.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - disk_read</title>
</head>
<body>
<div class="para func">
<h2>disk_read</h2>
<p>The disk_read function is called to read data from the sector(s) of storage device.</p>
<pre>
DRESULT disk_read (
BYTE <span class="arg">pdrv</span>, <span class="c">/* [IN] Physical drive number */</span>
BYTE* <span class="arg">buff</span>, <span class="c">/* [OUT] Pointer to the read data buffer */</span>
LBA_t <span class="arg">sector</span>, <span class="c">/* [IN] Start sector number */</span>
UINT <span class="arg">count</span> <span class="c">/* [IN] Number of sectros to read */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>pdrv</dt>
<dd>Physical drive number to identify the target device.</dd>
<dt>buff</dt>
<dd>Pointer to the first item of the <em>byte array</em> to store read data. Size of read data will be the sector size * <tt class="arg">count</tt> bytes.</dd>
<dt>sector</dt>
<dd>Start sector number in 32-bit or 64-bit LBA. The data type <tt>LBA_t</tt> is an alias of <tt>DWORD</tt> or <tt>QWORD</tt> depends on the configuration option.</dd>
<dt>count</dt>
<dd>Number of sectors to read.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Value</h4>
<dl class="ret">
<dt>RES_OK (0)</dt>
<dd>The function succeeded.</dd>
<dt>RES_ERROR</dt>
<dd>An unrecoverable hard error occured during the read operation.</dd>
<dt>RES_PARERR</dt>
<dd>Invalid parameter.</dd>
<dt>RES_NOTRDY</dt>
<dd>The device has not been initialized.</dd>
</dl>
</div>
<div class="para desc">
<h4>Description</h4>
<p>Read/write operation to the generic storage devices, such as memory card, hadddisk and optical disk, is done in unit of block of data bytes called <em>sector</em>. FatFs supports the sector size in range of 512 to 4096 bytes. When FatFs is configured for fixed sector size (<tt>FF_MIN_SS == FF_MAX_SS</tt>, this is the most case), the generic read/write function must work at the sector size only. When FatFs is configured for variable sector size (<tt>FF_MIN_SS &lt; FF_MAX_SS</tt>), the sector size of medium is inquired with <tt>disk_ioctl</tt> function after <tt>disk_initialize</tt> function succeeded.</p>
<p>There are some considerations about the memory addres passed via <tt class="arg">buff</tt>. It is not that always aligned with the word boundary because the argument is defined as <tt>BYTE*</tt>. The unaligned transfer request can occure at <a href="appnote.html#fs1">direct transfer</a>. If the bus architecture, especially DMA controller, does not allow unaligned memory access, it should be solved in this function. If it is the case, there are some workarounds described below to avoid this issue.</p>
<ul>
<li>Convert word transfer to byte transfer with some trick in this function. - Recommended.</li>
<li>On the <tt>f_read()</tt> calls, avoid long read request that includes a whole of sector. - Any direct transfer never occures.</li>
<li>On the <tt>f_read(fp, dat, btw, bw)</tt> calls, make sure that <tt>(((UINT)dat &amp; 3) == (f_tell(fp) &amp; 3))</tt> is true. - Word alignment of <tt class="arg">buff</tt> is guaranteed.</li>
</ul>
<p>Also the memory area may be out of reach in DMA. This is the case if it is located on the tightly coupled memory which is usually used for stack. Use double buffered transfer, or avoid to define file I/O buffer, FATFS and FIL structure as local variables where on the stack.</p>
<p>Generally, a multiple sector read request must not be split into single sector transactions to the storage device, or read throughput gets worse.</p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,48 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/dstat.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - disk_status</title>
</head>
<body>
<div class="para func">
<h2>disk_status</h2>
<p>The disk_status function is called to inquire the current drive status.</p>
<pre>
DSTATUS disk_status (
BYTE <span class="arg">pdrv</span> <span class="c">/* [IN] Physical drive number */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameter</h4>
<dl class="par">
<dt>pdrv</dt>
<dd>Physical drive number to identify the target device. Always zero at single drive system.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>The current drive status is returned in combination of status flags described below. FatFs refers only <tt>STA_NOINIT</tt> and <tt>STA_PROTECT</tt>.</p>
<dl class="ret">
<dt>STA_NOINIT</dt>
<dd>Indicates that the device has not been initialized and not ready to work. This flag is set on system reset, media removal or failure of <a href="dinit.html"><tt>disk_initialize</tt></a> function. It is cleared on <tt>disk_initialize</tt> function succeeded. Any media change that occurs asynchronously must be captured and reflect it to the status flags, or auto-mount function will not work correctly. If the system does not support media change detection, application program needs to explicitly re-mount the volume with <tt>f_mount</tt> function after each media change.</dd>
<dt>STA_NODISK</dt>
<dd>Indicates that no medium in the drive. This is always cleared at fixed disk drive. Note that FatFs does not refer this flag.</dd>
<dt>STA_PROTECT</dt>
<dd>Indicates that the medium is write protected. This is always cleared at the drives without write protect function. Not valid if <tt>STA_NODISK</tt> is set.</dd>
</dl>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,76 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/dwrite.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - disk_write</title>
</head>
<body>
<div class="para func">
<h2>disk_write</h2>
<p>The disk_write function is called to write data to the sector(s) of storage device.</p>
<pre>
DRESULT disk_write (
BYTE <span class="arg">pdrv</span>, <span class="c">/* [IN] Physical drive number */</span>
const BYTE* <span class="arg">buff</span>, <span class="c">/* [IN] Pointer to the data to be written */</span>
LBA_t <span class="arg">sector</span>, <span class="c">/* [IN] Sector number to write from */</span>
UINT <span class="arg">count</span> <span class="c">/* [IN] Number of sectors to write */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>pdrv</dt>
<dd>Physical drive number to identify the target device.</dd>
<dt>buff</dt>
<dd>Pointer to the first item of the <em>byte array</em> to be written. The size of data to be written is sector size * <tt class="arg">count</tt> bytes.</dd>
<dt>sector</dt>
<dd>Start sector number in 32-bit or 64-bit LBA. The data type <tt>LBA_t</tt> is an alias of <tt>DWORD</tt> or <tt>QWORD</tt> depends on the configuration option.</dd>
<dt>count</dt>
<dd>Number of sectors to write.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<dl class="ret">
<dt>RES_OK (0)</dt>
<dd>The function succeeded.</dd>
<dt>RES_ERROR</dt>
<dd>An unrecoverable hard error occured during the write operation.</dd>
<dt>RES_WRPRT</dt>
<dd>The medium is write protected.</dd>
<dt>RES_PARERR</dt>
<dd>Invalid parameter.</dd>
<dt>RES_NOTRDY</dt>
<dd>The device has not been initialized.</dd>
</dl>
</div>
<div class="para desc">
<h4>Description</h4>
<p>The specified memory address is not that always aligned to word boundary because the argument is defined as <tt>BYTE*</tt>. For more information, refer to the description of <a href="dread.html"><tt>disk_read</tt></a> function.</p>
<p>Generally, a multiple sector write request (<tt class="arg">count</tt><tt> &gt; 1</tt>) must not be split into single sector transactions to the storage device, or the file write throughput will be drastically decreased.</p>
<p>FatFs expects delayed write function of the disk control layer. The write operation to the media does not need to be completed at return from this function by what write operation is in progress or data is only stored into the write-back cache. But write data on the <tt class="arg">buff</tt> is invalid after return from this function. The write completion request is done by <tt>CTRL_SYNC</tt> command of <tt><a href="dioctl.html">disk_ioctl</a></tt> function. Therefore, if a delayed write function is implemented, the write throughput of the filesystem will be improved.</p>
<p><em>Remarks: Application program MUST NOT call this function, or FAT structure on the volume can be collapsed.</em></p>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>This function is not needed when <tt><a href="config.html#fs_readonly">FF_FS_READONLY</a> == 1</tt>.</p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,62 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/eof.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_eof</title>
</head>
<body>
<div class="para func">
<h2>f_eof</h2>
<p>The f_eof function tests for end-of-file on a file.</p>
<pre>
int f_eof (
FIL* <span class="arg">fp</span> <span class="c">/* [IN] File object */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>fp</dt>
<dd>Pointer to the open file object structure.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>The <tt>f_eof</tt> function returns a non-zero value if the read/write pointer has reached end of the file; otherwise it returns a zero.</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>In this revision, this function is implemented as a macro. It does not have any validation and mutual exclusion.</p>
<pre>
<span class="k">#define</span> f_eof(fp) ((int)((fp)->fptr == (fp)->fsize))
</pre>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>Always available.</p>
</div>
<div class="para ref">
<h4>See Also</h4>
<p><tt><a href="open.html">f_open</a>, <a href="lseek.html">f_lseek</a>, <a href="sfile.html">FIL</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,62 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/error.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_error</title>
</head>
<body>
<div class="para func">
<h2>f_error</h2>
<p>The f_error tests for an error on a file.</p>
<pre>
int f_error (
FIL* <span class="arg">fp</span> <span class="c">/* [IN] File object */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>fp</dt>
<dd>Pointer to the open file object structure.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>Returns a non-zero value if a hard error has occured; otherwise it returns a zero.</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>In this revision, this function is implemented as a macro. It does not have any validation and mutual exclusion.</p>
<pre>
<span class="k">#define</span> f_error(fp) ((fp)->err)
</pre>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>Always available.</p>
</div>
<div class="para ref">
<h4>See Also</h4>
<p><tt><a href="open.html">f_open</a>, <a href="sfile.html">FIL</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,117 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/lseek.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_expand</title>
</head>
<body>
<div class="para func">
<h2>f_expand</h2>
<p>The f_expand function prepares or allocates a contiguous data area to the file.</p>
<pre>
FRESULT f_expand (
FIL* <span class="arg">fp</span>, <span class="c">/* [IN] File object */</span>
FSIZE_t <span class="arg">fsz</span>, <span class="c">/* [IN] File size expanded to */</span>
BYTE <span class="arg">opt</span> <span class="c">/* [IN] Allocation mode */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>fp</dt>
<dd>Pointer to the open file object.</dd>
<dt>fsz</dt>
<dd>Number of bytes in size to prepare or allocate for the file. The data type <tt>FSIZE_t</tt> is an alias of either <tt>DWORD</tt>(32-bit) or <tt>QWORD</tt>(64-bit) depends on the configuration option <tt>FF_FS_EXFAT</tt>.</dd>
<dt>opt</dt>
<dd>Allocation mode. Prepare to allocate (0) or Allocate now (1).</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>
<a href="rc.html#ok">FR_OK</a>,
<a href="rc.html#de">FR_DISK_ERR</a>,
<a href="rc.html#ie">FR_INT_ERR</a>,
<a href="rc.html#io">FR_INVALID_OBJECT</a>,
<a href="rc.html#dn">FR_DENIED</a>,
<a href="rc.html#tm">FR_TIMEOUT</a>
</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>The <tt>f_expand</tt> function prepares or allocates a contiguous data area to the file. When <tt class="arg">opt</tt> is 1, the function allocates a contiguous data area to the file. Unlike expansion of file size by <tt>f_lseek</tt> function, the file must be truncated prior to use this function and read/write pointer of the file stays at offset 0 after the function call. The file content allocated with this function is <em>undefined</em> because no data is written to the file in this process. The function can fail with <tt>FR_DENIED</tt> due to some reasons below.</p>
<ul>
<li>No free contiguous space was found.</li>
<li>Size of the file was not zero.</li>
<li>The file has been opened in read-only mode.</li>
<li>Not allowable file size. (&gt;= 4 GB on FAT volume)</li>
</ul>
<p>When <tt class="arg">opt</tt> is 0, the function finds a contiguous data area and set it as suggested point for allocation. The subsequent cluster allocation begins at top of the contiguous area found by this function. Thus the write file is guaranteed be contiguous and without allocation delay until the file size reaches that size unless any other changes to the volume is performed.</p>
<p>The contiguous file has an advantage at time-critical read/write operations. It eliminates some overheads in the filesystem and the storage device caused by random access due to fragmented file data.</p>
<p>Also the contiguous file can be easily accessed directly via low-level disk functions. But this is not recommended in consideration for portability and future compatibility. If the file is not confirmed be contiguous, use <a href="../res/app5.c">this function</a> to examine if it is contiguous or not.</p>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>Available when <tt>FF_USE_EXPAND == 1</tt> and <tt>FF_FS_READONLY == 0</tt>.</p>
</div>
<div class="para use">
<h4>Example</h4>
<pre>
<span class="c">/* Creating a contiguous file */</span>
<span class="c">/* Create a new file */</span>
res = f_open(fp = malloc(sizeof (FIL)), "file.dat", FA_WRITE|FA_CREATE_ALWAYS);
if (res) { <span class="c">/* Check if the file has been opened */</span>
free(fp);
die("Failed to open the file.");
}
<span class="c">/* Alloacte a 100 MiB of contiguous area to the file */</span>
res = <em>f_expand</em>(fp, 104857600, 1);
if (res) { <span class="c">/* Check if the file has been expanded */</span>
f_close(fp);
free(fp);
die("Failed to allocate contiguous area.");
}
<span class="c">/* Now you have a contiguous file accessible with fp */</span>
</pre>
<pre>
<span class="c">/* Accessing the contiguous file via low-level disk functions */</span>
<span class="c">/* Get physical location of the file data */</span>
drv = fp-&gt;obj.fs-&gt;pdrv;
lba = fp-&gt;obj.fs-&gt;database + fp-&gt;obj.fs-&gt;csize * (fp-&gt;obj.sclust - 2);
<span class="c">/* Write 2048 sectors from top of the file at a time */</span>
res = disk_write(drv, buffer, lba, 2048);
</pre>
</div>
<div class="para ref">
<h4>See Also</h4>
<p><tt><a href="open.html">f_open</a>, <a href="lseek.html">f_lseek</a>, <a href="sfile.html">FIL</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,57 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/fattime.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - get_fattime</title>
</head>
<body>
<div class="para func">
<h2>get_fattime</h2>
<p>The get_fattime function is called to get the current time.</p>
<pre>
DWORD get_fattime (void);
</pre>
</div>
<div class="para ret">
<h4>Return Value</h4>
<p>Currnet local time shall be returned as bit-fields packed into a <tt>DWORD</tt> value. The bit fields are as follows:</p>
<dl class="ret">
<dt>bit31:25</dt>
<dd>Year origin from the 1980 (0..127, e.g. 37 for 2017)</dd>
<dt>bit24:21</dt>
<dd>Month (1..12)</dd>
<dt>bit20:16</dt>
<dd>Day of the month (1..31)</dd>
<dt>bit15:11</dt>
<dd>Hour (0..23)</dd>
<dt>bit10:5</dt>
<dd>Minute (0..59)</dd>
<dt>bit4:0</dt>
<dd>Second / 2 (0..29, e.g. 25 for 50)</dd>
</dl>
</div>
<div class="para desc">
<h4>Description</h4>
<p>The <tt>get_fattime</tt> function shall return any valid time even if the system does not support a real time clock. If a zero is returned, the file will not have a valid timestamp.</p>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>This function is not needed when <tt>FF_FS_READONLY == 1</tt> or <tt>FF_FS_NORTC == 1</tt>.</p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,95 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/fdisk.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_fdisk</title>
</head>
<body>
<div class="para func">
<h2>f_fdisk</h2>
<p>The f_fdisk fucntion divides a physical drive.</p>
<pre>
FRESULT f_fdisk (
BYTE <span class="arg">pdrv</span>, <span class="c">/* [IN] Physical drive number */</span>
const LBA_t <span class="arg">ptbl[]</span>, <span class="c">/* [IN] Partition map table */</span>
void* <span class="arg">work</span> <span class="c">/* [IN] Work area */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>pdrv</dt>
<dd>Specifies the <em>physical drive</em> to be divided. This is not the logical drive number but the drive identifier passed to the low level disk functions.</dd>
<dt>ptbl</dt>
<dd>List of partitions to create on the drive. The data type <tt>LBA_t</tt> is alias of <tt>DWORD</tt> or <tt>QWORD</tt> depends on the configuration option <tt><a href="config.html#fs_lba64">FF_LBA64</a></tt>.</dd>
<dt>work</dt>
<dd>Pointer to the function work area. The size must be at least <tt><a href="config.html#max_ss">FF_MAX_SS</a></tt> bytes. When a null pointer is given with <tt><a href="config.html#use_lfn">FF_USE_LFN</a> = 3</tt>, a memory block is obtained in this function for the working buffer.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>
<a href="rc.html#ok">FR_OK</a>,
<a href="rc.html#de">FR_DISK_ERR</a>,
<a href="rc.html#nr">FR_NOT_READY</a>,
<a href="rc.html#wp">FR_WRITE_PROTECTED</a>,
<a href="rc.html#ip">FR_INVALID_PARAMETER</a>,
<a href="rc.html#nc">FR_NOT_ENOUGH_CORE</a>
</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>The <tt>f_fdisk</tt> function creates partitions on the physical drive. The partitioning format can be in generic MBR or GPT. The partition map table specifies how to divide the physical drive. The first item specifies the size of the first partition and the partitions are located on the drive in order of from the first item. When the value of item is less than or equal to 100, it specifies the partition size in percentage of the entire drive space. When it is larger than 100, it specifies number of sectors. The partition map table is terminated by a zero, no space is remaining for next allocation or 4th partition is created in MBR format. If the specified size is larger than remaining space on the drive, the partition is clipped at the size of remaining space.</p>
<p>By default, partitions are created in MBR format. It can create upto four primary partitions on a drive. GPT format is used to create the partitions when 64-bit LBA is enabled (<tt>FF_LBA64 = 1</tt>) and the drive size is equal to or larger than <tt><a href="config.html#fs_gptmin">FF_MIN_GPT</a></tt> sectors. It can create over ten partitions on a drive.</p>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>Available when <tt><a href="config.html#fs_readonly">FF_FS_READOLNY</a> == 0</tt>, <tt><a href="config.html#use_mkfs">FF_USE_MKFS</a> == 1</tt> and <tt><a href="config.html#multi_partition">FF_MULTI_PARTITION</a> == 1</tt>.</p>
</div>
<div class="para use">
<h4>Example</h4>
<pre>
<span class="c">/* Volume mapping table defined by user (required when FF_MULTI_PARTITION == 1) */</span>
PARTITION VolToPart[FF_VOLUMES] = {
{0, 1}, <span class="c">/* "0:" ==> Physical drive 0, 1st partition */</span>
{0, 2}, <span class="c">/* "1:" ==> Physical drive 0, 2nd partition */</span>
{1, 0} <span class="c">/* "2:" ==> Physical drive 1, auto detection */</span>
};
</pre>
<pre>
<span class="c">/* Initialize a brand-new disk drive mapped to physical drive 0 */</span>
BYTE work[FF_MAX_SS]; <span class="c">/* Working buffer */</span>
LBA_t plist[] = {50, 50, 0}; <span class="c">/* Divide the drive into two partitions */</span>
<span class="c">/* {0x10000000, 100}; 256M sectors for 1st partition and left all for 2nd partition */</span>
<span class="c">/* {20, 20, 20, 0}; 20% for 3 partitions each and remaing space is left not allocated */</span>
<em>f_fdisk</em>(0, plist, work); <span class="c">/* Divide physical drive 0 */</span>
f_mkfs("0:", 0, work, sizeof work); <span class="c">/* Create FAT volume on the logical drive 0 */</span>
f_mkfs("1:", 0, work, sizeof work); <span class="c">/* Create FAT volume on the logical drive 1 */</span>
</pre>
</div>
<div class="para ref">
<h4>See Also</h4>
<p><a href="filename.html#vol">Volume management</a>, <a href="mkfs.html"><tt>f_mkfs</tt></a></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,91 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/filename.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - Path Names</title>
</head>
<body>
<h1>Path Names on the FatFs API</h1>
<div class="para doc" id="nam">
<h3>Format of the Path Names</h3>
<p>The format of path name on the FatFs module is similer to the filename specs of DOS/Windos as follows:</p>
<pre>[<em>drive#</em>:][/]<em>directory</em>/<em>file</em></pre>
<p>The FatFs module supports long file name (LFN) and 8.3 format file name (SFN). The LFN can be used when <tt><a href="config.html#use_lfn">FF_USE_LFN</a> &gt;= 1</tt>. The sub-directories are separated with a <tt>\</tt> or <tt>/</tt> as the same way as DOS/Windows API. Duplicated separators are skipped and ignored. Only a difference is that the heading drive prefix to specify the logical drive number is in a numeral (0-9) + a colon, while it is an alphabet (A-Z) + a colon in DOS/Windows. The logical drive number is identifier to specify the FAT volume to be accessed. When drive prefix is omitted, the logical drive number is assumed as <em>default drive</em>.</p>
<p>Control characters (<tt>\0</tt> to <tt>\x1F</tt>) are recognized as end of the path name. Leading/embedded white spaces in the path name are valid as a part of the name in LFN configuration but the white space is recognized as end of the path name in non-LFN configuration. Trailing white spaces and dots are ignored in both configurations.</p>
<p>In default configuration (<tt><a href="config.html#fs_rpath">FF_FS_RPATH</a> == 0</tt>), it does not have a concept of current directory like OS oriented filesystem. Every object on the volume is always specified in full path name that followed from the root directory. Dot directory names (<tt>".", ".."</tt>) are not allowed. Heading separator is ignored and it can be exist or omitted. The default drive is fixed to drive 0.</p>
<p>When relative path is enabled (<tt>FF_FS_RPATH &gt;= 1</tt>), specified path is followed from the root directory if a heading separator is exist. If not, it is followed from the current directory of the drive set by <a href="chdir.html"><tt>f_chdir</tt></a> function. Dot names are also allowed for the path names. The default drive is the current drive set by <a href="chdrive.html"><tt>f_chdrive</tt></a> function.</p>
<table class="lst2">
<tr><td>Path name</td><td>FF_FS_RPATH == 0</td><td>FF_FS_RPATH &gt;= 1</td></tr>
<tr class="lst3"><td>file.txt</td><td>A file in the root directory of the drive 0</td><td>A file in the current directory of the current drive</td></tr>
<tr><td>/file.txt</td><td>A file in the root directory of the drive 0</td><td>A file in the root directory of the current drive</td></tr>
<tr><td></td><td>The root directory of the drive 0</td><td>The current directory of the current drive</td></tr>
<tr><td>/</td><td>The root directory of the drive 0</td><td>The root directory of the current drive</td></tr>
<tr><td>2:</td><td>The root directory of the drive 2</td><td>The current directory of the drive 2</td></tr>
<tr><td>2:/</td><td>The root directory of the drive 2</td><td>The root directory of the drive 2</td></tr>
<tr><td>2:file.txt</td><td>A file in the root directory of the drive 2</td><td>A file in the current directory of the drive 2</td></tr>
<tr><td>../file.txt</td><td>Invalid name</td><td>A file in the parent directory</td></tr>
<tr><td>.</td><td>Invalid name</td><td>This directory</td></tr>
<tr><td>..</td><td>Invalid name</td><td>Parent directory of the current directory (*)</td></tr>
<tr><td>dir1/..</td><td>Invalid name</td><td>The current directory</td></tr>
<tr><td>/..</td><td>Invalid name</td><td>The root directory (sticks the top level)</td></tr>
</table>
<p>Also the drive prefix can be in pre-defined arbitrary string. When the option <tt><a href="config.html#str_volume_id">FF_STR_VOLUME_ID</a> == 1</tt>, also arbitrary string volume ID can be used as drive prefix. e.g. <tt>"flash:file1.txt"</tt>, <tt>"ram:temp.dat"</tt> or <tt>"sd:"</tt>. When <tt>FF_STR_VOLUME_ID == 2</tt>, Unix style drive prefix can be used. e.g. <tt>"/flash/file1.txt"</tt>, <tt>"/ram/temp.dat"</tt> or <tt>"/usb"</tt>. However, it cannot traverse the drives such as <tt>"/flash/../ram/temp.dat"</tt>. The Unix style drive prefix may lead a confusion in identification between volume ID and file name. For instance, which does <tt>"/flash"</tt> mean, a file <tt>"flash"</tt> on the root directory without drive prefix or a drive prefix of <tt>"flash"</tt>? If the string following a heading slash matches with any volume ID, it is treated as a drive prefix.</p>
<p><em>Remark: In this revision, double dot name <tt>".."</tt> cannot follow the parent directory on the exFAT volume. It will work as <tt>"."</tt> and stay there.</em></p>
</div>
<div class="para doc" id="case">
<h3>Legal Characters and Case Sensitivity</h3>
<p>On the FAT filesystem, legal characters for object name (file/directory name) are, <tt>0-9 A-Z ! # $ % &amp; ' ( ) - @ ^ _ ` { } ~</tt> and any extended character. The valid character codes of extended characters are depends on the configured code page. Under LFN supported system, also <tt>+ , ; = [ ]</tt> and white space are legal for the object name and the white spaces and dots can be placed anywhere in the path name except end of the name.</p>
<p>FAT filesystem is case-insensitive to the object names on the volume. Object name on the FAT volume is compared in case-insensitive. For instance, these three names, <tt>file.txt</tt>, <tt>File.Txt</tt> and <tt>FILE.TXT</tt>, are identical. This is applied to extended charactres as well. When an object is created on the FAT volume, up converted name is recorded to the SFN entry, and the raw name is recorded to the LFN entry when LFN function is enabled.</p>
<p>As for the MS-DOS and PC DOS for CJK (DOS/DBCS), extended characters ware recorded to the SFN entry without up-case conversion and compared in case-sensitive. This causes a problem on compatibility with Windows system when any object with extended characters is created on the volume by DOS/DBCS system; therfore the object names with DBCS extended characters should not be used on the FAT volume shared by those systems. FatFs works with case-sensitive to the extended characters in only non-LFN with DBCS configuration (DOS/DBCS specs). But in LFN configuration, FatFs works with case-insensitive to the extended character (WindowsNT specs).</p>
</div>
<div class="para doc" id="uni">
<h3>Unicode API</h3>
<p>The path names are input/output in either ANSI/OEM code or Unicode depends on the configuration options. The type of arguments which specifies the path names is defined as <tt>TCHAR</tt>. It is an alias of <tt>char</tt> by default and the code set used for the path name string is ANSI/OEM specifid by <tt><a href="config.html#code_page">FF_CODE_PAGE</a></tt>. When <tt><a href="config.html#lfn_unicode">FF_LFN_UNICODE</a></tt> is set to 1 or larger, the type of the <tt>TCHAR</tt> is switched to proper type to support the Unicode string. When Unicode API is specified by this option, the full-featured LFN specification is supported and the Unicode specific characters, such as ✝☪✡☸☭, can also be used for the path name. It also affects data types and encoding of the string I/O functions. To define literal strings, <tt>_T(s)</tt> and <tt>_TEXT(s)</tt> macro are available to specify the string in proper type. The code shown below is an example to define the literal strings.</p>
<pre>
f_open(fp, <span class="e">"filename.txt"</span>, FA_READ); <span class="c">/* ANSI/OEM string (char) */</span>
f_open(fp, <span class="e">L"filename.txt"</span>, FA_READ); <span class="c">/* UTF-16 string (WCHAR) */</span>
f_open(fp, <span class="e">u8"filename.txt"</span>, FA_READ); <span class="c">/* UTF-8 string (char) */</span>
f_open(fp, <span class="e">U"filename.txt"</span>, FA_READ); <span class="c">/* UTF-32 string (DWORD) */</span>
f_open(fp, <span class="e">_T("filename.txt")</span>, FA_READ); <span class="c">/* Changed by configuration (TCHAR) */</span>
</pre>
</div>
<div class="para doc" id="vol">
<h3>Volume Management</h3>
<p>By default, each logical drive is associated with the physical drive in same drive number. An FAT volume on the physical drive is serched by the volume mount process. It reads boot sectors and checks it if it is an FAT boot sector in order of LBA 0 as SFD format, 1st partition, 2nd partition, 3rd partition, ..., as MBR or GPT format.</p>
<p>When multiple partition feature is enabled, <tt><a href="config.html#multi_partition">FF_MULTI_PARTITION = 1</a></tt>, each individual logical drive is associated with arbitrary partition or drive specified by volume management table, <tt>VolToPart[]</tt>. The table needs to be defined by user to resolve the mappings of logical drives and partitions. Following code is an example of a volume management table.</p>
<pre>
Example: "0:", "1:" and "2:" are associated with three partitions on the physical drive 0 (fixed drive)
"3:" is associated with physical drive 1 (removable drive)
PARTITION VolToPart[FF_VOLUMES] = {
{0, 1}, <span class="c">/* "0:" ==> 1st partition of physical drive 0 */</span>
{0, 2}, <span class="c">/* "1:" ==> 2nd partition of physical drive 0 */</span>
{0, 3}, <span class="c">/* "2:" ==> 3rd partition of physical drive 0 */</span>
{1, 0} <span class="c">/* "3:" ==> Physical drive 1 */</span>
};
</pre>
<div><img src="../res/f7.png" width="900" height="288" alt="relationship between logical drive and physical drive"></div>
<p>There are some considerations on using multi-partition configuration.</p>
<ul>
<li>The physical drive that hosts two or more mounted partitions must be non-removable, or all volumes on the drive must be unmounted when remove the medium.</li>
<li>When make any change to the <tt>VolToPart[]</tt>, corresponding volume should be unmounted prior to make change the item.</li>
<li>On the MBR format drive, up to four primary partitions (1-4) can be specified. The partition 1 specifies the first item in the partition table and the partition 2 specifies the second one, and so on. Logical patitions in the extended partition is not supported.</li>
<li>On the GPT format drive, there is no limitation. The partition 1 specifies the first Microsoft basic data partition found in the partition table and the partition 2 specifies the second one found, and so on.</li>
<li>Windows does not support multiple volumes on the storage with removable class. Only the first parition found on the drive will be mounted.</li>
<li>For further information, refer to <tt><a href="fdisk.html">f_fdisk</a></tt> and <tt><a href="mkfs.html">f_mkfs</a></tt>function.</li>
</ul>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,111 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/findfirst.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_findfirst</title>
</head>
<body>
<div class="para func">
<h2>f_findfirst</h2>
<p>The f_findfirst function searches a directroy for an item.</p>
<pre>
FRESULT f_findfirst (
DIR* <span class="arg">dp</span>, <span class="c">/* [OUT] Poninter to the directory object */</span>
FILINFO* <span class="arg">fno</span>, <span class="c">/* [OUT] Pointer to the file information structure */</span>
const TCHAR* <span class="arg">path</span>, <span class="c">/* [IN] Pointer to the directory name to be opened */</span>
const TCHAR* <span class="arg">pattern</span> <span class="c">/* [IN] Pointer to the matching pattern string */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>dp</dt>
<dd>Pointer to the blank directory object.</dd>
<dt>fno</dt>
<dd>Pointer to the <a href="sfileinfo.html">file information structure</a> to store the information about the found item.</dd>
<dt>path</dt>
<dd>Pointer to the null-terminated string that specifies the <a href="filename.html">directory name</a> to be opened.</dd>
<dt>pattern</dt>
<dd>Pointer to the nul-terminated string that specifies the name matching pattern to be searched for. It is referred by also subsequent <tt>f_findnext</tt> function, so that the string must be valid while the successive function calls.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>
<a href="rc.html#ok">FR_OK</a>,
<a href="rc.html#de">FR_DISK_ERR</a>,
<a href="rc.html#ie">FR_INT_ERR</a>,
<a href="rc.html#nr">FR_NOT_READY</a>,
<a href="rc.html#np">FR_NO_PATH</a>,
<a href="rc.html#in">FR_INVALID_NAME</a>,
<a href="rc.html#io">FR_INVALID_OBJECT</a>,
<a href="rc.html#id">FR_INVALID_DRIVE</a>,
<a href="rc.html#ne">FR_NOT_ENABLED</a>,
<a href="rc.html#ns">FR_NO_FILESYSTEM</a>,
<a href="rc.html#tm">FR_TIMEOUT</a>,
<a href="rc.html#nc">FR_NOT_ENOUGH_CORE</a>,
<a href="rc.html#tf">FR_TOO_MANY_OPEN_FILES</a>
</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>After the directory specified by <tt class="arg">path</tt> could be opened, it starts to search the directory for items with the name specified by <tt class="arg">pattern</tt>. If the first item is found, the information about the object is stored into the file information structure <tt class="arg">fno</tt>.</p>
<p>The matching pattern can contain wildcard characters (<tt>?</tt> and <tt>*</tt>). A <tt>?</tt> matches an any character and an <tt>*</tt> matches an any string in length of zero or longer. When support of long file name is enabled, only <tt>fname[]</tt> is tested at <tt>FF_USE_FIND == 1</tt> and also <tt>altname[]</tt> is tested at <tt>FF_USE_FIND == 2</tt>. In this revision, there are some differences listed below between FatFs and standard systems in matching condition.</p>
<ul>
<li><tt>"*.*"</tt> never matches any name without extension while it matches any name with or without extension at the standard systems.</li>
<li>Any pattern terminated with a period never matches any name while it matches the name without extensiton at the standard systems.</li>
<li><a href="filename.html#case">DBCS extended characters</a> are compared in case-sensitive at LFN with ANSI/OEM API.</li>
</ul>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>This is a wrapper function of <a href="opendir.html"><tt>f_opendir</tt></a> and <a href="readdir.html"><tt>f_readdir</tt></a> function. Available when <tt><a href="config.html#use_find">FF_USE_FIND</a> &gt;= 1</tt> and <tt><a href="config.html#fs_minimize">FF_FS_MINIMIZE</a> &lt;= 1</tt>.</p>
</div>
<div class="para use">
<h4>Examples</h4>
<pre>
<span class="c">/* Search a directory for objects and display it */</span>
void find_image_file (void)
{
FRESULT fr; <span class="c">/* Return value */</span>
DIR dj; <span class="c">/* Directory search object */</span>
FILINFO fno; <span class="c">/* File information */</span>
fr = <em>f_findfirst</em>(&amp;dj, &amp;fno, "", "dsc*.jpg"); <span class="c">/* Start to search for photo files */</span>
while (fr == FR_OK &amp;&amp; fno.fname[0]) { <span class="c">/* Repeat while an item is found */</span>
printf("%s\n", fno.fname); <span class="c">/* Display the object name */</span>
fr = f_findnext(&amp;dj, &amp;fno); <span class="c">/* Search for next item */</span>
}
f_closedir(&amp;dj);
}
</pre>
</div>
<div class="para ref">
<h4>See Also</h4>
<p><tt><a href="findnext.html">f_findnext</a>, <a href="closedir.html">f_closedir</a>, <a href="sdir.html">DIR</a>, <a href="sfileinfo.html">FILINFO</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,69 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/findnext.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_findnext</title>
</head>
<body>
<div class="para func">
<h2>f_findnext</h2>
<p>The f_findnext function searches for a next matched object</p>
<pre>
FRESULT f_findnext (
DIR* <span class="arg">dp</span>, <span class="c">/* [IN] Poninter to the directory object */</span>
FILINFO* <span class="arg">fno</span> <span class="c">/* [OUT] Pointer to the file information structure */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>dp</dt>
<dd>Pointer to the valid directory object created by <tt>f_findfirst</tt> function.</dd>
<dt>fno</dt>
<dd>Pointer to the file information structure to store the information about the found directory item.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>
<a href="rc.html#ok">FR_OK</a>,
<a href="rc.html#de">FR_DISK_ERR</a>,
<a href="rc.html#ie">FR_INT_ERR</a>,
<a href="rc.html#nr">FR_NOT_READY</a>,
<a href="rc.html#io">FR_INVALID_OBJECT</a>,
<a href="rc.html#tm">FR_TIMEOUT</a>,
<a href="rc.html#nc">FR_NOT_ENOUGH_CORE</a>
</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>It continues the search from a previous call to the <tt>f_findfirst</tt> or <tt>f_findnext</tt> function. If found, the information about the object is stored into the file information structure. If no item to be read, a null string will be returned into <tt>fno-&gt;fname[]</tt>.</p>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>This is a wrapper function of <a href="readdir.html"><tt>f_readdir</tt></a> function. Available when <tt><a href="config.html#use_find">FF_USE_FIND</a> == 1</tt> and <tt><a href="config.html#fs_minimize">FF_FS_MINIMIZE</a> &lt;= 1</tt>.</p>
</div>
<div class="para ref">
<h4>See Also</h4>
<p><tt><a href="findfirst.html">f_findfirst</a>, <a href="closedir.html">f_closedir</a>, <a href="sdir.html">DIR</a>, <a href="sfileinfo.html">FILINFO</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,139 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/forward.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_forward</title>
</head>
<body>
<div class="para func">
<h2>f_forward</h2>
<p>The f_forward function reads the file data and forward it to the data streaming device.</p>
<pre>
FRESULT f_forward (
FIL* <span class="arg">fp</span>, <span class="c">/* [IN] File object */</span>
UINT (*<span class="arg">func</span>)(const BYTE*,UINT), <span class="c">/* [IN] Data streaming function */</span>
UINT <span class="arg">btf</span>, <span class="c">/* [IN] Number of bytes to forward */</span>
UINT* <span class="arg">bf</span> <span class="c">/* [OUT] Number of bytes forwarded */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>fp</dt>
<dd>Pointer to the open file object.</dd>
<dt>func</dt>
<dd>Pointer to the user-defined data streaming function. For details, refer to the sample code.</dd>
<dt>btf</dt>
<dd>Number of bytes to forward in range of <tt>UINT</tt>.</dd>
<dt>bf</dt>
<dd>Pointer to the <tt>UINT</tt> variable to return number of bytes forwarded.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>
<a href="rc.html#ok">FR_OK</a>,
<a href="rc.html#de">FR_DISK_ERR</a>,
<a href="rc.html#ie">FR_INT_ERR</a>,
<a href="rc.html#io">FR_INVALID_OBJECT</a>,
<a href="rc.html#dn">FR_DENIED</a>,
<a href="rc.html#tm">FR_TIMEOUT</a>
</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>The <tt>f_forward</tt> function reads the data from the file and forward it to the outgoing stream without data buffer. This is suitable for small memory system because it does not require any data buffer at application module. The file pointer of the file object increases in number of bytes forwarded. In case of <tt class="arg">*bf</tt> is less than <tt class="arg">btf</tt> without error, it means the requested bytes could not be transferred due to end of file or stream goes busy during data transfer.</p>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>Available when <tt><a href="config.html#use_forward">FF_USE_FORWARD</a> == 1</tt>.</p>
</div>
<div class="para use">
<h4>Example (Audio playback)</h4>
<pre>
<span class="c">/*------------------------------------------------------------------------*/</span>
<span class="c">/* Sample code of data transfer function to be called back from f_forward */</span>
<span class="c">/*------------------------------------------------------------------------*/</span>
UINT out_stream ( <span class="c">/* Returns number of bytes sent or stream status */</span>
const BYTE *p, <span class="c">/* Pointer to the data block to be sent */</span>
UINT btf <span class="c">/* &gt;0: Transfer call (Number of bytes to be sent). 0: Sense call */</span>
)
{
UINT cnt = 0;
if (btf == 0) { <span class="c">/* Sense call */</span>
<span class="c">/* Return stream status (0: Busy, 1: Ready) */</span>
<span class="c">/* When once it returned ready to sense call, it must accept a byte at least */</span>
<span class="c">/* at subsequent transfer call, or f_forward will fail with FR_INT_ERR. */</span>
if (FIFO_READY) cnt = 1;
}
else { <span class="c">/* Transfer call */</span>
do { <span class="c">/* Repeat while there is any data to be sent and the stream is ready */</span>
FIFO_PORT = *p++;
cnt++;
} while (cnt &lt; btf &amp;&amp; FIFO_READY);
}
return cnt;
}
<span class="c">/*------------------------------------------------------------------------*/</span>
<span class="c">/* Sample code using f_forward function */</span>
<span class="c">/*------------------------------------------------------------------------*/</span>
FRESULT play_file (
char *fn <span class="c">/* Pointer to the audio file name to be played */</span>
)
{
FRESULT rc;
FIL fil;
UINT dmy;
<span class="c">/* Open the audio file in read only mode */</span>
rc = f_open(&amp;fil, fn, FA_READ);
if (rc) return rc;
<span class="c">/* Repeat until the file pointer reaches end of the file */</span>
while (rc == FR_OK &amp;&amp; !f_eof(&amp;fil)) {
<span class="c">/* some processes... */</span>
<span class="c">/* Fill output stream periodicaly or on-demand */</span>
rc = <em>f_forward</em>(&amp;fil, out_stream, 1000, &amp;dmy);
}
<span class="c">/* Close the file and return */</span>
f_close(&amp;fil);
return rc;
}
</pre>
</div>
<div class="para ref">
<h4>See Also</h4>
<p><tt><a href="open.html">f_open</a>, <a href="gets.html">fgets</a>, <a href="write.html">f_write</a>, <a href="close.html">f_close</a>, <a href="sfile.html">FIL</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,83 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/getcwd.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_getcwd</title>
</head>
<body>
<div class="para func">
<h2>f_getcwd</h2>
<p>The f_getcwd function retrieves the current directory of the current drive.</p>
<pre>
FRESULT f_getcwd (
TCHAR* <span class="arg">buff</span>, <span class="c">/* [OUT] Buffer to return path name */</span>
UINT <span class="arg">len</span> <span class="c">/* [IN] The length of the buffer */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>buff</dt>
<dd>Pointer to the buffer to receive the current directory string.</dd>
<dt>len</dt>
<dd>Size of the buffer in unit of <tt>TCHAR</tt>.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>
<a href="rc.html#ok">FR_OK</a>,
<a href="rc.html#de">FR_DISK_ERR</a>,
<a href="rc.html#ie">FR_INT_ERR</a>,
<a href="rc.html#nr">FR_NOT_READY</a>,
<a href="rc.html#ne">FR_NOT_ENABLED</a>,
<a href="rc.html#ns">FR_NO_FILESYSTEM</a>,
<a href="rc.html#tm">FR_TIMEOUT</a>,
<a href="rc.html#nc">FR_NOT_ENOUGH_CORE</a>
</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>The <tt>f_getcwd</tt> function retrieves full path name of the current directory of the current drive. When <tt><a href="config.html#volumes">FF_VOLUMES</a> &gt;= 2</tt>, a heading drive prefix is added to the path name. The style of drive prefix depends on <tt><a href="config.html#str_volume_id">FF_STR_VOLUME_ID</a></tt>.</p>
<p><em>Note: In this revision, this function cannot retrieve the current directory path on the exFAT volume. It always returns the root directory path.</em></p>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>Available when <tt><a href="config.html#fs_rpath">FF_FS_RPATH</a> == 2</tt>.</p>
</div>
<div class="para use">
<h4>Example</h4>
<pre>
FRESULT fr;
TCHAR str[SZ_STR];
fr = <em>f_getcwd</em>(str, SZ_STR); <span class="c">/* Get current directory path */</span>
</pre>
</div>
<div class="para ref">
<h4>See Also</h4>
<p><tt><a href="chdrive.html">f_chdrive</a>, <a href="chdir.html">f_chdir</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,94 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/getfree.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_getfree</title>
</head>
<body>
<div class="para func">
<h2>f_getfree</h2>
<p>The f_getfree function gets number of the free clusters on the volume.</p>
<pre>
FRESULT f_getfree (
const TCHAR* <span class="arg">path</span>, <span class="c">/* [IN] Logical drive number */</span>
DWORD* <span class="arg">nclst</span>, <span class="c">/* [OUT] Number of free clusters */</span>
FATFS** <span class="arg">fatfs</span> <span class="c">/* [OUT] Corresponding filesystem object */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>path</dt>
<dd>Pointer to the null-terminated string that specifies the <a href="filename.html">logical drive</a>. A null-string means the default drive.</dd>
<dt>nclst</dt>
<dd>Pointer to the <tt>DWORD</tt> variable to store number of free clusters.</dd>
<dt>fatfs</dt>
<dd>Pointer to pointer that to store a pointer to the corresponding filesystem object.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>
<a href="rc.html#ok">FR_OK</a>,
<a href="rc.html#de">FR_DISK_ERR</a>,
<a href="rc.html#ie">FR_INT_ERR</a>,
<a href="rc.html#nr">FR_NOT_READY</a>,
<a href="rc.html#id">FR_INVALID_DRIVE</a>,
<a href="rc.html#ne">FR_NOT_ENABLED</a>,
<a href="rc.html#ns">FR_NO_FILESYSTEM</a>,
<a href="rc.html#tm">FR_TIMEOUT</a>
</p>
</div>
<div class="para desc">
<h4>Descriptions</h4>
<p>The <tt>f_getfree</tt> function gets number of free clusters on the volume. The member <tt>csize</tt> in the filesystem object indicates number of sectors per cluster, so that the free space in unit of sector can be calcurated with this information. In case of FSINFO structure on the FAT32 volume is not in sync, this function can return an incorrect free cluster count. To avoid this problem, FatFs can be forced full FAT scan by <tt><a href="config.html#fs_nofsinfo">FF_FS_NOFSINFO</a></tt> option.</p>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>Available when <tt><a href="config.html#fs_readonly">FF_FS_READONLY</a> == 0</tt> and <tt><a href="config.html#fs_minimize">FF_FS_MINIMIZE</a> == 0</tt>.</p>
</div>
<div class="para use">
<h4>Example</h4>
<pre>
FATFS *fs;
DWORD fre_clust, fre_sect, tot_sect;
<span class="c">/* Get volume information and free clusters of drive 1 */</span>
res = <em>f_getfree</em>("1:", &amp;fre_clust, &amp;fs);
if (res) die(res);
<span class="c">/* Get total sectors and free sectors */</span>
tot_sect = (fs->n_fatent - 2) * fs->csize;
fre_sect = fre_clust * fs->csize;
<span class="c">/* Print the free space (assuming 512 bytes/sector) */</span>
printf("%10lu KiB total drive space.\n%10lu KiB available.\n", tot_sect / 2, fre_sect / 2);
</pre>
</div>
<div class="para ref">
<h4>See Also</h4>
<p><tt><a href="sfatfs.html">FATFS</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,90 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/getlabel.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_getlabel</title>
</head>
<body>
<div class="para func">
<h2>f_getlabel</h2>
<p>The f_getlabel function returns volume label and volume serial number of a volume.</p>
<pre>
FRESULT f_getlabel (
const TCHAR* <span class="arg">path</span>, <span class="c">/* [IN] Drive number */</span>
TCHAR* <span class="arg">label</span>, <span class="c">/* [OUT] Volume label */</span>
DWORD* <span class="arg">vsn</span> <span class="c">/* [OUT] Volume serial number */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>path</dt>
<dd>Pointer to the null-terminated string that specifies the <a href="filename.html">logical drive</a>. Null-string specifies the default drive.</dd>
<dt>label</dt>
<dd>Pointer to the buffer to store the volume label. If the volume has no label, a null-string will be returned. Set null pointer if this information is not needed. The buffer size should be shown below at least to avoid buffer overflow.<br>
<table class="lst2">
<tr><td>Configuration</td><td>FF_FS_EXFAT == 0</td><td>FF_FS_EXFAT == 1</td></tr>
<tr><td>FF_USE_LFN == 0</td><td>12 items</td><td>-</td></tr>
<tr><td>FF_LFN_UNICODE == 0</td><td>12 items</td><td>23 items</td></tr>
<tr><td>FF_LFN_UNICODE == 1/3</td><td>12 items</td><td>12 items</td></tr>
<tr><td>FF_LFN_UNICODE == 2</td><td>34 items</td><td>34 items</td></tr>
</table>
</dd>
<dt>vsn</dt>
<dd>Pointer to the <tt>DWORD</tt> variable to store the volume serial number. Set null pointer if this information is not needed.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>
<a href="rc.html#ok">FR_OK</a>,
<a href="rc.html#de">FR_DISK_ERR</a>,
<a href="rc.html#ie">FR_INT_ERR</a>,
<a href="rc.html#nr">FR_NOT_READY</a>,
<a href="rc.html#id">FR_INVALID_DRIVE</a>,
<a href="rc.html#ne">FR_NOT_ENABLED</a>,
<a href="rc.html#ns">FR_NO_FILESYSTEM</a>,
<a href="rc.html#tm">FR_TIMEOUT</a>
</p>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>Available when <tt><a href="config.html#use_label">FF_USE_LABEL</a> == 1</tt>.</p>
</div>
<div class="para use">
<h4>Example</h4>
<pre>
char str[12];
<span class="c">/* Get volume label of the default drive */</span>
<em>f_getlabel</em>("", str, 0);
<span class="c">/* Get volume label of the drive 2 */</span>
<em>f_getlabel</em>("2:", str, 0);
</pre>
</div>
<div class="para ref">
<h4>See Also</h4>
<tt><a href="setlabel.html">f_setlabel</a></tt>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,65 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/gets.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_gets</title>
</head>
<body>
<div class="para func">
<h2>f_gets</h2>
<p>The f_gets reads a string from the file.</p>
<pre>
TCHAR* f_gets (
TCHAR* <span class="arg">buff</span>, <span class="c">/* [OUT] Read buffer */</span>
int <span class="arg">len</span>, <span class="c">/* [IN] Size of the read buffer */</span>
FIL* <span class="arg">fp</span> <span class="c">/* [IN] File object */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>buff</dt>
<dd>Pointer to read buffer to store the read string.</dd>
<dt>len</dt>
<dd>Size of the read buffer in unit of item.</dd>
<dt>fp</dt>
<dd>Pointer to the open file object structure.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>When the function succeeded, <tt class="arg">buff</tt> will be returuned.</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>The read operation continues until a <tt>'\n'</tt> is stored, reached end of the file or the buffer is filled with <tt>len - 1</tt> characters. The read string is terminated with a <tt>'\0'</tt>. When no character to read or any error occured during read operation, it returns a null pointer. The status of EOF and error can be examined with <tt>f_eof</tt> and <tt>f_error</tt> function.</p>
<p>When FatFs is configured to Unicode API (<tt><a href="config.html#lfn_unicode">FF_LFN_UNICODE</a> >= 1</tt>), data types on the srting fuctions, <tt>f_putc</tt>, <tt>f_puts</tt>, <tt>f_printf</tt> and <tt>f_gets</tt>, is also switched to Unicode. The character encoding <em>on the file</em> to be read via this function is assumed as <a href="config.html#strf_encode"><tt>FF_STRF_ENCODE</tt></a>. If the character encoding on the file differs from that on the API, it is converted in this function. In this case, input characters with wrong encoding will be lost.<p>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>This is a wrapper function of <a href="read.html"><tt>f_read</tt></a> function. Available when <tt><a href="config.html#use_strfunc">FF_USE_STRFUNC</a> &gt;= 1</tt>. When it is set to 2, <tt>'\r'</tt>s contained in the file are stripped out.</p>
</div>
<div class="para ref">
<h4>See Also</h4>
<p><tt><a href="open.html">f_open</a>, <a href="read.html">f_read</a>, <a href="putc.html">f_putc</a>, <a href="puts.html">f_puts</a>, <a href="printf.html">f_printf</a>, <a href="close.html">f_close</a>, <a href="sfile.html">FIL</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,131 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/lseek.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_lseek</title>
</head>
<body>
<div class="para func">
<h2>f_lseek</h2>
<p>The f_lseek function moves the file read/write pointer of an open file object. It can also be used to expand the file size (cluster pre-allocation). </p>
<pre>
FRESULT f_lseek (
FIL* <span class="arg">fp</span>, <span class="c">/* [IN] File object */</span>
FSIZE_t <span class="arg">ofs</span> <span class="c">/* [IN] File read/write pointer */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>fp</dt>
<dd>Pointer to the open file object.</dd>
<dt>ofs</dt>
<dd>Byte offset from top of the file to set read/write pointer. The data type <tt>FSIZE_t</tt> is an alias of either <tt>DWORD</tt>(32-bit) or <tt>QWORD</tt>(64-bit) depends on the configuration option <tt><a href="config.html#fs_exfat">FF_FS_EXFAT</a></tt>.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>
<a href="rc.html#ok">FR_OK</a>,
<a href="rc.html#de">FR_DISK_ERR</a>,
<a href="rc.html#ie">FR_INT_ERR</a>,
<a href="rc.html#io">FR_INVALID_OBJECT</a>,
<a href="rc.html#tm">FR_TIMEOUT</a>
</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>File read/write ponter in the open file object points the data byte to be read/written at next read/write operation. It advances as the number of bytes read/written. The <tt>f_lseek</tt> function moves the file read/write pointer without any read/write operation to the file.</p>
<p>When an offset beyond the file size is specified at write mode, the file size is expanded to the specified offset. The file data in the expanded area is <em>undefined</em> because no data is written to the file in this process. This is suitable to pre-allocate a data area to the file quickly for fast write operation. When a contiguous data area needs to be allocated to the file, use <tt>f_expand</tt> function instead. After the <tt>f_lseek</tt> function succeeded, the current read/write pointer should be checked in order to make sure the read/write pointer has been moved correctry. In case of the read/write pointer is not the expected value, either of followings has been occured.</p>
<ul>
<li>End of file. The specified <tt class="arg">ofs</tt> was clipped at end of the file because the file has been opened in read-only mode.</li>
<li>Disk full. There is no free space on the volume to expand the file.</li>
</ul>
<p>The fast seek feature enables fast backward/long seek operations without FAT access by using an on-memory CLMT (cluster link map table). It is applied to <tt>f_read</tt> and <tt>f_write</tt> function as well, however, the file size cannot be expanded by <tt>f_write</tt>, <tt>f_lseek</tt> function while the file is at fast seek mode.</p>
<p>The fast seek mode is enabled when the member <tt>cltbl</tt> in the file object is not NULL. The CLMT must be created into the <tt>DWORD</tt> array prior to use the fast seek. To create the CLMT, set address of the <tt>DWORD</tt> array to the member <tt>cltbl</tt> in the open file object, set the size of array in unit of items to the first item and call the <tt>f_lseek</tt> function with <tt class="arg">ofs</tt><tt> = CREATE_LINKMAP</tt>. After the function succeeded and CLMT is created, no FAT access is occured in subsequent <tt>f_read</tt>, <tt>f_write</tt>, <tt>f_lseek</tt> function to the file. The number of items used or required is returned into the first item of the array. The number of items to be used is (number of the file fragments + 1) * 2. For example, when the file is fragmented in 5, 12 items in the array will be used. If the function failed with <tt>FR_NOT_ENOUGH_CORE</tt>, the given array size is insufficient for the file.</p>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>Available when <tt><a href="config.html#fs_minimize">FF_FS_MINIMIZE</a> &lt;= 2</tt>. To use fast seek function, <tt><a href="config.html#use_fastseek">FF_USE_FASTSEEK</a></tt> needs to be set 1 to enable this feature.</p>
</div>
<div class="para use">
<h4>Example</h4>
<pre>
<span class="c">/* Open file */</span>
fp = malloc(sizeof (FIL));
res = f_open(fp, "file.dat", FA_READ|FA_WRITE);
if (res) ...
<span class="c">/* Move to offset of 5000 from top of the file */</span>
res = <em>f_lseek</em>(fp, 5000);
<span class="c">/* Move to end of the file to append data */</span>
res = <em>f_lseek</em>(fp, f_size(fp));
<span class="c">/* Forward 3000 bytes */</span>
res = <em>f_lseek</em>(fp, f_tell(fp) + 3000);
<span class="c">/* Rewind 2000 bytes (take care on wraparound) */</span>
res = <em>f_lseek</em>(fp, f_tell(fp) - 2000);
</pre>
<pre>
<span class="c">/* Cluster pre-allocation (to prevent buffer overrun on streaming write) */</span>
res = f_open(fp, recfile, FA_CREATE_NEW | FA_WRITE); <span class="c">/* Create a file */</span>
res = <em>f_lseek</em>(fp, PRE_SIZE); <span class="c">/* Expand file size (cluster pre-allocation) */</span>
if (res || f_tell(fp) != PRE_SIZE) ... <span class="c">/* Check if the file has been expanded successfly */</span>
res = <em>f_lseek</em>(fp, DATA_START); <span class="c">/* Record data stream WITHOUT cluster allocation delay */</span>
... <span class="c">/* Write operation should be aligned to sector boundary to optimize the write throughput */</span>
res = f_truncate(fp); <span class="c">/* Truncate unused area */</span>
res = <em>f_lseek</em>(fp, 0); <span class="c">/* Set file header */</span>
...
res = f_close(fp);
</pre>
<pre>
<span class="c">/* Using fast seek function */</span>
DWORD clmt[SZ_TBL]; <span class="c">/* Cluster link map table buffer */</span>
res = f_open(fp, fname, FA_READ | FA_WRITE); <span class="c">/* Open a file */</span>
res = <em>f_lseek</em>(fp, ofs1); <span class="c">/* This is normal seek (cltbl is nulled on file open) */</span>
fp-&gt;cltbl = clmt; <span class="c">/* Enable fast seek function (cltbl != NULL) */</span>
clmt[0] = SZ_TBL; <span class="c">/* Set table size */</span>
res = <em>f_lseek</em>(fp, CREATE_LINKMAP); <span class="c">/* Create CLMT */</span>
...
res = <em>f_lseek</em>(fp, ofs2); <span class="c">/* This is fast seek */</span>
</pre>
</div>
<div class="para ref">
<h4>See Also</h4>
<p><tt><a href="open.html">f_open</a>, <a href="truncate.html">f_truncate</a>, <a href="expand.html">f_expand</a>, <a href="sfile.html">FIL</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,80 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/mkdir.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_mkdir</title>
</head>
<body>
<div class="para func">
<h2>f_mkdir</h2>
<p>The f_mkdir function creates a new directory.</p>
<pre>
FRESULT f_mkdir (
const TCHAR* <span class="arg">path</span> <span class="c">/* [IN] Directory name */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameter</h4>
<dl class="par">
<dt>path</dt>
<dd>Pointer to the null-terminated string that specifies the <a href="filename.html">directory name</a> to create. </dd>
</dl>
</div>
<div class="para ret">
<h4>Return Value</h4>
<p>
<a href="rc.html#ok">FR_OK</a>,
<a href="rc.html#de">FR_DISK_ERR</a>,
<a href="rc.html#ie">FR_INT_ERR</a>,
<a href="rc.html#nr">FR_NOT_READY</a>,
<a href="rc.html#np">FR_NO_PATH</a>,
<a href="rc.html#in">FR_INVALID_NAME</a>,
<a href="rc.html#dn">FR_DENIED</a>,
<a href="rc.html#ex">FR_EXIST</a>,
<a href="rc.html#wp">FR_WRITE_PROTECTED</a>,
<a href="rc.html#id">FR_INVALID_DRIVE</a>,
<a href="rc.html#ne">FR_NOT_ENABLED</a>,
<a href="rc.html#ns">FR_NO_FILESYSTEM</a>,
<a href="rc.html#tm">FR_TIMEOUT</a>,
<a href="rc.html#nc">FR_NOT_ENOUGH_CORE</a>
</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>This function creates a new directory. To remove a directory, use <a href="unlink.html"><tt>f_unlink</tt></a> function.</p>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>Available when <tt><a href="config.html#fs_readonly">FF_FS_READONLY</a> == 0</tt> and <tt><a href="config.html#fs_minimize">FF_FS_MINIMIZE</a> == 0</tt>.</p>
</div>
<div class="para use">
<h4>Example</h4>
<pre>
res = <em>f_mkdir</em>("sub1");
if (res) die(res);
res = <em>f_mkdir</em>("sub1/sub2");
if (res) die(res);
res = <em>f_mkdir</em>("sub1/sub2/sub3");
if (res) die(res);
</pre>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,126 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/mkfs.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_mkfs</title>
</head>
<body>
<div class="para func">
<h2>f_mkfs</h2>
<p>The f_mkfs fucntion creates an FAT/exFAT volume on the logical drive.</p>
<pre>
FRESULT f_mkfs (
const TCHAR* <span class="arg">path</span>, <span class="c">/* [IN] Logical drive number */</span>
const MKFS_PARM* <span class="arg">opt</span>,<span class="c">/* [IN] Format options */</span>
void* <span class="arg">work</span>, <span class="c">/* [-] Working buffer */</span>
UINT <span class="arg">len</span> <span class="c">/* [IN] Size of working buffer */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>path</dt>
<dd>Pointer to the null-terminated string specifies the <a href="filename.html">logical drive</a> to be formatted. If it has no drive number in it, it means to specify the default drive. The logical drive may or may not have been mounted for the format process.</dd>
<dt>opt</dt>
<dd>Specifies the structure holding format options. If a null pointer is given, it gives the function all options in default value. The format option structure has five members described below:<br>
<dl class="par">
<dt>BYTE fmt</dt>
<dd>Specifies combination of FAT type flags, <tt>FM_FAT</tt>, <tt>FM_FAT32</tt>, <tt>FM_EXFAT</tt> and bitwise-or of these three, <tt>FM_ANY</tt>. <tt>FM_EXFAT</tt> is ignored when exFAT is not enabled. These flags specify which FAT type to be created on the volume. If two or more types are specified, one out of them will be selected depends on the volume size and <tt class="arg">au_size</tt>. The flag <tt>FM_SFD</tt> specifies to create the volume on the drive in SFD format. The default value is <tt>FM_ANY</tt>.</dd>
<dt>DWORD au_size</dt>
<dd>Specifies size of the allocation unit (cluter) in unit of byte. The valid value is power of 2 between the sector size and 128 * sector size inclusive for FAT/FAT32 volume and up to 16 MB for exFAT volume. If a zero (also default value) or any invalid value is given, the default allocation unit size depends on the volume size is used.</dd>
<dt>UINT n_align</dt>
<dd>Specifies alignment of the volume data area (file allocation pool, usually erase block boundary of flash media) in unit of sector. The valid value for this member is between 1 and 32768 inclusive in power of 2. If a zero (also default value) or any invalid value is given, the function obtains the block size from lower layer via <tt>disk_ioctl</tt> function.</dd>
<dt>BYTE n_fat</dt>
<dd>Specifies number of FAT copies on the FAT/FAT32 volume. Valid value for this member is 1 or 2. The default value (0) and any invaid value is considered as 1. If the FAT type is exFAT, this value has no effect.</dd>
<dt>UINT n_root</dt>
<dd>Specifies number of root directory entries on the FAT volume. Valid value for this member is up to 32768 and aligned to sector size / 32. The default value (0) and any invaid value is considered as 512. If the FAT type is FAT32 or exFAT, this value has no effect.</dd>
</dl>
<dt>work</dt>
<dd>Pointer to the working buffer used for the format process. When a null pointer is given with <tt><a href="config.html#use_lfn">FF_USE_LFN</a> == 3</tt>, the function obtains a memory block in this function for the working buffer.</dd>
<dt>len</dt>
<dd>Size of the working buffer in unit of byte. It needs to be the sector size of the corresponding physical drive at least. Plenty of working buffer reduces number of write transactions to the drive and the format process will finish quickly.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>
<a href="rc.html#ok">FR_OK</a>,
<a href="rc.html#de">FR_DISK_ERR</a>,
<a href="rc.html#nr">FR_NOT_READY</a>,
<a href="rc.html#wp">FR_WRITE_PROTECTED</a>,
<a href="rc.html#id">FR_INVALID_DRIVE</a>,
<a href="rc.html#ma">FR_MKFS_ABORTED</a>,
<a href="rc.html#ip">FR_INVALID_PARAMETER</a>,
<a href="rc.html#nc">FR_NOT_ENOUGH_CORE</a>
</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>The FAT sub-type, FAT12/FAT16/FAT32, of FAT volume except exFAT is determined by only number of clusters on the volume and nothing else, according to the FAT specification issued by Microsoft. Thus the FAT sub-type of created volume depends on the volume size and the cluster size. In case of the combination of FAT type and cluter size specified by argument cannot be valid on the volume, the function will fail with <tt>FR_MKFS_ABORTED</tt>.</p>
<p>The allocation unit, also knows as <em>cluster</em>, is a unit of disk space allocation for files. When the size of allocation unit is 32768 bytes, a file with 100 bytes in size occupies 32768 bytes of disk space. The space efficiency of disk usage gets worse as increasing size of allocation unit, but, on the other hand, the read/write performance increases. Therefore the size of allocation unit is a trade-off between space efficiency and performance. For the large storages in GB order, 32768 bytes or larger (this is automatically selected by default) is recommended for most case unless extremely many small files are created on a volume.</p>
<p>When the logical drive to be formatted is associated with a physical drive (<tt><a href="config.html#multi_partition">FF_MULTI_PARTITION</a> = 0</tt>) and <tt>FM_SFD</tt> flag is not specified, a partition occupies entire disk space is created and then the FAT volume is created in the partition. When <tt>FM_SFD</tt> flag is specified, the FAT volume is created without any disk partitioning.</p>
<p>When the logical drive to be formatted is associated with a specific partition by multiple partition feature (<tt>FF_MULTI_PARTITION = 1</tt>), the FAT volume is created on the partition specified by the <a href="filename.html#vol">volume mapping table</a> and <tt>FM_SFD</tt> flag is ignored. The physical drive needs to be partitioned with <tt>f_fdisk</tt> function or any partitioning tool prior to create the FAT volume with this function.</p>
<p>There are three disk partitioning formats, MBR, GPT and SFD. The MBR format (aka FDISK format) is usually used for harddisk, memory card and U disk. It can divide a physical drive into one or more partitions with a partition table. The GPT (GUID Partition Table) is a newly defined patitioning format for large storage devices. FatFs suppors the GPT only when 64-bit LBA is enabled. SFD (super-floppy disk) is non-partitioned disk format. The FAT volume occupies the entire physical drive without any disk partitioning. It is usually used for floppy disk, optical disk and most super-floppy media. Some combination of systems and media support only either partitioned format or non-partitioned format and the other is not supported.</p>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>Available when <tt><a href="config.html#fs_readonly">FF_FS_READOLNY</a> == 0</tt> and <tt><a href="config.html#use_mkfs">FF_USE_MKFS</a> == 1</tt>.</p>
</div>
<div class="para use">
<h4>Example</h4>
<pre>
<span class="c">/* Format default drive and create a file */</span>
int main (void)
{
FATFS fs; <span class="c">/* Filesystem object */</span>
FIL fil; <span class="c">/* File object */</span>
FRESULT res; <span class="c">/* API result code */</span>
UINT bw; <span class="c">/* Bytes written */</span>
BYTE work[FF_MAX_SS]; <span class="c">/* Work area (larger is better for processing time) */</span>
<span class="c">/* Format the default drive with default parameters */</span>
res = <em>f_mkfs</em>("", 0, work, sizeof work);
if (res) ...
<span class="c">/* Gives a work area to the default drive */</span>
f_mount(&amp;fs, "", 0);
<span class="c">/* Create a file as new */</span>
res = f_open(&amp;fil, "hello.txt", FA_CREATE_NEW | FA_WRITE);
if (res) ...
<span class="c">/* Write a message */</span>
f_write(&amp;fil, "Hello, World!\r\n", 15, &amp;bw);
if (bw != 15) ...
<span class="c">/* Close the file */</span>
f_close(&amp;fil);
<span class="c">/* Unregister work area */</span>
f_mount(0, "", 0);
...
</pre>
</div>
<div class="para ref">
<h4>See Also</h4>
<p><a href="../res/mkfs.xlsx">Example of volume size and format parameters</a>, <a href="filename.html#vol">Volume management</a>, <tt><a href="fdisk.html">f_fdisk</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,113 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/mount.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_mount</title>
</head>
<body>
<div class="para func">
<h2>f_mount</h2>
<p>The f_mount fucntion registers/unregisters filesystem object to the FatFs module.</p>
<pre>
FRESULT f_mount (
FATFS* <span class="arg">fs</span>, <span class="c">/* [IN] Filesystem object */</span>
const TCHAR* <span class="arg">path</span>, <span class="c">/* [IN] Logical drive number */</span>
BYTE <span class="arg">opt</span> <span class="c">/* [IN] Initialization option */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>fs</dt>
<dd>Pointer to the filesystem object to be registered and cleared. Null pointer unregisters the registered filesystem object.</dd>
<dt>path</dt>
<dd>Pointer to the null-terminated string that specifies the <a href="filename.html">logical drive</a>. The string without drive number means the default drive.</dd>
<dt>opt</dt>
<dd>Mounting option. 0: Do not mount now (to be mounted on the first access to the volume), 1: Force mounted the volume to check if it is ready to work.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>
<a href="rc.html#ok">FR_OK</a>,
<a href="rc.html#id">FR_INVALID_DRIVE</a>,
<a href="rc.html#de">FR_DISK_ERR</a>,
<a href="rc.html#nr">FR_NOT_READY</a>,
<a href="rc.html#ne">FR_NOT_ENABLED</a>,
<a href="rc.html#ns">FR_NO_FILESYSTEM</a>
</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>FatFs requires work area (<em>filesystem object</em>) for each logical drives (FAT volumes). Prior to perform any file/directory operations, a filesystem object needs to be registered with <tt>f_mount</tt> function to the logical drive. The file/directory API functions get ready to work after this procedure. If there is any open object of file or directory on the logical drive, the object will be invalidated by this function. Some management functions, <tt>f_mkfs</tt>, <tt>f_fdisk</tt> and <tt>f_setcp</tt>, do not want a filesystem object.</p>
<p>The <tt>f_mount</tt> function registers/unregisters a filesystem object to the FatFs module as follows:</p>
<ol>
<li>Determines the logical drive which specified by <tt class="arg">path</tt>.</li>
<li>Clears and unregisters the regsitered work area of the volume if exist.</li>
<li>Clears and registers the new work area to the volume if <tt class="arg">fs</tt> is not NULL.</li>
<li>Performs volume mount process to the volume if forced mounting is specified.</li>
</ol>
<p>If forced mounting is not specified (<tt>opt = 0</tt>), this function always succeeds regardless of the physical drive status. It only clears (de-initializes) the given work area and registers its address to the internal table and no activity of the physical drive in this function. The volume mount process will be attempted on subsequent file/directroy function if the filesystem object is not initialized. (delayed mounting) The volume mount processes, initialize the corresponding physical drive, find the FAT volume in it and then initialize the work area, is performed in the subsequent file/directory functions when either of following conditions is true.</p>
<ul>
<li>Filesystem object has not been initialized. It is de-initialized by <tt>f_mount</tt> function.</li>
<li>Physical drive is not initialized. It is de-initialized by system reset or media removal.</li>
</ul>
<p>If the function with forced mounting (<tt>opt = 1</tt>) failed with <tt>FR_NOT_READY</tt>, it means that the filesystem object has been registered successfully but the volume is currently not ready to work. The volume mount process will be attempted on subsequent file/directroy function.</p>
<p>If implementation of the disk I/O layer lacks asynchronous media change detection, application program needs to perform <tt>f_mount</tt> function after each media change to force cleared the filesystem object.</p>
<p>To unregister the work area, specify a NULL to the <tt class="arg">fs</tt>, and then the work area can be discarded.</p>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>Always available.</p>
</div>
<div class="para use">
<h4>Example</h4>
<pre>
int main (void)
{
FATFS *fs; <span class="c">/* Ponter to the filesystem object */</span>
fs = malloc(sizeof (FATFS)); <span class="c">/* Get work area for the volume */</span>
<em>f_mount</em>(fs, "", 0); <span class="c">/* Mount the default drive */</span>
f_open(... <span class="c">/* Here any file API can be used */</span>
...
<em>f_mount</em>(fs, "", 0); <span class="c">/* Re-mount the default drive to reinitialize the filesystem */</span>
...
<em>f_mount</em>(0, "", 0); <span class="c">/* Unmount the default drive */</span>
free(fs); <span class="c">/* Here the work area can be discarded */</span>
...
}
</pre>
</div>
<div class="para ref">
<h4>See Also</h4>
<p><tt><a href="open.html">f_open</a></tt>, <tt><a href="sfatfs.html">FATFS</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,185 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/open.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_open</title>
</head>
<body>
<div class="para func">
<h2>f_open</h2>
<p>The f_open function opens a file.</p>
<pre>
FRESULT f_open (
FIL* <span class="arg">fp</span>, <span class="c">/* [OUT] Pointer to the file object structure */</span>
const TCHAR* <span class="arg">path</span>, <span class="c">/* [IN] File name */</span>
BYTE <span class="arg">mode</span> <span class="c">/* [IN] Mode flags */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>fp</dt>
<dd>Pointer to the blank file object structure.</dd>
<dt>path</dt>
<dd>Pointer to the null-terminated string that specifies the <a href="filename.html">file name</a> to open or create.</dd>
<dt>mode</dt>
<dd>Mode flags that specifies the type of access and open method for the file. It is specified by a combination of following flags.<br>
<table class="lst">
<tr><th>Flags</th><th>Meaning</th></tr>
<tr><td>FA_READ</td><td>Specifies read access to the object. Data can be read from the file.</tr>
<tr><td>FA_WRITE</td><td>Specifies write access to the object. Data can be written to the file. Combine with <tt>FA_READ</tt> for read-write access.</td></tr>
<tr><td>FA_OPEN_EXISTING</td><td>Opens the file. The function fails if the file is not existing. (Default)</td></tr>
<tr><td>FA_CREATE_NEW</td><td>Creates a new file. The function fails with <tt>FR_EXIST</tt> if the file is existing.</td></tr>
<tr><td>FA_CREATE_ALWAYS</td><td>Creates a new file. If the file is existing, it will be truncated and overwritten.</td></tr>
<tr><td>FA_OPEN_ALWAYS</td><td>Opens the file if it is existing. If not, a new file will be created.</td></tr>
<tr><td>FA_OPEN_APPEND</td><td>Same as <tt>FA_OPEN_ALWAYS</tt> except the read/write pointer is set end of the file.</td></tr>
</table>
Mode flags of POSIX fopen() corresponds to FatFs mode flags as follows:<br>
<table class="lst2">
<tr><th>POSIX</th><th>FatFs</th></tr>
<tr><td>"r"</td><td>FA_READ</td></tr>
<tr><td>"r+"</td><td>FA_READ | FA_WRITE</td></tr>
<tr><td>"w"</td><td>FA_CREATE_ALWAYS | FA_WRITE</td></tr>
<tr><td>"w+"</td><td>FA_CREATE_ALWAYS | FA_WRITE | FA_READ</td></tr>
<tr><td>"a"</td><td>FA_OPEN_APPEND | FA_WRITE</td></tr>
<tr><td>"a+"</td><td>FA_OPEN_APPEND | FA_WRITE | FA_READ</td></tr>
<tr><td>"wx"</td><td>FA_CREATE_NEW | FA_WRITE</td></tr>
<tr><td>"w+x"</td><td>FA_CREATE_NEW | FA_WRITE | FA_READ</td></tr>
</table>
</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>
<a href="rc.html#ok">FR_OK</a>,
<a href="rc.html#de">FR_DISK_ERR</a>,
<a href="rc.html#ie">FR_INT_ERR</a>,
<a href="rc.html#nr">FR_NOT_READY</a>,
<a href="rc.html#nf">FR_NO_FILE</a>,
<a href="rc.html#np">FR_NO_PATH</a>,
<a href="rc.html#in">FR_INVALID_NAME</a>,
<a href="rc.html#dn">FR_DENIED</a>,
<a href="rc.html#ex">FR_EXIST</a>,
<a href="rc.html#io">FR_INVALID_OBJECT</a>,
<a href="rc.html#wp">FR_WRITE_PROTECTED</a>,
<a href="rc.html#id">FR_INVALID_DRIVE</a>,
<a href="rc.html#ne">FR_NOT_ENABLED</a>,
<a href="rc.html#ns">FR_NO_FILESYSTEM</a>,
<a href="rc.html#tm">FR_TIMEOUT</a>,
<a href="rc.html#lo">FR_LOCKED</a>,
<a href="rc.html#nc">FR_NOT_ENOUGH_CORE</a>,
<a href="rc.html#tf">FR_TOO_MANY_OPEN_FILES</a>
</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>The <tt>f_open</tt> function opens a file and creates a <em>file object</em>. The file object is used for subsequent read/write operations to the file to identify the file. Open file should be closed with <a href="close.html"><tt>f_close</tt></a> function after the session of the file access. If any change to the file is made and not closed prior to power down, media removal or re-mount, or the file can be collapsed.</p>
<p>If duplicated file open is needed, read <a href="appnote.html#dup">here</a> carefully. However duplicated open of a file with any write mode flag is always prohibited.</p>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>Always available. Only <tt>FA_READ</tt> and <tt>FA_OPEN_EXISTING</tt> are available for the mode flags when <tt><a href="config.html#fs_readonly">FF_FS_READONLY</a> == 1</tt>.</p>
</div>
<div class="para use">
<h4>Example</h4>
<pre>
<span class="c">/* Read a text file and display it */</span>
FATFS FatFs; <span class="c">/* Work area (filesystem object) for logical drive */</span>
int main (void)
{
FIL fil; <span class="c">/* File object */</span>
char line[100]; <span class="c">/* Line buffer */</span>
FRESULT fr; <span class="c">/* FatFs return code */</span>
<span class="c">/* Register work area to the default drive */</span>
f_mount(&amp;FatFs, "", 0);
<span class="c">/* Open a text file */</span>
fr = <em>f_open</em>(&amp;fil, "message.txt", FA_READ);
if (fr) return (int)fr;
<span class="c">/* Read every line and display it */</span>
while (f_gets(line, sizeof line, &amp;fil)) {
printf(line);
}
<span class="c">/* Close the file */</span>
f_close(&amp;fil);
return 0;
}
</pre>
<pre>
<span class="c">/* Copy a file "file.bin" on the drive 1 to drive 0 */</span>
int main (void)
{
FATFS fs0, fs1; <span class="c">/* Work area (filesystem object) for logical drives */</span>
FIL fsrc, fdst; <span class="c">/* File objects */</span>
BYTE buffer[4096]; <span class="c">/* File copy buffer */</span>
FRESULT fr; <span class="c">/* FatFs function common result code */</span>
UINT br, bw; <span class="c">/* File read/write count */</span>
<span class="c">/* Register work area for each logical drive */</span>
f_mount(&amp;fs0, "0:", 0);
f_mount(&amp;fs1, "1:", 0);
<span class="c">/* Open source file on the drive 1 */</span>
fr = <em>f_open</em>(&amp;fsrc, "1:file.bin", FA_READ);
if (fr) return (int)fr;
<span class="c">/* Create destination file on the drive 0 */</span>
fr = <em>f_open</em>(&amp;fdst, "0:file.bin", FA_WRITE | FA_CREATE_ALWAYS);
if (fr) return (int)fr;
<span class="c">/* Copy source to destination */</span>
for (;;) {
fr = f_read(&amp;fsrc, buffer, sizeof buffer, &amp;br); <span class="c">/* Read a chunk of source file */</span>
if (fr || br == 0) break; <span class="c">/* error or eof */</span>
fr = f_write(&amp;fdst, buffer, br, &amp;bw); <span class="c">/* Write it to the destination file */</span>
if (fr || bw &lt; br) break; <span class="c">/* error or disk full */</span>
}
<span class="c">/* Close open files */</span>
f_close(&amp;fsrc);
f_close(&amp;fdst);
<span class="c">/* Unregister work area prior to discard it */</span>
f_mount(0, "0:", 0);
f_mount(0, "1:", 0);
return (int)fr;
}
</pre>
</div>
<div class="para ref">
<h4>See Also</h4>
<p><tt><a href="read.html">f_read</a>, <a href="write.html">f_write</a>, <a href="close.html">f_close</a>, <a href="sfile.html">FIL</a>, <a href="sfatfs.html">FATFS</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,75 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/opendir.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_opendir</title>
</head>
<body>
<div class="para func">
<h2>f_opendir</h2>
<p>The f_opendir function opens a directory.</p>
<pre>
FRESULT f_opendir (
DIR* <span class="arg">dp</span>, <span class="c">/* [OUT] Pointer to the directory object structure */</span>
const TCHAR* <span class="arg">path</span> <span class="c">/* [IN] Directory name */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>dp</dt>
<dd>Pointer to the blank directory object to create a new one.</dd>
<dt>path</dt>
<dd>Pointer to the null-terminated string that specifies the <a href="filename.html">directory name</a> to be opened.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>
<a href="rc.html#ok">FR_OK</a>,
<a href="rc.html#de">FR_DISK_ERR</a>,
<a href="rc.html#ie">FR_INT_ERR</a>,
<a href="rc.html#nr">FR_NOT_READY</a>,
<a href="rc.html#np">FR_NO_PATH</a>,
<a href="rc.html#in">FR_INVALID_NAME</a>,
<a href="rc.html#io">FR_INVALID_OBJECT</a>,
<a href="rc.html#id">FR_INVALID_DRIVE</a>,
<a href="rc.html#ne">FR_NOT_ENABLED</a>,
<a href="rc.html#ns">FR_NO_FILESYSTEM</a>,
<a href="rc.html#tm">FR_TIMEOUT</a>,
<a href="rc.html#nc">FR_NOT_ENOUGH_CORE</a>,
<a href="rc.html#tf">FR_TOO_MANY_OPEN_FILES</a>
</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>The <tt>f_opendir</tt> function opens an exsisting directory and creates a directory object for subsequent <tt>f_readdir</tt> function.</p>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>Available when <tt><a href="config.html#fs_minimize">FF_FS_MINIMIZE</a> &lt;= 1</tt>.</p>
</div>
<div class="para ref">
<h4>See Also</h4>
<p><tt><a href="readdir.html">f_readdir</a>, <a href="closedir.html">f_closedir</a>, <a href="sdir.html">DIR</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,98 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/printf.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_printf</title>
</head>
<body>
<div class="para func">
<h2>f_printf</h2>
<p>The f_printf function writes formatted string to the file.</p>
<pre>
int f_printf (
FIL* <span class="arg">fp</span>, <span class="c">/* [IN] File object */</span>
const TCHAR* <span class="arg">fmt</span>, <span class="c">/* [IN] Format stirng */</span>
...
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>fp</dt>
<dd>Pointer to the open file object structure.</dd>
<dt>fmt</dt>
<dd>Pointer to the null <tt>'\0'</tt> terminated format string. The terminator character will not be output.</dd>
<dt>...</dt>
<dd>Optional arguments...</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>When the string was written successfuly, it returns number of character encoding units written to the file. When the function failed due to disk full or any error, an <tt>EOF (-1)</tt> will be returned.</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>The format control directive is a sub-set of standard library shown as follows:</p>
<pre>
%[flag][width][type]
</pre>
<dl>
<dt>flag</dt><dd>Padding options. A <tt>-</tt> specifies left justified. A <tt>0</tt> specifies zero padded.</dd>
<dt>width</dt><dd>Minimum width of the field, <tt>1-99</tt> or <tt>*</tt>. If the width of generated string is less than the specified value, rest field is padded with white spaces or zeros. An <tt>*</tt> specifies the value comes from an argument in int type.</dd>
<dt>type</dt><dd><tt>c s d u o x b</tt> and prefix <tt>l</tt> specify type of the argument, character, string, signed integer in decimal, unsigned integer in decimal, unsigned integer in octal, unsigned integer in hexdecimal and unsigned integer in binary respectively. If <tt>sizeof (long)</tt> is greater than <tt>sizeof (int)</tt> (this is typical of 8/16-bit systems), a prefix <tt>l</tt> needs to be explicitly specified for long integer argument. These characters except for <tt>x</tt> are case insensitive.</dd>
</dl>
<p>When FatFs is configured for Unicode API (<tt><a href="config.html#lfn_unicode">FF_LFN_UNICODE</a> &gt;= 1</tt>), character encoding on the string fuctions, <tt>f_putc</tt>, <tt>f_puts</tt>, <tt>f_printf</tt> and <tt>f_gets</tt> function, is also switched to Unicode. The Unicode characters in multiple encoding unit, such as surrogate pair and multi-byte sequence, should not be divided into two function calls, or the character will be lost. The character encoding <em>on the file</em> to be written via this function is selected by <tt><a href="config.html#strf_encode">FF_STRF_ENCODE</a></tt>. The characters with wrong encoding or invalid for the output encoding will be lost.</p>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>This is a wrapper function of <a href="write.html"><tt>f_write</tt></a> function. Available when <tt><a href="config.html#fs_readonly">FF_FS_READONLY</a> == 0</tt> and <tt><a href="config.html#use_strfunc">FF_USE_STRFUNC</a> &gt;= 1</tt>. When <tt>FF_USE_STRFUNC == 2</tt>, <tt>'\n'</tt>s in the generated string are written as <tt>'\r'+'\n'</tt> each.</p>
</div>
<div class="para use">
<h4>Example</h4>
<pre>
<em>f_printf</em>(&amp;fil, "%d", 1234); <span class="c">/* "1234" */</span>
<em>f_printf</em>(&amp;fil, "%6d,%3d%%", -200, 5); <span class="c">/* " -200, 5%" */</span>
<em>f_printf</em>(&amp;fil, "%ld", 12345L); <span class="c">/* "12345" */</span>
<em>f_printf</em>(&amp;fil, "%06d", 25); <span class="c">/* "000025" */</span>
<em>f_printf</em>(&amp;fil, "%06d", -25); <span class="c">/* "000-25" */</span>
<em>f_printf</em>(&amp;fil, "%*d", 5, 100); <span class="c">/* " 100" */</span>
<em>f_printf</em>(&amp;fil, "%-6d", 25); <span class="c">/* "25 " */</span>
<em>f_printf</em>(&amp;fil, "%u", -1); <span class="c">/* "65535" or "4294967295" */</span>
<em>f_printf</em>(&amp;fil, "%04x", 0xAB3); <span class="c">/* "0ab3" */</span>
<em>f_printf</em>(&amp;fil, "%08lX", 0x123ABCL); <span class="c">/* "00123ABC" */</span>
<em>f_printf</em>(&amp;fil, "%04o", 255); <span class="c">/* "0377" */</span>
<em>f_printf</em>(&amp;fil, "%016b", 0x550F); <span class="c">/* "0101010100001111" */</span>
<em>f_printf</em>(&amp;fil, "%s", "String"); <span class="c">/* "String" */</span>
<em>f_printf</em>(&amp;fil, "%8s", "abc"); <span class="c">/* " abc" */</span>
<em>f_printf</em>(&amp;fil, "%-8s", "abc"); <span class="c">/* "abc " */</span>
<em>f_printf</em>(&amp;fil, "%c", 'a'); <span class="c">/* "a" */</span>
<em>f_printf</em>(&amp;fil, "%f", 10.0); <span class="c">/* f_printf lacks floating point support */</span>
</pre>
</div>
<div class="para ref">
<h4>See Also</h4>
<p><tt><a href="open.html">f_open</a>, <a href="putc.html">f_putc</a>, <a href="puts.html">f_puts</a>, <a href="gets.html">f_gets</a>, <a href="close.html">f_close</a>, <a href="sfile.html">FIL</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,60 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/putc.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_putc</title>
</head>
<body>
<div class="para func">
<h2>f_putc</h2>
<p>The f_putc funciton puts a character to the file.</p>
<pre>
int f_putc (
TCHAR <span class="arg">chr</span>, <span class="c">/* [IN] A character to write */</span>
FIL* <span class="arg">fp</span> <span class="c">/* [IN] File object */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>chr</dt>
<dd>A character to write.</dd>
<dt>fp</dt>
<dd>Pointer to the open file object structuer.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>When the character was written successfuly, it returns number of character encoding units written to the file. When the function failed due to disk full or any error, an <tt>EOF (-1)</tt> will be returned.</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>When FatFs is configured for Unicode API (<tt><a href="config.html#lfn_unicode">FF_LFN_UNICODE</a> &gt;= 1</tt>), character encoding on the string fuctions, <tt>f_putc</tt>, <tt>f_puts</tt>, <tt>f_printf</tt> and <tt>f_gets</tt> function, is also switched to Unicode. The character encoding <em>on the file</em> to be read/written via those functions is selected by <tt><a href="config.html#strf_encode">FF_STRF_ENCODE</a></tt>. The Unicode characters in multiple encoding unit, such as surrogate pair and multi-byte sequence, cannot be written with this function.</p>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>This is a wrapper function of <a href="write.html"><tt>f_write</tt></a> function. Available when <tt><a href="config.html#fs_readonly">FF_FS_READONLY</a> == 0</tt> and <tt><a href="config.html#use_strfunc">FF_USE_STRFUNC</a> &gt;= 1</tt>. When <tt>FF_USE_STRFUNC == 2</tt>, a <tt>'\n'</tt> is output as <tt>'\r'+'\n'</tt>.</p>
</div>
<div class="para ref">
<h4>See Also</h4>
<p><tt><a href="open.html">f_open</a>, <a href="puts.html">f_puts</a>, <a href="printf.html">f_printf</a>, <a href="gets.html">f_gets</a>, <a href="close.html">f_close</a>, <a href="sfile.html">FIL</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,61 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/puts.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_puts</title>
</head>
<body>
<div class="para func">
<h2>f_puts</h2>
<p>The f_puts function writes a string to the file.</p>
<pre>
int f_puts (
const TCHAR* <span class="arg">str</span>, <span class="c">/* [IN] String */</span>
FIL* <span class="arg">fp</span> <span class="c">/* [IN] File object */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>str</dt>
<dd>Pointer to the null terminated string to be written. The terminator character will not be written.</dd>
<dt>fp</dt>
<dd>Pointer to the open file object structure.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Value</h4>
<p>When the string was written successfuly, it returns number of character encoding units written to the file. When the function failed due to disk full or any error, an EOF (-1) will be returned.</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>When FatFs is configured for Unicode API (<tt><a href="config.html#lfn_unicode">FF_LFN_UNICODE</a> &gt;= 1</tt>), character encoding on the string fuctions, <tt>f_putc</tt>, <tt>f_puts</tt>, <tt>f_printf</tt> and <tt>f_gets</tt> function, is also switched to Unicode. The input Unicode characters in multiple encoding unit, such as surrogate pair and multi-byte sequence, should not be divided into two function calls, or the character will be lost. The character encoding <em>on the file</em> to be written via this functions is selected by <tt><a href="config.html#strf_encode">FF_STRF_ENCODE</a></tt>. The characters with wrong encoding or invalid for the output encoding will be lost.</p>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>This is a wrapper function of <a href="write.html"><tt>f_write</tt></a> function. Available when <tt><a href="config.html#fs_readonly">FF_FS_READONLY</a> == 0</tt> and <tt><a href="config.html#use_strfunc">FF_USE_STRFUNC</a> &gt;= 1</tt>. When <tt>FF_USE_STRFUNC == 2</tt>, <tt>'\n'</tt>s contained in the input string are output as <tt>'\r'+'\n'</tt> each.</p>
</div>
<div class="para ref">
<h4>See Also</h4>
<p><tt><a href="open.html">f_open</a>, <a href="putc.html">f_putc</a>, <a href="printf.html">f_printf</a>, <a href="gets.html">f_gets</a>, <a href="close.html">f_close</a>, <a href="sfile.html">FIL</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,130 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/rc.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - API Return Code</title>
</head>
<body>
<h1>Return Code of API Functions</h1>
<p>Most of API functions return common result code in enum type <tt>FRESULT</tt>. When an API function succeeded, it returns zero (<tt>FR_OK</tt>), otherwise it returns non-zero value indicates type of error.</p>
<dl class="ret">
<dt id="ok">FR_OK (0)</dt>
<dd>The function succeeded.</dd>
<dt id="de">FR_DISK_ERR</dt>
<dd>The lower layer, <tt>disk_read</tt>, <tt>disk_write</tt> or <tt>disk_ioctl</tt> function, reported that an unrecoverable hard error occured.<br>Note that if once this error occured at any operation to an open file, the file object is aborted and any operations to the file except for close will be rejected.</dd>
<dt id="ie">FR_INT_ERR</dt>
<dd>Assertion failed. An insanity is detected in the internal process. One of the following possibilities is suspected.
<ul>
<li>Work area (file system object, file object or etc...) has been broken by stack overflow or any other tasks. This is the reason in most case.</li>
<li>There is an error of the FAT structure on the volume.</li>
<li>There is a bug in the FatFs module itself.</li>
<li>Wrong lower layer implementation.</li>
</ul>
Note that if once this error occured at any operation to an open file, the file object is aborted and all operations to the file except for close will be rejected.
</dd>
<dt id="nr">FR_NOT_READY</dt>
<dd>The lower layer, <a href="dinit.html"><tt>disk_initialize</tt></a> function, reported that the storage device could not be got ready to work. One of the following possibilities is suspected.
<ul>
<li>No medium in the drive.</li>
<li>Wrong lower layer implementation.</li>
<li>Wrong hardware configuration.</li>
<li>The storage device has broken.</li>
</ul>
</dd>
<dt id="nf">FR_NO_FILE</dt>
<dd>Could not find the file in the directory.</dd>
<dt id="np">FR_NO_PATH</dt>
<dd>Could not find the path. A directory in the path name could not be found.</dd>
<dt id="in">FR_INVALID_NAME</dt>
<dd>The given string is invalid as the <a href="filename.html">path name</a>. One of the following possibilities is suspected.
<ul>
<li>There is a character not allowed for the file name.</li>
<li>The file name is out of 8.3 format. (at non-LFN cfg.)</li>
<li><tt>FF_MAX_LFN</tt> is insufficient for the file name. (at LFN cfg.)</li>
<li>There is any character encoding error in the string.</li>
</ul>
</dd>
<dt id="dn">FR_DENIED</dt>
<dd>The required access was denied due to one of the following reasons:
<ul>
<li>Write mode open against the read-only file.</li>
<li>Deleting the read-only file or directory.</li>
<li>Deleting the non-empty directory or current directory.</li>
<li>Reading the file opened without <tt>FA_READ</tt> flag.</li>
<li>Any modification to the file opened without <tt>FA_WRITE</tt> flag.</li>
<li>Could not create the object due to root directory full or disk full.</li>
<li>Could not allocate a contiguous area to the file.</li>
</ul>
</dd>
<dt id="ex">FR_EXIST</dt>
<dd>Name collision. An object with the same name is already existing in the directory.</dd>
<dt id="io">FR_INVALID_OBJECT</dt>
<dd>The file/directory object is invalid or a null pointer is given. There are some reasons as follows:
<ul>
<li>It has been closed, or the structure has been collapsed.</li>
<li>It has been invalidated. Open objects on the volume are invalidated by voulme mount process.</li>
<li>Physical drive is not ready to work due to a media removal.</li>
</ul>
</dd>
<dt id="wp">FR_WRITE_PROTECTED</dt>
<dd>A write mode operation against the write-protected media.</dd>
<dt id="id">FR_INVALID_DRIVE</dt>
<dd>Invalid drive number is specified in the path name or a null pointer is given as the path name. (Related option: <tt><a href="config.html#volumes">FF_VOLUMES</a></tt>)</dd>
<dt id="ne">FR_NOT_ENABLED</dt>
<dd>Work area for the logical drive has not been registered by <tt>f_mount</tt> function.</dd>
<dt id="ns">FR_NO_FILESYSTEM</dt>
<dd>There is no valid FAT volume on the drive or wrong lower layer implementation.</dd>
<dt id="ma">FR_MKFS_ABORTED</dt>
<dd>The <tt>f_mkfs</tt> function aborted before start in format due to a reason as follows:
<ul>
<li>It is impossible to format with the given parameters.</li>
<li>The size of volume is too small. 128 sectors minimum with <tt>FM_SFD</tt> option.</li>
<li>The partition bound to the logical drive coulud not be found. (Related option: <tt><a href="config.html#multi_partition">FF_MULTI_PARTITION</a></tt>)</li>
</ul>
</dd>
<dt id="tm">FR_TIMEOUT</dt>
<dd>The function was canceled due to a timeout of <a href="appnote.html#reentrant">thread-safe control</a>. (Related option: <tt><a href="config.html#timeout">FF_TIMEOUT</a></tt>)</dd>
<dt id="lo">FR_LOCKED</dt>
<dd>The operation to the object was rejected by <a href="appnote.html#dup">file sharing control</a>. (Related option: <tt><a href="config.html#fs_lock">FF_FS_LOCK</a></tt>)</dd>
<dt id="nc">FR_NOT_ENOUGH_CORE</dt>
<dd>Not enough memory for the operation. There is one of the following reasons:
<ul>
<li>Could not allocate a memory for LFN working buffer. (Related option: <tt><a href="config.html#use_lfn">FF_USE_LFN</a></tt>)</li>
<li>Size of the given buffer is insufficient for the size required.</li>
</ul>
</dd>
<dt id="tf">FR_TOO_MANY_OPEN_FILES</dt>
<dd>Number of open objects has been reached maximum value and no more object can be opened. (Related option: <tt><a href="config.html#fs_lock">FF_FS_LOCK</a></tt>)</dd>
<dt id="ip">FR_INVALID_PARAMETER</dt>
<dd>The given parameter is invalid or there is an inconsistent for the volume.</dd>
</dl>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,74 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/read.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_read</title>
</head>
<body>
<div class="para func">
<h2>f_read</h2>
<p>The f_read function reads data from a file.</p>
<pre>
FRESULT f_read (
FIL* <span class="arg">fp</span>, <span class="c">/* [IN] File object */</span>
void* <span class="arg">buff</span>, <span class="c">/* [OUT] Buffer to store read data */</span>
UINT <span class="arg">btr</span>, <span class="c">/* [IN] Number of bytes to read */</span>
UINT* <span class="arg">br</span> <span class="c">/* [OUT] Number of bytes read */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>fp</dt>
<dd>Pointer to the open file object.</dd>
<dt>buff</dt>
<dd>Pointer to the buffer to store the read data.</dd>
<dt>btr</dt>
<dd>Number of bytes to read in range of <tt>UINT</tt> type.</dd>
<dt>br</dt>
<dd>Pointer to the <tt>UINT</tt> variable that receives number of bytes read. This value is always valid after the function call regardless of the function return code. If the return value is equal to <tt class="arg">btr</tt>, the function return code should be <tt>FR_OK</tt>.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>
<a href="rc.html#ok">FR_OK</a>,
<a href="rc.html#de">FR_DISK_ERR</a>,
<a href="rc.html#ie">FR_INT_ERR</a>,
<a href="rc.html#dn">FR_DENIED</a>,
<a href="rc.html#io">FR_INVALID_OBJECT</a>,
<a href="rc.html#tm">FR_TIMEOUT</a>
</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>The function starts to read data from the file at the file offset pointed by read/write pointer. The read/write pointer advances as number of bytes read. After the function succeeded, <tt class="arg">*br</tt> should be checked to detect end of the file. In case of <tt class="arg">*br</tt> &lt; <tt class="arg">btr</tt>, it means the read/write pointer reached end of the file during read operation.</p>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>Always available.</p>
</div>
<div class="para ref">
<h4>See Also</h4>
<p><tt><a href="open.html">f_open</a>, <a href="gets.html">fgets</a>, <a href="write.html">f_write</a>, <a href="close.html">f_close</a>, <a href="sfile.html">FIL</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,130 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/readdir.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_readdir</title>
</head>
<body>
<div class="para func">
<h2>f_readdir</h2>
<p>The f_readdir function reads an item of the directory.</p>
<pre>
FRESULT f_readdir (
DIR* <span class="arg">dp</span>, <span class="c">/* [IN] Directory object */</span>
FILINFO* <span class="arg">fno</span> <span class="c">/* [OUT] File information structure */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>dp</dt>
<dd>Pointer to the open directory object.</dd>
<dt>fno</dt>
<dd>Pointer to the <a href="sfileinfo.html">file information structure</a> to store the information about read item. A null pointer rewinds the read index of the directory.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>
<a href="rc.html#ok">FR_OK</a>,
<a href="rc.html#de">FR_DISK_ERR</a>,
<a href="rc.html#ie">FR_INT_ERR</a>,
<a href="rc.html#io">FR_INVALID_OBJECT</a>,
<a href="rc.html#tm">FR_TIMEOUT</a>,
<a href="rc.html#nc">FR_NOT_ENOUGH_CORE</a>
</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>The <tt>f_readdir</tt> function reads a directory item, informations about the object. Items in the directory can be read in sequence by <tt>f_readdir</tt> function calls. Dot entries (<tt>"."</tt> and <tt>".."</tt>) in the sub-directory are filtered out and they will never appear in the read items. When all directory items have been read and no item to read, a null string is stored into the <tt>fno-&gt;fname[]</tt> without any error. When a null pointer is given to the <tt class="arg">fno</tt>, the read index of the directory object is rewinded.</p>
<p>When support of long file name (LFN) is enabled, a member <tt>altname[]</tt> is defined in the file information structure to store the short file name of the object. If the long file name is not accessible due to some reason listed below, short file name is stored to the <tt>fname[]</tt> and <tt>altname[]</tt> has a null string.</p>
<ul>
<li>The item has no LFN. (Not the case at exFAT volume)</li>
<li>Setting of <a href="config.html#max_lfn"><tt>FF_MAX_LFN</tt></a> is insufficient to handle the LFN. (Not the case at <tt>FF_MAX_LFN == 255</tt>)</li>
<li>Setting of <a href="config.html#lfn_buf"><tt>FF_LFN_BUF</tt></a> is insufficient to store the LFN.</li>
<li>The LFN contains some character not defined in current code page. (Not the case at <tt>FF_LFN_UNICODE &gt;= 1</tt>)</li>
</ul>
<p>There is a problem on reading a directory of exFAT volume. The exFAT does not support short file name. This means no name can be returned on the condition above. If it is the case, "?" is returned into the <tt>fname[]</tt> to indicate that the object is not accessible. To avoid this problem, configure FatFs <tt><a href="config.html#lfn_unicode">FF_LFN_UNICODE</a> &gt;= 1</tt> and <tt>FF_MAX_LFN == 255</tt> to support the full feature of LFN specification.</p>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>Available when <tt><a href="config.html#fs_minimize">FF_FS_MINIMIZE</a> &lt;= 1</tt>.</p>
</div>
<div class="para use">
<h4>Sample Code</h4>
<pre>
FRESULT scan_files (
char* path <span class="c">/* Start node to be scanned (***also used as work area***) */</span>
)
{
FRESULT res;
DIR dir;
UINT i;
static FILINFO fno;
res = f_opendir(&amp;dir, path); <span class="c">/* Open the directory */</span>
if (res == FR_OK) {
for (;;) {
res = <em>f_readdir</em>(&amp;dir, &amp;fno); <span class="c">/* Read a directory item */</span>
if (res != FR_OK || fno.fname[0] == 0) break; <span class="c">/* Break on error or end of dir */</span>
if (fno.fattrib &amp; AM_DIR) { <span class="c">/* It is a directory */</span>
i = strlen(path);
sprintf(&amp;path[i], "/%s", fno.fname);
res = scan_files(path); <span class="c">/* Enter the directory */</span>
if (res != FR_OK) break;
path[i] = 0;
} else { <span class="c">/* It is a file. */</span>
printf("%s/%s\n", path, fno.fname);
}
}
f_closedir(&amp;dir)
}
return res;
}
int main (void)
{
FATFS fs;
FRESULT res;
char buff[256];
res = f_mount(&amp;fs, "", 1);
if (res == FR_OK) {
strcpy(buff, "/");
res = scan_files(buff);
}
return res;
}
</pre>
</div>
<div class="para ref">
<h4>See Also</h4>
<p><tt><a href="opendir.html">f_opendir</a>, <a href="closedir.html">f_closedir</a>, <a href="stat.html">f_stat</a>, <a href="sfileinfo.html">FILINFO</a>, <a href="sdir.html">DIR</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,87 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/rename.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_rename</title>
</head>
<body>
<div class="para func">
<h2>f_rename</h2>
<p>The f_rename function renames and/or moves a file or sub-directory.</p>
<pre>
FRESULT f_rename (
const TCHAR* <span class="arg">old_name</span>, <span class="c">/* [IN] Old object name */</span>
const TCHAR* <span class="arg">new_name</span> <span class="c">/* [IN] New object name */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>old_name</dt>
<dd>Pointer to a null-terminated string that specifies the existing <a href="filename.html">file or sub-directory</a> to be renamed.</dd>
<dt>new_name</dt>
<dd>Pointer to a null-terminated string that specifies the new object name. A drive number may be specified in this string but it is ignored and assumed as the same drive of the <tt class="arg">old_name</tt>. Any object with this path name except <tt class="arg">old_name</tt> must not be exist, or the function fails with <tt>FR_EXIST</tt>.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>
<a href="rc.html#ok">FR_OK</a>,
<a href="rc.html#de">FR_DISK_ERR</a>,
<a href="rc.html#ie">FR_INT_ERR</a>,
<a href="rc.html#nr">FR_NOT_READY</a>,
<a href="rc.html#ok">FR_NO_FILE</a>,
<a href="rc.html#np">FR_NO_PATH</a>,
<a href="rc.html#in">FR_INVALID_NAME</a>,
<a href="rc.html#ex">FR_EXIST</a>,
<a href="rc.html#wp">FR_WRITE_PROTECTED</a>,
<a href="rc.html#id">FR_INVALID_DRIVE</a>,
<a href="rc.html#ne">FR_NOT_ENABLED</a>,
<a href="rc.html#ns">FR_NO_FILESYSTEM</a>,
<a href="rc.html#tm">FR_TIMEOUT</a>,
<a href="rc.html#lo">FR_LOCKED</a>,
<a href="rc.html#nc">FR_NOT_ENOUGH_CORE</a>
</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>Renames a file or sub-directory and can also move it to other directory in the same volume. The object to be renamed must not be an open object, or <em>the FAT volume can be collapsed</em>. Such the wrong operation is rejected safely when <a href="appnote.html#dup">file lock function</a> is enabled.</p>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>Available when <tt><a href="config.html#fs_readonly">FF_FS_READONLY</a> == 0</tt> and <tt><a href="config.html#fs_minimize">FF_FS_MINIMIZE</a> == 0</tt>.</p>
</div>
<div class="para use">
<h4>Example</h4>
<pre>
<span class="c">/* Rename an object in the default drive */</span>
<em>f_rename</em>("oldname.txt", "newname.txt");
<span class="c">/* Rename an object in the drive 2 */</span>
<em>f_rename</em>("2:oldname.txt", "newname.txt");
<span class="c">/* Rename an object and move it to another directory in the drive */</span>
<em>f_rename</em>("log.txt", "old/log0001.txt");
</pre>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,38 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/sdir.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - DIR</title>
</head>
<body>
<div class="para">
<h2>DIR</h2>
<p>The <tt>DIR</tt> structure is used for the work area to read a directory by <tt>f_oepndir</tt>, <tt>f_readdir</tt>, <tt>f_findfirst</tt> and <tt>f_findnext</tt> function. Application program <em>must not</em> modify any member in this structure, or <tt>f_readdir</tt> function will not work properly.</p>
<pre>
<span class="k">typedef</span> <span class="k">struct</span> {
FFOBJID obj; <span class="c">/* Object identifier */</span>
DWORD dptr; <span class="c">/* Current read/write offset */</span>
DWORD clust; <span class="c">/* Current cluster */</span>
LBA_t sect; <span class="c">/* Current sector */</span>
BYTE* dir; <span class="c">/* Pointer to the current SFN entry in the win[] */</span>
BYTE* fn; <span class="c">/* Pointer to the SFN buffer (in/out) {file[8],ext[3],status[1]} */</span>
<span class="k">#if</span> FF_USE_LFN
DWORD blk_ofs; <span class="c">/* Offset of the entry block (0xFFFFFFFF:Invalid) */</span>
WCHAR* lfn; <span class="c">/* Pointer to the LFN working buffer (in/out) */</span>
<span class="k">#endif</span>
<span class="k">#if</span> FF_USE_FIND
const TCHAR* pat; <span class="c">/* Ponter to the matching pattern */</span>
<span class="k">#endif</span>
} DIR;
</pre>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,82 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/getcwd.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_setcp</title>
</head>
<body>
<div class="para func">
<h2>f_setcp</h2>
<p>The f_setcp function sets the active code page.</p>
<pre>
FRESULT f_setcp (
WORD <span class="arg">cp</span> <span class="c">/* [IN] Code page to be set */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>cp</dt>
<dd>OEM code page to be used for the path name. Valid values are as follows.<br>
<table class="lst1">
<tr><th>Value</th><th>Meaning</th></tr>
<tr><td>0</td><td>Initial value (any extended character cannot be used)</td></tr>
<tr><td>437</td><td>U.S.</td></tr>
<tr><td>720</td><td>Arabic</td></tr>
<tr><td>737</td><td>Greek</td></tr>
<tr><td>771</td><td>KBL</td></tr>
<tr><td>775</td><td>Baltic</td></tr>
<tr><td>850</td><td>Latin 1</td></tr>
<tr><td>852</td><td>Latin 2</td></tr>
<tr><td>855</td><td>Cyrillic</td></tr>
<tr><td>857</td><td>Turkish</td></tr>
<tr><td>860</td><td>Portuguese</td></tr>
<tr><td>861</td><td>Icelandic</td></tr>
<tr><td>862</td><td>Hebrew</td></tr>
<tr><td>863</td><td>Canadian French</td></tr>
<tr><td>864</td><td>Arabic</td></tr>
<tr><td>865</td><td>Nordic</td></tr>
<tr><td>866</td><td>Russian</td></tr>
<tr><td>869</td><td>Greek 2</td></tr>
<tr><td>932</td><td>Japanese (DBCS)</td></tr>
<tr><td>936</td><td>Simplified Chinese (DBCS)</td></tr>
<tr><td>949</td><td>Korean (DBCS)</td></tr>
<tr><td>950</td><td>Traditional Chinese (DBCS)</td></tr>
</table>
</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>
<a href="rc.html#ok">FR_OK</a>,
<a href="rc.html#ip">FR_INVALID_PARAMETER</a>
</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>The <tt>f_setcp</tt> function sets the active code page for the path name. Also code conversion of string functions will be affected by the setting of code page when <tt><a href="config.html#lfn_unicode">FF_LFN_UNICODE</a> &gt;= 1</tt> and <tt><a href="config.html#strf_encode">FF_STRF_ENCODE</a> == 0</tt>. Because the initial setting of the code page is 0 and API function with extended character will not work properly, a valid code page needs to be set on the system start-up and it should not be changed on the fly.</p>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>Available when <tt><a href="config.html#code_page">FF_CODE_PAGE</a> == 0</tt>.</p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,92 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/setlabel.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_setlabel</title>
</head>
<body>
<div class="para func">
<h2>f_setlabel</h2>
<p>The f_setlabel function sets/removes the label of a volume.</p>
<pre>
FRESULT f_setlabel (
const TCHAR* <span class="arg">label</span> <span class="c">/* [IN] Volume label to be set */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>label</dt>
<dd>Pointer to the null-terminated string that specifies the volume label to be set.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>
<a href="rc.html#ok">FR_OK</a>,
<a href="rc.html#de">FR_DISK_ERR</a>,
<a href="rc.html#ie">FR_INT_ERR</a>,
<a href="rc.html#nr">FR_NOT_READY</a>,
<a href="rc.html#in">FR_INVALID_NAME</a>,
<a href="rc.html#wp">FR_WRITE_PROTECTED</a>,
<a href="rc.html#id">FR_INVALID_DRIVE</a>,
<a href="rc.html#ne">FR_NOT_ENABLED</a>,
<a href="rc.html#ns">FR_NO_FILESYSTEM</a>,
<a href="rc.html#tm">FR_TIMEOUT</a>
</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>When the string has a drive prefix, the volume label will be set to the volume specified by the drive prefix. Unix style volume ID cannot be used to specify the volume. If drive number is not specified, the volume label will be set to the default drive. If length of the given volume label is zero, the volume label on the volume will be removed. The format of the volume label is as shown below:</p>
<ul>
<li>Up to 11 bytes long as conversion of OEM code page at FAT volume.</li>
<li>Up to 11 characters long at exFAT volume.</li>
<li>Allowable characters for FAT volume are: characters allowed for SFN excludes dot. Low-case characters are up converted.</li>
<li>Allowable characters for exFAT volume are: characters allowed for LFN includes dot. Low-case characters are preserved.</li>
<li>Spaces can be embedded anywhere in the volume label. Trailing spaces are truncated off at FAT volume.</li>
</ul>
<p>Remark: The standard system (Windows) has a problem at the volume label with a heading <tt>\xE5</tt> on the FAT volume. To avoid this problem, this function rejects such volume label as invalid name.</p>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>Available when <tt><a href="config.html#fs_readonly">FF_FS_READONLY</a> == 0</tt> and <tt><a href="config.html#use_label">FF_USE_LABEL</a> == 1</tt>.</p>
</div>
<div class="para use">
<h4>Example</h4>
<pre>
<span class="c">/* Set volume label to the default drive */</span>
<em>f_setlabel</em>("DATA DISK");
<span class="c">/* Set volume label to the drive 2 */</span>
<em>f_setlabel</em>("2:DISK 3 OF 4");
<span class="c">/* Remove volume label of the drive 2 */</span>
<em>f_setlabel</em>("2:");
</pre>
</div>
<div class="para ref">
<h4>See Also</h4>
<tt><a href="getlabel.html">f_getlabel</a></tt>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,62 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/sfatfs.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - FATFS</title>
</head>
<body>
<div class="para">
<h2>FATFS</h2>
<p>The <tt>FATFS</tt> structure (filesystem object) holds dynamic work area of individual logical drives. It is given by application program and registerd/unregisterd to the FatFs module with <tt>f_mount</tt> function. Initialization of the structure is done by volume mount process whenever necessary. Application program <em>must not</em> modify any member in this structure, or the FAT volume will be collapsed.</p>
<pre>
<span class="k">typedef</span> <span class="k">struct</span> {
BYTE fs_type; <span class="c">/* FAT type (0, FS_FAT12, FS_FAT16, FS_FAT32 or FS_EXFAT) */</span>
BYTE pdrv; <span class="c">/* Hosting physical drive of this volume */</span>
BYTE n_fats; <span class="c">/* Number of FAT copies (1,2) */</span>
BYTE wflag; <span class="c">/* win[] flag (b0:win[] is dirty) */</span>
BYTE fsi_flag; <span class="c">/* FSINFO flags (b7:Disabled, b0:Dirty) */</span>
WORD id; <span class="c">/* Volume mount ID */</span>
WORD n_rootdir; <span class="c">/* Number of root directory entries (FAT12/16) */</span>
WORD csize; <span class="c">/* Sectors per cluster */</span>
<span class="k">#if</span> FF_MAX_SS != FF_MIN_SS
WORD ssize; <span class="c">/* Sector size (512,1024,2048 or 4096) */</span>
<span class="k">#endif</span>
<span class="k">#if</span> FF_FS_EXFAT
BYTE* dirbuf; <span class="c">/* Directory entry block scratchpad buffer */</span>
<span class="k">#endif</span>
<span class="k">#if</span> FF_FS_REENTRANT
FF_SYNC_t sobj; <span class="c">/* Identifier of sync object */</span>
<span class="k">#endif</span>
<span class="k">#if</span> !FF_FS_READONLY
DWORD last_clust; <span class="c">/* FSINFO: Last allocated cluster (0xFFFFFFFF if invalid) */</span>
DWORD free_clust; <span class="c">/* FSINFO: Number of free clusters (0xFFFFFFFF if invalid) */</span>
<span class="k">#endif</span>
<span class="k">#if</span> FF_FS_RPATH
DWORD cdir; <span class="c">/* Cluster number of current directory (0:root) */</span>
<span class="k">#if</span> FF_FS_EXFAT
DWORD cdc_scl; <span class="c">/* Containing directory start cluster (invalid when cdir is 0) */</span>
DWORD cdc_size; <span class="c">/* b31-b8:Size of containing directory, b7-b0: Chain status */</span>
DWORD cdc_ofs; <span class="c">/* Offset in the containing directory (invalid when cdir is 0) */</span>
<span class="k">#endif</span>
<span class="k">#endif</span>
DWORD n_fatent; <span class="c">/* Number of FAT entries (Number of clusters + 2) */</span>
DWORD fsize; <span class="c">/* Sectors per FAT */</span>
LBA_t volbase; <span class="c">/* Volume base LBA */</span>
LBA_t fatbase; <span class="c">/* FAT base LBA */</span>
LBA_t dirbase; <span class="c">/* Root directory base (LBA|Cluster) */</span>
LBA_t database; <span class="c">/* Data base LBA */</span>
LBA_t winsect; <span class="c">/* Sector LBA appearing in the win[] */</span>
BYTE win[FF_MAX_SS]; <span class="c">/* Disk access window for directory, FAT (and file data at tiny cfg) */</span>
} FATFS;
</pre>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,43 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/sfile.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - FIL</title>
</head>
<body>
<div class="para">
<h2>FIL</h2>
<p>The <tt>FIL</tt> structure (file object) holds the state of an open file. It is created by <tt>f_open</tt> function and discarded by <tt>f_close</tt> function. Application program <em>must not</em> modify any member in this structure except for <tt>cltbl</tt>, or the FAT volume will be collapsed. Note that a sector buffer is defined in this structure at non-tiny configuration (<tt><a href="config.html#fs_tiny">FF_FS_TINY</a> == 0</tt>), so that the <tt>FIL</tt> structures at that configuration should not be defined as auto variable.</p>
<pre>
<span class="k">typedef</span> <span class="k">struct</span> {
FFOBJID obj; <span class="c">/* Object identifier */</span>
BYTE flag; <span class="c">/* File object status flags */</span>
BYTE err; <span class="c">/* Abort flag (error code) */</span>
FSIZE_t fptr; <span class="c">/* File read/write pointer (Byte offset origin from top of the file) */</span>
DWORD clust; <span class="c">/* Current cluster of fptr (One cluster behind if fptr is on the cluster boundary. Invalid if fptr == 0.) */</span>
LBA_t sect; <span class="c">/* Current data sector (Can be invalid if fptr is on the cluster boundary.)*/</span>
<span class="k">#if</span> !FF_FS_READONLY
LBA_t dir_sect; <span class="c">/* Sector number containing the directory entry */</span>
BYTE* dir_ptr; <span class="c">/* Ponter to the directory entry in the window */</span>
<span class="k">#endif</span>
<span class="k">#if</span> FF_USE_FASTSEEK
DWORD* cltbl; <span class="c">/* Pointer to the cluster link map table (Nulled on file open. Set by application.) */</span>
<span class="k">#endif</span>
<span class="k">#if</span> !FF_FS_TINY
BYTE buf[FF_MAX_SS]; <span class="c">/* File private data transfer buffer (Always valid if fptr is not on the sector boundary but can be invalid if fptr is on the sector boundary.) */</span>
<span class="k">#endif</span>
} FIL;
</pre>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,78 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/sfileinfo.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - FILINFO</title>
</head>
<body>
<div class="para">
<h2>FILINFO</h2>
<p>The <tt>FILINFO</tt> structure holds information about the object retrieved by <tt>f_readdir</tt>, <tt>f_findfirst</tt>, <tt>f_findnext</tt> and <tt>f_stat</tt> function. Be careful in the size of structure when LFN is enabled.</p>
<pre>
<span class="k">typedef struct</span> {
FSIZE_t fsize; <span class="c">/* File size */</span>
WORD fdate; <span class="c">/* Last modified date */</span>
WORD ftime; <span class="c">/* Last modified time */</span>
BYTE fattrib; <span class="c">/* Attribute */</span>
<span class="k">#if</span> FF_USE_LFN
TCHAR altname[FF_SFN_BUF + 1]; <span class="c">/* Alternative object name */</span>
TCHAR fname[FF_LFN_BUF + 1]; <span class="c">/* Primary object name */</span>
<span class="k">#else</span>
TCHAR fname[12 + 1]; <span class="c">/* Object name */</span>
<span class="k">#endif</span>
} FILINFO;
</pre>
</div>
<h4>Members</h4>
<dl>
<dt>fsize</dt>
<dd>Size of the file in unit of byte. <tt>FSIZE_t</tt> is an alias of integer type either <tt>DWORD</tt>(32-bit) or <tt>QWORD</tt>(64-bit) depends on the configuration option <tt>FF_FS_EXFAT</tt>. Do not care if the item is a sub-directory.</dd>
<dt>fdate</dt>
<dd>The date when the file was modified or the directory was created.<br>
<dl>
<dt>bit15:9</dt>
<dd>Year origin from 1980 (0..127)</dd>
<dt>bit8:5</dt>
<dd>Month (1..12)</dd>
<dt>bit4:0</dt>
<dd>Day (1..31)</dd>
</dl>
</dd>
<dt>ftime</dt>
<dd>The time when the file was modified or the directory was created.<br>
<dl>
<dt>bit15:11</dt>
<dd>Hour (0..23)</dd>
<dt>bit10:5</dt>
<dd>Minute (0..59)</dd>
<dt>bit4:0</dt>
<dd>Second / 2 (0..29)</dd>
</dl>
</dd>
<dt>fattrib</dt>
<dd>The attribute flags in combination of:<br>
<table class="lst">
<tr><th>Flag</th><th>Meaning</th></tr>
<tr><td>AM_RDO</td><td>Read-only. Write mode open and deleting is rejected.</td></tr>
<tr><td>AM_HID</td><td>Hidden. Should not be shown in normal directory listing.</td></tr>
<tr><td>AM_SYS</td><td>System. Used by system and should not be accessed.</td></tr>
<tr><td>AM_ARC</td><td>Archive. Set on new creation or any modification to the file.</td></tr>
<tr><td>AM_DIR</td><td>Directory. This is not a file but a sub-directory container.</td></tr>
</table>
</dd>
<dt>fname[]</dt>
<dd>Null-terminated object name. A null string is stored when no item to read and it indicates this structure is invalid. The size of <tt>fname[]</tt> and <tt>altname[]</tt> each can be configured at LFN configuration.</dd>
<dt>altname[]</dt>
<dd>Alternative object name is stored if available. This member is not available in non-LFN configuration.</dd>
</dl>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,62 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/size.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_size</title>
</head>
<body>
<div class="para func">
<h2>f_size</h2>
<p>The f_size function gets the size of a file.</p>
<pre>
FSIZE_t f_size (
FIL* <span class="arg">fp</span> <span class="c">/* [IN] File object */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>fp</dt>
<dd>Pointer to the open file object structure.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>Returns the size of the file in unit of byte.</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>In this revision, the <tt>f_size</tt> function is implemented as a macro. It does not have any validation and mutual exclusion.</p>
<pre>
<span class="k">#define</span> f_size(fp) ((fp)->obj.objsize)
</pre>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>Always available.</p>
</div>
<div class="para ref">
<h4>See Also</h4>
<p><tt><a href="open.html">f_open</a>, <a href="lseek.html">f_lseek</a>, <a href="sfile.html">FIL</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,110 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/stat.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_stat</title>
</head>
<body>
<div class="para func">
<h2>f_stat</h2>
<p>The f_stat function checks the existence of a file or sub-directory.</p>
<pre>
FRESULT f_stat (
const TCHAR* <span class="arg">path</span>, <span class="c">/* [IN] Object name */</span>
FILINFO* <span class="arg">fno</span> <span class="c">/* [OUT] FILINFO structure */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>path</dt>
<dd>Pointer to the null-terminated string that specifies the <a href="filename.html">object</a> to get its information. The object must not be the root direcotry.</dd>
<dt>fno</dt>
<dd>Pointer to the blank <tt>FILINFO</tt> structure to store the information of the object. Set null pointer if it is not needed.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>
<a href="rc.html#ok">FR_OK</a>,
<a href="rc.html#de">FR_DISK_ERR</a>,
<a href="rc.html#ie">FR_INT_ERR</a>,
<a href="rc.html#nr">FR_NOT_READY</a>,
<a href="rc.html#ok">FR_NO_FILE</a>,
<a href="rc.html#np">FR_NO_PATH</a>,
<a href="rc.html#in">FR_INVALID_NAME</a>,
<a href="rc.html#id">FR_INVALID_DRIVE</a>,
<a href="rc.html#ne">FR_NOT_ENABLED</a>,
<a href="rc.html#ns">FR_NO_FILESYSTEM</a>,
<a href="rc.html#tm">FR_TIMEOUT</a>,
<a href="rc.html#nc">FR_NOT_ENOUGH_CORE</a>
</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>The <tt>f_stat</tt> function checks the existence of a file or sub-directory. If not exist, the function returns with <tt>FR_NO_FILE</tt>. If exist, the function returns with <tt>FR_OK</tt> and the informations about the object, size, timestamp and attribute, is stored to the file information structure. For details of the file information, refer to the <tt>FILINFO</tt> structure and <a href="readdir.html"><tt>f_readdir</tt></a> function.</p>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>Available when <tt><a href="config.html#fs_minimize">FF_FS_MINIMIZE</a> == 0</tt>.</p>
</div>
<div class="para use">
<h4>Example</h4>
<pre>
FRESULT fr;
FILINFO fno;
printf("Test for 'file.txt'...\n");
fr = f_stat("file.txt", &amp;fno);
switch (fr) {
case FR_OK:
printf("Size: %lu\n", fno.fsize);
printf("Timestamp: %u/%02u/%02u, %02u:%02u\n",
(fno.fdate &gt;&gt; 9) + 1980, fno.fdate &gt;&gt; 5 &amp; 15, fno.fdate &amp; 31,
fno.ftime &gt;&gt; 11, fno.ftime &gt;&gt; 5 &amp; 63);
printf("Attributes: %c%c%c%c%c\n",
(fno.fattrib &amp; AM_DIR) ? 'D' : '-',
(fno.fattrib &amp; AM_RDO) ? 'R' : '-',
(fno.fattrib &amp; AM_HID) ? 'H' : '-',
(fno.fattrib &amp; AM_SYS) ? 'S' : '-',
(fno.fattrib &amp; AM_ARC) ? 'A' : '-');
break;
case FR_NO_FILE:
printf("It is not exist.\n");
break;
default:
printf("An error occured. (%d)\n", fr);
}
</pre>
</div>
<div class="para ref">
<h4>References</h4>
<p><tt><a href="opendir.html">f_opendir</a>, <a href="readdir.html">f_readdir</a>, <a href="sfileinfo.html">FILINFO</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,88 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/sync.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_sync</title>
</head>
<body>
<div class="para func">
<h2>f_sync</h2>
<p>The f_sync function flushes the cached information of a writing file.</p>
<pre>
FRESULT f_sync (
FIL* <span class="arg">fp</span> <span class="c">/* [IN] File object */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameter</h4>
<dl class="par">
<dt>fp</dt>
<dd>Pointer to the open file object to be flushed.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>
<a href="rc.html#ok">FR_OK</a>,
<a href="rc.html#de">FR_DISK_ERR</a>,
<a href="rc.html#ie">FR_INT_ERR</a>,
<a href="rc.html#io">FR_INVALID_OBJECT</a>,
<a href="rc.html#tm">FR_TIMEOUT</a>
</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>The <tt>f_sync</tt> function performs the same process as <tt>f_close</tt> function but the file is left opened and can continue read/write/seek operations to the file. This is suitable for the applications that open files for a long time in write mode, such as data logger. Performing <tt>f_sync</tt> function in certain interval can minimize the risk of data loss due to a sudden blackout, wrong media removal or unrecoverable disk error. For more information, refer to <a href="appnote.html#critical">application note</a>.</p>
<pre>
Case 1. Normal write sequence
Time --&gt; ↓Normal shutdown
OwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwC &lt;Power off&gt;
Case 2. Without using f_sync()
Time --&gt; ↓System crush
O<span class="e">wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww</span>
|&lt;--------------- All data written will be lost ------------------&gt;|
Case 3. Using f_sync()
Time --&gt; ↓System crush
OwwwwwwwwSwwwwwwwwSwwwwwwwwSwwwwwwwwSwwwwwwwwSwwwwwwwwSwwwwwwwwS<span class="e">wwwww</span>
Data after last f_sync will be lost |&lt;-&gt;|
O - f_open()
C - f_close()
w - f_write()
S - f_sync()
</pre>
<p>However there is no sense in <tt>f_sync</tt> function immediataly before <tt>f_close</tt> function because it performs <tt>f_sync</tt> function in it. In other words, the differnce between those functions is that the file object is invalidated or not.</p>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>Available when <tt><a href="config.html#fs_readonly">FF_FS_READONLY</a> == 0</tt>.</p>
</div>
<div class="para ref">
<h4>See Also</h4>
<p><tt><a href="close.html">f_close</a></tt>, <a href="appnote.html#critical">Critical section</a></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,62 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/tell.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_tell</title>
</head>
<body>
<div class="para func">
<h2>f_tell</h2>
<p>The f_tell function gets the current read/write pointer of a file.</p>
<pre>
FSIZE_t f_tell (
FIL* <span class="arg">fp</span> <span class="c">/* [IN] File object */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>fp</dt>
<dd>Pointer to the open file object structure.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>Returns current read/write pointer of the file.</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>In this revision, the <tt>f_tell</tt> function is implemented as a macro. It does not have any validation and mutual exclusion.</p>
<pre>
<span class="k">#define</span> f_tell(fp) ((fp)->fptr)
</pre>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>Always available.</p>
</div>
<div class="para ref">
<h4>See Also</h4>
<p><tt><a href="open.html">f_open</a>, <a href="lseek.html">f_lseek</a>, <a href="sfile.html">FIL</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,66 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/truncate.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_truncate</title>
</head>
<body>
<div class="para func">
<h2>f_truncate</h2>
<p>The f_truncate function truncates the file size.</p>
<pre>
FRESULT f_truncate (
FIL* <span class="arg">fp</span> <span class="c">/* [IN] File object */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameter</h4>
<dl class="par">
<dt>fp</dt>
<dd>Pointer to the open file object to be truncated.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>
<a href="rc.html#ok">FR_OK</a>,
<a href="rc.html#de">FR_DISK_ERR</a>,
<a href="rc.html#ie">FR_INT_ERR</a>,
<a href="rc.html#dn">FR_DENIED</a>,
<a href="rc.html#io">FR_INVALID_OBJECT</a>,
<a href="rc.html#tm">FR_TIMEOUT</a>
</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>The <tt>f_truncate</tt> function truncates the file size to the current file read/write pointer. This function has no effect if the file read/write pointer is already pointing end of the file.</p>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>Available when <tt><a href="config.html#fs_readonly">FF_FS_READONLY</a> == 0</tt> and <tt><a href="config.html#fs_minimize">FF_FS_MINIMIZE</a> == 0</tt>.</p>
</div>
<div class="para ref">
<h4>See Also</h4>
<p><tt><a href="open.html">f_open</a>, <a href="lseek.html">f_lseek</a>, <a href="sfile.html">FIL</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,74 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/unlink.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_unlink</title>
</head>
<body>
<div class="para func">
<h2>f_unlink</h2>
<p>The f_unlink function removes a file or sub-directory from the volume.</p>
<pre>
FRESULT f_unlink (
const TCHAR* <span class="arg">path</span> <span class="c">/* [IN] Object name */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameter</h4>
<dl class="par">
<dt>path</dt>
<dd>Pointer to a null-terminated string that specifies the <a href="filename.html">file or sub-directory</a> to be removed.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>
<a href="rc.html#ok">FR_OK</a>,
<a href="rc.html#de">FR_DISK_ERR</a>,
<a href="rc.html#ie">FR_INT_ERR</a>,
<a href="rc.html#nr">FR_NOT_READY</a>,
<a href="rc.html#ok">FR_NO_FILE</a>,
<a href="rc.html#np">FR_NO_PATH</a>,
<a href="rc.html#in">FR_INVALID_NAME</a>,
<a href="rc.html#dn">FR_DENIED</a>,
<a href="rc.html#wp">FR_WRITE_PROTECTED</a>,
<a href="rc.html#id">FR_INVALID_DRIVE</a>,
<a href="rc.html#ne">FR_NOT_ENABLED</a>,
<a href="rc.html#ns">FR_NO_FILESYSTEM</a>,
<a href="rc.html#tm">FR_TIMEOUT</a>,
<a href="rc.html#lo">FR_LOCKED</a>,
<a href="rc.html#nc">FR_NOT_ENOUGH_CORE</a>
</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>
If condition of the object to be removed is applicable to the following terms, the function will be rejected.<ul>
<li>The file/sub-directory must not have read-only attribute (<tt>AM_RDO</tt>), or the function will be rejected with <tt>FR_DENIED</tt>.</li>
<li>The sub-directory must be empty and must not be current directory, or the function will be rejected with <tt>FR_DENIED</tt>.</li>
<li>The file/sub-directory must not be opened, or the <em>FAT volume can be collapsed</em>. It will be rejected safely when <a href="appnote.html#dup">file lock function</a> is enabled.</li>
</ul>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>Available when <tt><a href="config.html#fs_readonly">FF_FS_READONLY</a> == 0</tt> and <tt><a href="config.html#fs_minimize">FF_FS_MINIMIZE</a> == 0</tt>.</p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,99 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/utime.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_utime</title>
</head>
<body>
<div class="para func">
<h2>f_utime</h2>
<p>The f_utime function changes the timestamp of a file or sub-directory.</p>
<pre>
FRESULT f_utime (
const TCHAR* <span class="arg">path</span>, <span class="c">/* [IN] Object name */</span>
const FILINFO* <span class="arg">fno</span> <span class="c">/* [IN] Time and data to be set */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>path</dt>
<dd>Pointer to the null-terminated string that specifies an <a href="filename.html">object</a> to be changed.</dd>
<dt>fno</dt>
<dd>Pointer to the file information structure that has a timestamp to be set in member fdate and ftime. Do not care any other members.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>
<a href="rc.html#ok">FR_OK</a>,
<a href="rc.html#de">FR_DISK_ERR</a>,
<a href="rc.html#ie">FR_INT_ERR</a>,
<a href="rc.html#nr">FR_NOT_READY</a>,
<a href="rc.html#ok">FR_NO_FILE</a>,
<a href="rc.html#np">FR_NO_PATH</a>,
<a href="rc.html#in">FR_INVALID_NAME</a>,
<a href="rc.html#wp">FR_WRITE_PROTECTED</a>,
<a href="rc.html#id">FR_INVALID_DRIVE</a>,
<a href="rc.html#ne">FR_NOT_ENABLED</a>,
<a href="rc.html#ns">FR_NO_FILESYSTEM</a>,
<a href="rc.html#tm">FR_TIMEOUT</a>,
<a href="rc.html#nc">FR_NOT_ENOUGH_CORE</a>
</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>The <tt>f_utime</tt> function changes the timestamp of a file or sub-directory</p>
</div>
<div class="para use">
<h4>Example</h4>
<pre>
FRESULT set_timestamp (
char *obj, <span class="c">/* Pointer to the file name */</span>
int year,
int month,
int mday,
int hour,
int min,
int sec
)
{
FILINFO fno;
fno.fdate = (WORD)(((year - 1980) * 512U) | month * 32U | mday);
fno.ftime = (WORD)(hour * 2048U | min * 32U | sec / 2U);
return <em>f_utime</em>(obj, &amp;fno);
}
</pre>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>Available when <tt><a href="config.html#fs_readonly">FF_FS_READONLY</a> == 0</tt> and <tt><a href="config.html#use_chmod">FF_USE_CHMOD</a> == 1</tt>.</p>
</div>
<div class="para ref">
<h4>See Also</h4>
<p><tt><a href="stat.html">f_stat</a>, <a href="sfileinfo.html">FILINFO</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,74 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="up" title="FatFs" href="../00index_e.html">
<link rel="alternate" hreflang="ja" title="Japanese" href="../ja/write.html">
<link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
<title>FatFs - f_write</title>
</head>
<body>
<div class="para func">
<h2>f_write</h2>
<p>The f_write writes data to a file.</p>
<pre>
FRESULT f_write (
FIL* <span class="arg">fp</span>, <span class="c">/* [IN] Pointer to the file object structure */</span>
const void* <span class="arg">buff</span>, <span class="c">/* [IN] Pointer to the data to be written */</span>
UINT <span class="arg">btw</span>, <span class="c">/* [IN] Number of bytes to write */</span>
UINT* <span class="arg">bw</span> <span class="c">/* [OUT] Pointer to the variable to return number of bytes written */</span>
);
</pre>
</div>
<div class="para arg">
<h4>Parameters</h4>
<dl class="par">
<dt>fp</dt>
<dd>Pointer to the open file object structure.</dd>
<dt>buff</dt>
<dd>Pointer to the data to be written.</dd>
<dt>btw</dt>
<dd>Specifies number of bytes to write in range of <tt>UINT</tt> type.</dd>
<dt>bw</dt>
<dd>Pointer to the <tt>UINT</tt> variable that receives the number of bytes written. This value is always valid after the function call regardless of the function return code. If the return value is equal to <tt class="arg">btw</tt>, the function return code should be <tt>FR_OK</tt>.</dd>
</dl>
</div>
<div class="para ret">
<h4>Return Values</h4>
<p>
<a href="rc.html#ok">FR_OK</a>,
<a href="rc.html#de">FR_DISK_ERR</a>,
<a href="rc.html#ie">FR_INT_ERR</a>,
<a href="rc.html#dn">FR_DENIED</a>,
<a href="rc.html#io">FR_INVALID_OBJECT</a>,
<a href="rc.html#tm">FR_TIMEOUT</a>
</p>
</div>
<div class="para desc">
<h4>Description</h4>
<p>The function starts to write data to the file at the file offset pointed by read/write pointer. The read/write pointer advances as number of bytes written. After the function succeeded, <tt class="arg">*bw</tt> should be checked to detect the disk full. In case of <tt class="arg">*bw</tt> &lt; <tt class="arg">btw</tt>, it means the volume got full during the write operation. The function can take a time when the volume is full or close to full.</p>
</div>
<div class="para comp">
<h4>QuickInfo</h4>
<p>Available when <tt><a href="config.html#fs_readonly">FF_FS_READONLY</a> == 0</tt>.</p>
</div>
<div class="para ref">
<h4>See Also</h4>
<p><tt><a href="open.html">f_open</a>, <a href="read.html">f_read</a>, <a href="putc.html">fputc</a>, <a href="puts.html">fputs</a>, <a href="printf.html">fprintf</a>, <a href="close.html">f_close</a>, <a href="sfile.html">FIL</a></tt></p>
</div>
<p class="foot"><a href="../00index_e.html">Return</a></p>
</body>
</html>

View File

@ -0,0 +1,44 @@
/*------------------------------------------------------------/
/ Open or create a file in append mode
/ (This function was sperseded by FA_OPEN_APPEND flag at FatFs R0.12a)
/------------------------------------------------------------*/
FRESULT open_append (
FIL* fp, /* [OUT] File object to create */
const char* path /* [IN] File name to be opened */
)
{
FRESULT fr;
/* Opens an existing file. If not exist, creates a new file. */
fr = f_open(fp, path, FA_WRITE | FA_OPEN_ALWAYS);
if (fr == FR_OK) {
/* Seek to end of the file to append data */
fr = f_lseek(fp, f_size(fp));
if (fr != FR_OK)
f_close(fp);
}
return fr;
}
int main (void)
{
FRESULT fr;
FATFS fs;
FIL fil;
/* Open or create a log file and ready to append */
f_mount(&fs, "", 0);
fr = open_append(&fil, "logfile.txt");
if (fr != FR_OK) return 1;
/* Append a line */
f_printf(&fil, "%02u/%02u/%u, %2u:%02u\n", Mday, Mon, Year, Hour, Min);
/* Close the file */
f_close(&fil);
return 0;
}

View File

@ -0,0 +1,81 @@
/*------------------------------------------------------------/
/ Delete a sub-directory even if it contains any file
/-------------------------------------------------------------/
/ The delete_node() function is for R0.12+.
/ It works regardless of FF_FS_RPATH.
*/
FRESULT delete_node (
TCHAR* path, /* Path name buffer with the sub-directory to delete */
UINT sz_buff, /* Size of path name buffer (items) */
FILINFO* fno /* Name read buffer */
)
{
UINT i, j;
FRESULT fr;
DIR dir;
fr = f_opendir(&dir, path); /* Open the sub-directory to make it empty */
if (fr != FR_OK) return fr;
for (i = 0; path[i]; i++) ; /* Get current path length */
path[i++] = _T('/');
for (;;) {
fr = f_readdir(&dir, fno); /* Get a directory item */
if (fr != FR_OK || !fno->fname[0]) break; /* End of directory? */
j = 0;
do { /* Make a path name */
if (i + j >= sz_buff) { /* Buffer over flow? */
fr = 100; break; /* Fails with 100 when buffer overflow */
}
path[i + j] = fno->fname[j];
} while (fno->fname[j++]);
if (fno->fattrib & AM_DIR) { /* Item is a sub-directory */
fr = delete_node(path, sz_buff, fno);
} else { /* Item is a file */
fr = f_unlink(path);
}
if (fr != FR_OK) break;
}
path[--i] = 0; /* Restore the path name */
f_closedir(&dir);
if (fr == FR_OK) fr = f_unlink(path); /* Delete the empty sub-directory */
return fr;
}
int main (void) /* How to use */
{
FRESULT fr;
FATFS fs;
TCHAR buff[256];
FILINFO fno;
f_mount(&fs, _T("5:"), 0);
/* Directory to be deleted */
_tcscpy(buff, _T("5:dir"));
/* Delete the directory */
fr = delete_node(buff, sizeof buff / sizeof buff[0], &fno);
/* Check the result */
if (fr) {
_tprintf(_T("Failed to delete the directory. (%u)\n"), fr);
return fr;
} else {
_tprintf(_T("The directory and the contents have successfully been deleted.\n"), buff);
return 0;
}
}

View File

@ -0,0 +1,109 @@
/*----------------------------------------------------------------------/
/ Allocate a contiguous area to the file
/-----------------------------------------------------------------------/
/ This function checks if the file is contiguous with desired size.
/ If not, a block of contiguous sectors is allocated to the file.
/ If the file has been opened without FA_WRITE flag, it only checks if
/ the file is contiguous and returns the resulut.
/-----------------------------------------------------------------------/
/ This function can work with FatFs R0.09 - R0.11a.
/ It is incompatible with R0.12+. Use f_expand function instead.
/----------------------------------------------------------------------*/
/* Declarations of FatFs internal functions accessible from applications.
/ This is intended to be used for disk checking/fixing or dirty hacks :-) */
DWORD clust2sect (FATFS* fs, DWORD clst);
DWORD get_fat (FATFS* fs, DWORD clst);
FRESULT put_fat (FATFS* fs, DWORD clst, DWORD val);
DWORD allocate_contiguous_clusters ( /* Returns the first sector in LBA (0:error or not contiguous) */
FIL* fp, /* Pointer to the open file object */
DWORD len /* Number of bytes to allocate */
)
{
DWORD csz, tcl, ncl, ccl, cl;
if (f_lseek(fp, 0) || !len) /* Check if the given parameters are valid */
return 0;
csz = 512UL * fp->fs->csize; /* Cluster size in unit of byte (assuming 512 bytes/sector) */
tcl = (len + csz - 1) / csz; /* Total number of clusters required */
len = tcl * csz; /* Round-up file size to the cluster boundary */
/* Check if the existing cluster chain is contiguous */
if (len == fp->fsize) {
ncl = 0; ccl = fp->sclust;
do {
cl = get_fat(fp->fs, ccl); /* Get the cluster status */
if (cl + 1 < 3) return 0; /* Hard error? */
if (cl != ccl + 1 && cl < fp->fs->n_fatent) break; /* Not contiguous? */
ccl = cl;
} while (++ncl < tcl);
if (ncl == tcl) /* Is the file contiguous? */
return clust2sect(fp->fs, fp->sclust); /* File is contiguous. Return the start sector */
}
/* File is not contiguous */
#if _FS_READONLY
return 0; /* Exit if in read-only cfg. */
#else
if (!(fp->flag & FA_WRITE)) return 0; /* Exit if the file object is for read-only */
if (f_truncate(fp)) return 0; /* Remove the non-contiguous chain */
/* Find a free contiguous area */
ccl = cl = 2; ncl = 0;
do {
if (cl >= fp->fs->n_fatent) return 0; /* No contiguous area is found. */
if (get_fat(fp->fs, cl)) { /* Encounterd a cluster in use */
do { /* Skip the block of used clusters */
cl++;
if (cl >= fp->fs->n_fatent) return 0; /* No contiguous area is found. */
} while (get_fat(fp->fs, cl));
ccl = cl; ncl = 0;
}
cl++; ncl++;
} while (ncl < tcl);
/* Create a contiguous cluster chain */
fp->fs->last_clust = ccl - 1;
if (f_lseek(fp, len)) return 0;
return clust2sect(fp->fs, fp->sclust); /* Return file start sector */
#endif
}
int main (void)
{
FRESULT fr;
DRESULT dr;
FATFS fs;
FIL fil;
DWORD org;
/* Open or create a file to write */
f_mount(&fs, "", 0);
fr = f_open(&fil, "fastrec.log", FA_READ | FA_WRITE | FA_OPEN_ALWAYS);
if (fr) return 1;
/* Check if the file is 256MB in size and occupies a contiguous area.
/ If not, a contiguous area will be re-allocated to the file. */
org = allocate_contiguous_clusters(&fil, 0x10000000);
if (!org) {
printf("Function failed due to any error or insufficient contiguous area.\n");
f_close(&fil);
return 1;
}
/* Now you can read/write the file without filesystem layer. */
...
dr = disk_write(fil.fs->drv, Buff, org, 1024); /* Write 512KiB from top of the file */
...
f_close(&fil);
return 0;
}

View File

@ -0,0 +1,315 @@
/*----------------------------------------------------------------------/
/ Low level disk I/O module function checker /
/-----------------------------------------------------------------------/
/ WARNING: The data on the target drive will be lost!
*/
#include <stdio.h>
#include <string.h>
#include "ff.h" /* Declarations of sector size */
#include "diskio.h" /* Declarations of disk functions */
static DWORD pn ( /* Pseudo random number generator */
DWORD pns /* 0:Initialize, !0:Read */
)
{
static DWORD lfsr;
UINT n;
if (pns) {
lfsr = pns;
for (n = 0; n < 32; n++) pn(0);
}
if (lfsr & 1) {
lfsr >>= 1;
lfsr ^= 0x80200003;
} else {
lfsr >>= 1;
}
return lfsr;
}
int test_diskio (
BYTE pdrv, /* Physical drive number to be checked (all data on the drive will be lost) */
UINT ncyc, /* Number of test cycles */
DWORD* buff, /* Pointer to the working buffer */
UINT sz_buff /* Size of the working buffer in unit of byte */
)
{
UINT n, cc, ns;
DWORD sz_drv, lba, lba2, sz_eblk, pns = 1;
WORD sz_sect;
BYTE *pbuff = (BYTE*)buff;
DSTATUS ds;
DRESULT dr;
printf("test_diskio(%u, %u, 0x%08X, 0x%08X)\n", pdrv, ncyc, (UINT)buff, sz_buff);
if (sz_buff < FF_MAX_SS + 8) {
printf("Insufficient work area to run the program.\n");
return 1;
}
for (cc = 1; cc <= ncyc; cc++) {
printf("**** Test cycle %u of %u start ****\n", cc, ncyc);
printf(" disk_initalize(%u)", pdrv);
ds = disk_initialize(pdrv);
if (ds & STA_NOINIT) {
printf(" - failed.\n");
return 2;
} else {
printf(" - ok.\n");
}
printf("**** Get drive size ****\n");
printf(" disk_ioctl(%u, GET_SECTOR_COUNT, 0x%08X)", pdrv, (UINT)&sz_drv);
sz_drv = 0;
dr = disk_ioctl(pdrv, GET_SECTOR_COUNT, &sz_drv);
if (dr == RES_OK) {
printf(" - ok.\n");
} else {
printf(" - failed.\n");
return 3;
}
if (sz_drv < 128) {
printf("Failed: Insufficient drive size to test.\n");
return 4;
}
printf(" Number of sectors on the drive %u is %lu.\n", pdrv, sz_drv);
#if FF_MAX_SS != FF_MIN_SS
printf("**** Get sector size ****\n");
printf(" disk_ioctl(%u, GET_SECTOR_SIZE, 0x%X)", pdrv, (UINT)&sz_sect);
sz_sect = 0;
dr = disk_ioctl(pdrv, GET_SECTOR_SIZE, &sz_sect);
if (dr == RES_OK) {
printf(" - ok.\n");
} else {
printf(" - failed.\n");
return 5;
}
printf(" Size of sector is %u bytes.\n", sz_sect);
#else
sz_sect = FF_MAX_SS;
#endif
printf("**** Get block size ****\n");
printf(" disk_ioctl(%u, GET_BLOCK_SIZE, 0x%X)", pdrv, (UINT)&sz_eblk);
sz_eblk = 0;
dr = disk_ioctl(pdrv, GET_BLOCK_SIZE, &sz_eblk);
if (dr == RES_OK) {
printf(" - ok.\n");
} else {
printf(" - failed.\n");
}
if (dr == RES_OK || sz_eblk >= 2) {
printf(" Size of the erase block is %lu sectors.\n", sz_eblk);
} else {
printf(" Size of the erase block is unknown.\n");
}
/* Single sector write test */
printf("**** Single sector write test ****\n");
lba = 0;
for (n = 0, pn(pns); n < sz_sect; n++) pbuff[n] = (BYTE)pn(0);
printf(" disk_write(%u, 0x%X, %lu, 1)", pdrv, (UINT)pbuff, lba);
dr = disk_write(pdrv, pbuff, lba, 1);
if (dr == RES_OK) {
printf(" - ok.\n");
} else {
printf(" - failed.\n");
return 6;
}
printf(" disk_ioctl(%u, CTRL_SYNC, NULL)", pdrv);
dr = disk_ioctl(pdrv, CTRL_SYNC, 0);
if (dr == RES_OK) {
printf(" - ok.\n");
} else {
printf(" - failed.\n");
return 7;
}
memset(pbuff, 0, sz_sect);
printf(" disk_read(%u, 0x%X, %lu, 1)", pdrv, (UINT)pbuff, lba);
dr = disk_read(pdrv, pbuff, lba, 1);
if (dr == RES_OK) {
printf(" - ok.\n");
} else {
printf(" - failed.\n");
return 8;
}
for (n = 0, pn(pns); n < sz_sect && pbuff[n] == (BYTE)pn(0); n++) ;
if (n == sz_sect) {
printf(" Read data matched.\n");
} else {
printf(" Read data differs from the data written.\n");
return 10;
}
pns++;
printf("**** Multiple sector write test ****\n");
lba = 5; ns = sz_buff / sz_sect;
if (ns > 4) ns = 4;
if (ns > 1) {
for (n = 0, pn(pns); n < (UINT)(sz_sect * ns); n++) pbuff[n] = (BYTE)pn(0);
printf(" disk_write(%u, 0x%X, %lu, %u)", pdrv, (UINT)pbuff, lba, ns);
dr = disk_write(pdrv, pbuff, lba, ns);
if (dr == RES_OK) {
printf(" - ok.\n");
} else {
printf(" - failed.\n");
return 11;
}
printf(" disk_ioctl(%u, CTRL_SYNC, NULL)", pdrv);
dr = disk_ioctl(pdrv, CTRL_SYNC, 0);
if (dr == RES_OK) {
printf(" - ok.\n");
} else {
printf(" - failed.\n");
return 12;
}
memset(pbuff, 0, sz_sect * ns);
printf(" disk_read(%u, 0x%X, %lu, %u)", pdrv, (UINT)pbuff, lba, ns);
dr = disk_read(pdrv, pbuff, lba, ns);
if (dr == RES_OK) {
printf(" - ok.\n");
} else {
printf(" - failed.\n");
return 13;
}
for (n = 0, pn(pns); n < (UINT)(sz_sect * ns) && pbuff[n] == (BYTE)pn(0); n++) ;
if (n == (UINT)(sz_sect * ns)) {
printf(" Read data matched.\n");
} else {
printf(" Read data differs from the data written.\n");
return 14;
}
} else {
printf(" Test skipped.\n");
}
pns++;
printf("**** Single sector write test (unaligned buffer address) ****\n");
lba = 5;
for (n = 0, pn(pns); n < sz_sect; n++) pbuff[n+3] = (BYTE)pn(0);
printf(" disk_write(%u, 0x%X, %lu, 1)", pdrv, (UINT)(pbuff+3), lba);
dr = disk_write(pdrv, pbuff+3, lba, 1);
if (dr == RES_OK) {
printf(" - ok.\n");
} else {
printf(" - failed.\n");
return 15;
}
printf(" disk_ioctl(%u, CTRL_SYNC, NULL)", pdrv);
dr = disk_ioctl(pdrv, CTRL_SYNC, 0);
if (dr == RES_OK) {
printf(" - ok.\n");
} else {
printf(" - failed.\n");
return 16;
}
memset(pbuff+5, 0, sz_sect);
printf(" disk_read(%u, 0x%X, %lu, 1)", pdrv, (UINT)(pbuff+5), lba);
dr = disk_read(pdrv, pbuff+5, lba, 1);
if (dr == RES_OK) {
printf(" - ok.\n");
} else {
printf(" - failed.\n");
return 17;
}
for (n = 0, pn(pns); n < sz_sect && pbuff[n+5] == (BYTE)pn(0); n++) ;
if (n == sz_sect) {
printf(" Read data matched.\n");
} else {
printf(" Read data differs from the data written.\n");
return 18;
}
pns++;
printf("**** 4GB barrier test ****\n");
if (sz_drv >= 128 + 0x80000000 / (sz_sect / 2)) {
lba = 6; lba2 = lba + 0x80000000 / (sz_sect / 2);
for (n = 0, pn(pns); n < (UINT)(sz_sect * 2); n++) pbuff[n] = (BYTE)pn(0);
printf(" disk_write(%u, 0x%X, %lu, 1)", pdrv, (UINT)pbuff, lba);
dr = disk_write(pdrv, pbuff, lba, 1);
if (dr == RES_OK) {
printf(" - ok.\n");
} else {
printf(" - failed.\n");
return 19;
}
printf(" disk_write(%u, 0x%X, %lu, 1)", pdrv, (UINT)(pbuff+sz_sect), lba2);
dr = disk_write(pdrv, pbuff+sz_sect, lba2, 1);
if (dr == RES_OK) {
printf(" - ok.\n");
} else {
printf(" - failed.\n");
return 20;
}
printf(" disk_ioctl(%u, CTRL_SYNC, NULL)", pdrv);
dr = disk_ioctl(pdrv, CTRL_SYNC, 0);
if (dr == RES_OK) {
printf(" - ok.\n");
} else {
printf(" - failed.\n");
return 21;
}
memset(pbuff, 0, sz_sect * 2);
printf(" disk_read(%u, 0x%X, %lu, 1)", pdrv, (UINT)pbuff, lba);
dr = disk_read(pdrv, pbuff, lba, 1);
if (dr == RES_OK) {
printf(" - ok.\n");
} else {
printf(" - failed.\n");
return 22;
}
printf(" disk_read(%u, 0x%X, %lu, 1)", pdrv, (UINT)(pbuff+sz_sect), lba2);
dr = disk_read(pdrv, pbuff+sz_sect, lba2, 1);
if (dr == RES_OK) {
printf(" - ok.\n");
} else {
printf(" - failed.\n");
return 23;
}
for (n = 0, pn(pns); pbuff[n] == (BYTE)pn(0) && n < (UINT)(sz_sect * 2); n++) ;
if (n == (UINT)(sz_sect * 2)) {
printf(" Read data matched.\n");
} else {
printf(" Read data differs from the data written.\n");
return 24;
}
} else {
printf(" Test skipped.\n");
}
pns++;
printf("**** Test cycle %u of %u completed ****\n\n", cc, ncyc);
}
return 0;
}
int main (int argc, char* argv[])
{
int rc;
DWORD buff[FF_MAX_SS]; /* Working buffer (4 sector in size) */
/* Check function/compatibility of the physical drive #0 */
rc = test_diskio(0, 3, buff, sizeof buff);
if (rc) {
printf("Sorry the function/compatibility test failed. (rc=%d)\nFatFs will not work with this disk driver.\n", rc);
} else {
printf("Congratulations! The disk driver works well.\n");
}
return rc;
}

View File

@ -0,0 +1,38 @@
/*----------------------------------------------------------------------/
/ Test if the file is contiguous /
/----------------------------------------------------------------------*/
FRESULT test_contiguous_file (
FIL* fp, /* [IN] Open file object to be checked */
int* cont /* [OUT] 1:Contiguous, 0:Fragmented or zero-length */
)
{
DWORD clst, clsz, step;
FSIZE_t fsz;
FRESULT fr;
*cont = 0;
fr = f_lseek(fp, 0); /* Validates and prepares the file */
if (fr != FR_OK) return fr;
#if FF_MAX_SS == FF_MIN_SS
clsz = (DWORD)fp->obj.fs->csize * FF_MAX_SS; /* Cluster size */
#else
clsz = (DWORD)fp->obj.fs->csize * fp->obj.fs->ssize;
#endif
fsz = fp->obj.objsize;
if (fsz > 0) {
clst = fp->obj.sclust - 1; /* A cluster leading the first cluster for first test */
while (fsz) {
step = (fsz >= clsz) ? clsz : (DWORD)fsz;
fr = f_lseek(fp, f_tell(fp) + step); /* Advances file pointer a cluster */
if (fr != FR_OK) return fr;
if (clst + 1 != fp->clust) break; /* Is not the cluster next to previous one? */
clst = fp->clust; fsz -= step; /* Get current cluster for next test */
}
if (fsz == 0) *cont = 1; /* All done without fail? */
}
return FR_OK;
}

View File

@ -0,0 +1,61 @@
/*---------------------------------------------------------------------*/
/* Raw Read/Write Throughput Checker */
/*---------------------------------------------------------------------*/
#include <stdio.h>
#include <systimer.h>
#include "diskio.h"
#include "ff.h"
int test_raw_speed (
BYTE pdrv, /* Physical drive number */
DWORD lba, /* Start LBA for read/write test */
DWORD len, /* Number of bytes to read/write (must be multiple of sz_buff) */
void* buff, /* Read/write buffer */
UINT sz_buff /* Size of read/write buffer (must be multiple of FF_MAX_SS) */
)
{
WORD ss;
DWORD ofs, tmr;
#if FF_MIN_SS != FF_MAX_SS
if (disk_ioctl(pdrv, GET_SECTOR_SIZE, &ss) != RES_OK) {
printf("\ndisk_ioctl() failed.\n");
return 0;
}
#else
ss = FF_MAX_SS;
#endif
printf("Starting raw write test at sector %lu in %u bytes of data chunks...", lba, sz_buff);
tmr = systimer();
for (ofs = 0; ofs < len / ss; ofs += sz_buff / ss) {
if (disk_write(pdrv, buff, lba + ofs, sz_buff / ss) != RES_OK) {
printf("\ndisk_write() failed.\n");
return 0;
}
}
if (disk_ioctl(pdrv, CTRL_SYNC, 0) != RES_OK) {
printf("\ndisk_ioctl() failed.\n");
return 0;
}
tmr = systimer() - tmr;
printf("\n%lu bytes written and it took %lu timer ticks.\n", len, tmr);
printf("Starting raw read test at sector %lu in %u bytes of data chunks...", lba, sz_buff);
tmr = systimer();
for (ofs = 0; ofs < len / ss; ofs += sz_buff / ss) {
if (disk_read(pdrv, buff, lba + ofs, sz_buff / ss) != RES_OK) {
printf("\ndisk_read() failed.\n");
return 0;
}
}
tmr = systimer() - tmr;
printf("\n%lu bytes read and it took %lu timer ticks.\n", len, tmr);
printf("Test completed.\n");
return 1;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Some files were not shown because too many files have changed in this diff Show More