{"id":340,"date":"2018-02-16T02:42:43","date_gmt":"2018-02-16T02:42:43","guid":{"rendered":"http:\/\/fpganow.com\/?p=340"},"modified":"2018-02-16T13:50:22","modified_gmt":"2018-02-16T13:50:22","slug":"coding-standards-matter","status":"publish","type":"post","link":"https:\/\/fpganow.com\/index.php\/2018\/02\/16\/coding-standards-matter\/","title":{"rendered":"Coding Standards Matter&#8230;"},"content":{"rendered":"<p>I have wired up the components of my 10 Gigabit FPGA Accelerated Network card with great care, and I decided to have my &#8220;tester&#8221; application skip the lwIP stack and to pass the received packet directly to the host for testing\/verification purposes.<\/p>\n<p>Everything was checking out fine, the LabVIEW code looked flawless, the interface to the 10 Gigabit Transceiver was perfect.\u00a0 All looked fine, but for some reason I was not receiving the packets on the host.<\/p>\n<p>I analyzed the code, inserted probes and what not.\u00a0 And finally, I was reading through the actual C++ code (MicroBlaze C++ that is) I found the bug.<\/p>\n<p>A very simple bug hidden in plain sight!<\/p>\n<hr \/>\n<p>\/\/ Now echo the data back out<br \/>\nif (XLlFifo_iTxVacancy(fifo_1)) {<br \/>\nXGpio_DiscreteWrite(&amp;gpio_2, 2, 0xF001);<br \/>\nfor ( i = 0; i &lt; recv_len_bytes; i++) {<br \/>\nXGpio_DiscreteWrite(&amp;gpio_2, 2, buffer[i]);<\/p>\n<p>XLlFifo_Write(fifo_1, buffer, recv_len_bytes);<\/p>\n<p>}<\/p>\n<p>XLlFifo_iTxSetLen(fifo_1, recv_len_bytes);<br \/>\n}<\/p>\n<hr \/>\n<p>Do you see the error?\u00a0 Well, neither did I, until I read the documentation for XLlFifo_Write again, for the umteenth time&#8230; I was writing the data of the packet to the buffer (length of packet) squared times! Why? Because the single call to XLlFifo_Write is writing the entire packet on each call.<\/p>\n<p>Anyway, I am now re-synthesizing my code and we will see what happens when I run it in around 2 hours time.<\/p>\n<p>Also, I added the TKEEP signal to my AXI Stream FIFO, and it worked exactly as expected, meaning that:<\/p>\n<ul class=\"ili-indent\">\n<li>If I send 12 bytes from the LabVIEW FPGA FIFO in to the MicroBlaze, it detects 12 bytes<\/li>\n<li>If I send 13 bytes, with the TKEEP signal being 0b0001 for the last word only, and 0xF for the rest, I get 13 bytes in the MicroBlaze code.<\/li>\n<li>If I send 14 bytes&#8230; and so on and so forth, MicroBlaze recognized only that many bytes.<\/li>\n<\/ul>\n<p>However, everything was aligned to 32 bit words.<\/p>\n<p>Maybe I will work on cleaning up and pushing some of my code to github while I wait&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have wired up the components of my 10 Gigabit FPGA Accelerated Network card with great care, and I decided to have my &#8220;tester&#8221; application skip the lwIP stack and to pass the received packet directly to the host for testing\/verification purposes. Everything was checking out fine, the LabVIEW code looked flawless, the interface to &#8230; <a title=\"Coding Standards Matter&#8230;\" class=\"read-more\" href=\"https:\/\/fpganow.com\/index.php\/2018\/02\/16\/coding-standards-matter\/\" aria-label=\"Read more about Coding Standards Matter&#8230;\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-340","post","type-post","status-publish","format-standard","hentry","category-uncategorized","masonry-post","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50"],"_links":{"self":[{"href":"https:\/\/fpganow.com\/index.php\/wp-json\/wp\/v2\/posts\/340","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fpganow.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fpganow.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fpganow.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fpganow.com\/index.php\/wp-json\/wp\/v2\/comments?post=340"}],"version-history":[{"count":3,"href":"https:\/\/fpganow.com\/index.php\/wp-json\/wp\/v2\/posts\/340\/revisions"}],"predecessor-version":[{"id":344,"href":"https:\/\/fpganow.com\/index.php\/wp-json\/wp\/v2\/posts\/340\/revisions\/344"}],"wp:attachment":[{"href":"https:\/\/fpganow.com\/index.php\/wp-json\/wp\/v2\/media?parent=340"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fpganow.com\/index.php\/wp-json\/wp\/v2\/categories?post=340"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fpganow.com\/index.php\/wp-json\/wp\/v2\/tags?post=340"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}