    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>ACCU  :: Raspberry Pi Linux User Mode GPIO in C++ â€“ Part 1</title>
        <link>https://members.accu.org/index.php/journals/2099</link>
        <description>Professionalism in Programming</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Administrator</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.xaraya.org" /> 
        <admin:errorReportsTo rdf:resource="mailto:webeditor@accu.org" />
       <sy:updatePeriod>hourly</sy:updatePeriod>
       <sy:updateFrequency>1</sy:updateFrequency>
       <docs>http://backend.userland.com/rss</docs>


        <h2>Journal Articles</h2>


<div class="xar-mod-head"><span class="xar-mod-title">CVu Journal Vol 27, #2 - May 2015 + Programming Topics</span></div>

<table border="0" cellpadding="1" cellspacing="0">
    <tbody>
    <tr>
        <td valign="top">
            Browse in :
       </td>
       <td valign="top">

                                            <a href="https://members.accu.org/index.php/journals/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c76/">Journals</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c77/">CVu</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c349/">272</a>
                    (9)
<br />

                                            <a href="https://members.accu.org/index.php/journals/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c13/">Topics</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c65/">Programming</a>
                    (877)
<br />

                                            <a href="https://members.accu.org/index.php/journals/c349-65/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/journals/c349+65/">All of these categories</a>
<br />
</td>
   </tr>
   </tbody>
</table>




<div class="xar-error">
   <p>
 <strong>Note:</strong> when you create a new publication type,
the articles module will automatically use the templates
<em>user-display-[publicationtype].xt</em>
and <em>user-summary-[publicationtype].xt</em>.
If those templates do not exist when you try to preview or display a new article,
you'll get this warning :-)  Please place your own templates in themes/<em>yourtheme</em>/modules/articles . The templates will get the extension .xt there. </p>
</div>
<div class="xar-norm xar-standard-box-padding">
   <h1><strong>Title:</strong>&nbsp;Raspberry Pi Linux User Mode GPIO in C++ â€“ Part 1</h1>
<p><strong>Author:</strong>&nbsp;Martin Moene</p>
<p>
<strong>Date:</strong> 03 May 2015 17:15:48 +01:00 or Sun, 03 May 2015 17:15:48 +01:00</p>
<p><strong>Summary:</strong>&nbsp;Ralph McArdell expands the Raspberry Pi with a C++ library.</p>
<p><strong>Body:</strong>&nbsp;<p>I started experimenting with general purpose input/output (GPIO) with a Raspberry Pi using PythonÂ <a href="#[1]">[1</a>, <a href="#[2]">2]</a> which enabled the reading and writing of Boolean values representing on/off states (in fact high/low voltage states) â€“ reading switch states, turning lights on and off and the like. Shortly after I had the Python Raspberry Pi GPIO library up and running the original Gertboard <a href="#[3]">[3]</a> kit was released. The Gertboard interfaces to the Raspberry Pi via its P1 IO expansion header connector (J8 on later B+/A+/2.0 models) and provides a smorgasbord of hardware devices that use a variety of peripheral interfaces. So I ordered and built one enabling me to play with peripheral IO beyond basic GPIO. At the time the Gertboard had test and example C code available for Linux <a href="#[4]">[4]</a>, particularly Raspbian the Raspberry Pi specific Linux distribution. Similar to the Python case I felt the provided C code could be expressed more cleanly. I thought it would be interesting to see what advantages C++, hopefully C++11, features and idioms might provide.</p>

<h2>A thought: germ of a library</h2>


<p>The originally provided Gertboard test and example C code, in a fashion similar to the Wiring Pi libraryÂ <a href="#[5]">[5]</a>, manages the Raspberry Piâ€™s BCM2835 processorâ€™s peripherals by directly accessing peripheralsâ€™ memory mapped control registers from user mode by using <code>mmap</code> to map sections of the <code>/dev/mem</code> physical memory device. A single function sets up <code>mmap</code>-ed regions in a rather long winded and repetitive way for all supported peripherals â€“ even if only one or two peripheral regions are required. Oddly, for each mapped register-block a block of free-store is first allocated which is larger than required to ensure a correctly aligned block can be passed to <code>mmap</code>. When done of course all these resources have to be explicitly released.</p>

