⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filesys_8h.html

📁 MP3播放器源代码, VS1003B
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<p>Definition at line <a class="el" href="filesys_8h-source.html#l00022">22</a> of file <a class="el" href="filesys_8h-source.html">filesys.h</a>.    </td>  </tr></table><hr><h2>Function Documentation</h2><a class="anchor" name="a10" doxytag="filesys.h::BuildFragmentTable" ></a><p><table class="mdTable" width="100%" cellpadding="2" cellspacing="0">  <tr>    <td class="mdRow">      <table cellpadding="0" cellspacing="0" border="0">        <tr>          <td class="md" nowrap valign="top"> unsigned char BuildFragmentTable           </td>          <td class="md" valign="top">(&nbsp;</td>          <td class="md" nowrap valign="top">void&nbsp;</td>          <td class="mdname1" valign="top" nowrap>          </td>          <td class="md" valign="top">&nbsp;)&nbsp;</td>          <td class="md" nowrap></td>        </tr>      </table>    </td>  </tr></table><table cellspacing=5 cellpadding=0 border=0>  <tr>    <td>      &nbsp;    </td>    <td><p>Build a fragment table starting from current sector. <p>Returns number of fragments in song. This function is used to get fast access to the filesystem when playing so cluster chain needs not be followed when the song is playing, that would be too slow with MMC cards without extra buffer memory for the file allocation tables.<p>Note: <a class="el" href="filesys_8c.html">filesys.c</a> module does not use the fragment table internally. it is written to be a service to the player routine, which uses <a class="el" href="storage_8c.html">storage.c</a> module directly for disk access after using the <a class="el" href="filesys_8c.html">filesys.c</a> module for finding a file to play. I am listening to Darude's Sandstorm while coding this.<p>In terms of memory allocation, this function is devilish. At one stage temp.l is used just to make compiler use memory at temp.l instead of spilling to another unnecessary temp variable... <p>Definition at line <a class="el" href="filesys_8c-source.html#l00401">401</a> of file <a class="el" href="filesys_8c-source.html">filesys.c</a>.<p>References <a class="el" href="unionAddress.html#o1">Address::b</a>, <a class="el" href="buffer_8h-source.html#l00131">Address::B::b0</a>, <a class="el" href="buffer_8h-source.html#l00132">Address::B::b1</a>, <a class="el" href="buffer_8h-source.html#l00134">Address::B::b3</a>, <a class="el" href="filesys_8c-source.html#l00029">dataStart</a>, <a class="el" href="buffer_8c-source.html#l00010">diskSect</a>, <a class="el" href="buffer_8h-source.html#l00114">DiskBlock::Fat16Table</a>, <a class="el" href="buffer_8h-source.html#l00117">DiskBlock::Fat32Table</a>, <a class="el" href="filesys_8c-source.html#l00032">fatSectorsPerCluster</a>, <a class="el" href="filesys_8c-source.html#l00021">fatStart</a>, <a class="el" href="filesys_8c-source.html#l00047">fileSize</a>, <a class="el" href="filesys_8c.html#a6">fragment</a>, <a class="el" href="filesys_8c-source.html#l00068">IS_FAT_12</a>, <a class="el" href="filesys_8h-source.html#l00015">IS_FAT_32</a>, <a class="el" href="board_8h-source.html#l00255">Temp::l</a>, <a class="el" href="buffer_8h-source.html#l00129">Address::l</a>, <a class="el" href="filesys_8h-source.html#l00027">fragmentEntry::length</a>, <a class="el" href="filesys_8c-source.html#l00037">MAX_NUMBER_FRAGMENTS</a>, <a class="el" href="board_8h-source.html#l00280">Public</a>, <a class="el" href="storage_8c-source.html#l00110">ReadDiskSector()</a>, <a class="el" href="buffer_8c-source.html#l00015">sectorAddress</a>, <a class="el" href="filesys_8h-source.html#l00026">fragmentEntry::start</a>, and <a class="el" href="board_8c.html#a0">temp</a>.<p>Referenced by <a class="el" href="player_8c-source.html#l00724">PlayCurrentFile()</a>.<p><pre class="fragment"><div>00401                                          {00402 00403   <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> c=0;00404   <a class="code" href="unionAddress.html">addressType</a> <span class="keyword">this</span>,next;00405   <a class="code" href="unionAddress.html">addressType</a> fatSector;00406   <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> entryNumber;00407 00408 00409   <span class="keywordflow">if</span> (<a class="code" href="filesys_8c.html#a12">IS_FAT_12</a>){00410     ConsoleWrite(<span class="stringliteral">"Single fragment support for FAT12"</span>);00411     <a class="code" href="filesys_8c.html#a6">fragment</a>[0].<a class="code" href="structfragmentEntry.html#o0">start</a> = <a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a>;00412     <a class="code" href="filesys_8c.html#a6">fragment</a>[0].<a class="code" href="structfragmentEntry.html#o1">length</a> = <a class="code" href="filesys_8c.html#a7">fileSize</a>/512;00413     <span class="keywordflow">return</span>(1); <span class="comment">//Return 1 fragment</span>00414   }00415 00416 00417   <span class="comment">//as long as the sectorAddress is "sane"...</span>00418   <span class="keywordflow">while</span> (!(<a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o1">b</a>.<a class="code" href="structAddress_1_1B.html#o3">b3</a> &amp; 0x80)){00419         00420     <a class="code" href="filesys_8c.html#a6">fragment</a>[c].<a class="code" href="structfragmentEntry.html#o0">start</a> = <a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a>;00421     <a class="code" href="filesys_8c.html#a6">fragment</a>[c].<a class="code" href="structfragmentEntry.html#o1">length</a> = <a class="code" href="filesys_8c.html#a5">fatSectorsPerCluster</a>;00422     00423     <span class="comment">/* Find cluster entry for the current sector */</span>00424     00425     <span class="comment">/* in how manyth sector from start of data area are we? -&gt;this */</span>00426     <span class="keyword">this</span>.l = <a class="code" href="buffer_8c.html#a2">sectorAddress</a>.<a class="code" href="unionAddress.html#o0">l</a> - <a class="code" href="filesys_8c.html#a4">dataStart</a>;00427     <span class="comment">/* convert from CurrentSectorN to currentClusterN */</span>00428     <span class="keyword">this</span>.l /= <a class="code" href="filesys_8c.html#a5">fatSectorsPerCluster</a>;00429     <span class="comment">/* this.l is now the current cluster number */</span>00430     00431     00432     <span class="comment">/* now let's find the FAT entry for this.l cluster */</span>00433     <span class="keywordflow">if</span> (!<a class="code" href="filesys_8h.html#a0">IS_FAT_32</a>){ <span class="comment">//FAT16</span>00434       entryNumber = <span class="keyword">this</span>.b.b0; <span class="comment">/* 256 entries / page in FAT16 table */</span>00435       fatSector.<a class="code" href="unionAddress.html#o0">l</a> = <span class="keyword">this</span>.l &gt;&gt; 8; <span class="comment">/* Div by n of entries/page in FAT16 tbl*/</span>00436     }<span class="keywordflow">else</span>{ <span class="comment">//FAT32</span>00437       entryNumber = (<span class="keyword">this</span>.b.b0 &amp; 0x7f); <span class="comment">/* 128 entries/page in FAT32 table */</span>00438       fatSector.<a class="code" href="unionAddress.html#o0">l</a> = <span class="keyword">this</span>.l &gt;&gt; 7; <span class="comment">/* Div by n of entries/page in FAT32 tbl*/</span>00439     }00440     fatSector.<a class="code" href="unionAddress.html#o0">l</a> += <a class="code" href="filesys_8c.html#a2">fatStart</a>;00441     <span class="comment">/* fatSector.l is now the DISK SECTOR NUMBER CONTAINING THE FAT table */</span>00442     <span class="comment">/* read this page into memory */</span>00443     <a class="code" href="storage_8h.html#a2">ReadDiskSector</a>(fatSector.<a class="code" href="unionAddress.html#o0">l</a>);    00444     00445     <span class="keywordflow">if</span> (!<a class="code" href="filesys_8h.html#a0">IS_FAT_32</a>){ <span class="comment">//FAT16</span>00446       next.<a class="code" href="unionAddress.html#o0">l</a> = <a class="code" href="buffer_8c.html#a0">diskSect</a>.<a class="code" href="unionDiskBlock.html#o3">Fat16Table</a>[entryNumber]; <span class="comment">/* get next cluster n */</span>00447       <span class="comment">/* Check for FAT16 end-of-file condition */</span>00448       <span class="keywordflow">if</span> ((next.<a class="code" href="unionAddress.html#o1">b</a>.<a class="code" href="structAddress_1_1B.html#o1">b1</a> == 0xff) &amp;&amp; (next.<a class="code" href="unionAddress.html#o1">b</a>.<a class="code" href="structAddress_1_1B.html#o0">b0</a> == 0xff)){00449         <span class="comment">/* FAT16 End of file */</span>00450         next.<a class="code" href="unionAddress.html#o1">b</a>.<a class="code" href="structAddress_1_1B.html#o3">b3</a> = 0xff; <span class="comment">/* return a large value (fat32 compatible) */</span>00451       }00452     }<span class="keywordflow">else</span>{ <span class="comment">//FAT32</span>00453       next.<a class="code" href="unionAddress.html#o0">l</a> = <a class="code" href="buffer_8c.html#a0">diskSect</a>.<a class="code" href="unionDiskBlock.html#o4">Fat32Table</a>[entryNumber]&amp;0x0fffffff;00454     }00455     <span class="comment">/* next.l is the FAT entry (next cluster number) */</span>00456     00457     00458     ConsoleWrite(<span class="stringliteral">"\rFragment start: cluster "</span>);00459     ConsolePutUInt(<span class="keyword">this</span>.l);00460     ConsoleWrite(<span class="stringliteral">"sector "</span>);00461     ConsolePutUInt(fragment[c].start);00462 00463     <span class="keywordflow">while</span> (next.<a class="code" href="unionAddress.html#o0">l</a>==(<span class="keyword">this</span>.l+1)){00464       <span class="comment">//Not a fragment break -- continue to next entry </span>00465 00466       <span class="comment">//in this temp.l is used only to allow compiler memory spilling to temp</span>00467       <a class="code" href="board_8c.html#a0">temp</a>.<a class="code" href="unionTemp.html#o2">l</a> = <a class="code" href="filesys_8c.html#a6">fragment</a>[c].<a class="code" href="structfragmentEntry.html#o1">length</a>;00468       <a class="code" href="board_8c.html#a0">temp</a>.<a class="code" href="unionTemp.html#o2">l</a> += <a class="code" href="filesys_8c.html#a5">fatSectorsPerCluster</a>;00469       <a class="code" href="filesys_8c.html#a6">fragment</a>[c].<a class="code" href="structfragmentEntry.html#o1">length</a> = <a class="code" href="board_8c.html#a0">temp</a>.<a class="code" href="unionTemp.html#o2">l</a>;00470 00471       entryNumber++;00472 00473       <span class="comment">// --- Check for a page break</span>00474       <span class="keywordflow">if</span> (entryNumber==0){ <span class="comment">//entryNumber has rolled over!!!! (8bit char)</span>00475         <span class="comment">//FAT16 table page border is reached</span>00476         fatSector.<a class="code" href="unionAddress.html#o0">l</a>++; <span class="comment">//Advance to next page;</span>00477         entryNumber=0;00478         <a class="code" href="storage_8h.html#a2">ReadDiskSector</a>(fatSector.<a class="code" href="unionAddress.html#o0">l</a>);00479       }00480       <span class="keywordflow">if</span> (<a class="code" href="filesys_8h.html#a0">IS_FAT_32</a> &amp;&amp; (entryNumber==128)){00481         <span class="comment">//FAT32 table page border is reached</span>00482         fatSector.<a class="code" href="unionAddress.html#o0">l</a>++;00483         entryNumber=0;00484         <a class="code" href="storage_8h.html#a2">ReadDiskSector</a>(fatSector.<a class="code" href="unionAddress.html#o0">l</a>);00485       }00486       00487       <span class="comment">// --- Advance to next cluster</span>00488       <span class="keyword">this</span>.l = next.<a class="code" href="unionAddress.html#o0">l</a>;00489       00490       <span class="keywordflow">if</span> (!<a class="code" href="filesys_8h.html#a0">IS_FAT_32</a>){00491         <span class="comment">//FAT16 get next cluster n</span>00492         next.<a class="code" href="unionAddress.html#o0">l</a> = <a class="code" href="buffer_8c.html#a0">diskSect</a>.<a class="code" href="unionDiskBlock.html#o3">Fat16Table</a>[entryNumber];       00493         <span class="keywordflow">if</span> ((next.<a class="code" href="unionAddress.html#o1">b</a>.<a class="code" href="structAddress_1_1B.html#o1">b1</a>==0xff)&amp;&amp;(next.<a class="code" href="unionAddress.html#o1">b</a>.<a class="code" href="structAddress_1_1B.html#o0">b0</a>==0xff)){00494           <span class="comment">//FAT16 end-of-file</span>00495           next.<a class="code" href="unionAddress.html#o1">b</a>.<a class="code" href="structAddress_1_1B.html#o3">b3</a> = 0xff; <span class="comment">//mark end-of-file (FAT32 compatible)</span>00496         }00497       }<span class="keywordflow">else</span>{00498         <span class="comment">//FAT32 get next cluster n</span>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -