add functions for usb port reset & config setting

This commit is contained in:
Eric Wild 2022-02-25 15:45:17 +01:00
parent a9470fdc99
commit 421311ef2a
5 changed files with 52 additions and 0 deletions

View File

@ -119,6 +119,25 @@ runs on USB_CT {
g_USB_Tguard.stop;
}
function f_usb_set_configuration(integer dev_hdl, integer bConfigurationValue)
runs on USB_CT {
var USB_result res;
var integer req_hdl := f_usb_get_req_hdl();
g_USB_Tguard.start;
USB.send(ts_USB_set_configuration(dev_hdl, bConfigurationValue, req_hdl));
USB.receive(USB_result:{req_hdl, dev_hdl, ?}) -> value res { log("Received ", res); }
g_USB_Tguard.stop;
}
function f_usb_reset_device()
runs on USB_CT {
var USB_result res;
var integer req_hdl := f_usb_get_req_hdl();
g_USB_Tguard.start;
USB.send(ts_USB_reset_device(g_dev_hdl, req_hdl));
USB.receive(USB_result:{req_hdl, g_dev_hdl, ?}) -> value res { log("Received USB reset response", res); }
g_USB_Tguard.stop;
}
/* Send a USB Device Request and wait for its completion to arrive */
function f_usb_dev_req(template (value) USB_DeviceRequest req)
runs on USB_CT return USB_transfer_compl

View File

@ -432,6 +432,17 @@ void USB__PT_PROVIDER::outgoing_send(const USB__claim__interface& send_par)
incoming_message(USB__result(send_par.req__hdl(), send_par.device__hdl(), rc));
}
void USB__PT_PROVIDER::outgoing_send(const USB__reset__device& send_par)
{
USB_Device *dev = usbdev_by_hdl(send_par.device__hdl());
int rc;
rc = libusb_reset_device(dev->mHandle);
if (rc != 0)
log(TTCN_ERROR, "Cannot reset USB dev! \n");
incoming_message(USB__result(send_par.req__hdl(), send_par.device__hdl(), rc));
}
void USB__PT_PROVIDER::outgoing_send(const USB__release__interface& send_par)
{
USB_Device *dev = usbdev_by_hdl(send_par.device__hdl());

View File

@ -93,6 +93,7 @@ protected:
void user_start();
void user_stop();
void outgoing_send(const USB__reset__device& send_par);
void outgoing_send(const USB__open__vid__pid& send_par);
void outgoing_send(const USB__open__path& send_par);
void outgoing_send(const USB__transfer& send_par);

View File

@ -2,6 +2,7 @@ module USB_PortType {
import from USB_PortTypes all;
type port USB_PT message {
out USB_reset_device;
out USB_open_vid_pid;
out USB_open_path;
out USB_set_configuration;

View File

@ -130,6 +130,11 @@ module USB_PortTypes {
octetstring data
};
type record USB_reset_device {
integer req_hdl,
integer device_hdl
};
/* Response: USB_result */
template (value) USB_open_vid_pid
ts_USB_open_vid_pid(USB_vendor_id vid, USB_product_id pid, integer device_hdl := -1,
@ -189,6 +194,21 @@ ts_USB_get_config_descriptor_by_value(integer device_hdl, integer cfg_val, integ
config_value := cfg_val
}
template (value) USB_set_configuration
ts_USB_set_configuration(integer device_hdl, integer config_num := 1, integer req_hdl := -1) :=
{
req_hdl := req_hdl,
device_hdl := device_hdl,
configuration := config_num
}
template (value) USB_reset_device
ts_USB_reset_device(integer device_hdl, integer req_hdl := -1) :=
{
req_hdl := req_hdl,
device_hdl := device_hdl
}
template USB_descriptor
tr_USB_descriptor(template integer device_hdl :=?, template integer req_hdl := ?,
template integer result_code := ?, template octetstring data := ?) := {