<p>It occurred to me that in C++ I would wrap mapped of parts of <code>/dev/mem</code> in a resource managing type that used the RAII (Resource Acquisition Is Initialisation) <a href="#[6]">[6]</a> idiom. It was this thought that was to lead to a Raspberry Pi user mode C++ library. So putting some code where my brain was, so to speak, I went ahead and implemented such a beast. The result was a class template called <code>phymem_ptr</code>, with most of the implementation being taken care of by the non-template base class <code>raw_phymem_ptr</code> which works with un-typed pointers (<code>void*</code>) .</p>

<p>Having implemented, and tested, <code>phymem_ptr</code> using Phil Nashâ€™s Catch library <a href="#[7]">[7]</a>, I re-implemented one of the simpler Gertboard example programs â€“ <span class="filename">ocol.c</span> â€“ in C++ using <code>phymem_ptr</code>. I felt the result was a definite improvement but more could be done and the obvious next step seemed to be to start with basic GPIO and, following my thinking with the Raspberry Pi GPIO Python library, model the abstractions after C++ library IO. Of course as this would be solving essentially the same problem as the Python GPIO library there were bound to be other concepts that would transfer to the C++ implementation â€“ a notion of GPIO pin number as represented in the Python library as the <code>PinId</code> type for example.</p>

<h2>In the beginningâ€¦</h2>

<p>Having decided to write more than <code>phymem_ptr</code>, its tests and the <code>ocol</code>-in-C++ example it was time to bootstrap a project. Things such as project name, licensing terms, directory structure and what development process to utilise had to be decided.</p>

<p>The name <code>rpi-peripherals</code> was chosen for the library (though embarrassingly due to a typo it was <code>rpi-periphals</code> for quite a while â€“ doh!). The longer term â€˜peripheralsâ€™ was chosen rather than â€˜gpioâ€™ as the intention was for the library to provide support for more than just basic GPIO. As there was no reason to do otherwise the same dual BSD/GPL licensing used for the Python Raspberry Pi GPIO library was selected.</p>

<p>A fairly standard project directory structure was devised having few files in the project root and source, build and outputs etc. in various subdirectories such as <span class="filename">src</span>, <span class="filename">bin</span>, <span class="filename">lib</span>. At the time of writing all the source with the exception of header files required for the public interface of the library is in the <span class="filename">src</span> subdirectory with no further division. On the other hand all test and example source are in subdirectories <span class="filename">tests</span> and <span class="filename">examples</span> of <span class="filename">src</span> respectfully.</p>

<p>I did not want the library to require any development tools other than what could be expected to be installed on a typical Raspberry Pi Raspbian installation (plus git â€“ keep readingâ€¦). That meant using the Raspbian distributionâ€™s default version of g++ (4.6.3) and I fell back to using <code>make</code> â€“ well GNU <code>make</code> â€“ and wrote a <span class="filename">Makefile</span> for (and placed in) each directory in which code was to be compiled, as well as a top level <span class="filename">Makefile</span> as a driver and a common file, <span class="filename">makeinclude.mak</span>, that defined common values such as directory and file names and tool names and flags. Code was developed on a Raspberry Pi running Raspbian, edited from a Windows session in Notepad++ with builds, tests etc. run via <code>ssh</code> accessed from a Ubuntu Desktop Linux virtual machine. The project was placed under git source control on GitHub as dibase-rpi-peripherals <a href="#[8]">[8]</a>. As previously mentioned Phil Nashâ€™s Catch library was used for tests, which was added to the repository as a git sub-module.</p>

<p>Rather than use GitHubâ€™s repository wiki for documentation, as was done for the Python Raspberry Pi GPIO library, this time Doxygen commenting was used in header files, and a Doxygen project configuration <span class="filename">Doxyfile</span> was added to the project.</p>

<h2>What did you want for starters?</h2>

<p>The scope for the initial functionality was mostly a subset of that of the Python Raspberry Pi GPIO library:</p>

<ul>
	<li>Targeting only Raspberry Pi Linux distributions, especially Raspbian</li>
	<li>Single GPIO pin input and output, with no edge event support</li>
	<li>A pin id abstraction</li>
	<li>Internal pin in use / pin free resource management</li>
	<li>Library specific exception types</li>
</ul>

