2008-05-30 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / ada / g-sercom.ads
blob3d327cec76fb3fd50dd6ea5d27e3892905357d42
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 the port name for the given port number
50 type Data_Rate is
51 (B1200, B2400, B4800, B9600, B19200, B38400, B57600, B115200);
52 -- Speed of the communication
54 type Data_Bits is (B8, B7);
55 -- Communication bits
57 type Stop_Bits_Number is (One, Two);
58 -- One or two stop bits
60 type Parity_Check is (None, Even, Odd);
61 -- Either no parity check or an even or odd parity
63 type Serial_Port is new Ada.Streams.Root_Stream_Type with private;
65 procedure Open
66 (Port : out Serial_Port;
67 Name : Port_Name);
68 -- Open the given port name. Raises Serial_Error if the port cannot be
69 -- opened.
71 procedure Set
72 (Port : Serial_Port;
73 Rate : Data_Rate := B9600;
74 Bits : Data_Bits := B8;
75 Stop_Bits : Stop_Bits_Number := One;
76 Parity : Parity_Check := None;
77 Block : Boolean := True;
78 Timeout : Duration := 10.0);
79 -- The communication port settings. If Block is set then a read call
80 -- will wait for the whole buffer to be filed. If Block is not set then
81 -- the given Timeout (in seconds) is used. Note that the timeout precision
82 -- may be limited on some implementation (e.g. on GNU/Linux the maximum
83 -- precision is a tenth of seconds).
85 overriding procedure Read
86 (Port : in out Serial_Port;
87 Buffer : out Ada.Streams.Stream_Element_Array;
88 Last : out Ada.Streams.Stream_Element_Offset);
89 -- Read a set of bytes, put result into Buffer and set Last accordingly.
90 -- Last is set to 0 if no byte has been read.
92 overriding procedure Write
93 (Port : in out Serial_Port;
94 Buffer : Ada.Streams.Stream_Element_Array);
95 -- Write buffer into the port
97 procedure Close (Port : in out Serial_Port);
98 -- Close port
100 private
102 type Port_Data;
103 type Port_Data_Access is access Port_Data;
105 type Serial_Port is new Ada.Streams.Root_Stream_Type with record
106 H : Port_Data_Access;
107 end record;
109 Data_Rate_Value : constant array (Data_Rate) of Interfaces.C.unsigned :=
110 (B1200 => 1_200,
111 B2400 => 2_400,
112 B4800 => 4_800,
113 B9600 => 9_600,
114 B19200 => 19_200,
115 B38400 => 38_400,
116 B57600 => 57_600,
117 B115200 => 115_200);
119 end GNAT.Serial_Communications;