From fef95271a7bf8b395612922f8d8645e1be0cea9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Fr=C3=B6schle?= Date: Mon, 10 Dec 2012 12:13:51 +0000 Subject: [PATCH] replaced "integer.h" with stdint.h --- SD_CARD/BaS_gcc/include/diskio.h | 12 +- SD_CARD/BaS_gcc/include/ff.h | 152 +++++----- SD_CARD/BaS_gcc/include/integer.h | 37 --- SD_CARD/BaS_gcc/sources/ff.c | 475 +++++++++++++++--------------- SD_CARD/BaS_gcc/sources/main.c | 18 +- SD_CARD/BaS_gcc/sources/mmcbb.c | 90 +++--- 6 files changed, 374 insertions(+), 410 deletions(-) delete mode 100644 SD_CARD/BaS_gcc/include/integer.h diff --git a/SD_CARD/BaS_gcc/include/diskio.h b/SD_CARD/BaS_gcc/include/diskio.h index a6a2311..31ba8fc 100644 --- a/SD_CARD/BaS_gcc/include/diskio.h +++ b/SD_CARD/BaS_gcc/include/diskio.h @@ -16,7 +16,7 @@ extern "C" { /* Status of Disk Functions */ -typedef BYTE DSTATUS; +typedef uint8_t DSTATUS; /* Results of Disk Functions */ typedef enum { @@ -32,13 +32,13 @@ typedef enum { /* Prototypes for disk control functions */ -DSTATUS disk_initialize (BYTE); -DSTATUS disk_status (BYTE); -DRESULT disk_read (BYTE, BYTE*, DWORD, BYTE); +DSTATUS disk_initialize (uint8_t); +DSTATUS disk_status (uint8_t); +DRESULT disk_read (uint8_t, uint8_t*, uint32_t, uint8_t); #if _READONLY == 0 -DRESULT disk_write (BYTE, const BYTE*, DWORD, BYTE); +DRESULT disk_write (uint8_t, const uint8_t*, uint32_t, uint8_t); #endif -DRESULT disk_ioctl (BYTE, BYTE, void*); +DRESULT disk_ioctl (uint8_t, uint8_t, void*); /* Disk Status Bits (DSTATUS) */ diff --git a/SD_CARD/BaS_gcc/include/ff.h b/SD_CARD/BaS_gcc/include/ff.h index e6f6cce..3764231 100644 --- a/SD_CARD/BaS_gcc/include/ff.h +++ b/SD_CARD/BaS_gcc/include/ff.h @@ -34,15 +34,15 @@ extern "C" { #if _MULTI_PARTITION /* Multiple partition configuration */ typedef struct { - BYTE pd; /* Physical drive number */ - BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */ + uint8_t pd; /* Physical drive number */ + uint8_t pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */ } PARTITION; extern PARTITION VolToPart[]; /* Volume - Partition resolution table */ #define LD2PD(vol) (VolToPart[vol].pd) /* Get physical drive number */ #define LD2PT(vol) (VolToPart[vol].pt) /* Get partition index */ #else /* Single partition configuration */ -#define LD2PD(vol) (BYTE)(vol) /* Each logical drive is bound to the same physical drive number */ +#define LD2PD(vol) (uint8_t)(vol) /* Each logical drive is bound to the same physical drive number */ #define LD2PT(vol) 0 /* Always mounts the 1st partition or in SFD */ #endif @@ -56,7 +56,7 @@ extern PARTITION VolToPart[]; /* Volume - Partition resolution table */ #error _LFN_UNICODE must be 0 in non-LFN cfg. #endif #ifndef _INC_TCHAR -typedef WCHAR TCHAR; +typedef uint16_t TCHAR; #define _T(x) L ## x #define _TEXT(x) L ## x #endif @@ -75,35 +75,35 @@ typedef char TCHAR; /* File system object structure (FATFS) */ typedef struct { - BYTE fs_type; /* FAT sub-type (0:Not mounted) */ - BYTE drv; /* Physical drive number */ - BYTE csize; /* Sectors per cluster (1,2,4...128) */ - BYTE n_fats; /* Number of FAT copies (1,2) */ - BYTE wflag; /* win[] dirty flag (1:must be written back) */ - BYTE fsi_flag; /* fsinfo dirty flag (1:must be written back) */ - WORD id; /* File system mount ID */ - WORD n_rootdir; /* Number of root directory entries (FAT12/16) */ + uint8_t fs_type; /* FAT sub-type (0:Not mounted) */ + uint8_t drv; /* Physical drive number */ + uint8_t csize; /* Sectors per cluster (1,2,4...128) */ + uint8_t n_fats; /* Number of FAT copies (1,2) */ + uint8_t wflag; /* win[] dirty flag (1:must be written back) */ + uint8_t fsi_flag; /* fsinfo dirty flag (1:must be written back) */ + uint16_t id; /* File system mount ID */ + uint16_t n_rootdir; /* Number of root directory entries (FAT12/16) */ #if _MAX_SS != 512 - WORD ssize; /* Bytes per sector (512, 1024, 2048 or 4096) */ + uint16_t ssize; /* Bytes per sector (512, 1024, 2048 or 4096) */ #endif #if _FS_REENTRANT _SYNC_t sobj; /* Identifier of sync object */ #endif #if !_FS_READONLY - DWORD last_clust; /* Last allocated cluster */ - DWORD free_clust; /* Number of free clusters */ - DWORD fsi_sector; /* fsinfo sector (FAT32) */ + uint32_t last_clust; /* Last allocated cluster */ + uint32_t free_clust; /* Number of free clusters */ + uint32_t fsi_sector; /* fsinfo sector (FAT32) */ #endif #if _FS_RPATH - DWORD cdir; /* Current directory start cluster (0:root) */ + uint32_t cdir; /* Current directory start cluster (0:root) */ #endif - DWORD n_fatent; /* Number of FAT entries (= number of clusters + 2) */ - DWORD fsize; /* Sectors per FAT */ - DWORD fatbase; /* FAT start sector */ - DWORD dirbase; /* Root directory start sector (FAT32:Cluster#) */ - DWORD database; /* Data start sector */ - DWORD winsect; /* Current sector appearing in the win[] */ - BYTE win[_MAX_SS]; /* Disk access window for Directory, FAT (and Data on tiny cfg) */ + uint32_t n_fatent; /* Number of FAT entries (= number of clusters + 2) */ + uint32_t fsize; /* Sectors per FAT */ + uint32_t fatbase; /* FAT start sector */ + uint32_t dirbase; /* Root directory start sector (FAT32:Cluster#) */ + uint32_t database; /* Data start sector */ + uint32_t winsect; /* Current sector appearing in the win[] */ + uint8_t win[_MAX_SS]; /* Disk access window for Directory, FAT (and Data on tiny cfg) */ } FATFS; @@ -112,26 +112,26 @@ typedef struct { typedef struct { FATFS* fs; /* Pointer to the related file system object */ - WORD id; /* File system mount ID of the related file system object */ - BYTE flag; /* File status flags */ - BYTE pad1; - DWORD fptr; /* File read/write pointer (0ed on file open) */ - DWORD fsize; /* File size */ - DWORD sclust; /* File data start cluster (0:no data cluster, always 0 when fsize is 0) */ - DWORD clust; /* Current cluster of fpter */ - DWORD dsect; /* Current data sector of fpter */ + uint16_t id; /* File system mount ID of the related file system object */ + uint8_t flag; /* File status flags */ + uint8_t pad1; + uint32_t fptr; /* File read/write pointer (0ed on file open) */ + uint32_t fsize; /* File size */ + uint32_t sclust; /* File data start cluster (0:no data cluster, always 0 when fsize is 0) */ + uint32_t clust; /* Current cluster of fpter */ + uint32_t dsect; /* Current data sector of fpter */ #if !_FS_READONLY - DWORD dir_sect; /* Sector containing the directory entry */ - BYTE* dir_ptr; /* Pointer to the directory entry in the window */ + uint32_t dir_sect; /* Sector containing the directory entry */ + uint8_t* dir_ptr; /* Pointer to the directory entry in the window */ #endif #if _USE_FASTSEEK - DWORD* cltbl; /* Pointer to the cluster link map table (null on file open) */ + uint32_t* cltbl; /* Pointer to the cluster link map table (null on file open) */ #endif #if _FS_LOCK - UINT lockid; /* File lock ID (index of file semaphore table Files[]) */ + uint32_t lockid; /* File lock ID (index of file semaphore table Files[]) */ #endif #if !_FS_TINY - BYTE buf[_MAX_SS]; /* File data read/write buffer */ + uint8_t buf[_MAX_SS]; /* File data read/write buffer */ #endif } FIL; @@ -141,16 +141,16 @@ typedef struct { typedef struct { FATFS* fs; /* Pointer to the owner file system object */ - WORD id; /* Owner file system mount ID */ - WORD index; /* Current read/write index number */ - DWORD sclust; /* Table start cluster (0:Root dir) */ - DWORD clust; /* Current cluster */ - DWORD sect; /* Current sector */ - BYTE* dir; /* Pointer to the current SFN entry in the win[] */ - BYTE* fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */ + uint16_t id; /* Owner file system mount ID */ + uint16_t index; /* Current read/write index number */ + uint32_t sclust; /* Table start cluster (0:Root dir) */ + uint32_t clust; /* Current cluster */ + uint32_t sect; /* Current sector */ + uint8_t* dir; /* Pointer to the current SFN entry in the win[] */ + uint8_t* fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */ #if _USE_LFN - WCHAR* lfn; /* Pointer to the LFN working buffer */ - WORD lfn_idx; /* Last matched LFN index number (0xFFFF:No LFN) */ + uint16_t* lfn; /* Pointer to the LFN working buffer */ + uint16_t lfn_idx; /* Last matched LFN index number (0xFFFF:No LFN) */ #endif } DIR; @@ -159,14 +159,14 @@ typedef struct { /* File status structure (FILINFO) */ typedef struct { - DWORD fsize; /* File size */ - WORD fdate; /* Last modified date */ - WORD ftime; /* Last modified time */ - BYTE fattrib; /* Attribute */ + uint32_t fsize; /* File size */ + uint16_t fdate; /* Last modified date */ + uint16_t ftime; /* Last modified time */ + uint8_t fattrib; /* Attribute */ TCHAR fname[13]; /* Short file name (8.3 format) */ #if _USE_LFN TCHAR* lfname; /* Pointer to the LFN buffer */ - UINT lfsize; /* Size of LFN buffer in TCHAR */ + uint32_t lfsize; /* Size of LFN buffer in TCHAR */ #endif } FILINFO; @@ -202,29 +202,29 @@ typedef enum { /*--------------------------------------------------------------*/ /* FatFs module application interface */ -FRESULT f_mount (BYTE, FATFS*); /* Mount/Unmount a logical drive */ -FRESULT f_open (FIL*, const TCHAR*, BYTE); /* Open or create a file */ -FRESULT f_read (FIL*, void*, UINT, UINT*); /* Read data from a file */ -FRESULT f_lseek (FIL*, DWORD); /* Move file pointer of a file object */ +FRESULT f_mount (uint8_t, FATFS*); /* Mount/Unmount a logical drive */ +FRESULT f_open (FIL*, const TCHAR*, uint8_t); /* Open or create a file */ +FRESULT f_read (FIL*, void*, uint32_t, uint32_t*); /* Read data from a file */ +FRESULT f_lseek (FIL*, uint32_t); /* Move file pointer of a file object */ FRESULT f_close (FIL*); /* Close an open file object */ FRESULT f_opendir (DIR*, const TCHAR*); /* Open an existing directory */ FRESULT f_readdir (DIR*, FILINFO*); /* Read a directory item */ FRESULT f_stat (const TCHAR*, FILINFO*); /* Get file status */ -FRESULT f_write (FIL*, const void*, UINT, UINT*); /* Write data to a file */ -FRESULT f_getfree (const TCHAR*, DWORD*, FATFS**); /* Get number of free clusters on the drive */ +FRESULT f_write (FIL*, const void*, uint32_t, uint32_t*); /* Write data to a file */ +FRESULT f_getfree (const TCHAR*, uint32_t*, FATFS**); /* Get number of free clusters on the drive */ FRESULT f_truncate (FIL*); /* Truncate file */ FRESULT f_sync (FIL*); /* Flush cached data of a writing file */ FRESULT f_unlink (const TCHAR*); /* Delete an existing file or directory */ FRESULT f_mkdir (const TCHAR*); /* Create a new directory */ -FRESULT f_chmod (const TCHAR*, BYTE, BYTE); /* Change attribute of the file/dir */ +FRESULT f_chmod (const TCHAR*, uint8_t, uint8_t); /* Change attribute of the file/dir */ FRESULT f_utime (const TCHAR*, const FILINFO*); /* Change times-tamp of the file/dir */ FRESULT f_rename (const TCHAR*, const TCHAR*); /* Rename/Move a file or directory */ -FRESULT f_chdrive (BYTE); /* Change current drive */ +FRESULT f_chdrive (uint8_t); /* Change current drive */ FRESULT f_chdir (const TCHAR*); /* Change current directory */ -FRESULT f_getcwd (TCHAR*, UINT); /* Get current directory */ -FRESULT f_forward (FIL*, UINT(*)(const BYTE*,UINT), UINT, UINT*); /* Forward data to the stream */ -FRESULT f_mkfs (BYTE, BYTE, UINT); /* Create a file system on the drive */ -FRESULT f_fdisk (BYTE, const DWORD[], void*); /* Divide a physical drive into some partitions */ +FRESULT f_getcwd (TCHAR*, uint32_t); /* Get current directory */ +FRESULT f_forward (FIL*, uint32_t(*)(const uint8_t*,uint32_t), uint32_t, uint32_t*); /* Forward data to the stream */ +FRESULT f_mkfs (uint8_t, uint8_t, uint32_t); /* Create a file system on the drive */ +FRESULT f_fdisk (uint8_t, const uint32_t[], void*); /* Divide a physical drive into some partitions */ int f_putc (TCHAR, FIL*); /* Put a character to the file */ int f_puts (const TCHAR*, FIL*); /* Put a string to the file */ int f_printf (FIL*, const TCHAR*, ...); /* Put a formatted string to the file */ @@ -247,22 +247,22 @@ TCHAR* f_gets (TCHAR*, int, FIL*); /* Get a string from the file */ /* RTC function */ #if !_FS_READONLY -DWORD get_fattime (void); +uint32_t get_fattime (void); #endif /* Unicode support functions */ #if _USE_LFN /* Unicode - OEM code conversion */ -WCHAR ff_convert (WCHAR, UINT); /* OEM-Unicode bidirectional conversion */ -WCHAR ff_wtoupper (WCHAR); /* Unicode upper-case conversion */ +uint16_t ff_convert (uint16_t, uint32_t); /* OEM-Unicode bidirectional conversion */ +uint16_t ff_wtoupper (uint16_t); /* Unicode upper-case conversion */ #if _USE_LFN == 3 /* Memory functions */ -void* ff_memalloc (UINT); /* Allocate memory block */ +void* ff_memalloc (uint32_t); /* Allocate memory block */ void ff_memfree (void*); /* Free memory block */ #endif #endif /* Sync functions */ #if _FS_REENTRANT -int ff_cre_syncobj (BYTE, _SYNC_t*);/* Create a sync object */ +int ff_cre_syncobj (uint8_t, _SYNC_t*);/* Create a sync object */ int ff_req_grant (_SYNC_t); /* Lock sync object */ void ff_rel_grant (_SYNC_t); /* Unlock sync object */ int ff_del_syncobj (_SYNC_t); /* Delete a sync object */ @@ -319,15 +319,15 @@ int ff_del_syncobj (_SYNC_t); /* Delete a sync object */ /* Multi-byte word access macros */ #if _WORD_ACCESS == 1 /* Enable word access to the FAT structure */ -#define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr)) -#define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr)) -#define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val) -#define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val) +#define LD_WORD(ptr) (uint16_t)(* (uint16_t *)(uint8_t *)(ptr)) +#define LD_DWORD(ptr) (uint32_t)(* (uint32_t *)(uint8_t *)(ptr)) +#define ST_WORD(ptr,val) *(uint16_t *)(uint8_t *)(ptr) = (uint16_t)(val) +#define ST_DWORD(ptr,val) *(uint32_t *)(uint8_t *)(ptr) = (uint32_t)(val) #else /* Use byte-by-byte access to the FAT structure */ -#define LD_WORD(ptr) (WORD)(((WORD)*((BYTE*)(ptr)+1)<<8)|(WORD)*(BYTE*)(ptr)) -#define LD_DWORD(ptr) (DWORD)(((DWORD)*((BYTE*)(ptr)+3)<<24)|((DWORD)*((BYTE*)(ptr)+2)<<16)|((WORD)*((BYTE*)(ptr)+1)<<8)|*(BYTE*)(ptr)) -#define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8) -#define ST_DWORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8); *((BYTE*)(ptr)+2)=(BYTE)((DWORD)(val)>>16); *((BYTE*)(ptr)+3)=(BYTE)((DWORD)(val)>>24) +#define LD_WORD(ptr) (uint16_t)(((uint16_t)*((uint8_t *)(ptr) + 1) << 8)| (uint16_t) *(uint8_t *)(ptr)) +#define LD_DWORD(ptr) (uint32_t)(((uint32_t)*((uint8_t *)(ptr) + 3) << 24) | ((uint32_t)*((uint8_t*)(ptr) + 2) << 16) | ((uint16_t) *((uint8_t*)(ptr) + 1) << 8) | *(uint8_t*)(ptr)) +#define ST_WORD(ptr,val) *(uint8_t *)(ptr) = (uint8_t)(val); *((uint8_t *)(ptr)+1) = (uint8_t)((uint16_t)(val) >> 8) +#define ST_DWORD(ptr,val) *(uint8_t *)(ptr) = (uint8_t)(val); *((uint8_t *)(ptr) + 1) = (uint8_t)((uint16_t)(val) >> 8); *((uint8_t*)(ptr) + 2) = (uint8_t)((uint32_t)(val) >> 16); *((uint8_t *)(ptr) + 3) = (uint8_t)((uint32_t)(val) >> 24) #endif #ifdef __cplusplus diff --git a/SD_CARD/BaS_gcc/include/integer.h b/SD_CARD/BaS_gcc/include/integer.h deleted file mode 100644 index 137b988..0000000 --- a/SD_CARD/BaS_gcc/include/integer.h +++ /dev/null @@ -1,37 +0,0 @@ -/*-------------------------------------------*/ -/* Integer type definitions for FatFs module */ -/*-------------------------------------------*/ - -#ifndef _INTEGER -#define _INTEGER - -#ifdef _WIN32 /* FatFs development platform */ - -#include -#include - -#else /* Embedded platform */ - -/* These types must be 16-bit, 32-bit or larger integer */ -typedef int INT; -typedef unsigned int UINT; - -/* These types must be 8-bit integer */ -typedef char CHAR; -typedef unsigned char UCHAR; -typedef unsigned char BYTE; - -/* These types must be 16-bit integer */ -typedef short SHORT; -typedef unsigned short USHORT; -typedef unsigned short WORD; -typedef unsigned short WCHAR; - -/* These types must be 32-bit integer */ -typedef long LONG; -typedef unsigned long ULONG; -typedef unsigned long DWORD; - -#endif - -#endif diff --git a/SD_CARD/BaS_gcc/sources/ff.c b/SD_CARD/BaS_gcc/sources/ff.c index 709e59c..345b3e0 100644 --- a/SD_CARD/BaS_gcc/sources/ff.c +++ b/SD_CARD/BaS_gcc/sources/ff.c @@ -95,8 +95,9 @@ / Changed option name _FS_SHARE to _FS_LOCK. /---------------------------------------------------------------------------*/ -#include "ff.h" /* FatFs configurations and declarations */ -#include "diskio.h" /* Declarations of low level disk I/O functions */ +#include +#include /* FatFs configurations and declarations */ +#include /* Declarations of low level disk I/O functions */ /*-------------------------------------------------------------------------- @@ -143,9 +144,9 @@ #endif typedef struct { FATFS *fs; /* File ID 1, volume (NULL:blank entry) */ - DWORD clu; /* File ID 2, directory */ - WORD idx; /* File ID 3, directory index */ - WORD ctr; /* File open counter, 0:none, 0x01..0xFF:read open count, 0x100:write mode */ + uint32_t clu; /* File ID 2, directory */ + uint16_t idx; /* File ID 3, directory index */ + uint16_t ctr; /* File open counter, 0:none, 0x01..0xFF:read open count, 0x100:write mode */ } FILESEM; #endif @@ -352,14 +353,14 @@ typedef struct { /* User Provided Timer Function for FatFs module */ /*---------------------------------------------------------*/ -DWORD get_fattime (void) +uint32_t get_fattime (void) { - return ((DWORD)(2012 - 1980) << 25) /* Year = 2012 */ - | ((DWORD)1 << 21) /* Month = 1 */ - | ((DWORD)1 << 16) /* Day_m = 1*/ - | ((DWORD)0 << 11) /* Hour = 0 */ - | ((DWORD)0 << 5) /* Min = 0 */ - | ((DWORD)0 >> 1); /* Sec = 0 */ + return ((uint32_t)(2012 - 1980) << 25) /* Year = 2012 */ + | ((uint32_t)1 << 21) /* Month = 1 */ + | ((uint32_t)1 << 16) /* Day_m = 1*/ + | ((uint32_t)0 << 11) /* Hour = 0 */ + | ((uint32_t)0 << 5) /* Min = 0 */ + | ((uint32_t)0 >> 1); /* Sec = 0 */ } /* Character code support macros */ @@ -370,15 +371,15 @@ DWORD get_fattime (void) #if _DF1S /* Code page is DBCS */ #ifdef _DF2S /* Two 1st byte areas */ -#define IsDBCS1(c) (((BYTE)(c) >= _DF1S && (BYTE)(c) <= _DF1E) || ((BYTE)(c) >= _DF2S && (BYTE)(c) <= _DF2E)) +#define IsDBCS1(c) (((uint8_t)(c) >= _DF1S && (uint8_t)(c) <= _DF1E) || ((uint8_t)(c) >= _DF2S && (uint8_t)(c) <= _DF2E)) #else /* One 1st byte area */ -#define IsDBCS1(c) ((BYTE)(c) >= _DF1S && (BYTE)(c) <= _DF1E) +#define IsDBCS1(c) ((uint8_t)(c) >= _DF1S && (uint8_t)(c) <= _DF1E) #endif #ifdef _DS3S /* Three 2nd byte areas */ -#define IsDBCS2(c) (((BYTE)(c) >= _DS1S && (BYTE)(c) <= _DS1E) || ((BYTE)(c) >= _DS2S && (BYTE)(c) <= _DS2E) || ((BYTE)(c) >= _DS3S && (BYTE)(c) <= _DS3E)) +#define IsDBCS2(c) (((uint8_t)(c) >= _DS1S && (uint8_t)(c) <= _DS1E) || ((uint8_t)(c) >= _DS2S && (uint8_t)(c) <= _DS2E) || ((uint8_t)(c) >= _DS3S && (uint8_t)(c) <= _DS3E)) #else /* Two 2nd byte areas */ -#define IsDBCS2(c) (((BYTE)(c) >= _DS1S && (BYTE)(c) <= _DS1E) || ((BYTE)(c) >= _DS2S && (BYTE)(c) <= _DS2E)) +#define IsDBCS2(c) (((uint8_t)(c) >= _DS1S && (uint8_t)(c) <= _DS1E) || ((uint8_t)(c) >= _DS2S && (uint8_t)(c) <= _DS2E)) #endif #else /* Code page is SBCS */ @@ -486,11 +487,11 @@ FATFS *FatFs[_VOLUMES]; /* Pointer to the file system objects (logical drives) * #endif static -WORD Fsid; /* File system mount ID */ +uint16_t Fsid; /* File system mount ID */ #if _FS_RPATH static -BYTE CurrVol; /* Current drive */ +uint8_t CurrVol; /* Current drive */ #endif #if _FS_LOCK @@ -499,12 +500,12 @@ FILESEM Files[_FS_LOCK]; /* File lock semaphores */ #endif #if _USE_LFN == 0 /* No LFN feature */ -#define DEF_NAMEBUF BYTE sfn[12] +#define DEF_NAMEBUF uint8_t sfn[12] #define INIT_BUF(dobj) (dobj).fn = sfn #define FREE_BUF() #elif _USE_LFN == 1 /* LFN feature with static working buffer */ -static WCHAR LfnBuf[_MAX_LFN+1]; +static uint16_t LfnBuf[_MAX_LFN+1]; #define DEF_NAMEBUF BYTE sfn[12] #define INIT_BUF(dobj) { (dobj).fn = sfn; (dobj).lfn = LfnBuf; } #define FREE_BUF() @@ -541,9 +542,9 @@ static WCHAR LfnBuf[_MAX_LFN+1]; /* Copy memory to memory */ static -void mem_cpy (void* dst, const void* src, UINT cnt) { - BYTE *d = (BYTE*)dst; - const BYTE *s = (const BYTE*)src; +void mem_cpy (void* dst, const void* src, uint32_t cnt) { + uint8_t *d = (uint8_t*)dst; + const uint8_t *s = (const uint8_t*)src; #if _WORD_ACCESS == 1 while (cnt >= sizeof (int)) { @@ -558,17 +559,17 @@ void mem_cpy (void* dst, const void* src, UINT cnt) { /* Fill memory */ static -void mem_set (void* dst, int val, UINT cnt) { - BYTE *d = (BYTE*)dst; +void mem_set (void* dst, int val, uint32_t cnt) { + uint8_t *d = (uint8_t*)dst; while (cnt--) - *d++ = (BYTE)val; + *d++ = (uint8_t)val; } /* Compare memory to memory */ static -int mem_cmp (const void* dst, const void* src, UINT cnt) { - const BYTE *d = (const BYTE *)dst, *s = (const BYTE *)src; +int mem_cmp (const void* dst, const void* src, uint32_t cnt) { + const uint8_t *d = (const uint8_t *)dst, *s = (const uint8_t *)src; int r = 0; while (cnt-- && (r = *d++ - *s++) == 0) ; @@ -627,7 +628,7 @@ FRESULT chk_lock ( /* Check if the file can be accessed */ int acc /* Desired access (0:Read, 1:Write, 2:Delete/Rename) */ ) { - UINT i, be; + uint32_t i, be; /* Search file semaphore table */ for (i = be = 0; i < _FS_LOCK; i++) { @@ -650,7 +651,7 @@ FRESULT chk_lock ( /* Check if the file can be accessed */ static int enq_lock (void) /* Check if an entry is available for a new file */ { - UINT i; + uint32_t i; for (i = 0; i < _FS_LOCK && Files[i].fs; i++) ; return (i == _FS_LOCK) ? 0 : 1; @@ -658,12 +659,12 @@ int enq_lock (void) /* Check if an entry is available for a new file */ static -UINT inc_lock ( /* Increment file open counter and returns its index (0:int error) */ +uint32_t inc_lock ( /* Increment file open counter and returns its index (0:int error) */ DIR* dj, /* Directory object pointing the file to register or increment */ int acc /* Desired access mode (0:Read, !0:Write) */ ) { - UINT i; + uint32_t i; for (i = 0; i < _FS_LOCK; i++) { /* Find the file */ @@ -691,10 +692,10 @@ UINT inc_lock ( /* Increment file open counter and returns its index (0:int erro static FRESULT dec_lock ( /* Decrement file open counter */ - UINT i /* Semaphore index */ + uint32_t i /* Semaphore index */ ) { - WORD n; + uint16_t n; FRESULT res; @@ -717,7 +718,7 @@ void clear_lock ( /* Clear lock entries of the volume */ FATFS *fs ) { - UINT i; + uint32_t i; for (i = 0; i < _FS_LOCK; i++) { if (Files[i].fs == fs) Files[i].fs = 0; @@ -734,10 +735,10 @@ void clear_lock ( /* Clear lock entries of the volume */ static FRESULT move_window ( FATFS *fs, /* File system object */ - DWORD sector /* Sector number to make appearance in the fs->win[] */ + uint32_t sector /* Sector number to make appearance in the fs->win[] */ ) /* Move to zero only writes back dirty window */ { - DWORD wsect; + uint32_t wsect; wsect = fs->winsect; @@ -748,7 +749,7 @@ FRESULT move_window ( return FR_DISK_ERR; fs->wflag = 0; if (wsect < (fs->fatbase + fs->fsize)) { /* In FAT area */ - BYTE nf; + uint8_t nf; for (nf = fs->n_fats; nf > 1; nf--) { /* Reflect the change to all FAT copies */ wsect += fs->fsize; disk_write(fs->drv, fs->win, wsect, 1); @@ -814,9 +815,9 @@ FRESULT sync ( /* FR_OK: successful, FR_DISK_ERR: failed */ /*-----------------------------------------------------------------------*/ -DWORD clust2sect ( /* !=0: Sector number, 0: Failed - invalid cluster# */ +uint32_t clust2sect ( /* !=0: Sector number, 0: Failed - invalid cluster# */ FATFS *fs, /* File system object */ - DWORD clst /* Cluster# to be converted */ + uint32_t clst /* Cluster# to be converted */ ) { clst -= 2; @@ -832,13 +833,13 @@ DWORD clust2sect ( /* !=0: Sector number, 0: Failed - invalid cluster# */ /*-----------------------------------------------------------------------*/ -DWORD get_fat ( /* 0xFFFFFFFF:Disk error, 1:Internal error, Else:Cluster status */ +uint32_t get_fat ( /* 0xFFFFFFFF:Disk error, 1:Internal error, Else:Cluster status */ FATFS *fs, /* File system object */ - DWORD clst /* Cluster# to get the link information */ + uint32_t clst /* Cluster# to get the link information */ ) { - UINT wc, bc; - BYTE *p; + uint32_t wc, bc; + uint8_t *p; if (clst < 2 || clst >= fs->n_fatent) /* Check range */ @@ -846,7 +847,7 @@ DWORD get_fat ( /* 0xFFFFFFFF:Disk error, 1:Internal error, Else:Cluster status switch (fs->fs_type) { case FS_FAT12 : - bc = (UINT)clst; bc += bc / 2; + bc = (uint32_t)clst; bc += bc / 2; if (move_window(fs, fs->fatbase + (bc / SS(fs)))) break; wc = fs->win[bc % SS(fs)]; bc++; if (move_window(fs, fs->fatbase + (bc / SS(fs)))) break; @@ -877,12 +878,12 @@ DWORD get_fat ( /* 0xFFFFFFFF:Disk error, 1:Internal error, Else:Cluster status FRESULT put_fat ( FATFS *fs, /* File system object */ - DWORD clst, /* Cluster# to be changed in range of 2 to fs->n_fatent - 1 */ - DWORD val /* New value to mark the cluster */ + uint32_t clst, /* Cluster# to be changed in range of 2 to fs->n_fatent - 1 */ + uint32_t val /* New value to mark the cluster */ ) { - UINT bc; - BYTE *p; + uint32_t bc; + uint8_t *p; FRESULT res; @@ -892,24 +893,24 @@ FRESULT put_fat ( } else { switch (fs->fs_type) { case FS_FAT12 : - bc = (UINT)clst; bc += bc / 2; + bc = (uint32_t)clst; bc += bc / 2; res = move_window(fs, fs->fatbase + (bc / SS(fs))); if (res != FR_OK) break; p = &fs->win[bc % SS(fs)]; - *p = (clst & 1) ? ((*p & 0x0F) | ((BYTE)val << 4)) : (BYTE)val; + *p = (clst & 1) ? ((*p & 0x0F) | ((uint8_t)val << 4)) : (uint8_t)val; bc++; fs->wflag = 1; res = move_window(fs, fs->fatbase + (bc / SS(fs))); if (res != FR_OK) break; p = &fs->win[bc % SS(fs)]; - *p = (clst & 1) ? (BYTE)(val >> 4) : ((*p & 0xF0) | ((BYTE)(val >> 8) & 0x0F)); + *p = (clst & 1) ? (uint8_t)(val >> 4) : ((*p & 0xF0) | ((uint8_t)(val >> 8) & 0x0F)); break; case FS_FAT16 : res = move_window(fs, fs->fatbase + (clst / (SS(fs) / 2))); if (res != FR_OK) break; p = &fs->win[clst * 2 % SS(fs)]; - ST_WORD(p, (WORD)val); + ST_WORD(p, (uint16_t)val); break; case FS_FAT32 : @@ -941,13 +942,13 @@ FRESULT put_fat ( static FRESULT remove_chain ( FATFS *fs, /* File system object */ - DWORD clst /* Cluster# to remove a chain from */ + uint32_t clst /* Cluster# to remove a chain from */ ) { FRESULT res; - DWORD nxt; + uint32_t nxt; #if _USE_ERASE - DWORD scl = clst, ecl = clst, rt[2]; + uint32_t scl = clst, ecl = clst, rt[2]; #endif if (clst < 2 || clst >= fs->n_fatent) { /* Check range */ @@ -992,12 +993,12 @@ FRESULT remove_chain ( /*-----------------------------------------------------------------------*/ #if !_FS_READONLY static -DWORD create_chain ( /* 0:No free cluster, 1:Internal error, 0xFFFFFFFF:Disk error, >=2:New cluster# */ +uint32_t create_chain ( /* 0:No free cluster, 1:Internal error, 0xFFFFFFFF:Disk error, >=2:New cluster# */ FATFS *fs, /* File system object */ - DWORD clst /* Cluster# to stretch. 0 means create a new chain. */ + uint32_t clst /* Cluster# to stretch. 0 means create a new chain. */ ) { - DWORD cs, ncl, scl; + uint32_t cs, ncl, scl; FRESULT res; @@ -1052,12 +1053,12 @@ DWORD create_chain ( /* 0:No free cluster, 1:Internal error, 0xFFFFFFFF:Disk err #if _USE_FASTSEEK static -DWORD clmt_clust ( /* <2:Error, >=2:Cluster number */ +uint32_t clmt_clust ( /* <2:Error, >=2:Cluster number */ FIL* fp, /* Pointer to the file object */ - DWORD ofs /* File offset to be converted to cluster# */ + uint32_t ofs /* File offset to be converted to cluster# */ ) { - DWORD cl, ncl, *tbl; + uint32_t cl, ncl, *tbl; tbl = fp->cltbl + 1; /* Top of CLMT */ @@ -1081,11 +1082,11 @@ DWORD clmt_clust ( /* <2:Error, >=2:Cluster number */ static FRESULT dir_sdi ( DIR *dj, /* Pointer to directory object */ - WORD idx /* Index of directory table */ + uint16_t idx /* Index of directory table */ ) { - DWORD clst; - WORD ic; + uint32_t clst; + uint16_t ic; dj->index = idx; @@ -1132,8 +1133,8 @@ FRESULT dir_next ( /* FR_OK:Succeeded, FR_NO_FILE:End of table, FR_DENIED:EOT an int stretch /* 0: Do not stretch table, 1: Stretch table if needed */ ) { - DWORD clst; - WORD i; + uint32_t clst; + uint16_t i; //stretch = stretch; /* To suppress warning on read-only cfg. */ @@ -1155,7 +1156,7 @@ FRESULT dir_next ( /* FR_OK:Succeeded, FR_NO_FILE:End of table, FR_DENIED:EOT an if (clst == 0xFFFFFFFF) return FR_DISK_ERR; if (clst >= dj->fs->n_fatent) { /* When it reached end of dynamic table */ #if !_FS_READONLY - BYTE c; + uint8_t c; if (!stretch) return FR_NO_FILE; /* When do not stretch, report EOT */ clst = create_chain(dj->fs, dj->clust); /* Stretch cluster chain */ if (clst == 0) return FR_DENIED; /* No free cluster */ @@ -1195,16 +1196,16 @@ FRESULT dir_next ( /* FR_OK:Succeeded, FR_NO_FILE:End of table, FR_DENIED:EOT an /*-----------------------------------------------------------------------*/ static -DWORD ld_clust ( +uint32_t ld_clust ( FATFS *fs, /* Pointer to the fs object */ - BYTE *dir /* Pointer to the directory entry */ + uint8_t *dir /* Pointer to the directory entry */ ) { - DWORD cl; + uint32_t cl; cl = LD_WORD(dir+DIR_FstClusLO); if (fs->fs_type == FS_FAT32) - cl |= (DWORD)LD_WORD(dir+DIR_FstClusHI) << 16; + cl |= (uint32_t)LD_WORD(dir+DIR_FstClusHI) << 16; return cl; } @@ -1213,8 +1214,8 @@ DWORD ld_clust ( #if !_FS_READONLY static void st_clust ( - BYTE *dir, /* Pointer to the directory entry */ - DWORD cl /* Value to be set */ + uint8_t *dir, /* Pointer to the directory entry */ + uint32_t cl /* Value to be set */ ) { ST_WORD(dir+DIR_FstClusLO, cl); @@ -1229,17 +1230,17 @@ void st_clust ( /*-----------------------------------------------------------------------*/ #if _USE_LFN static -const BYTE LfnOfs[] = {1,3,5,7,9,14,16,18,20,22,24,28,30}; /* Offset of LFN chars in the directory entry */ +const uint8_t LfnOfs[] = {1,3,5,7,9,14,16,18,20,22,24,28,30}; /* Offset of LFN chars in the directory entry */ static int cmp_lfn ( /* 1:Matched, 0:Not matched */ - WCHAR *lfnbuf, /* Pointer to the LFN to be compared */ - BYTE *dir /* Pointer to the directory entry containing a part of LFN */ + uint16_t *lfnbuf, /* Pointer to the LFN to be compared */ + uint8_t *dir /* Pointer to the directory entry containing a part of LFN */ ) { - UINT i, s; - WCHAR wc, uc; + uint32_t i, s; + uint16_t wc, uc; i = ((dir[LDIR_Ord] & ~LLE) - 1) * 13; /* Get offset in the LFN buffer */ @@ -1265,12 +1266,12 @@ int cmp_lfn ( /* 1:Matched, 0:Not matched */ static int pick_lfn ( /* 1:Succeeded, 0:Buffer overflow */ - WCHAR *lfnbuf, /* Pointer to the Unicode-LFN buffer */ - BYTE *dir /* Pointer to the directory entry */ + uint16_t *lfnbuf, /* Pointer to the Unicode-LFN buffer */ + uint8_t *dir /* Pointer to the directory entry */ ) { - UINT i, s; - WCHAR wc, uc; + uint32_t i, s; + uint16_t wc, uc; i = ((dir[LDIR_Ord] & 0x3F) - 1) * 13; /* Offset in the LFN buffer */ @@ -1298,14 +1299,14 @@ int pick_lfn ( /* 1:Succeeded, 0:Buffer overflow */ #if !_FS_READONLY static void fit_lfn ( - const WCHAR *lfnbuf, /* Pointer to the LFN buffer */ - BYTE *dir, /* Pointer to the directory entry */ - BYTE ord, /* LFN order (1-20) */ - BYTE sum /* SFN sum */ + const uint16_t *lfnbuf, /* Pointer to the LFN buffer */ + uint8_t *dir, /* Pointer to the directory entry */ + uint8_t ord, /* LFN order (1-20) */ + uint8_t sum /* SFN sum */ ) { - UINT i, s; - WCHAR wc; + uint32_t i, s; + uint16_t wc; dir[LDIR_Chksum] = sum; /* Set check sum */ @@ -1334,20 +1335,20 @@ void fit_lfn ( /*-----------------------------------------------------------------------*/ #if _USE_LFN void gen_numname ( - BYTE *dst, /* Pointer to generated SFN */ - const BYTE *src, /* Pointer to source SFN to be modified */ - const WCHAR *lfn, /* Pointer to LFN */ - WORD seq /* Sequence number */ + uint8_t *dst, /* Pointer to generated SFN */ + const uint8_t *src, /* Pointer to source SFN to be modified */ + const uint16_t *lfn, /* Pointer to LFN */ + uint16_t seq /* Sequence number */ ) { - BYTE ns[8], c; - UINT i, j; + uint8_t ns[8], c; + uint32_t i, j; mem_cpy(dst, src, 11); if (seq > 5) { /* On many collisions, generate a hash number instead of sequential number */ - do seq = (seq >> 1) + (seq << 15) + (WORD)*lfn++; while (*lfn); + do seq = (seq >> 1) + (seq << 15) + (uint16_t)*lfn++; while (*lfn); } /* itoa (hexdecimal) */ @@ -1381,12 +1382,12 @@ void gen_numname ( /*-----------------------------------------------------------------------*/ #if _USE_LFN static -BYTE sum_sfn ( - const BYTE *dir /* Ptr to directory entry */ +uint8_t sum_sfn ( + const uint8_t *dir /* Ptr to directory entry */ ) { - BYTE sum = 0; - UINT n = 11; + uint8_t sum = 0; + uint32_t n = 11; do sum = (sum >> 1) + (sum << 7) + *dir++; while (--n); return sum; @@ -1406,9 +1407,9 @@ FRESULT dir_find ( ) { FRESULT res; - BYTE c, *dir; + uint8_t c, *dir; #if _USE_LFN - BYTE a, ord, sum; + uint8_t a, ord, sum; #endif res = dir_sdi(dj, 0); /* Rewind directory object */ @@ -1467,9 +1468,9 @@ FRESULT dir_read ( ) { FRESULT res; - BYTE c, *dir; + uint8_t c, *dir; #if _USE_LFN - BYTE a, ord = 0xFF, sum = 0xFF; + uint8_t a, ord = 0xFF, sum = 0xFF; #endif res = FR_NO_FILE; @@ -1524,11 +1525,11 @@ FRESULT dir_register ( /* FR_OK:Successful, FR_DENIED:No free entry or too many ) { FRESULT res; - BYTE c, *dir; + uint8_t c, *dir; #if _USE_LFN /* LFN configuration */ - WORD n, ne, is; - BYTE sn[12], *fn, sum; - WCHAR *lfn; + uint16_t n, ne, is; + uint8_t sn[12], *fn, sum; + uint16_t *lfn; fn = dj->fn; lfn = dj->lfn; @@ -1581,7 +1582,7 @@ FRESULT dir_register ( /* FR_OK:Successful, FR_DENIED:No free entry or too many do { /* Store LFN entries in bottom first */ res = move_window(dj->fs, dj->sect); if (res != FR_OK) break; - fit_lfn(dj->lfn, dj->dir, (BYTE)ne, sum); + fit_lfn(dj->lfn, dj->dir, (uint8_t)ne, sum); dj->fs->wflag = 1; res = dir_next(dj, 0); /* Next entry */ } while (res == FR_OK && --ne); @@ -1632,10 +1633,10 @@ FRESULT dir_remove ( /* FR_OK: Successful, FR_DISK_ERR: A disk error */ { FRESULT res; #if _USE_LFN /* LFN configuration */ - WORD i; + uint16_t i; i = dj->index; /* SFN index */ - res = dir_sdi(dj, (WORD)((dj->lfn_idx == 0xFFFF) ? i : dj->lfn_idx)); /* Goto the SFN or top of the LFN entries */ + res = dir_sdi(dj, (uint16_t)((dj->lfn_idx == 0xFFFF) ? i : dj->lfn_idx)); /* Goto the SFN or top of the LFN entries */ if (res == FR_OK) { do { res = move_window(dj->fs, dj->sect); @@ -1677,13 +1678,13 @@ FRESULT create_name ( ) { #ifdef _EXCVT - static const BYTE excvt[] = _EXCVT; /* Upper conversion table for extended chars */ + static const uint8_t excvt[] = _EXCVT; /* Upper conversion table for extended chars */ #endif #if _USE_LFN /* LFN configuration */ - BYTE b, cf; - WCHAR w, *lfn; - UINT i, ni, si, di; + uint8_t b, cf; + uint16_t w, *lfn; + uint32_t i, ni, si, di; const TCHAR *p; /* Create LFN in Unicode */ @@ -1698,7 +1699,7 @@ FRESULT create_name ( #if !_LFN_UNICODE w &= 0xFF; if (IsDBCS1(w)) { /* Check if it is a DBC 1st byte (always false on SBCS cfg) */ - b = (BYTE)p[si++]; /* Get 2nd byte */ + b = (uint8_t)p[si++]; /* Get 2nd byte */ if (!IsDBCS2(b)) return FR_INVALID_NAME; /* Reject invalid sequence */ w = (w << 8) + b; /* Create a DBC */ @@ -1769,7 +1770,7 @@ FRESULT create_name ( if (i >= ni - 1) { cf |= NS_LOSS | NS_LFN; i = ni; continue; } - dj->fn[i++] = (BYTE)(w >> 8); + dj->fn[i++] = (uint8_t)(w >> 8); } else { /* Single byte char */ if (!w || chk_chr("+,;=[]", w)) { /* Replace illegal chars for SFN */ w = '_'; cf |= NS_LOSS | NS_LFN;/* Lossy conversion */ @@ -1783,7 +1784,7 @@ FRESULT create_name ( } } } - dj->fn[i++] = (BYTE)w; + dj->fn[i++] = (uint8_t)w; } if (dj->fn[0] == DDE) dj->fn[0] = NDDE; /* If the first char collides with deleted mark, replace it with 0x05 */ @@ -1802,8 +1803,8 @@ FRESULT create_name ( #else /* Non-LFN configuration */ - BYTE b, c, d, *sfn; - UINT ni, si, i; + uint8_t b, c, d, *sfn; + uint32_t ni, si, i; const char *p; /* Create file name in directory form */ @@ -1814,7 +1815,7 @@ FRESULT create_name ( #if _FS_RPATH if (p[si] == '.') { /* Is this a dot entry? */ for (;;) { - c = (BYTE)p[si++]; + c = (uint8_t)p[si++]; if (c != '.' || si >= 3) break; sfn[i++] = c; } @@ -1825,7 +1826,7 @@ FRESULT create_name ( } #endif for (;;) { - c = (BYTE)p[si++]; + c = (uint8_t)p[si++]; if (c <= ' ' || c == '/' || c == '\\') break; /* Break on end of segment */ if (c == '.' || i >= ni) { if (ni != 8 || c != '.') return FR_INVALID_NAME; @@ -1843,7 +1844,7 @@ FRESULT create_name ( #endif } if (IsDBCS1(c)) { /* Check if it is a DBC 1st byte (always false on SBCS cfg) */ - d = (BYTE)p[si++]; /* Get 2nd byte */ + d = (uint8_t)p[si++]; /* Get 2nd byte */ if (!IsDBCS2(d) || i >= ni - 1) /* Reject invalid DBC */ return FR_INVALID_NAME; sfn[i++] = c; @@ -1890,8 +1891,8 @@ void get_fileinfo ( /* No return code */ FILINFO *fno /* Pointer to the file information to be filled */ ) { - UINT i; - BYTE nt, *dir; + uint32_t i; + uint8_t nt, *dir; TCHAR *p, c; @@ -1937,7 +1938,7 @@ void get_fileinfo ( /* No return code */ #if _USE_LFN if (fno->lfname && fno->lfsize) { TCHAR *tp = fno->lfname; - WCHAR w, *lfn; + uint16_t w, *lfn; i = 0; if (dj->sect && dj->lfn_idx != 0xFFFF) {/* Get LFN if available */ @@ -1973,7 +1974,7 @@ FRESULT follow_path ( /* FR_OK(0): successful, !=0: error code */ ) { FRESULT res; - BYTE *dir, ns; + uint8_t *dir, ns; #if _FS_RPATH @@ -1988,7 +1989,7 @@ FRESULT follow_path ( /* FR_OK(0): successful, !=0: error code */ dj->sclust = 0; /* Start from the root dir */ #endif - if ((UINT)*path < ' ') { /* Nul path means the start directory itself */ + if ((uint32_t)*path < ' ') { /* Nul path means the start directory itself */ res = dir_sdi(dj, 0); dj->dir = 0; } else { /* Follow path */ @@ -2029,9 +2030,9 @@ FRESULT follow_path ( /* FR_OK(0): successful, !=0: error code */ /*-----------------------------------------------------------------------*/ static -BYTE check_fs ( /* 0:FAT-VBR, 1:Any BR but not FAT, 2:Not a BR, 3:Disk error */ +uint8_t check_fs ( /* 0:FAT-VBR, 1:Any BR but not FAT, 2:Not a BR, 3:Disk error */ FATFS *fs, /* File system object */ - DWORD sect /* Sector# (lba) to check if it is an FAT boot record or not */ + uint32_t sect /* Sector# (lba) to check if it is an FAT boot record or not */ ) { if (disk_read(fs->drv, fs->win, sect, 1) != RES_OK) /* Load boot record */ @@ -2058,14 +2059,14 @@ static FRESULT chk_mounted ( /* FR_OK(0): successful, !=0: any error occurred */ const TCHAR **path, /* Pointer to pointer to the path name (drive number) */ FATFS **rfs, /* Pointer to pointer to the found file system object */ - BYTE wmode /* !=0: Check write protection for write access */ + uint8_t wmode /* !=0: Check write protection for write access */ ) { - BYTE fmt, b, pi, *tbl; - UINT vol; + uint8_t fmt, b, pi, *tbl; + uint32_t vol; DSTATUS stat; - DWORD bsect, fasize, tsect, sysect, nclst, szbfat; - WORD nrsv; + uint32_t bsect, fasize, tsect, sysect, nclst, szbfat; + uint16_t nrsv; const TCHAR *p = *path; FATFS *fs; @@ -2257,7 +2258,7 @@ FRESULT validate ( /* FR_OK(0): The object is valid, !=0: Invalid */ /*-----------------------------------------------------------------------*/ FRESULT f_mount ( - BYTE vol, /* Logical drive number to be mounted/unmounted */ + uint8_t vol, /* Logical drive number to be mounted/unmounted */ FATFS *fs /* Pointer to new file system object (NULL for unmount)*/ ) { @@ -2299,12 +2300,12 @@ FRESULT f_mount ( FRESULT f_open ( FIL *fp, /* Pointer to the blank file object */ const TCHAR *path, /* Pointer to the file name */ - BYTE mode /* Access mode and file open mode flags */ + uint8_t mode /* Access mode and file open mode flags */ ) { FRESULT res; DIR dj; - BYTE *dir; + uint8_t *dir; DEF_NAMEBUF; @@ -2313,7 +2314,7 @@ FRESULT f_open ( #if !_FS_READONLY mode &= FA_READ | FA_WRITE | FA_CREATE_ALWAYS | FA_OPEN_ALWAYS | FA_CREATE_NEW; - res = chk_mounted(&path, &dj.fs, (BYTE)(mode & ~FA_READ)); + res = chk_mounted(&path, &dj.fs, (uint8_t)(mode & ~FA_READ)); #else mode &= FA_READ; res = chk_mounted(&path, &dj.fs, 0); @@ -2333,7 +2334,7 @@ FRESULT f_open ( } /* Create or Open a file */ if (mode & (FA_CREATE_ALWAYS | FA_OPEN_ALWAYS | FA_CREATE_NEW)) { - DWORD dw, cl; + uint32_t dw, cl; if (res != FR_OK) { /* No file, create new */ if (res == FR_NO_FILE) /* There is no file to open, create a new entry */ @@ -2431,14 +2432,14 @@ FRESULT f_open ( FRESULT f_read ( FIL *fp, /* Pointer to the file object */ void *buff, /* Pointer to data buffer */ - UINT btr, /* Number of bytes to read */ - UINT *br /* Pointer to number of bytes read */ + uint32_t btr, /* Number of bytes to read */ + uint32_t *br /* Pointer to number of bytes read */ ) { FRESULT res; - DWORD clst, sect, remain; - UINT rcnt, cc; - BYTE csect, *rbuff = buff; + uint32_t clst, sect, remain; + uint32_t rcnt, cc; + uint8_t csect, *rbuff = buff; *br = 0; /* Clear read byte counter */ @@ -2450,12 +2451,12 @@ FRESULT f_read ( if (!(fp->flag & FA_READ)) /* Check access mode */ LEAVE_FF(fp->fs, FR_DENIED); remain = fp->fsize - fp->fptr; - if (btr > remain) btr = (UINT)remain; /* Truncate btr by remaining bytes */ + if (btr > remain) btr = (uint32_t)remain; /* Truncate btr by remaining bytes */ for ( ; btr; /* Repeat until all data read */ rbuff += rcnt, fp->fptr += rcnt, *br += rcnt, btr -= rcnt) { if ((fp->fptr % SS(fp->fs)) == 0) { /* On the sector boundary? */ - csect = (BYTE)(fp->fptr / SS(fp->fs) & (fp->fs->csize - 1)); /* Sector offset in the cluster */ + csect = (uint8_t)(fp->fptr / SS(fp->fs) & (fp->fs->csize - 1)); /* Sector offset in the cluster */ if (!csect) { /* On the cluster boundary? */ if (fp->fptr == 0) { /* On the top of the file? */ clst = fp->sclust; /* Follow from the origin */ @@ -2478,7 +2479,7 @@ FRESULT f_read ( if (cc) { /* Read maximum contiguous sectors directly */ if (csect + cc > fp->fs->csize) /* Clip at cluster boundary */ cc = fp->fs->csize - csect; - if (disk_read(fp->fs->drv, rbuff, sect, (BYTE)cc) != RES_OK) + if (disk_read(fp->fs->drv, rbuff, sect, (uint8_t)cc) != RES_OK) ABORT(fp->fs, FR_DISK_ERR); #if !_FS_READONLY && _FS_MINIMIZE <= 2 /* Replace one of the read sectors with cached data if it contains a dirty sector */ #if _FS_TINY @@ -2507,7 +2508,7 @@ FRESULT f_read ( #endif fp->dsect = sect; } - rcnt = SS(fp->fs) - ((UINT)fp->fptr % SS(fp->fs)); /* Get partial sector data from sector buffer */ + rcnt = SS(fp->fs) - ((uint32_t)fp->fptr % SS(fp->fs)); /* Get partial sector data from sector buffer */ if (rcnt > btr) rcnt = btr; #if _FS_TINY if (move_window(fp->fs, fp->dsect)) /* Move sector window */ @@ -2532,15 +2533,15 @@ FRESULT f_read ( FRESULT f_write ( FIL *fp, /* Pointer to the file object */ const void *buff, /* Pointer to the data to be written */ - UINT btw, /* Number of bytes to write */ - UINT *bw /* Pointer to number of bytes written */ + uint32_t btw, /* Number of bytes to write */ + uint32_t *bw /* Pointer to number of bytes written */ ) { FRESULT res; - DWORD clst, sect; - UINT wcnt, cc; - const BYTE *wbuff = buff; - BYTE csect; + uint32_t clst, sect; + uint32_t wcnt, cc; + const uint8_t *wbuff = buff; + uint8_t csect; *bw = 0; /* Clear write byte counter */ @@ -2551,12 +2552,12 @@ FRESULT f_write ( LEAVE_FF(fp->fs, FR_INT_ERR); if (!(fp->flag & FA_WRITE)) /* Check access mode */ LEAVE_FF(fp->fs, FR_DENIED); - if ((DWORD)(fp->fsize + btw) < fp->fsize) btw = 0; /* File size cannot reach 4GB */ + if ((uint32_t)(fp->fsize + btw) < fp->fsize) btw = 0; /* File size cannot reach 4GB */ for ( ; btw; /* Repeat until all data written */ wbuff += wcnt, fp->fptr += wcnt, *bw += wcnt, btw -= wcnt) { if ((fp->fptr % SS(fp->fs)) == 0) { /* On the sector boundary? */ - csect = (BYTE)(fp->fptr / SS(fp->fs) & (fp->fs->csize - 1)); /* Sector offset in the cluster */ + csect = (uint8_t)(fp->fptr / SS(fp->fs) & (fp->fs->csize - 1)); /* Sector offset in the cluster */ if (!csect) { /* On the cluster boundary? */ if (fp->fptr == 0) { /* On the top of the file? */ clst = fp->sclust; /* Follow from the origin */ @@ -2592,7 +2593,7 @@ FRESULT f_write ( if (cc) { /* Write maximum contiguous sectors directly */ if (csect + cc > fp->fs->csize) /* Clip at cluster boundary */ cc = fp->fs->csize - csect; - if (disk_write(fp->fs->drv, wbuff, sect, (BYTE)cc) != RES_OK) + if (disk_write(fp->fs->drv, wbuff, sect, (uint8_t)cc) != RES_OK) ABORT(fp->fs, FR_DISK_ERR); #if _FS_TINY if (fp->fs->winsect - sect < cc) { /* Refill sector cache if it gets invalidated by the direct write */ @@ -2622,7 +2623,7 @@ FRESULT f_write ( #endif fp->dsect = sect; } - wcnt = SS(fp->fs) - ((UINT)fp->fptr % SS(fp->fs));/* Put partial sector into file I/O buffer */ + wcnt = SS(fp->fs) - ((uint32_t)fp->fptr % SS(fp->fs));/* Put partial sector into file I/O buffer */ if (wcnt > btw) wcnt = btw; #if _FS_TINY if (move_window(fp->fs, fp->dsect)) /* Move sector window */ @@ -2653,8 +2654,8 @@ FRESULT f_sync ( ) { FRESULT res; - DWORD tim; - BYTE *dir; + uint32_t tim; + uint8_t *dir; res = validate(fp); /* Check validity of the object */ @@ -2743,7 +2744,7 @@ FRESULT f_close ( #if _FS_RPATH >= 1 FRESULT f_chdrive ( - BYTE drv /* Drive number */ + uint8_t drv /* Drive number */ ) { if (drv >= _VOLUMES) return FR_INVALID_DRIVE; @@ -2789,13 +2790,13 @@ FRESULT f_chdir ( #if _FS_RPATH >= 2 FRESULT f_getcwd ( TCHAR *path, /* Pointer to the directory path */ - UINT sz_path /* Size of path */ + uint32_t sz_path /* Size of path */ ) { FRESULT res; DIR dj; - UINT i, n; - DWORD ccl; + uint32_t i, n; + uint32_t ccl; TCHAR *tp; FILINFO fno; DEF_NAMEBUF; @@ -2867,7 +2868,7 @@ FRESULT f_getcwd ( FRESULT f_lseek ( FIL *fp, /* Pointer to the file object */ - DWORD ofs /* File pointer from top of file */ + uint32_t ofs /* File pointer from top of file */ ) { FRESULT res; @@ -2880,7 +2881,7 @@ FRESULT f_lseek ( #if _USE_FASTSEEK if (fp->cltbl) { /* Fast seek */ - DWORD cl, pcl, ncl, tcl, dsc, tlen, ulen, *tbl; + uint32_t cl, pcl, ncl, tcl, dsc, tlen, ulen, *tbl; if (ofs == CREATE_LINKMAP) { /* Create CLMT */ tbl = fp->cltbl; @@ -2937,7 +2938,7 @@ FRESULT f_lseek ( /* Normal Seek */ { - DWORD clst, bcs, nsect, ifptr; + uint32_t clst, bcs, nsect, ifptr; if (ofs > fp->fsize /* In read-only mode, clip offset with the file size */ #if !_FS_READONLY @@ -2948,7 +2949,7 @@ FRESULT f_lseek ( ifptr = fp->fptr; fp->fptr = nsect = 0; if (ofs) { - bcs = (DWORD)fp->fs->csize * SS(fp->fs); /* Cluster size (byte) */ + bcs = (uint32_t)fp->fs->csize * SS(fp->fs); /* Cluster size (byte) */ if (ifptr > 0 && (ofs - 1) / bcs >= (ifptr - 1) / bcs) { /* When seek to same or following cluster, */ fp->fptr = (ifptr - 1) & ~(bcs - 1); /* start from the current cluster */ @@ -3147,15 +3148,15 @@ FRESULT f_stat ( FRESULT f_getfree ( const TCHAR *path, /* Pointer to the logical drive number (root dir) */ - DWORD *nclst, /* Pointer to the variable to return number of free clusters */ + uint32_t *nclst, /* Pointer to the variable to return number of free clusters */ FATFS **fatfs /* Pointer to pointer to corresponding file system object to return */ ) { FRESULT res; FATFS *fs; - DWORD n, clst, sect, stat; - UINT i; - BYTE fat, *p; + uint32_t n, clst, sect, stat; + uint32_t i; + uint8_t fat, *p; /* Get drive number */ @@ -3217,7 +3218,7 @@ FRESULT f_truncate ( ) { FRESULT res; - DWORD ncl; + uint32_t ncl; if (!fp) return FR_INVALID_OBJECT; @@ -3268,8 +3269,8 @@ FRESULT f_unlink ( { FRESULT res; DIR dj, sdj; - BYTE *dir; - DWORD dclst; + uint8_t *dir; + uint32_t dclst; DEF_NAMEBUF; @@ -3336,8 +3337,8 @@ FRESULT f_mkdir ( { FRESULT res; DIR dj; - BYTE *dir, n; - DWORD dsc, dcl, pcl, tim = get_fattime(); + uint8_t *dir, n; + uint32_t dsc, dcl, pcl, tim = get_fattime(); DEF_NAMEBUF; @@ -3405,13 +3406,13 @@ FRESULT f_mkdir ( FRESULT f_chmod ( const TCHAR *path, /* Pointer to the file path */ - BYTE value, /* Attribute bits */ - BYTE mask /* Attribute mask to change */ + uint8_t value, /* Attribute bits */ + uint8_t mask /* Attribute mask to change */ ) { FRESULT res; DIR dj; - BYTE *dir; + uint8_t *dir; DEF_NAMEBUF; @@ -3428,7 +3429,7 @@ FRESULT f_chmod ( res = FR_INVALID_NAME; } else { /* File or sub directory */ mask &= AM_RDO|AM_HID|AM_SYS|AM_ARC; /* Valid attribute mask */ - dir[DIR_Attr] = (value & mask) | (dir[DIR_Attr] & (BYTE)~mask); /* Apply attribute change */ + dir[DIR_Attr] = (value & mask) | (dir[DIR_Attr] & (uint8_t)~mask); /* Apply attribute change */ dj.fs->wflag = 1; res = sync(dj.fs); } @@ -3452,7 +3453,7 @@ FRESULT f_utime ( { FRESULT res; DIR dj; - BYTE *dir; + uint8_t *dir; DEF_NAMEBUF; @@ -3493,8 +3494,8 @@ FRESULT f_rename ( { FRESULT res; DIR djo, djn; - BYTE buf[21], *dir; - DWORD dw; + uint8_t buf[21], *dir; + uint32_t dw; DEF_NAMEBUF; @@ -3567,15 +3568,15 @@ FRESULT f_rename ( FRESULT f_forward ( FIL *fp, /* Pointer to the file object */ - UINT (*func)(const BYTE*,UINT), /* Pointer to the streaming function */ - UINT btr, /* Number of bytes to forward */ - UINT *bf /* Pointer to number of bytes forwarded */ + uint32_t (*func)(const uint8_t*,uint32_t), /* Pointer to the streaming function */ + uint32_t btr, /* Number of bytes to forward */ + uint32_t *bf /* Pointer to number of bytes forwarded */ ) { FRESULT res; - DWORD remain, clst, sect; - UINT rcnt; - BYTE csect; + uint32_t remain, clst, sect; + uint32_t rcnt; + uint8_t csect; *bf = 0; /* Clear transfer byte counter */ @@ -3590,11 +3591,11 @@ FRESULT f_forward ( LEAVE_FF(fp->fs, FR_DENIED); remain = fp->fsize - fp->fptr; - if (btr > remain) btr = (UINT)remain; /* Truncate btr by remaining bytes */ + if (btr > remain) btr = (uint32_t)remain; /* Truncate btr by remaining bytes */ for ( ; btr && (*func)(0, 0); /* Repeat until all data transferred or stream becomes busy */ fp->fptr += rcnt, *bf += rcnt, btr -= rcnt) { - csect = (BYTE)(fp->fptr / SS(fp->fs) & (fp->fs->csize - 1)); /* Sector offset in the cluster */ + csect = (uint8_t)(fp->fptr / SS(fp->fs) & (fp->fs->csize - 1)); /* Sector offset in the cluster */ if ((fp->fptr % SS(fp->fs)) == 0) { /* On the sector boundary? */ if (!csect) { /* On the cluster boundary? */ clst = (fp->fptr == 0) ? /* On the top of the file? */ @@ -3610,9 +3611,9 @@ FRESULT f_forward ( if (move_window(fp->fs, sect)) /* Move sector window */ ABORT(fp->fs, FR_DISK_ERR); fp->dsect = sect; - rcnt = SS(fp->fs) - (WORD)(fp->fptr % SS(fp->fs)); /* Forward data from sector window */ + rcnt = SS(fp->fs) - (uint16_t)(fp->fptr % SS(fp->fs)); /* Forward data from sector window */ if (rcnt > btr) rcnt = btr; - rcnt = (*func)(&fp->fs->win[(WORD)fp->fptr % SS(fp->fs)], rcnt); + rcnt = (*func)(&fp->fs->win[(uint16_t)fp->fptr % SS(fp->fs)], rcnt); if (!rcnt) ABORT(fp->fs, FR_INT_ERR); } @@ -3631,18 +3632,18 @@ FRESULT f_forward ( FRESULT f_mkfs ( - BYTE drv, /* Logical drive number */ - BYTE sfd, /* Partitioning rule 0:FDISK, 1:SFD */ - UINT au /* Allocation unit size [bytes] */ + uint8_t drv, /* Logical drive number */ + uint8_t sfd, /* Partitioning rule 0:FDISK, 1:SFD */ + uint32_t au /* Allocation unit size [bytes] */ ) { - static const WORD vst[] = { 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 0}; - static const WORD cst[] = {32768, 16384, 8192, 4096, 2048, 16384, 8192, 4096, 2048, 1024, 512}; - BYTE fmt, md, sys, *tbl, pdrv, part; - DWORD n_clst, vs, n, wsect; - UINT i; - DWORD b_vol, b_fat, b_dir, b_data; /* LBA */ - DWORD n_vol, n_rsv, n_fat, n_dir; /* Size */ + static const uint16_t vst[] = { 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 0}; + static const uint16_t cst[] = {32768, 16384, 8192, 4096, 2048, 16384, 8192, 4096, 2048, 1024, 512}; + uint8_t fmt, md, sys, *tbl, pdrv, part; + uint32_t n_clst, vs, n, wsect; + uint32_t i; + uint32_t b_vol, b_fat, b_dir, b_data; /* LBA */ + uint32_t n_vol, n_rsv, n_fat, n_dir; /* Size */ FATFS *fs; DSTATUS stat; @@ -3705,7 +3706,7 @@ FRESULT f_mkfs ( n_fat = (fmt == FS_FAT12) ? (n_clst * 3 + 1) / 2 + 3 : (n_clst * 2) + 4; n_fat = (n_fat + SS(fs) - 1) / SS(fs); n_rsv = 1; - n_dir = (DWORD)N_ROOTDIR * SZ_DIR / SS(fs); + n_dir = (uint32_t)N_ROOTDIR * SZ_DIR / SS(fs); } b_fat = b_vol + n_rsv; /* FAT area start sector */ b_dir = b_fat + n_fat * N_FATS; /* Directory area start sector */ @@ -3753,8 +3754,8 @@ FRESULT f_mkfs ( tbl[4] = sys; /* System type */ tbl[5] = 254; /* Partition end head */ n = (b_vol + n_vol) / 63 / 255; - tbl[6] = (BYTE)((n >> 2) | 63); /* Partition end sector */ - tbl[7] = (BYTE)n; /* End cylinder */ + tbl[6] = (uint8_t)((n >> 2) | 63); /* Partition end sector */ + tbl[7] = (uint8_t)n; /* End cylinder */ ST_DWORD(tbl+8, 63); /* Partition start in LBA */ ST_DWORD(tbl+12, n_vol); /* Partition size in LBA */ ST_WORD(fs->win+BS_55AA, 0xAA55); /* MBR signature */ @@ -3770,7 +3771,7 @@ FRESULT f_mkfs ( mem_cpy(tbl, "\xEB\xFE\x90" "MSDOS5.0", 11);/* Boot jump code, OEM name */ i = SS(fs); /* Sector size */ ST_WORD(tbl+BPB_BytsPerSec, i); - tbl[BPB_SecPerClus] = (BYTE)au; /* Sectors per cluster */ + tbl[BPB_SecPerClus] = (uint8_t)au; /* Sectors per cluster */ ST_WORD(tbl+BPB_RsvdSecCnt, n_rsv); /* Reserved sectors */ tbl[BPB_NumFATs] = N_FATS; /* Number of FATs */ i = (fmt == FS_FAT32) ? 0 : N_ROOTDIR; /* Number of rootdir entries */ @@ -3839,7 +3840,7 @@ FRESULT f_mkfs ( #if _USE_ERASE /* Erase data area if needed */ { - DWORD eb[2]; + uint32_t eb[2]; eb[0] = wsect; eb[1] = wsect + (n_clst - ((fmt == FS_FAT32) ? 1 : 0)) * au - 1; disk_ioctl(pdrv, CTRL_ERASE_SECTOR, eb); @@ -3867,15 +3868,15 @@ FRESULT f_mkfs ( /*-----------------------------------------------------------------------*/ FRESULT f_fdisk ( - BYTE pdrv, /* Physical drive number */ - const DWORD szt[], /* Pointer to the size table for each partitions */ + uint8_t pdrv, /* Physical drive number */ + const uint32_t szt[], /* Pointer to the size table for each partitions */ void* work /* Pointer to the working buffer */ ) { - UINT i, n, sz_cyl, tot_cyl, b_cyl, e_cyl, p_cyl; - BYTE s_hd, e_hd, *p, *buf = (BYTE*)work; + uint32_t i, n, sz_cyl, tot_cyl, b_cyl, e_cyl, p_cyl; + uint8_t s_hd, e_hd, *p, *buf = (uint8_t*)work; DSTATUS stat; - DWORD sz_disk, sz_part, s_part; + uint32_t sz_disk, sz_part, s_part; stat = disk_initialize(pdrv); @@ -3894,10 +3895,10 @@ FRESULT f_fdisk ( mem_set(buf, 0, _MAX_SS); p = buf + MBR_Table; b_cyl = 0; for (i = 0; i < 4; i++, p += SZ_PTE) { - p_cyl = (szt[i] <= 100) ? (DWORD)tot_cyl * szt[i] / 100 : szt[i] / sz_cyl; + p_cyl = (szt[i] <= 100) ? (uint32_t)tot_cyl * szt[i] / 100 : szt[i] / sz_cyl; if (!p_cyl) continue; - s_part = (DWORD)sz_cyl * b_cyl; - sz_part = (DWORD)sz_cyl * p_cyl; + s_part = (uint32_t)sz_cyl * b_cyl; + sz_part = (uint32_t)sz_cyl * p_cyl; if (i == 0) { /* Exclude first track of cylinder 0 */ s_hd = 1; s_part += 63; sz_part -= 63; @@ -3909,12 +3910,12 @@ FRESULT f_fdisk ( /* Set partition table */ p[1] = s_hd; /* Start head */ - p[2] = (BYTE)((b_cyl >> 2) + 1); /* Start sector */ - p[3] = (BYTE)b_cyl; /* Start cylinder */ + p[2] = (uint8_t)((b_cyl >> 2) + 1); /* Start sector */ + p[3] = (uint8_t)b_cyl; /* Start cylinder */ p[4] = 0x06; /* System type (temporary setting) */ p[5] = e_hd; /* End head */ - p[6] = (BYTE)((e_cyl >> 2) + 63); /* End sector */ - p[7] = (BYTE)e_cyl; /* End cylinder */ + p[6] = (uint8_t)((e_cyl >> 2) + 63); /* End sector */ + p[7] = (uint8_t)e_cyl; /* End cylinder */ ST_DWORD(p + 8, s_part); /* Start sector in LBA */ ST_DWORD(p + 12, sz_part); /* Partition size */ @@ -3946,8 +3947,8 @@ TCHAR* f_gets ( { int n = 0; TCHAR c, *p = buff; - BYTE s[2]; - UINT rc; + uint8_t s[2]; + uint32_t rc; while (n < len - 1) { /* Read bytes until buffer gets filled */ @@ -3997,8 +3998,8 @@ int f_putc ( FIL* fil /* Pointer to the file object */ ) { - UINT bw, btw; - BYTE s[3]; + uint32_t bw, btw; + uint8_t s[3]; #if _USE_STRFUNC >= 2 @@ -4007,22 +4008,22 @@ int f_putc ( #if _LFN_UNICODE /* Write the character in UTF-8 encoding */ if (c < 0x80) { /* 7-bit */ - s[0] = (BYTE)c; + s[0] = (uint8_t)c; btw = 1; } else { if (c < 0x800) { /* 11-bit */ - s[0] = (BYTE)(0xC0 | (c >> 6)); - s[1] = (BYTE)(0x80 | (c & 0x3F)); + s[0] = (uint8_t)(0xC0 | (c >> 6)); + s[1] = (uint8_t)(0x80 | (c & 0x3F)); btw = 2; } else { /* 16-bit */ - s[0] = (BYTE)(0xE0 | (c >> 12)); - s[1] = (BYTE)(0x80 | ((c >> 6) & 0x3F)); - s[2] = (BYTE)(0x80 | (c & 0x3F)); + s[0] = (uint8_t)(0xE0 | (c >> 12)); + s[1] = (uint8_t)(0x80 | ((c >> 6) & 0x3F)); + s[2] = (uint8_t)(0x80 | (c & 0x3F)); btw = 3; } } #else /* Write the character without conversion */ - s[0] = (BYTE)c; + s[0] = (uint8_t)c; btw = 1; #endif f_write(fil, s, btw, &bw); /* Write the char to the file */ @@ -4062,9 +4063,9 @@ int f_printf ( ) { va_list arp; - BYTE f, r; - UINT i, j, w; - ULONG v; + uint8_t f, r; + uint32_t i, j, w; + uint32_t v; TCHAR c, d, s[16], *p; int res, chc, cc; @@ -4126,7 +4127,7 @@ int f_printf ( } /* Get an argument and put it in numeral */ - v = (f & 4) ? (ULONG)va_arg(arp, long) : ((d == 'D') ? (ULONG)(long)va_arg(arp, int) : (ULONG)va_arg(arp, unsigned int)); + v = (f & 4) ? (uint32_t)va_arg(arp, long) : ((d == 'D') ? (uint32_t)(long)va_arg(arp, int) : (uint32_t)va_arg(arp, unsigned int)); if (d == 'D' && (v & 0x80000000)) { v = 0 - v; f |= 8; diff --git a/SD_CARD/BaS_gcc/sources/main.c b/SD_CARD/BaS_gcc/sources/main.c index f3aa9b5..0c0ba4a 100644 --- a/SD_CARD/BaS_gcc/sources/main.c +++ b/SD_CARD/BaS_gcc/sources/main.c @@ -8,7 +8,7 @@ FATFS Fatfs; /* File system object */ FIL Fil; /* File object */ -BYTE Buff[128]; /* File read buffer */ +uint8_t Buff[128]; /* File read buffer */ void die ( /* Stop with dying message */ @@ -29,7 +29,7 @@ int main (void) FRESULT rc; /* Result code */ DIR dir; /* Directory object */ FILINFO fno; /* File information object */ - UINT bw, br, i; + uint32_t bw, br, i; f_mount(0, &Fatfs); /* Register volume work area (never fails) */ @@ -89,12 +89,12 @@ int main (void) /* User Provided Timer Function for FatFs module */ /*---------------------------------------------------------*/ -DWORD get_fattime (void) +uint32_t get_fattime (void) { - return ((DWORD)(2012 - 1980) << 25) /* Year = 2012 */ - | ((DWORD)1 << 21) /* Month = 1 */ - | ((DWORD)1 << 16) /* Day_m = 1*/ - | ((DWORD)0 << 11) /* Hour = 0 */ - | ((DWORD)0 << 5) /* Min = 0 */ - | ((DWORD)0 >> 1); /* Sec = 0 */ + return ((uint32_t)(2012 - 1980) << 25) /* Year = 2012 */ + | ((uint32_t)1 << 21) /* Month = 1 */ + | ((uint32_t)1 << 16) /* Day_m = 1*/ + | ((uint32_t)0 << 11) /* Hour = 0 */ + | ((uint32_t)0 << 5) /* Min = 0 */ + | ((uint32_t)0 >> 1); /* Sec = 0 */ } diff --git a/SD_CARD/BaS_gcc/sources/mmcbb.c b/SD_CARD/BaS_gcc/sources/mmcbb.c index d0c23c6..691177e 100644 --- a/SD_CARD/BaS_gcc/sources/mmcbb.c +++ b/SD_CARD/BaS_gcc/sources/mmcbb.c @@ -104,10 +104,10 @@ static volatile DSTATUS Stat = STA_NOINIT; /* Physical drive status */ static volatile -UINT Timer1, Timer2; /* 1kHz decrement timer stopped at zero (disk_timerproc()) */ +uint32_t Timer1, Timer2; /* 1kHz decrement timer stopped at zero (disk_timerproc()) */ static -BYTE CardType; /* Card type flags */ +uint8_t CardType; /* Card type flags */ @@ -116,7 +116,7 @@ BYTE CardType; /* Card type flags */ /*-----------------------------------------------------------------------*/ /* Exchange a byte */ -static BYTE xchg_spi(BYTE byte) +static uint8_t xchg_spi(uint8_t byte) { * (volatile uint8_t *) (&MCF_DSPI_DTFR + 3) = byte; @@ -132,7 +132,7 @@ static BYTE xchg_spi(BYTE byte) * buff: pointer to data buffer * btr: number of bytes to receive (16, 64 or 512) */ -static void rcvr_spi_multi(BYTE *buff, UINT count) +static void rcvr_spi_multi(uint8_t *buff, uint32_t count) { int i; @@ -147,7 +147,7 @@ static void rcvr_spi_multi(BYTE *buff, UINT count) * buff: pointer to data * btx: number of bytes to send */ -static void xmit_spi_multi(const BYTE *buff, UINT btx) +static void xmit_spi_multi(const uint8_t *buff, uint32_t btx) { int i; @@ -171,7 +171,7 @@ static int card_ready(void) * wt: timeout in ms * returns 1: ready, 0: timeout */ -static int wait_ready (UINT wt) +static int wait_ready (uint32_t wt) { return waitfor(wt, card_ready); } @@ -250,11 +250,11 @@ void power_off (void) /* Disable SPI function */ static int rcvr_datablock ( /* 1:OK, 0:Error */ - BYTE *buff, /* Data buffer */ - UINT btr /* Data block length (byte) */ + uint8_t *buff, /* Data buffer */ + uint32_t btr /* Data block length (byte) */ ) { - BYTE token; + uint8_t token; Timer1 = 200; @@ -279,11 +279,11 @@ int rcvr_datablock ( /* 1:OK, 0:Error */ #if _USE_WRITE static int xmit_datablock ( /* 1:OK, 0:Failed */ - const BYTE *buff, /* Ponter to 512 byte data to be sent */ - BYTE token /* Token */ + const uint8_t *buff, /* Ponter to 512 byte data to be sent */ + uint8_t token /* Token */ ) { - BYTE resp; + uint8_t resp; if (!wait_ready(500)) return 0; /* Wait for card ready */ @@ -306,12 +306,12 @@ int xmit_datablock ( /* 1:OK, 0:Failed */ /* Send a command packet to the MMC */ /*-----------------------------------------------------------------------*/ -static BYTE send_cmd ( /* Return value: R1 resp (bit7==1:Failed to send) */ - BYTE cmd, /* Command index */ - DWORD arg /* Argument */ +static uint8_t send_cmd ( /* Return value: R1 resp (bit7==1:Failed to send) */ + uint8_t cmd, /* Command index */ + uint32_t arg /* Argument */ ) { - BYTE n, res; + uint8_t n, res; if (cmd & 0x80) { /* Send a CMD55 prior to ACMD */ @@ -326,10 +326,10 @@ static BYTE send_cmd ( /* Return value: R1 resp (bit7==1:Failed to send) */ /* Send command packet */ xchg_spi(0x40 | cmd); /* Start + command index */ - xchg_spi((BYTE)(arg >> 24)); /* Argument[31..24] */ - xchg_spi((BYTE)(arg >> 16)); /* Argument[23..16] */ - xchg_spi((BYTE)(arg >> 8)); /* Argument[15..8] */ - xchg_spi((BYTE)arg); /* Argument[7..0] */ + xchg_spi((uint8_t)(arg >> 24)); /* Argument[31..24] */ + xchg_spi((uint8_t)(arg >> 16)); /* Argument[23..16] */ + xchg_spi((uint8_t)(arg >> 8)); /* Argument[15..8] */ + xchg_spi((uint8_t)arg); /* Argument[7..0] */ n = 0x01; /* Dummy CRC + Stop */ if (cmd == CMD0) n = 0x95; /* Valid CRC for CMD0(0) */ if (cmd == CMD8) n = 0x87; /* Valid CRC for CMD8(0x1AA) */ @@ -359,9 +359,9 @@ static BYTE send_cmd ( /* Return value: R1 resp (bit7==1:Failed to send) */ * * drv: physical drive number (0) */ -DSTATUS disk_initialize(BYTE drv) +DSTATUS disk_initialize(uint8_t drv) { - BYTE n, cmd, ty, ocr[4]; + uint8_t n, cmd, ty, ocr[4]; if (drv) return STA_NOINIT; /* Supports only drive 0 */ @@ -416,7 +416,7 @@ DSTATUS disk_initialize(BYTE drv) /*-----------------------------------------------------------------------*/ DSTATUS disk_status ( - BYTE drv /* Physical drive number (0) */ + uint8_t drv /* Physical drive number (0) */ ) { if (drv) return STA_NOINIT; /* Supports only drive 0 */ @@ -431,10 +431,10 @@ DSTATUS disk_status ( /*-----------------------------------------------------------------------*/ DRESULT disk_read ( - BYTE drv, /* Physical drive number (0) */ - BYTE *buff, /* Pointer to the data buffer to store read data */ - DWORD sector, /* Start sector number (LBA) */ - BYTE count /* Number of sectors to read (1..128) */ + uint8_t drv, /* Physical drive number (0) */ + uint8_t *buff, /* Pointer to the data buffer to store read data */ + uint32_t sector, /* Start sector number (LBA) */ + uint8_t count /* Number of sectors to read (1..128) */ ) { if (drv || !count) return RES_PARERR; /* Check parameter */ @@ -469,10 +469,10 @@ DRESULT disk_read ( #if _USE_WRITE DRESULT disk_write ( - BYTE drv, /* Physical drive number (0) */ - const BYTE *buff, /* Ponter to the data to write */ - DWORD sector, /* Start sector number (LBA) */ - BYTE count /* Number of sectors to write (1..128) */ + uint8_t drv, /* Physical drive number (0) */ + const uint8_t *buff, /* Ponter to the data to write */ + uint32_t sector, /* Start sector number (LBA) */ + uint8_t count /* Number of sectors to write (1..128) */ ) { if (drv || !count) return RES_PARERR; /* Check parameter */ @@ -510,14 +510,14 @@ DRESULT disk_write ( #if _USE_IOCTL DRESULT disk_ioctl ( - BYTE drv, /* Physical drive number (0) */ - BYTE ctrl, /* Control command code */ + uint8_t drv, /* Physical drive number (0) */ + uint8_t ctrl, /* Control command code */ void *buff /* Pointer to the conrtol data */ ) { DRESULT res; - BYTE n, csd[16], *ptr = buff; - DWORD *dp, st, ed, csize; + uint8_t n, csd[16], *ptr = buff; + uint32_t *dp, st, ed, csize; if (drv) return RES_PARERR; /* Check parameter */ @@ -536,19 +536,19 @@ DRESULT disk_ioctl ( case GET_SECTOR_COUNT : /* Get drive capacity in unit of sector (DWORD) */ if ((send_cmd(CMD9, 0) == 0) && rcvr_datablock(csd, 16)) { if ((csd[0] >> 6) == 1) { /* SDC ver 2.00 */ - csize = csd[9] + ((WORD)csd[8] << 8) + ((DWORD)(csd[7] & 63) << 16) + 1; - *(DWORD*)buff = csize << 10; + csize = csd[9] + ((uint16_t)csd[8] << 8) + ((uint32_t)(csd[7] & 63) << 16) + 1; + *(uint32_t*)buff = csize << 10; } else { /* SDC ver 1.XX or MMC ver 3 */ n = (csd[5] & 15) + ((csd[10] & 128) >> 7) + ((csd[9] & 3) << 1) + 2; - csize = (csd[8] >> 6) + ((WORD)csd[7] << 2) + ((WORD)(csd[6] & 3) << 10) + 1; - *(DWORD*)buff = csize << (n - 9); + csize = (csd[8] >> 6) + ((uint16_t)csd[7] << 2) + ((uint16_t)(csd[6] & 3) << 10) + 1; + *(uint32_t*)buff = csize << (n - 9); } res = RES_OK; } break; case GET_SECTOR_SIZE : /* Get sector size in unit of byte (WORD) */ - *(WORD*)buff = 512; + *(uint16_t*)buff = 512; res = RES_OK; break; @@ -558,16 +558,16 @@ DRESULT disk_ioctl ( xchg_spi(0xFF); if (rcvr_datablock(csd, 16)) { /* Read partial block */ for (n = 64 - 16; n; n--) xchg_spi(0xFF); /* Purge trailing data */ - *(DWORD*)buff = 16UL << (csd[10] >> 4); + *(uint32_t*)buff = 16UL << (csd[10] >> 4); res = RES_OK; } } } else { /* SDC ver 1.XX or MMC */ if ((send_cmd(CMD9, 0) == 0) && rcvr_datablock(csd, 16)) { /* Read CSD */ if (CardType & CT_SD1) { /* SDC ver 1.XX */ - *(DWORD*)buff = (((csd[10] & 63) << 1) + ((WORD)(csd[11] & 128) >> 7) + 1) << ((csd[13] >> 6) - 1); + *(uint32_t*)buff = (((csd[10] & 63) << 1) + ((uint16_t)(csd[11] & 128) >> 7) + 1) << ((csd[13] >> 6) - 1); } else { /* MMC */ - *(DWORD*)buff = ((WORD)((csd[10] & 124) >> 2) + 1) * (((csd[11] & 3) << 3) + ((csd[11] & 224) >> 5) + 1); + *(uint32_t*)buff = ((uint16_t)((csd[10] & 124) >> 2) + 1) * (((csd[11] & 3) << 3) + ((csd[11] & 224) >> 5) + 1); } res = RES_OK; } @@ -641,8 +641,8 @@ DRESULT disk_ioctl ( void disk_timerproc (void) { - WORD n; - BYTE s; + uint16_t n; + uint8_t s; n = Timer1; /* 1kHz decrement timer stopped at 0 */