<p>Since the development of the Python Raspberry Pi GPIO library a major Raspberry Pi board revision had taken place that changed some of the pin assignments on the Raspberry Pi P1 connector and added a new P5 connector with additional GPIO pins. This meant that converting a P1 connector pin number to a BCM2835 GPIO pin number was no longer a simple fixed mapping. It was now dynamically dependent on which board revision the code was running on. Additionally, of course, the newer boards had a P5 to BCM2835 pin mapping. Hence additional support for determining a board revision was needed. </p>

<p>Following the initial development of the library there have been further additions to the Raspberry Pi family in the form of the A+, B+, compute module models and now the Raspberry Pi 2.0 B model. I am yet to find the time to completely update the library to support all these board versionsâ€™ GPIO specifics.</p>

<h2>First cut</h2>

<p>The library usage would be broadly similar to the Python Raspberry Pi GPIO library: an object representing an input or output pin would be associated with a GPIO pin by opening the required pin which would be specified as a pin id type instance. If valid and the pin is not in use the open request would be successful and the GPIO pin object could be used to either read or write Boolean values from/to the associated GPIO pin. On GPIO pin object destruction the pin would be marked as free for further use.</p>

<p>Here we have several types of object: input and output pin objects, pin id objects, some form of GPIO pin allocation management object and of course direct access via a <code>phymem_ptr</code> to the GPIO peripheralâ€™s registers.</p>

<p>Rather than mapping the BCM2835 GPIO peripheralâ€™s registers as an array of structure-less 32-bit words (i.e. unsigned integers), as had been done for the original <code>ocol</code>-in-C++ example, it seemed more reasonable to provide a type reflecting the BCM2835 GPIO peripheralâ€™s register layout that could be used to specialise <code>phymem_ptr</code>.</p>

<p>This rough structure outline is shown in Figure 1.</p>

<table class="sidebartable">
	<tr>
		<td><img src="http://accu.org/content/images/journals/cvu27-2/McArdell/McArdell-01.png" /></td>
	</tr>
	<tr>
		<td class="title">Figure 1</td>
	</tr>
</table>

<p>The <code>ipin</code>, <code>opin</code> and <code>pin_id</code> types are intended as the public interface to the library while the rest would be internal to the library â€“ in fact during refactoring after the initial development phase such code was placed into a separate inner namespace called <code>internal</code> and the header files for the public entities were moved from the project <span class="filename">src</span> to the <span class="filename">include</span> directory. The â€˜oâ€™ and â€˜iâ€™ prefixes to <code>ipin</code> and <code>opin</code> were taken from C++ IOStream library <code>std::istream</code> and <code>std::ostream</code> naming.</p>

<h2>So how do I register?</h2>

<p>In order to create a structure representing the GPIO peripheralâ€™s register-block detailed knowledge of register layout, usage and location are obvious requirements. Such detailed technical information is to be found in the Broadcom BCM2835 ARM Peripherals document <a href="#[9]">[9]</a>, although as it contains errors and omissions the errata page at eLinux <a href="#[10]">[10]</a> is also useful. </p>

<p>As an aside: when perusing the Raspberry Piâ€™s Linux kernel source code <a href="#[11]">[11]</a> you will find very little specific BCM2835 support <a href="#[12]">[12]</a>; most chip-specific support appears to be provided by the BCM2708 specific code <a href="#[13]">[13]</a>. It is to be assumed that this chip is very similar in its peripheral support to the Raspberry Piâ€™s BCM2835, so detailed BCM2835 specifics may well apply to the BCM2708 as well.</p>

<p>Separating the mapping of peripheral register block addresses with <code>phymem_ptr</code> and the register block layout representation as manifested by the <code>gpio_registers</code> class type for the GPIO peripheral allows instances of register layout representation types to be arbitrarily created in memory â€“ as function-scope automatic objects for example. This allows easy unit testing of the representation type to ensure it is sane before having to rely on it when mapped over a peripheralâ€™s register block and fiddling with real peripheral registers.</p>

<p>It seemed that adding operations (member functions) for manipulating the fields of the GPIO peripheralâ€™s registers would be convenient for users of the <code>gpio_registers</code> type and would allow such operations to be fully unit tested. However, a balance had to be struck between spending time developing an all-singing all-dancing set of operations and just getting things done. The balance point I chose was to implement operations to access single fields. Many peripheral fields are bit fields and so in certain scenarios reading or writing to multiple bits fields in one go could be more efficient. I left this as optimisation territory, facilitated only by having all register data members be public. In fact the <code>gpio_registers</code> class type was implemented as a <code>struct</code>. I felt this was justified as it was intended to be a low-level type internal to the library.</p>

