From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00,FREEMAIL_FROM, FROM_STARTS_WITH_NUMS autolearn=no autolearn_force=no version=3.4.4 X-Received: by 2002:a37:bf82:: with SMTP id p124mr24113670qkf.337.1580237634530; Tue, 28 Jan 2020 10:53:54 -0800 (PST) X-Received: by 2002:aca:5303:: with SMTP id h3mr3650671oib.109.1580237634289; Tue, 28 Jan 2020 10:53:54 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!feeder5.feed.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr2.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!g89no8238837qtd.0!news-out.google.com!w29ni826qtc.0!nntp.google.com!g89no8238833qtd.0!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 28 Jan 2020 10:53:53 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: google-groups.googlegroups.com; posting-host=2001:8b0:ca:2:0:0:0:fd; posting-account=TiHetgoAAACluCgYkPc8-TWs6dBNgSne NNTP-Posting-Host: 2001:8b0:ca:2:0:0:0:fd References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: GNATCOLL-Mmap example From: Bob Goddard <1963bib@googlemail.com> Injection-Date: Tue, 28 Jan 2020 18:53:54 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader01.eternal-september.org comp.lang.ada:57974 Date: 2020-01-28T10:53:53-08:00 List-Id: On Tuesday, 28 January 2020 08:25:25 UTC, Dmitry A. Kazakov wrote: > On 2020-01-25 22:52, Bob Goddard wrote: > > > I need to map the RPi's GPIO memory addresses so that I can do what I need to do. > > See files under: > > /sys/class/gpio > > You can use standard Ada I/O to read and set GPIO pins. E.g. > > /sys/class/gpio/gpio/XXX/value This was the way I started, but could not get it to read anything. It just blocks trying to read a single character. My c code works fine using the wiringPi libs. Stephen Leake: Mmap is used to read more than just disk files. Opening /dev/mem, or even /dev/gpiomem, is just another file. Regardless, I got it to work. The moral of the story, is never assume example code in the library source works, or even can compile. I got it running a couple of days ago, and have since spent time banging my head against a wall. This works, both with System.Mmap & GNATCOLL.Mmap... with Ada.Unchecked_Conversion; with Ada.Text_IO; with GNATCOLL.Mmap; use GNATCOLL.Mmap; with Ada.Strings.Unbounded; with Ada.Strings.Unbounded.Text_IO; procedure Mmaptest is package Mmap renames GNATCOLL.Mmap; File : Mmap.Mapped_File; Reg : Mmap.Mapped_Region; Str : Mmap.Str_Access; Offs : Mmap.File_Size := 0; Page : constant Mmap.File_Size := Mmap.File_Size (Mmap.Get_Page_Size); begin File := Mmap.Open_Write ("/tmp/file_on_disk"); while Offs < Mmap.Length (File) loop Mmap.Read (File, Reg, Offs, Length => Page, Mutable => False); Str := Mmap.Data (Reg); Ada.Strings.Unbounded.Text_IO.Put (Ada.Strings.Unbounded.To_Unbounded_String ( Str (Integer (Offs - Mmap.Offset (Reg)) + 1 .. Mmap.Last (Reg))) ); Offs := Offs + Page; -- Mmap.File_Size (Mmap.Last (Reg)); end loop; Mmap.Free (Reg); if Reg /= Mmap.Invalid_Mapped_Region then Ada.Text_IO.Put_Line ("Mapped region still valid"); end if; Mmap.Close (File); if File /= Mmap.Invalid_Mapped_File then Ada.Text_IO.Put_Line ("Mapped file still valid"); end if; end Mmaptest;