OpenCores
URL https://opencores.org/ocsvn/usb_fpga_2_14/usb_fpga_2_14/trunk

Subversion Repositories usb_fpga_2_14

[/] [usb_fpga_2_14/] [trunk/] [docs/] [c/] [html/] [ucecho_8c.html] - Rev 2

Compare with Previous | Blame | View Log

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.8"/>
<title>ZTEX core API for C: ucecho.c File Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">ZTEX core API for C
   </div>
   <div id="projectbrief">Host software API for ZTEX FPGA Boards for C</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.8 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('ucecho_8c.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a></div>
 
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>
 
<div class="header">
  <div class="headertitle">
<div class="title">ucecho.c File Reference</div>  </div>
</div><!--header-->
<div class="contents">
 
<p>ucecho example for C.  
<a href="#details">More...</a></p>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>ucecho example for C. </p>
<p>This example demonstrates the usage of the C API and the low speed interface of default firmware.</p>
<p>The host software writes data to this interface, the FPGA converts it to uppercase and stores it such that it can be read back from the host through the low speed interface.</p>
<p>The correct bitstream is detected and found automatically if the binary is executed from the directory tree of the SDK. Otherwise it can be specified with parameter '-s'.</p>
<p>Full list of options can be obtained with '-h' </p><div class="fragment"><div class="line"><span class="comment">/*#</span></div>
<div class="line"><span class="comment">   ZTEX Core API for C with examples</span></div>
<div class="line"><span class="comment">   Copyright (C) 2009-2017 ZTEX GmbH.</span></div>
<div class="line"><span class="comment">   http://www.ztex.de</span></div>
<div class="line"><span class="comment"></span></div>
<div class="line"><span class="comment">   This program is free software; you can redistribute it and/or modify</span></div>
<div class="line"><span class="comment">   it under the terms of the GNU General Public License version 3 as</span></div>
<div class="line"><span class="comment">   published by the Free Software Foundation.</span></div>
<div class="line"><span class="comment"></span></div>
<div class="line"><span class="comment">   This program is distributed in the hope that it will be useful, but</span></div>
<div class="line"><span class="comment">   WITHOUT ANY WARRANTY; without even the implied warranty of</span></div>
<div class="line"><span class="comment">   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span></div>
<div class="line"><span class="comment">   General Public License for more details.</span></div>
<div class="line"><span class="comment"></span></div>
<div class="line"><span class="comment">   You should have received a copy of the GNU General Public License</span></div>
<div class="line"><span class="comment">   along with this program; if not, see http://www.gnu.org/licenses/.</span></div>
<div class="line"><span class="comment">#*/</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include &lt;stdio.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;stdarg.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;stdlib.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;string.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;sys/types.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;fcntl.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;libusb-1.0/libusb.h&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include &quot;<a class="code" href="ztex_8h.html">ztex.h</a>&quot;</span></div>
<div class="line"></div>
<div class="line"><span class="keyword">static</span> <span class="keywordtype">char</span>* prog_name = NULL;          <span class="comment">// name of the programm</span></div>
<div class="line"></div>
<div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span> paramerr(<span class="keyword">const</span> <span class="keywordtype">char</span>* format,...)</div>
<div class="line">{</div>
<div class="line">    fprintf(stderr, <span class="stringliteral">&quot;Usage: %s options\n&quot;</span>,prog_name);</div>
<div class="line">    fprintf(stderr, <span class="stringliteral">&quot;  -h                           Display this usage information\n&quot;</span></div>
<div class="line">                    <span class="stringliteral">&quot;  -fu &lt;vendor ID&gt;:&lt;product ID&gt; Select device by USB IDs, default: 0x221A:0x100, &lt;0:ignore ID\n&quot;</span></div>
<div class="line">                    <span class="stringliteral">&quot;  -fd &lt;bus&gt;:&lt;device&gt;           Select device by bus number and device address\n&quot;</span></div>
<div class="line">                    <span class="stringliteral">&quot;  -fs &lt;string&gt;                 Select device by serial number string\n&quot;</span></div>
<div class="line">                    <span class="stringliteral">&quot;  -fp &lt;string&gt;                 Select device by product string\n&quot;</span></div>
<div class="line">                    <span class="stringliteral">&quot;  -s &lt;path&gt;                    Addtional search path for bitstream, default &#39;..&quot;</span>DIRSEP<span class="stringliteral">&quot;..&quot;</span>DIRSEP<span class="stringliteral">&quot;examples&quot;</span>DIRSEP<span class="stringliteral">&quot;ucecho&#39;\n&quot;</span></div>
<div class="line">                    <span class="stringliteral">&quot;  -r                           Reset device (default: reset configuration only)\n&quot;</span></div>
<div class="line">                    <span class="stringliteral">&quot;  -i                           Print device info\n&quot;</span></div>
<div class="line">                    <span class="stringliteral">&quot;  -p                           Print matching USB devices\n&quot;</span></div>
<div class="line">                    <span class="stringliteral">&quot;  -pa                          Print all USB devices\n&quot;</span></div>
<div class="line">            );</div>
<div class="line">    <span class="keywordflow">if</span> ( format ) {</div>
<div class="line">        va_list args;</div>
<div class="line">        va_start(args,format);</div>
<div class="line">        vfprintf(stderr, format, args);</div>
<div class="line">        va_end(args);</div>
<div class="line">        <span class="keywordflow">return</span> 1;</div>
<div class="line">    }</div>
<div class="line">    <span class="keywordflow">return</span> 0;</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)</div>
<div class="line">{</div>
<div class="line">    <span class="keywordtype">int</span> id_vendor = 0x221A;     <span class="comment">// ZTEX vendor ID</span></div>
<div class="line">    <span class="keywordtype">int</span> id_product = 0x100;     <span class="comment">// default product ID for ZTEX firmware</span></div>
<div class="line">    <span class="keywordtype">int</span> status = 0;</div>
<div class="line">    libusb_device **devs = NULL;</div>
<div class="line">    <span class="keywordtype">int</span> print_all=0, print=0, print_info=0, reset_dev=0;</div>
<div class="line">    <span class="keywordtype">int</span> busnum = -1, devnum = -1;</div>
<div class="line">    <span class="keywordtype">char</span> *sn_string = NULL, *product_string = NULL;</div>
<div class="line">    libusb_device_handle *handle = NULL;</div>
<div class="line">    <a class="code" href="structztex__device__info.html">ztex_device_info</a> info;</div>
<div class="line">    <span class="keywordtype">char</span> *bitstream_fn = NULL, *bitstream_path = NULL;</div>
<div class="line">    <span class="keywordtype">char</span> sbuf[8192];</div>
<div class="line">    uint8_t cbuf[1024];</div>
<div class="line">    uint32_t vbuf[256];</div>
<div class="line">    <span class="keywordtype">int</span> vlen,slen;</div>
<div class="line"></div>
<div class="line">    prog_name = argv[0];</div>
<div class="line">    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=1; i&lt;argc; i++) {</div>
<div class="line">        <span class="keywordflow">if</span> ( !strcmp(argv[i],<span class="stringliteral">&quot;-h&quot;</span>) ) <span class="keywordflow">return</span> paramerr(NULL);</div>
<div class="line">        <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( !strcmp(argv[i],<span class="stringliteral">&quot;-p&quot;</span>) ) print=1;</div>
<div class="line">        <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( !strcmp(argv[i],<span class="stringliteral">&quot;-pa&quot;</span>) ) print_all=1;</div>
<div class="line">        <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( !strcmp(argv[i],<span class="stringliteral">&quot;-i&quot;</span>) ) print_info=1;</div>
<div class="line">        <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( !strcmp(argv[i],<span class="stringliteral">&quot;-r&quot;</span>) ) reset_dev=1;</div>
<div class="line">        <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( !strcmp(argv[i],<span class="stringliteral">&quot;-fu&quot;</span>) ) {</div>
<div class="line">            i++;</div>
<div class="line">            <span class="keywordflow">if</span> (i&gt;=argc || sscanf(argv[i],<span class="stringliteral">&quot;%i:%i&quot;</span>, &amp;id_vendor, &amp;id_product)!=2 ) <span class="keywordflow">return</span> paramerr(<span class="stringliteral">&quot;Error: &lt;vendor ID&gt;:&lt;product ID&gt; expected after -fu\n&quot;</span>);</div>
<div class="line">        }</div>
<div class="line">        <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( !strcmp(argv[i],<span class="stringliteral">&quot;-fd&quot;</span>) ) {</div>
<div class="line">            i++;</div>
<div class="line">            <span class="keywordflow">if</span> (i&gt;=argc || sscanf(argv[i],<span class="stringliteral">&quot;%i:%i&quot;</span>, &amp;busnum, &amp;devnum)!=2 ) <span class="keywordflow">return</span> paramerr(<span class="stringliteral">&quot;Error: &lt;bus&gt;:&lt;device&gt; expected after -fd\n&quot;</span>);</div>
<div class="line">        }</div>
<div class="line">        <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( !strcmp(argv[i],<span class="stringliteral">&quot;-fs&quot;</span>) ) {</div>
<div class="line">            i++;</div>
<div class="line">            <span class="keywordflow">if</span> (i&gt;=argc ) <span class="keywordflow">return</span> paramerr(<span class="stringliteral">&quot;Error: &lt;string&gt; expected after -fs\n&quot;</span>);</div>
<div class="line">            sn_string = argv[i];</div>
<div class="line">        }</div>
<div class="line">        <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( !strcmp(argv[i],<span class="stringliteral">&quot;-fp&quot;</span>) ) {</div>
<div class="line">            i++;</div>
<div class="line">            <span class="keywordflow">if</span> (i&gt;=argc ) <span class="keywordflow">return</span> paramerr(<span class="stringliteral">&quot;Error: &lt;string&gt; expected after -fp\n&quot;</span>);</div>
<div class="line">            product_string = argv[i];</div>
<div class="line">        }</div>
<div class="line">        <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( !strcmp(argv[i],<span class="stringliteral">&quot;-s&quot;</span>) ) {</div>
<div class="line">            i++;</div>
<div class="line">            <span class="keywordflow">if</span> (i&gt;=argc ) <span class="keywordflow">return</span> paramerr(<span class="stringliteral">&quot;Error: &lt;path&gt; expected after -s\n&quot;</span>);</div>
<div class="line">            bitstream_path = argv[i];</div>
<div class="line">        }</div>
<div class="line">        <span class="keywordflow">else</span> <span class="keywordflow">return</span> paramerr(<span class="stringliteral">&quot;Error: Invalid parameter %s\n&quot;</span>, argv[i]);</div>
<div class="line">    }</div>
<div class="line"></div>
<div class="line">    <span class="comment">// INIT libusb</span></div>
<div class="line">    status = libusb_init(NULL);</div>
<div class="line">    <span class="keywordflow">if</span> (status &lt; 0) {</div>
<div class="line">        fprintf(stderr,<span class="stringliteral">&quot;Error: Unable to init libusb: %s\n&quot;</span>, libusb_error_name(status));</div>
<div class="line">        <span class="keywordflow">return</span> 1;</div>
<div class="line">    }</div>
<div class="line"></div>
<div class="line">    <span class="comment">// find all USB devices</span></div>
<div class="line">    status = libusb_get_device_list(NULL, &amp;devs);</div>
<div class="line">    <span class="keywordflow">if</span> (status &lt; 0) {</div>
<div class="line">        fprintf(stderr,<span class="stringliteral">&quot;Error: Unable to get device list: %s\n&quot;</span>, libusb_error_name(status));</div>
<div class="line">        <span class="keywordflow">goto</span> err;</div>
<div class="line">    }</div>
<div class="line">    </div>
<div class="line">    <span class="comment">// print bus info or find device</span></div>
<div class="line">    <span class="keywordtype">int</span> dev_idx = <a class="code" href="ztex_8h.html#a8ee4c93eef23fbc8044347a7ce351cf5">ztex_scan_bus</a>(sbuf, <span class="keyword">sizeof</span>(sbuf), devs, print_all ? -1 : print ? 1 : 0, id_vendor, id_product, busnum, devnum, sn_string, product_string);</div>
<div class="line">    printf(sbuf);</div>
<div class="line">    <span class="keywordflow">if</span> ( print || print_all ) {</div>
<div class="line">        status = 0;</div>
<div class="line">        <span class="keywordflow">goto</span> noerr;</div>
<div class="line">    } <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( dev_idx&lt;0 ) {</div>
<div class="line">        <span class="keywordflow">if</span> (dev_idx==-1) fprintf(stderr,<span class="stringliteral">&quot;Error: No device found\n&quot;</span>);</div>
<div class="line">        <span class="keywordflow">goto</span> err;</div>
<div class="line">    }</div>
<div class="line"></div>
<div class="line">    <span class="comment">// open device</span></div>
<div class="line">    status = libusb_open(devs[dev_idx], &amp;handle);</div>
<div class="line">    <span class="keywordflow">if</span> (status &lt; 0) {</div>
<div class="line">        fprintf(stderr,<span class="stringliteral">&quot;Error: Unable to open device: %s\n&quot;</span>, libusb_error_name(status));</div>
<div class="line">        <span class="keywordflow">goto</span> err;</div>
<div class="line">    }</div>
<div class="line">    libusb_free_device_list(devs, 1);</div>
<div class="line">    devs=NULL;</div>
<div class="line">    libusb_set_configuration(handle,1);</div>
<div class="line">    </div>
<div class="line">    <span class="comment">// reset configuration or device</span></div>
<div class="line">   <span class="keywordflow">if</span> ( ! reset_dev ) {</div>
<div class="line">        status = libusb_set_configuration(handle,-1);</div>
<div class="line">        <span class="keywordflow">if</span> (status &lt; 0) {</div>
<div class="line">            fprintf(stderr,<span class="stringliteral">&quot;Warning: Unable to unconfigure device: %s, trying to reset it\n&quot;</span>, libusb_error_name(status));</div>
<div class="line"><span class="preprocessor">#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)</span></div>
<div class="line">            fprintf(stderr,<span class="stringliteral">&quot;Due to limitations of Windows neither this nor device reset works. This may cause further errors ...\n&quot;</span>);</div>
<div class="line"><span class="preprocessor">#endif    </span></div>
<div class="line">            reset_dev = 1;</div>
<div class="line">        }</div>
<div class="line">    }</div>
<div class="line">    <span class="keywordflow">if</span> ( reset_dev ) {</div>
<div class="line">        status = libusb_reset_device(handle);</div>
<div class="line">        <span class="keywordflow">if</span> (status &lt; 0) {</div>
<div class="line">            fprintf(stderr,<span class="stringliteral">&quot;Error: Unable to reset device: %s\n&quot;</span>, libusb_error_name(status));</div>
<div class="line">            <span class="keywordflow">goto</span> err;</div>
<div class="line">        }</div>
<div class="line">    }</div>
<div class="line">    status = libusb_set_configuration(handle,1);</div>
<div class="line">    <span class="keywordflow">if</span> (status &lt; 0) fprintf(stderr,<span class="stringliteral">&quot;Warning: Unable to set configuration 1: %s\n&quot;</span>, libusb_error_name(status));</div>
<div class="line">    fflush(stderr);</div>
<div class="line"></div>
<div class="line">    </div>
<div class="line">    <span class="comment">// get and print device info</span></div>
<div class="line">    status = <a class="code" href="ztex_8h.html#a28cef9d1e168b782b03579c4a59505d3">ztex_get_device_info</a>(handle, &amp;info);</div>
<div class="line">    <span class="keywordflow">if</span> ( status &lt; 0 ) {</div>
<div class="line">        fprintf(stderr,<span class="stringliteral">&quot;Error: Unable to get device info: %s\n&quot;</span>, libusb_error_name(status));</div>
<div class="line">        <span class="keywordflow">goto</span> err;</div>
<div class="line">    }</div>
<div class="line">    <span class="keywordflow">if</span> ( print_info ) {</div>
<div class="line">        <a class="code" href="ztex_8h.html#aa64c1cefed076a0f48cafa1882593c79">ztex_print_device_info</a>( sbuf, <span class="keyword">sizeof</span>(sbuf), &amp;info );</div>
<div class="line">        printf(sbuf);</div>
<div class="line">        status = <a class="code" href="ztex_8h.html#ae679e66864c90211a3d8b4670a64d497">ztex_get_fpga_config</a>(handle);</div>
<div class="line">        <span class="keywordflow">if</span> ( status &lt; 0 ) {</div>
<div class="line">            fprintf(stderr,<span class="stringliteral">&quot;Error: Unable to get FPGA configuration state: %s\n&quot;</span>, libusb_error_name(status));</div>
<div class="line">            <span class="keywordflow">goto</span> err;</div>
<div class="line">        }</div>
<div class="line">        printf(<span class="stringliteral">&quot;FPGA: %s\n&quot;</span>, status==0 ? <span class="stringliteral">&quot;unconfigured&quot;</span> : <span class="stringliteral">&quot;configured&quot;</span>);</div>
<div class="line">        status = 0;</div>
<div class="line">        <span class="keywordflow">goto</span> noerr;</div>
<div class="line">    }</div>
<div class="line">    fflush(stderr);</div>
<div class="line">    </div>
<div class="line">    <span class="comment">// find bitstream</span></div>
<div class="line">    bitstream_fn = <a class="code" href="ztex_8h.html#a74c89f5aa7e3754d88f1dc95846b5cbe">ztex_find_bitstream</a>( &amp;info, bitstream_path ? bitstream_path : <span class="stringliteral">&quot;..&quot;</span>DIRSEP<span class="stringliteral">&quot;..&quot;</span>DIRSEP<span class="stringliteral">&quot;examples&quot;</span>DIRSEP<span class="stringliteral">&quot;ucecho&quot;</span> , <span class="stringliteral">&quot;ucecho&quot;</span>);</div>
<div class="line">    <span class="keywordflow">if</span> ( bitstream_fn )  {</div>
<div class="line">        printf(<span class="stringliteral">&quot;Using bitstream &#39;%s&#39;\n&quot;</span>, bitstream_fn);</div>
<div class="line">        fflush(stdout);</div>
<div class="line">    }</div>
<div class="line">    <span class="keywordflow">else</span> {</div>
<div class="line">        fprintf(stderr,<span class="stringliteral">&quot;Warning: Bitstream not found\n&quot;</span>);</div>
<div class="line">        <span class="keywordflow">goto</span> nobitstream;</div>
<div class="line">    }</div>
<div class="line">    </div>
<div class="line">    <span class="comment">// read and upload bitstream</span></div>
<div class="line">    FILE *fd = fopen(bitstream_fn, <span class="stringliteral">&quot;rb&quot;</span>);</div>
<div class="line">    <span class="keywordflow">if</span> ( fd == NULL ) {</div>
<div class="line">        fprintf(stderr,<span class="stringliteral">&quot;Warning: Error opening file &#39;%s&#39;\n&quot;</span>, bitstream_fn);</div>
<div class="line">        <span class="keywordflow">goto</span> nobitstream;</div>
<div class="line">    }</div>
<div class="line">    status = <a class="code" href="ztex_8h.html#a1861aa844f2ad3cacf37bbde0f9d6bcb">ztex_upload_bitstream</a>(sbuf,<span class="keyword">sizeof</span>(sbuf),handle,&amp;info,fd,-1);</div>
<div class="line">    fclose(fd);</div>
<div class="line">    fprintf(stderr,sbuf);</div>
<div class="line">    </div>
<div class="line">nobitstream:</div>
<div class="line">    fflush(stderr);</div>
<div class="line">    status = <a class="code" href="ztex_8h.html#ae679e66864c90211a3d8b4670a64d497">ztex_get_fpga_config</a>(handle);</div>
<div class="line">    <span class="keywordflow">if</span> ( status &lt; 0 ) {</div>
<div class="line">        fprintf(stderr,<span class="stringliteral">&quot;Error: Unable to get FPGA configuration state: %s\n&quot;</span>, libusb_error_name(status));</div>
<div class="line">        <span class="keywordflow">goto</span> err;</div>
<div class="line">    } <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( status == 0 ) {</div>
<div class="line">        fprintf(stderr,<span class="stringliteral">&quot;Error: FPGA not configured\n&quot;</span>);</div>
<div class="line">        <span class="keywordflow">goto</span> err;</div>
<div class="line">    }</div>
<div class="line"></div>
<div class="line">    <span class="comment">// ucecho test</span></div>
<div class="line">    sbuf[0]=0;</div>
<div class="line">    <span class="keywordflow">while</span> ( strcmp(sbuf,<span class="stringliteral">&quot;quit&quot;</span>) ) {</div>
<div class="line">        printf(<span class="stringliteral">&quot;Enter a string or `quit&#39; to exit the program: &quot;</span>);</div>
<div class="line">        fflush(stdout);</div>
<div class="line">        fgets(sbuf, <span class="keyword">sizeof</span>(sbuf)-1, stdin);</div>
<div class="line">        slen = strlen(sbuf);</div>
<div class="line">        <span class="keywordflow">while</span> ( (slen&gt;0) &amp;&amp; (sbuf[slen-1]&lt;32) ) slen--;</div>
<div class="line">        sbuf[slen]=0; </div>
<div class="line">        <span class="keywordflow">if</span> ( sbuf[0] ) {</div>
<div class="line">            vlen = (slen+3)&gt;&gt;2;</div>
<div class="line">            <span class="keywordflow">if</span> ( vlen &gt; 256 ) vlen = 256;</div>
<div class="line">            memcpy(cbuf, sbuf, vlen*4);</div>
<div class="line">            <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i&lt;vlen*4; i++) </div>
<div class="line">                vbuf[i] = cbuf[i*4+0] | (cbuf[i*4+1]&lt;&lt;8) | (cbuf[i*4+2]&lt;&lt;16) | (cbuf[i*4+3]&lt;&lt;24);</div>
<div class="line">            printf(<span class="stringliteral">&quot;Send %d words to address 10 ...\n&quot;</span>,vlen);</div>
<div class="line">            status = <a class="code" href="ztex_8h.html#a3e23422eb1fedebf51335b4c4d199b8c">ztex_default_lsi_set2</a>(handle,10,vbuf,vlen);</div>
<div class="line">            <span class="keywordflow">if</span> ( status&lt;0 ) {</div>
<div class="line">                fprintf(stderr,<span class="stringliteral">&quot;Warning: Error writing to LSI: %s\n&quot;</span>, strerror(status));</div>
<div class="line">                <span class="keywordflow">goto</span> err;</div>
<div class="line">            }</div>
<div class="line">            </div>
<div class="line">            status = <a class="code" href="ztex_8h.html#aae9072dbf0828d9782abdd87114e1119">ztex_default_lsi_get2</a>(handle,10,vbuf,vlen);</div>
<div class="line">            <span class="keywordflow">if</span> ( status&lt;0 ) {</div>
<div class="line">                fprintf(stderr,<span class="stringliteral">&quot;Warning: Error reading from to LSI: %s\n&quot;</span>, strerror(status));</div>
<div class="line">                <span class="keywordflow">goto</span> err;</div>
<div class="line">            }</div>
<div class="line">            <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i&lt;vlen; i++) {</div>
<div class="line">                cbuf[i*4+0] = vbuf[i];</div>
<div class="line">                cbuf[i*4+1] = vbuf[i]&gt;&gt;8;</div>
<div class="line">                cbuf[i*4+2] = vbuf[i]&gt;&gt;16;</div>
<div class="line">                cbuf[i*4+3] = vbuf[i]&gt;&gt;24;</div>
<div class="line">            }</div>
<div class="line">            cbuf[slen]=0;</div>
<div class="line">            printf(<span class="stringliteral">&quot;Read %d words starting from 10: %s\n&quot;</span>, vlen, cbuf );  </div>
<div class="line">            </div>
<div class="line">            <span class="keywordflow">if</span> ( vlen&gt;1 ) {</div>
<div class="line">                status = <a class="code" href="ztex_8h.html#aae9072dbf0828d9782abdd87114e1119">ztex_default_lsi_get2</a>(handle,11,vbuf,vlen);</div>
<div class="line">                <span class="keywordflow">if</span> ( status&lt;0 ) {</div>
<div class="line">                    fprintf(stderr,<span class="stringliteral">&quot;Warning: Error reading from to LSI: %s\n&quot;</span>, strerror(status));</div>
<div class="line">                    <span class="keywordflow">goto</span> err;</div>
<div class="line">                }</div>
<div class="line">                <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i&lt;vlen; i++) {</div>
<div class="line">                    cbuf[i*4+0] = vbuf[i];</div>
<div class="line">                    cbuf[i*4+1] = vbuf[i]&gt;&gt;8;</div>
<div class="line">                    cbuf[i*4+2] = vbuf[i]&gt;&gt;16;</div>
<div class="line">                    cbuf[i*4+3] = vbuf[i]&gt;&gt;24;</div>
<div class="line">                }</div>
<div class="line">                cbuf[slen-4]=0;</div>
<div class="line">                printf(<span class="stringliteral">&quot;Read %d words starting from 11: %s\n&quot;</span>, vlen-1, cbuf );  </div>
<div class="line">            }</div>
<div class="line">        }</div>
<div class="line">        printf(<span class="stringliteral">&quot;\n&quot;</span>);</div>
<div class="line">    }</div>
<div class="line"></div>
<div class="line">    <span class="comment">// release resources</span></div>
<div class="line">    status = 0;</div>
<div class="line">    <span class="keywordflow">goto</span> noerr;</div>
<div class="line">err:</div>
<div class="line">    status = 1;</div>
<div class="line">noerr:</div>
<div class="line">    <span class="keywordflow">if</span> ( bitstream_fn ) free(bitstream_fn);</div>
<div class="line">    <span class="keywordflow">if</span> ( handle ) libusb_close(handle);</div>
<div class="line">    <span class="keywordflow">if</span> ( devs ) libusb_free_device_list(devs, 1);</div>
<div class="line">    libusb_exit(NULL);</div>
<div class="line"><span class="preprocessor">#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)</span></div>
<div class="line">    <span class="keywordflow">if</span> ( strcmp(sbuf,<span class="stringliteral">&quot;quit&quot;</span>) ) {</div>
<div class="line">        printf(<span class="stringliteral">&quot;Press &lt;return&gt; to quit\n&quot;</span>);</div>
<div class="line">        fflush(NULL);</div>
<div class="line">        fgetc(stdin);</div>
<div class="line">    }   </div>
<div class="line"><span class="preprocessor">#endif    </span></div>
<div class="line">    <span class="keywordflow">return</span> status;</div>
<div class="line">}</div>
</div><!-- fragment --> </div></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_0f883cfafa81589f73fbd50f77c9be78.html">capi</a></li><li class="navelem"><a class="el" href="dir_811541c6271c17b41af027698e62c386.html">c</a></li><li class="navelem"><a class="el" href="ucecho_8c.html">ucecho.c</a></li>
    <li class="footer">Generated on Wed Mar 22 2017 19:03:08 for ZTEX core API for C by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.8 </li>
  </ul>
</div>
</body>
</html>
 

Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.