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
31 when Success => Err := DbC.Success;
32 when Data_Buffer_Error => Err := DbC.Communication_Error;
33 when Babble_Detected_Error => Err := DbC.Communication_Error;
34 when USB_Transaction_Error => Err := DbC.Communication_Error;
35 when TRB_Error => Err := DbC.Driver_Error;
36 when Stall_Error => Err := DbC.Stall_Error;
37 when Short_Packet => Err := DbC.Data_Residue;
38 when Bandwidth_Error => Err := DbC.Not_Enough_Bandwidth;
39 when Command_Aborted => Err := DbC.Timeout;
40 when Secondary_Bandwidth_Error => Err := DbC.Not_Enough_Bandwidth;
41 when Split_Transaction_Error => Err := DbC.Communication_Error;
42 when others => Err := DbC.Unknown_Error;
43 pragma Debug (Debug.Put_Reg8 ("Unknown_Error", Word8 (CC)));
46 (Debug_Error_Codes and Err /= DbC.Success and Err /= DbC.Unknown_Error,
47 Debug.Put_Reg8 ("Completion code", Word8 (CC)));
51 ----------------------------------------------------------------------------
53 procedure Set_Length (Data : in out T; Length : in Natural)
55 Status : constant Word32 := Data.Status;
57 Data.Status := (Status and not 16#1_ffff#) or
58 (Word32 (Length) and 16#1_ffff#);
61 function Get_Event_Length (Data : T) return Natural
63 Status : constant Word32 := Data.Status;
65 return Natural (Status and 16#ff_ffff#);
68 ----------------------------------------------------------------------------
70 function Get_Completion_Code (Data : T) return Completion_Code
72 Status : constant Word32 := Data.Status;
74 return Completion_Code (Shift_Right (Status, 24));
75 end Get_Completion_Code;
77 ----------------------------------------------------------------------------
79 procedure Set_Cycle (Data : in out T; Cycle : in Bit)
81 Control : constant Word32 := Data.Control;
83 Data.Control := (Control and not 1) or Word32 (Cycle);
86 function Get_Cycle (Data : T) return Bit
88 Control : constant Word32 := Data.Control;
90 return Bit (Control and 1);
93 procedure Set_Toggle_Cycle (Data : in out T)
95 Control : constant Word32 := Data.Control;
97 Data.Control := Control or 16#00_02#;
100 procedure Set_ISP (Data : in out T)
102 Control : constant Word32 := Data.Control;
104 Data.Control := Control or 16#00_04#;
107 procedure Set_IOC (Data : in out T)
109 Control : constant Word32 := Data.Control;
111 Data.Control := Control or 16#00_20#;
114 ----------------------------------------------------------------------------
116 procedure Set_Type (Data : in out T; TRB_Type : in TRB_Types)
118 Control : constant Word32 := Data.Control;
120 Data.Control := (Control and not 16#fc00#) or
121 Shift_Left (Word32 (TRB_Type), 10);
124 function Get_Type (Data : T) return TRB_Types
126 Control : constant Word32 := Data.Control;
128 return TRB_Types (Shift_Right (Control, 10) and 63);
131 ----------------------------------------------------------------------------
133 function Get_Endpoint_ID (Data : T) return Natural
135 Control : constant Word32 := Data.Control;
137 return Natural (Shift_Right (Control, 16) and 16#1f#);
140 function Get_Slot_ID (Data : T) return Word8
142 Control : constant Word32 := Data.Control;
144 return Word8 (Shift_Right (Control, 24));
147 ----------------------------------------------------------------------------
149 procedure Set_Parameter (Data : in out T; Parameter : Word64)
152 Data.Parameter := Parameter;
155 function Get_Parameter (Data : T) return Word64
157 Result : constant Word64 := Data.Parameter;
162 ----------------------------------------------------------------------------
164 procedure Clear (TR : out T; PCS : in Bit)
168 (Parameter => 0, Status => 0, Control => Word32 ((not PCS) and 1));
171 procedure Clear_Ring (TR : out Transfer_Ring; PCS : in Bit)
176 (Parameter => 0, Status => 0, Control => Word32 ((not PCS) and 1)));
179 procedure Init_Cycle_Ring
180 (Ring : out Transfer_Ring;
181 Physical : in Word64)
184 Clear_Ring (Ring, 1);
187 Last : constant Ring_Range := Ring'Last;
190 -- Link last T in the ring to the first.
192 Set_Type (Ring (Last), Link);
193 Set_Toggle_Cycle (Ring (Last));
194 Ring (Last).Parameter := Physical;
200 -- vim: set ts=8 sts=3 sw=3 et: