mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-08-23 15:07:29 +00:00
FatFs: Update to release R0.12b.
This commit is contained in:
@@ -37,17 +37,17 @@
|
||||
<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 ANSI C.</li>
|
||||
<li>Size of integer types<br>
|
||||
The FatFs module assumes that size of <tt>char</tt>/<tt>short</tt>/<tt>long</tt> are 8/16/32 bit and <tt>int</tt> is 16 or 32 bit. These correspondence are defined in <tt>integer.h</tt>. This will not be a problem on most compilers. When any conflict with existing definitions is occured, you must resolve it with care.</li>
|
||||
The FatFs module assumes that size of <tt>char</tt>/<tt>short</tt>/<tt>long</tt> are 8/16/32 bit and <tt>int</tt> is 16 or 32 bit. These correspondence are defined in <tt>integer.h</tt>. This will not be a problem on most compilers. When a conflict with existing definitions is occured, you must resolve it with care.</li>
|
||||
</ul>
|
||||
|
||||
<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 with FatFs API is provided, no additional function is needed. (b) To attach existing disk drivers with different API, glue functions are needed to translate the APIs between FatFs and the drivers.</p>
|
||||
<p>(a) If a working disk module with FatFs disk interface is provided, nothing else will be needed. (b) To attach existing disk drivers with different interface, glue functions are needed to translate the interfaces between FatFs and the drivers.</p>
|
||||
<p><img src="../res/funcs.png" width="750" height="420" alt="functional diagram"></p>
|
||||
|
||||
<h4>Which function is required?</h4>
|
||||
<p>You need to provide only low level disk I/O functions that required by FatFs module and nothing else. If a working disk module for the target system is already existing, you need to write only glue functions to attach it to the FatFs module. If not, you need to port any other disk module or write it from scratch. Most of defined functions are not that always required. For example, disk write function is not required at read-only configuration. Following table shows which function is required depends on the configuration options.</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 module for the target system is already existing, you need to write only glue functions to attach it to the FatFs module. If not, you need to port another disk module or write it from scratch. Most of defined functions are not that always required. For example, disk 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>
|
||||
@@ -81,21 +81,21 @@ The FatFs module assumes that size of <tt>char</tt>/<tt>short</tt>/<tt>long</tt>
|
||||
<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.1k</td><td>6.6k</td><td>6.2k</td><td>12.1k</td><td>10.5k</td><td>11.2k</td><td>12.6k</td><td>8.5k</td><td>8.7k</td><td>6.3k</td><td>8.4k</td></tr>
|
||||
<tr class="ral"><td class="cal">text (Min, R/W)</td> <td>6.6k</td><td>4.5k</td><td>4.2k</td> <td>7.9k</td> <td>7.0k</td> <td>7.6k</td> <td>8.8k</td><td>5.9k</td><td>5.8k</td><td>4.3k</td><td>5.8k</td></tr>
|
||||
<tr class="ral"><td class="cal">text (Full, R/O)</td> <td>4.8k</td><td>3.1k</td><td>2.9k</td> <td>5.8k</td> <td>5.1k</td> <td>5.5k</td> <td>6.4k</td><td>4.1k</td><td>4.0k</td><td>3.1k</td><td>4.0k</td></tr>
|
||||
<tr class="ral"><td class="cal">text (Min, R/O)</td> <td>3.5k</td><td>2.4k</td><td>2.3k</td> <td>4.4k</td> <td>3.9k</td> <td>4.2k</td> <td>5.0k</td><td>3.3k</td><td>3.1k</td><td>2.4k</td><td>3.1k</td></tr>
|
||||
<tr class="ral"><td class="cal">text (Full, R/W)</td><td>10.4k</td><td>6.8k</td><td>6.3k</td><td>12.4k</td> <td>9.8k</td><td>11.1k</td><td>12.8k</td><td>8.6k</td><td>8.9k</td><td>6.4k</td><td>8.5k</td></tr>
|
||||
<tr class="ral"><td class="cal">text (Min, R/W)</td> <td>6.8k</td><td>4.6k</td><td>4.3k</td> <td>8.2k</td> <td>6.7k</td> <td>7.6k</td> <td>9.1k</td><td>6.0k</td><td>5.9k</td><td>4.5k</td><td>5.9k</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.6k</td> <td>4.6k</td> <td>5.3k</td> <td>6.3k</td><td>4.0k</td><td>3.9k</td><td>3.0k</td><td>3.9k</td></tr>
|
||||
<tr class="ral"><td class="cal">text (Min, R/O)</td> <td>3.6k</td><td>2.4k</td><td>2.3k</td> <td>4.4k</td> <td>3.5k</td> <td>4.0k</td> <td>4.9k</td><td>3.3k</td><td>3.0k</td><td>2.4k</td><td>3.1k</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>(_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>(_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 on some target systems with following condition. The memory sizes are in unit of byte, <em>V</em> denotes option <tt>_VOLUMES</tt> and <em>F</em> denotes number of open files. All samples here are optimezed in code size.</p>
|
||||
<pre>
|
||||
FatFs R0.12 options:
|
||||
FatFs R0.12b options:
|
||||
_FS_READONLY 0 (R/W) or 1 (R/O)
|
||||
_FS_MINIMIZE 0 (Full, with all basic functions) or 3 (Min, with fully minimized)
|
||||
_FS_TINY 0 (Default) or 1 (Tiny file object)
|
||||
And any other options are left unchanged from original setting.
|
||||
And other options are left unchanged from original setting.
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
@@ -160,22 +160,22 @@ And any other options are left unchanged from original setting.
|
||||
|
||||
<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">_LFN_UNICODE</a></tt>. This means that FatFs supports the full featured LFN specification. The data type <tt>TCHAR</tt> specifies any string on the API is an alias of <tt>char</tt>(ANSI) or <tt>WCHAR</tt>(UTF-16). For more information, refer to the description in the <a href="filename.html#uni">file name</a>.</p>
|
||||
<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">_LFN_UNICODE</a></tt>. This means that FatFs supports the full featured LFN specification. The data type <tt>TCHAR</tt> specifies strings on the API is an alias of <tt>char</tt>(ANSI/OEM) or <tt>WCHAR</tt>(UTF-16). For more information, refer to the description in the <a href="filename.html#uni">file name</a>.</p>
|
||||
</div>
|
||||
|
||||
<div class="para doc" id="exfat">
|
||||
<h3>exFAT File System</h3>
|
||||
<p>The exFAT (Microsoft's Extended File Allocation Table) file system is a replacement of the FAT file system which has been widely used in the embedded systems and consumer devices. It is adopted by SDA (SD Association) as a recommended file system for high capacity SD cards (>32GB) and they are being shipped with this format, so that the exFAT will soon become one of the standard file systems for removable media.</p>
|
||||
<p>The exFAT file system allows the file size larger than 4 GiB limit what FAT file system allows upto and some file system overhead, especially file allocation delay, are reduced as well. This feature improves the write throughput to the file. However a problem on the current implementation of FatFs is that write throughput at writing to the growing edge of the fragmented file gets less than the throughput on the FAT volume. Pre-allocating a contiguous block with <tt>f_expand</tt> function may be a workaround of this problem.</p>
|
||||
<p>Note that the exFAT is a patent of Microsoft Corporation. The exFAT function of FatFs is an implementation based on US. Pat. App. Pub. No. 2009/0164440 A1. FatFs module can swich the exFAT on or off by configuration option. When enable the exFAT on the commercial products, you will need to be licensed by Microsoft depends on the final destination of the products.</p></div>
|
||||
<p>Note that the exFAT is a patent of Microsoft Corporation. The exFAT function of FatFs is an implementation based on US. Pat. App. Pub. No. 2009/0164440 A1. FatFs module can swich the exFAT on/off by configuration option. When enable the exFAT on the commercial products, you will need to be licensed by Microsoft depends on the final destination of the products.</p></div>
|
||||
<p><em>Remark: Enabling exFAT discards C89 compatibility because of need for 64-bit integer type.</em></p>
|
||||
|
||||
<div class="para doc" id="reentrant">
|
||||
<h3>Re-entrancy</h3>
|
||||
<p>The file operations to the different volume is always re-entrant regardless of configurations except when LFN enabled with static working buffer. It can work simultaneously without any mutual exclusion.</p>
|
||||
<p>The file operations to the same volume is not re-entrant but it can also be configured thread-safe by option <tt><a href="config.html#fs_reentrant">_FS_REENTRANT</a></tt>. It enables to control exclusive use of each file system object. In this case, also the OS dependent synchronization object control functions, <tt>ff_cre_syncobj/ff_del_syncobj/ff_req_grant/ff_rel_grant</tt>, needed to be added to the project. There are some examples in the <tt>option/syscall.c</tt>.</p>
|
||||
<p>When a file function is called while the volume is being accessed by any other 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>_TIMEOUT</tt>, the file function will abort with <tt>FR_TIMEOUT</tt>. The timeout function might not be supported on the some RTOSs.</p>
|
||||
<p>There is an exception on the re-entrancy for <tt>f_mount/f_mkfs/f_fdisk</tt> function. These volume management functions are not re-entrant to the same volume and corresponding physical drive. When use these functions, any other tasks need to avoid to access the volume.</p>
|
||||
<p>When a file function is called while the volume is being accessed by other 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>_TIMEOUT</tt>, the file function will abort with <tt>FR_TIMEOUT</tt>. The timeout function might not be supported on the some RTOSs.</p>
|
||||
<p>There is an exception on the re-entrancy for <tt>f_mount/f_mkfs/f_fdisk</tt> function. These volume management functions are not re-entrant to the same volume and corresponding physical drive. When use these functions, other tasks need to avoid to access the volume.</p>
|
||||
<p>Note that this section describes on the re-entrancy of the FatFs module itself. The <tt>_FS_REENTRANT</tt> controls only exclusive use of each file system object and it does not that prevent to re-enter the low level disk functions. For example, only <tt>disk_status</tt> function can be re-entered at single volume system and any disk function can be re-entered at multiple volume system. Thus the low level disk I/O layer must be always thread-safe when any FatFs API is re-entered by two or more tasks.</p>
|
||||
</div>
|
||||
|
||||
@@ -218,7 +218,7 @@ Figure 6. Comparison between Multiple/Single Sector Write<br>
|
||||
|
||||
<div class="para doc" id="critical">
|
||||
<h3>Critical Section</h3>
|
||||
<p>If a write operation to the FAT volume is interrupted due to any accidental failure, such as sudden blackout, incorrect 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>
|
||||
<p>If a write operation to the FAT volume is interrupted due to an accidental failure, such as sudden blackout, incorrect 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">
|
||||
@@ -236,17 +236,17 @@ Figure 5. Minimized critical section<br>
|
||||
<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 the files that 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>
|
||||
<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 whenever a useful code is found.</p>
|
||||
<ol>
|
||||
<li><a href="../res/app1.c">Open or create a file for append</a> (for R0.12 and older)</li>
|
||||
<li><a href="../res/app1.c">Open or create a file for append</a> (for only R0.12 and earlier)</li>
|
||||
<li><a href="../res/app2.c">Empty a directory</a></li>
|
||||
<li><a href="../res/app3.c">Allocate contiguous area to the file</a> (for R0.11a and older)</li>
|
||||
<li><a href="../res/app4.c">Function/compatibility checker for low level disk I/O module</a></li>
|
||||
<li><a href="../res/app3.c">Allocate contiguous area to the file</a> (for only R0.11a and earlier)</li>
|
||||
<li><a href="../res/app4.c">Compatibility checker for low level disk I/O module</a></li>
|
||||
<li><a href="../res/mkfatimg.zip">FAT image creator</a></li>
|
||||
</ol>
|
||||
</div>
|
||||
@@ -256,15 +256,15 @@ Figure 5. Minimized critical section<br>
|
||||
<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 file system module R0.12a /
|
||||
/ FatFs - Generic FAT file system module Rx.xx /
|
||||
/-----------------------------------------------------------------------------/
|
||||
/
|
||||
/ Copyright (C) 2016, ChaN, all right reserved.
|
||||
/ 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.
|
||||
/
|
||||
|
Reference in New Issue
Block a user