Micro template library A library for building device drivers
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test__spi__impl_8cpp_source.html 18 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
  5. <meta http-equiv="X-UA-Compatible" content="IE=9"/>
  6. <meta name="generator" content="Doxygen 1.8.14"/>
  7. <meta name="viewport" content="width=device-width, initial-scale=1"/>
  8. <title>uTL: test/tests/test_spi_impl.cpp Source File</title>
  9. <link href="tabs.css" rel="stylesheet" type="text/css"/>
  10. <script type="text/javascript" src="jquery.js"></script>
  11. <script type="text/javascript" src="dynsections.js"></script>
  12. <link href="navtree.css" rel="stylesheet" type="text/css"/>
  13. <script type="text/javascript" src="resize.js"></script>
  14. <script type="text/javascript" src="navtreedata.js"></script>
  15. <script type="text/javascript" src="navtree.js"></script>
  16. <script type="text/javascript">
  17. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  18. $(document).ready(initResizable);
  19. /* @license-end */</script>
  20. <link href="search/search.css" rel="stylesheet" type="text/css"/>
  21. <script type="text/javascript" src="search/searchdata.js"></script>
  22. <script type="text/javascript" src="search/search.js"></script>
  23. <link href="doxygen.css" rel="stylesheet" type="text/css" />
  24. </head>
  25. <body>
  26. <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
  27. <div id="titlearea">
  28. <table cellspacing="0" cellpadding="0">
  29. <tbody>
  30. <tr style="height: 56px;">
  31. <td id="projectalign" style="padding-left: 0.5em;">
  32. <div id="projectname">uTL
  33. </div>
  34. <div id="projectbrief">micro Template library</div>
  35. </td>
  36. </tr>
  37. </tbody>
  38. </table>
  39. </div>
  40. <!-- end header part -->
  41. <!-- Generated by Doxygen 1.8.14 -->
  42. <script type="text/javascript">
  43. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  44. var searchBox = new SearchBox("searchBox", "search",false,'Search');
  45. /* @license-end */
  46. </script>
  47. <script type="text/javascript" src="menudata.js"></script>
  48. <script type="text/javascript" src="menu.js"></script>
  49. <script type="text/javascript">
  50. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  51. $(function() {
  52. initMenu('',true,false,'search.php','Search');
  53. $(document).ready(function() { init_search(); });
  54. });
  55. /* @license-end */</script>
  56. <div id="main-nav"></div>
  57. </div><!-- top -->
  58. <div id="side-nav" class="ui-resizable side-nav-resizable">
  59. <div id="nav-tree">
  60. <div id="nav-tree-contents">
  61. <div id="nav-sync" class="sync"></div>
  62. </div>
  63. </div>
  64. <div id="splitbar" style="-moz-user-select:none;"
  65. class="ui-resizable-handle">
  66. </div>
  67. </div>
  68. <script type="text/javascript">
  69. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  70. $(document).ready(function(){initNavTree('test__spi__impl_8cpp_source.html','');});
  71. /* @license-end */
  72. </script>
  73. <div id="doc-content">
  74. <!-- window showing the filter options -->
  75. <div id="MSearchSelectWindow"
  76. onmouseover="return searchBox.OnSearchSelectShow()"
  77. onmouseout="return searchBox.OnSearchSelectHide()"
  78. onkeydown="return searchBox.OnSearchSelectKey(event)">
  79. </div>
  80. <!-- iframe showing the search results (closed by default) -->
  81. <div id="MSearchResultsWindow">
  82. <iframe src="javascript:void(0)" frameborder="0"
  83. name="MSearchResults" id="MSearchResults">
  84. </iframe>
  85. </div>
  86. <div class="header">
  87. <div class="headertitle">
  88. <div class="title">test_spi_impl.cpp</div> </div>
  89. </div><!--header-->
  90. <div class="contents">
  91. <a href="test__spi__impl_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span>&#160;</div><div class="line"><a name="l00020"></a><span class="lineno"> 20</span>&#160;<span class="preprocessor">#include &lt;<a class="code" href="gtest_8h.html">gtest/gtest.h</a>&gt;</span></div><div class="line"><a name="l00021"></a><span class="lineno"> 21</span>&#160;<span class="preprocessor">#include &lt;<a class="code" href="spi__bb_8h.html">utl/com/spi_bb.h</a>&gt;</span></div><div class="line"><a name="l00022"></a><span class="lineno"> 22</span>&#160;</div><div class="line"><a name="l00023"></a><span class="lineno"> 23</span>&#160;</div><div class="line"><a name="l00030"></a><span class="lineno"><a class="line" href="namespacetest__spi.html"> 30</a></span>&#160;<span class="keyword">namespace </span><a class="code" href="namespacetest__spi.html">test_spi</a> {</div><div class="line"><a name="l00031"></a><span class="lineno"> 31</span>&#160; <span class="keyword">using namespace </span><a class="code" href="namespaceutl.html">utl</a>;</div><div class="line"><a name="l00032"></a><span class="lineno"> 32</span>&#160;</div><div class="line"><a name="l00033"></a><span class="lineno"> 33</span>&#160; <span class="comment">// implementer class stub</span></div><div class="line"><a name="l00034"></a><span class="lineno"><a class="line" href="classtest__spi_1_1_s_p_i.html"> 34</a></span>&#160; <span class="keyword">class </span><a class="code" href="classtest__spi_1_1_s_p_i.html">SPI</a> : <span class="keyword">public</span> <a class="code" href="classutl_1_1spi__bb__i.html">spi_bb_i</a>&lt;SPI, spi::cpol::LOW, spi::cpha::LOW&gt; {</div><div class="line"><a name="l00035"></a><span class="lineno"> 35</span>&#160; <span class="keyword">friend</span> <a class="code" href="classutl_1_1spi__bb__i.html">spi_bb_i&lt;SPI, spi::cpol::LOW, spi::cpha::LOW&gt;</a>;</div><div class="line"><a name="l00036"></a><span class="lineno"> 36</span>&#160; <span class="keywordtype">void</span> MOSI (<span class="keywordtype">bool</span> st) { (void)st; } <span class="comment">// Imaginary pin functionality</span></div><div class="line"><a name="l00037"></a><span class="lineno"> 37</span>&#160; <span class="keywordtype">bool</span> MISO () { <span class="keywordflow">return</span> <span class="keyword">true</span>; } <span class="comment">// All reads become 0xFF</span></div><div class="line"><a name="l00038"></a><span class="lineno"> 38</span>&#160; <span class="keywordtype">void</span> SCLK (<span class="keywordtype">bool</span> st) { (void)st; } <span class="comment">// Imaginary pin functionality</span></div><div class="line"><a name="l00039"></a><span class="lineno"> 39</span>&#160; <span class="keywordtype">void</span> delay (uint32_t nsec) { (void)nsec; } <span class="comment">// Imaginary delay functionality</span></div><div class="line"><a name="l00040"></a><span class="lineno"> 40</span>&#160;</div><div class="line"><a name="l00041"></a><span class="lineno"> 41</span>&#160; <span class="keyword">public</span>:</div><div class="line"><a name="l00042"></a><span class="lineno"><a class="line" href="classtest__spi_1_1_s_p_i.html#a588741b66c9890b0d47d84a09f8a19ce"> 42</a></span>&#160; <a class="code" href="classtest__spi_1_1_s_p_i.html#a588741b66c9890b0d47d84a09f8a19ce">SPI</a> (uint32_t clk =100000) noexcept : <span class="comment">// expect 100000 default constructed clock</span></div><div class="line"><a name="l00043"></a><span class="lineno"> 43</span>&#160; <a class="code" href="classutl_1_1spi__bb__i.html">spi_bb_i</a>&lt;<a class="code" href="classtest__spi_1_1_s_p_i.html">SPI</a>, spi::<a class="code" href="namespaceutl_1_1spi.html#a89e3e1af5df0b6c37239f7e336969f8a">cpol</a>::LOW, spi::<a class="code" href="namespaceutl_1_1spi.html#aa49fe33d495226891cef0a870cba59df">cpha</a>::LOW&gt;(clk) {</div><div class="line"><a name="l00044"></a><span class="lineno"> 44</span>&#160; }</div><div class="line"><a name="l00045"></a><span class="lineno"> 45</span>&#160; };</div><div class="line"><a name="l00046"></a><span class="lineno"> 46</span>&#160;</div><div class="line"><a name="l00047"></a><span class="lineno"> 47</span>&#160; <span class="comment">// fixture</span></div><div class="line"><a name="l00048"></a><span class="lineno"><a class="line" href="classtest__spi_1_1_test__spi__impl.html"> 48</a></span>&#160; <span class="keyword">class </span><a class="code" href="classtest__spi_1_1_test__spi__impl.html">Test_spi_impl</a> : <span class="keyword">public</span> <a class="code" href="classtesting_1_1_test.html">::testing::Test</a> {</div><div class="line"><a name="l00049"></a><span class="lineno"> 49</span>&#160; <span class="keyword">protected</span>:</div><div class="line"><a name="l00050"></a><span class="lineno"> 50</span>&#160; <span class="comment">//void SetUp() override { }</span></div><div class="line"><a name="l00051"></a><span class="lineno"> 51</span>&#160; <span class="comment">//void TearDown() override { }</span></div><div class="line"><a name="l00052"></a><span class="lineno"><a class="line" href="classtest__spi_1_1_test__spi__impl.html#aba59883c01ad683d209dcf422991d131"> 52</a></span>&#160; <a class="code" href="classtest__spi_1_1_s_p_i.html">SPI</a> spi {};</div><div class="line"><a name="l00053"></a><span class="lineno"> 53</span>&#160; };</div><div class="line"><a name="l00054"></a><span class="lineno"> 54</span>&#160;</div><div class="line"><a name="l00055"></a><span class="lineno"><a class="line" href="namespacetest__spi.html#a08b6fb6773314f5914664f2089ea4eac"> 55</a></span>&#160; <a class="code" href="namespacetest__spi.html#a08b6fb6773314f5914664f2089ea4eac">TEST_F</a>(<a class="code" href="classtest__spi_1_1_test__spi__impl.html">Test_spi_impl</a>, TestConcept) {</div><div class="line"><a name="l00056"></a><span class="lineno"> 56</span>&#160;<span class="comment">// EXPECT_EQ(Spi_i&lt;SPI&gt;, true);</span></div><div class="line"><a name="l00057"></a><span class="lineno"> 57</span>&#160; }</div><div class="line"><a name="l00058"></a><span class="lineno"> 58</span>&#160;</div><div class="line"><a name="l00059"></a><span class="lineno"><a class="line" href="namespacetest__spi.html#a751c0b9fe17b002b0ab620f180a46307"> 59</a></span>&#160; <a class="code" href="namespacetest__spi.html#a08b6fb6773314f5914664f2089ea4eac">TEST_F</a>(<a class="code" href="classtest__spi_1_1_test__spi__impl.html">Test_spi_impl</a>, TestConstruction) {</div><div class="line"><a name="l00060"></a><span class="lineno"> 60</span>&#160; <a class="code" href="gtest_8h.html#a4159019abda84f5366acdb7604ff220a">EXPECT_EQ</a>(spi.clock(), 100000UL);</div><div class="line"><a name="l00061"></a><span class="lineno"> 61</span>&#160; }</div><div class="line"><a name="l00062"></a><span class="lineno"> 62</span>&#160;</div><div class="line"><a name="l00063"></a><span class="lineno"><a class="line" href="namespacetest__spi.html#aa98da2aecf8b42f492ec1c206e8b8aba"> 63</a></span>&#160; <a class="code" href="namespacetest__spi.html#a08b6fb6773314f5914664f2089ea4eac">TEST_F</a> (<a class="code" href="classtest__spi_1_1_test__spi__impl.html">Test_spi_impl</a>, TestFunctionality) {</div><div class="line"><a name="l00064"></a><span class="lineno"> 64</span>&#160; uint8_t b = 42;</div><div class="line"><a name="l00065"></a><span class="lineno"> 65</span>&#160; uint8_t bb[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};</div><div class="line"><a name="l00066"></a><span class="lineno"> 66</span>&#160; uint8_t bbb[<span class="keyword">sizeof</span> bb];</div><div class="line"><a name="l00067"></a><span class="lineno"> 67</span>&#160;</div><div class="line"><a name="l00068"></a><span class="lineno"> 68</span>&#160; spi.clock(500000UL);</div><div class="line"><a name="l00069"></a><span class="lineno"> 69</span>&#160; <a class="code" href="gtest_8h.html#a4159019abda84f5366acdb7604ff220a">EXPECT_EQ</a>(spi.clock(), 500000UL);</div><div class="line"><a name="l00070"></a><span class="lineno"> 70</span>&#160;</div><div class="line"><a name="l00071"></a><span class="lineno"> 71</span>&#160; <a class="code" href="gtest_8h.html#a4159019abda84f5366acdb7604ff220a">EXPECT_EQ</a>(spi.tx_data(b), 0xFF);</div><div class="line"><a name="l00072"></a><span class="lineno"> 72</span>&#160; <a class="code" href="gtest_8h.html#a4159019abda84f5366acdb7604ff220a">EXPECT_EQ</a>(spi.tx_data(bb, bbb, <span class="keyword">sizeof</span>(bb)), <span class="keyword">sizeof</span> (bb));</div><div class="line"><a name="l00073"></a><span class="lineno"> 73</span>&#160; <a class="code" href="gtest_8h.html#a4159019abda84f5366acdb7604ff220a">EXPECT_EQ</a>(spi.rx_data(), 0xFF);</div><div class="line"><a name="l00074"></a><span class="lineno"> 74</span>&#160;</div><div class="line"><a name="l00075"></a><span class="lineno"> 75</span>&#160; spi.rx_data(bbb, <span class="keyword">sizeof</span> bb);</div><div class="line"><a name="l00076"></a><span class="lineno"> 76</span>&#160; <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=0 ; i&lt;<span class="keyword">sizeof</span> bb ; ++i) {</div><div class="line"><a name="l00077"></a><span class="lineno"> 77</span>&#160; <a class="code" href="gtest_8h.html#a4159019abda84f5366acdb7604ff220a">EXPECT_EQ</a> (bbb[i], 0xFF);</div><div class="line"><a name="l00078"></a><span class="lineno"> 78</span>&#160; }</div><div class="line"><a name="l00079"></a><span class="lineno"> 79</span>&#160; }</div><div class="line"><a name="l00080"></a><span class="lineno"> 80</span>&#160;}</div><div class="ttc" id="namespaceutl_1_1spi_html_a89e3e1af5df0b6c37239f7e336969f8a"><div class="ttname"><a href="namespaceutl_1_1spi.html#a89e3e1af5df0b6c37239f7e336969f8a">utl::spi::cpol</a></div><div class="ttdeci">cpol</div><div class="ttdef"><b>Definition:</b> <a href="spi_8h_source.html#l00047">spi.h:47</a></div></div>
  92. <div class="ttc" id="classtest__spi_1_1_test__spi__impl_html"><div class="ttname"><a href="classtest__spi_1_1_test__spi__impl.html">test_spi::Test_spi_impl</a></div><div class="ttdef"><b>Definition:</b> <a href="test__spi__impl_8cpp_source.html#l00048">test_spi_impl.cpp:48</a></div></div>
  93. <div class="ttc" id="classtest__spi_1_1_s_p_i_html"><div class="ttname"><a href="classtest__spi_1_1_s_p_i.html">test_spi::SPI</a></div><div class="ttdef"><b>Definition:</b> <a href="test__spi__impl_8cpp_source.html#l00034">test_spi_impl.cpp:34</a></div></div>
  94. <div class="ttc" id="namespacetest__spi_html"><div class="ttname"><a href="namespacetest__spi.html">test_spi</a></div><div class="ttdef"><b>Definition:</b> <a href="test__spi__impl_8cpp_source.html#l00030">test_spi_impl.cpp:30</a></div></div>
  95. <div class="ttc" id="namespacetest__spi_html_a08b6fb6773314f5914664f2089ea4eac"><div class="ttname"><a href="namespacetest__spi.html#a08b6fb6773314f5914664f2089ea4eac">test_spi::TEST_F</a></div><div class="ttdeci">TEST_F(Test_spi_impl, TestConcept)</div><div class="ttdef"><b>Definition:</b> <a href="test__spi__impl_8cpp_source.html#l00055">test_spi_impl.cpp:55</a></div></div>
  96. <div class="ttc" id="gtest_8h_html"><div class="ttname"><a href="gtest_8h.html">gtest.h</a></div></div>
  97. <div class="ttc" id="namespaceutl_1_1spi_html_aa49fe33d495226891cef0a870cba59df"><div class="ttname"><a href="namespaceutl_1_1spi.html#aa49fe33d495226891cef0a870cba59df">utl::spi::cpha</a></div><div class="ttdeci">cpha</div><div class="ttdef"><b>Definition:</b> <a href="spi_8h_source.html#l00054">spi.h:54</a></div></div>
  98. <div class="ttc" id="namespaceutl_html"><div class="ttname"><a href="namespaceutl.html">utl</a></div><div class="ttdoc">STL&amp;#39;s core language concepts. </div><div class="ttdef"><b>Definition:</b> <a href="__1wire_8h_source.html#l00030">_1wire.h:30</a></div></div>
  99. <div class="ttc" id="classutl_1_1spi__bb__i_html"><div class="ttname"><a href="classutl_1_1spi__bb__i.html">utl::spi_bb_i</a></div><div class="ttdoc">A bit banking implementation of spi bus inherited from spi_i base class. </div><div class="ttdef"><b>Definition:</b> <a href="spi__bb_8h_source.html#l00056">spi_bb.h:56</a></div></div>
  100. <div class="ttc" id="classtesting_1_1_test_html"><div class="ttname"><a href="classtesting_1_1_test.html">testing::Test</a></div><div class="ttdef"><b>Definition:</b> <a href="gtest_8h_source.html#l15014">gtest.h:15014</a></div></div>
  101. <div class="ttc" id="spi__bb_8h_html"><div class="ttname"><a href="spi__bb_8h.html">spi_bb.h</a></div><div class="ttdoc">A bit banking implementation of spi bus inherited from spi_i base class. </div></div>
  102. <div class="ttc" id="gtest_8h_html_a4159019abda84f5366acdb7604ff220a"><div class="ttname"><a href="gtest_8h.html#a4159019abda84f5366acdb7604ff220a">EXPECT_EQ</a></div><div class="ttdeci">#define EXPECT_EQ(val1, val2)</div><div class="ttdef"><b>Definition:</b> <a href="gtest_8h_source.html#l16643">gtest.h:16643</a></div></div>
  103. <div class="ttc" id="classtest__spi_1_1_s_p_i_html_a588741b66c9890b0d47d84a09f8a19ce"><div class="ttname"><a href="classtest__spi_1_1_s_p_i.html#a588741b66c9890b0d47d84a09f8a19ce">test_spi::SPI::SPI</a></div><div class="ttdeci">SPI(uint32_t clk=100000) noexcept</div><div class="ttdef"><b>Definition:</b> <a href="test__spi__impl_8cpp_source.html#l00042">test_spi_impl.cpp:42</a></div></div>
  104. </div><!-- fragment --></div><!-- contents -->
  105. </div><!-- doc-content -->
  106. <!-- start footer part -->
  107. <div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  108. <ul>
  109. <li class="navelem"><a class="el" href="dir_13e138d54eb8818da29c3992edef070a.html">test</a></li><li class="navelem"><a class="el" href="dir_d84abbe486a7f5f39e3c9088ffc1760a.html">tests</a></li><li class="navelem"><a class="el" href="test__spi__impl_8cpp.html">test_spi_impl.cpp</a></li>
  110. <li class="footer">Generated by
  111. <a href="http://www.doxygen.org/index.html">
  112. <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.14 </li>
  113. </ul>
  114. </div>
  115. </body>
  116. </html>