<p>I decided against using C/C++ bit fields â€“ instead using 32-bit unsigned integer types as register data members with access via individual member functions. I suppose I could have looked up the specifics of the GCC bit field implementation, checked whether they were compatible (e.g. guaranteed 32-bit reads and writes for underlying 32-bit integer field types) and if they were then utilised unions to allow accessing whole registers or bit field parts thereof. Such a scheme would probably cover many, maybe even most, cases.</p>

<p>As the <code>gpio_registers struct</code> was a direct reflection of the GPIO peripheralâ€™s registers and fields I decided that all registers would be represented by data members and operation member functions would be provided to access all fields even if they were not known to be needed. One quite major upside of this decision is that it made me really read and understand the associated documentation â€“ making me more able to later decide on what would be needed!</p>

<h2>What pin was that?</h2>

<p>The need to identify and validate GPIO pin numbers and their encapsulation in the <code>pin_id</code> type has been mentioned in connection with the public <code>ipin</code> and <code>opin</code> types. However, it turns out, unsurprisingly when you think about it, that the GPIO peripheral has many register-sets containing fields for each of the BCM2835â€™s 54 GPIO pins. Thus operations often need to specify which GPIO pin they were to be applied to. As the <code>pin_id</code> type would obviously be useful as a GPIO pin id parameter type in these cases its implementation occurred earlier than I originally anticipated.</p>

<p>The basic idea behind the <code>pin_id</code> type is that instances may be explicitly constructed from a suitable integer type, and may be converted back to an integer type. However during construction the range of the integer passed is validated to ensure it is in the required range. If it is not a <code>std::invalid_argument</code> exception is thrown. Hence, barring deliberate malice, if you have a <code>pin_id</code> object you know it represents a valid GPIO pin number. Only allowing explicit construction makes clear what the number represents.</p>

<p>To support using Raspberry Pi P1 or P5 connector pin values the base <code>pin_id</code> type is sub-classed to provide the logic for mapping from one value to another by the rather clumsily named <code>rpi_version_mapped_pin_id</code> which provides a single, rather cumbersome, constructor. This class is not meant to be used directly, rather its two sub-classes <code>p1_pin</code> and <code>p5_pin</code> are designed to be used directly and provide constructors that require only a connector pin number as parameter, which is passed along with a bunch of fixed values relevant for each connector to their base <code>rpi_version_mapped_pin_id</code> constructor. Note that this is a case where a base class destructor does <em>not</em> need to be virtual as by design all <code>pin_id</code> sub-types add no extra state that might require cleaning up. Once successfully constructed a <code>pin_id</code> or sub-type instance always represents a valid BCM2835 GPIO pin number value.</p>

<p>The <code>rpi_version_mapped_pin_id</code> typeâ€™s constructor takes a 2-dimensional array mapping connector pin numbers to BCM2835 GPIO pin numbers for each supported major Raspberry Pi board revision â€“ termed versions, along with dimension size values: the number of pins and number of versions supported by the mapping array. A major revision here is one that changes available connectors and/or GPIO pin associations with connector pins.</p>

<p>The implementation logic makes use of the <code>rpi_info</code> type that lives in the outer <code>rpi</code> namespace and provides an interface to obtain information on the Raspberry Pi system the code is running on. It currently only provides Raspberry Pi raw revision and version information, derived from the <code>Revision</code> entry in the Raspbian <span class="filename">/proc/cpuinfo</span> pseudo file. There is no formula to map revisions to versions and relies on published information <a href="#[14]">[14]</a>. Of course this means <code>rpi_info</code> code will require updating to take advantage of future major board revisions. However the mapping arrays used by <code>p1_pin</code> and <code>p5_pin</code> would also require updating, and of course support for any new connectors would need to be added. This is an area of the code base that is likely to change while adding support for all the various Raspberry Pi models now available.</p>

