2 -- Copyright (C) 2016-2017 secunet Security Networks AG
4 -- This program is free software; you can redistribute it and/or modify
5 -- it under the terms of the GNU General Public License as published by
6 -- the Free Software Foundation; either version 2 of the License, or
7 -- (at your option) any later version.
9 -- This program is distributed in the hope that it will be useful,
10 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- GNU General Public License for more details.
21 package body HW.DbC.TRBs
24 Debug_Error_Codes : constant Boolean := False;
26 function CC_To_Usb_Error (CC : Completion_Code) return Error
28 use type HW.DbC.Error;
32 when Success => Err := DbC.Success;
33 when Data_Buffer_Error => Err := DbC.Communication_Error;
34 when Babble_Detected_Error => Err := DbC.Communication_Error;
35 when USB_Transaction_Error => Err := DbC.Communication_Error;
36 when TRB_Error => Err := DbC.Driver_Error;
37 when Stall_Error => Err := DbC.Stall_Error;
38 when Short_Packet => Err := DbC.Data_Residue;
39 when Bandwidth_Error => Err := DbC.Not_Enough_Bandwidth;
40 when Command_Aborted => Err := DbC.Timeout;
41 when Secondary_Bandwidth_Error => Err := DbC.Not_Enough_Bandwidth;
42 when Split_Transaction_Error => Err := DbC.Communication_Error;
43 when others => Err := DbC.Unknown_Error;
44 pragma Debug (Debug.Put_Reg8 ("Unknown_Error", Word8 (CC)));
47 (Debug_Error_Codes and Err /= DbC.Success and Err /= DbC.Unknown_Error,
48 Debug.Put_Reg8 ("Completion code", Word8 (CC)));
52 ----------------------------------------------------------------------------
54 procedure Set_Length (Data : in out T; Length : in Natural)
56 Status : constant Word32 := Data.Status;
58 Data.Status := (Status and not 16#1_ffff#) or
59 (Word32 (Length) and 16#1_ffff#);
62 function Get_Event_Length (Data : T) return Natural
64 Status : constant Word32 := Data.Status;
66 return Natural (Status and 16#ff_ffff#);
69 ----------------------------------------------------------------------------
71 function Get_Completion_Code (Data : T) return Completion_Code
73 Status : constant Word32 := Data.Status;
75 return Completion_Code (Shift_Right (Status, 24));
76 end Get_Completion_Code;
78 ----------------------------------------------------------------------------
80 procedure Set_Cycle (Data : in out T; Cycle : in Bit)
82 Control : constant Word32 := Data.Control;
84 Data.Control := (Control and not 1) or Word32 (Cycle);
87 function Get_Cycle (Data : T) return Bit
89 Control : constant Word32 := Data.Control;
91 return Bit (Control and 1);
94 procedure Set_Toggle_Cycle (Data : in out T)
96 Control : constant Word32 := Data.Control;
98 Data.Control := Control or 16#00_02#;
101 procedure Set_ISP (Data : in out T)
103 Control : constant Word32 := Data.Control;
105 Data.Control := Control or 16#00_04#;
108 procedure Set_IOC (Data : in out T)
110 Control : constant Word32 := Data.Control;
112 Data.Control := Control or 16#00_20#;
115 ----------------------------------------------------------------------------
117 procedure Set_Type (Data : in out T; TRB_Type : in TRB_Types)
119 Control : constant Word32 := Data.Control;
121 Data.Control := (Control and not 16#fc00#) or
122 Shift_Left (Word32 (TRB_Type), 10);
125 function Get_Type (Data : T) return TRB_Types
127 Control : constant Word32 := Data.Control;
129 return TRB_Types (Shift_Right (Control, 10) and 63);
132 ----------------------------------------------------------------------------
134 function Get_Endpoint_ID (Data : T) return Natural
136 Control : constant Word32 := Data.Control;
138 return Natural (Shift_Right (Control, 16) and 16#1f#);
141 function Get_Slot_ID (Data : T) return Word8
143 Control : constant Word32 := Data.Control;
145 return Word8 (Shift_Right (Control, 24));
148 ----------------------------------------------------------------------------
150 procedure Set_Parameter (Data : in out T; Parameter : Word64)
153 Data.Parameter := Parameter;
156 function Get_Parameter (Data : T) return Word64
158 Result : constant Word64 := Data.Parameter;
163 ----------------------------------------------------------------------------
165 procedure Clear (TR : out T; PCS : in Bit)
169 (Parameter => 0, Status => 0, Control => Word32 ((not PCS) and 1));
172 procedure Clear_Ring (TR : out Transfer_Ring; PCS : in Bit)
177 (Parameter => 0, Status => 0, Control => Word32 ((not PCS) and 1)));
180 procedure Init_Cycle_Ring
181 (Ring : out Transfer_Ring;
182 Physical : in Word64)
185 Clear_Ring (Ring, 1);
188 Last : constant Ring_Range := Ring'Last;
191 -- Link last T in the ring to the first.
193 Set_Type (Ring (Last), Link);
194 Set_Toggle_Cycle (Ring (Last));
195 Ring (Last).Parameter := Physical;
201 -- vim: set ts=8 sts=3 sw=3 et: