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="stylesheet" href="../css_e.css" type="text/css" media="screen" title="ELM Default"> 7<title>FatFs - f_forward</title> 8</head> 9 10<body> 11 12<div class="para func"> 13<h2>f_forward</h2> 14<p>The f_forward function reads the file data and forward it to the data streaming device.</p> 15<pre> 16FRESULT f_forward ( 17 FIL* <span class="arg">fp</span>, <span class="c">/* [IN] File object */</span> 18 UINT (*<span class="arg">func</span>)(const BYTE*,UINT), <span class="c">/* [IN] Data streaming function */</span> 19 UINT <span class="arg">btf</span>, <span class="c">/* [IN] Number of bytes to forward */</span> 20 UINT* <span class="arg">bf</span> <span class="c">/* [OUT] Number of bytes forwarded */</span> 21); 22</pre> 23</div> 24 25<div class="para arg"> 26<h4>Parameters</h4> 27<dl class="par"> 28<dt>fp</dt> 29<dd>Pointer to the open file object. If a null pointer is given, the function fails with <tt>FR_INVALID_OBJECT</tt>.</dd> 30<dt>func</dt> 31<dd>Pointer to the user-defined data streaming function. For details, refer to the sample code.</dd> 32<dt>btf</dt> 33<dd>Number of bytes to forward in range of <tt>UINT</tt>.</dd> 34<dt>bf</dt> 35<dd>Pointer to the variable in <tt>UINT</tt> type to return number of bytes forwarded.</dd> 36</dl> 37</div> 38 39 40<div class="para ret"> 41<h4>Return Values</h4> 42<p> 43<a href="rc.html#ok">FR_OK</a>, 44<a href="rc.html#de">FR_DISK_ERR</a>, 45<a href="rc.html#ie">FR_INT_ERR</a>, 46<a href="rc.html#io">FR_INVALID_OBJECT</a>, 47<a href="rc.html#dn">FR_DENIED</a>, 48<a href="rc.html#tm">FR_TIMEOUT</a> 49</p> 50</div> 51 52 53<div class="para desc"> 54<h4>Description</h4> 55<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> 56</div> 57 58 59<div class="para comp"> 60<h4>QuickInfo</h4> 61<p>Available when <tt><a href="config.html#use_forward">FF_USE_FORWARD</a> == 1</tt>.</p> 62</div> 63 64 65<div class="para use"> 66<h4>Example</h4> 67<pre> 68<span class="c">/*------------------------------------------------------------------------*/</span> 69<span class="c">/* Sample code of data transfer function to be called back from f_forward */</span> 70<span class="c">/*------------------------------------------------------------------------*/</span> 71 72UINT out_stream ( <span class="c">/* Returns number of bytes sent or stream status */</span> 73 const BYTE *p, <span class="c">/* Pointer to the data block to be sent */</span> 74 UINT btf <span class="c">/* >0: Transfer call (Number of bytes to be sent). 0: Sense call */</span> 75) 76{ 77 UINT cnt = 0; 78 79 80 if (btf == 0) { <span class="c">/* Sense call */</span> 81 <span class="c">/* Return stream status (0: Busy, 1: Ready) */</span> 82 <span class="c">/* When once it returned ready to sense call, it must accept a byte at least */</span> 83 <span class="c">/* at subsequent transfer call, or f_forward will fail with FR_INT_ERR. */</span> 84 if (FIFO_READY) cnt = 1; 85 } 86 else { <span class="c">/* Transfer call */</span> 87 do { <span class="c">/* Repeat while there is any data to be sent and the stream is ready */</span> 88 FIFO_PORT = *p++; 89 cnt++; 90 } while (cnt < btf && FIFO_READY); 91 } 92 93 return cnt; 94} 95 96 97<span class="c">/*------------------------------------------------------------------------*/</span> 98<span class="c">/* Sample code using f_forward function */</span> 99<span class="c">/*------------------------------------------------------------------------*/</span> 100 101FRESULT play_file ( 102 char *fn <span class="c">/* Pointer to the audio file name to be played */</span> 103) 104{ 105 FRESULT rc; 106 FIL fil; 107 UINT dmy; 108 109 <span class="c">/* Open the audio file in read only mode */</span> 110 rc = <em>f_open</em>(&fil, fn, FA_READ); 111 if (rc) return rc; 112 113 <span class="c">/* Repeat until the file pointer reaches end of the file */</span> 114 while (rc == FR_OK && !<em>f_eof</em>(&fil)) { 115 116 <span class="c">/* some processes... */</span> 117 118 <span class="c">/* Fill output stream periodicaly or on-demand */</span> 119 rc = <em>f_forward</em>(&fil, out_stream, 1000, &dmy); 120 } 121 122 <span class="c">/* Close the file and return */</span> 123 <em>f_close</em>(&fil); 124 return rc; 125} 126</pre> 127</div> 128 129 130<div class="para ref"> 131<h4>See Also</h4> 132<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> 133</div> 134 135 136<p class="foot"><a href="../00index_e.html">Return</a></p> 137</body> 138</html> 139