<p>To support referring to Raspberry Pi P1 and P5 connector pins by name I created a set of static global constant <code>pin_id</code> objects. These are created by specialisations of special static pin id type templates <code>static_pin_id</code>, <code>static_p1_pin</code> and <code>static_p5_pin</code> that contain no data providing just a single conversion operator member function that converts to a <code>pin_id</code>. Each template takes a single integer template parameter representing a connector pin or BCM2835 GPIO pin number. Each conversion function defines a static object of <code>pin_id</code> type or associated sub-type. For the P1 pins that changed between board versions and the P5 pins, if none are used then the <code>rpi_info</code> machinery should not be required. Those P1 pins that did not change between board versions are defined directly as their associated BCM2835 GPIO pin value by <code>static_pin_id</code> objects. The case for using <code>static_pin_id</code> objects over just defining global constant <code>pin_id</code> objects is not as great as for the use of <code>static_p1_pin</code> and <code>static_p5_pin</code> objects. The main benefit would be ensuring initialisation before use of the function-scope static <code>pin_id</code> object.</p>

<p>A future direction for <code>pin_id</code> <em>et al.</em> would be to investigate whether use could be made of constant expressions (<code>constexpr</code>).</p>

<h2>Excuse me, is that pin free?</h2>

<p>GPIO pins are a resource and as such I had to decide on an allocation policy. The easy part was deciding that a pin should not be permitted to be used by more than one object at a time within the same process. However the inter-process policy is not so easy. For a start there is no magic system wide registry of in use GPIO pins, so any policy implemented would have to rely on other processes doing likewise. There are various possible policies, including:</p>

<ul>
	<li>Ignoring the issue and only track pin usage within a process</li>
	<li>Require pins to be marked as allocated beforehand by some other agent, and presumably marked as free after executing by a similar external agent</li>
	<li>Require that pins are marked as free for use before allocation and mark them as allocated/free as required.</li>
</ul>

<p>How to determine whether a pin was in use or free was another choice. This boiled down to either devising some sort of custom registry which would not be too useful if only my library used it or use some pre-existing indicator that might also allow such in use/is free information to work between libraries. </p>

<p>The most obvious policy, and the one I decided on, was to follow that which I had used for the Python Raspberry Pi GPIO library: check to see if a pin was in use by checking to see if it was exported from the <span class="filename">/sys/class/gpio/</span> driver. If not then export it to acquire the pin and un-export the pin to release it. This scheme is in no way water tight. For a start any process with sufficient access rights can un-export an â€˜allocatedâ€™ pin at any moment. Then there is the matter of un-clean exit from a process leaving pins marked as unavailable because the un-exporting de-allocations failed to run â€“ the main problem here is with signals, especially <code>SIGKILL</code>, that cannot be caught and handled to force de-allocation before unceremonious exit.</p>

<p>This is all taken care of by the <code>pin_allocator</code> type. Or to be precise the <code>pin_allocator</code> type alias as it is a <code>typedef</code> for a specialisation of the <code>pin_cache_allocator</code> class template that provides the intra-process allocator logic by deferring decisions initially to an alternate allocator whose type is provided by the single template type parameter and caches the results. The <code>pin_allocator</code> type alias specialises <code>pin_cache_allocator</code> with the <code>pin_export_allocator</code> that provides support, with the help of a <span class="filename">sys</span> file system module, for allocating by exporting from <span class="filename">/sys/class/gpio/</span> and de-allocating by un-exporting. </p>

<h2>Itâ€™s a wrap!</h2>

<p>The services of <code>gpio_registers</code> and <code>pin_allocator</code> types are wrapped up behind the public interface types <code>ipin</code> and <code>opin</code>. As mentioned previously the <code>ipin</code> and <code>opin</code> types provide an abstraction modelled after the C++ IOStream library. In particular those of the <code>std::ifstream</code> and <code>std::ofstream</code> types (or any other specialisation from the underlying basic-templates). Operations on single bits are quite limited compared to those on streams of characters so other than providing open and close semantics the only other operations from the IOStreams types that really applied were <code>get</code> for <code>ipin</code> to read the Boolean value of a GPIO pin and <code>put</code> for <code>opin</code> to write, or set, the Boolean value of a GPIO pin.</p>

<p>There is quite a lot of common functionality around the implementation of the open and close operations of <code>ipin</code> and <code>opin</code>. This was pulled out into a common base type <code>pin_base</code> having a totally protected interface. Following the <code>std::ifstream</code> and <code>std::ofstream</code> examples I originally provided explicit <code>open</code> and <code>close</code> operations which were called as appropriate by <code>ipin</code> and <code>opin</code> constructors and destructors. Later, having observed that a purer form of RAII that only allowed resources to be acquired through construction was proving to be a Good Thingâ„¢, I refactored <code>ipin</code>, <code>opin</code> and <code>pin_base</code> to remove the default constructors and the <code>open</code> and <code>close</code> member functions which considerably simplified the implementation.</p>

