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