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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,610e53a911ec64b3 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1995-03-27 08:00:48 PST Path: nntp.gmd.de!news.rwth-aachen.de!news.rhrz.uni-bonn.de!news.uni-stuttgart.de!rz.uni-karlsruhe.de!xlink.net!howland.reston.ans.net!cs.utexas.edu!news.sprintlink.net!uunet!portal.austin.ibm.com!bocanews.bocaraton.ibm.com!watnews.watson.ibm.com!ncohen From: ncohen@watson.ibm.com (Norman H. Cohen) Newsgroups: comp.lang.ada Subject: Re: Importing C Structures Date: 27 Mar 1995 16:00:48 GMT Organization: IBM T.J. Watson Research Center Distribution: world Message-ID: <3l6nfg$12kj@watnews1.watson.ibm.com> References: <3kr4q3$jd9@newsflash.concordia.ca> <3ksg66$h1c@newssvr.cacd.rockwell.com> Reply-To: ncohen@watson.ibm.com NNTP-Posting-Host: rios8.watson.ibm.com Date: 1995-03-27T16:00:48+00:00 List-Id: In article , vladimir@speedy.intrepid.com (Vladimir Vukicevic) writes: |> In article <3ksg66$h1c@newssvr.cacd.rockwell.com> rswhite@cacd.rockwell.com (Robert S. White) writes: |> |> > Do you have a clean way to handle hardware registers that have one |> > meaning when you read them and another when you write to them with |> > nice seperate names for each type of usage? ... |> > Recommendations? |> |> Something like this (in Ada 95): |> |> Input_Register : Integer; |> for Input_Register'Address use |> System.Storage_Elements.To_Address (16#0020); |> |> Output_Register : Integer; |> for Output_Register'Address use |> System.Storage_Elements.To_Address (16#0020); |> |> This is perfectly valid and within the spirit of the 95 LRM. Yes, it is. Personally, I think memory-mapped I/O is a pernicious abstraction. Just because the hardware lies and claims that we are reading from or writing to a storage location when we are reading from or writing to a device, I see no need to perpetuate this lie in the source program and make it appear as though we are reading from or writing to a variable. Therefore, I would prefer a procedural interface: with System; package Low_Level_IO is -- Loosely inspired by RM83 14.6 type Device_Address is new System.Address; type Word is mod 2**32; -- or whatever procedure Send_Control (Device: in Device_Address; Data: in Word); procedure Receive_Control (Device: in Device_Address; Data: out Word); end Low_Level_IO; with System.Address_To_Access_Conversions; package body Low_Level_IO is use System; package Word_Pointers is new Address_To_Access_Conversions (Word); procedure Send_Control (Device: in Device_Address; Data: in Word) is begin Word_Pointers.To_Pointer(Address(Device)).all := Data; end Send_Control; procedure Receive_Control (Device: in Device_Address; Data: out Word) is begin Data := Word_Pointers.To_Pointer(Address(Device)).all; end Receive_Control; end Low_Level_IO; Code procedures would provide even less of a suggestion that some variable is being updated or referenced. -- Norman H. Cohen ncohen@watson.ibm.com