<p>Each <code>ipin</code> and <code>opin</code> instance needs to acquire a GPIO pin for use if available, access the GPIO register block and, of course, to release the pin when done. Unsurprisingly <code>pin_id</code> objects are used to pass around GPIO pin values. As they appear in the public interface of the public library types <code>ipin</code> and <code>opin</code>, <code>pin_id</code> and related types are also part of the libraryâ€™s public API. </p>

<p>Each BCM2835 has only one set of GPIO pins so there need only be one instance of the <code>pin_allocator</code> type. Likewise, they only have one GPIO peripheral register block hence there only needs to be a single instance of <code>gpio_registers</code> mapped to the relevant physical memory address as a <code>phymem_ptr&lt;volatile gpio_registers&gt;</code> (the type pointed to by the <code>phymem_ptr</code> specialisation is qualified <code>volatile</code> because the hardware at the mapped locations are <em>not</em> memory but device registers that have to be accessed in the prescribed way and so the compiler is not free to assume it knows what is going on). </p>

<p>So without getting overly sophisticated the obvious pattern to use here was <span class="pattern">Singleton</span> (Iâ€™ll wait until some of you have recovered your composureâ€¦). </p>

<p>For those wondering about systems using multiple BCM2835 chips that as they have their peripheral registersâ€™ memory locations hard-baked into the silicon such systems would not be feasible, GPIO and peripherals wise, without doing something exotic.</p>

<p>So what was needed was a singleton class containing a <code>pin_allocator</code> and a <code>phymem_ptr&lt;volatile gpio_registers&gt;</code> with the single instance being accessed via an <code>instance</code> member function that returned a reference to the function local static instance. Singletons of this form are sometimes known as Meyers Singletons <a href="#[15]">[15]</a> after advice given in Scott Meyerâ€™s book <em>Effective C++</em> <a href="#[16]">[16]</a>. In fact this type was implemented as a <code>struct</code> called <code>gpio_ctrl</code> that allows direct access to the singletonâ€™s allocator and GPIO registers members. The implementation was initially placed within, and local to, the implementation file for the <code>ipin</code>, <code>opin</code> and <code>pin_base</code> classes as there was at the time no need for anything else to access it. This changed later on and at that time <code>gpio_ctrl</code> was moved out into its own library-internal header and implementation file.</p>

<h2>Testing, testing</h2>

<p>Unit testing has already been mentioned in relation to the <code>gpio_registers </code>type. However, after a while the project settled into three classes of tests:</p>

<ul>
	<li>Unit tests that relied on nothing else and could in theory be built and executed on another platform.</li>
	<li>Platform tests, a form of integration tests that required a Raspberry Pi and/or Linux/Raspbian operating system services such as <span class="filename">/dev/mem</span> or <span class="filename">/sys/class/gpio/</span>.</li>
	<li>Interactive tests, a form of platform integration tests that additionally require some user action. Usually this meant ensuring the hardware was suitably connected for the tests and often that the tester perform a requested action with the test hardware such as closing or opening a switch or confirming that the expected result such as a lamp lighting or turning off occurred.</li>
</ul>

<p>Each class of test has its own executable. Unit tests do not require any special access to execute but the two integration test varieties generally require root access via <code>sudo</code> or similar â€“ as do applications â€“ including examples â€“ built with the library. </p>

<p>Unit and platform tests can be run quickly as regression tests and could be run automatically. Interactive tests take a bit more time and care and obviously need to be run manually. The Catch test runner feature allowing the use of wildcards in the specification of which tests to execute is especially useful for only running the group of interactive tests that are currently of interest, especially as the hardware to support other interactive tests may not be wired up at the time.</p>

<p>It has occurred to me that it would be possible to create a specialist piece of hardware â€“ a custom circuit board or similar â€“ designed specifically to support the sort of testing performed by the interactive tests. It might even be possible to arrange for many tests to be performed and verified automatically. Such a device combined with the test software would I suppose be similar to ATE â€“ Automated Test Equipment. It would however be quite involved and would almost certainly be overkill.</p>

