FatFs Module Application Note

Started by tha, May 05, 2022, 10:36:15 AM

Previous topic - Next topic

tha

Considerations on Flash Memory Media

เพื่อเพิ่มสูงสุด the write performance of flash memory media, อย่างเช่น SDC, CFC and U Disk, มันต้องถูกควบคุมโดยคำนึงถึงคุณลักษณะของมัน.

Using Mutiple-Sector Write

The write throughput of the flash memory media จะแย่ที่สุดที่ single sector write transaction. The write throughput เพิ่มขึ้นตามจำนวนของ sectors ต่อ a write transaction ดังแสดงใน Figure 6. ผลกระทบนี้ปรากฎมากขึ้นที่ความเร็วอินเทอร์เฟซที่เร็วขึ้นและ the performance ratio มักจะกลายมาเป็นมากกว่าสิบ. ผลลัพธ์นี้อธิบายอย่างชัดเจนว่า multiple block write (W:16K, 32 sectors) เร็วกว่า single block write (W:100, 1 sector), และการ์ดที่ใหญ่กว่ามักจะช้าในการเขียนบล็อกเดียว. จำนวนของ write transactions ยังส่งผลต่อ life time of the flash memory media ด้วย. เมื่อเปรียบเทียบที่จำนวนเดียวกันของ write data, the single sector write ใน Figure 6 ข้างบนใช้ flash memory media 16 เท่ามากกว่า multiple sector write ใน Figure 6 ข้างล่าง. Single sector write ค่อนข้างเจ็บปวดสำหรับ the flash memory media.
ดังนั้น the application program ควรเขียน the data ใน large block เท่าที่เป็นได้. The ideal write chunk size and alighment คือ size of sector, and size of cluster คือ the best. แน่นอนว่าทุก layers ระหว่าง the application และ the storage device ต้องมีการพิจารณาเกี่ยวกับ multiple sector write, อย่างไรก็ตามส่วนใหญ่ของ open-source memory card drivers จะขาดมัน. อย่าแบ่ง a multiple sector write request ลงใน single sector write transactions หรือ the write throughput ลดลง. โปรดทราบว่า FatFs module และ its sample disk drivers รองรับ multiple sector read/write operation.


tha

Forcing Memory Erase

เมื่อลบ a file ด้วย f_unlink function, the data clusters ที่ครอบครองโดย the file จะถูกทำเครื่องหมาย 'free' บน the FAT. แต่ the data sectors ที่บรรจุ the file data นั้นไม่ได้ถูกใช้กับกระบวนการใดๆ, ดังนั้นข้อมูลไฟล์ที่เหลือจะครอบครองส่วนหนึ่งของ the flash memory array เป็น 'live block'.  ถ้า the file data สามารถถูกลบบนการเอาออก the file, those data blocks จะถูกเปลี่ยนเป็น the free block pool. นี้อาจข้าม internal block erase operation ไปยัง the data block บน next write operation. ดังผลลัพท์ the write performance อาจจะถูกปรับปรุงให้ดีขึ้น. FatFs สามารถจัดการฟังชั่นนี้โดยการเซ็ต FF_USE_TRIM เป็น 1. โปรดทราบว่าเนื่องจากเอฟเฟกต์นี้มาจากความคาดหวังของ internal process of the storage device, มันจึงไม่ได้ผลเสมอไป. applications ส่วนใหญ่จะไม่ต้องการฟังชั่นนี้. นอกจากนี้ f_unlink function อาจใช้เวลาในการลบไฟล์ขนาดใหญ่.

tha

Critical Section

ถ้า a write operation ไปยัง the FAT volume ถูกอินเตอร์รัพท์เนื่องจาก an accidental failure, อย่างเช่น sudden blackout, wrong media removal และ unrecoverable disk error, the FAT structure on the volume สามารถถูกทำให้แตก. ภาพต่อไปนี้แสดง the critical section of the FatFs module.



