• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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=utf-8">
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>
18FRESULT 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#dn">FR_DENIED</a>,
50<a href="rc.html#tm">FR_TIMEOUT</a>
51</p>
52</div>
53
54
55<div class="para desc">
56<h4>Description</h4>
57<p>The <tt>f_forward</tt> function reads the data from the file and forward it to the outgoing stream. This function is suitable for small memory system, because it does not require any data buffer in the application module. The file pointer of the file object advances 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 size of data could not be transferred due to end of file or stream goes busy during data transfer.</p>
58</div>
59
60
61<div class="para comp">
62<h4>QuickInfo</h4>
63<p>Available when <tt><a href="config.html#use_forward">FF_USE_FORWARD</a> == 1</tt>.</p>
64</div>
65
66
67<div class="para use">
68<h4>Example</h4>
69<pre>
70<span class="c">/*------------------------------------------------------------------------*/</span>
71<span class="c">/* Sample code of data transfer function to be called back from f_forward */</span>
72<span class="c">/*------------------------------------------------------------------------*/</span>
73
74UINT out_stream (   <span class="c">/* Returns number of bytes sent or stream status */</span>
75    const BYTE *p,  <span class="c">/* Pointer to the data block to be sent */</span>
76    UINT btf        <span class="c">/* &gt;0: Transfer call (Number of bytes to be sent). 0: Sense call */</span>
77)
78{
79    UINT cnt = 0;
80
81
82    if (btf == 0) {     <span class="c">/* Sense call */</span>
83        <span class="c">/* Return stream status (0: Busy, 1: Ready) */</span>
84        <span class="c">/* When once it returned ready to sense call, it must accept a byte at least */</span>
85        <span class="c">/* at subsequent transfer call, or f_forward will fail with FR_INT_ERR. */</span>
86        if (FIFO_READY) cnt = 1;
87    }
88    else {              <span class="c">/* Transfer call */</span>
89        do {    <span class="c">/* Repeat while there is any data to be sent and the stream is ready */</span>
90            FIFO_PORT = *p++;
91            cnt++;
92        } while (cnt &lt; btf &amp;&amp; FIFO_READY);
93    }
94
95    return cnt;
96}
97
98
99<span class="c">/*------------------------------------------------------------------------*/</span>
100<span class="c">/* Sample code using f_forward function                                   */</span>
101<span class="c">/*------------------------------------------------------------------------*/</span>
102
103FRESULT play_file (
104    char *fn        <span class="c">/* Pointer to the audio file name to be played */</span>
105)
106{
107    FRESULT rc;
108    FIL fil;
109    UINT dmy;
110
111    <span class="c">/* Open the audio file in read only mode */</span>
112    rc = f_open(&amp;fil, fn, FA_READ);
113    if (rc) return rc;
114
115    <span class="c">/* Repeat until the file pointer reaches end of the file */</span>
116    while (rc == FR_OK &amp;&amp; !f_eof(&amp;fil)) {
117
118        <span class="c">/* some processes... */</span>
119
120        <span class="c">/* Fill output stream periodicaly or on-demand */</span>
121        rc = <em>f_forward</em>(&amp;fil, out_stream, 1000, &amp;dmy);
122    }
123
124    <span class="c">/* Close the file and return */</span>
125    f_close(&amp;fil);
126    return rc;
127}
128</pre>
129</div>
130
131
132<div class="para ref">
133<h4>See Also</h4>
134<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>
135</div>
136
137<p class="foot"><a href="../00index_e.html">Return</a></p>
138</body>
139</html>
140