Skip to content

Commit

Permalink
Merge pull request #10 from ThyMYthOS/usb_requests
Browse files Browse the repository at this point in the history
Implement GET_STATUS request
  • Loading branch information
Fabien-Chouteau authored Apr 10, 2024
2 parents 442ad91 + 5553223 commit 0c6173d
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/usb-device-control.adb
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ package body USB.Device.Control is

case Req.Request is
when 0 => -- GET_STATUS
raise Program_Error with "GET_STATUS not implemented";
return Get_Status (This, Req);
when 1 => -- CLEAR_FEATURE
raise Program_Error with "CLEAR_FEATURE not implemented";
when 3 => -- SET_FEATURE
Expand Down
20 changes: 20 additions & 0 deletions src/usb-device.adb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,26 @@ package body USB.Device is
This.Ctrl.State := Idle;
end Stall_Control_EP;

----------------
-- Get_Status --
----------------

function Get_Status (This : in out USB_Device_Stack;
Req : Setup_Data)
return Setup_Request_Answer
is
begin
if Req.Value = 0 and then Req.Index = 0 and then Req.Length = 2 then
This.Ctrl.Buffer (1) := 0; -- Reserved
This.Ctrl.Buffer (2) := 0; -- B1: Remote Wakeup; B0: Self Powered
This.Ctrl.Buf := This.Ctrl.Buffer'Address;
This.Ctrl.Len := Storage_Offset (2);
return Handled;
end if;

return Not_Supported;
end Get_Status;

----------------
-- Get_String --
----------------
Expand Down
4 changes: 4 additions & 0 deletions src/usb-device.ads
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,10 @@ private

procedure Stall_Control_EP (This : in out USB_Device_Stack);

function Get_Status (This : in out USB_Device_Stack;
Req : Setup_Data)
return Setup_Request_Answer;

function Get_String (This : in out USB_Device_Stack;
Index : String_Id)
return Setup_Request_Answer;
Expand Down
29 changes: 29 additions & 0 deletions tests/src/tests-device.adb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,34 @@ package body Tests.Device is
Early_Address => True);
end Set_Early_Address;

----------------
-- Get_Status --
----------------

procedure Get_Status (Unused : in out UDC_Stub_Fixture) is
Scenario : aliased constant UDC_Stub.Stub_Scenario :=
UDC_Scenarios.Enumeration (Verbose => False) &
UDC_Scenarios.Get_Status (Verbose => True);

RX_Data : aliased constant UInt8_Array := (1 .. 2 => 0);

Expected : constant AAA.Strings.Vector := AAA.Strings.Empty_Vector
.Append ("UDC Verbose on")
.Append ("UDC Poll -> SETUP_REQUEST [EP_OUT 0] Type: (DEVICE_TO_HOST,STAND,DEV) Req: 0 Val: 0 Index: 0 Len: 2")
.Append ("UDC EP_Ready_For_Data [EP_OUT 0] FALSE")
.Append ("UDC EP_Write_Packet [EP_IN 0] 2 bytes")
.Append ("0000_0000_0000_0000: 00 00 ..")
.Append ("UDC Poll -> TRANSFER_COMPLETE [EP_IN 0] BCNT: 2")
.Append ("UDC EP_Ready_For_Data [EP_OUT 0] TRUE")
.Append ("UDC Poll -> NONE");
begin

USB_Testing.UDC_Scenarios.Basic_UDC_Test (Scenario,
Expected,
RX_Data,
Early_Address => True);
end Get_Status;

----------------------
-- Control_Data_Out --
----------------------
Expand Down Expand Up @@ -365,6 +393,7 @@ begin
Suite.Add_Test (UDC_Stub_Caller.Create ("No Status Out ZLP", No_Status_Out_ZLP'Access));
Suite.Add_Test (UDC_Stub_Caller.Create ("Set_Address", Set_Address'Access));
Suite.Add_Test (UDC_Stub_Caller.Create ("Set_Early_Address", Set_Early_Address'Access));
Suite.Add_Test (UDC_Stub_Caller.Create ("Get_Status", Get_Status'Access));
Suite.Add_Test (UDC_Stub_Caller.Create ("Control_Data_Out", Control_Data_Out'Access));
Suite.Add_Test (UDC_Stub_Caller.Create ("String Descriptor", String_Descriptor'Access));
Suite.Add_Test (UDC_Stub_Caller.Create ("iface Setup Dispatch", Iface_Setup_Dispatch'Access));
Expand Down
12 changes: 12 additions & 0 deletions tests/src/usb_testing-udc_scenarios.ads
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ package USB_Testing.UDC_Scenarios is
)
);

function Get_Status (Verbose : Boolean)
return UDC_Stub.Stub_Scenario
is (((Kind => Set_Verbose, Verbose => Verbose)

, (Kind => UDC_Event_E,
Evt => (Kind => Setup_Request,
Req => ((Dev, 0, Stand, Device_To_Host),
0, 0, 0, 2),
Req_EP => 0))
)
);

function Get_Config (Verbose : Boolean)
return UDC_Stub.Stub_Scenario
is (((Kind => Set_Verbose, Verbose => Verbose)
Expand Down

0 comments on commit 0c6173d

Please sign in to comment.