An interruption ใน the red section อาจทำให้เกิด a cross link; ด้วยเหตุนี้, the object ที่กำลังถูกเปลี่ยนอาจสูญหายได้. ถ้า an interruption ใน the yellow section ถูกทำให้เกิดขึ้น, มีอย่างน้อยหนึ่งรายการที่อาจเป็นได้ข้างล่าง.

  •  The file data ที่กำลังถูกเขียนใหม่ถูกยุบ.
  •  ไฟล์ที่กำลังถูกต่อท้ายจะคืนค่าสถานะเริ่มต้น
  •  ไฟล์ที่สร้างใหม่หายไป
  •  ไฟล์ที่สร้างใหม่หรือเขียนทับจะยังคงอยู่ แต่ไม่มีเนื้อหา
  •  ประสิทธิภาพของการใช้ดิสก์แย่ลงเนื่องจากคลัสเตอร์สูญหาย

แต่ละ case ไม่ส่งผลกระทบต่อ file ใดๆที่ไม่เปิดใน write mode. เพื่อให้ความเสี่ยงลดลงต่ำที่สุดของ data loss, the critical section สามารถถูกทำให้ลดลงต่ำที่สุดโดยการลดลงต่ำที่สุดเวลาที่ file ถูกเปิดใน write mode หรือการใช้ f_sync function ดังแสดงใน Figure 5.


tha

Various Usable Functions for FatFs Projects

เหล่านี้คือตัวอย่างการใช้เพิ่มเติมของ FatFs APIs. รายการใหม่จะถูกเพิ่มเมื่อ useful code example ถูกพบ.

1.  Open or Create File for Append (แทนที่ด้วย FA_OPEN_APPEND flag ที่เพิ่มที่ R0.12)
2.  Delete Non-empty Sub-directory (for R0.12 และใหม่กว่า)
3.  Create Contiguous File (superseded by f_expand function added at R0.12)
4.  Test if the File is Contiguous or Not
5.  Compatibility Checker for Storage Device Control Module
6.  Performance Checker for Storage Device Control Module
7.  FAT Volume Image Creator (Pre-creating built-in FAT volume)
8.  Virtual Drive Feature (refer to lpc176x/ in ffsample.zip)
9.  Embedded Unicode String Utilities (OEMxxx→Unicode, Unicode→OEMxxx, Unicode→Unicode)

tha

About FatFs License

FatFs กำลังได้รับพัฒนาเป็นโปรเจ็กต์ส่วนตัวของผู้เขียน, ChaN. มันเป็นอิสระจากโค้ดที่คนอื่นเขียนในรุ่นปัจจุบัน. code block ต่อไปนี้แสดงสำเนาของt he FatFs license document ที่ถูกรวมไว้ใน the source files.

ดังนั้น FatFs license เป็นหนึ่งของ the BSD-style licenses แต่มีคุณลักษณะที่มีนัยสำคัญ. FatFs ถูกมุ่งหมายสำหรับ embedded systems เป็นหลัก. เพื่อที่จะขยายการใช้งานสำหรับผลิตภัณฑ์เชิงพาณิชย์, การแจกจ่ายซ้ำของ FatFs ใน binary form, อย่างเช่น embedded code, binary library และ any forms โดยไม่มี source code, ไม่จำเป็นต้องรวมเกี่ยวกับ FatFs ไว้ในเอกสารประกอบ. นี้เทียบเท่ากับ the 1-clause BSD license. แน่นอน FatFs เข้ากันได้กับส่วนใหญ่ของ open source software licenses รวมถึง GNU GPL. เมื่อคุณแจกจ่ายซ้ำ the FatFs source code ที่มีการเปลี่ยนแปลงใดๆหรือสร้าง a fork, the license ยังสามารถถูกเปลี่ยนเป็น GNU GPL, BSD-style license หรือ any open source software license ที่เข้ากันได้กับ FatFs license ได้ด้วย.