2009-10-01 Tobias Burnus <burnus@net-b.de>
[official-gcc/alias-decl.git] / gcc / ada / g-sercom.ads
blob8b4c55906846eaf40d14a5cb82292be0b2c34f6a
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- G N A T . S E R I A L _ C O M M U N I C A T I O N S --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2007-2008, AdaCore --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
21 -- --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
28 -- --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
31 -- --
32 ------------------------------------------------------------------------------
34 -- Serial communications package, implemented on Windows and GNU/Linux
36 with Ada.Streams;
37 with Interfaces.C;
39 package GNAT.Serial_Communications is
41 Serial_Error : exception;
42 -- Raised when a communication problem occurs
44 type Port_Name is new String;
45 -- A serial com port name
47 function Name (Number : Positive) return Port_Name;
48 -- Returns a possible port name for the given legacy PC architecture serial
49 -- port number (COM<number>: on Windows, ttyS<number-1> on Linux).
50 -- Note that this function does not support other kinds of serial ports
51 -- nor operating systems other than Windows and Linux. For all other
52 -- cases, an explicit port name can be passed directly to Open.
54 type Data_Rate is
55 (B1200, B2400, B4800, B9600, B19200, B38400, B57600, B115200);
56 -- Speed of the communication
58 type Data_Bits is (CS8, CS7);
59 -- Communication bits
61 type Stop_Bits_Number is (One, Two);
62 -- One or two stop bits
64 type Parity_Check is (None, Even, Odd);
65 -- Either no parity check or an even or odd parity
67 type Serial_Port is new Ada.Streams.Root_Stream_Type with private;
69 procedure Open
70 (Port : out Serial_Port;
71 Name : Port_Name);
72 -- Open the given port name. Raises Serial_Error if the port cannot be
73 -- opened.
75 procedure Set
76 (Port : Serial_Port;
77 Rate : Data_Rate := B9600;
78 Bits : Data_Bits := CS8;
79 Stop_Bits : Stop_Bits_Number := One;
80 Parity : Parity_Check := None;
81 Block : Boolean := True;
82 Timeout : Duration := 10.0);
83 -- The communication port settings. If Block is set then a read call
84 -- will wait for the whole buffer to be filed. If Block is not set then
85 -- the given Timeout (in seconds) is used. Note that the timeout precision
86 -- may be limited on some implementation (e.g. on GNU/Linux the maximum
87 -- precision is a tenth of seconds).
89 overriding procedure Read
90 (Port : in out Serial_Port;
91 Buffer : out Ada.Streams.Stream_Element_Array;
92 Last : out Ada.Streams.Stream_Element_Offset);
93 -- Read a set of bytes, put result into Buffer and set Last accordingly.
94 -- Last is set to 0 if no byte has been read.
96 overriding procedure Write
97 (Port : in out Serial_Port;
98 Buffer : Ada.Streams.Stream_Element_Array);
99 -- Write buffer into the port
101 procedure Close (Port : in out Serial_Port);
102 -- Close port
104 private
106 type Port_Data;
107 type Port_Data_Access is access Port_Data;
109 type Serial_Port is new Ada.Streams.Root_Stream_Type with record
110 H : Port_Data_Access;
111 end record;
113 Data_Rate_Value : constant array (Data_Rate) of Interfaces.C.unsigned :=
114 (B1200 => 1_200,
115 B2400 => 2_400,
116 B4800 => 4_800,
117 B9600 => 9_600,
118 B19200 => 19_200,
119 B38400 => 38_400,
120 B57600 => 57_600,
121 B115200 => 115_200);
123 end GNAT.Serial_Communications;