File: /home/oboss/Users/gec/sources/Demonstrator/Low_Level_Drivers/serial_interface.ads

1     --% Compilation Unit:	Serial_Interface
2     --
3     --% Category: Generic Package Declaration
4     --
5     --% Release:  $Name:  $
6     --
7     --% Version:  $Revision: 2.0 $
8     --
9     --% Author:   $Author: gec $
10     --
11     --% Revision Log:
12     --    $Log: serial_interface.ads,v $
13     --    Revision 2.0  2003/04/04 08:50:32  gec
14     --    Initial release of source files serving as baseline for OBOSS-III project.
15     --
16     --    Revision 1.1.1.1  2003/04/04 08:13:05  gec
17     --    Imported using TkCVS
18     --
19     --
20     --
21     --% Project: OBOSS
22     --
23     --% Copyright (C) 2003 by Terma A/S
24     --  Proprietary and intellectual rights of Terma A/S, Denmark,
25     --  are involved in the subject-matter of this material and
26     --  all manufacturing, reproduction, use, disclosure, and
27     --  sales rights pertaining to such subject-matter are
28     --  expressly reserved. This material is submitted for a
29     --  specific purpose as agreed, and the recipient by
30     --  accepting this material agrees that this material will
31     --  not be used, copied, or reproduced in whole or in part
32     --  nor its contents revealed in any manner or to any person,
33     --  except to meet the purpose for which it was submitted and
34     --  subject to the terms of the agreement.
35     --
36     --% Target Dependencies:
37     --    None
38     --% Compiler Dependencies:
39     --    None
40     
41     --~-----------------------------------------------------------------------------
42     
43     with Basic_Types;
44     with Kernel.Peripherals;
45     with Task_Priority_Control;
46     with Mission_Parameters;
47     with Ada.Interrupts;
48     generic
49     
50        -- UART channel to be interfaced by the instance
51        Channel : in     Kernel.Peripherals.UART_Channel;
52        -- Priority of critical region protecting  UART access
53        UART_Protection_Priority
54                                 : in     Task_Priority_Control.
55                                   Passive_Task_Priority;
56        -- Application ID used for generation of event reports in case of anomalies
57        My_Application_ID : in     Mission_Parameters.APID;
58        -- Priority of protected object hanlding interrupts
59        Interrupt_Handler_Priority
60                                   : in     Task_Priority_Control.
61                                     Interrupt_Task_Priority;
62        -- Priority and stack size of Sporadic task forwarding data read from UART
63        Receiver_Task_Priority : in     Task_Priority_Control.Active_Task_Priority;
64        Receiver_Task_Stack_Size : in     Natural;
65        -- Size of buffer for received data elements
66        Receive_Buffer_Size : in     Positive;
67        -- Operation handling data received on the serial interface
68        with procedure Forward_Data
69              (Data : in     Basic_Types.Byte_Array);
70     
71     package Serial_Interface is
72     
73        --% Library Package:
74        --    Drivers for the UARTS on the ERC-32 processor.
75        --% Active Tasks:
76        -->   task_name - Category
77        --% Passive Tasks:
78        -->   task_name - Description
79     
80        --% Subprogram:
81        --    Initialise UART A and UART B on the ERC-32
82        --% Parameter Constraints:
83        -->   None
84        --% Exceptions Raised:
85        -->   None
86     
87        procedure Init_UARTs
88              (Baudrate  : in     Kernel.Peripherals.UART_Baudrate;
89               Parity    : in     Kernel.Peripherals.UART_Parity;
90               Stop_Bits : in     Kernel.Peripherals.UART_Stop_Bits)
91              renames Kernel.Peripherals.Init_UART;
92     
93        --% Subprogram:
94        --    Transmit Data on UART identified by Channel.
95        --    Transmisison will be atomic.
96        --% Parameter Constraints:
97        -->   None
98        --% Exceptions Raised:
99        -->   None
100     
101        procedure Send
102              (Data : in     Basic_Types.Byte_Array);
103     
104        -- A very large error counter that will not produce constraint error
105        type Error_Counter is mod Integer'Last;
106     
107        --   Statistics on errors detected on serial interface identified by
108        --+    Channel
109     
110        type UART_Error_Counters is
111           record
112              Framing_Error   : Error_Counter := 0;
113              Parity_Error    : Error_Counter := 0;
114              Overrun_Error   : Error_Counter := 0;
115              Buffer_Overflow : Error_Counter := 0;
116           end record;
117     
118     
119        --VIOLATION-- [V12] Non-constant object declarations are not permitted in
120        --VIOLATION--   the visible part of a package specification.
121        UART_Errors : UART_Error_Counters;
122     
123        -- Definition of mapping from UART channels to their associated Ready
124        --+    interrupts
125        type UART_Channel_Interrupt_Mapping is array
126              (Kernel.Peripherals.UART_Channel) of Ada.Interrupts.Interrupt_ID;
127        Channel_To_Interrupt_Mapping : constant UART_Channel_Interrupt_Mapping :=
128                    (Kernel.Peripherals.A =>
129                        Ada.Interrupts.Interrupt_ID
130                              (Kernel.Peripherals.UART_A_Ready),
131                     Kernel.Peripherals.B =>
132                        Ada.Interrupts.Interrupt_ID
133                              (Kernel.Peripherals.UART_B_Ready));
134     
135        protected UART_Handler
136        --VIOLATION-- [V35] Protected specifications are not allowed in the visible
137        --VIOLATION--   part of a package specification.
138        is
139     
140           --% Protected Specification:
141           --    Interrupt handler for UART interrupt
142           --    NOTE: The protected objects specification must reside in the public
143           --+    part of the package due to an error in GNAT/ORK.
144     
145           --% Subprogram:
146           --    Handles Ready interrupt generated by UART as selected by the
147           --+    Channel formal parameter.
148           --% Parameter Constraints:
149           -->   None
150           --% Exceptions Raised:
151           -->   None
152     
153           pragma Interrupt_Priority (Interrupt_Handler_Priority);
154           procedure Handle_Ready_Interrupt;
155           pragma Attach_Handler
156                 (Handle_Ready_Interrupt, Channel_To_Interrupt_Mapping(Channel));
157     
158           --% Subprogram:
159           --    Extract data elements received on UART indicated by Channel
160           --+    parameter.
161           --    Will block caller if no data is currently available
162           --% Parameter Constraints:
163           -->   None
164           --% Exceptions Raised:
165           -->   None
166     
167           entry Receive_Data
168                 (Data :    out Basic_Types.Byte);
169     
170        private
171     
172           Data_In_Queue : Boolean := False;
173     
174        end UART_Handler;
175     
176     end Serial_Interface;
177     
178     --~-----------------------------------------------------------------------------
179