<h2>References</h2>

<p class="bibliomixed"><a id="[1]"></a>[1]	Raspberry Pi Linux User Mode GPIO in Python, <em>CVu</em>, Volume 27 Issue 1, March 2015</p>

<p class="bibliomixed"><a id="[2]"></a>[2]	Github repository for the Python Raspberry Pi GPIO library:<a href="https://github.com/ralph-mcardell/dibase-rpi-python">https://github.com/ralph-mcardell/dibase-rpi-python</a></p>

<p class="bibliomixed"><a id="[3]"></a>[3]	Gertboard Raspberry Pi IO expansion board:<a href="http://www.raspberrypi.org/archives/411">http://www.raspberrypi.org/archives/411</a></p>

<p class="bibliomixed"><a id="[4]"></a>[4]	Available for download as the ZIP file gertboard_sw_20120725.zip: <a href="http://www.element14.com/community/servlet/JiveServlet/download/38-101479">http://www.element14.com/community/servlet/JiveServlet/download/38-101479</a> </p>

<p class="bibliomixed"><a id="[5]"></a>[5]	The Wiring Pi Library:<a href="https://projects.drogon.net/raspberry-pi/wiringpi/">https://projects.drogon.net/raspberry-pi/wiringpi/</a> </p>

<p class="bibliomixed"><a id="[6]"></a>[6]	See for example:<a href="http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization ">http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization </a></p>

<p class="bibliomixed"><a id="[7]"></a>[7]	Catch: C++ Automated Test Cases in Headers<a href="https://github.com/philsquared/Catch">https://github.com/philsquared/Catch</a></p>

<p class="bibliomixed"><a id="[8]"></a>[8]	GitHub repository for the C++ rpi-peripherals library:<a href="https://github.com/ralph-mcardell/dibase-rpi-peripherals">https://github.com/ralph-mcardell/dibase-rpi-peripherals</a></p>

<p class="bibliomixed"><a id="[9]"></a>[9]	BCM2835 ARM Peripherals: <a href="http://www.raspberrypi.org/wp-content/uploads/2012/02/BCM2835-ARM-Peripherals.pdf">http://www.raspberrypi.org/wp-content/uploads/2012/02/BCM2835-ARM-Peripherals.pdf</a></p>

<p class="bibliomixed"><a id="[10]"></a>[10]	eLinux BCM2835 ARM Peripherals errata page:<a href="http://elinux.org/BCM2835_datasheet_errata">http://elinux.org/BCM2835_datasheet_errata</a></p>

<p class="bibliomixed"><a id="[11]"></a>[11]	Raspberry Pi Linux source code Github repository:<a href="https://github.com/raspberrypi/linux">https://github.com/raspberrypi/linux</a></p>

<p class="bibliomixed"><a id="[12]"></a>[12]	Raspberry Pi Linux kernel source BCM2835 specific support:<a href="https://github.com/raspberrypi/linux/tree/rpi-3.10.y/arch/arm/mach-bcm2835">https://github.com/raspberrypi/linux/tree/rpi-3.10.y/arch/arm/mach-bcm2835</a> (note: for the rpi-3.10.y branch, use branch selection dropdown to select another)</p>

<p class="bibliomixed"><a id="[13]"></a>[13]	Raspberry Pi Linux kernel source BCM2708 specific support:<a href="https://github.com/raspberrypi/linux/tree/rpi-3.10.y/arch/arm/mach-bcm2708">https://github.com/raspberrypi/linux/tree/rpi-3.10.y/arch/arm/mach-bcm2708</a> (note: for the rpi-3.10.y branch, use branch selection dropdown to select another)</p>

<p class="bibliomixed"><a id="[14]"></a>[14]	eLinux RPi HardwareHistory page:<a href="http://elinux.org/RPi_HardwareHistory">http://elinux.org/RPi_HardwareHistory</a></p>

<p class="bibliomixed"><a id="[15]"></a>[15]	See for example the second variant presented in:<a href="http://www.devartplus.com/3-simple-ways-to-create-singleton-in-c/">http://www.devartplus.com/3-simple-ways-to-create-singleton-in-c/</a> </p>

<p class="bibliomixed"><a id="[16]"></a>[16]	See Scott Meyerâ€™s site at: <a href="http://www.aristeia.com/books.html">http://www.aristeia.com/books.html</a></p>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
