Skip to content
Brent Seidel edited this page Feb 22, 2017 · 4 revisions

#General Purpose I/O This is a collection of one bit inputs and outputs. They can be found on both the BeagleBone Black and the Raspberry Pi and probably most other embedded computers.

The following types are defined:

   type GPIO_record is abstract tagged limited null record;
   type GPIO is access all GPIO_record'Class;
   type direction is (input, output);

The abstract base class offers the following methods:

   procedure configure(self : in out GPIO_record;
                       pin : string; port : string; dir : direction) is abstract;

Configure a new GPIO object. The pin control file and GPIO directory must correspond, otherwise things will not work correctly. Pin should be one of the pin constants and port should be one of the gpio constants from the device specific pins packages.

   procedure configure(self : in out GPIO_record;
                       port : string; dir : direction) is abstract;

Not all GPIOs have an associated pin control file. Some pins are dedicated to GPIO and have no other function. This version of configure doesn't require a pin control file.

   procedure set(self : GPIO_record; value : bit) is abstract;

Set the value of an output GPIO.

   function get(self : GPIO_record) return bit is abstract;

Read the value of an input GPIO.

The configure methods still have a Linux flavor to them. It is likely that they will eventually be moved out of the abstract base class.

Using the following code to toggle a gpio as fast as possible:

loop
   gpio.set(1);
   gpio.set(0);
end loop;

I got the following results:

System Frequency
BeagleBone Black 60 kHz
Raspberry PI 3 160 kHz

Note that the times are only approximate and can vary greatly depending on other processing on the processor.

By way of comparison, an Arduino Mega 2560 got 126.6kHz or 128.2kHz (it toggled between the two as I measured it) in a similar tight loop using digitalWrite(). If you need fairly consistent timing, it is better to use an Arduino or something similar that has no OS (or a real-time OS).

Clone this wiki locally