]> cloudbase.mooo.com Git - z180-stamp.git/blob - fatfs/doc/en/forward.html
Import fatfs R0.12b
[z180-stamp.git] / fatfs / doc / en / forward.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html lang="en">
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
5 <meta http-equiv="Content-Style-Type" content="text/css">
6 <link rel="up" title="FatFs" href="../00index_e.html">
7 <link rel="alternate" hreflang="ja" title="Japanese" href="../ja/forward.html">
8 <link rel="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default">
9 <title>FatFs - f_forward</title>
10 </head>
11
12 <body>
13
14 <div class="para func">
15 <h2>f_forward</h2>
16 <p>The f_forward function reads the file data and forward it to the data streaming device.</p>
17 <pre>
18 FRESULT f_forward (
19 FIL* <span class="arg">fp</span>, <span class="c">/* [IN] File object */</span>
20 UINT (*<span class="arg">func</span>)(const BYTE*,UINT), <span class="c">/* [IN] Data streaming function */</span>
21 UINT <span class="arg">btf</span>, <span class="c">/* [IN] Number of bytes to forward */</span>
22 UINT* <span class="arg">bf</span> <span class="c">/* [OUT] Number of bytes forwarded */</span>
23 );
24 </pre>
25 </div>
26
27 <div class="para arg">
28 <h4>Parameters</h4>
29 <dl class="par">
30 <dt>fp</dt>
31 <dd>Pointer to the open file object.</dd>
32 <dt>func</dt>
33 <dd>Pointer to the user-defined data streaming function. For details, refer to the sample code.</dd>
34 <dt>btf</dt>
35 <dd>Number of bytes to forward in range of <tt>UINT</tt>.</dd>
36 <dt>bf</dt>
37 <dd>Pointer to the <tt>UINT</tt> variable to return number of bytes forwarded.</dd>
38 </dl>
39 </div>
40
41
42 <div class="para ret">
43 <h4>Return Values</h4>
44 <p>
45 <a href="rc.html#ok">FR_OK</a>,
46 <a href="rc.html#de">FR_DISK_ERR</a>,
47 <a href="rc.html#ie">FR_INT_ERR</a>,
48 <a href="rc.html#io">FR_INVALID_OBJECT</a>,
49 <a href="rc.html#tm">FR_TIMEOUT</a>
50 </p>
51 </div>
52
53
54 <div class="para desc">
55 <h4>Description</h4>
56 <p>The <tt>f_forward</tt> function reads the data from the file and forward it to the outgoing stream without data buffer. This is suitable for small memory system because it does not require any data buffer at application module. The file pointer of the file object increases in number of bytes forwarded. In case of <tt class="arg">*bf</tt> is less than <tt class="arg">btf</tt> without error, it means the requested bytes could not be transferred due to end of file or stream goes busy during data transfer.</p>
57 </div>
58
59
60 <div class="para comp">
61 <h4>QuickInfo</h4>
62 <p>Available when <tt>_USE_FORWARD == 1</tt>.</p>
63 </div>
64
65
66 <div class="para use">
67 <h4>Example (Audio playback)</h4>
68 <pre>
69 <span class="c">/*------------------------------------------------------------------------*/</span>
70 <span class="c">/* Sample code of data transfer function to be called back from f_forward */</span>
71 <span class="c">/*------------------------------------------------------------------------*/</span>
72
73 UINT out_stream ( <span class="c">/* Returns number of bytes sent or stream status */</span>
74 const BYTE *p, <span class="c">/* Pointer to the data block to be sent */</span>
75 UINT btf <span class="c">/* &gt;0: Transfer call (Number of bytes to be sent). 0: Sense call */</span>
76 )
77 {
78 UINT cnt = 0;
79
80
81 if (btf == 0) { <span class="c">/* Sense call */</span>
82 <span class="c">/* Return stream status (0: Busy, 1: Ready) */</span>
83 <span class="c">/* When once it returned ready to sense call, it must accept a byte at least */</span>
84 <span class="c">/* at subsequent transfer call, or f_forward will fail with FR_INT_ERR. */</span>
85 if (FIFO_READY) cnt = 1;
86 }
87 else { <span class="c">/* Transfer call */</span>
88 do { <span class="c">/* Repeat while there is any data to be sent and the stream is ready */</span>
89 FIFO_PORT = *p++;
90 cnt++;
91 } while (cnt &lt; btf &amp;&amp; FIFO_READY);
92 }
93
94 return cnt;
95 }
96
97
98 <span class="c">/*------------------------------------------------------------------------*/</span>
99 <span class="c">/* Sample code using f_forward function */</span>
100 <span class="c">/*------------------------------------------------------------------------*/</span>
101
102 FRESULT play_file (
103 char *fn <span class="c">/* Pointer to the audio file name to be played */</span>
104 )
105 {
106 FRESULT rc;
107 FIL fil;
108 UINT dmy;
109
110 <span class="c">/* Open the audio file in read only mode */</span>
111 rc = f_open(&amp;fil, fn, FA_READ);
112 if (rc) return rc;
113
114 <span class="c">/* Repeat until the file pointer reaches end of the file */</span>
115 while (rc == FR_OK &amp;&amp; !f_eof(&amp;fil)) {
116
117 <span class="c">/* any other processes... */</span>
118
119 <span class="c">/* Fill output stream periodicaly or on-demand */</span>
120 rc = f_forward(&amp;fil, out_stream, 1000, &amp;dmy);
121 }
122
123 <span class="c">/* Close the file and return */</span>
124 f_close(&amp;fil);
125 return rc;
126 }
127 </pre>
128 </div>
129
130
131 <div class="para ref">
132 <h4>See Also</h4>
133 <p><tt><a href="open.html">f_open</a>, <a href="gets.html">fgets</a>, <a href="write.html">f_write</a>, <a href="close.html">f_close</a>, <a href="sfile.html">FIL</a></tt></p>
134 </div>
135
136 <p class="foot"><a href="../00index_e.html">Return</a></p>
137 </body>
138 </html>