annotate gcc/ada/libgnat/g-sercom.ads @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
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 --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 2007-2018, AdaCore --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
17 -- --
kono
parents:
diff changeset
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
19 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
20 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
23 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
25 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
26 -- --
kono
parents:
diff changeset
27 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
29 -- --
kono
parents:
diff changeset
30 ------------------------------------------------------------------------------
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 -- Serial communications package, implemented on Windows and GNU/Linux
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 with Ada.Streams;
kono
parents:
diff changeset
35 with Interfaces.C;
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 package GNAT.Serial_Communications is
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 -- Following is a simple example of using GNAT.Serial_Communications.
kono
parents:
diff changeset
40 --
kono
parents:
diff changeset
41 -- with Ada.Streams;
kono
parents:
diff changeset
42 -- with GNAT.Serial_Communications;
kono
parents:
diff changeset
43 --
kono
parents:
diff changeset
44 -- procedure Serial is
kono
parents:
diff changeset
45 -- use Ada.Streams;
kono
parents:
diff changeset
46 -- use GNAT;
kono
parents:
diff changeset
47 --
kono
parents:
diff changeset
48 -- subtype Message is Stream_Element_Array (1 .. 20);
kono
parents:
diff changeset
49 --
kono
parents:
diff changeset
50 -- Data : constant String (1 .. 20) := "ABCDEFGHIJLKMNOPQRST";
kono
parents:
diff changeset
51 -- Buffer : Message;
kono
parents:
diff changeset
52 --
kono
parents:
diff changeset
53 -- S_Port : constant Natural := 5;
kono
parents:
diff changeset
54 -- -- Serial port number
kono
parents:
diff changeset
55 --
kono
parents:
diff changeset
56 -- begin
kono
parents:
diff changeset
57 -- -- Convert message (String -> Stream_Element_Array)
kono
parents:
diff changeset
58 --
kono
parents:
diff changeset
59 -- for K in Data'Range loop
kono
parents:
diff changeset
60 -- Buffer (Stream_Element_Offset (K)) := Character'Pos (Data (K));
kono
parents:
diff changeset
61 -- end loop;
kono
parents:
diff changeset
62 --
kono
parents:
diff changeset
63 -- declare
kono
parents:
diff changeset
64 -- Port_Name : constant Serial_Communications.Port_Name :=
kono
parents:
diff changeset
65 -- Serial_Communications.Name (Number => S_Port);
kono
parents:
diff changeset
66 -- Port : Serial_Communications.Serial_Port;
kono
parents:
diff changeset
67 --
kono
parents:
diff changeset
68 -- begin
kono
parents:
diff changeset
69 -- Serial_Communications.Open
kono
parents:
diff changeset
70 -- (Port => Port,
kono
parents:
diff changeset
71 -- Name => Port_Name);
kono
parents:
diff changeset
72 --
kono
parents:
diff changeset
73 -- Serial_Communications.Set
kono
parents:
diff changeset
74 -- (Port => Port,
kono
parents:
diff changeset
75 -- Rate => Serial_Communications.B9600,
kono
parents:
diff changeset
76 -- Bits => Serial_Communications.CS8,
kono
parents:
diff changeset
77 -- Stop_Bits => Serial_Communications.One,
kono
parents:
diff changeset
78 -- Parity => Serial_Communications.Even);
kono
parents:
diff changeset
79 --
kono
parents:
diff changeset
80 -- Serial_Communications.Write
kono
parents:
diff changeset
81 -- (Port => Port,
kono
parents:
diff changeset
82 -- Buffer => Buffer);
kono
parents:
diff changeset
83 --
kono
parents:
diff changeset
84 -- Serial_Communications.Close
kono
parents:
diff changeset
85 -- (Port => Port);
kono
parents:
diff changeset
86 -- end;
kono
parents:
diff changeset
87 -- end Serial;
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 Serial_Error : exception;
kono
parents:
diff changeset
90 -- Raised when a communication problem occurs
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 type Port_Name is new String;
kono
parents:
diff changeset
93 -- A serial com port name
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 function Name (Number : Positive) return Port_Name;
kono
parents:
diff changeset
96 -- Returns a possible port name for the given legacy PC architecture serial
kono
parents:
diff changeset
97 -- port number (COM<number>: on Windows, ttyS<number-1> on Linux).
kono
parents:
diff changeset
98 -- Note that this function does not support other kinds of serial ports
kono
parents:
diff changeset
99 -- nor operating systems other than Windows and Linux. For all other
kono
parents:
diff changeset
100 -- cases, an explicit port name can be passed directly to Open.
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 type Data_Rate is
kono
parents:
diff changeset
103 (B75, B110, B150, B300, B600, B1200, B2400, B4800, B9600,
kono
parents:
diff changeset
104 B19200, B38400, B57600, B115200);
kono
parents:
diff changeset
105 -- Speed of the communication
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 type Data_Bits is (CS8, CS7);
kono
parents:
diff changeset
108 -- Communication bits
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110 type Stop_Bits_Number is (One, Two);
kono
parents:
diff changeset
111 -- One or two stop bits
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 type Parity_Check is (None, Even, Odd);
kono
parents:
diff changeset
114 -- Either no parity check or an even or odd parity
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 type Flow_Control is (None, RTS_CTS, Xon_Xoff);
kono
parents:
diff changeset
117 -- No flow control, hardware flow control, software flow control
kono
parents:
diff changeset
118
kono
parents:
diff changeset
119 type Serial_Port is new Ada.Streams.Root_Stream_Type with private;
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 procedure Open
kono
parents:
diff changeset
122 (Port : out Serial_Port;
kono
parents:
diff changeset
123 Name : Port_Name);
kono
parents:
diff changeset
124 -- Open the given port name. Raises Serial_Error if the port cannot be
kono
parents:
diff changeset
125 -- opened.
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 procedure Set
kono
parents:
diff changeset
128 (Port : Serial_Port;
kono
parents:
diff changeset
129 Rate : Data_Rate := B9600;
kono
parents:
diff changeset
130 Bits : Data_Bits := CS8;
kono
parents:
diff changeset
131 Stop_Bits : Stop_Bits_Number := One;
kono
parents:
diff changeset
132 Parity : Parity_Check := None;
kono
parents:
diff changeset
133 Block : Boolean := True;
kono
parents:
diff changeset
134 Local : Boolean := True;
kono
parents:
diff changeset
135 Flow : Flow_Control := None;
kono
parents:
diff changeset
136 Timeout : Duration := 10.0);
kono
parents:
diff changeset
137 -- The communication port settings. If Block is set then a read call
kono
parents:
diff changeset
138 -- will wait for the whole buffer to be filed. If Block is not set then
kono
parents:
diff changeset
139 -- the given Timeout (in seconds) is used. If Local is set then modem
kono
parents:
diff changeset
140 -- control lines (in particular DCD) are ignored (not supported on
kono
parents:
diff changeset
141 -- Windows). Flow indicates the flow control type as defined above.
kono
parents:
diff changeset
142
kono
parents:
diff changeset
143 -- Note: the timeout precision may be limited on some implementation
kono
parents:
diff changeset
144 -- (e.g. on GNU/Linux the maximum precision is a tenth of seconds).
kono
parents:
diff changeset
145
kono
parents:
diff changeset
146 -- Note: calling this procedure may reinitialize the serial port hardware
kono
parents:
diff changeset
147 -- and thus cause loss of some buffered data if used during communication.
kono
parents:
diff changeset
148
kono
parents:
diff changeset
149 overriding procedure Read
kono
parents:
diff changeset
150 (Port : in out Serial_Port;
kono
parents:
diff changeset
151 Buffer : out Ada.Streams.Stream_Element_Array;
kono
parents:
diff changeset
152 Last : out Ada.Streams.Stream_Element_Offset);
kono
parents:
diff changeset
153 -- Read a set of bytes, put result into Buffer and set Last accordingly.
kono
parents:
diff changeset
154 -- Last is set to Buffer'First - 1 if no byte has been read, unless
kono
parents:
diff changeset
155 -- Buffer'First = Stream_Element_Offset'First, in which case the exception
kono
parents:
diff changeset
156 -- Constraint_Error is raised instead.
kono
parents:
diff changeset
157
kono
parents:
diff changeset
158 overriding procedure Write
kono
parents:
diff changeset
159 (Port : in out Serial_Port;
kono
parents:
diff changeset
160 Buffer : Ada.Streams.Stream_Element_Array);
kono
parents:
diff changeset
161 -- Write buffer into the port
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 procedure Close (Port : in out Serial_Port);
kono
parents:
diff changeset
164 -- Close port
kono
parents:
diff changeset
165
kono
parents:
diff changeset
166 private
kono
parents:
diff changeset
167
kono
parents:
diff changeset
168 type Port_Data;
kono
parents:
diff changeset
169 type Port_Data_Access is access Port_Data;
kono
parents:
diff changeset
170
kono
parents:
diff changeset
171 type Serial_Port is new Ada.Streams.Root_Stream_Type with record
kono
parents:
diff changeset
172 H : Port_Data_Access;
kono
parents:
diff changeset
173 end record;
kono
parents:
diff changeset
174
kono
parents:
diff changeset
175 Data_Rate_Value : constant array (Data_Rate) of Interfaces.C.unsigned :=
kono
parents:
diff changeset
176 (B75 => 75,
kono
parents:
diff changeset
177 B110 => 110,
kono
parents:
diff changeset
178 B150 => 150,
kono
parents:
diff changeset
179 B300 => 300,
kono
parents:
diff changeset
180 B600 => 600,
kono
parents:
diff changeset
181 B1200 => 1_200,
kono
parents:
diff changeset
182 B2400 => 2_400,
kono
parents:
diff changeset
183 B4800 => 4_800,
kono
parents:
diff changeset
184 B9600 => 9_600,
kono
parents:
diff changeset
185 B19200 => 19_200,
kono
parents:
diff changeset
186 B38400 => 38_400,
kono
parents:
diff changeset
187 B57600 => 57_600,
kono
parents:
diff changeset
188 B115200 => 115_200);
kono
parents:
diff changeset
189
kono
parents:
diff changeset
190 end GNAT.Serial_Communications;